summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndy Mast <andy@cyngn.com>2014-07-03 15:59:39 -0700
committerAndy Mast <andy@cyngn.com>2014-07-07 14:02:59 -0700
commit66f10198e64367b60c173ea34c1fc7f8936a0b2c (patch)
tree848f3f0da68f150cea68fcaa3b39f58e4b8c1218
parent3a864f06103819671efe1e579958557f3d2cb24f (diff)
downloadpackages_apps_ThemeChooser-66f10198e64367b60c173ea34c1fc7f8936a0b2c.tar.gz
packages_apps_ThemeChooser-66f10198e64367b60c173ea34c1fc7f8936a0b2c.tar.bz2
packages_apps_ThemeChooser-66f10198e64367b60c173ea34c1fc7f8936a0b2c.zip
Use automated previews for all the things
This will pull in the automated previews for wallpaper, status bar, nav bar, and from the content provider and display them. The typeface is also correctly shown. Change-Id: I08147974f9b2e324b670a4cba5ba4728356921b0
-rw-r--r--res/layout/v2_fragment_pager_list.xml29
-rw-r--r--res/layout/v2_nav_bar_preview_item.xml43
-rw-r--r--res/layout/v2_status_bar_preview_item.xml58
-rw-r--r--res/layout/v2item_font.xml7
-rw-r--r--res/layout/v2item_icon.xml13
-rw-r--r--res/layout/v2item_navbar.xml11
-rw-r--r--res/layout/v2item_statusbar.xml11
-rw-r--r--res/values/colors.xml3
-rw-r--r--res/values/dimens.xml3
-rw-r--r--res/values/strings.xml4
-rw-r--r--res/values/styles.xml6
-rw-r--r--src/org/cyanogenmod/theme/chooserv2/ThemeFragment.java389
-rw-r--r--src/org/cyanogenmod/theme/util/IconPreviewHelper.java2
13 files changed, 504 insertions, 75 deletions
diff --git a/res/layout/v2_fragment_pager_list.xml b/res/layout/v2_fragment_pager_list.xml
index cef65f9..e332817 100644
--- a/res/layout/v2_fragment_pager_list.xml
+++ b/res/layout/v2_fragment_pager_list.xml
@@ -10,15 +10,26 @@
android:layout_gravity="center_vertical"
android:divider="@null"
android:scrollbars="none"
+ android:fillViewport="true"
android:drawSelectorOnTop="false">
-
- <LinearLayout android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical">
- <include layout="@layout/v2item_statusbar"/>
- <include layout="@layout/v2item_font"/>
- <include layout="@layout/v2item_icon"/>
- <include layout="@layout/v2item_navbar"/>
- </LinearLayout>
+ <FrameLayout android:layout_width="match_parent"
+ android:layout_height="match_parent">
+ <ImageView
+ android:id="@+id/wallpaper"
+ android:layout_width="match_parent"
+ android:layout_height="@dimen/theme_preview_height"
+ android:scaleType="centerCrop"
+ />
+ <RelativeLayout
+ android:id="@+id/preview_container"
+ android:layout_width="match_parent"
+ android:layout_height="@dimen/theme_preview_height"
+ android:orientation="vertical">
+ <include layout="@layout/v2_status_bar_preview_item"/>
+ <include layout="@layout/v2item_font"/>
+ <include layout="@layout/v2item_icon"/>
+ <include layout="@layout/v2_nav_bar_preview_item"/>
+ </RelativeLayout>
+ </FrameLayout>
</ScrollView>
</LinearLayout> \ No newline at end of file
diff --git a/res/layout/v2_nav_bar_preview_item.xml b/res/layout/v2_nav_bar_preview_item.xml
new file mode 100644
index 0000000..937eea4
--- /dev/null
+++ b/res/layout/v2_nav_bar_preview_item.xml
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/navigation_bar"
+ android:orientation="horizontal"
+ android:layout_width="match_parent"
+ android:layout_height="@*android:dimen/system_bar_height"
+ android:layout_alignParentBottom="true"
+ android:paddingStart="6dp"
+ android:paddingEnd="6dp"
+ android:background="#00000000">
+
+ <!-- Dummy view for padding -->
+ <View
+ android:layout_width="0dp"
+ android:layout_height="match_parent"
+ android:layout_weight="1" />
+
+ <ImageView
+ android:id="@+id/back_button"
+ android:layout_width="@dimen/navigation_button_width"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_vertical" />
+
+ <ImageView
+ android:id="@+id/home_button"
+ android:layout_width="@dimen/navigation_button_width"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_vertical" />
+
+ <ImageView
+ android:id="@+id/recent_button"
+ android:layout_width="@dimen/navigation_button_width"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_vertical" />
+
+ <!-- Dummy view for padding -->
+ <View
+ android:layout_width="0dp"
+ android:layout_height="match_parent"
+ android:layout_weight="1" />
+
+</LinearLayout> \ No newline at end of file
diff --git a/res/layout/v2_status_bar_preview_item.xml b/res/layout/v2_status_bar_preview_item.xml
new file mode 100644
index 0000000..caa6933
--- /dev/null
+++ b/res/layout/v2_status_bar_preview_item.xml
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/status_bar"
+ android:orientation="horizontal"
+ android:layout_width="match_parent"
+ android:layout_height="@*android:dimen/status_bar_height"
+ android:paddingStart="6dp"
+ android:paddingEnd="6dp"
+ android:background="#00000000">
+
+ <!-- dummy view to push everything to the right. -->
+ <View
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"/>
+
+ <ImageView
+ android:id="@+id/bluetooth_icon"
+ android:layout_width="wrap_content"
+ android:layout_height="@*android:dimen/status_bar_icon_size"
+ android:layout_gravity="center_vertical"
+ android:paddingEnd="6dp"
+ android:scaleType="fitCenter"/>
+
+ <ImageView
+ android:id="@+id/wifi_icon"
+ android:layout_width="wrap_content"
+ android:layout_height="@*android:dimen/status_bar_icon_size"
+ android:layout_gravity="center_vertical"
+ android:scaleType="fitCenter"/>
+
+ <ImageView
+ android:id="@+id/signal_icon"
+ android:layout_width="wrap_content"
+ android:layout_height="@*android:dimen/status_bar_icon_size"
+ android:layout_gravity="center_vertical"
+ android:paddingEnd="6dp"
+ android:scaleType="fitCenter"/>
+
+ <ImageView
+ android:id="@+id/battery"
+ android:layout_width="wrap_content"
+ android:layout_height="@*android:dimen/status_bar_icon_size"
+ android:layout_gravity="center_vertical"
+ android:paddingEnd="6dp"
+ android:scaleType="fitCenter"/>
+
+ <TextView
+ android:id="@+id/clock"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:gravity="center_vertical"
+ android:layout_gravity="center_vertical"
+ android:text="@string/status_bar_clock_text"
+ style="@style/TextAppearance.StatusBar.Clock"/>
+
+</LinearLayout> \ No newline at end of file
diff --git a/res/layout/v2item_font.xml b/res/layout/v2item_font.xml
index 3854506..d2f3ce7 100644
--- a/res/layout/v2item_font.xml
+++ b/res/layout/v2item_font.xml
@@ -1,8 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/font_preview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
+ android:layout_below="@+id/status_bar"
android:text="@string/font_preview_letters"
+ android:textColor="@color/font_preview_color"
+ android:shadowColor="@color/font_preview_shadow_color"
+ android:shadowDx="2"
+ android:shadowDy="2"
+ android:shadowRadius="4"
android:textSize="32sp"
android:gravity="center_horizontal"
/>
diff --git a/res/layout/v2item_icon.xml b/res/layout/v2item_icon.xml
index ea74d67..f313239 100644
--- a/res/layout/v2item_icon.xml
+++ b/res/layout/v2item_icon.xml
@@ -3,27 +3,28 @@
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/icon_container"
android:layout_width="match_parent"
- android:layout_height="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_below="@+id/font_preview"
+ android:layout_marginTop="40dp"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:paddingLeft="30dp"
- android:paddingRight="40dp"
- android:paddingTop="40dp" >
+ android:paddingRight="30dp">
<ImageView
android:layout_width="0px"
android:layout_weight="1"
- android:layout_height="wrap_content"
+ android:layout_height="48dp"
android:src="@drawable/comp_icon1"
/>
<ImageView
android:layout_width="0px"
android:layout_weight="1"
- android:layout_height="wrap_content"
+ android:layout_height="48dp"
android:src="@drawable/comp_icon2"
/>
<ImageView
android:layout_width="0px"
- android:layout_height="wrap_content"
+ android:layout_height="48dp"
android:layout_weight="1"
android:src="@drawable/comp_icon3"
/>
diff --git a/res/layout/v2item_navbar.xml b/res/layout/v2item_navbar.xml
deleted file mode 100644
index f478cb4..0000000
--- a/res/layout/v2item_navbar.xml
+++ /dev/null
@@ -1,11 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
- <ImageView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:src="@drawable/comp_navbar"
- />
-</LinearLayout> \ No newline at end of file
diff --git a/res/layout/v2item_statusbar.xml b/res/layout/v2item_statusbar.xml
deleted file mode 100644
index 41d909e..0000000
--- a/res/layout/v2item_statusbar.xml
+++ /dev/null
@@ -1,11 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
- <ImageView xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:background="@drawable/comp_stsbar"
- />
-</LinearLayout> \ No newline at end of file
diff --git a/res/values/colors.xml b/res/values/colors.xml
index e032555..897e145 100644
--- a/res/values/colors.xml
+++ b/res/values/colors.xml
@@ -26,4 +26,7 @@
<color name="apply_button_progress_color">#6bd1e9</color>
<color name="apply_button_default_color">#00b1e5</color>
<color name="apply_button_pressed_color">#008ef2</color>
+
+ <color name="font_preview_color">#ffffff</color>
+ <color name="font_preview_shadow_color">#dd000000</color>
</resources>
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index 38e2f4b..14d95b6 100644
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -19,4 +19,7 @@
<dimen name="button_bar_height">62dip</dimen>
<dimen name="sliding_up_panel_parallax_distance">150dp</dimen>
<dimen name="item_browse_height">260dp</dimen>
+ <dimen name="expanded_preview_margin">66dp</dimen>
+ <dimen name="navigation_button_width">80dp</dimen>
+ <dimen name="theme_preview_height">264dp</dimen>
</resources>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 395e85c..147c33f 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -70,4 +70,8 @@
<item>https://play.google.com/store/search?q=theme+engine&amp;c=apps</item>
<item>http://wiki.cyanogenmod.org/w/Themes</item>
</string-array>
+
+ <string name="status_bar_clock_text" translatable="false">5:30</string>
+ <string name="status_bar">Status bar</string>
+ <string name="navigation_bar">Navigation bar</string>
</resources>
diff --git a/res/values/styles.xml b/res/values/styles.xml
index 657f712..065cadb 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -108,4 +108,10 @@
<item name="android:textColor">#FFFFFF</item>
</style>
+ <style name="TextAppearance.StatusBar.Clock" parent="@*android:style/TextAppearance.StatusBar.Icon">
+ <!-- Note: must be dp to fit in status bar -->
+ <item name="android:textSize">16dp</item>
+ <item name="android:textStyle">normal</item>
+ </style>
+
</resources>
diff --git a/src/org/cyanogenmod/theme/chooserv2/ThemeFragment.java b/src/org/cyanogenmod/theme/chooserv2/ThemeFragment.java
index 7be0a0d..cc66ba6 100644
--- a/src/org/cyanogenmod/theme/chooserv2/ThemeFragment.java
+++ b/src/org/cyanogenmod/theme/chooserv2/ThemeFragment.java
@@ -15,27 +15,89 @@
*/
package org.cyanogenmod.theme.chooserv2;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.content.res.Resources;
+import android.database.Cursor;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.graphics.Typeface;
+import android.graphics.drawable.BitmapDrawable;
+import android.graphics.drawable.Drawable;
+import android.net.Uri;
import android.os.Bundle;
+import android.provider.Settings;
+import android.provider.ThemesContract;
+import android.provider.ThemesContract.PreviewColumns;
+import android.provider.ThemesContract.ThemesColumns;
import android.support.v4.app.Fragment;
-import android.support.v4.view.ViewPager;
+import android.support.v4.app.LoaderManager;
+import android.support.v4.content.CursorLoader;
+import android.support.v4.content.Loader;
+import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.animation.DecelerateInterpolator;
-import android.widget.ScrollView;
+import android.widget.ImageView;
+import android.widget.RelativeLayout;
+import android.widget.TextView;
import org.cyanogenmod.theme.chooser.R;
+import org.cyanogenmod.theme.util.IconPreviewHelper;
+import org.cyanogenmod.theme.util.ThemedTypefaceHelper;
import java.util.ArrayList;
import java.util.List;
-public class ThemeFragment extends Fragment {
- public static final int ANIMATE_START_DELAY = 75;
- public static final int ANIMATE_DURATION = 500;
+public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallbacks<Cursor> {
+ public static final int ANIMATE_START_DELAY = 200;
+ public static final int ANIMATE_DURATION = 800;
public static final int ANIMATE_INTERPOLATE_FACTOR = 3;
- private ScrollView mScrollView;
+
+ private static final ComponentName COMPONENT_MESSAGING =
+ new ComponentName("com.android.mms", "com.android.mms.ui.ConversationList");
+ private static final ComponentName COMPONENT_CAMERANEXT =
+ new ComponentName("com.cyngn.cameranext", "com.android.camera.CameraLauncher");
+ private static final ComponentName COMPONENT_CAMERA =
+ new ComponentName("com.android.camera2", "com.android.camera.CameraActivity");
+ private static final ComponentName COMPONENT_SETTINGS =
+ new ComponentName("com.android.settings", "com.android.settings.Settings");
+ private static final ComponentName COMPONENT_PEOPLE =
+ new ComponentName("com.android.contacts",
+ "com.android.contacts.activities.PeopleActivity");
+ private static final String CAMERA_NEXT_PACKAGE = "com.cyngn.cameranext";
+
+ private static ComponentName[] sIconComponents;
+
+ private String mPkgName;
+ private Typeface mTypefaceNormal;
+ private int mBatteryStyle;
+
+ private ViewGroup mScrollView;
private ViewGroup mScrollContent;
+ private ViewGroup mPreviewContent; // Contains icons, font, nav/status etc. Not wallpaper
+
+ //Status Bar Views
+ private ImageView mBluetooth;
+ private ImageView mWifi;
+ private ImageView mSignal;
+ private ImageView mBattery;
+ private TextView mClock;
+
+ // Other Misc Preview Views
+ private ImageView mWallpaper;
+ private ViewGroup mStatusBar;
+ private TextView mFontPreview;
+ private ViewGroup mIconContainer;
+
+ // Nav Bar Views
+ private ViewGroup mNavBar;
+ private ImageView mBackButton;
+ private ImageView mHomeButton;
+ private ImageView mRecentButton;
static ThemeFragment newInstance(String pkgName) {
ThemeFragment f = new ThemeFragment();
@@ -51,63 +113,101 @@ public class ThemeFragment extends Fragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+ mPkgName = getArguments().getString("pkgName");
+ mBatteryStyle = Settings.System.getInt(getActivity().getContentResolver(),
+ Settings.System.STATUS_BAR_BATTERY, 0);
+
+ getIconComponents(getActivity());
+ ThemedTypefaceHelper helper = new ThemedTypefaceHelper();
+ helper.load(getActivity(), mPkgName);
+ mTypefaceNormal = helper.getTypeface(Typeface.NORMAL);
}
- /**
- * The Fragment's UI is just a simple text view showing its
- * instance number.
- */
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
-
- ViewPager.LayoutParams params = new ViewPager.LayoutParams();
- params.width = ViewPager.LayoutParams.MATCH_PARENT;
- params.height = ViewPager.LayoutParams.MATCH_PARENT;
-
View v = inflater.inflate(R.layout.v2_fragment_pager_list, container, false);
- v.setLayoutParams(params);
- mScrollView = (ScrollView) v.findViewById(android.R.id.list);
+ mScrollView = (ViewGroup) v.findViewById(android.R.id.list);
mScrollContent = (ViewGroup) mScrollView.getChildAt(0);
+ mPreviewContent = (ViewGroup) v.findViewById(R.id.preview_container);
+
+ // Status Bar
+ mStatusBar = (ViewGroup) v.findViewById(R.id.status_bar);
+ mBluetooth = (ImageView) v.findViewById(R.id.bluetooth_icon);
+ mWifi = (ImageView) v.findViewById(R.id.wifi_icon);
+ mSignal = (ImageView) v.findViewById(R.id.signal_icon);
+ mBattery = (ImageView) v.findViewById(R.id.battery);
+ mClock = (TextView) v.findViewById(R.id.clock);
+
+ // Wallpaper / Font / Icons
+ 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);
+
+ // Nav Bar
+ mNavBar = (ViewGroup) v.findViewById(R.id.navigation_bar);
+ mBackButton = (ImageView) v.findViewById(R.id.back_button);
+ mHomeButton = (ImageView) v.findViewById(R.id.home_button);
+ mRecentButton = (ImageView) v.findViewById(R.id.recent_button);
+
+ getLoaderManager().initLoader(0, null, this);
return v;
}
public void expand() {
- for (int i = 0; i < mScrollContent.getChildCount(); i++) {
- View child = mScrollContent.getChildAt(i);
- ViewGroup.LayoutParams layout = child.getLayoutParams();
- layout.height = 400;
+ ViewGroup.LayoutParams layoutParams = mScrollContent.getLayoutParams();
+ layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
+ mScrollContent.setLayoutParams(layoutParams);
+
+ layoutParams = mPreviewContent.getLayoutParams();
+ layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
+
+ for (int i = 0; i < mPreviewContent.getChildCount(); i++) {
+ View child = mPreviewContent.getChildAt(i);
+ RelativeLayout.LayoutParams layout =
+ (RelativeLayout.LayoutParams) child.getLayoutParams();
+ int botMargin = (int) child.getContext().getResources()
+ .getDimension(R.dimen.expanded_preview_margin);
+ layout.setMargins(0, 0, 0, botMargin);
child.setLayoutParams(layout);
}
mScrollContent.requestLayout();
- animateChildren();
- }
+ animateChildren(true);
+ animateWallpaperOut();
+ }
public void collapse() {
- for (int i = 0; i < mScrollContent.getChildCount(); i++) {
- View child = mScrollContent.getChildAt(i);
- ViewGroup.LayoutParams layout = child.getLayoutParams();
- layout.height = ViewGroup.LayoutParams.WRAP_CONTENT;
+ ViewGroup.LayoutParams layoutParams = mPreviewContent.getLayoutParams();
+ Resources resources = mPreviewContent.getResources();
+ layoutParams.height = (int) resources.getDimension(R.dimen.theme_preview_height);
+
+ for (int i = 0; i < mPreviewContent.getChildCount(); i++) {
+ View child = mPreviewContent.getChildAt(i);
+ RelativeLayout.LayoutParams layout =
+ (RelativeLayout.LayoutParams) child.getLayoutParams();
+ layout.setMargins(0, 0, 0, 0);
child.setLayoutParams(layout);
}
- mScrollContent.requestLayout();
+ mPreviewContent.requestLayout();
- animateChildren();
+ animateChildren(false);
+ animateWallpaperIn();
}
// This will animate the children's vertical value between the existing and
// new layout changes
- private void animateChildren() {
+ private void animateChildren(final boolean isExpanding) {
final ViewGroup root = (ViewGroup) getActivity().getWindow()
.getDecorView().findViewById(android.R.id.content);
// Get the child's current location
final List<Float> prevYs = new ArrayList<Float>();
- for (int i = 0; i < mScrollContent.getChildCount(); i++) {
- final View v = mScrollContent.getChildAt(i);
+ for (int i = 0; i < mPreviewContent.getChildCount(); i++) {
+ final View v = mPreviewContent.getChildAt(i);
int[] pos = new int[2];
v.getLocationInWindow(pos);
prevYs.add((float) pos[1]);
@@ -119,14 +219,14 @@ public class ThemeFragment extends Fragment {
public boolean onPreDraw() {
observer.removeOnPreDrawListener(this);
- for (int i = mScrollContent.getChildCount() - 1; i >= 0; i--) {
- final View v = mScrollContent.getChildAt(i);
+ for (int i = mPreviewContent.getChildCount() - 1; i >= 0; i--) {
+ final View v = mPreviewContent.getChildAt(i);
float prevY;
float endY;
if (i >= prevYs.size()) {
// View is being created
- prevY = mScrollContent.getTop() + mScrollContent.getHeight();
+ prevY = mPreviewContent.getTop() + mPreviewContent.getHeight();
endY = v.getY();
} else {
prevY = prevYs.get(i);
@@ -138,8 +238,12 @@ public class ThemeFragment extends Fragment {
v.setTranslationY((prevY - endY));
root.getOverlay().add(v);
+ // Expanding has a delay while the wallpaper begins to fade out
+ // Collapsing is opposite of this so wallpaper will have the delay instead
+ int startDelay = isExpanding ? ANIMATE_START_DELAY : 0;
+
v.animate()
- .setStartDelay(ANIMATE_START_DELAY)
+ .setStartDelay(startDelay)
.translationY(0)
.setDuration(ANIMATE_DURATION)
.setInterpolator(
@@ -147,7 +251,7 @@ public class ThemeFragment extends Fragment {
.withEndAction(new Runnable() {
public void run() {
root.getOverlay().remove(v);
- mScrollContent.addView(v, 0);
+ mPreviewContent.addView(v, 0);
}
});
@@ -157,4 +261,215 @@ public class ThemeFragment extends Fragment {
}
});
}
+
+ private void animateWallpaperOut() {
+ int[] location = new int[2];
+ mWallpaper.getLocationOnScreen(location);
+
+ final int prevY = location[1];
+
+ final ViewTreeObserver observer = mScrollContent.getViewTreeObserver();
+ observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
+ public boolean onPreDraw() {
+ observer.removeOnPreDrawListener(this);
+
+ int[] location = new int[2];
+ mWallpaper.getLocationOnScreen(location);
+ final int newY = location[1];
+
+ mWallpaper.setTranslationY(prevY - newY);
+ mWallpaper.animate()
+ .alpha(0)
+ .setDuration(300)
+ .withEndAction(new Runnable() {
+ public void run() {
+ mWallpaper.setVisibility(View.GONE);
+ }
+ });
+ return false;
+ }
+ });
+ }
+
+ private void animateWallpaperIn() {
+ mWallpaper.setTranslationY(0);
+ mWallpaper.animate()
+ .setStartDelay(ANIMATE_START_DELAY)
+ .alpha(1f)
+ .setDuration(300)
+ .withEndAction(new Runnable() {
+ public void run() {
+ mWallpaper.setVisibility(View.VISIBLE);
+ }
+ });
+ }
+
+ @Override
+ public Loader<Cursor> onCreateLoader(int id, Bundle args) {
+ String[] projection = {
+ ThemesColumns.PKG_NAME,
+ ThemesColumns.TITLE,
+ ThemesColumns.WALLPAPER_URI,
+ ThemesColumns.HOMESCREEN_URI,
+ PreviewColumns.WALLPAPER_PREVIEW,
+ PreviewColumns.STATUSBAR_BACKGROUND,
+ PreviewColumns.STATUSBAR_WIFI_ICON,
+ PreviewColumns.STATUSBAR_WIFI_COMBO_MARGIN_END,
+ PreviewColumns.STATUSBAR_BLUETOOTH_ICON,
+ PreviewColumns.STATUSBAR_SIGNAL_ICON,
+ PreviewColumns.STATUSBAR_CLOCK_TEXT_COLOR,
+ PreviewColumns.STATUSBAR_BATTERY_CIRCLE,
+ PreviewColumns.STATUSBAR_BATTERY_LANDSCAPE,
+ PreviewColumns.STATUSBAR_BATTERY_PORTRAIT,
+ PreviewColumns.NAVBAR_BACK_BUTTON,
+ PreviewColumns.NAVBAR_HOME_BUTTON,
+ PreviewColumns.NAVBAR_RECENT_BUTTON,
+ PreviewColumns.ICON_PREVIEW_1,
+ PreviewColumns.ICON_PREVIEW_2,
+ PreviewColumns.ICON_PREVIEW_3,
+ PreviewColumns.ICON_PREVIEW_4
+ };
+
+ Uri uri = ThemesContract.PreviewColumns.CONTENT_URI;
+ String selection = ThemesContract.ThemesColumns.PKG_NAME + "= ?";
+ String[] selectionArgs = new String[]{mPkgName};
+ return new CursorLoader(getActivity(), uri, projection, selection, selectionArgs, null);
+ }
+
+ @Override
+ public void onLoadFinished(Loader<Cursor> loader, Cursor c) {
+ c.moveToFirst();
+ loadWallpaper(c);
+ loadStatusBar(c);
+ loadIcons(c);
+ loadNavBar(c);
+ }
+
+ @Override
+ public void onLoaderReset(Loader<Cursor> loader) {
+
+ }
+
+ private void loadWallpaper(Cursor c) {
+ int wpIdx = c.getColumnIndex(PreviewColumns.WALLPAPER_PREVIEW);
+ Bitmap bitmap = loadBitmapBlob(c, wpIdx);
+ mWallpaper.setImageBitmap(bitmap);
+ }
+
+ private void loadStatusBar(Cursor c) {
+ int backgroundIdx = c.getColumnIndex(PreviewColumns.STATUSBAR_BACKGROUND);
+ int wifiIdx = c.getColumnIndex(PreviewColumns.STATUSBAR_WIFI_ICON);
+ int wifiMarginIdx = c.getColumnIndex(PreviewColumns.STATUSBAR_WIFI_COMBO_MARGIN_END);
+ int bluetoothIdx = c.getColumnIndex(PreviewColumns.STATUSBAR_BLUETOOTH_ICON);
+ int signalIdx = c.getColumnIndex(PreviewColumns.STATUSBAR_SIGNAL_ICON);
+ int batteryIdx = c.getColumnIndex(getBatteryIndex(mBatteryStyle));
+ int clockColorIdx = c.getColumnIndex(PreviewColumns.STATUSBAR_CLOCK_TEXT_COLOR);
+
+ Bitmap background = loadBitmapBlob(c, backgroundIdx);
+ Bitmap bluetoothIcon = loadBitmapBlob(c, bluetoothIdx);
+ Bitmap wifiIcon = loadBitmapBlob(c, wifiIdx);
+ Bitmap signalIcon = loadBitmapBlob(c, signalIdx);
+ Bitmap batteryIcon = loadBitmapBlob(c, batteryIdx);
+ int wifiMargin = c.getInt(wifiMarginIdx);
+ int clockTextColor = c.getInt(clockColorIdx);
+
+ mStatusBar.setBackground(new BitmapDrawable(getActivity().getResources(), background));
+ mBluetooth.setImageBitmap(bluetoothIcon);
+ mWifi.setImageBitmap(wifiIcon);
+ mSignal.setImageBitmap(signalIcon);
+ mBattery.setImageBitmap(batteryIcon);
+ mClock.setTextColor(clockTextColor);
+
+ ViewGroup.MarginLayoutParams params =
+ (ViewGroup.MarginLayoutParams) mWifi.getLayoutParams();
+ params.setMarginEnd(wifiMargin);
+ mWifi.requestLayout();
+
+ if (mBatteryStyle == 4) {
+ mBattery.setVisibility(View.GONE);
+ } else {
+ mBattery.setVisibility(View.VISIBLE);
+ }
+ }
+
+ private String getBatteryIndex(int type) {
+ switch(type) {
+ case 2:
+ return PreviewColumns.STATUSBAR_BATTERY_CIRCLE;
+ case 5:
+ return PreviewColumns.STATUSBAR_BATTERY_LANDSCAPE;
+ default:
+ return PreviewColumns.STATUSBAR_BATTERY_PORTRAIT;
+ }
+ }
+
+ private void loadIcons(Cursor c) {
+ int[] iconIdx = new int[4];
+ iconIdx[0] = c.getColumnIndex(PreviewColumns.ICON_PREVIEW_1);
+ iconIdx[1] = c.getColumnIndex(PreviewColumns.ICON_PREVIEW_2);
+ iconIdx[2] = c.getColumnIndex(PreviewColumns.ICON_PREVIEW_3);
+ iconIdx[3] = c.getColumnIndex(PreviewColumns.ICON_PREVIEW_4);
+
+ // Set the icons. If the provider does not have an icon preview then
+ // fall back to the default icon set
+ IconPreviewHelper helper = new IconPreviewHelper(getActivity(), "");
+ for(int i=0; i < mIconContainer.getChildCount() && i < iconIdx.length; i++) {
+ ImageView v = (ImageView) mIconContainer.getChildAt(i);
+ Bitmap bitmap = loadBitmapBlob(c, iconIdx[i]);
+ if (bitmap == null) {
+ ComponentName component = sIconComponents[i];
+ Drawable icon = helper.getDefaultIcon(component.getPackageName(),
+ component.getClassName());
+ v.setImageDrawable(icon);
+ } else {
+ v.setImageBitmap(bitmap);
+ }
+ }
+ }
+
+ private void loadNavBar(Cursor c) {
+ int backButtonIdx = c.getColumnIndex(PreviewColumns.NAVBAR_BACK_BUTTON);
+ int homeButtonIdx = c.getColumnIndex(PreviewColumns.NAVBAR_HOME_BUTTON);
+ int recentButtonIdx = c.getColumnIndex(PreviewColumns.NAVBAR_RECENT_BUTTON);
+ int backgroundIdx = c.getColumnIndex(PreviewColumns.STATUSBAR_BACKGROUND);
+
+ Bitmap background = loadBitmapBlob(c, backgroundIdx);
+ Bitmap backButton = loadBitmapBlob(c, backButtonIdx);
+ Bitmap homeButton = loadBitmapBlob(c, homeButtonIdx);
+ Bitmap recentButton = loadBitmapBlob(c, recentButtonIdx);
+
+ mNavBar.setBackground(new BitmapDrawable(getActivity().getResources(), background));
+ mBackButton.setImageBitmap(backButton);
+ mHomeButton.setImageBitmap(homeButton);
+ mRecentButton.setImageBitmap(recentButton);
+ }
+
+ private Bitmap loadBitmapBlob(Cursor cursor, int columnIdx) {
+ byte[] blob = cursor.getBlob(columnIdx);
+ if (blob == null) return null;
+ return BitmapFactory.decodeByteArray(blob, 0, blob.length);
+ }
+
+ public static ComponentName[] getIconComponents(Context context) {
+ if (sIconComponents == null || sIconComponents.length == 0) {
+ sIconComponents = new ComponentName[]{COMPONENT_CAMERA, COMPONENT_MESSAGING,
+ COMPONENT_PEOPLE};
+
+ PackageManager pm = context.getPackageManager();
+
+ if (!pm.hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
+ sIconComponents[0] = COMPONENT_SETTINGS;
+ } else {
+ // decide on which camera icon to use
+ try {
+ if (pm.getPackageInfo(CAMERA_NEXT_PACKAGE, 0) != null) {
+ sIconComponents[0] = COMPONENT_CAMERANEXT;
+ }
+ } catch (PackageManager.NameNotFoundException e) {
+ // default to COMPONENT_CAMERA
+ }
+ }
+ }
+ return sIconComponents;
+ }
}
diff --git a/src/org/cyanogenmod/theme/util/IconPreviewHelper.java b/src/org/cyanogenmod/theme/util/IconPreviewHelper.java
index a0b5709..ce85fd1 100644
--- a/src/org/cyanogenmod/theme/util/IconPreviewHelper.java
+++ b/src/org/cyanogenmod/theme/util/IconPreviewHelper.java
@@ -131,7 +131,7 @@ public class IconPreviewHelper {
* @param activityName
* @return
*/
- private Drawable getDefaultIcon(String pkgName, String activityName) {
+ public Drawable getDefaultIcon(String pkgName, String activityName) {
Drawable drawable = null;
ComponentName component = new ComponentName(pkgName, activityName);
PackageManager pm = mContext.getPackageManager();