diff options
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; |