diff options
Diffstat (limited to 'src')
7 files changed, 207 insertions, 98 deletions
diff --git a/src/com/android/dialer/DialtactsActivity.java b/src/com/android/dialer/DialtactsActivity.java index 47e52342a..fc0f1fb24 100644 --- a/src/com/android/dialer/DialtactsActivity.java +++ b/src/com/android/dialer/DialtactsActivity.java @@ -84,7 +84,7 @@ import com.android.dialer.util.IntentUtil; import com.android.dialer.util.DialerUtils; import com.android.dialer.widget.ActionBarController; import com.android.dialer.widget.SearchEditTextLayout; -import com.android.dialer.widget.SearchEditTextLayout.OnBackButtonClickedListener; +import com.android.dialer.widget.SearchEditTextLayout.Callback; import com.android.dialerbind.DatabaseHelperManager; import com.android.phone.common.animation.AnimUtils; import com.android.phone.common.animation.AnimationListenerAdapter; @@ -136,6 +136,8 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O private static final int ACTIVITY_REQUEST_CODE_VOICE_SEARCH = 1; + private static final int FAB_SCALE_IN_DELAY_MS = 300; + private FrameLayout mParentLayout; /** @@ -338,14 +340,19 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O }; /** - * If the search term is empty and the user closes the soft keyboard, close the search UI. + * Handles the user closing the soft keyboard. */ private final View.OnKeyListener mSearchEditTextLayoutListener = new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { - if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN && - TextUtils.isEmpty(mSearchView.getText().toString())) { - maybeExitSearchUi(); + if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) { + if (TextUtils.isEmpty(mSearchView.getText().toString())) { + // If the search term is empty, close the search UI. + maybeExitSearchUi(); + } else { + // If the search term is not empty, show the dialpad fab. + showFabInSearchUi(); + } } return false; } @@ -394,11 +401,17 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O .setOnClickListener(mSearchViewOnClickListener); searchEditTextLayout.findViewById(R.id.search_box_start_search) .setOnClickListener(mSearchViewOnClickListener); - searchEditTextLayout.setOnBackButtonClickedListener(new OnBackButtonClickedListener() { + searchEditTextLayout.setCallback(new SearchEditTextLayout.Callback() { @Override public void onBackButtonClicked() { onBackPressed(); } + + @Override + public void onSearchViewClicked() { + // Hide FAB, as the keyboard is shown. + mFloatingActionButtonController.scaleOut(); + } }); mIsLandscape = getResources().getConfiguration().orientation @@ -463,7 +476,8 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O observer.removeOnGlobalLayoutListener(this); int screenWidth = mParentLayout.getWidth(); mFloatingActionButtonController.setScreenWidth(screenWidth); - updateFloatingActionButtonControllerAlignment(false /* animate */); + mFloatingActionButtonController.align( + getFabAlignment(), false /* animate */); } }); @@ -527,7 +541,7 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O } prepareVoiceSearchButton(); mDialerDatabaseHelper.startSmartDialUpdateThread(); - updateFloatingActionButtonControllerAlignment(false /* animate */); + mFloatingActionButtonController.align(getFabAlignment(), false /* animate */); Trace.endSection(); } @@ -744,7 +758,7 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O updateSearchFragmentPosition(); - updateFloatingActionButtonControllerAlignment(animate); + mFloatingActionButtonController.align(getFabAlignment(), animate); if (animate) { mDialpadFragment.getView().startAnimation(mSlideOut); } else { @@ -948,6 +962,8 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O mInDialpadSearch = smartDialSearch; mInRegularSearch = !smartDialSearch; + mFloatingActionButtonController.scaleOut(); + SearchFragment fragment = (SearchFragment) getFragmentManager().findFragmentByTag(tag); if (animate) { transaction.setCustomAnimations(android.R.animator.fade_in, 0); @@ -959,6 +975,15 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O fragment = new SmartDialSearchFragment(); } else { fragment = new RegularSearchFragment(); + fragment.setOnTouchListener(new View.OnTouchListener() { + @Override + public boolean onTouch(View v, MotionEvent event) { + // Show the FAB when the user touches the lists fragment and the soft + // keyboard is hidden. + showFabInSearchUi(); + return false; + } + }); } transaction.add(R.id.dialtacts_frame, fragment, tag); } else { @@ -995,6 +1020,14 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O setNotInSearchUi(); + // Restore the FAB for the lists fragment. + if (getFabAlignment() != FloatingActionButtonController.ALIGN_END) { + mFloatingActionButtonController.setVisible(false); + } + mFloatingActionButtonController.scaleIn(FAB_SCALE_IN_DELAY_MS); + onPageScrolled(mListsFragment.getCurrentTabIndex(), 0 /* offset */, 0 /* pixelOffset */); + onPageSelected(mListsFragment.getCurrentTabIndex()); + final FragmentTransaction transaction = getFragmentManager().beginTransaction(); if (mSmartDialSearchFragment != null) { transaction.remove(mSmartDialSearchFragment); @@ -1055,6 +1088,14 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O return false; } + private void showFabInSearchUi() { + mFloatingActionButtonController.changeIcon( + getResources().getDrawable(R.drawable.fab_ic_dial), + getResources().getString(R.string.action_menu_dialpad_button)); + mFloatingActionButtonController.align(getFabAlignment(), false /* animate */); + mFloatingActionButtonController.scaleIn(FAB_SCALE_IN_DELAY_MS); + } + @Override public void onDialpadQueryChanged(String query) { if (mSmartDialSearchFragment != null) { @@ -1251,16 +1292,12 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O return mActionBarHeight; } - /** - * Updates controller based on currently known information. - * - * @param animate Whether or not to animate the transition. - */ - private void updateFloatingActionButtonControllerAlignment(boolean animate) { - int align = (!mIsLandscape && - mListsFragment.getCurrentTabIndex() == ListsFragment.TAB_INDEX_SPEED_DIAL) ? - FloatingActionButtonController.ALIGN_MIDDLE : - FloatingActionButtonController.ALIGN_END; - mFloatingActionButtonController.align(align, 0 /* offsetX */, 0 /* offsetY */, animate); + + private int getFabAlignment() { + if (!mIsLandscape && !isInSearchUi() && + mListsFragment.getCurrentTabIndex() == ListsFragment.TAB_INDEX_SPEED_DIAL) { + return FloatingActionButtonController.ALIGN_MIDDLE; + } + return FloatingActionButtonController.ALIGN_END; } } diff --git a/src/com/android/dialer/calllog/CallLogAdapter.java b/src/com/android/dialer/calllog/CallLogAdapter.java index 69fbb034b..4304002da 100644 --- a/src/com/android/dialer/calllog/CallLogAdapter.java +++ b/src/com/android/dialer/calllog/CallLogAdapter.java @@ -41,7 +41,6 @@ import com.android.dialer.PhoneCallDetailsHelper; import com.android.dialer.R; import com.android.dialer.contactinfo.ContactInfoCache; import com.android.dialer.contactinfo.ContactInfoCache.OnContactInfoChangedListener; -import com.android.dialer.util.DialerUtils; import com.android.dialer.voicemail.VoicemailPlaybackPresenter; import com.google.common.annotations.VisibleForTesting; @@ -105,24 +104,6 @@ public class CallLogAdapter extends GroupingListAdapter /** Helper to group call log entries. */ private final CallLogGroupBuilder mCallLogGroupBuilder; - /** Listener for the primary or secondary actions in the list. - * Primary opens the call details. - * Secondary calls or plays. - **/ - private final View.OnClickListener mActionListener = new View.OnClickListener() { - @Override - public void onClick(View view) { - final IntentProvider intentProvider = (IntentProvider) view.getTag(); - if (intentProvider != null) { - final Intent intent = intentProvider.getIntent(mContext); - // See IntentProvider.getCallDetailIntentProvider() for why this may be null. - if (intent != null) { - DialerUtils.startActivityWithErrorToast(mContext, intent); - } - } - } - }; - /** * The OnClickListener used to expand or collapse the action buttons of a call log entry. */ @@ -135,9 +116,13 @@ public class CallLogAdapter extends GroupingListAdapter return; } + // Always reset the voicemail playback state on expand or collapse. + mVoicemailPlaybackPresenter.reset(); + if (viewHolder.getAdapterPosition() == mCurrentlyExpandedPosition) { // Hide actions, if the clicked item is the expanded item. viewHolder.showActions(false); + mCurrentlyExpandedPosition = RecyclerView.NO_POSITION; mCurrentlyExpandedRowId = NO_EXPANDED_LIST_ITEM; } else { @@ -308,7 +293,7 @@ public class CallLogAdapter extends GroupingListAdapter CallLogListItemViewHolder viewHolder = CallLogListItemViewHolder.create( view, mContext, - mActionListener, + mExpandCollapseListener, mPhoneNumberUtilsWrapper, mCallLogViewsHelper, mVoicemailPlaybackPresenter); @@ -317,7 +302,6 @@ public class CallLogAdapter extends GroupingListAdapter viewHolder.callLogEntryView.setAccessibilityDelegate(mAccessibilityDelegate); viewHolder.primaryActionView.setTag(viewHolder); - viewHolder.primaryActionView.setOnClickListener(mExpandCollapseListener); return viewHolder; } @@ -414,13 +398,14 @@ public class CallLogAdapter extends GroupingListAdapter views.dayGroupHeader.setVisibility(View.GONE); } + mCallLogViewsHelper.setPhoneCallDetails(mContext, views, details); + // Update the expanded position if the rowIds match, in case ViewHolders were added/removed. // Then restore the state of the row on rebind. if (mCurrentlyExpandedRowId == views.rowId) { mCurrentlyExpandedPosition = position; } views.showActions(mCurrentlyExpandedPosition == position); - views.updateCallButton(); String nameForDefaultImage = null; if (TextUtils.isEmpty(info.name)) { diff --git a/src/com/android/dialer/calllog/CallLogFragment.java b/src/com/android/dialer/calllog/CallLogFragment.java index 6f9767c41..0f19f1491 100644 --- a/src/com/android/dialer/calllog/CallLogFragment.java +++ b/src/com/android/dialer/calllog/CallLogFragment.java @@ -188,7 +188,6 @@ public class CallLogFragment extends Fragment setHasOptionsMenu(true); mVoicemailPlaybackPresenter = new VoicemailPlaybackPresenter(activity, state); - activity.setVolumeControlStream(VoicemailPlaybackPresenter.PLAYBACK_STREAM); } /** Called by the CallLogQueryHandler when the list of calls has been fetched or updated. */ diff --git a/src/com/android/dialer/calllog/CallLogListItemViewHolder.java b/src/com/android/dialer/calllog/CallLogListItemViewHolder.java index 987bcb85d..f54720b31 100644 --- a/src/com/android/dialer/calllog/CallLogListItemViewHolder.java +++ b/src/com/android/dialer/calllog/CallLogListItemViewHolder.java @@ -31,6 +31,7 @@ import android.view.ViewGroup; import android.view.ViewStub; import android.view.ViewTreeObserver; import android.widget.QuickContactBadge; +import android.widget.ImageView; import android.widget.TextView; import com.android.contacts.common.CallUtil; @@ -42,6 +43,7 @@ import com.android.dialer.PhoneCallDetailsHelper; import com.android.dialer.PhoneCallDetailsViews; import com.android.dialer.R; import com.android.dialer.calllog.CallLogAsyncTaskUtil; +import com.android.dialer.util.DialerUtils; import com.android.dialer.voicemail.VoicemailPlaybackPresenter; import com.android.dialer.voicemail.VoicemailPlaybackLayout; @@ -51,7 +53,8 @@ import com.android.dialer.voicemail.VoicemailPlaybackLayout; * * This object also contains UI logic pertaining to the view, to isolate it from the CallLogAdapter. */ -public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder { +public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder + implements View.OnClickListener { /** The root view of the call log list item */ public final View rootView; @@ -66,12 +69,13 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder { /** The view containing the details for the call log row, including the action buttons. */ public final CardView callLogEntryView; /** The actionable view which places a call to the number corresponding to the call log row. */ - public final View callActionView; + public final ImageView primaryActionButtonView; /** The view containing call log item actions. Null until the ViewStub is inflated. */ public View actionsView; /** The button views below are assigned only when the action section is expanded. */ public VoicemailPlaybackLayout voicemailPlaybackView; + public View callButtonView; public View videoCallButtonView; public View createNewContactButtonView; public View addToExistingContactButtonView; @@ -135,16 +139,18 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder { private static final int VOICEMAIL_TRANSCRIPTION_MAX_LINES = 10; private final Context mContext; - private final View.OnClickListener mActionListener; private final PhoneNumberUtilsWrapper mPhoneNumberUtilsWrapper; private final CallLogListItemHelper mCallLogListItemHelper; private final VoicemailPlaybackPresenter mVoicemailPlaybackPresenter; private final int mPhotoSize; + private View.OnClickListener mExpandCollapseListener; + private boolean mVoicemailPrimaryActionButtonClicked; + private CallLogListItemViewHolder( Context context, - View.OnClickListener actionListener, + View.OnClickListener expandCollapseListener, PhoneNumberUtilsWrapper phoneNumberUtilsWrapper, CallLogListItemHelper callLogListItemHelper, VoicemailPlaybackPresenter voicemailPlaybackPresenter, @@ -154,11 +160,11 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder { PhoneCallDetailsViews phoneCallDetailsViews, CardView callLogEntryView, TextView dayGroupHeader, - View callActionView) { + ImageView primaryActionButtonView) { super(rootView); mContext = context; - mActionListener = actionListener; + mExpandCollapseListener = expandCollapseListener; mPhoneNumberUtilsWrapper = phoneNumberUtilsWrapper; mCallLogListItemHelper = callLogListItemHelper; mVoicemailPlaybackPresenter = voicemailPlaybackPresenter; @@ -169,7 +175,7 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder { this.phoneCallDetailsViews = phoneCallDetailsViews; this.callLogEntryView = callLogEntryView; this.dayGroupHeader = dayGroupHeader; - this.callActionView = callActionView; + this.primaryActionButtonView = primaryActionButtonView; Resources resources = mContext.getResources(); mPhotoSize = mContext.getResources().getDimensionPixelSize(R.dimen.contact_photo_size); @@ -180,22 +186,21 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder { quickContactView.setPrioritizedMimeType(Phone.CONTENT_ITEM_TYPE); - if (callActionView != null) { - callActionView.setOnClickListener(mActionListener); - } + primaryActionButtonView.setOnClickListener(this); + primaryActionView.setOnClickListener(mExpandCollapseListener); } public static CallLogListItemViewHolder create( View view, Context context, - View.OnClickListener actionListener, + View.OnClickListener expandCollapseListener, PhoneNumberUtilsWrapper phoneNumberUtilsWrapper, CallLogListItemHelper callLogListItemHelper, VoicemailPlaybackPresenter voicemailPlaybackPresenter) { return new CallLogListItemViewHolder( context, - actionListener, + expandCollapseListener, phoneNumberUtilsWrapper, callLogListItemHelper, voicemailPlaybackPresenter, @@ -205,7 +210,7 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder { PhoneCallDetailsViews.fromView(view), (CardView) view.findViewById(R.id.call_log_row), (TextView) view.findViewById(R.id.call_log_day_group_label), - view.findViewById(R.id.call_icon)); + (ImageView) view.findViewById(R.id.primary_action_button)); } /** @@ -223,54 +228,64 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder { voicemailPlaybackView = (VoicemailPlaybackLayout) actionsView .findViewById(R.id.voicemail_playback_layout); + callButtonView = actionsView.findViewById(R.id.call_action); + callButtonView.setOnClickListener(this); + videoCallButtonView = actionsView.findViewById(R.id.video_call_action); - videoCallButtonView.setOnClickListener(mActionListener); + videoCallButtonView.setOnClickListener(this); createNewContactButtonView = actionsView.findViewById(R.id.create_new_contact_action); - createNewContactButtonView.setOnClickListener(mActionListener); + createNewContactButtonView.setOnClickListener(this); addToExistingContactButtonView = actionsView.findViewById(R.id.add_to_existing_contact_action); - addToExistingContactButtonView.setOnClickListener(mActionListener); + addToExistingContactButtonView.setOnClickListener(this); sendMessageView = actionsView.findViewById(R.id.send_message_action); - sendMessageView.setOnClickListener(mActionListener); + sendMessageView.setOnClickListener(this); detailsButtonView = actionsView.findViewById(R.id.details_action); - detailsButtonView.setOnClickListener(mActionListener); + detailsButtonView.setOnClickListener(this); } bindActionButtons(); } - public void updateCallButton() { - boolean canPlaceCallToNumber = - PhoneNumberUtilsWrapper.canPlaceCallsTo(number, numberPresentation); - - if (canPlaceCallToNumber) { - boolean isVoicemailNumber = - mPhoneNumberUtilsWrapper.isVoicemailNumber(accountHandle, number); - if (isVoicemailNumber) { - // Make a general call to voicemail to ensure that if there are multiple accounts - // it does not call the voicemail number of a specific phone account. - callActionView.setTag(IntentProvider.getReturnVoicemailCallIntentProvider()); + private void updatePrimaryActionButton(boolean isExpanded) { + if (!TextUtils.isEmpty(voicemailUri)) { + // Treat as voicemail list item; show play button if not expanded. + if (!isExpanded) { + primaryActionButtonView.setImageResource(R.drawable.ic_play_arrow_24dp); + primaryActionButtonView.setVisibility(View.VISIBLE); } else { - callActionView.setTag(IntentProvider.getReturnCallIntentProvider(number)); + primaryActionButtonView.setVisibility(View.GONE); } - - if (nameOrNumber != null) { - callActionView.setContentDescription(TextUtils.expandTemplate( + } else { + // Treat as normal list item; show call button, if possible. + boolean canPlaceCallToNumber = + PhoneNumberUtilsWrapper.canPlaceCallsTo(number, numberPresentation); + + if (canPlaceCallToNumber) { + boolean isVoicemailNumber = + mPhoneNumberUtilsWrapper.isVoicemailNumber(accountHandle, number); + if (isVoicemailNumber) { + // Call to generic voicemail number, in case there are multiple accounts. + primaryActionButtonView.setTag( + IntentProvider.getReturnVoicemailCallIntentProvider()); + } else { + primaryActionButtonView.setTag( + IntentProvider.getReturnCallIntentProvider(number)); + } + + primaryActionButtonView.setContentDescription(TextUtils.expandTemplate( mContext.getString(R.string.description_call_action), nameOrNumber)); + primaryActionButtonView.setImageResource(R.drawable.ic_call_24dp); + primaryActionButtonView.setVisibility(View.VISIBLE); } else { - callActionView.setContentDescription( - mContext.getString(R.string.description_call_log_call_action)); + primaryActionButtonView.setTag(null); + primaryActionButtonView.setVisibility(View.GONE); } - - callActionView.setVisibility(View.VISIBLE); - } else { - callActionView.setTag(null); - callActionView.setVisibility(View.GONE); } } @@ -282,13 +297,23 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder { boolean canPlaceCallToNumber = PhoneNumberUtilsWrapper.canPlaceCallsTo(number, numberPresentation); + if (!TextUtils.isEmpty(voicemailUri) && canPlaceCallToNumber) { + callButtonView.setTag(IntentProvider.getReturnCallIntentProvider(number)); + ((TextView) callButtonView.findViewById(R.id.call_action_text)) + .setText(TextUtils.expandTemplate( + mContext.getString(R.string.call_log_action_call), + nameOrNumber)); + callButtonView.setVisibility(View.VISIBLE); + } else { + callButtonView.setVisibility(View.GONE); + } + // If one of the calls had video capabilities, show the video call button. if (CallUtil.isVideoEnabled(mContext) && canPlaceCallToNumber && phoneCallDetailsViews.callTypeIcons.isVideoShown()) { videoCallButtonView.setTag(IntentProvider.getReturnVideoCallIntentProvider(number)); videoCallButtonView.setVisibility(View.VISIBLE); } else { - videoCallButtonView.setTag(null); videoCallButtonView.setVisibility(View.GONE); } @@ -298,7 +323,8 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder { Uri uri = Uri.parse(voicemailUri); mVoicemailPlaybackPresenter.setPlaybackView( - voicemailPlaybackView, uri, false /* startPlayingImmediately */); + voicemailPlaybackView, uri, mVoicemailPrimaryActionButtonClicked); + mVoicemailPrimaryActionButtonClicked = false; CallLogAsyncTaskUtil.markVoicemailAsRead(mContext, uri); } else { @@ -348,6 +374,8 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder { actionsView.setVisibility(View.GONE); } } + + updatePrimaryActionButton(show); } public void expandVoicemailTranscriptionView(boolean isExpanded) { @@ -392,6 +420,23 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder { } } + @Override + public void onClick(View view) { + if (view.getId() == R.id.primary_action_button && !TextUtils.isEmpty(voicemailUri)) { + mVoicemailPrimaryActionButtonClicked = true; + mExpandCollapseListener.onClick(primaryActionView); + } else { + final IntentProvider intentProvider = (IntentProvider) view.getTag(); + if (intentProvider != null) { + final Intent intent = intentProvider.getIntent(mContext); + // See IntentProvider.getCallDetailIntentProvider() for why this may be null. + if (intent != null) { + DialerUtils.startActivityWithErrorToast(mContext, intent); + } + } + } + } + @NeededForTesting public static CallLogListItemViewHolder createForTest(Context context) { Resources resources = context.getResources(); @@ -401,7 +446,7 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder { CallLogListItemViewHolder viewHolder = new CallLogListItemViewHolder( context, - null /* actionListener */, + null /* expandCollapseListener */, phoneNumberUtilsWrapper, new CallLogListItemHelper(phoneCallDetailsHelper, resources), null /* voicemailPlaybackPresenter */, @@ -411,7 +456,7 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder { PhoneCallDetailsViews.createForTest(context), new CardView(context), new TextView(context), - new View(context)); + new ImageView(context)); viewHolder.detailsButtonView = new TextView(context); viewHolder.actionsView = new View(context); viewHolder.voicemailPlaybackView = new VoicemailPlaybackLayout(context); diff --git a/src/com/android/dialer/list/SearchFragment.java b/src/com/android/dialer/list/SearchFragment.java index f86c0e5cf..78c3ad3c1 100644 --- a/src/com/android/dialer/list/SearchFragment.java +++ b/src/com/android/dialer/list/SearchFragment.java @@ -50,6 +50,7 @@ public class SearchFragment extends PhoneNumberPickerFragment { private static final String TAG = SearchFragment.class.getSimpleName(); private OnListFragmentScrolledListener mActivityScrollListener; + private View.OnTouchListener mActivityOnTouchListener; /* * Stores the untouched user-entered string that is used to populate the add to contacts @@ -123,6 +124,9 @@ public class SearchFragment extends PhoneNumberPickerFragment { int totalItemCount) { } }); + if (mActivityOnTouchListener != null) { + listView.setOnTouchListener(mActivityOnTouchListener); + } updatePosition(false /* animate */); } @@ -298,4 +302,8 @@ public class SearchFragment extends PhoneNumberPickerFragment { getAdapter().setQueryString(null); } } + + public void setOnTouchListener(View.OnTouchListener onTouchListener) { + mActivityOnTouchListener = onTouchListener; + } } diff --git a/src/com/android/dialer/voicemail/VoicemailPlaybackPresenter.java b/src/com/android/dialer/voicemail/VoicemailPlaybackPresenter.java index d47e9e213..60425e484 100644 --- a/src/com/android/dialer/voicemail/VoicemailPlaybackPresenter.java +++ b/src/com/android/dialer/voicemail/VoicemailPlaybackPresenter.java @@ -121,6 +121,7 @@ public class VoicemailPlaybackPresenter */ private final AtomicInteger mDuration = new AtomicInteger(0); + private Activity mActivity; private Context mContext; private PlaybackView mView; private static MediaPlayer mMediaPlayer; @@ -147,11 +148,14 @@ public class VoicemailPlaybackPresenter private PowerManager.WakeLock mProximityWakeLock; private AudioManager mAudioManager; - public VoicemailPlaybackPresenter(Context context, Bundle savedInstanceState) { - mContext = context; + public VoicemailPlaybackPresenter(Activity activity, Bundle savedInstanceState) { + mActivity = activity; + mContext = activity; mAsyncTaskExecutor = AsyncTaskExecutors.createAsyncTaskExecutor(); mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); + mActivity.setVolumeControlStream(VoicemailPlaybackPresenter.PLAYBACK_STREAM); + if (savedInstanceState != null) { // Restores playback state when activity is recreated, such as after rotation. mVoicemailUri = (Uri) savedInstanceState.getParcelable(VOICEMAIL_URI_KEY); @@ -178,6 +182,18 @@ public class VoicemailPlaybackPresenter mMediaPlayer.setOnCompletionListener(this); } + public void reset() { + pausePlayback(); + + mView = null; + mVoicemailUri = null; + + mIsPrepared = false; + mIsPlaying = false; + mPosition = 0; + mDuration.set(0); + } + /** * Specify the view which this presenter controls and the voicemail for playback. */ @@ -204,7 +220,6 @@ public class VoicemailPlaybackPresenter mView.onSpeakerphoneOn(false); checkForContent(); - } } @@ -341,7 +356,9 @@ public class VoicemailPlaybackPresenter public void run() { if (mIsWaitingForResult.getAndSet(false)) { mContext.getContentResolver().unregisterContentObserver(this); - mView.setFetchContentTimeout(); + if (mView != null) { + mView.setFetchContentTimeout(); + } } } @@ -384,7 +401,11 @@ public class VoicemailPlaybackPresenter * and it will call {@link #onError()} otherwise. */ private void prepareToPlayContent() { + if (mView == null) { + return; + } mIsPrepared = false; + mView.setIsBuffering(); try { @@ -402,7 +423,11 @@ public class VoicemailPlaybackPresenter */ @Override public void onPrepared(MediaPlayer mp) { + if (mView == null) { + return; + } mIsPrepared = true; + mDuration.set(mMediaPlayer.getDuration()); mView.enableUiElements(); @@ -421,7 +446,7 @@ public class VoicemailPlaybackPresenter */ @Override public boolean onError(MediaPlayer mp, int what, int extra) { - handleError(new IllegalStateException("MediaPlayer error listener invoked")); + handleError(new IllegalStateException("MediaPlayer error listener invoked: " + extra)); return true; } diff --git a/src/com/android/dialer/widget/SearchEditTextLayout.java b/src/com/android/dialer/widget/SearchEditTextLayout.java index f1fa9868a..544749f33 100644 --- a/src/com/android/dialer/widget/SearchEditTextLayout.java +++ b/src/com/android/dialer/widget/SearchEditTextLayout.java @@ -61,13 +61,14 @@ public class SearchEditTextLayout extends FrameLayout { private ValueAnimator mAnimator; - private OnBackButtonClickedListener mOnBackButtonClickedListener; + private Callback mCallback; /** * Listener for the back button next to the search view being pressed */ - public interface OnBackButtonClickedListener { + public interface Callback { public void onBackButtonClicked(); + public void onSearchViewClicked(); } public SearchEditTextLayout(Context context, AttributeSet attrs) { @@ -78,8 +79,8 @@ public class SearchEditTextLayout extends FrameLayout { mPreImeKeyListener = listener; } - public void setOnBackButtonClickedListener(OnBackButtonClickedListener listener) { - mOnBackButtonClickedListener = listener; + public void setCallback(Callback listener) { + mCallback = listener; } @Override @@ -126,6 +127,15 @@ public class SearchEditTextLayout extends FrameLayout { } }); + mSearchView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (mCallback != null) { + mCallback.onSearchViewClicked(); + } + } + }); + mSearchView.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { @@ -151,8 +161,8 @@ public class SearchEditTextLayout extends FrameLayout { findViewById(R.id.search_back_button).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { - if (mOnBackButtonClickedListener != null) { - mOnBackButtonClickedListener.onBackButtonClicked(); + if (mCallback != null) { + mCallback.onBackButtonClicked(); } } }); |