aboutsummaryrefslogtreecommitdiff
path: root/src/com/android/tv/menu/BaseCardView.java
diff options
context:
space:
mode:
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);
}
}