diff options
author | Danesh M <daneshm90@gmail.com> | 2012-04-23 00:21:30 -0400 |
---|---|---|
committer | Ricardo Cerqueira <github@cerqueira.org> | 2012-05-06 23:54:29 +0100 |
commit | 39aef3c7a80f647dc0d7f1e9849f4121a69c6b47 (patch) | |
tree | fb45fd95c9fe3b482d95fe57d98b07271eba9df4 /policy | |
parent | 1fb53b877c04baf0fd8fb81e3acdd366f6e0a1d7 (diff) | |
download | frameworks_base-39aef3c7a80f647dc0d7f1e9849f4121a69c6b47.zip frameworks_base-39aef3c7a80f647dc0d7f1e9849f4121a69c6b47.tar.gz frameworks_base-39aef3c7a80f647dc0d7f1e9849f4121a69c6b47.tar.bz2 |
Lockscreen : Customizable shortcuts
Allow users to choose lockscreen shortcuts / icons :
Phone - 1-5 targets
Tablets - 1-8 targets
Patchset 2 : Fix default target reading
Patchset 3 : Switch to resolveActivityInfo
Patchset 4 : Case check for empty target
Patchset 5 : Add index check for targetDescriptions
: Minor cleanup
Patchset 6 : Custom icons
: The RSS, Browser, Facebook, Twitter and Podcasts images are
derivative works by DvTonder made from the from the WPZOOM Developer Icon Pack,
licensed under Creative Commons Attribution-NonCommercial-ShareAlike, (c) WPZOOM
Patchset 7 : Fix variable reference
Patchset 8 : Change storing method (dynamically get drawable id)
Patchset 9 : Randomz...
Patchset 10 : Icon pack support (Template found at : https://github.com/Danesh/CmIconPicker)
: Removed stock messaging icon, use ours instead.
Patchset 11 : Code cleanup
Change-Id: I93c842a78fff3517002f7be08555db5b585f6eb8
Diffstat (limited to 'policy')
-rw-r--r-- | policy/src/com/android/internal/policy/impl/LockScreen.java | 189 |
1 files changed, 171 insertions, 18 deletions
diff --git a/policy/src/com/android/internal/policy/impl/LockScreen.java b/policy/src/com/android/internal/policy/impl/LockScreen.java index c87afe4..51c1dae 100644 --- a/policy/src/com/android/internal/policy/impl/LockScreen.java +++ b/policy/src/com/android/internal/policy/impl/LockScreen.java @@ -21,12 +21,23 @@ import com.android.internal.widget.LockPatternUtils; import com.android.internal.widget.SlidingTab; import com.android.internal.widget.WaveView; import com.android.internal.widget.multiwaveview.MultiWaveView; +import com.android.internal.widget.multiwaveview.TargetDrawable; import android.app.ActivityManager; import android.content.Context; import android.content.Intent; +import android.content.pm.ActivityInfo; +import android.content.pm.PackageManager; +import android.content.pm.PackageManager.NameNotFoundException; import android.content.res.Configuration; import android.content.res.Resources; +import android.content.res.Resources.NotFoundException; +import android.graphics.BitmapFactory; +import android.graphics.drawable.BitmapDrawable; +import android.graphics.drawable.Drawable; +import android.graphics.drawable.InsetDrawable; +import android.graphics.drawable.LayerDrawable; +import android.graphics.drawable.StateListDrawable; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.View; @@ -38,6 +49,8 @@ import android.provider.MediaStore; import android.provider.Settings; import java.io.File; +import java.net.URISyntaxException; +import java.util.ArrayList; /** * The screen within {@link LockPatternKeyguardView} that shows general @@ -185,6 +198,9 @@ class LockScreen extends LinearLayout implements KeyguardScreen { private final MultiWaveView mMultiWaveView; private boolean mCameraDisabled; + private String[] mStoredTargets; + private int mTargetOffset; + private boolean mIsScreenLarge; MultiWaveViewMethods(MultiWaveView multiWaveView) { mMultiWaveView = multiWaveView; @@ -201,16 +217,134 @@ class LockScreen extends LinearLayout implements KeyguardScreen { } } + public boolean isScreenLarge() { + final int screenSize = Resources.getSystem().getConfiguration().screenLayout & + Configuration.SCREENLAYOUT_SIZE_MASK; + boolean isScreenLarge = screenSize == Configuration.SCREENLAYOUT_SIZE_LARGE || + screenSize == Configuration.SCREENLAYOUT_SIZE_XLARGE; + return isScreenLarge; + } + + private StateListDrawable getLayeredDrawable(Drawable back, Drawable front, int inset, boolean frontBlank) { + Resources res = getResources(); + InsetDrawable[] inactivelayer = new InsetDrawable[2]; + InsetDrawable[] activelayer = new InsetDrawable[2]; + inactivelayer[0] = new InsetDrawable(res.getDrawable(com.android.internal.R.drawable.ic_lockscreen_lock_pressed), 0, 0, 0, 0); + inactivelayer[1] = new InsetDrawable(front, inset, inset, inset, inset); + activelayer[0] = new InsetDrawable(back, 0, 0, 0, 0); + activelayer[1] = new InsetDrawable(frontBlank ? res.getDrawable(android.R.color.transparent) : front, inset, inset, inset, inset); + StateListDrawable states = new StateListDrawable(); + LayerDrawable inactiveLayerDrawable = new LayerDrawable(inactivelayer); + inactiveLayerDrawable.setId(0, 0); + inactiveLayerDrawable.setId(1, 1); + LayerDrawable activeLayerDrawable = new LayerDrawable(activelayer); + activeLayerDrawable.setId(0, 0); + activeLayerDrawable.setId(1, 1); + states.addState(TargetDrawable.STATE_INACTIVE, inactiveLayerDrawable); + states.addState(TargetDrawable.STATE_ACTIVE, activeLayerDrawable); + return states; + } + public void updateResources() { - int resId; - if (mCameraDisabled) { - // Fall back to showing ring/silence if camera is disabled by DPM... - resId = mSilentMode ? R.array.lockscreen_targets_when_silent - : R.array.lockscreen_targets_when_soundon; + String storedVal = Settings.System.getString(mContext.getContentResolver(), + Settings.System.LOCKSCREEN_TARGETS); + if (storedVal == null) { + int resId; + mStoredTargets = null; + if (mCameraDisabled) { + // Fall back to showing ring/silence if camera is disabled by DPM... + resId = mSilentMode ? R.array.lockscreen_targets_when_silent + : R.array.lockscreen_targets_when_soundon; + } else { + resId = R.array.lockscreen_targets_with_camera; + } + mMultiWaveView.setTargetResources(resId); } else { - resId = R.array.lockscreen_targets_with_camera; + mStoredTargets = storedVal.split("\\|"); + mIsScreenLarge = isScreenLarge(); + ArrayList<TargetDrawable> storedDraw = new ArrayList<TargetDrawable>(); + final Resources res = getResources(); + final int targetInset = mIsScreenLarge ? MultiWaveView.TABLET_TARGET_INSET : + MultiWaveView.PHONE_TARGET_INSET; + final PackageManager packMan = mContext.getPackageManager(); + final boolean isLandscape = mCreationOrientation == Configuration.ORIENTATION_LANDSCAPE; + final Drawable blankActiveDrawable = res.getDrawable(R.drawable.ic_lockscreen_target_activated); + final InsetDrawable activeBack = new InsetDrawable(blankActiveDrawable, 0, 0, 0, 0); + // Shift targets for landscape lockscreen on phones + mTargetOffset = isLandscape && !mIsScreenLarge ? 2 : 0; + if (mTargetOffset == 2) { + storedDraw.add(new TargetDrawable(res, null)); + storedDraw.add(new TargetDrawable(res, null)); + } + // Add unlock target + storedDraw.add(new TargetDrawable(res, res.getDrawable(R.drawable.ic_lockscreen_unlock))); + for (int i = 0; i < 8 - mTargetOffset - 1; i++) { + int tmpInset = targetInset; + if (i < mStoredTargets.length) { + String uri = mStoredTargets[i]; + if (!uri.equals(MultiWaveView.EMPTY_TARGET)) { + try { + Intent in = Intent.parseUri(uri,0); + Drawable front = null; + Drawable back = activeBack; + boolean frontBlank = false; + if (in.hasExtra(MultiWaveView.ICON_FILE)) { + String fSource = in.getStringExtra(MultiWaveView.ICON_FILE); + if (fSource != null) { + File fPath = new File(fSource); + if (fPath.exists()) { + front = new BitmapDrawable(res, BitmapFactory.decodeFile(fSource)); + } + } + } else if (in.hasExtra(MultiWaveView.ICON_RESOURCE)) { + String rSource = in.getStringExtra(MultiWaveView.ICON_RESOURCE); + String rPackage = in.getStringExtra(MultiWaveView.ICON_PACKAGE); + if (rSource != null) { + if (rPackage != null) { + try { + Context rContext = mContext.createPackageContext(rPackage, 0); + int id = rContext.getResources().getIdentifier(rSource, "drawable", rPackage); + front = rContext.getResources().getDrawable(id); + id = rContext.getResources().getIdentifier(rSource.replaceAll("_normal", "_activated"), + "drawable", rPackage); + back = rContext.getResources().getDrawable(id); + tmpInset = 0; + frontBlank = true; + } catch (NameNotFoundException e) { + e.printStackTrace(); + } catch (NotFoundException e) { + e.printStackTrace(); + } + } else { + front = res.getDrawable(res.getIdentifier(rSource, "drawable", "android")); + back = res.getDrawable(res.getIdentifier( + rSource.replaceAll("_normal", "_activated"), "drawable", "android")); + tmpInset = 0; + frontBlank = true; + } + } + } + if (front == null || back == null) { + ActivityInfo aInfo = in.resolveActivityInfo(packMan, PackageManager.GET_ACTIVITIES); + if (aInfo != null) { + front = aInfo.loadIcon(packMan); + } else { + front = res.getDrawable(android.R.drawable.sym_def_app_icon); + } + } + storedDraw.add(new TargetDrawable(res, getLayeredDrawable(back,front, tmpInset, frontBlank))); + } catch (Exception e) { + storedDraw.add(new TargetDrawable(res, null)); + } + } else { + storedDraw.add(new TargetDrawable(res, null)); + } + } else { + storedDraw.add(new TargetDrawable(res, null)); + } + } + mMultiWaveView.setTargetResources(storedDraw); } - mMultiWaveView.setTargetResources(resId); } public void onGrabbed(View v, int handle) { @@ -222,19 +356,38 @@ class LockScreen extends LinearLayout implements KeyguardScreen { } public void onTrigger(View v, int target) { - if (target == 0 || target == 1) { // 0 = unlock/portrait, 1 = unlock/landscape - mCallback.goToUnlockScreen(); - } else if (target == 2 || target == 3) { // 2 = alt/portrait, 3 = alt/landscape - if (!mCameraDisabled) { - // Start the Camera - Intent intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA); - intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - mContext.startActivity(intent); + if (mStoredTargets == null) { + if (target == 0 || target == 1) { // 0 = unlock/portrait, 1 = unlock/landscape + mCallback.goToUnlockScreen(); + } else if (target == 2 || target == 3) { // 2 = alt/portrait, 3 = alt/landscape + if (!mCameraDisabled) { + // Start the Camera + Intent intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA); + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + mContext.startActivity(intent); + mCallback.goToUnlockScreen(); + } else { + toggleRingMode(); + mUnlockWidgetMethods.updateResources(); + mCallback.pokeWakelock(); + } + } + } else { + final boolean isLand = mCreationOrientation == Configuration.ORIENTATION_LANDSCAPE; + if ((target == 0 && (mIsScreenLarge || !isLand)) || (target == 2 && !mIsScreenLarge && isLand)) { mCallback.goToUnlockScreen(); } else { - toggleRingMode(); - mUnlockWidgetMethods.updateResources(); - mCallback.pokeWakelock(); + target -= 1 + mTargetOffset; + if (target < mStoredTargets.length && mStoredTargets[target] != null) { + try { + Intent tIntent = Intent.parseUri(mStoredTargets[target], 0); + tIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + mContext.startActivity(tIntent); + mCallback.goToUnlockScreen(); + return; + } catch (URISyntaxException e) { + } + } } } } |