diff options
Diffstat (limited to 'java/com/android/dialer/app/widget')
-rw-r--r-- | java/com/android/dialer/app/widget/ActionBarController.java | 107 | ||||
-rw-r--r-- | java/com/android/dialer/app/widget/SearchEditTextLayout.java | 188 |
2 files changed, 147 insertions, 148 deletions
diff --git a/java/com/android/dialer/app/widget/ActionBarController.java b/java/com/android/dialer/app/widget/ActionBarController.java index 3daa0e2d4..8ab57bcfb 100644 --- a/java/com/android/dialer/app/widget/ActionBarController.java +++ b/java/com/android/dialer/app/widget/ActionBarController.java @@ -31,12 +31,12 @@ public class ActionBarController { private static final String KEY_IS_FADED_OUT = "key_actionbar_is_faded_out"; private static final String KEY_IS_EXPANDED = "key_actionbar_is_expanded"; - private ActivityUi mActivityUi; - private SearchEditTextLayout mSearchBox; + private ActivityUi activityUi; + private SearchEditTextLayout searchBox; - private boolean mIsActionBarSlidUp; + private boolean isActionBarSlidUp; - private final AnimationCallback mFadeOutCallback = + private final AnimationCallback fadeOutCallback = new AnimationCallback() { @Override public void onAnimationEnd() { @@ -49,24 +49,23 @@ public class ActionBarController { } }; - private ValueAnimator mAnimator; + private ValueAnimator animator; public ActionBarController(ActivityUi activityUi, SearchEditTextLayout searchBox) { - mActivityUi = activityUi; - mSearchBox = searchBox; + this.activityUi = activityUi; + this.searchBox = searchBox; } /** @return Whether or not the action bar is currently showing (both slid down and visible) */ public boolean isActionBarShowing() { - return !mIsActionBarSlidUp && !mSearchBox.isFadedOut(); + return !isActionBarSlidUp && !searchBox.isFadedOut(); } /** Called when the user has tapped on the collapsed search box, to start a new search query. */ public void onSearchBoxTapped() { - LogUtil.d( - "ActionBarController.onSearchBoxTapped", "isInSearchUi " + mActivityUi.isInSearchUi()); - if (!mActivityUi.isInSearchUi()) { - mSearchBox.expand(true /* animate */, true /* requestFocus */); + LogUtil.d("ActionBarController.onSearchBoxTapped", "isInSearchUi " + activityUi.isInSearchUi()); + if (!activityUi.isInSearchUi()) { + searchBox.expand(true /* animate */, true /* requestFocus */); } } @@ -75,13 +74,13 @@ public class ActionBarController { LogUtil.d( "ActionBarController.onSearchUIExited", "isExpanded: %b, isFadedOut %b", - mSearchBox.isExpanded(), - mSearchBox.isFadedOut()); - if (mSearchBox.isExpanded()) { - mSearchBox.collapse(true /* animate */); + searchBox.isExpanded(), + searchBox.isFadedOut()); + if (searchBox.isExpanded()) { + searchBox.collapse(true /* animate */); } - if (mSearchBox.isFadedOut()) { - mSearchBox.fadeIn(); + if (searchBox.isFadedOut()) { + searchBox.fadeIn(); } slideActionBar(false /* slideUp */, false /* animate */); @@ -95,16 +94,16 @@ public class ActionBarController { LogUtil.d( "ActionBarController.onDialpadDown", "isInSearchUi: %b, hasSearchQuery: %b, isFadedOut: %b, isExpanded: %b", - mActivityUi.isInSearchUi(), - mActivityUi.hasSearchQuery(), - mSearchBox.isFadedOut(), - mSearchBox.isExpanded()); - if (mActivityUi.isInSearchUi()) { - if (mSearchBox.isFadedOut()) { - mSearchBox.setVisible(true); + activityUi.isInSearchUi(), + activityUi.hasSearchQuery(), + searchBox.isFadedOut(), + searchBox.isExpanded()); + if (activityUi.isInSearchUi()) { + if (searchBox.isFadedOut()) { + searchBox.setVisible(true); } - if (!mSearchBox.isExpanded()) { - mSearchBox.expand(false /* animate */, false /* requestFocus */); + if (!searchBox.isExpanded()) { + searchBox.expand(false /* animate */, false /* requestFocus */); } slideActionBar(false /* slideUp */, true /* animate */); } @@ -115,71 +114,71 @@ public class ActionBarController { * state changes have actually occurred. */ public void onDialpadUp() { - LogUtil.d("ActionBarController.onDialpadUp", "isInSearchUi " + mActivityUi.isInSearchUi()); - if (mActivityUi.isInSearchUi()) { + LogUtil.d("ActionBarController.onDialpadUp", "isInSearchUi " + activityUi.isInSearchUi()); + if (activityUi.isInSearchUi()) { slideActionBar(true /* slideUp */, true /* animate */); } else { // From the lists fragment - mSearchBox.fadeOut(mFadeOutCallback); + searchBox.fadeOut(fadeOutCallback); } } public void slideActionBar(boolean slideUp, boolean animate) { LogUtil.d("ActionBarController.slidingActionBar", "up: %b, animate: %b", slideUp, animate); - if (mAnimator != null && mAnimator.isRunning()) { - mAnimator.cancel(); - mAnimator.removeAllUpdateListeners(); + if (animator != null && animator.isRunning()) { + animator.cancel(); + animator.removeAllUpdateListeners(); } if (animate) { - mAnimator = slideUp ? ValueAnimator.ofFloat(0, 1) : ValueAnimator.ofFloat(1, 0); - mAnimator.addUpdateListener( + animator = slideUp ? ValueAnimator.ofFloat(0, 1) : ValueAnimator.ofFloat(1, 0); + animator.addUpdateListener( animation -> { final float value = (float) animation.getAnimatedValue(); - setHideOffset((int) (mActivityUi.getActionBarHeight() * value)); + setHideOffset((int) (activityUi.getActionBarHeight() * value)); }); - mAnimator.start(); + animator.start(); } else { - setHideOffset(slideUp ? mActivityUi.getActionBarHeight() : 0); + setHideOffset(slideUp ? activityUi.getActionBarHeight() : 0); } - mIsActionBarSlidUp = slideUp; + isActionBarSlidUp = slideUp; } public void setAlpha(float alphaValue) { - mSearchBox.animate().alpha(alphaValue).start(); + searchBox.animate().alpha(alphaValue).start(); } private void setHideOffset(int offset) { - mActivityUi.setActionBarHideOffset(offset); + activityUi.setActionBarHideOffset(offset); } /** Saves the current state of the action bar into a provided {@link Bundle} */ public void saveInstanceState(Bundle outState) { - outState.putBoolean(KEY_IS_SLID_UP, mIsActionBarSlidUp); - outState.putBoolean(KEY_IS_FADED_OUT, mSearchBox.isFadedOut()); - outState.putBoolean(KEY_IS_EXPANDED, mSearchBox.isExpanded()); + outState.putBoolean(KEY_IS_SLID_UP, isActionBarSlidUp); + outState.putBoolean(KEY_IS_FADED_OUT, searchBox.isFadedOut()); + outState.putBoolean(KEY_IS_EXPANDED, searchBox.isExpanded()); } /** Restores the action bar state from a provided {@link Bundle}. */ public void restoreInstanceState(Bundle inState) { - mIsActionBarSlidUp = inState.getBoolean(KEY_IS_SLID_UP); + isActionBarSlidUp = inState.getBoolean(KEY_IS_SLID_UP); final boolean isSearchBoxFadedOut = inState.getBoolean(KEY_IS_FADED_OUT); if (isSearchBoxFadedOut) { - if (!mSearchBox.isFadedOut()) { - mSearchBox.setVisible(false); + if (!searchBox.isFadedOut()) { + searchBox.setVisible(false); } - } else if (mSearchBox.isFadedOut()) { - mSearchBox.setVisible(true); + } else if (searchBox.isFadedOut()) { + searchBox.setVisible(true); } final boolean isSearchBoxExpanded = inState.getBoolean(KEY_IS_EXPANDED); if (isSearchBoxExpanded) { - if (!mSearchBox.isExpanded()) { - mSearchBox.expand(false, false); + if (!searchBox.isExpanded()) { + searchBox.expand(false, false); } - } else if (mSearchBox.isExpanded()) { - mSearchBox.collapse(false); + } else if (searchBox.isExpanded()) { + searchBox.collapse(false); } } @@ -188,7 +187,7 @@ public class ActionBarController { * laid out and actually has a height. */ public void restoreActionBarOffset() { - slideActionBar(mIsActionBarSlidUp /* slideUp */, false /* animate */); + slideActionBar(isActionBarSlidUp /* slideUp */, false /* animate */); } public interface ActivityUi { diff --git a/java/com/android/dialer/app/widget/SearchEditTextLayout.java b/java/com/android/dialer/app/widget/SearchEditTextLayout.java index ebd62080b..40189a873 100644 --- a/java/com/android/dialer/app/widget/SearchEditTextLayout.java +++ b/java/com/android/dialer/app/widget/SearchEditTextLayout.java @@ -36,83 +36,83 @@ public class SearchEditTextLayout extends FrameLayout { private static final float EXPAND_MARGIN_FRACTION_START = 0.8f; private static final int ANIMATION_DURATION = 200; /* Subclass-visible for testing */ - protected boolean mIsExpanded = false; - protected boolean mIsFadedOut = false; - private OnKeyListener mPreImeKeyListener; - private int mTopMargin; - private int mBottomMargin; - private int mLeftMargin; - private int mRightMargin; - private float mCollapsedElevation; - private View mCollapsed; - private View mExpanded; - private EditText mSearchView; - private View mSearchIcon; - private View mCollapsedSearchBox; - private View mVoiceSearchButtonView; - private View mOverflowButtonView; - private View mClearButtonView; - - private ValueAnimator mAnimator; - - private Callback mCallback; - - private boolean mVoiceSearchEnabled; + protected boolean isExpanded = false; + protected boolean isFadedOut = false; + private OnKeyListener preImeKeyListener; + private int topMargin; + private int bottomMargin; + private int leftMargin; + private int rightMargin; + private float collapsedElevation; + private View collapsed; + private View expanded; + private EditText searchView; + private View searchIcon; + private View collapsedSearchBox; + private View voiceSearchButtonView; + private View overflowButtonView; + private View clearButtonView; + + private ValueAnimator animator; + + private Callback callback; + + private boolean voiceSearchEnabled; public SearchEditTextLayout(Context context, AttributeSet attrs) { super(context, attrs); } public void setPreImeKeyListener(OnKeyListener listener) { - mPreImeKeyListener = listener; + preImeKeyListener = listener; } public void setCallback(Callback listener) { - mCallback = listener; + callback = listener; } public void setVoiceSearchEnabled(boolean enabled) { - mVoiceSearchEnabled = enabled; - updateVisibility(mIsExpanded); + voiceSearchEnabled = enabled; + updateVisibility(isExpanded); } @Override protected void onFinishInflate() { MarginLayoutParams params = (MarginLayoutParams) getLayoutParams(); - mTopMargin = params.topMargin; - mBottomMargin = params.bottomMargin; - mLeftMargin = params.leftMargin; - mRightMargin = params.rightMargin; + topMargin = params.topMargin; + bottomMargin = params.bottomMargin; + leftMargin = params.leftMargin; + rightMargin = params.rightMargin; - mCollapsedElevation = getElevation(); + collapsedElevation = getElevation(); - mCollapsed = findViewById(R.id.search_box_collapsed); - mExpanded = findViewById(R.id.search_box_expanded); - mSearchView = (EditText) mExpanded.findViewById(R.id.search_view); + collapsed = findViewById(R.id.search_box_collapsed); + expanded = findViewById(R.id.search_box_expanded); + searchView = (EditText) expanded.findViewById(R.id.search_view); - mSearchIcon = findViewById(R.id.search_magnifying_glass); - mCollapsedSearchBox = findViewById(R.id.search_box_start_search); - mVoiceSearchButtonView = findViewById(R.id.voice_search_button); - mOverflowButtonView = findViewById(R.id.dialtacts_options_menu_button); - mClearButtonView = findViewById(R.id.search_close_button); + searchIcon = findViewById(R.id.search_magnifying_glass); + collapsedSearchBox = findViewById(R.id.search_box_start_search); + voiceSearchButtonView = findViewById(R.id.voice_search_button); + overflowButtonView = findViewById(R.id.dialtacts_options_menu_button); + clearButtonView = findViewById(R.id.search_close_button); // Convert a long click into a click to expand the search box. Touch events are also // forwarded to the searchView. This accelerates the long-press scenario for copy/paste. - mCollapsed.setOnLongClickListener( + collapsed.setOnLongClickListener( new OnLongClickListener() { @Override public boolean onLongClick(View view) { - mCollapsed.performClick(); + collapsed.performClick(); return false; } }); - mCollapsed.setOnTouchListener( + collapsed.setOnTouchListener( (v, event) -> { - mSearchView.onTouchEvent(event); + searchView.onTouchEvent(event); return false; }); - mSearchView.setOnFocusChangeListener( + searchView.setOnFocusChangeListener( new OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { @@ -124,24 +124,24 @@ public class SearchEditTextLayout extends FrameLayout { } }); - mSearchView.setOnClickListener( + searchView.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { - if (mCallback != null) { - mCallback.onSearchViewClicked(); + if (callback != null) { + callback.onSearchViewClicked(); } } }); - mSearchView.addTextChangedListener( + searchView.addTextChangedListener( new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) {} @Override public void onTextChanged(CharSequence s, int start, int before, int count) { - mClearButtonView.setVisibility(TextUtils.isEmpty(s) ? View.GONE : View.VISIBLE); + clearButtonView.setVisibility(TextUtils.isEmpty(s) ? View.GONE : View.VISIBLE); } @Override @@ -153,7 +153,7 @@ public class SearchEditTextLayout extends FrameLayout { new OnClickListener() { @Override public void onClick(View v) { - mSearchView.setText(null); + searchView.setText(null); } }); @@ -162,8 +162,8 @@ public class SearchEditTextLayout extends FrameLayout { new OnClickListener() { @Override public void onClick(View v) { - if (mCallback != null) { - mCallback.onBackButtonClicked(); + if (callback != null) { + callback.onBackButtonClicked(); } } }); @@ -173,8 +173,8 @@ public class SearchEditTextLayout extends FrameLayout { @Override public boolean dispatchKeyEventPreIme(KeyEvent event) { - if (mPreImeKeyListener != null) { - if (mPreImeKeyListener.onKey(this, event.getKeyCode(), event)) { + if (preImeKeyListener != null) { + if (preImeKeyListener.onKey(this, event.getKeyCode(), event)) { return true; } } @@ -187,28 +187,28 @@ public class SearchEditTextLayout extends FrameLayout { public void fadeOut(AnimUtils.AnimationCallback callback) { AnimUtils.fadeOut(this, ANIMATION_DURATION, callback); - mIsFadedOut = true; + isFadedOut = true; } public void fadeIn() { AnimUtils.fadeIn(this, ANIMATION_DURATION); - mIsFadedOut = false; + isFadedOut = false; } public void fadeIn(AnimUtils.AnimationCallback callback) { AnimUtils.fadeIn(this, ANIMATION_DURATION, AnimUtils.NO_DELAY, callback); - mIsFadedOut = false; + isFadedOut = false; } public void setVisible(boolean visible) { if (visible) { setAlpha(1); setVisibility(View.VISIBLE); - mIsFadedOut = false; + isFadedOut = false; } else { setAlpha(0); setVisibility(View.GONE); - mIsFadedOut = true; + isFadedOut = true; } } @@ -216,15 +216,15 @@ public class SearchEditTextLayout extends FrameLayout { updateVisibility(true /* isExpand */); if (animate) { - AnimUtils.crossFadeViews(mExpanded, mCollapsed, ANIMATION_DURATION); - mAnimator = ValueAnimator.ofFloat(EXPAND_MARGIN_FRACTION_START, 0f); + AnimUtils.crossFadeViews(expanded, collapsed, ANIMATION_DURATION); + animator = ValueAnimator.ofFloat(EXPAND_MARGIN_FRACTION_START, 0f); setMargins(EXPAND_MARGIN_FRACTION_START); prepareAnimator(); } else { - mExpanded.setVisibility(View.VISIBLE); - mExpanded.setAlpha(1); + expanded.setVisibility(View.VISIBLE); + expanded.setAlpha(1); setMargins(0f); - mCollapsed.setVisibility(View.GONE); + collapsed.setVisibility(View.GONE); } // Set 9-patch background. This owns the padding, so we need to restore the original values. @@ -237,27 +237,27 @@ public class SearchEditTextLayout extends FrameLayout { setPaddingRelative(paddingStart, paddingTop, paddingEnd, paddingBottom); if (requestFocus) { - mSearchView.requestFocus(); + searchView.requestFocus(); } - mIsExpanded = true; + isExpanded = true; } public void collapse(boolean animate) { updateVisibility(false /* isExpand */); if (animate) { - AnimUtils.crossFadeViews(mCollapsed, mExpanded, ANIMATION_DURATION); - mAnimator = ValueAnimator.ofFloat(0f, 1f); + AnimUtils.crossFadeViews(collapsed, expanded, ANIMATION_DURATION); + animator = ValueAnimator.ofFloat(0f, 1f); prepareAnimator(); } else { - mCollapsed.setVisibility(View.VISIBLE); - mCollapsed.setAlpha(1); + collapsed.setVisibility(View.VISIBLE); + collapsed.setAlpha(1); setMargins(1f); - mExpanded.setVisibility(View.GONE); + expanded.setVisibility(View.GONE); } - mIsExpanded = false; - setElevation(mCollapsedElevation); + isExpanded = false; + setElevation(collapsedElevation); setBackgroundResource(R.drawable.rounded_corner); } @@ -271,30 +271,30 @@ public class SearchEditTextLayout extends FrameLayout { int collapsedViewVisibility = isExpand ? View.GONE : View.VISIBLE; int expandedViewVisibility = isExpand ? View.VISIBLE : View.GONE; - mSearchIcon.setVisibility(collapsedViewVisibility); - mCollapsedSearchBox.setVisibility(collapsedViewVisibility); - if (mVoiceSearchEnabled) { - mVoiceSearchButtonView.setVisibility(collapsedViewVisibility); + searchIcon.setVisibility(collapsedViewVisibility); + collapsedSearchBox.setVisibility(collapsedViewVisibility); + if (voiceSearchEnabled) { + voiceSearchButtonView.setVisibility(collapsedViewVisibility); } else { - mVoiceSearchButtonView.setVisibility(View.GONE); + voiceSearchButtonView.setVisibility(View.GONE); } - mOverflowButtonView.setVisibility(collapsedViewVisibility); + overflowButtonView.setVisibility(collapsedViewVisibility); // TODO: Prevents keyboard from jumping up in landscape mode after exiting the // SearchFragment when the query string is empty. More elegant fix? - //mExpandedSearchBox.setVisibility(expandedViewVisibility); - if (TextUtils.isEmpty(mSearchView.getText())) { - mClearButtonView.setVisibility(View.GONE); + // mExpandedSearchBox.setVisibility(expandedViewVisibility); + if (TextUtils.isEmpty(searchView.getText())) { + clearButtonView.setVisibility(View.GONE); } else { - mClearButtonView.setVisibility(expandedViewVisibility); + clearButtonView.setVisibility(expandedViewVisibility); } } private void prepareAnimator() { - if (mAnimator != null) { - mAnimator.cancel(); + if (animator != null) { + animator.cancel(); } - mAnimator.addUpdateListener( + animator.addUpdateListener( new AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { @@ -303,16 +303,16 @@ public class SearchEditTextLayout extends FrameLayout { } }); - mAnimator.setDuration(ANIMATION_DURATION); - mAnimator.start(); + animator.setDuration(ANIMATION_DURATION); + animator.start(); } public boolean isExpanded() { - return mIsExpanded; + return isExpanded; } public boolean isFadedOut() { - return mIsFadedOut; + return isFadedOut; } /** @@ -322,10 +322,10 @@ public class SearchEditTextLayout extends FrameLayout { */ private void setMargins(float fraction) { MarginLayoutParams params = (MarginLayoutParams) getLayoutParams(); - params.topMargin = (int) (mTopMargin * fraction); - params.bottomMargin = (int) (mBottomMargin * fraction); - params.leftMargin = (int) (mLeftMargin * fraction); - params.rightMargin = (int) (mRightMargin * fraction); + params.topMargin = (int) (topMargin * fraction); + params.bottomMargin = (int) (bottomMargin * fraction); + params.leftMargin = (int) (leftMargin * fraction); + params.rightMargin = (int) (rightMargin * fraction); requestLayout(); } |