summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndy Mast <andy@cyngn.com>2014-07-15 10:56:03 -0700
committerAndy Mast <andy@cyngn.com>2014-07-16 00:53:51 +0000
commitc460d99e917188040e3753ed1a1e752d60cbaa29 (patch)
treebae19304d810c511cc936683462ac72ae14017a1 /src
parent2eb74dea8d599fc2cd96e823d062fc422a58665b (diff)
downloadpackages_apps_ThemeChooser-c460d99e917188040e3753ed1a1e752d60cbaa29.zip
packages_apps_ThemeChooser-c460d99e917188040e3753ed1a1e752d60cbaa29.tar.gz
packages_apps_ThemeChooser-c460d99e917188040e3753ed1a1e752d60cbaa29.tar.bz2
Implemented bottom title card
Change-Id: Iba41091d408f8251a035b1d762c599a0fa7e025e
Diffstat (limited to 'src')
-rw-r--r--src/android/support/v4/view/ThemeViewPager.java37
-rw-r--r--src/org/cyanogenmod/theme/chooserv2/ChooserActivity.java36
-rw-r--r--src/org/cyanogenmod/theme/chooserv2/ComponentCardView.java9
-rw-r--r--src/org/cyanogenmod/theme/chooserv2/ThemeFragment.java155
4 files changed, 188 insertions, 49 deletions
diff --git a/src/android/support/v4/view/ThemeViewPager.java b/src/android/support/v4/view/ThemeViewPager.java
index e1513e1..9a4ce9d 100644
--- a/src/android/support/v4/view/ThemeViewPager.java
+++ b/src/android/support/v4/view/ThemeViewPager.java
@@ -16,14 +16,13 @@
package android.support.v4.view;
import android.content.Context;
+import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
+import org.cyanogenmod.theme.chooser.R;
public class ThemeViewPager extends ViewPager {
private boolean mExpanded;
@@ -48,7 +47,37 @@ public class ThemeViewPager extends ViewPager {
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
- return !mExpanded;
+ boolean intercept = false;
+
+ if (!mExpanded) {
+ switch (ev.getAction()) {
+ case MotionEvent.ACTION_DOWN:
+ intercept = !isTouchingApplyButton(ev);
+ break;
+ }
+ }
+
+ return intercept;
+ }
+
+ private boolean isTouchingApplyButton(MotionEvent ev) {
+ int x = (int) ev.getRawX();
+ int y = (int) ev.getRawY();
+ View v = getViewForPosition(getCurrentItem());
+ View apply = v.findViewById(R.id.apply);
+ if (apply == null) return false;
+
+ int location[] = new int[2];
+ apply.getLocationOnScreen(location);
+ int viewX = location[0];
+ int viewY = location[1];
+
+ if((x > viewX && x < (viewX + apply.getWidth())) &&
+ ( y > viewY && y < (viewY + apply.getHeight()))){
+ return true;
+ } else {
+ return false;
+ }
}
@Override
diff --git a/src/org/cyanogenmod/theme/chooserv2/ChooserActivity.java b/src/org/cyanogenmod/theme/chooserv2/ChooserActivity.java
index 945ca36..901dbcf 100644
--- a/src/org/cyanogenmod/theme/chooserv2/ChooserActivity.java
+++ b/src/org/cyanogenmod/theme/chooserv2/ChooserActivity.java
@@ -59,10 +59,7 @@ public class ChooserActivity extends FragmentActivity
private PagerContainer mContainer;
private ThemeViewPager mPager;
- private TextView mThemeName;
- private Button mApply;
private Button mEdit;
- private ViewGroup mApplyEditBtns;
private ThemesAdapter mAdapter;
private ThemeManager mService;
private boolean mExpanded = false;
@@ -77,9 +74,6 @@ public class ChooserActivity extends FragmentActivity
mContainer = (PagerContainer) findViewById(R.id.pager_container);
mPager = (ThemeViewPager) findViewById(R.id.viewpager);
- mThemeName = (TextView) findViewById(R.id.theme_name);
- mApplyEditBtns = (ViewGroup) findViewById(R.id.apply_edit_container);
- mApply = (Button) findViewById(R.id.apply);
mEdit = (Button) findViewById(R.id.edit);
mPager.setOnClickListener(mPagerClickListener);
@@ -93,7 +87,6 @@ public class ChooserActivity extends FragmentActivity
mPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
public void onPageSelected(int position) {
- updateThemeName();
}
public void onPageScrolled(int position,
@@ -105,14 +98,6 @@ public class ChooserActivity extends FragmentActivity
}
});
- mApply.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- int position = mPager.getCurrentItem();
- String pkgName = mAdapter.getItemPkgName(position);
- mService.requestThemeChange(pkgName);
- }
- });
-
mEdit.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
mExpanded = true;
@@ -267,12 +252,6 @@ public class ChooserActivity extends FragmentActivity
}
}
- private void updateThemeName() {
- int position = mPager.getCurrentItem();
- String name = mAdapter.getItemName(position);
- mThemeName.setText(name);
- }
-
private View.OnClickListener mPagerClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
@@ -317,8 +296,6 @@ public class ChooserActivity extends FragmentActivity
// old cursor once we return.)
mAdapter.swapCursor(data);
mAdapter.notifyDataSetChanged();
-
- updateThemeName();
}
@Override
@@ -383,19 +360,6 @@ public class ChooserActivity extends FragmentActivity
return mCursor == null ? 1 : mCursor.getCount() + 1;
}
- public String getItemName(int position) {
- if (position == 0) {
- return getString(R.string.my_theme);
- }
-
- mCursor.moveToPosition(position - 1);
- int pkgIdx = mCursor.getColumnIndex(ThemesColumns.PKG_NAME);
- int titleIdx = mCursor.getColumnIndex(ThemesColumns.TITLE);
- String pkgName = mCursor.getString(pkgIdx);
- return DEFAULT.equals(pkgName) ? mContext.getString(R.string.holo)
- : mCursor.getString(titleIdx);
- }
-
public String getItemPkgName(int position) {
if (position == 0) {
return ThemeFragment.CURRENTLY_APPLIED_THEME;
diff --git a/src/org/cyanogenmod/theme/chooserv2/ComponentCardView.java b/src/org/cyanogenmod/theme/chooserv2/ComponentCardView.java
index d4c4fb6..a20f032 100644
--- a/src/org/cyanogenmod/theme/chooserv2/ComponentCardView.java
+++ b/src/org/cyanogenmod/theme/chooserv2/ComponentCardView.java
@@ -5,6 +5,8 @@ import android.animation.ValueAnimator;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Rect;
+import android.graphics.drawable.Drawable;
+import android.graphics.drawable.NinePatchDrawable;
import android.graphics.drawable.TransitionDrawable;
import android.util.AttributeSet;
import android.view.View;
@@ -56,12 +58,15 @@ public class ComponentCardView extends LinearLayout {
public void expand() {
TransitionDrawable bg = (TransitionDrawable) getBackground();
- Rect paddingRect = new Rect();
- bg.getPadding(paddingRect);
+ if (bg != null) {
+ Rect paddingRect = new Rect();
+ bg.getPadding(paddingRect);
+ }
setPadding(mExpandPadLeft, mExpandPadTop, mExpandPadRight, mExpandPadBottom);
if (mLabel != null) {
+ mLabel.setAlpha(0f);
mLabel.setVisibility(View.VISIBLE);
}
}
diff --git a/src/org/cyanogenmod/theme/chooserv2/ThemeFragment.java b/src/org/cyanogenmod/theme/chooserv2/ThemeFragment.java
index fee1dca..752bb2d 100644
--- a/src/org/cyanogenmod/theme/chooserv2/ThemeFragment.java
+++ b/src/org/cyanogenmod/theme/chooserv2/ThemeFragment.java
@@ -15,18 +15,22 @@
*/
package org.cyanogenmod.theme.chooserv2;
+import android.animation.IntEvaluator;
+import android.animation.ValueAnimator;
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.ThemeConfig;
+import android.content.res.ThemeManager;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
+import android.graphics.drawable.NinePatchDrawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
@@ -42,8 +46,10 @@ import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
+import android.view.ViewParent;
import android.view.ViewTreeObserver;
import android.view.animation.DecelerateInterpolator;
+import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
@@ -126,6 +132,7 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb
private TextView mClock;
// Other Misc Preview Views
+ private FrameLayout mShadowFrame;
private ImageView mWallpaper;
private ViewGroup mStatusBar;
private TextView mFontPreview;
@@ -137,6 +144,12 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb
private ImageView mHomeButton;
private ImageView mRecentButton;
+ // Title Card Views
+ private ViewGroup mTitleCard;
+ private TextView mTitle;
+ private ImageView mApply;
+ private ImageView mOverflow;
+
private Handler mHandler;
private int mActiveCardId = -1;
@@ -196,11 +209,12 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb
mBattery = (ImageView) v.findViewById(R.id.battery);
mClock = (TextView) v.findViewById(R.id.clock);
- // Wallpaper / Font / Icons
+ // Wallpaper / Font / Icons / etc
mWallpaper = (ImageView) v.findViewById(R.id.wallpaper);
mFontPreview = (TextView) v.findViewById(R.id.font_preview);
mFontPreview.setTypeface(mTypefaceNormal);
mIconContainer = (ViewGroup) v.findViewById(R.id.icon_container);
+ mShadowFrame = (FrameLayout) v.findViewById(R.id.shadow_frame);
// Nav Bar
mNavBar = (ViewGroup) v.findViewById(R.id.navigation_bar);
@@ -208,6 +222,22 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb
mHomeButton = (ImageView) v.findViewById(R.id.home_button);
mRecentButton = (ImageView) v.findViewById(R.id.recent_button);
+ // Title Card
+ mTitleCard = (ViewGroup)v.findViewById(R.id.title_card);
+ mTitle = (TextView) v.findViewById(R.id.title);
+ mOverflow = (ImageView) v.findViewById(R.id.overflow);
+ mApply = (ImageView) v.findViewById(R.id.apply);
+ mApply.setOnClickListener(new View.OnClickListener() {
+ public void onClick(View v) {
+ Context context = getActivity();
+ if (context != null) {
+ ThemeManager mService =
+ (ThemeManager) context.getSystemService(Context.THEME_SERVICE);
+ mService.requestThemeChange(mPkgName);
+ }
+ }
+ });
+
getLoaderManager().initLoader(LOADER_ID_ALL, null, this);
initCards(v);
@@ -231,6 +261,20 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb
content.setPadding(0, 0, 0, 0);
ViewGroup.LayoutParams layoutParams = mPreviewContent.getLayoutParams();
layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
+ mPreviewContent.setLayoutParams(layoutParams);
+ mScrollView.setPadding(0,0,0,0);
+
+ // The parent of the wallpaper squishes the wp slightly because of padding from the 9 patch
+ // When the parent expands, the wallpaper returns to regular size which creates an
+ // undesireable effect.
+ Rect padding = new Rect();
+ NinePatchDrawable bg = (NinePatchDrawable) mShadowFrame.getBackground();
+ bg.getPadding(padding);
+ ViewGroup.LayoutParams wpParams = mWallpaper.getLayoutParams();
+ wpParams.width -= padding.left + padding.right;
+ mWallpaper.setLayoutParams(wpParams);
+ mIconContainer.setPadding(padding.left, padding.top, padding.right, padding.bottom);
+ mShadowFrame.setBackground(null);
// Expand the children
for (int i = 0; i < mPreviewContent.getChildCount(); i++) {
@@ -252,11 +296,16 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb
// Collect the present position of all the children. The next layout/draw cycle will
// change these bounds since we just expanded them. Then we can animate from prev location
- // to the new location.
- animateChildren(true, getChildrensGlobalBounds());
+ // to the new location. Note that the order of these calls matter as they all
+ // add themselves to the root layout as overlays
+ mScrollView.requestLayout();
animateWallpaperOut();
+ animateTitleCard(true);
+ animateChildren(true, getChildrensGlobalBounds());
mSelector = ((ChooserActivity) getActivity()).getComponentSelector();
mSelector.setOnItemClickedListener(mOnComponentItemClicked);
+
+
}
// Returns the boundaries for all the children in the scrollview relative to the window
@@ -287,6 +336,36 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb
int leftRightPadding = (int) r.getDimension(R.dimen.collapsed_theme_page_padding);
content.setPadding(leftRightPadding, 0, leftRightPadding, 0);
+ //Move the theme preview so that it is near the center of page per spec
+ int paddingTop = (int) r.getDimension(R.dimen.collapsed_theme_page_padding_top);
+ mScrollView.setPadding(0, paddingTop, 0, 0);
+
+ // During expand the wallpaper size decreases slightly to makeup for 9patch padding
+ // so when we collapse we should increase it again.
+ mShadowFrame.setBackgroundResource(R.drawable.bg_themepreview_shadow);
+ Rect padding = new Rect();
+ final NinePatchDrawable bg = (NinePatchDrawable) mShadowFrame.getBackground();
+ bg.getPadding(padding);
+ ViewGroup.LayoutParams wpParams = mWallpaper.getLayoutParams();
+ wpParams.width += padding.left + padding.right;
+ mWallpaper.setLayoutParams(wpParams);
+
+ // Gradually fade the drop shadow back in or else it will be out of place
+ ValueAnimator shadowAnimation = ValueAnimator.ofObject(new IntEvaluator(), 0, 255);
+ shadowAnimation.setDuration(ANIMATE_DURATION);
+ shadowAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
+ @Override
+ public void onAnimationUpdate(ValueAnimator animator) {
+ bg.setAlpha((Integer) animator.getAnimatedValue());
+ }
+
+ });
+ shadowAnimation.start();
+
+ //Move the title card back in
+ mTitleCard.setVisibility(View.VISIBLE);
+ mTitleCard.setTranslationY(0);
+
// Shrink the height
ViewGroup.LayoutParams layoutParams = mPreviewContent.getLayoutParams();
Resources resources = mPreviewContent.getResources();
@@ -310,9 +389,10 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb
child.getLayoutParams();
child.collapse();
}
- mPreviewContent.requestLayout();
+ mScrollView.requestLayout();
animateChildren(false, getChildrensGlobalBounds());
animateWallpaperIn();
+ animateTitleCard(false);
}
// This will animate the children's vertical positions between the previous bounds and the
@@ -375,15 +455,62 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb
}
}
}, ANIMATE_DURATION / 2);
+ }
+ return true;
+ }
+ });
+ }
+
+ private void animateTitleCard(final boolean expand) {
+ final ViewGroup parent = (ViewGroup) mTitleCard.getParent();
+ // Get current location of the title card
+ int[] location = new int[2];
+ mTitleCard.getLocationOnScreen(location);
+ final int prevY = location[1];
+ final ViewTreeObserver observer = mScrollContent.getViewTreeObserver();
+ observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
+ public boolean onPreDraw() {
+ observer.removeOnPreDrawListener(this);
+
+ final ViewGroup root = (ViewGroup) getActivity().getWindow()
+ .getDecorView().findViewById(android.R.id.content);
+
+ root.getOverlay().add(mTitleCard);
+ //Move title card back where it was before the relayout
+ float alpha = 1f;
+ if (expand) {
+ int[] endPos = new int[2];
+ mTitleCard.getLocationInWindow(endPos);
+ int endY = endPos[1];
+ mTitleCard.setTranslationY(prevY - endY);
+ alpha = 0;
+ } else {
}
- return false;
+
+ // Fade the title card and move it out of the way
+ mTitleCard.animate()
+ .alpha(alpha)
+ .setDuration(ANIMATE_DURATION)
+ .withEndAction(new Runnable() {
+ public void run() {
+ root.getOverlay().remove(mTitleCard);
+ parent.addView(mTitleCard);
+ if (expand) {
+ mTitleCard.setVisibility(View.GONE);
+ }
+ }
+ });
+ return true;
}
});
}
private void animateWallpaperOut() {
+ final ViewGroup root = (ViewGroup) getActivity().getWindow()
+ .getDecorView().findViewById(android.R.id.content);
+
int[] location = new int[2];
mWallpaper.getLocationOnScreen(location);
@@ -393,6 +520,7 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb
observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
public boolean onPreDraw() {
observer.removeOnPreDrawListener(this);
+ root.getOverlay().add(mWallpaper);
int[] location = new int[2];
mWallpaper.getLocationOnScreen(location);
@@ -400,14 +528,16 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb
mWallpaper.setTranslationY(prevY - newY);
mWallpaper.animate()
- .alpha(0)
+ .alpha(0f)
.setDuration(300)
.withEndAction(new Runnable() {
public void run() {
+ root.getOverlay().remove(mWallpaper);
+ mShadowFrame.addView(mWallpaper, 0);
mWallpaper.setVisibility(View.GONE);
}
});
- return false;
+ return true;
}
});
}
@@ -553,6 +683,7 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb
loadStatusBar(c);
loadIcons(c);
loadNavBar(c);
+ loadTitle(c);
loadFont(c);
break;
case LOADER_ID_STATUS_BAR:
@@ -576,6 +707,16 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb
@Override
public void onLoaderReset(Loader<Cursor> loader) {}
+ private void loadTitle(Cursor c) {
+ if (CURRENTLY_APPLIED_THEME.equals(mPkgName)) {
+ mTitle.setText(R.string.my_theme);
+ } else {
+ int titleIdx = c.getColumnIndex(ThemesColumns.TITLE);
+ String title = c.getString(titleIdx);
+ mTitle.setText(title);
+ }
+ }
+
private void loadWallpaper(Cursor c) {
if (CURRENTLY_APPLIED_THEME.equals(mPkgName)) {
mWallpaper.setBackground(getActivity().getWallpaper());