diff options
author | Clark Scheff <clark@cyngn.com> | 2014-08-01 14:40:00 -0700 |
---|---|---|
committer | Clark Scheff <clark@cyngn.com> | 2014-08-04 17:00:58 +0000 |
commit | a3436527cd7531db85d8e844d70fcb0f049727a9 (patch) | |
tree | 891f28bc875e5b1d9590b26d71095c74de83dfe3 /src | |
parent | 3f8d7af0709c4ef693a934a1e904f3dc227f1f06 (diff) | |
download | packages_apps_ThemeChooser-a3436527cd7531db85d8e844d70fcb0f049727a9.zip packages_apps_ThemeChooser-a3436527cd7531db85d8e844d70fcb0f049727a9.tar.gz packages_apps_ThemeChooser-a3436527cd7531db85d8e844d70fcb0f049727a9.tar.bz2 |
Scroll the ScrollView to reveal content behing component selector.
The current implementation shifted the entire content view up which
caused the top to be off screen and the user unable to scroll all the
way to the top while the component selector was out. This patch
animates scrolling the content in the ScrollView and adds a space view
to the bottom so that all content will be visible above the component
selector.
Change-Id: I48577e941b6429db3673b6769f44f3519097b2e8
Diffstat (limited to 'src')
-rw-r--r-- | src/com/cyngn/theme/chooser/ChooserActivity.java | 9 | ||||
-rw-r--r-- | src/com/cyngn/theme/chooser/ThemeFragment.java | 74 |
2 files changed, 78 insertions, 5 deletions
diff --git a/src/com/cyngn/theme/chooser/ChooserActivity.java b/src/com/cyngn/theme/chooser/ChooserActivity.java index 9809015..1c375de 100644 --- a/src/com/cyngn/theme/chooser/ChooserActivity.java +++ b/src/com/cyngn/theme/chooser/ChooserActivity.java @@ -59,7 +59,6 @@ public class ChooserActivity extends FragmentActivity public static final int REQUEST_UNINSTALL = 1; // Request code public static final String EXTRA_PKGNAME = "pkgName"; - private static final long SLIDE_CONTENT_ANIM_DURATION = 300L; private static final long MOVE_TO_MY_THEME_DELAY = 750L; private static final int OFFSCREEN_PAGE_LIMIT = 3; @@ -256,19 +255,19 @@ public class ChooserActivity extends FragmentActivity coordinates[1] += v.getHeight(); int top = getWindowManager().getDefaultDisplay().getHeight() - height; if (coordinates[1] > top) { - slideContentUp(top - coordinates[1]); + slideContentUp(top - coordinates[1], height); } } } - private void slideContentUp(int yDelta) { + private void slideContentUp(int yDelta, int selectorHeight) { yDelta -= getResources().getDimensionPixelSize(R.dimen.content_offset_padding); + getCurrentFragment().slideContentUp(-yDelta, selectorHeight); mContainerYOffset = yDelta; - mContainer.animate().translationYBy(yDelta).setDuration(SLIDE_CONTENT_ANIM_DURATION); } private void slideContentDown(final int yDelta) { - mContainer.animate().translationYBy(-yDelta).setDuration(SLIDE_CONTENT_ANIM_DURATION); + getCurrentFragment().slideContentDown(yDelta); } @Override diff --git a/src/com/cyngn/theme/chooser/ThemeFragment.java b/src/com/cyngn/theme/chooser/ThemeFragment.java index 17f11f0..07e1c59 100644 --- a/src/com/cyngn/theme/chooser/ThemeFragment.java +++ b/src/com/cyngn/theme/chooser/ThemeFragment.java @@ -75,6 +75,7 @@ import android.widget.LinearLayout; import android.widget.PopupMenu; import android.widget.ProgressBar; import android.widget.ScrollView; +import android.widget.Space; import android.widget.TextView; import android.widget.Toast; @@ -144,6 +145,9 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb new ComponentName("com.android.gallery3d", "com.android.gallery3d.app.GalleryActivity"); private static final String CAMERA_NEXT_PACKAGE = "com.cyngn.cameranext"; + private static final int ADDITIONAL_CONTENT_SPACE_ID = 123456; + private static final long SLIDE_CONTENT_ANIM_DURATION = 300L; + protected static final int LOADER_ID_ALL = 0; protected static final int LOADER_ID_STATUS_BAR = 1; protected static final int LOADER_ID_FONT = 2; @@ -1747,6 +1751,76 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb mCurrentTheme = currentTheme; } + /** + * Slides the scrollview content up and adds a space view at the bottom + * of mAdditionalCards so all content can be visible above the selector. + * + * We are using a ValueAnimator here to scroll the content rather than calling + * mScrollView.smoothScrollBy() since the speed of that animation cannot be customized. + * @param yDelta + * @param selectorHeight + */ + public void slideContentUp(final int yDelta, int selectorHeight) { + Space space = new Space(getActivity()); + space.setId(ADDITIONAL_CONTENT_SPACE_ID); + mAdditionalCards.addView(space, new LinearLayout.LayoutParams( + LinearLayout.LayoutParams.MATCH_PARENT, selectorHeight)); + final int startY = mScrollView.getScrollY(); + final ValueAnimator scrollAnimator = + ValueAnimator.ofInt(startY, startY + yDelta); + scrollAnimator.setDuration(SLIDE_CONTENT_ANIM_DURATION); + scrollAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { + @Override + public void onAnimationUpdate(ValueAnimator animation) { + int value = (Integer) animation.getAnimatedValue(); + mScrollView.scrollTo(0, value); + } + }); + scrollAnimator.start(); + } + + /** + * Slides the scrollview content down and removes a space view at the bottom + * of mAdditionalCards. + * + * We are using a ValueAnimator here to scroll the content rather than calling + * mScrollView.smoothScrollBy() since the speed of that animation cannot be customized. + * @param yDelta + */ + public void slideContentDown(int yDelta) { + final int startY = mScrollView.getScrollY(); + final ValueAnimator scrollAnimator = + ValueAnimator.ofInt(startY, startY + yDelta); + scrollAnimator.setDuration(SLIDE_CONTENT_ANIM_DURATION); + scrollAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { + @Override + public void onAnimationUpdate(ValueAnimator animation) { + int value = (Integer) animation.getAnimatedValue(); + mScrollView.scrollTo(0, value); + } + }); + scrollAnimator.addListener(new Animator.AnimatorListener() { + @Override + public void onAnimationStart(Animator animation) { + } + + @Override + public void onAnimationEnd(Animator animation) { + View space = mAdditionalCards.findViewById(ADDITIONAL_CONTENT_SPACE_ID); + if (space != null) mAdditionalCards.removeView(space); + } + + @Override + public void onAnimationCancel(Animator animation) { + } + + @Override + public void onAnimationRepeat(Animator animation) { + } + }); + scrollAnimator.start(); + } + class AnimationLoader extends AsyncTask<Void, Void, Boolean> { Context mContext; String mPkgName; |