diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/com/cyngn/theme/chooser/ChooserActivity.java | 22 | ||||
-rw-r--r-- | src/com/cyngn/theme/chooser/ComponentSelector.java | 84 | ||||
-rw-r--r-- | src/com/cyngn/theme/chooser/MyThemeFragment.java | 20 | ||||
-rw-r--r-- | src/com/cyngn/theme/chooser/ThemeFragment.java | 51 |
4 files changed, 133 insertions, 44 deletions
diff --git a/src/com/cyngn/theme/chooser/ChooserActivity.java b/src/com/cyngn/theme/chooser/ChooserActivity.java index a40a338..1158782 100644 --- a/src/com/cyngn/theme/chooser/ChooserActivity.java +++ b/src/com/cyngn/theme/chooser/ChooserActivity.java @@ -44,6 +44,7 @@ import android.support.v4.view.ViewPager; import android.text.TextUtils; import android.util.DisplayMetrics; import android.util.Log; +import android.util.MutableLong; import android.util.TypedValue; import android.view.View; import android.view.ViewPropertyAnimator; @@ -66,6 +67,8 @@ import static android.provider.ThemesContract.ThemesColumns.MODIFIES_BOOT_ANIM; import static android.provider.ThemesContract.ThemesColumns.MODIFIES_NOTIFICATIONS; import static android.provider.ThemesContract.ThemesColumns.MODIFIES_RINGTONES; +import static com.cyngn.theme.chooser.ComponentSelector.DEFAULT_COMPONENT_ID; + public class ChooserActivity extends FragmentActivity implements LoaderManager.LoaderCallbacks<Cursor> { public static final String THEME_STORE_PACKAGE = "com.cyngn.themestore"; @@ -138,6 +141,7 @@ public class ChooserActivity extends FragmentActivity // Current system theme configuration as component -> pkgName private Map<String, String> mCurrentTheme = new HashMap<String, String>(); + private MutableLong mCurrentWallpaperCmpntId = new MutableLong(DEFAULT_COMPONENT_ID); private boolean mIsPickingImage = false; private boolean mRestartLoaderOnCollapse = false; @@ -493,10 +497,11 @@ public class ChooserActivity extends FragmentActivity } public void showComponentSelector(String component, View v) { - showComponentSelector(component, null, v); + showComponentSelector(component, null, DEFAULT_COMPONENT_ID, v); } - public void showComponentSelector(String component, String selectedPkgName, View v) { + public void showComponentSelector(String component, String selectedPkgName, + long selectedCmpntId, View v) { if (component != null) { final Resources res = getResources(); int itemsPerPage = res.getInteger(R.integer.default_items_per_page); @@ -513,7 +518,7 @@ public class ChooserActivity extends FragmentActivity R.dimen.component_selection_cell_height_sounds); } if (mSaveApplyLayout.getVisibility() == View.VISIBLE) hideSaveApplyButton(); - mSelector.show(component, selectedPkgName, itemsPerPage, height); + mSelector.show(component, selectedPkgName, selectedCmpntId, itemsPerPage, height); // determine if we need to shift the cards up int[] coordinates = new int[2]; @@ -776,13 +781,19 @@ public class ChooserActivity extends FragmentActivity private void populateCurrentTheme(Cursor c) { c.moveToPosition(-1); + //Default to first wallpaper + mCurrentWallpaperCmpntId.value = DEFAULT_COMPONENT_ID; while(c.moveToNext()) { int mixkeyIdx = c.getColumnIndex(ThemesContract.MixnMatchColumns.COL_KEY); int pkgIdx = c.getColumnIndex(ThemesContract.MixnMatchColumns.COL_VALUE); + int cmpntIdIdx = c.getColumnIndex(ThemesContract.MixnMatchColumns.COL_COMPONENT_ID); String mixkey = c.getString(mixkeyIdx); String component = ThemesContract.MixnMatchColumns.mixNMatchKeyToComponent(mixkey); String pkg = c.getString(pkgIdx); mCurrentTheme.put(component, pkg); + if (cmpntIdIdx >= 0 && TextUtils.equals(component, ThemesColumns.MODIFIES_LAUNCHER)) { + mCurrentWallpaperCmpntId.value = c.getLong(cmpntIdIdx); + } } } @@ -915,15 +926,18 @@ public class ChooserActivity extends FragmentActivity @Override public Fragment getItem(int position) { ThemeFragment f = null; + MutableLong wallpaperCmpntId; if (mInstalledThemes != null) { final String pkgName = mInstalledThemes.get(position); if (pkgName.equals(mAppliedBaseTheme)) { f = MyThemeFragment.newInstance(mAppliedBaseTheme, mAppliedThemeTitle, mAppliedThemeAuthor, mAnimateContentIn); + wallpaperCmpntId = mCurrentWallpaperCmpntId; } else { f = ThemeFragment.newInstance(pkgName, mAnimateContentIn); + wallpaperCmpntId = new MutableLong(DEFAULT_COMPONENT_ID); } - f.setCurrentTheme(mCurrentTheme); + f.setCurrentTheme(mCurrentTheme, wallpaperCmpntId); } return f; } diff --git a/src/com/cyngn/theme/chooser/ComponentSelector.java b/src/com/cyngn/theme/chooser/ComponentSelector.java index 7423dde..d47c47a 100644 --- a/src/com/cyngn/theme/chooser/ComponentSelector.java +++ b/src/com/cyngn/theme/chooser/ComponentSelector.java @@ -13,6 +13,7 @@ import android.graphics.Typeface; import android.graphics.drawable.BitmapDrawable; import android.media.MediaPlayer; import android.media.RingtoneManager; +import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; import android.provider.Settings; @@ -23,6 +24,7 @@ import android.support.v4.app.FragmentActivity; import android.support.v4.app.LoaderManager; import android.support.v4.content.CursorLoader; import android.support.v4.content.Loader; +import android.text.TextUtils; import android.util.AttributeSet; import android.util.Log; import android.view.LayoutInflater; @@ -76,6 +78,8 @@ public class ComponentSelector extends LinearLayout private static final int EXTRA_WALLPAPER_COMPONENTS = 2; + protected static final long DEFAULT_COMPONENT_ID = 0; + private Context mContext; private LayoutInflater mInflater; private ComponentSelectorLinearLayout mContent; @@ -88,6 +92,7 @@ public class ComponentSelector extends LinearLayout private int mItemsPerPage; private String mAppliedComponentPkgName; private String mSelectedComponentPkgName; + private long mSelectedComponentId; // animations for bringing selector in and out of view private Animation mAnimateIn; @@ -171,11 +176,17 @@ public class ComponentSelector extends LinearLayout } public void setComponentType(String component) { - setComponentType(component, null); + setComponentType(component, null, DEFAULT_COMPONENT_ID); } public void setComponentType(String component, String selectedPkgName) { + setComponentType(component, null, DEFAULT_COMPONENT_ID); + } + + public void setComponentType(String component, String selectedPkgName, + long selectedComponentId) { mSelectedComponentPkgName = selectedPkgName; + mSelectedComponentId = selectedComponentId; if (mComponentType == null || !mComponentType.equals(component)) { mContent.removeAllViews(); mComponentType = component; @@ -190,8 +201,12 @@ public class ComponentSelector extends LinearLayout // The child itself may have the tag, or in the case of sounds its the grandchild, // either way the parent of the textview will have the pkgName in its tag final View viewWithTag = (View) tv.getParent(); - final String pkgName = (String) viewWithTag.getTag(); - if (pkgName.equals(selectedPkgName)) { + final String pkgName = (String) viewWithTag.getTag(R.id.tag_key_package_name); + Long cmpntId = (Long) viewWithTag.getTag(R.id.tag_key_component_id); + if (cmpntId == null) { + cmpntId = DEFAULT_COMPONENT_ID; + } + if (pkgName.equals(selectedPkgName) && cmpntId == selectedComponentId) { tv.setTextColor(res.getColor(R.color.component_selection_current_text_color)); } else { tv.setTextColor(res.getColor(android.R.color.white)); @@ -224,9 +239,14 @@ public class ComponentSelector extends LinearLayout } public void show(String componentType, String selectedPkgName, int itemsPerPage, int height) { + show(componentType, selectedPkgName, DEFAULT_COMPONENT_ID, itemsPerPage, height); + } + + public void show(String componentType, String selectedPkgName, long selectedComponentId, + int itemsPerPage, int height) { setNumItemsPerPage(itemsPerPage); setHeight(height); - setComponentType(componentType, selectedPkgName); + setComponentType(componentType, selectedPkgName, selectedComponentId); show(); } @@ -285,6 +305,7 @@ public class ComponentSelector extends LinearLayout @Override public Loader<Cursor> onCreateLoader(int id, Bundle args) { + Uri uri = PreviewColumns.CONTENT_URI; String selection; String[] selectionArgs = { "1" }; String[] projection = { ThemesColumns.TITLE, ThemesColumns.PKG_NAME }; @@ -332,11 +353,13 @@ public class ComponentSelector extends LinearLayout }; break; case LOADER_ID_WALLPAPER: + uri = PreviewColumns.COMPONENTS_URI; selection = MODIFIES_LAUNCHER + "=?"; projection = new String[] { PreviewColumns.WALLPAPER_THUMBNAIL, ThemesColumns.TITLE, - ThemesColumns.PKG_NAME + ThemesColumns.PKG_NAME, + PreviewColumns.COMPONENT_ID }; break; case LOADER_ID_BOOTANIMATIONS: @@ -361,7 +384,8 @@ public class ComponentSelector extends LinearLayout projection = new String[] { PreviewColumns.LOCK_WALLPAPER_THUMBNAIL, ThemesColumns.TITLE, - ThemesColumns.PKG_NAME + ThemesColumns.PKG_NAME, + PreviewColumns.COMPONENT_ID }; break; default: @@ -370,8 +394,7 @@ public class ComponentSelector extends LinearLayout // sort in ascending order but make sure the "default" theme is always first String sortOrder = "(" + ThemesContract.ThemesColumns.IS_DEFAULT_THEME + "=1) DESC, " + ThemesContract.ThemesColumns.TITLE + " ASC"; - return new CursorLoader(mContext, PreviewColumns.CONTENT_URI, - projection, selection, selectionArgs, sortOrder); + return new CursorLoader(mContext, uri, projection, selection, selectionArgs, sortOrder); } @Override @@ -486,7 +509,7 @@ public class ComponentSelector extends LinearLayout setTitle(((TextView) v.findViewById(R.id.title)), cursor); v.findViewById(R.id.container).setBackground( new BitmapDrawable(Utils.loadBitmapBlob(cursor, backgroundIndex))); - v.setTag(cursor.getString(pkgNameIndex)); + v.setTag(R.id.tag_key_package_name, cursor.getString(pkgNameIndex)); v.setOnClickListener(mItemClickListener); return v; } @@ -504,7 +527,7 @@ public class ComponentSelector extends LinearLayout setTitle(((TextView) v.findViewById(R.id.title)), cursor); v.findViewById(R.id.container).setBackground( new BitmapDrawable(Utils.loadBitmapBlob(cursor, backgroundIndex))); - v.setTag(cursor.getString(pkgNameIndex)); + v.setTag(R.id.tag_key_package_name, cursor.getString(pkgNameIndex)); v.setOnClickListener(mItemClickListener); return v; } @@ -522,7 +545,7 @@ public class ComponentSelector extends LinearLayout preview.setTypeface(typefaceNormal); setTitle(((TextView) v.findViewById(R.id.title)), cursor); - v.setTag(cursor.getString(pkgNameIndex)); + v.setTag(R.id.tag_key_package_name, cursor.getString(pkgNameIndex)); v.setOnClickListener(mItemClickListener); return v; } @@ -537,7 +560,7 @@ public class ComponentSelector extends LinearLayout ((ImageView) v.findViewById(R.id.icon)).setImageBitmap( Utils.loadBitmapBlob(cursor, iconIndex)); setTitle(((TextView) v.findViewById(R.id.title)), cursor); - v.setTag(cursor.getString(pkgNameIndex)); + v.setTag(R.id.tag_key_package_name, cursor.getString(pkgNameIndex)); v.setOnClickListener(mItemClickListener); return v; } @@ -552,7 +575,7 @@ public class ComponentSelector extends LinearLayout ((ImageView) v.findViewById(R.id.icon)).setImageBitmap( Utils.loadBitmapBlob(cursor, styleIndex)); setTitle(((TextView) v.findViewById(R.id.title)), cursor); - v.setTag(cursor.getString(pkgNameIndex)); + v.setTag(R.id.tag_key_package_name, cursor.getString(pkgNameIndex)); v.setOnClickListener(mItemClickListener); return v; } @@ -564,20 +587,22 @@ public class ComponentSelector extends LinearLayout ImageView iv = (ImageView) v.findViewById(R.id.icon); if (position == 0) { iv.setImageResource(R.drawable.img_wallpaper_none); - v.setTag(""); + v.setTag(R.id.tag_key_package_name, ""); ((TextView) v.findViewById(R.id.title)).setText(R.string.wallpaper_none_title); } else if (position == 1) { iv.setImageResource(R.drawable.img_wallpaper_external); - v.setTag(EXTERNAL_WALLPAPER); + v.setTag(R.id.tag_key_package_name, EXTERNAL_WALLPAPER); ((TextView) v.findViewById(R.id.title)) .setText(R.string.wallpaper_external_title); } else { cursor.moveToPosition(position - EXTRA_WALLPAPER_COMPONENTS); int pkgNameIndex = cursor.getColumnIndex(ThemesContract.ThemesColumns.PKG_NAME); + int cmpntIdIndex = cursor.getColumnIndex(PreviewColumns.COMPONENT_ID); iv.setImageBitmap( Utils.loadBitmapBlob(cursor, wallpaperIndex)); setTitle(((TextView) v.findViewById(R.id.title)), cursor); - v.setTag(cursor.getString(pkgNameIndex)); + v.setTag(R.id.tag_key_package_name, cursor.getString(pkgNameIndex)); + v.setTag(R.id.tag_key_component_id, cursor.getLong(cmpntIdIndex)); } v.setOnClickListener(mItemClickListener); return v; @@ -593,7 +618,7 @@ public class ComponentSelector extends LinearLayout ((ImageView) v.findViewById(R.id.preview)).setImageBitmap( Utils.loadBitmapBlob(cursor, wallpaperIndex)); setTitle(((TextView) v.findViewById(R.id.title)), cursor); - v.setTag(cursor.getString(pkgNameIndex)); + v.setTag(R.id.tag_key_package_name, cursor.getString(pkgNameIndex)); v.setOnClickListener(mItemClickListener); return v; } @@ -612,7 +637,7 @@ public class ComponentSelector extends LinearLayout final int pkgNameIndex = cursor.getColumnIndex(ThemesContract.ThemesColumns.PKG_NAME); setTitle(((TextView) v.findViewById(R.id.title)), cursor); - v.setTag(cursor.getString(pkgNameIndex)); + v.setTag(R.id.tag_key_package_name, cursor.getString(pkgNameIndex)); v.setOnClickListener(mItemClickListener); container.addView(v, mSoundItemParams); final View playButton = v.findViewById(R.id.play_button); @@ -621,7 +646,7 @@ public class ComponentSelector extends LinearLayout @Override public void onClick(View v) { int type; - String pkgName = (String) v.getTag(); + String pkgName = (String) v.getTag(R.id.tag_key_package_name); if (component.equals(MODIFIES_RINGTONES)) { type = RingtoneManager.TYPE_RINGTONE; } else if (component.equals(MODIFIES_NOTIFICATIONS)) { @@ -686,13 +711,18 @@ public class ComponentSelector extends LinearLayout private void setTitle(TextView titleView, Cursor cursor) { String pkgName = cursor.getString(cursor.getColumnIndex(ThemesColumns.PKG_NAME)); + int cmpntIdIndex = cursor.getColumnIndex(PreviewColumns.COMPONENT_ID); + long cmpntId = DEFAULT_COMPONENT_ID; + if (cmpntIdIndex >= 0) { + cmpntId = cursor.getLong(cmpntIdIndex); + } if (ThemeUtils.getDefaultThemePackageName(mContext).equals(pkgName)) { titleView.setText(mContext.getString(R.string.default_tag_text)); titleView.setTypeface(titleView.getTypeface(), Typeface.BOLD); } else { titleView.setText(cursor.getString(cursor.getColumnIndex(ThemesColumns.TITLE))); } - if (pkgName.equals(mSelectedComponentPkgName)) { + if (pkgName.equals(mSelectedComponentPkgName) && cmpntId == mSelectedComponentId) { titleView.setTextColor(getResources().getColor( R.color.component_selection_current_text_color)); } @@ -701,12 +731,18 @@ public class ComponentSelector extends LinearLayout private OnClickListener mItemClickListener = new OnClickListener() { @Override public void onClick(View v) { - String pkgName = (String) v.getTag(); + long cmpntId = DEFAULT_COMPONENT_ID; + String pkgName = (String) v.getTag(R.id.tag_key_package_name); + Long cmpntIdTag = (Long) v.getTag(R.id.tag_key_component_id); + if (cmpntIdTag != null) { + cmpntId = cmpntIdTag; + } if (DEBUG_SELECTOR) Toast.makeText(mContext, pkgName, Toast.LENGTH_SHORT).show(); if (mListener != null && (!pkgName.equals(mSelectedComponentPkgName) || - pkgName.equals(EXTERNAL_WALLPAPER))) { + pkgName.equals(EXTERNAL_WALLPAPER) || cmpntId != mSelectedComponentId)) { mSelectedComponentPkgName = pkgName; - mListener.onItemClicked(pkgName); + mSelectedComponentId = cmpntId; + mListener.onItemClicked(pkgName, cmpntId); final int count = mContent.getChildCount(); final Resources res = getResources(); for (int i = 0; i < count; i++) { @@ -726,7 +762,7 @@ public class ComponentSelector extends LinearLayout }; public interface OnItemClickedListener { - public void onItemClicked(String pkgName); + public void onItemClicked(String pkgName, long componentId); } public interface OnOpenCloseListener { diff --git a/src/com/cyngn/theme/chooser/MyThemeFragment.java b/src/com/cyngn/theme/chooser/MyThemeFragment.java index b1cfa89..d1c14a1 100644 --- a/src/com/cyngn/theme/chooser/MyThemeFragment.java +++ b/src/com/cyngn/theme/chooser/MyThemeFragment.java @@ -29,6 +29,7 @@ import android.provider.ThemesContract.ThemesColumns; import android.support.v4.content.CursorLoader; import android.support.v4.content.Loader; import android.util.Log; +import android.util.MutableLong; import android.view.Gravity; import android.view.LayoutInflater; import android.view.MenuItem; @@ -38,7 +39,6 @@ import android.view.ViewGroup; import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.TextView; -import com.cyngn.theme.chooser.ThemeFragment; import com.cyngn.theme.util.AudioUtils; import com.cyngn.theme.util.PreferenceUtils; import com.cyngn.theme.util.ThemedTypefaceHelper; @@ -51,6 +51,8 @@ import java.util.Iterator; import java.util.List; import java.util.Map; +import static com.cyngn.theme.chooser.ComponentSelector.DEFAULT_COMPONENT_ID; + public class MyThemeFragment extends ThemeFragment { private static final String TAG = MyThemeFragment.class.getSimpleName(); @@ -179,11 +181,13 @@ public class MyThemeFragment extends ThemeFragment { } @Override - public void setCurrentTheme(Map<String, String> currentTheme) { - super.setCurrentTheme(currentTheme); + public void setCurrentTheme(Map<String, String> currentTheme, + MutableLong currentWallpaperComponentId) { + super.setCurrentTheme(currentTheme, currentWallpaperComponentId); for (String key : currentTheme.keySet()) { mSelectedComponentsMap.put(key, currentTheme.get(key)); } + mSelectedWallpaperComponentId = currentWallpaperComponentId.value; } @Override @@ -196,6 +200,10 @@ public class MyThemeFragment extends ThemeFragment { if (current == null || !current.equals(mSelectedComponentsMap.get(key))) { return true; } + if (ThemesColumns.MODIFIES_LAUNCHER.equals(key) && + mCurrentWallpaperComponentId.value != mSelectedWallpaperComponentId) { + return true; + } } return false; } @@ -266,7 +274,8 @@ public class MyThemeFragment extends ThemeFragment { private void loadComponentsToApply() { for (String component : mSelectedComponentsMap.keySet()) { - loadComponentFromPackage(mSelectedComponentsMap.get(component), component); + loadComponentFromPackage(mSelectedComponentsMap.get(component), component, + mSelectedWallpaperComponentId); } } @@ -397,7 +406,8 @@ public class MyThemeFragment extends ThemeFragment { for (String component : mSelectedComponentsMap.keySet()) { String currentPkg = mCurrentTheme.get(component); String selectedPkg = mSelectedComponentsMap.get(component); - if (currentPkg == null || mThemeResetting || !currentPkg.equals(selectedPkg)) { + if (currentPkg == null || mThemeResetting || !currentPkg.equals(selectedPkg) || + mCurrentWallpaperComponentId.value != mSelectedWallpaperComponentId) { componentsToApply.put(component, selectedPkg); } } diff --git a/src/com/cyngn/theme/chooser/ThemeFragment.java b/src/com/cyngn/theme/chooser/ThemeFragment.java index acec378..c1aa725 100644 --- a/src/com/cyngn/theme/chooser/ThemeFragment.java +++ b/src/com/cyngn/theme/chooser/ThemeFragment.java @@ -48,6 +48,7 @@ import android.support.v4.content.CursorLoader; import android.support.v4.content.Loader; import android.text.TextUtils; import android.util.Log; +import android.util.MutableLong; import android.util.SparseArray; import android.view.Display; import android.view.Gravity; @@ -106,6 +107,8 @@ import static android.provider.ThemesContract.ThemesColumns.MODIFIES_NAVIGATION_ import static android.provider.ThemesContract.ThemesColumns.MODIFIES_ICONS; import static android.provider.ThemesContract.ThemesColumns.MODIFIES_FONTS; +import static com.cyngn.theme.chooser.ComponentSelector.DEFAULT_COMPONENT_ID; + import static android.content.pm.ThemeUtils.SYSTEM_TARGET_API; public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallbacks<Cursor>, @@ -163,6 +166,7 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb protected static final int LOADER_ID_ALARM = 11; protected static final String ARG_PACKAGE_NAME = "pkgName"; + protected static final String ARG_COMPONENT_ID = "cmpntId"; protected static final String ARG_SKIP_LOADING_ANIM = "skipLoadingAnim"; protected static ComponentName[] sIconComponents; @@ -243,8 +247,10 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb protected ComponentSelector mSelector; // Supported components for the theme this fragment represents protected Map<String, String> mSelectedComponentsMap = new HashMap<String, String>(); + protected Long mSelectedWallpaperComponentId; // Current system theme configuration as component -> pkgName protected Map<String, String> mCurrentTheme = new HashMap<String, String>(); + protected MutableLong mCurrentWallpaperComponentId = new MutableLong(DEFAULT_COMPONENT_ID); // Set of components available in the base theme protected HashSet<String> mBaseThemeSupportedComponents = new HashSet<String>(); protected Cursor mCurrentCursor; @@ -289,6 +295,7 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb Bundle args = new Bundle(); args.putString(ARG_PACKAGE_NAME, pkgName); args.putBoolean(ARG_SKIP_LOADING_ANIM, skipLoadingAnim); + args.putLong(ARG_COMPONENT_ID, DEFAULT_COMPONENT_ID); f.setArguments(args); return f; } @@ -1188,6 +1195,7 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb mSelectedComponentsMap.clear(); Bundle args = new Bundle(); args.putString(ARG_PACKAGE_NAME, mBaseThemePkgName); + args.putLong(ARG_COMPONENT_ID, DEFAULT_COMPONENT_ID); getLoaderManager().restartLoader(LOADER_ID_ALL, args, this); mThemeResetting = true; } @@ -1195,8 +1203,10 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb @Override public Loader<Cursor> onCreateLoader(int id, Bundle args) { String pkgName = mPkgName; + long componentId = DEFAULT_COMPONENT_ID; if (args != null) { pkgName = args.getString(ARG_PACKAGE_NAME); + componentId = args.getLong(ARG_COMPONENT_ID, DEFAULT_COMPONENT_ID); } Uri uri = ThemesContract.PreviewColumns.CONTENT_URI; String selection = ThemesContract.ThemesColumns.PKG_NAME + "= ?"; @@ -1204,6 +1214,10 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb String[] projection = null; switch (id) { case LOADER_ID_ALL: + // Load all default component previews (component_id == 0) + selection = ThemesContract.ThemesColumns.PKG_NAME + "=? AND " + + PreviewColumns.COMPONENT_ID + "=?"; + selectionArgs = new String[] { pkgName, String.valueOf(DEFAULT_COMPONENT_ID) }; projection = new String[] { ThemesColumns.PKG_NAME, ThemesColumns.TITLE, @@ -1275,10 +1289,16 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb }; break; case LOADER_ID_WALLPAPER: + uri = PreviewColumns.COMPONENTS_URI; + // Load specified wallpaper previews (component_id is specified) + selection = ThemesContract.ThemesColumns.PKG_NAME + "=? AND " + + PreviewColumns.COMPONENT_ID + "=?"; + selectionArgs = new String[] { pkgName, String.valueOf(componentId) }; projection = new String[] { ThemesColumns.PKG_NAME, ThemesColumns.TITLE, - PreviewColumns.WALLPAPER_PREVIEW + PreviewColumns.WALLPAPER_PREVIEW, + PreviewColumns.COMPONENT_ID }; break; case LOADER_ID_NAVIGATION_BAR: @@ -1470,11 +1490,6 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb } } - // if the theme has no lockscreen, set an empty string to indicate "none"; - if (!mSelectedComponentsMap.containsKey(ThemesColumns.MODIFIES_LOCKSCREEN)) { - mSelectedComponentsMap.put(ThemesColumns.MODIFIES_LOCKSCREEN, WALLPAPER_NONE); - } - if (mApplyThemeOnPopulated) { applyTheme(); } @@ -1519,15 +1534,18 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb int pkgNameIdx = c.getColumnIndex(ThemesColumns.PKG_NAME); int wpIdx = c.getColumnIndex(PreviewColumns.WALLPAPER_PREVIEW); + int cmpntIdIdx = c.getColumnIndex(PreviewColumns.COMPONENT_ID); final Resources res = getResources(); Bitmap bitmap = Utils.loadBitmapBlob(c, wpIdx); if (bitmap != null) { mWallpaper.setImageBitmap(bitmap); mWallpaperCard.setWallpaper(new BitmapDrawable(res, bitmap)); String pkgName = c.getString(pkgNameIdx); + Long cmpntId = (cmpntIdIdx >= 0) ? c.getLong(cmpntIdIdx) : DEFAULT_COMPONENT_ID; if (!mPkgName.equals(pkgName) || (mPkgName.equals(pkgName) && mBaseThemeSupportedComponents.contains(MODIFIES_LAUNCHER))) { mSelectedComponentsMap.put(MODIFIES_LAUNCHER, pkgName); + mSelectedWallpaperComponentId = cmpntId; setCardTitle(mWallpaperCard, pkgName, getString(R.string.wallpaper_label)); } } else { @@ -1959,8 +1977,11 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb } mActiveCardId = v.getId(); String component = mCardIdsToComponentTypes.get(mActiveCardId); + // Only pass on mSelectedWallpaperComponentId if dealing with mods_launcher + long selectedComponentId = (ThemesColumns.MODIFIES_LAUNCHER.equals(component)) ? + mSelectedWallpaperComponentId : DEFAULT_COMPONENT_ID; getChooserActivity().showComponentSelector(component, - mSelectedComponentsMap.get(component), v); + mSelectedComponentsMap.get(component), selectedComponentId, v); fadeOutNonSelectedCards(mActiveCardId); stopMediaPlayers(); } @@ -2005,9 +2026,10 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb } }; - protected void loadComponentFromPackage(String pkgName, String component) { + protected void loadComponentFromPackage(String pkgName, String component, long componentId) { Bundle args = new Bundle(); args.putString(ARG_PACKAGE_NAME, pkgName); + args.putLong(ARG_COMPONENT_ID, componentId); int loaderId = LOADER_ID_INVALID; if (MODIFIES_STATUS_BAR.equals(component)) { loaderId = LOADER_ID_STATUS_BAR; @@ -2066,8 +2088,8 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb private OnItemClickedListener mOnComponentItemClicked = new OnItemClickedListener() { @Override - public void onItemClicked(String pkgName) { - loadComponentFromPackage(pkgName, mSelector.getComponentType()); + public void onItemClicked(String pkgName, long componentId) { + loadComponentFromPackage(pkgName, mSelector.getComponentType(), componentId); } }; @@ -2150,6 +2172,7 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb builder.setComponent(component, componentMap.get(component)); } builder.setRequestType(requestType); + builder.setWallpaperId(mSelectedWallpaperComponentId); return builder.build(); } @@ -2540,6 +2563,10 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb if (!mPkgName.equals(mSelectedComponentsMap.get(key))) { return true; } + if (ThemesColumns.MODIFIES_LAUNCHER.equals(key) && + mCurrentWallpaperComponentId.value != mSelectedWallpaperComponentId) { + return true; + } } return false; } @@ -2566,8 +2593,10 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb getChooserActivity().uninstallTheme(mPkgName); } - public void setCurrentTheme(Map<String, String> currentTheme) { + public void setCurrentTheme(Map<String, String> currentTheme, + MutableLong currentWallpaperComponentId) { mCurrentTheme = currentTheme; + mCurrentWallpaperComponentId = currentWallpaperComponentId; } /** |