diff options
Diffstat (limited to 'src/com/cyngn')
-rw-r--r-- | src/com/cyngn/theme/chooser/ChooserActivity.java | 9 | ||||
-rw-r--r-- | src/com/cyngn/theme/chooser/ComponentSelector.java | 193 | ||||
-rw-r--r-- | src/com/cyngn/theme/chooser/ThemeFragment.java | 98 | ||||
-rw-r--r-- | src/com/cyngn/theme/util/CursorLoaderHelper.java | 56 |
4 files changed, 230 insertions, 126 deletions
diff --git a/src/com/cyngn/theme/chooser/ChooserActivity.java b/src/com/cyngn/theme/chooser/ChooserActivity.java index b395ecc..78a583f 100644 --- a/src/com/cyngn/theme/chooser/ChooserActivity.java +++ b/src/com/cyngn/theme/chooser/ChooserActivity.java @@ -65,7 +65,6 @@ import java.util.Map; import static android.provider.ThemesContract.ThemesColumns.MODIFIES_ALARMS; import static android.provider.ThemesContract.ThemesColumns.MODIFIES_BOOT_ANIM; -import static android.provider.ThemesContract.ThemesColumns.MODIFIES_LIVE_LOCK_SCREEN; import static android.provider.ThemesContract.ThemesColumns.MODIFIES_NOTIFICATIONS; import static android.provider.ThemesContract.ThemesColumns.MODIFIES_RINGTONES; @@ -507,7 +506,7 @@ public class ChooserActivity extends FragmentActivity final Resources res = getResources(); int itemsPerPage = res.getInteger(R.integer.default_items_per_page); int height = res.getDimensionPixelSize(R.dimen.component_selection_cell_height); - if (MODIFIES_BOOT_ANIM.equals(component) || MODIFIES_LIVE_LOCK_SCREEN.equals(component)) { + if (MODIFIES_BOOT_ANIM.equals(component)) { itemsPerPage = res.getInteger(R.integer.bootani_items_per_page); height = res.getDimensionPixelSize( R.dimen.component_selection_cell_height_boot_anim); @@ -792,6 +791,12 @@ public class ChooserActivity extends FragmentActivity String component = ThemesContract.MixnMatchColumns.mixNMatchKeyToComponent(mixkey); String pkg = c.getString(pkgIdx); mCurrentTheme.put(component, pkg); + if (TextUtils.equals(component, ThemesColumns.MODIFIES_LIVE_LOCK_SCREEN)) { + mCurrentTheme.remove(ThemesColumns.MODIFIES_LOCKSCREEN); + } + if (TextUtils.equals(component, ThemesColumns.MODIFIES_LOCKSCREEN)) { + mCurrentTheme.remove(ThemesColumns.MODIFIES_LIVE_LOCK_SCREEN); + } if (cmpntIdIdx >= 0 && TextUtils.equals(component, ThemesColumns.MODIFIES_LAUNCHER)) { mCurrentWallpaperCmpntId.value = c.getLong(cmpntIdIdx); } diff --git a/src/com/cyngn/theme/chooser/ComponentSelector.java b/src/com/cyngn/theme/chooser/ComponentSelector.java index 53a0269..dcf049a 100644 --- a/src/com/cyngn/theme/chooser/ComponentSelector.java +++ b/src/com/cyngn/theme/chooser/ComponentSelector.java @@ -11,6 +11,7 @@ import android.content.res.Resources; import android.content.res.TypedArray; import android.database.ContentObserver; import android.database.Cursor; +import android.database.MatrixCursor; import android.graphics.Typeface; import android.graphics.drawable.BitmapDrawable; import android.media.MediaPlayer; @@ -60,7 +61,6 @@ 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.util.CursorLoaderHelper.LOADER_ID_LIVE_LOCK_SCREEN; import static com.cyngn.theme.util.CursorLoaderHelper.LOADER_ID_STATUS_BAR; import static com.cyngn.theme.util.CursorLoaderHelper.LOADER_ID_FONT; import static com.cyngn.theme.util.CursorLoaderHelper.LOADER_ID_ICONS; @@ -82,7 +82,6 @@ public class ComponentSelector extends LinearLayout public static final String EXTERNAL_WALLPAPER = "external"; private static final int EXTRA_WALLPAPER_COMPONENTS = 2; - private static final int EXTRA_LIVE_LOCK_COMPONENTS = 1; protected static final long DEFAULT_COMPONENT_ID = 0; @@ -111,12 +110,13 @@ public class ComponentSelector extends LinearLayout private MediaPlayer mMediaPlayer; private ImageView mCurrentPlayPause; - private int mCurrentLoaderId; - private TypefaceHelperCache mTypefaceCache; private ThemesObserver mThemesObserver; + public static final String IS_LIVE_LOCK_SCREEN_VIEW = "is_live_lock_screen_view"; + private View mPrevLockScreenView; + public ComponentSelector(Context context, AttributeSet attrs) { super(context, attrs); @@ -322,9 +322,6 @@ public class ComponentSelector extends LinearLayout if (MODIFIES_LOCKSCREEN.equals(component)) { return LOADER_ID_LOCKSCREEN; } - if (MODIFIES_LIVE_LOCK_SCREEN.equals(component)) { - return LOADER_ID_LIVE_LOCK_SCREEN; - } return -1; } @@ -335,13 +332,15 @@ public class ComponentSelector extends LinearLayout @Override public void onLoadFinished(Loader<Cursor> loader, final Cursor data) { - mCurrentLoaderId = loader.getId(); + int currentLoaderId = loader.getId(); int count = data.getCount(); int screenWidth = mContext.getResources().getDisplayMetrics().widthPixels; final Resources res = getResources(); int dividerPadding = res.getDimensionPixelSize(R.dimen.component_divider_padding_top); int dividerHeight = res.getDimensionPixelSize(R.dimen.component_divider_height); - switch (mCurrentLoaderId) { + MatrixCursor lockScreenMatrixCursor = null; + + switch (currentLoaderId) { case LOADER_ID_ALARM: case LOADER_ID_NOTIFICATION: case LOADER_ID_RINGTONE: @@ -355,21 +354,25 @@ public class ComponentSelector extends LinearLayout mContent.setShowDividers(LinearLayout.SHOW_DIVIDER_NONE); break; case LOADER_ID_BOOT_ANIMATION: - case LOADER_ID_LIVE_LOCK_SCREEN: dividerPadding = res.getDimensionPixelSize( R.dimen.component_divider_padding_top_bootani); dividerHeight = res.getDimensionPixelSize(R.dimen.component_divider_height_bootani); - if (mCurrentLoaderId == LOADER_ID_LIVE_LOCK_SCREEN) { - count += EXTRA_LIVE_LOCK_COMPONENTS; - } // fall through to default default: mItemParams = new LayoutParams(screenWidth / mItemsPerPage, ViewGroup.LayoutParams.MATCH_PARENT); - if (mCurrentLoaderId == LOADER_ID_WALLPAPER || - mCurrentLoaderId == LOADER_ID_LOCKSCREEN) { + if (currentLoaderId == LOADER_ID_WALLPAPER || + currentLoaderId == LOADER_ID_LOCKSCREEN) { count += EXTRA_WALLPAPER_COMPONENTS; } + + if (currentLoaderId == LOADER_ID_LOCKSCREEN) { + lockScreenMatrixCursor = splitLockScreenCursor(data); + if (lockScreenMatrixCursor != null) { + count = lockScreenMatrixCursor.getCount() + EXTRA_WALLPAPER_COMPONENTS; + } + } + mContent.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE); break; } @@ -377,7 +380,89 @@ public class ComponentSelector extends LinearLayout mContent.setDividerPadding(dividerPadding); mContent.setDividerHeight(dividerHeight); - new LoadItemsTask().execute(data ,count); + new LoadItemsTask().execute((lockScreenMatrixCursor != null) + ? lockScreenMatrixCursor : data, count); + } + + /* Some themes might contain a lock wallpaper AND a live lock screen. + * ThemesProvider will return one single row containing both thumbnail paths + * (ThemesProvider groups by theme_id) so we need to create a cursor on the + * fly to split that row into 2 to properly generate a view for each thumbnail + */ + private MatrixCursor splitLockScreenCursor(Cursor data) { + int lockWallPaperThumbnailIndx, llsThumbnailIndx, pkgIndx; + String lockWallPaperThumbnail, liveLockScreenThumbnail, pkgName; + MatrixCursor lockScreenMatrixCursor; + int needToSplitRowAt = -1; + + lockWallPaperThumbnailIndx = data.getColumnIndex(PreviewColumns.LOCK_WALLPAPER_THUMBNAIL); + llsThumbnailIndx = data.getColumnIndex(PreviewColumns.LIVE_LOCK_SCREEN_THUMBNAIL); + pkgIndx = data.getColumnIndex(ThemesColumns.PKG_NAME); + + if (lockWallPaperThumbnailIndx < 0 || llsThumbnailIndx < 0 || pkgIndx < 0) { + //An invalid cursor was provided, we can't continue processing + Log.e(TAG, "Failed to process cursor due to missing columns"); + return null; + } + + //Let's find out if we really need to allocate a MatrixCursor. + //If we find at least one row with valid data in lock_wallpaper_thumbnail AND + //live_lock_screen_thumbnail it means we do. + data.moveToPosition(-1); + while (data.moveToNext()) { + lockWallPaperThumbnail = data.getString(lockWallPaperThumbnailIndx); + liveLockScreenThumbnail = data.getString(llsThumbnailIndx); + if (!TextUtils.isEmpty(lockWallPaperThumbnail) + && !TextUtils.isEmpty(liveLockScreenThumbnail)) { + needToSplitRowAt = data.getPosition(); + break; + } + } + + if (needToSplitRowAt == -1) return null; + + lockScreenMatrixCursor = new MatrixCursor(data.getColumnNames()); + //Clone all the *regular* rows up to needToSplitRowAt + for (int indx = 0; indx < needToSplitRowAt; indx++) { + data.moveToPosition(indx); + lockScreenMatrixCursor.addRow(CursorLoaderHelper.getRowFromCursor(data)); + } + while (data.moveToNext()) { + lockWallPaperThumbnail = data.getString(lockWallPaperThumbnailIndx); + liveLockScreenThumbnail = data.getString(llsThumbnailIndx); + if (!TextUtils.isEmpty(lockWallPaperThumbnail) + && !TextUtils.isEmpty(liveLockScreenThumbnail)) { + pkgName = data.getString(pkgIndx); + + MatrixCursor.RowBuilder lockWallpaperRow = lockScreenMatrixCursor.newRow(); + MatrixCursor.RowBuilder liveLockScreenRow = lockScreenMatrixCursor.newRow(); + + for (String col : data.getColumnNames()) { + if (TextUtils.equals(col, PreviewColumns.LOCK_WALLPAPER_THUMBNAIL)) { + lockWallpaperRow.add(PreviewColumns.LOCK_WALLPAPER_THUMBNAIL, + lockWallPaperThumbnail); + liveLockScreenRow.add(PreviewColumns.LOCK_WALLPAPER_THUMBNAIL, null); + } else if (TextUtils.equals(col, PreviewColumns.LIVE_LOCK_SCREEN_THUMBNAIL)) { + lockWallpaperRow.add(PreviewColumns.LIVE_LOCK_SCREEN_THUMBNAIL, null); + liveLockScreenRow.add(PreviewColumns.LIVE_LOCK_SCREEN_THUMBNAIL, + liveLockScreenThumbnail); + } else if (TextUtils.equals(col, MODIFIES_LIVE_LOCK_SCREEN)) { + lockWallpaperRow.add(MODIFIES_LIVE_LOCK_SCREEN, 0); + liveLockScreenRow.add(MODIFIES_LIVE_LOCK_SCREEN, 1); + } else { + int colIndx = data.getColumnIndex(col); + lockWallpaperRow.add(col, CursorLoaderHelper.getFieldValueFromRow(data, + colIndx)); + liveLockScreenRow.add(col, CursorLoaderHelper.getFieldValueFromRow(data, + colIndx)); + } + } + } else { + //This is a regular row, so just clone it + lockScreenMatrixCursor.addRow(CursorLoaderHelper.getRowFromCursor(data)); + } + } + return lockScreenMatrixCursor; } @Override @@ -410,7 +495,7 @@ public class ComponentSelector extends LinearLayout } if (MODIFIES_LAUNCHER.equals(mComponentType)) { return newWallpapersView(cursor, container, position, - cursor.getColumnIndex(PreviewColumns.WALLPAPER_THUMBNAIL)); + cursor.getColumnIndex(PreviewColumns.WALLPAPER_THUMBNAIL), false); } if (MODIFIES_BOOT_ANIM.equals(mComponentType)) { return newBootanimationView(cursor, container, position); @@ -421,11 +506,17 @@ public class ComponentSelector extends LinearLayout return newSoundView(cursor, container, position, mComponentType); } if (MODIFIES_LOCKSCREEN.equals(mComponentType)) { - return newWallpapersView(cursor, container, position, - cursor.getColumnIndex(PreviewColumns.LOCK_WALLPAPER_THUMBNAIL)); - } - if (MODIFIES_LIVE_LOCK_SCREEN.equals(mComponentType)) { - return newLiveLockScreenView(cursor, container, position); + boolean isLiveLockScreen = false; + if (position >= EXTRA_WALLPAPER_COMPONENTS) { + cursor.moveToPosition(position - EXTRA_WALLPAPER_COMPONENTS); + int liveLockIndex = cursor.getColumnIndex(MODIFIES_LIVE_LOCK_SCREEN); + isLiveLockScreen = liveLockIndex >= 0 && + cursor.getInt(liveLockIndex) == 1; + } + int index = isLiveLockScreen + ? cursor.getColumnIndex(PreviewColumns.LIVE_LOCK_SCREEN_THUMBNAIL) + : cursor.getColumnIndex(PreviewColumns.LOCK_WALLPAPER_THUMBNAIL); + return newWallpapersView(cursor, container, position, index, isLiveLockScreen); } return null; } @@ -524,7 +615,7 @@ public class ComponentSelector extends LinearLayout } private View newWallpapersView(Cursor cursor, ViewGroup parent, int position, - int wallpaperIndex) { + int wallpaperIndex, boolean isLiveLockScreen) { View v = mInflater.inflate(R.layout.wallpaper_component_selection_item, parent, false); ImageView iv = (ImageView) v.findViewById(R.id.icon); @@ -548,6 +639,9 @@ public class ComponentSelector extends LinearLayout setTitle(((TextView) v.findViewById(R.id.title)), cursor); v.setTag(R.id.tag_key_package_name, cursor.getString(pkgNameIndex)); v.setTag(R.id.tag_key_component_id, cmpntId); + v.setTag(R.id.tag_key_live_lock_screen, isLiveLockScreen); + v.findViewById(R.id.live_lock_screen_ribbon) + .setVisibility(isLiveLockScreen ? View.VISIBLE : View.GONE); } v.setOnClickListener(mItemClickListener); return v; @@ -627,28 +721,6 @@ public class ComponentSelector extends LinearLayout return container; } - private View newLiveLockScreenView(Cursor cursor, ViewGroup parent, int position) { - View v = mInflater.inflate(R.layout.live_lock_component_selection_item, parent, - false); - ImageView iv = (ImageView) v.findViewById(R.id.icon); - if (position == 0) { - iv.setImageResource(R.drawable.img_wallpaper_none); - v.setTag(R.id.tag_key_package_name,""); - ((TextView) v.findViewById(R.id.title)).setText(R.string.wallpaper_none_title); - } else { - cursor.moveToPosition(position - EXTRA_LIVE_LOCK_COMPONENTS); - int wallpaperIndex = cursor.getColumnIndex(PreviewColumns.LIVE_LOCK_SCREEN_THUMBNAIL); - int pkgNameIndex = cursor.getColumnIndex(ThemesContract.ThemesColumns.PKG_NAME); - - iv.setImageBitmap( - Utils.loadBitmapBlob(cursor, wallpaperIndex)); - setTitle(((TextView) v.findViewById(R.id.title)), cursor); - v.setTag(R.id.tag_key_package_name, cursor.getString(pkgNameIndex)); - } - v.setOnClickListener(mItemClickListener); - return v; - } - private class LoadItemsTask extends AsyncTask<Object, Void, Void> { @Override @@ -664,6 +736,11 @@ public class ComponentSelector extends LinearLayout } }); } + + if (c instanceof MatrixCursor) { + c.close(); + } + // destroy the loader now that we are done with it ComponentSelector.this.post(new Runnable() { @Override @@ -704,12 +781,25 @@ public class ComponentSelector extends LinearLayout if (cmpntIdTag != null) { cmpntId = cmpntIdTag; } + Boolean isLiveLock = (Boolean) v.getTag(R.id.tag_key_live_lock_screen); + boolean isSamePkgButDifferentLockScreen = false; + Bundle params = null; + if (isLiveLock != null) { + params = new Bundle(); + params.putBoolean(IS_LIVE_LOCK_SCREEN_VIEW, isLiveLock); + + if (pkgName.equals(mSelectedComponentPkgName) && v != mPrevLockScreenView) { + isSamePkgButDifferentLockScreen = true; + } + mPrevLockScreenView = v; + } if (DEBUG_SELECTOR) Toast.makeText(mContext, pkgName, Toast.LENGTH_SHORT).show(); - if (mListener != null && (!pkgName.equals(mSelectedComponentPkgName) || + if (mListener != null && (isSamePkgButDifferentLockScreen || + !pkgName.equals(mSelectedComponentPkgName) || pkgName.equals(EXTERNAL_WALLPAPER) || cmpntId != mSelectedComponentId)) { mSelectedComponentPkgName = pkgName; mSelectedComponentId = cmpntId; - mListener.onItemClicked(pkgName, cmpntId); + mListener.onItemClicked(pkgName, cmpntId, params); final int count = mContent.getChildCount(); final Resources res = getResources(); for (int i = 0; i < count; i++) { @@ -747,12 +837,17 @@ public class ComponentSelector extends LinearLayout // reload items by calling setComponentType() final String componentType = mComponentType; mComponentType = null; - setComponentType(componentType, mSelectedComponentPkgName); + mContent.post(new Runnable() { + @Override + public void run() { + setComponentType(componentType, mSelectedComponentPkgName); + } + }); } } public interface OnItemClickedListener { - public void onItemClicked(String pkgName, long componentId); + public void onItemClicked(String pkgName, long componentId, Bundle params); } public interface OnOpenCloseListener { diff --git a/src/com/cyngn/theme/chooser/ThemeFragment.java b/src/com/cyngn/theme/chooser/ThemeFragment.java index 4dd4148..641651b 100644 --- a/src/com/cyngn/theme/chooser/ThemeFragment.java +++ b/src/com/cyngn/theme/chooser/ThemeFragment.java @@ -225,7 +225,6 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb protected ComponentCardView mFontCard; protected ComponentCardView mIconCard; protected ComponentCardView mBootAnimationCard; - protected ComponentCardView mLiveLockScreenCard; protected BootAniImageView mBootAnimation; // Nav Bar Views @@ -254,9 +253,6 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb // Style views protected ImageView mStylePreview; - // Live lock screen view - protected ImageView mLiveLockScreenView; - // Sound cards protected ComponentCardView mRingtoneCard; protected ImageView mRingtonePlayPause; @@ -360,8 +356,6 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb mCardIdsToComponentTypes.put(R.id.ringtone_preview_container, MODIFIES_RINGTONES); mCardIdsToComponentTypes.put(R.id.notification_preview_container, MODIFIES_NOTIFICATIONS); mCardIdsToComponentTypes.put(R.id.alarm_preview_container, MODIFIES_ALARMS); - mCardIdsToComponentTypes.put(R.id.live_lock_screen_preview_container, - MODIFIES_LIVE_LOCK_SCREEN); mMediaPlayers = new HashMap<ImageView, MediaPlayer>(3); } @@ -491,9 +485,6 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb mWallpaperCard = (WallpaperCardView) v.findViewById(R.id.wallpaper_card); mLockScreenCard = (WallpaperCardView) v.findViewById(R.id.lockscreen_card); - mLiveLockScreenCard = - (ComponentCardView) v.findViewById(R.id.live_lock_screen_preview_container); - mLiveLockScreenView = (ImageView) v.findViewById(R.id.live_lock_screen_preview); int translationY = getDistanceToMoveBelowScreen(mAdditionalCards); mAdditionalCards.setTranslationY(translationY); @@ -614,7 +605,8 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb }); if (isSuccess) { Map<String, String> appliedComponents = getComponentsToApply(); - if (appliedComponents.get(MODIFIES_LIVE_LOCK_SCREEN) != null) { + String modLLS = appliedComponents.get(MODIFIES_LIVE_LOCK_SCREEN); + if (modLLS != null && !TextUtils.equals(modLLS, "")) { setLiveLockScreenAsKeyguard(); } mProgress.setProgress(100); @@ -1316,6 +1308,7 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb case LOADER_ID_NAVIGATION_BAR: loadNavBar(c, animate); break; + case LOADER_ID_LIVE_LOCK_SCREEN: case LOADER_ID_LOCKSCREEN: loadLockScreen(c, animate); break; @@ -1334,9 +1327,6 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb case LOADER_ID_ALARM: loadAudible(RingtoneManager.TYPE_ALARM, c, animate); break; - case LOADER_ID_LIVE_LOCK_SCREEN: - loadLiveLockScreen(c, animate); - break; } } @@ -1404,14 +1394,6 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb setAddComponentTitle(mAlarmCard, getAudibleLabel(RingtoneManager.TYPE_ALARM)); } - } else if (MODIFIES_LIVE_LOCK_SCREEN.equals(component)) { - if (hasContent) { - loadLiveLockScreen(c, false); - } else { - mLiveLockScreenCard.setEmptyViewEnabled(true); - setAddComponentTitle(mLiveLockScreenCard, - getString(R.string.live_lock_screen_label)); - } } else { throw new IllegalArgumentException("Don't know how to load: " + component); } @@ -1510,16 +1492,30 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb if (mLockScreenCard.isShowingEmptyView()) mLockScreenCard.setEmptyViewEnabled(false); int pkgNameIdx = c.getColumnIndex(ThemesColumns.PKG_NAME); - int wpIdx = c.getColumnIndex(PreviewColumns.LOCK_WALLPAPER_PREVIEW); + int liveLockIndex = c.getColumnIndex(MODIFIES_LIVE_LOCK_SCREEN); + boolean isLiveLockScreen = liveLockIndex >= 0 && c.getInt(liveLockIndex) == 1; + + int wpIdx = isLiveLockScreen + ? c.getColumnIndex(PreviewColumns.LIVE_LOCK_SCREEN_PREVIEW) + : c.getColumnIndex(PreviewColumns.LOCK_WALLPAPER_PREVIEW); final Resources res = getResources(); Bitmap bitmap = Utils.loadBitmapBlob(c, wpIdx); if (bitmap != null) { mLockScreenCard.setWallpaper(new BitmapDrawable(res, bitmap)); String pkgName = c.getString(pkgNameIdx); if (!mPkgName.equals(pkgName) || (mPkgName.equals(pkgName) - && mBaseThemeSupportedComponents.contains(MODIFIES_LOCKSCREEN))) { - mSelectedComponentsMap.put(MODIFIES_LOCKSCREEN, pkgName); - setCardTitle(mLockScreenCard, pkgName, getString(R.string.lockscreen_label)); + && (mBaseThemeSupportedComponents.contains(MODIFIES_LOCKSCREEN) || + mBaseThemeSupportedComponents.contains(MODIFIES_LIVE_LOCK_SCREEN)))) { + if (isLiveLockScreen) { + mSelectedComponentsMap.put(MODIFIES_LOCKSCREEN, ""); + mSelectedComponentsMap.put(MODIFIES_LIVE_LOCK_SCREEN, pkgName); + setCardTitle(mLockScreenCard, pkgName, + getString(R.string.live_lock_screen_label)); + } else { + mSelectedComponentsMap.put(MODIFIES_LOCKSCREEN, pkgName); + mSelectedComponentsMap.put(MODIFIES_LIVE_LOCK_SCREEN, ""); + setCardTitle(mLockScreenCard, pkgName, getString(R.string.lockscreen_label)); + } } } else { // Set the lockscreen wallpaper to "None" @@ -1835,33 +1831,6 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb thread.start(); } - protected void loadLiveLockScreen(Cursor c, boolean animate) { - Drawable overlay = null; - if (animate) { - overlay = getOverlayDrawable(mLiveLockScreenView, false); - } - if (mLiveLockScreenCard.isShowingEmptyView()) { - mLiveLockScreenCard.setEmptyViewEnabled(false); - } - - int pkgNameIdx = c.getColumnIndex(ThemesColumns.PKG_NAME); - int styleIdx = c.getColumnIndex(PreviewColumns.LIVE_LOCK_SCREEN_PREVIEW); - mLiveLockScreenView.setImageBitmap(Utils.loadBitmapBlob(c, styleIdx)); - if (pkgNameIdx > -1) { - String pkgName = c.getString(pkgNameIdx); - if (!mPkgName.equals(pkgName) || (mPkgName.equals(pkgName) - && mBaseThemeSupportedComponents.contains(MODIFIES_LIVE_LOCK_SCREEN))) { - mSelectedComponentsMap.put(MODIFIES_LIVE_LOCK_SCREEN, pkgName); - setCardTitle(mLiveLockScreenCard, pkgName, - getString(R.string.live_lock_screen_label)); - } - } - if (animate) { - animateContentChange(R.id.live_lock_screen_preview_container, mLiveLockScreenView, - overlay); - } - } - protected Drawable getOverlayDrawable(View v, boolean requiresTransparency) { if (!v.isDrawingCacheEnabled()) v.setDrawingCacheEnabled(true); Bitmap cache = v.getDrawingCache(true).copy( @@ -2031,7 +2000,8 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb loaderId = LOADER_ID_WALLPAPER; } } - } else if (MODIFIES_LOCKSCREEN.equals(component)) { + } else if (MODIFIES_LOCKSCREEN.equals(component) + || MODIFIES_LIVE_LOCK_SCREEN.equals(component)) { if (pkgName != null && TextUtils.isEmpty(pkgName)) { mLockScreenCard.setWallpaper(null); mSelectedComponentsMap.put(ThemesColumns.MODIFIES_LOCKSCREEN, WALLPAPER_NONE); @@ -2042,7 +2012,11 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb setCardTitle(mLockScreenCard, WALLPAPER_NONE, getString(R.string.lockscreen_label)); } else { - loaderId = LOADER_ID_LOCKSCREEN; + if (MODIFIES_LIVE_LOCK_SCREEN.equals(component)) { + loaderId = LOADER_ID_LIVE_LOCK_SCREEN; + } else { + loaderId = LOADER_ID_LOCKSCREEN; + } } } else if (MODIFIES_OVERLAYS.equals(component)) { loaderId = LOADER_ID_STYLE; @@ -2054,8 +2028,6 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb loaderId = LOADER_ID_NOTIFICATION; } else if (MODIFIES_ALARMS.equals(component)) { loaderId = LOADER_ID_ALARM; - } else if (MODIFIES_LIVE_LOCK_SCREEN.equals(component)) { - loaderId = LOADER_ID_LIVE_LOCK_SCREEN; } else { return; } @@ -2067,8 +2039,18 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb private OnItemClickedListener mOnComponentItemClicked = new OnItemClickedListener() { @Override - public void onItemClicked(String pkgName, long componentId) { - loadComponentFromPackage(pkgName, mSelector.getComponentType(), componentId); + public void onItemClicked(String pkgName, long componentId, Bundle params) { + String component = mSelector.getComponentType(); + if (MODIFIES_LOCKSCREEN.equals(component) && params != null) { + boolean isLiveLockView = params.getBoolean( + ComponentSelector.IS_LIVE_LOCK_SCREEN_VIEW,false); + if (isLiveLockView) { + //We got here because an live lock thubmnail view was clicked. We need to + //replace the component to load the proper data from the provider. + component = MODIFIES_LIVE_LOCK_SCREEN; + } + } + loadComponentFromPackage(pkgName, component, componentId); } }; diff --git a/src/com/cyngn/theme/util/CursorLoaderHelper.java b/src/com/cyngn/theme/util/CursorLoaderHelper.java index fdbb64f..333899b 100644 --- a/src/com/cyngn/theme/util/CursorLoaderHelper.java +++ b/src/com/cyngn/theme/util/CursorLoaderHelper.java @@ -170,30 +170,27 @@ public class CursorLoaderHelper { selection = MODIFIES_ALARMS + "=?"; break; case LOADER_ID_LOCKSCREEN: - selection = MODIFIES_LOCKSCREEN + "=?"; + selection = MODIFIES_LOCKSCREEN + "=? OR " + MODIFIES_LIVE_LOCK_SCREEN + "=?"; + selectionArgs = new String[] { "1", "1" }; if (mThemeVersion >= 3) { projection = new String[]{ PreviewColumns.LOCK_WALLPAPER_THUMBNAIL, + PreviewColumns.LIVE_LOCK_SCREEN_THUMBNAIL, ThemesColumns.TITLE, ThemesColumns.PKG_NAME, + ThemesColumns.MODIFIES_LIVE_LOCK_SCREEN, PreviewColumns.COMPONENT_ID }; } else { projection = new String[]{ PreviewColumns.LOCK_WALLPAPER_THUMBNAIL, + PreviewColumns.LIVE_LOCK_SCREEN_THUMBNAIL, ThemesColumns.TITLE, + ThemesColumns.MODIFIES_LIVE_LOCK_SCREEN, ThemesColumns.PKG_NAME }; } break; - case LOADER_ID_LIVE_LOCK_SCREEN: - selection = MODIFIES_LIVE_LOCK_SCREEN + "=?"; - projection = new String[] { - PreviewColumns.LIVE_LOCK_SCREEN_THUMBNAIL, - ThemesColumns.TITLE, - ThemesColumns.PKG_NAME - }; - break; default: return null; } @@ -354,7 +351,15 @@ public class CursorLoaderHelper { projection = new String[]{ ThemesColumns.PKG_NAME, ThemesColumns.TITLE, - PreviewColumns.LOCK_WALLPAPER_PREVIEW + PreviewColumns.LOCK_WALLPAPER_PREVIEW, + }; + break; + case LOADER_ID_LIVE_LOCK_SCREEN: + projection = new String[]{ + ThemesColumns.PKG_NAME, + ThemesColumns.TITLE, + ThemesColumns.MODIFIES_LIVE_LOCK_SCREEN, + PreviewColumns.LIVE_LOCK_SCREEN_PREVIEW }; break; case LOADER_ID_STYLE: @@ -378,14 +383,31 @@ public class CursorLoaderHelper { ThemesColumns.TITLE }; break; - case LOADER_ID_LIVE_LOCK_SCREEN: - projection = new String[] { - ThemesColumns.PKG_NAME, - ThemesColumns.TITLE, - PreviewColumns.LIVE_LOCK_SCREEN_PREVIEW - }; - break; } return new CursorLoader(context, uri, projection, selection, selectionArgs, null); } + + public static Object[] getRowFromCursor(Cursor cursor) { + Object[] row = null; + if (cursor != null) { + int colCount = cursor.getColumnCount(); + row = new Object[colCount]; + for (int indx = 0; indx < colCount; indx++) { + row[indx] = getFieldValueFromRow(cursor, indx); + } + } + return row; + } + + public static Object getFieldValueFromRow(Cursor cursor, int position) { + switch (cursor.getType(position)) { + case Cursor.FIELD_TYPE_BLOB: return cursor.getBlob(position); + case Cursor.FIELD_TYPE_FLOAT: return cursor.getFloat(position); + case Cursor.FIELD_TYPE_INTEGER: return cursor.getInt(position); + case Cursor.FIELD_TYPE_STRING: return cursor.getString(position); + case Cursor.FIELD_TYPE_NULL: + default: + return null; + } + } }
\ No newline at end of file |