Merge "Removing sticky widgets in lockscreen" into jb-mr1-lockscreen-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
835579e817
@@ -110,6 +110,11 @@ public class LockPatternUtils {
|
||||
*/
|
||||
public static final String KEYGUARD_SHOW_SECURITY_CHALLENGE = "showsecuritychallenge";
|
||||
|
||||
/**
|
||||
* Tells the keyguard to show the widget with the specified id when the keyguard is created.
|
||||
*/
|
||||
public static final String KEYGUARD_SHOW_APPWIDGET = "showappwidget";
|
||||
|
||||
/**
|
||||
* Options used to lock the device upon user switch.
|
||||
*/
|
||||
@@ -1183,21 +1188,6 @@ public class LockPatternUtils {
|
||||
return true;
|
||||
}
|
||||
|
||||
public int getStickyAppWidgetIndex() {
|
||||
return Settings.Secure.getIntForUser(
|
||||
mContentResolver,
|
||||
Settings.Secure.LOCK_SCREEN_STICKY_APPWIDGET,
|
||||
-1,
|
||||
UserHandle.USER_CURRENT);
|
||||
}
|
||||
|
||||
public void setStickyAppWidgetIndex(int value) {
|
||||
Settings.Secure.putIntForUser(mContentResolver,
|
||||
Settings.Secure.LOCK_SCREEN_STICKY_APPWIDGET,
|
||||
value,
|
||||
UserHandle.USER_CURRENT);
|
||||
}
|
||||
|
||||
private long getLong(String secureSettingKey, long defaultValue) {
|
||||
try {
|
||||
return getLockSettings().getLong(secureSettingKey, defaultValue,
|
||||
|
||||
@@ -37,8 +37,6 @@ import android.os.Looper;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.os.SystemClock;
|
||||
import android.os.SystemProperties;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
@@ -75,6 +73,7 @@ public class KeyguardHostView extends KeyguardViewBase {
|
||||
private boolean mIsVerifyUnlockOnly;
|
||||
private boolean mEnableFallback; // TODO: This should get the value from KeyguardPatternView
|
||||
private SecurityMode mCurrentSecuritySelection = SecurityMode.Invalid;
|
||||
private int mAppWidgetToShow;
|
||||
|
||||
protected Runnable mLaunchRunnable;
|
||||
|
||||
@@ -84,7 +83,6 @@ public class KeyguardHostView extends KeyguardViewBase {
|
||||
private KeyguardSecurityModel mSecurityModel;
|
||||
private KeyguardViewStateManager mViewStateManager;
|
||||
|
||||
int mLocalStickyWidget = -1;
|
||||
boolean mPersitentStickyWidgetLoaded = false;
|
||||
|
||||
private Rect mTempRect = new Rect();
|
||||
@@ -768,7 +766,6 @@ public class KeyguardHostView extends KeyguardViewBase {
|
||||
// Once the screen turns off, we no longer consider this to be first boot and we want the
|
||||
// biometric unlock to start next time keyguard is shown.
|
||||
KeyguardUpdateMonitor.getInstance(mContext).setAlternateUnlockEnabled(true);
|
||||
saveStickyWidgetIndex();
|
||||
checkAppWidgetConsistency();
|
||||
showPrimarySecurityScreen(true);
|
||||
getSecurityView(mCurrentSecuritySelection).onPause();
|
||||
@@ -967,7 +964,7 @@ public class KeyguardHostView extends KeyguardViewBase {
|
||||
initializeTransportControl();
|
||||
}
|
||||
|
||||
private void removeTransportFromWidgetPager() {
|
||||
private boolean removeTransportFromWidgetPager() {
|
||||
int page = getWidgetPosition(R.id.keyguard_transport_control);
|
||||
if (page != -1) {
|
||||
mAppWidgetContainer.removeWidget(mTransportControl);
|
||||
@@ -976,8 +973,9 @@ public class KeyguardHostView extends KeyguardViewBase {
|
||||
KeyguardHostView.this.addView(mTransportControl);
|
||||
mTransportControl.setVisibility(View.GONE);
|
||||
mViewStateManager.setTransportState(KeyguardViewStateManager.TRANSPORT_GONE);
|
||||
mTransportControl.post(mSwitchPageRunnable);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void addTransportToWidgetPager() {
|
||||
@@ -1006,8 +1004,9 @@ public class KeyguardHostView extends KeyguardViewBase {
|
||||
mTransportControl.setKeyguardCallback(new TransportCallback() {
|
||||
@Override
|
||||
public void onListenerDetached() {
|
||||
removeTransportFromWidgetPager();
|
||||
mTransportControl.post(mSwitchPageRunnable);
|
||||
if (removeTransportFromWidgetPager()) {
|
||||
mTransportControl.post(mSwitchPageRunnable);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1183,7 +1182,6 @@ public class KeyguardHostView extends KeyguardViewBase {
|
||||
@Override
|
||||
public Parcelable onSaveInstanceState() {
|
||||
if (DEBUG) Log.d(TAG, "onSaveInstanceState");
|
||||
saveStickyWidgetIndex();
|
||||
Parcelable superState = super.onSaveInstanceState();
|
||||
SavedState ss = new SavedState(superState);
|
||||
ss.transportState = mViewStateManager.getTransportState();
|
||||
@@ -1207,9 +1205,7 @@ public class KeyguardHostView extends KeyguardViewBase {
|
||||
public void onWindowFocusChanged(boolean hasWindowFocus) {
|
||||
super.onWindowFocusChanged(hasWindowFocus);
|
||||
if (DEBUG) Log.d(TAG, "Window is " + (hasWindowFocus ? "focused" : "unfocused"));
|
||||
if (!hasWindowFocus) {
|
||||
saveStickyWidgetIndex();
|
||||
} else if (mShowSecurityWhenReturn) {
|
||||
if (hasWindowFocus && mShowSecurityWhenReturn) {
|
||||
SlidingChallengeLayout slider =
|
||||
(SlidingChallengeLayout) findViewById(R.id.sliding_layout);
|
||||
if (slider != null) {
|
||||
@@ -1243,31 +1239,13 @@ public class KeyguardHostView extends KeyguardViewBase {
|
||||
return null;
|
||||
}
|
||||
|
||||
private int getStickyWidget() {
|
||||
// The first time we query the persistent state. From that point, we use a locally updated
|
||||
// notion of the sticky widget page.
|
||||
if (!mPersitentStickyWidgetLoaded) {
|
||||
mLocalStickyWidget = mLockPatternUtils.getStickyAppWidgetIndex();
|
||||
mPersitentStickyWidgetLoaded = true;
|
||||
private boolean isWidgetPage(int pageIndex) {
|
||||
View v = mAppWidgetContainer.getChildAt(pageIndex);
|
||||
if (v != null && v instanceof KeyguardWidgetFrame) {
|
||||
KeyguardWidgetFrame kwf = (KeyguardWidgetFrame) v;
|
||||
return kwf.getContentAppWidgetId() != AppWidgetManager.INVALID_APPWIDGET_ID;
|
||||
}
|
||||
return mLocalStickyWidget;
|
||||
}
|
||||
|
||||
public void updateStickyWidget(int index) {
|
||||
if (index < 0 || index >= mAppWidgetContainer.getChildCount()) {
|
||||
return;
|
||||
}
|
||||
if (mAppWidgetContainer.isAddPage(index)) {
|
||||
return;
|
||||
}
|
||||
if (mAppWidgetContainer.isCameraPage(index)) {
|
||||
return;
|
||||
}
|
||||
if (isMusicPage(index)) {
|
||||
return;
|
||||
}
|
||||
|
||||
mLocalStickyWidget = index;
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean isMusicPage(int pageIndex) {
|
||||
@@ -1276,23 +1254,23 @@ public class KeyguardHostView extends KeyguardViewBase {
|
||||
|
||||
private int getAppropriateWidgetPage(boolean isMusicPlaying) {
|
||||
// assumes at least one widget (besides camera + add)
|
||||
|
||||
if (mAppWidgetToShow != AppWidgetManager.INVALID_APPWIDGET_ID) {
|
||||
final int childCount = mAppWidgetContainer.getChildCount();
|
||||
for (int i = 0; i < childCount; i++) {
|
||||
if (mAppWidgetContainer.getWidgetPageAt(i).getContentAppWidgetId()
|
||||
== mAppWidgetToShow) {
|
||||
mAppWidgetToShow = AppWidgetManager.INVALID_APPWIDGET_ID;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
mAppWidgetToShow = AppWidgetManager.INVALID_APPWIDGET_ID;
|
||||
}
|
||||
// if music playing, show transport
|
||||
if (isMusicPlaying) {
|
||||
if (DEBUG) Log.d(TAG, "Music playing, show transport");
|
||||
return mAppWidgetContainer.getWidgetPageIndex(mTransportControl);
|
||||
}
|
||||
|
||||
// if we have a valid sticky widget, show it
|
||||
int stickyWidgetIndex = getStickyWidget();
|
||||
if (stickyWidgetIndex > -1
|
||||
&& stickyWidgetIndex < mAppWidgetContainer.getChildCount()
|
||||
&& !mAppWidgetContainer.isAddPage(stickyWidgetIndex)
|
||||
&& !mAppWidgetContainer.isCameraPage(stickyWidgetIndex)) {
|
||||
if (DEBUG) Log.d(TAG, "Valid sticky widget found, show page " + stickyWidgetIndex);
|
||||
return stickyWidgetIndex;
|
||||
}
|
||||
|
||||
// else show the right-most widget (except for camera)
|
||||
int rightMost = mAppWidgetContainer.getChildCount() - 1;
|
||||
if (mAppWidgetContainer.isCameraPage(rightMost)) {
|
||||
@@ -1302,13 +1280,6 @@ public class KeyguardHostView extends KeyguardViewBase {
|
||||
return rightMost;
|
||||
}
|
||||
|
||||
private void saveStickyWidgetIndex() {
|
||||
if (DEBUG) Log.d(TAG, "saveStickyWidgetIndex: " + mLocalStickyWidget);
|
||||
if (mPersitentStickyWidgetLoaded && mLocalStickyWidget >= 0) {
|
||||
mLockPatternUtils.setStickyAppWidgetIndex(mLocalStickyWidget);
|
||||
}
|
||||
}
|
||||
|
||||
private void enableUserSelectorIfNecessary() {
|
||||
if (!UserManager.supportsMultipleUsers()) {
|
||||
return; // device doesn't support multi-user mode
|
||||
@@ -1380,6 +1351,11 @@ public class KeyguardHostView extends KeyguardViewBase {
|
||||
mAppWidgetContainer.setCurrentPage(getWidgetPosition(R.id.keyguard_multi_user_selector));
|
||||
}
|
||||
|
||||
public void goToWidget(int appWidgetId) {
|
||||
mAppWidgetToShow = appWidgetId;
|
||||
mSwitchPageRunnable.run();
|
||||
}
|
||||
|
||||
public boolean handleMenuKey() {
|
||||
// The following enables the MENU key to work for testing automation
|
||||
if (shouldEnableMenuKey()) {
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.android.internal.policy.impl.keyguard;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.ActivityManager;
|
||||
import android.appwidget.AppWidgetManager;
|
||||
import android.content.Context;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.res.Configuration;
|
||||
@@ -240,6 +241,11 @@ public class KeyguardViewManager {
|
||||
if (options.getBoolean(LockPatternUtils.KEYGUARD_SHOW_SECURITY_CHALLENGE)) {
|
||||
mKeyguardView.showNextSecurityScreenIfPresent();
|
||||
}
|
||||
int widgetToShow = options.getInt(LockPatternUtils.KEYGUARD_SHOW_APPWIDGET,
|
||||
AppWidgetManager.INVALID_APPWIDGET_ID);
|
||||
if (widgetToShow != AppWidgetManager.INVALID_APPWIDGET_ID) {
|
||||
mKeyguardView.goToWidget(widgetToShow);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -147,10 +147,6 @@ public class KeyguardViewStateManager implements
|
||||
// We only modify the page state if it is not currently under control by the slider.
|
||||
// This prevents conflicts.
|
||||
|
||||
if (mKeyguardHostView != null) {
|
||||
mKeyguardHostView.updateStickyWidget(newPageIndex);
|
||||
}
|
||||
|
||||
// If the page hasn't switched, don't bother with any of this
|
||||
if (mCurrentPage == newPageIndex) return;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user