diff options
author | Nick Chalko <nchalko@google.com> | 2017-05-04 14:37:34 -0700 |
---|---|---|
committer | Nick Chalko <nchalko@google.com> | 2017-05-05 06:18:44 -0700 |
commit | 3dfa929b24f38ac7836450176d88ceab41dc6ac5 (patch) | |
tree | 675a324760c582713e2e0080775ea17357f75b65 /src/com/android/tv/menu/BaseCardView.java | |
parent | fddf3fd148c1fc94c48ee5684e47dbb56512e758 (diff) | |
download | TV-3dfa929b24f38ac7836450176d88ceab41dc6ac5.tar.gz |
Sync to ub-tv-dev at f0024d79653da8c8999a91f995431a645a6ff4a2
Change-Id: I4199ec04cacb4a78be58b85302a39d917658dc28
Diffstat (limited to 'src/com/android/tv/menu/BaseCardView.java')
-rw-r--r-- | src/com/android/tv/menu/BaseCardView.java | 50 |
1 files changed, 31 insertions, 19 deletions
diff --git a/src/com/android/tv/menu/BaseCardView.java b/src/com/android/tv/menu/BaseCardView.java index c6a34a5d..fa74ce3e 100644 --- a/src/com/android/tv/menu/BaseCardView.java +++ b/src/com/android/tv/menu/BaseCardView.java @@ -57,6 +57,7 @@ public abstract class BaseCardView<T> extends LinearLayout implements ItemListRo private TextView mTextViewFocused; private final int mCardImageWidth; private final float mCardHeight; + private boolean mSelected; public BaseCardView(Context context) { this(context, null); @@ -103,23 +104,9 @@ public abstract class BaseCardView<T> extends LinearLayout implements ItemListRo /** * Called when the view is displayed. - * - * Before onBind is called, this view's text should be set to determine if it'll be extended - * or not in focus state. */ @Override public void onBind(T item, boolean selected) { - if (mTextView != null && mTextViewFocused != null) { - mTextViewFocused.measure( - MeasureSpec.makeMeasureSpec(mCardImageWidth, MeasureSpec.EXACTLY), - MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); - mExtendViewOnFocus = mTextViewFocused.getLineCount() > 1; - if (mExtendViewOnFocus) { - setTextViewFocusedAlpha(selected ? 1f : 0f); - } else { - setTextViewFocusedAlpha(1f); - } - } setFocusAnimatedValue(selected ? SCALE_FACTOR_1F : SCALE_FACTOR_0F); } @@ -128,6 +115,7 @@ public abstract class BaseCardView<T> extends LinearLayout implements ItemListRo @Override public void onSelected() { + mSelected = true; if (isAttachedToWindow() && getVisibility() == View.VISIBLE) { startFocusAnimation(SCALE_FACTOR_1F); } else { @@ -138,6 +126,7 @@ public abstract class BaseCardView<T> extends LinearLayout implements ItemListRo @Override public void onDeselected() { + mSelected = false; if (isAttachedToWindow() && getVisibility() == View.VISIBLE) { startFocusAnimation(SCALE_FACTOR_0F); } else { @@ -156,6 +145,7 @@ public abstract class BaseCardView<T> extends LinearLayout implements ItemListRo if (mTextView != null) { mTextView.setText(resId); } + onTextViewUpdated(); } /** @@ -168,6 +158,22 @@ public abstract class BaseCardView<T> extends LinearLayout implements ItemListRo if (mTextView != null) { mTextView.setText(text); } + onTextViewUpdated(); + } + + private void onTextViewUpdated() { + if (mTextView != null && mTextViewFocused != null) { + mTextViewFocused.measure( + MeasureSpec.makeMeasureSpec(mCardImageWidth, MeasureSpec.EXACTLY), + MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); + mExtendViewOnFocus = mTextViewFocused.getLineCount() > 1; + if (mExtendViewOnFocus) { + setTextViewFocusedAlpha(mSelected ? 1f : 0f); + } else { + setTextViewFocusedAlpha(1f); + } + } + setFocusAnimatedValue(mSelected ? SCALE_FACTOR_1F : SCALE_FACTOR_0F); } /** @@ -209,12 +215,18 @@ public abstract class BaseCardView<T> extends LinearLayout implements ItemListRo setScaleX(scale); setScaleY(scale); setTranslationZ(mFocusTranslationZ * animatedValue); - if (mExtendViewOnFocus) { + if (mTextView != null && mTextViewFocused != null) { ViewGroup.LayoutParams params = mTextView.getLayoutParams(); - params.height = Math.round(mTextViewHeight - + (mExtendedTextViewHeight - mTextViewHeight) * animatedValue); - setTextViewLayoutParams(params); - setTextViewFocusedAlpha(animatedValue); + int height = mExtendViewOnFocus ? Math.round(mTextViewHeight + + (mExtendedTextViewHeight - mTextViewHeight) * animatedValue) + : (int) mTextViewHeight; + if (height != params.height) { + params.height = height; + setTextViewLayoutParams(params); + } + if (mExtendViewOnFocus) { + setTextViewFocusedAlpha(animatedValue); + } } } |