From b0d064ed980e5525232390a561e4221069343b3f Mon Sep 17 00:00:00 2001 From: d34d Date: Mon, 28 Mar 2016 10:09:22 -0700 Subject: Add ModLock option in lock screen picker This will intent out to the live lock screen settings so the user can pick a live lock screen (ModLock) Change-Id: Ia5bf5a6961ca2a50032cea2da5355e3fae7ae37a TICKET: CYNGNOS-2301 --- res/values/strings.xml | 1 + src/com/cyngn/theme/chooser/ComponentSelector.java | 24 ++++++++++++++++------ src/com/cyngn/theme/chooser/ThemeFragment.java | 14 ++++++++++++- 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index ed39c7b..2fa25a8 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -69,6 +69,7 @@ Pick image None + MOD Lock Processing diff --git a/src/com/cyngn/theme/chooser/ComponentSelector.java b/src/com/cyngn/theme/chooser/ComponentSelector.java index 92397f0..5347250 100644 --- a/src/com/cyngn/theme/chooser/ComponentSelector.java +++ b/src/com/cyngn/theme/chooser/ComponentSelector.java @@ -79,8 +79,12 @@ public class ComponentSelector extends LinearLayout public static final String EXTERNAL_WALLPAPER = "external"; + public static final String MOD_LOCK = "mod_lock"; + private static final int EXTRA_WALLPAPER_COMPONENTS = 2; + private static final int EXTRA_LOCK_SCREEN_WALLPAPER_COMPONENTS = 3; + protected static final long DEFAULT_COMPONENT_ID = 0; private Context mContext; @@ -530,7 +534,8 @@ public class ComponentSelector extends LinearLayout } if (MODIFIES_LAUNCHER.equals(mComponentType)) { return newWallpapersView(cursor, container, position, - cursor.getColumnIndex(PreviewColumns.WALLPAPER_THUMBNAIL), false); + cursor.getColumnIndex(PreviewColumns.WALLPAPER_THUMBNAIL), false, + EXTRA_WALLPAPER_COMPONENTS); } if (MODIFIES_BOOT_ANIM.equals(mComponentType)) { return newBootanimationView(cursor, container, position); @@ -542,8 +547,8 @@ public class ComponentSelector extends LinearLayout } if (MODIFIES_LOCKSCREEN.equals(mComponentType)) { boolean isLiveLockScreen = false; - if (position >= EXTRA_WALLPAPER_COMPONENTS) { - cursor.moveToPosition(position - EXTRA_WALLPAPER_COMPONENTS); + if (position >= EXTRA_LOCK_SCREEN_WALLPAPER_COMPONENTS) { + cursor.moveToPosition(position - EXTRA_LOCK_SCREEN_WALLPAPER_COMPONENTS); int liveLockIndex = cursor.getColumnIndex(MODIFIES_LIVE_LOCK_SCREEN); isLiveLockScreen = liveLockIndex >= 0 && cursor.getInt(liveLockIndex) == 1; @@ -551,7 +556,8 @@ public class ComponentSelector extends LinearLayout int index = isLiveLockScreen ? cursor.getColumnIndex(PreviewColumns.LIVE_LOCK_SCREEN_THUMBNAIL) : cursor.getColumnIndex(PreviewColumns.LOCK_WALLPAPER_THUMBNAIL); - return newWallpapersView(cursor, container, position, index, isLiveLockScreen); + return newWallpapersView(cursor, container, position, index, isLiveLockScreen, + EXTRA_LOCK_SCREEN_WALLPAPER_COMPONENTS); } return null; } @@ -650,7 +656,7 @@ public class ComponentSelector extends LinearLayout } private View newWallpapersView(Cursor cursor, ViewGroup parent, int position, - int wallpaperIndex, boolean isLiveLockScreen) { + int wallpaperIndex, boolean isLiveLockScreen, int numExtraComponents) { View v = mInflater.inflate(R.layout.wallpaper_component_selection_item, parent, false); ImageView iv = (ImageView) v.findViewById(R.id.icon); @@ -663,8 +669,14 @@ public class ComponentSelector extends LinearLayout v.setTag(R.id.tag_key_package_name, EXTERNAL_WALLPAPER); ((TextView) v.findViewById(R.id.title)) .setText(R.string.wallpaper_external_title); + } else if (numExtraComponents == EXTRA_LOCK_SCREEN_WALLPAPER_COMPONENTS && position == 2) { + // TODO: update drawable once the asset is provided by design + iv.setImageResource(android.R.drawable.ic_lock_lock); + v.setTag(R.id.tag_key_package_name, MOD_LOCK); + ((TextView) v.findViewById(R.id.title)) + .setText(R.string.mod_lock_title); } else { - cursor.moveToPosition(position - EXTRA_WALLPAPER_COMPONENTS); + cursor.moveToPosition(position - numExtraComponents); int pkgNameIndex = cursor.getColumnIndex(ThemesContract.ThemesColumns.PKG_NAME); int cmpntIdIndex = cursor.getColumnIndex(PreviewColumns.COMPONENT_ID); long cmpntId = (cmpntIdIndex >= 0) ? diff --git a/src/com/cyngn/theme/chooser/ThemeFragment.java b/src/com/cyngn/theme/chooser/ThemeFragment.java index 7bf983a..103dca0 100644 --- a/src/com/cyngn/theme/chooser/ThemeFragment.java +++ b/src/com/cyngn/theme/chooser/ThemeFragment.java @@ -12,6 +12,7 @@ import android.animation.ValueAnimator; import android.app.Activity; import android.app.AlertDialog; import android.app.WallpaperManager; +import android.content.ActivityNotFoundException; import android.content.ComponentName; import android.content.Context; import android.content.DialogInterface; @@ -2085,7 +2086,7 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb getString(R.string.wallpaper_label)); } }; - requestPermissions(new String[] {READ_EXTERNAL_STORAGE}, + requestPermissions(new String[]{READ_EXTERNAL_STORAGE}, PERMISSION_REQUEST); } else { getChooserActivity().pickExternalWallpaper(); @@ -2131,6 +2132,8 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb setCardTitle(mLockScreenCard, WALLPAPER_NONE, getString(R.string.lockscreen_label)); } + } else if (ComponentSelector.MOD_LOCK.equals(pkgName)) { + startLiveLockScreenSettings(); } else { if (MODIFIES_LIVE_LOCK_SCREEN.equals(component)) { loaderId = LOADER_ID_LIVE_LOCK_SCREEN; @@ -2924,6 +2927,15 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb }, SHOW_LOCK_SCREEN_CARD_DELAY); } + protected void startLiveLockScreenSettings() { + Intent intent = new Intent(cyanogenmod.content.Intent.ACTION_OPEN_LIVE_LOCKSCREEN_SETTINGS); + try { + startActivity(intent); + } catch (ActivityNotFoundException e) { + // TODO: inform user that this action failed (Toast?) + } + } + class AnimationLoader extends AsyncTask { Context mContext; String mPkgName; -- cgit v1.1