aboutsummaryrefslogtreecommitdiff
path: root/src/com/android/tv/menu/BaseCardView.java
diff options
context:
space:
mode:
authorAdrian Roos <roosa@google.com>2017-05-05 20:16:08 +0000
committerAdrian Roos <roosa@google.com>2017-05-05 20:16:08 +0000
commit721bd0da688cd552737fbb753a00597f95103b95 (patch)
tree36da88c2d4365be7ee0a4dd0c732b9399d1c55ad /src/com/android/tv/menu/BaseCardView.java
parent3dfa929b24f38ac7836450176d88ceab41dc6ac5 (diff)
downloadTV-721bd0da688cd552737fbb753a00597f95103b95.tar.gz
Revert "Sync to ub-tv-dev at f0024d79653da8c8999a91f995431a645a6ff4a2"
This reverts commit 3dfa929b24f38ac7836450176d88ceab41dc6ac5. Change-Id: I1c76f626d966b8d4793a19677a8840ed0424d3a7
Diffstat (limited to 'src/com/android/tv/menu/BaseCardView.java')
-rw-r--r--src/com/android/tv/menu/BaseCardView.java50
1 files changed, 19 insertions, 31 deletions
diff --git a/src/com/android/tv/menu/BaseCardView.java b/src/com/android/tv/menu/BaseCardView.java
index fa74ce3e..c6a34a5d 100644
--- a/src/com/android/tv/menu/BaseCardView.java
+++ b/src/com/android/tv/menu/BaseCardView.java
@@ -57,7 +57,6 @@ 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);
@@ -104,9 +103,23 @@ 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);
}
@@ -115,7 +128,6 @@ 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 {
@@ -126,7 +138,6 @@ 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 {
@@ -145,7 +156,6 @@ public abstract class BaseCardView<T> extends LinearLayout implements ItemListRo
if (mTextView != null) {
mTextView.setText(resId);
}
- onTextViewUpdated();
}
/**
@@ -158,22 +168,6 @@ 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);
}
/**
@@ -215,18 +209,12 @@ public abstract class BaseCardView<T> extends LinearLayout implements ItemListRo
setScaleX(scale);
setScaleY(scale);
setTranslationZ(mFocusTranslationZ * animatedValue);
- if (mTextView != null && mTextViewFocused != null) {
+ if (mExtendViewOnFocus) {
ViewGroup.LayoutParams params = mTextView.getLayoutParams();
- int height = mExtendViewOnFocus ? Math.round(mTextViewHeight
- + (mExtendedTextViewHeight - mTextViewHeight) * animatedValue)
- : (int) mTextViewHeight;
- if (height != params.height) {
- params.height = height;
- setTextViewLayoutParams(params);
- }
- if (mExtendViewOnFocus) {
- setTextViewFocusedAlpha(animatedValue);
- }
+ params.height = Math.round(mTextViewHeight
+ + (mExtendedTextViewHeight - mTextViewHeight) * animatedValue);
+ setTextViewLayoutParams(params);
+ setTextViewFocusedAlpha(animatedValue);
}
}