summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDake Gu <dake@google.com>2015-11-18 19:18:21 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2015-11-18 19:18:21 +0000
commit0ed4899a86485dcffe5f70f62e50980f1f550549 (patch)
treed162aa05fa4184d02da9706143152280f14a6b6f
parent36459054e2064f283ae1f80b8d315e1428ba61de (diff)
parent8e5ae27d6db125867640b672cc97d4a158fdfd48 (diff)
downloadandroid_frameworks_support-0ed4899a86485dcffe5f70f62e50980f1f550549.tar.gz
android_frameworks_support-0ed4899a86485dcffe5f70f62e50980f1f550549.tar.bz2
android_frameworks_support-0ed4899a86485dcffe5f70f62e50980f1f550549.zip
Merge "GuidedStep: sync selectorView translationY to focused view" into mnc-ub-dev
-rw-r--r--v17/leanback/api21/android/support/v17/leanback/transition/TranslationAnimationCreator.java5
-rw-r--r--v17/leanback/res/animator/lb_guidedactions_selector_hide.xml1
-rw-r--r--v17/leanback/res/animator/lb_guidedactions_selector_show.xml1
-rw-r--r--v17/leanback/res/layout/lb_guidedactions.xml27
-rw-r--r--v17/leanback/res/layout/lb_guidedstep_fragment.xml2
-rw-r--r--v17/leanback/res/transition-v21/lb_guidedstep_activity_enter.xml10
-rw-r--r--v17/leanback/res/values/ids.xml3
-rw-r--r--v17/leanback/src/android/support/v17/leanback/app/GuidedStepFragment.java41
-rw-r--r--v17/leanback/src/android/support/v17/leanback/app/GuidedStepSupportFragment.java41
-rw-r--r--v17/leanback/src/android/support/v17/leanback/widget/GuidedActionsStylist.java195
10 files changed, 125 insertions, 201 deletions
diff --git a/v17/leanback/api21/android/support/v17/leanback/transition/TranslationAnimationCreator.java b/v17/leanback/api21/android/support/v17/leanback/transition/TranslationAnimationCreator.java
index c836e77841..2cc35452cc 100644
--- a/v17/leanback/api21/android/support/v17/leanback/transition/TranslationAnimationCreator.java
+++ b/v17/leanback/api21/android/support/v17/leanback/transition/TranslationAnimationCreator.java
@@ -48,9 +48,10 @@ class TranslationAnimationCreator {
if (startX == endX) {
return null;
}
+ float y = view.getTranslationY();
Path path = new Path();
- path.moveTo(startX, 0);
- path.lineTo(endX, 0);
+ path.moveTo(startX, y);
+ path.lineTo(endX, y);
ObjectAnimator anim =
ObjectAnimator.ofFloat(view, View.TRANSLATION_X, View.TRANSLATION_Y, path);
diff --git a/v17/leanback/res/animator/lb_guidedactions_selector_hide.xml b/v17/leanback/res/animator/lb_guidedactions_selector_hide.xml
index f829eb3e89..e5dafb03b1 100644
--- a/v17/leanback/res/animator/lb_guidedactions_selector_hide.xml
+++ b/v17/leanback/res/animator/lb_guidedactions_selector_hide.xml
@@ -17,7 +17,6 @@
<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@integer/lb_guidedactions_animation_duration"
android:propertyName="alpha"
- android:valueFrom="1.0"
android:valueTo="0.0"
android:interpolator="@animator/lb_decelerator_2"
android:valueType="floatType" />
diff --git a/v17/leanback/res/animator/lb_guidedactions_selector_show.xml b/v17/leanback/res/animator/lb_guidedactions_selector_show.xml
index e8d69e570a..fcfd9fa930 100644
--- a/v17/leanback/res/animator/lb_guidedactions_selector_show.xml
+++ b/v17/leanback/res/animator/lb_guidedactions_selector_show.xml
@@ -20,7 +20,6 @@
<objectAnimator
android:duration="@integer/lb_guidedactions_animation_duration"
android:propertyName="alpha"
- android:valueFrom="0"
android:valueTo="1.0"
android:interpolator="@animator/lb_decelerator_2"
android:valueType="floatType" />
diff --git a/v17/leanback/res/layout/lb_guidedactions.xml b/v17/leanback/res/layout/lb_guidedactions.xml
index b7df14005f..f2926d361b 100644
--- a/v17/leanback/res/layout/lb_guidedactions.xml
+++ b/v17/leanback/res/layout/lb_guidedactions.xml
@@ -24,21 +24,28 @@
android:layout_height="match_parent">
<android.support.v17.leanback.widget.NonOverlappingView
- android:id="@+id/guided_button_actions_background"
- android:transitionName="guided_button_actions_background"
+ android:id="@+id/guidedactions_list_background"
+ android:transitionName="guidedactions_list_background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
android:background="?attr/guidedActionsBackgroundDark" />
- <android.support.v17.leanback.widget.VerticalGridView
- android:transitionGroup="true"
- android:id="@+id/guidedactions_list"
- style="?attr/guidedActionsListStyle" />
+ <android.support.v17.leanback.widget.NonOverlappingFrameLayout
+ android:id="@+id/guidedactions_content"
+ android:transitionName="guidedactions_content"
+ android:transitionGroup="false"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+ <android.support.v17.leanback.widget.VerticalGridView
+ android:transitionGroup="true"
+ android:id="@+id/guidedactions_list"
+ style="?attr/guidedActionsListStyle" />
- <android.support.v17.leanback.widget.NonOverlappingView
- android:id="@+id/guidedactions_selector"
- android:transitionName="guidedactions_selector"
- style="?attr/guidedActionsSelectorStyle" />
+ <android.support.v17.leanback.widget.NonOverlappingView
+ android:id="@+id/guidedactions_selector"
+ android:transitionName="guidedactions_selector"
+ style="?attr/guidedActionsSelectorStyle" />
+ </android.support.v17.leanback.widget.NonOverlappingFrameLayout>
</RelativeLayout>
diff --git a/v17/leanback/res/layout/lb_guidedstep_fragment.xml b/v17/leanback/res/layout/lb_guidedstep_fragment.xml
index ca6efc4c47..a41d47d32b 100644
--- a/v17/leanback/res/layout/lb_guidedstep_fragment.xml
+++ b/v17/leanback/res/layout/lb_guidedstep_fragment.xml
@@ -64,7 +64,7 @@
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
- android:elevation="@dimen/lb_guidedactions_elevation" />
+ android:elevation="?attr/guidedActionsElevation" />
</android.support.v17.leanback.widget.NonOverlappingFrameLayout>
</LinearLayout>
diff --git a/v17/leanback/res/transition-v21/lb_guidedstep_activity_enter.xml b/v17/leanback/res/transition-v21/lb_guidedstep_activity_enter.xml
index 120f9425a1..5ee74ee028 100644
--- a/v17/leanback/res/transition-v21/lb_guidedstep_activity_enter.xml
+++ b/v17/leanback/res/transition-v21/lb_guidedstep_activity_enter.xml
@@ -40,12 +40,14 @@
android:slideEdge="@integer/slideEdgeEnd">
<targets>
<target android:targetId="@id/action_fragment_background" />
- <target android:targetId="@id/guided_button_actions_background" />
- <target android:targetId="@id/guidedactions_selector" />
+ <target android:targetId="@id/guidedactions_list_background" />
+ <target android:targetId="@id/guidedactions_content" />
<target android:targetId="@id/guidedactions_list" />
- <target android:targetId="@id/guided_button_actions_background2" />
- <target android:targetId="@id/guidedactions_selector2" />
+ <target android:targetId="@id/guidedactions_selector" />
+ <target android:targetId="@id/guidedactions_list_background2" />
+ <target android:targetId="@id/guidedactions_content2" />
<target android:targetId="@id/guidedactions_list2" />
+ <target android:targetId="@id/guidedactions_selector2" />
</targets>
</slide>
</transitionSet> \ No newline at end of file
diff --git a/v17/leanback/res/values/ids.xml b/v17/leanback/res/values/ids.xml
index a5cf99a5be..ca84efc8a8 100644
--- a/v17/leanback/res/values/ids.xml
+++ b/v17/leanback/res/values/ids.xml
@@ -36,8 +36,9 @@
<item type="id" name="lb_control_closed_captioning" />
<item type="id" name="guidedactions_root2" />
- <item type="id" name="guided_button_actions_background2" />
+ <item type="id" name="guidedactions_list_background2" />
<item type="id" name="guidedactions_list2" />
<item type="id" name="guidedactions_selector2" />
+ <item type="id" name="guidedactions_content2" />
</resources>
diff --git a/v17/leanback/src/android/support/v17/leanback/app/GuidedStepFragment.java b/v17/leanback/src/android/support/v17/leanback/app/GuidedStepFragment.java
index 554f7e3d0f..8be8f24f47 100644
--- a/v17/leanback/src/android/support/v17/leanback/app/GuidedStepFragment.java
+++ b/v17/leanback/src/android/support/v17/leanback/app/GuidedStepFragment.java
@@ -409,13 +409,17 @@ public class GuidedStepFragment extends Fragment implements GuidedActionAdapter.
TransitionHelper.addSharedElement(ft, disappearing.getView().findViewById(
R.id.guidedactions_selector), "guidedactions_selector");
TransitionHelper.addSharedElement(ft, disappearing.getView().findViewById(
- R.id.guided_button_actions_background), "guided_button_actions_background");
+ R.id.guidedactions_content), "guidedactions_content");
+ TransitionHelper.addSharedElement(ft, disappearing.getView().findViewById(
+ R.id.guidedactions_list_background), "guidedactions_list_background");
TransitionHelper.addSharedElement(ft, disappearing.getView().findViewById(
R.id.guidedactions_root2), "guidedactions_root2");
TransitionHelper.addSharedElement(ft, disappearing.getView().findViewById(
R.id.guidedactions_selector2), "guidedactions_selector2");
TransitionHelper.addSharedElement(ft, disappearing.getView().findViewById(
- R.id.guided_button_actions_background2), "guided_button_actions_background2");
+ R.id.guidedactions_content2), "guidedactions_content2");
+ TransitionHelper.addSharedElement(ft, disappearing.getView().findViewById(
+ R.id.guidedactions_list_background2), "guidedactions_list_background2");
}
/**
@@ -743,17 +747,9 @@ public class GuidedStepFragment extends Fragment implements GuidedActionAdapter.
final int uiStyle = getUiStyle();
if (uiStyle == UI_STYLE_REPLACE) {
Object enterTransition = TransitionHelper.createFadeAndShortSlide(Gravity.END);
- TransitionHelper.exclude(enterTransition, R.id.action_fragment_background, true);
- TransitionHelper.exclude(enterTransition, R.id.guided_button_actions_background,
- true);
- TransitionHelper.exclude(enterTransition, R.id.guided_button_actions_background2,
- true);
- TransitionHelper.exclude(enterTransition, R.id.guidedactions_selector, true);
TransitionHelper.exclude(enterTransition, R.id.guidedstep_background, true);
TransitionHelper.setEnterTransition(this, enterTransition);
- // exit transition is unchanged, same as default UI_STYLE_ENTRANCE
-
Object changeBounds = TransitionHelper.createChangeBounds(false);
TransitionHelper.setSharedElementEnterTransition(this, changeBounds);
} else if (uiStyle == UI_STYLE_ENTRANCE) {
@@ -763,39 +759,24 @@ public class GuidedStepFragment extends Fragment implements GuidedActionAdapter.
Object slide = TransitionHelper.createFadeAndShortSlide(Gravity.END |
Gravity.START);
TransitionHelper.include(slide, R.id.content_fragment);
- TransitionHelper.include(slide, R.id.action_fragment_background);
- TransitionHelper.include(slide, R.id.guided_button_actions_background);
- TransitionHelper.include(slide, R.id.guidedactions_selector);
- TransitionHelper.include(slide, R.id.guidedactions_list);
- TransitionHelper.include(slide, R.id.guided_button_actions_background2);
- TransitionHelper.include(slide, R.id.guidedactions_selector2);
- TransitionHelper.include(slide, R.id.guidedactions_list2);
+ TransitionHelper.include(slide, R.id.action_fragment_root);
Object enterTransition = TransitionHelper.createTransitionSet(false);
TransitionHelper.addTransition(enterTransition, fade);
TransitionHelper.addTransition(enterTransition, slide);
TransitionHelper.setEnterTransition(this, enterTransition);
- Object exitTransition = TransitionHelper.createFadeAndShortSlide(Gravity.START);
- TransitionHelper.exclude(exitTransition, R.id.action_fragment_background, true);
- TransitionHelper.exclude(exitTransition, R.id.guided_button_actions_background,
- true);
- TransitionHelper.exclude(exitTransition, R.id.guidedactions_selector, true);
- TransitionHelper.exclude(exitTransition, R.id.guided_button_actions_background2,
- true);
- TransitionHelper.exclude(exitTransition, R.id.guidedactions_selector2, true);
- TransitionHelper.exclude(exitTransition, R.id.guidedstep_background, true);
- TransitionHelper.setExitTransition(this, exitTransition);
// No shared element transition
TransitionHelper.setSharedElementEnterTransition(this, null);
} else if (uiStyle == UI_STYLE_ACTIVITY_ROOT) {
// for Activity root, we dont need enter transition, use activity transition
TransitionHelper.setEnterTransition(this, null);
- // exit transition is unchanged, same as UI_STYLE_ENTRANCE
// No shared element transition
TransitionHelper.setSharedElementEnterTransition(this, null);
- } else {
- return;
}
+ // exitTransition is same for all style
+ Object exitTransition = TransitionHelper.createFadeAndShortSlide(Gravity.START);
+ TransitionHelper.exclude(exitTransition, R.id.guidedstep_background, true);
+ TransitionHelper.setExitTransition(this, exitTransition);
}
}
diff --git a/v17/leanback/src/android/support/v17/leanback/app/GuidedStepSupportFragment.java b/v17/leanback/src/android/support/v17/leanback/app/GuidedStepSupportFragment.java
index 7a25b26a99..ad186ff1b7 100644
--- a/v17/leanback/src/android/support/v17/leanback/app/GuidedStepSupportFragment.java
+++ b/v17/leanback/src/android/support/v17/leanback/app/GuidedStepSupportFragment.java
@@ -411,13 +411,17 @@ public class GuidedStepSupportFragment extends Fragment implements GuidedActionA
TransitionHelper.addSharedElement(ft, disappearing.getView().findViewById(
R.id.guidedactions_selector), "guidedactions_selector");
TransitionHelper.addSharedElement(ft, disappearing.getView().findViewById(
- R.id.guided_button_actions_background), "guided_button_actions_background");
+ R.id.guidedactions_content), "guidedactions_content");
+ TransitionHelper.addSharedElement(ft, disappearing.getView().findViewById(
+ R.id.guidedactions_list_background), "guidedactions_list_background");
TransitionHelper.addSharedElement(ft, disappearing.getView().findViewById(
R.id.guidedactions_root2), "guidedactions_root2");
TransitionHelper.addSharedElement(ft, disappearing.getView().findViewById(
R.id.guidedactions_selector2), "guidedactions_selector2");
TransitionHelper.addSharedElement(ft, disappearing.getView().findViewById(
- R.id.guided_button_actions_background2), "guided_button_actions_background2");
+ R.id.guidedactions_content2), "guidedactions_content2");
+ TransitionHelper.addSharedElement(ft, disappearing.getView().findViewById(
+ R.id.guidedactions_list_background2), "guidedactions_list_background2");
}
/**
@@ -745,17 +749,9 @@ public class GuidedStepSupportFragment extends Fragment implements GuidedActionA
final int uiStyle = getUiStyle();
if (uiStyle == UI_STYLE_REPLACE) {
Object enterTransition = TransitionHelper.createFadeAndShortSlide(Gravity.END);
- TransitionHelper.exclude(enterTransition, R.id.action_fragment_background, true);
- TransitionHelper.exclude(enterTransition, R.id.guided_button_actions_background,
- true);
- TransitionHelper.exclude(enterTransition, R.id.guided_button_actions_background2,
- true);
- TransitionHelper.exclude(enterTransition, R.id.guidedactions_selector, true);
TransitionHelper.exclude(enterTransition, R.id.guidedstep_background, true);
TransitionHelper.setEnterTransition(this, enterTransition);
- // exit transition is unchanged, same as default UI_STYLE_ENTRANCE
-
Object changeBounds = TransitionHelper.createChangeBounds(false);
TransitionHelper.setSharedElementEnterTransition(this, changeBounds);
} else if (uiStyle == UI_STYLE_ENTRANCE) {
@@ -765,39 +761,24 @@ public class GuidedStepSupportFragment extends Fragment implements GuidedActionA
Object slide = TransitionHelper.createFadeAndShortSlide(Gravity.END |
Gravity.START);
TransitionHelper.include(slide, R.id.content_fragment);
- TransitionHelper.include(slide, R.id.action_fragment_background);
- TransitionHelper.include(slide, R.id.guided_button_actions_background);
- TransitionHelper.include(slide, R.id.guidedactions_selector);
- TransitionHelper.include(slide, R.id.guidedactions_list);
- TransitionHelper.include(slide, R.id.guided_button_actions_background2);
- TransitionHelper.include(slide, R.id.guidedactions_selector2);
- TransitionHelper.include(slide, R.id.guidedactions_list2);
+ TransitionHelper.include(slide, R.id.action_fragment_root);
Object enterTransition = TransitionHelper.createTransitionSet(false);
TransitionHelper.addTransition(enterTransition, fade);
TransitionHelper.addTransition(enterTransition, slide);
TransitionHelper.setEnterTransition(this, enterTransition);
- Object exitTransition = TransitionHelper.createFadeAndShortSlide(Gravity.START);
- TransitionHelper.exclude(exitTransition, R.id.action_fragment_background, true);
- TransitionHelper.exclude(exitTransition, R.id.guided_button_actions_background,
- true);
- TransitionHelper.exclude(exitTransition, R.id.guidedactions_selector, true);
- TransitionHelper.exclude(exitTransition, R.id.guided_button_actions_background2,
- true);
- TransitionHelper.exclude(exitTransition, R.id.guidedactions_selector2, true);
- TransitionHelper.exclude(exitTransition, R.id.guidedstep_background, true);
- TransitionHelper.setExitTransition(this, exitTransition);
// No shared element transition
TransitionHelper.setSharedElementEnterTransition(this, null);
} else if (uiStyle == UI_STYLE_ACTIVITY_ROOT) {
// for Activity root, we dont need enter transition, use activity transition
TransitionHelper.setEnterTransition(this, null);
- // exit transition is unchanged, same as UI_STYLE_ENTRANCE
// No shared element transition
TransitionHelper.setSharedElementEnterTransition(this, null);
- } else {
- return;
}
+ // exitTransition is same for all style
+ Object exitTransition = TransitionHelper.createFadeAndShortSlide(Gravity.START);
+ TransitionHelper.exclude(exitTransition, R.id.guidedstep_background, true);
+ TransitionHelper.setExitTransition(this, exitTransition);
}
}
diff --git a/v17/leanback/src/android/support/v17/leanback/widget/GuidedActionsStylist.java b/v17/leanback/src/android/support/v17/leanback/widget/GuidedActionsStylist.java
index 8cdcdc8c4c..6e5d5067db 100644
--- a/v17/leanback/src/android/support/v17/leanback/widget/GuidedActionsStylist.java
+++ b/v17/leanback/src/android/support/v17/leanback/widget/GuidedActionsStylist.java
@@ -22,6 +22,7 @@ import android.content.Context;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.content.res.TypedArray;
+import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.support.annotation.NonNull;
@@ -243,12 +244,15 @@ public class GuidedActionsStylist implements FragmentAnimationProvider {
private static String TAG = "GuidedActionsStylist";
- private View mMainView;
+ private ViewGroup mMainView;
private VerticalGridView mActionsGridView;
private View mBgView;
private View mSelectorView;
+ private View mContentView;
private boolean mButtonActions;
+ private Animator mSelectorAnimator;
+
// Cached values from resources
private float mEnabledTextAlpha;
private float mDisabledTextAlpha;
@@ -274,21 +278,17 @@ public class GuidedActionsStylist implements FragmentAnimationProvider {
* @return The view to be added to the caller's view hierarchy.
*/
public View onCreateView(LayoutInflater inflater, ViewGroup container) {
- mMainView = inflater.inflate(onProvideLayoutId(), container, false);
+ mMainView = (ViewGroup) inflater.inflate(onProvideLayoutId(), container, false);
+ mContentView = mMainView.findViewById(R.id.guidedactions_content);
mSelectorView = mMainView.findViewById(R.id.guidedactions_selector);
mSelectorView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
@Override
public void onLayoutChange(View v, int left, int top, int right, int bottom,
int oldLeft, int oldTop, int oldRight, int oldBottom) {
- final View focusedChild = mActionsGridView.getFocusedChild();
- if (focusedChild != null && mSelectorView.getVisibility() == View.VISIBLE &&
- mSelectorView.getHeight() > 0) {
- mSelectorView.setScaleY((float) focusedChild.getHeight()
- / mSelectorView.getHeight());
- }
+ updateSelectorView(false);
}
});
- mBgView = mMainView.findViewById(R.id.guided_button_actions_background);
+ mBgView = mMainView.findViewById(R.id.guidedactions_list_background);
if (mMainView instanceof VerticalGridView) {
mActionsGridView = (VerticalGridView) mMainView;
} else {
@@ -300,8 +300,16 @@ public class GuidedActionsStylist implements FragmentAnimationProvider {
mActionsGridView.setWindowAlignmentOffsetPercent(50f);
mActionsGridView.setWindowAlignment(VerticalGridView.WINDOW_ALIGN_NO_EDGE);
if (mSelectorView != null) {
- mActionsGridView.setOnScrollListener(new
- SelectorAnimator(mSelectorView, mActionsGridView));
+ mActionsGridView.setOnScrollListener(new RecyclerView.OnScrollListener() {
+ @Override
+ public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
+ if (newState == RecyclerView.SCROLL_STATE_IDLE) {
+ if (mSelectorView.getAlpha() != 1f) {
+ updateSelectorView(true);
+ }
+ }
+ }
+ });
}
}
@@ -343,13 +351,23 @@ public class GuidedActionsStylist implements FragmentAnimationProvider {
public void setAsButtonActions() {
mButtonActions = true;
mMainView.setId(R.id.guidedactions_root2);
- ViewCompat.setTransitionName(mMainView, "guidedactions_root");
- mActionsGridView.setId(R.id.guidedactions_list2);
- mSelectorView.setId(R.id.guidedactions_selector2);
- ViewCompat.setTransitionName(mSelectorView, "guidedactions_selector2");
- mBgView.setId(R.id.guided_button_actions_background2);
- ViewCompat.setTransitionName(mBgView, "guided_button_actions_background2");
- mBgView.setVisibility(View.VISIBLE);
+ ViewCompat.setTransitionName(mMainView, "guidedactions_root2");
+ if (mActionsGridView != null) {
+ mActionsGridView.setId(R.id.guidedactions_list2);
+ }
+ if (mSelectorView != null) {
+ mSelectorView.setId(R.id.guidedactions_selector2);
+ ViewCompat.setTransitionName(mSelectorView, "guidedactions_selector2");
+ }
+ if (mContentView != null) {
+ mContentView.setId(R.id.guidedactions_content2);
+ ViewCompat.setTransitionName(mContentView, "guidedactions_content2");
+ }
+ if (mBgView != null) {
+ mBgView.setId(R.id.guidedactions_list_background2);
+ ViewCompat.setTransitionName(mBgView, "guidedactions_list_background2");
+ mBgView.setVisibility(View.VISIBLE);
+ }
}
/**
@@ -362,22 +380,10 @@ public class GuidedActionsStylist implements FragmentAnimationProvider {
final ViewTreeObserver.OnGlobalFocusChangeListener mGlobalFocusChangeListener =
new ViewTreeObserver.OnGlobalFocusChangeListener() {
- private boolean mChildFocused;
@Override
public void onGlobalFocusChanged(View oldFocus, View newFocus) {
- final View focusedChild = mActionsGridView.getFocusedChild();
- if (focusedChild == null) {
- mSelectorView.setVisibility(View.INVISIBLE);
- mChildFocused = false;
- } else if (!mChildFocused) {
- mChildFocused = true;
- mSelectorView.setVisibility(View.VISIBLE);
- if (mSelectorView.getHeight() > 0) {
- mSelectorView.setScaleY((float) focusedChild.getHeight()
- / mSelectorView.getHeight());
- }
- }
+ updateSelectorView(false);
}
};
@@ -389,8 +395,10 @@ public class GuidedActionsStylist implements FragmentAnimationProvider {
mActionsGridView.getViewTreeObserver().removeOnGlobalFocusChangeListener(
mGlobalFocusChangeListener);
}
+ endSelectorAnimator();
mActionsGridView = null;
mSelectorView = null;
+ mContentView = null;
mBgView = null;
mMainView = null;
}
@@ -737,8 +745,7 @@ public class GuidedActionsStylist implements FragmentAnimationProvider {
*/
@Override
public void onImeAppearing(@NonNull List<Animator> animators) {
- animators.add(createAnimator(mActionsGridView, R.attr.guidedStepImeAppearingAnimation));
- animators.add(createAnimator(mSelectorView, R.attr.guidedStepImeAppearingAnimation));
+ animators.add(createAnimator(mContentView, R.attr.guidedStepImeAppearingAnimation));
}
/**
@@ -746,8 +753,7 @@ public class GuidedActionsStylist implements FragmentAnimationProvider {
*/
@Override
public void onImeDisappearing(@NonNull List<Animator> animators) {
- animators.add(createAnimator(mActionsGridView, R.attr.guidedStepImeDisappearingAnimation));
- animators.add(createAnimator(mSelectorView, R.attr.guidedStepImeDisappearingAnimation));
+ animators.add(createAnimator(mContentView, R.attr.guidedStepImeDisappearingAnimation));
}
/*
@@ -809,96 +815,43 @@ public class GuidedActionsStylist implements FragmentAnimationProvider {
return (int)(mDisplayHeight - 2*mVerticalPadding - 2*mTitleMaxLines*title.getLineHeight());
}
- /**
- * SelectorAnimator
- * Controls animation for selected item backgrounds
- * TODO: Move into focus animation override?
- */
- private static class SelectorAnimator extends RecyclerView.OnScrollListener {
-
- private final View mSelectorView;
- private final ViewGroup mParentView;
- private volatile boolean mFadedOut = true;
-
- SelectorAnimator(View selectorView, ViewGroup parentView) {
- mSelectorView = selectorView;
- mParentView = parentView;
+ private void endSelectorAnimator() {
+ if (mSelectorAnimator != null) {
+ mSelectorAnimator.end();
+ mSelectorAnimator = null;
}
+ }
- // We want to fade in the selector if we've stopped scrolling on it. If
- // we're scrolling, we want to ensure to dim the selector if we haven't
- // already. We dim the last highlighted view so that while a user is
- // scrolling, nothing is highlighted.
- @Override
- public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
- Animator animator = null;
- boolean fadingOut = false;
- if (newState == RecyclerView.SCROLL_STATE_IDLE) {
- // The selector starts with a height of 0. In order to scale up from
- // 0, we first need the set the height to 1 and scale from there.
- View focusedChild = mParentView.getFocusedChild();
- if (focusedChild != null) {
- int selectorHeight = mSelectorView.getHeight();
- float scaleY = (float) focusedChild.getHeight() / selectorHeight;
- AnimatorSet animators = (AnimatorSet)createAnimator(mSelectorView,
- R.attr.guidedActionsSelectorShowAnimation);
- if (mFadedOut) {
- // selector is completely faded out, so we can just scale before fading in.
- mSelectorView.setScaleY(scaleY);
- animator = animators.getChildAnimations().get(0);
- } else {
- // selector is not faded out, so we must animate the scale as we fade in.
- ((ObjectAnimator)animators.getChildAnimations().get(1))
- .setFloatValues(scaleY);
- animator = animators;
- }
- }
- } else {
- animator = createAnimator(mSelectorView, R.attr.guidedActionsSelectorHideAnimation);
- fadingOut = true;
- }
- if (animator != null) {
- animator.addListener(new Listener(fadingOut));
- animator.start();
- }
+ private void updateSelectorView(boolean animate) {
+ if (mActionsGridView == null || mSelectorView == null || mSelectorView.getHeight() <= 0) {
+ return;
}
-
- /**
- * Sets {@link BaseScrollAdapterFragment#mFadedOut}
- * {@link BaseScrollAdapterFragment#mFadedOut} is true, iff
- * {@link BaseScrollAdapterFragment#mSelectorView} has an alpha of 0
- * (faded out). If false the view either has an alpha of 1 (visible) or
- * is in the process of animating.
- */
- private class Listener implements Animator.AnimatorListener {
- private boolean mFadingOut;
- private boolean mCanceled;
-
- public Listener(boolean fadingOut) {
- mFadingOut = fadingOut;
- }
-
- @Override
- public void onAnimationStart(Animator animation) {
- if (!mFadingOut) {
- mFadedOut = false;
- }
- }
-
- @Override
- public void onAnimationEnd(Animator animation) {
- if (!mCanceled && mFadingOut) {
- mFadedOut = true;
- }
- }
-
- @Override
- public void onAnimationCancel(Animator animation) {
- mCanceled = true;
+ final View focusedChild = mActionsGridView.getFocusedChild();
+ endSelectorAnimator();
+ if (focusedChild == null || !mActionsGridView.hasFocus()
+ || mActionsGridView.getScrollState() != RecyclerView.SCROLL_STATE_IDLE) {
+ if (animate) {
+ mSelectorAnimator = createAnimator(mSelectorView,
+ R.attr.guidedActionsSelectorHideAnimation);
+ mSelectorAnimator.start();
+ } else {
+ mSelectorView.setAlpha(0f);
}
-
- @Override
- public void onAnimationRepeat(Animator animation) {
+ } else {
+ final float scaleY = (float) focusedChild.getHeight() / mSelectorView.getHeight();
+ Rect r = new Rect(0, 0, focusedChild.getWidth(), focusedChild.getHeight());
+ mMainView.offsetDescendantRectToMyCoords(focusedChild, r);
+ mMainView.offsetRectIntoDescendantCoords(mSelectorView, r);
+ mSelectorView.setTranslationY(r.exactCenterY() - mSelectorView.getHeight() * 0.5f);
+ if (animate) {
+ mSelectorAnimator = createAnimator(mSelectorView,
+ R.attr.guidedActionsSelectorShowAnimation);
+ ((ObjectAnimator) ((AnimatorSet) mSelectorAnimator).getChildAnimations().get(1))
+ .setFloatValues(scaleY);
+ mSelectorAnimator.start();
+ } else {
+ mSelectorView.setAlpha(1f);
+ mSelectorView.setScaleY(scaleY);
}
}
}