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.java132
1 files changed, 63 insertions, 69 deletions
diff --git a/src/com/android/tv/menu/BaseCardView.java b/src/com/android/tv/menu/BaseCardView.java
index 4c5e6c78..3a94ebbf 100644
--- a/src/com/android/tv/menu/BaseCardView.java
+++ b/src/com/android/tv/menu/BaseCardView.java
@@ -29,12 +29,9 @@ import android.view.ViewGroup;
import android.view.ViewOutlineProvider;
import android.widget.LinearLayout;
import android.widget.TextView;
-
import com.android.tv.R;
-/**
- * A base class to render a card.
- */
+/** A base class to render a card. */
public abstract class BaseCardView<T> extends LinearLayout implements ItemListRowView.CardView<T> {
private static final float SCALE_FACTOR_0F = 0f;
private static final float SCALE_FACTOR_1F = 1f;
@@ -49,10 +46,8 @@ public abstract class BaseCardView<T> extends LinearLayout implements ItemListRo
private final float mExtendedCardHeight;
private final float mTextViewHeight;
private final float mExtendedTextViewHeight;
- @Nullable
- private TextView mTextView;
- @Nullable
- private TextView mTextViewFocused;
+ @Nullable private TextView mTextView;
+ @Nullable private TextView mTextViewFocused;
private final int mCardImageWidth;
private final float mCardHeight;
private boolean mSelected;
@@ -74,27 +69,32 @@ public abstract class BaseCardView<T> extends LinearLayout implements ItemListRo
setClipToOutline(true);
mFocusAnimDuration = getResources().getInteger(R.integer.menu_focus_anim_duration);
- mFocusTranslationZ = getResources().getDimension(R.dimen.channel_card_elevation_focused)
- - getResources().getDimension(R.dimen.card_elevation_normal);
- mVerticalCardMargin = 2 * (
- getResources().getDimensionPixelOffset(R.dimen.menu_list_padding_top)
- + getResources().getDimensionPixelOffset(R.dimen.menu_list_margin_top));
+ mFocusTranslationZ =
+ getResources().getDimension(R.dimen.channel_card_elevation_focused)
+ - getResources().getDimension(R.dimen.card_elevation_normal);
+ mVerticalCardMargin =
+ 2
+ * (getResources().getDimensionPixelOffset(R.dimen.menu_list_padding_top)
+ + getResources()
+ .getDimensionPixelOffset(R.dimen.menu_list_margin_top));
// Ensure the same elevation and focus animation for all subclasses.
setElevation(getResources().getDimension(R.dimen.card_elevation_normal));
mCardCornerRadius = getResources().getDimensionPixelSize(R.dimen.channel_card_round_radius);
- setOutlineProvider(new ViewOutlineProvider() {
- @Override
- public void getOutline(View view, Outline outline) {
- outline.setRoundRect(0, 0, view.getWidth(), view.getHeight(), mCardCornerRadius);
- }
- });
+ setOutlineProvider(
+ new ViewOutlineProvider() {
+ @Override
+ public void getOutline(View view, Outline outline) {
+ outline.setRoundRect(
+ 0, 0, view.getWidth(), view.getHeight(), mCardCornerRadius);
+ }
+ });
mCardImageWidth = getResources().getDimensionPixelSize(R.dimen.card_image_layout_width);
mCardHeight = getResources().getDimensionPixelSize(R.dimen.card_layout_height);
- mExtendedCardHeight = getResources().getDimensionPixelSize(
- R.dimen.card_layout_height_extended);
+ mExtendedCardHeight =
+ getResources().getDimensionPixelSize(R.dimen.card_layout_height_extended);
mTextViewHeight = getResources().getDimensionPixelSize(R.dimen.card_meta_layout_height);
- mExtendedTextViewHeight = getResources().getDimensionPixelOffset(
- R.dimen.card_meta_layout_height_extended);
+ mExtendedTextViewHeight =
+ getResources().getDimensionPixelOffset(R.dimen.card_meta_layout_height_extended);
}
@Override
@@ -104,16 +104,14 @@ public abstract class BaseCardView<T> extends LinearLayout implements ItemListRo
mTextViewFocused = (TextView) findViewById(R.id.card_text_focused);
}
- /**
- * Called when the view is displayed.
- */
+ /** Called when the view is displayed. */
@Override
public void onBind(T item, boolean selected) {
setFocusAnimatedValue(selected ? SCALE_FACTOR_1F : SCALE_FACTOR_0F);
}
@Override
- public void onRecycled() { }
+ public void onRecycled() {}
@Override
public void onSelected() {
@@ -137,9 +135,7 @@ public abstract class BaseCardView<T> extends LinearLayout implements ItemListRo
}
}
- /**
- * Sets text of this card view.
- */
+ /** Sets text of this card view. */
public void setText(int resId) {
if (mTextResId != resId) {
mTextResId = resId;
@@ -155,9 +151,7 @@ public abstract class BaseCardView<T> extends LinearLayout implements ItemListRo
}
}
- /**
- * Sets text of this card view.
- */
+ /** Sets text of this card view. */
public void setText(String text) {
if (!TextUtils.equals(text, mTextString)) {
mTextString = text;
@@ -176,8 +170,8 @@ public abstract class BaseCardView<T> extends LinearLayout implements ItemListRo
private void onTextViewUpdated() {
if (mTextView != null && mTextViewFocused != null) {
mTextViewFocused.measure(
- MeasureSpec.makeMeasureSpec(mCardImageWidth, MeasureSpec.EXACTLY),
- MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
+ MeasureSpec.makeMeasureSpec(mCardImageWidth, MeasureSpec.EXACTLY),
+ MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
mExtendViewOnFocus = mTextViewFocused.getLineCount() > 1;
if (mExtendViewOnFocus) {
setTextViewFocusedAlpha(mSelected ? 1f : 0f);
@@ -188,9 +182,7 @@ public abstract class BaseCardView<T> extends LinearLayout implements ItemListRo
setFocusAnimatedValue(mSelected ? SCALE_FACTOR_1F : SCALE_FACTOR_0F);
}
- /**
- * Enables or disables text view of this card view.
- */
+ /** Enables or disables text view of this card view. */
public void setTextViewEnabled(boolean enabled) {
if (mTextViewFocused != null) {
mTextViewFocused.setEnabled(enabled);
@@ -200,38 +192,38 @@ public abstract class BaseCardView<T> extends LinearLayout implements ItemListRo
}
}
- /**
- * Called when the focus animation started.
- */
+ /** Called when the focus animation started. */
protected void onFocusAnimationStart(boolean selected) {
if (mExtendViewOnFocus) {
setTextViewFocusedAlpha(selected ? 1f : 0f);
}
}
- /**
- * Called when the focus animation ended.
- */
+ /** Called when the focus animation ended. */
protected void onFocusAnimationEnd(boolean selected) {
// do nothing.
}
/**
- * Called when the view is bound, or while focus animation is running with a value
- * between {@code SCALE_FACTOR_0F} and {@code SCALE_FACTOR_1F}.
+ * Called when the view is bound, or while focus animation is running with a value between
+ * {@code SCALE_FACTOR_0F} and {@code SCALE_FACTOR_1F}.
*/
protected void onSetFocusAnimatedValue(float animatedValue) {
- float cardViewHeight = (mExtendViewOnFocus && isFocused())
- ? mExtendedCardHeight : mCardHeight;
+ float cardViewHeight =
+ (mExtendViewOnFocus && isFocused()) ? mExtendedCardHeight : mCardHeight;
float scale = 1f + (mVerticalCardMargin / cardViewHeight) * animatedValue;
setScaleX(scale);
setScaleY(scale);
setTranslationZ(mFocusTranslationZ * animatedValue);
if (mTextView != null && mTextViewFocused != null) {
ViewGroup.LayoutParams params = mTextView.getLayoutParams();
- int height = mExtendViewOnFocus ? Math.round(mTextViewHeight
- + (mExtendedTextViewHeight - mTextViewHeight) * animatedValue)
- : (int) mTextViewHeight;
+ int height =
+ mExtendViewOnFocus
+ ? Math.round(
+ mTextViewHeight
+ + (mExtendedTextViewHeight - mTextViewHeight)
+ * animatedValue)
+ : (int) mTextViewHeight;
if (height != params.height) {
params.height = height;
setTextViewLayoutParams(params);
@@ -252,25 +244,27 @@ public abstract class BaseCardView<T> extends LinearLayout implements ItemListRo
final boolean selected = targetAnimatedValue == SCALE_FACTOR_1F;
mFocusAnimator = ValueAnimator.ofFloat(mFocusAnimatedValue, targetAnimatedValue);
mFocusAnimator.setDuration(mFocusAnimDuration);
- mFocusAnimator.addListener(new AnimatorListenerAdapter() {
- @Override
- public void onAnimationStart(Animator animation) {
- setHasTransientState(true);
- onFocusAnimationStart(selected);
- }
+ mFocusAnimator.addListener(
+ new AnimatorListenerAdapter() {
+ @Override
+ public void onAnimationStart(Animator animation) {
+ setHasTransientState(true);
+ onFocusAnimationStart(selected);
+ }
- @Override
- public void onAnimationEnd(Animator animation) {
- setHasTransientState(false);
- onFocusAnimationEnd(selected);
- }
- });
- mFocusAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
- @Override
- public void onAnimationUpdate(ValueAnimator animation) {
- setFocusAnimatedValue((Float) animation.getAnimatedValue());
- }
- });
+ @Override
+ public void onAnimationEnd(Animator animation) {
+ setHasTransientState(false);
+ onFocusAnimationEnd(selected);
+ }
+ });
+ mFocusAnimator.addUpdateListener(
+ new ValueAnimator.AnimatorUpdateListener() {
+ @Override
+ public void onAnimationUpdate(ValueAnimator animation) {
+ setFocusAnimatedValue((Float) animation.getAnimatedValue());
+ }
+ });
mFocusAnimator.start();
}