Merge "Use settings to persist sticky widget." into jb-mr1-lockscreen-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
b2f21c53cf
@ -3216,20 +3216,27 @@ public final class Settings {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This preference contains the string that shows for owner info on LockScren.
|
* This preference contains the string that shows for owner info on LockScreen.
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
public static final String LOCK_SCREEN_OWNER_INFO = "lock_screen_owner_info";
|
public static final String LOCK_SCREEN_OWNER_INFO = "lock_screen_owner_info";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Id of the user-selected appwidget on the lockscreen, or -1 if none
|
* Ids of the user-selected appwidgets on the lockscreen (comma-delimited).
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
public static final String LOCK_SCREEN_APPWIDGET_IDS =
|
public static final String LOCK_SCREEN_APPWIDGET_IDS =
|
||||||
"lock_screen_appwidget_ids";
|
"lock_screen_appwidget_ids";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This preference enables showing the owner info on LockScren.
|
* Index of the lockscreen appwidget to restore, -1 if none.
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public static final String LOCK_SCREEN_STICKY_APPWIDGET =
|
||||||
|
"lock_screen_sticky_appwidget";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This preference enables showing the owner info on LockScreen.
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
public static final String LOCK_SCREEN_OWNER_INFO_ENABLED =
|
public static final String LOCK_SCREEN_OWNER_INFO_ENABLED =
|
||||||
|
@ -150,7 +150,6 @@ public class LockPatternUtils {
|
|||||||
private final ContentResolver mContentResolver;
|
private final ContentResolver mContentResolver;
|
||||||
private DevicePolicyManager mDevicePolicyManager;
|
private DevicePolicyManager mDevicePolicyManager;
|
||||||
private ILockSettings mLockSettingsService;
|
private ILockSettings mLockSettingsService;
|
||||||
private int mStickyWidgetIndex = -1;
|
|
||||||
|
|
||||||
// The current user is set by KeyguardViewMediator and shared by all LockPatternUtils.
|
// The current user is set by KeyguardViewMediator and shared by all LockPatternUtils.
|
||||||
private static volatile int sCurrentUserId = UserHandle.USER_NULL;
|
private static volatile int sCurrentUserId = UserHandle.USER_NULL;
|
||||||
@ -1162,6 +1161,21 @@ public class LockPatternUtils {
|
|||||||
return true;
|
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) {
|
private long getLong(String secureSettingKey, long defaultValue) {
|
||||||
try {
|
try {
|
||||||
return getLockSettings().getLong(secureSettingKey, defaultValue,
|
return getLockSettings().getLong(secureSettingKey, defaultValue,
|
||||||
@ -1311,12 +1325,4 @@ public class LockPatternUtils {
|
|||||||
return getBoolean(LOCKSCREEN_POWER_BUTTON_INSTANTLY_LOCKS, true);
|
return getBoolean(LOCKSCREEN_POWER_BUTTON_INSTANTLY_LOCKS, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getStickyWidgetIndex() {
|
|
||||||
return mStickyWidgetIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setStickyWidgetIndex(int stickyWidgetIndex) {
|
|
||||||
mStickyWidgetIndex = stickyWidgetIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -249,14 +249,6 @@ public class KeyguardHostView extends KeyguardViewBase {
|
|||||||
mViewMediatorCallback.onUserActivityTimeoutChanged();
|
mViewMediatorCallback.onUserActivityTimeoutChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPageSwitch(int newPageIndex) {
|
|
||||||
if (!isCameraOrAdd(newPageIndex)) {
|
|
||||||
if (DEBUG) Log.d(TAG, "Setting sticky widget index: " + newPageIndex);
|
|
||||||
mLockPatternUtils.setStickyWidgetIndex(newPageIndex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -737,6 +729,7 @@ public class KeyguardHostView extends KeyguardViewBase {
|
|||||||
@Override
|
@Override
|
||||||
public void onScreenTurnedOff() {
|
public void onScreenTurnedOff() {
|
||||||
if (DEBUG) Log.d(TAG, "screen off, instance " + Integer.toHexString(hashCode()));
|
if (DEBUG) Log.d(TAG, "screen off, instance " + Integer.toHexString(hashCode()));
|
||||||
|
saveStickyWidgetIndex();
|
||||||
showPrimarySecurityScreen(true);
|
showPrimarySecurityScreen(true);
|
||||||
getSecurityView(mCurrentSecuritySelection).onPause();
|
getSecurityView(mCurrentSecuritySelection).onPause();
|
||||||
}
|
}
|
||||||
@ -859,8 +852,7 @@ public class KeyguardHostView extends KeyguardViewBase {
|
|||||||
slider.showHandle(true);
|
slider.showHandle(true);
|
||||||
slider.showChallenge(true);
|
slider.showChallenge(true);
|
||||||
}
|
}
|
||||||
View v = mAppWidgetContainer.getChildAt(mAppWidgetContainer.getCurrentPage());
|
if (isCameraPage(mAppWidgetContainer.getCurrentPage())) {
|
||||||
if (v instanceof CameraWidgetFrame) {
|
|
||||||
mAppWidgetContainer.scrollLeft();
|
mAppWidgetContainer.scrollLeft();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1050,6 +1042,8 @@ public class KeyguardHostView extends KeyguardViewBase {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Parcelable onSaveInstanceState() {
|
public Parcelable onSaveInstanceState() {
|
||||||
|
if (DEBUG) Log.d(TAG, "onSaveInstanceState");
|
||||||
|
saveStickyWidgetIndex();
|
||||||
Parcelable superState = super.onSaveInstanceState();
|
Parcelable superState = super.onSaveInstanceState();
|
||||||
SavedState ss = new SavedState(superState);
|
SavedState ss = new SavedState(superState);
|
||||||
ss.transportState = mTransportState;
|
ss.transportState = mTransportState;
|
||||||
@ -1058,6 +1052,7 @@ public class KeyguardHostView extends KeyguardViewBase {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRestoreInstanceState(Parcelable state) {
|
public void onRestoreInstanceState(Parcelable state) {
|
||||||
|
if (DEBUG) Log.d(TAG, "onRestoreInstanceState");
|
||||||
if (!(state instanceof SavedState)) {
|
if (!(state instanceof SavedState)) {
|
||||||
super.onRestoreInstanceState(state);
|
super.onRestoreInstanceState(state);
|
||||||
return;
|
return;
|
||||||
@ -1068,70 +1063,82 @@ public class KeyguardHostView extends KeyguardViewBase {
|
|||||||
post(mSwitchPageRunnable);
|
post(mSwitchPageRunnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onWindowFocusChanged(boolean hasWindowFocus) {
|
||||||
|
super.onWindowFocusChanged(hasWindowFocus);
|
||||||
|
if (DEBUG) Log.d(TAG, "Window is " + (hasWindowFocus ? "focused" : "unfocused"));
|
||||||
|
if (!hasWindowFocus) {
|
||||||
|
saveStickyWidgetIndex();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void showAppropriateWidgetPage() {
|
private void showAppropriateWidgetPage() {
|
||||||
boolean music = mTransportControl.isMusicPlaying() || mTransportState == TRANSPORT_VISIBLE;
|
boolean isMusicPlaying =
|
||||||
if (music) {
|
mTransportControl.isMusicPlaying() || mTransportState == TRANSPORT_VISIBLE;
|
||||||
|
if (isMusicPlaying) {
|
||||||
mTransportState = TRANSPORT_VISIBLE;
|
mTransportState = TRANSPORT_VISIBLE;
|
||||||
} else if (mTransportState == TRANSPORT_VISIBLE) {
|
} else if (mTransportState == TRANSPORT_VISIBLE) {
|
||||||
mTransportState = TRANSPORT_INVISIBLE;
|
mTransportState = TRANSPORT_INVISIBLE;
|
||||||
}
|
}
|
||||||
int pageToShow = getAppropriateWidgetPage();
|
int pageToShow = getAppropriateWidgetPage(isMusicPlaying);
|
||||||
mAppWidgetContainer.setCurrentPage(pageToShow);
|
mAppWidgetContainer.setCurrentPage(pageToShow);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isCameraOrAdd(int pageIndex) {
|
private boolean isCameraPage(int pageIndex) {
|
||||||
View v = mAppWidgetContainer.getChildAt(pageIndex);
|
View v = mAppWidgetContainer.getChildAt(pageIndex);
|
||||||
return v.getId() == R.id.keyguard_add_widget || v instanceof CameraWidgetFrame;
|
return v != null && v instanceof CameraWidgetFrame;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getAppropriateWidgetPage() {
|
private boolean isAddPage(int pageIndex) {
|
||||||
|
View v = mAppWidgetContainer.getChildAt(pageIndex);
|
||||||
|
return v != null && v.getId() == R.id.keyguard_add_widget;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getAppropriateWidgetPage(boolean isMusicPlaying) {
|
||||||
// assumes at least one widget (besides camera + add)
|
// assumes at least one widget (besides camera + add)
|
||||||
|
|
||||||
boolean music = mTransportControl.isMusicPlaying() || mTransportState == TRANSPORT_VISIBLE;
|
|
||||||
// if music playing, show transport
|
// if music playing, show transport
|
||||||
if (music) {
|
if (isMusicPlaying) {
|
||||||
if (DEBUG) Log.d(TAG, "Music playing, show transport");
|
if (DEBUG) Log.d(TAG, "Music playing, show transport");
|
||||||
return mAppWidgetContainer.indexOfChild(mTransportControl);
|
return mAppWidgetContainer.indexOfChild(mTransportControl);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if multi-user applicable, show it
|
// if we have a valid sticky widget, show it
|
||||||
UserManager userManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
|
int stickyWidgetIndex = mLockPatternUtils.getStickyAppWidgetIndex();
|
||||||
View multiUserView = findViewById(R.id.keyguard_multi_user_selector);
|
|
||||||
int multiUserPosition = mAppWidgetContainer.indexOfChild(multiUserView);
|
|
||||||
if (multiUserPosition != -1 && userManager.getUsers(true).size() > 1) {
|
|
||||||
if (DEBUG) Log.d(TAG, "Multi-user applicable, show it");
|
|
||||||
return multiUserPosition;
|
|
||||||
}
|
|
||||||
|
|
||||||
// if we have a sticky widget, show it
|
|
||||||
int stickyWidgetIndex = mLockPatternUtils.getStickyWidgetIndex();
|
|
||||||
if (stickyWidgetIndex > -1
|
if (stickyWidgetIndex > -1
|
||||||
&& stickyWidgetIndex < mAppWidgetContainer.getChildCount()
|
&& stickyWidgetIndex < mAppWidgetContainer.getChildCount()
|
||||||
&& !isCameraOrAdd(stickyWidgetIndex)) {
|
&& !isAddPage(stickyWidgetIndex)
|
||||||
if (DEBUG) Log.d(TAG, "Sticky widget found, show it");
|
&& !isCameraPage(stickyWidgetIndex)) {
|
||||||
|
if (DEBUG) Log.d(TAG, "Valid sticky widget found, show page " + stickyWidgetIndex);
|
||||||
return stickyWidgetIndex;
|
return stickyWidgetIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if we have a status view, show it
|
// else show the right-most widget (except for camera)
|
||||||
View statusView = findViewById(R.id.keyguard_status_view);
|
|
||||||
int statusViewIndex = mAppWidgetContainer.indexOfChild(statusView);
|
|
||||||
if (statusViewIndex > -1) {
|
|
||||||
if (DEBUG) Log.d(TAG, "Status widget found, show it");
|
|
||||||
return mAppWidgetContainer.indexOfChild(statusView);
|
|
||||||
}
|
|
||||||
|
|
||||||
// else the right-most (except for camera)
|
|
||||||
int rightMost = mAppWidgetContainer.getChildCount() - 1;
|
int rightMost = mAppWidgetContainer.getChildCount() - 1;
|
||||||
if (mAppWidgetContainer.getChildAt(rightMost) instanceof CameraWidgetFrame) {
|
if (isCameraPage(rightMost)) {
|
||||||
rightMost--;
|
rightMost--;
|
||||||
}
|
}
|
||||||
if (DEBUG) Log.d(TAG, "Show right-most");
|
if (DEBUG) Log.d(TAG, "Show right-most page " + rightMost);
|
||||||
return rightMost;
|
return rightMost;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void saveStickyWidgetIndex() {
|
||||||
|
int stickyWidgetIndex = mAppWidgetContainer.getCurrentPage();
|
||||||
|
if (isAddPage(stickyWidgetIndex)) {
|
||||||
|
stickyWidgetIndex++;
|
||||||
|
}
|
||||||
|
if (isCameraPage(stickyWidgetIndex)) {
|
||||||
|
stickyWidgetIndex--;
|
||||||
|
}
|
||||||
|
if (stickyWidgetIndex < 0 || stickyWidgetIndex >= mAppWidgetContainer.getChildCount()) {
|
||||||
|
stickyWidgetIndex = -1;
|
||||||
|
}
|
||||||
|
if (DEBUG) Log.d(TAG, "saveStickyWidgetIndex: " + stickyWidgetIndex);
|
||||||
|
mLockPatternUtils.setStickyAppWidgetIndex(stickyWidgetIndex);
|
||||||
|
}
|
||||||
|
|
||||||
private void enableUserSelectorIfNecessary() {
|
private void enableUserSelectorIfNecessary() {
|
||||||
// if there are multiple users, we need to add the multi-user switcher widget to the
|
// if there are multiple users, we need to enable to multi-user switcher
|
||||||
// keyguard.
|
|
||||||
UserManager mUm = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
|
UserManager mUm = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
|
||||||
List<UserInfo> users = mUm.getUsers(true);
|
List<UserInfo> users = mUm.getUsers(true);
|
||||||
|
|
||||||
|
@ -116,7 +116,6 @@ public class KeyguardWidgetPager extends PagedView implements PagedView.PageSwit
|
|||||||
if (mCallbacks != null) {
|
if (mCallbacks != null) {
|
||||||
mCallbacks.onUserActivityTimeoutChanged();
|
mCallbacks.onUserActivityTimeoutChanged();
|
||||||
mCallbacks.userActivity();
|
mCallbacks.userActivity();
|
||||||
mCallbacks.onPageSwitch(newPageIndex);
|
|
||||||
}
|
}
|
||||||
KeyguardWidgetFrame oldWidgetPage = getWidgetPageAt(oldPageIndex);
|
KeyguardWidgetFrame oldWidgetPage = getWidgetPageAt(oldPageIndex);
|
||||||
if (oldWidgetPage != null) {
|
if (oldWidgetPage != null) {
|
||||||
@ -156,7 +155,6 @@ public class KeyguardWidgetPager extends PagedView implements PagedView.PageSwit
|
|||||||
public interface Callbacks {
|
public interface Callbacks {
|
||||||
public void userActivity();
|
public void userActivity();
|
||||||
public void onUserActivityTimeoutChanged();
|
public void onUserActivityTimeoutChanged();
|
||||||
public void onPageSwitch(int newPageIndex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addWidget(View widget) {
|
public void addWidget(View widget) {
|
||||||
|
Reference in New Issue
Block a user