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
|
||||
*/
|
||||
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
|
||||
*/
|
||||
public static final String 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
|
||||
*/
|
||||
public static final String LOCK_SCREEN_OWNER_INFO_ENABLED =
|
||||
|
@ -150,7 +150,6 @@ public class LockPatternUtils {
|
||||
private final ContentResolver mContentResolver;
|
||||
private DevicePolicyManager mDevicePolicyManager;
|
||||
private ILockSettings mLockSettingsService;
|
||||
private int mStickyWidgetIndex = -1;
|
||||
|
||||
// The current user is set by KeyguardViewMediator and shared by all LockPatternUtils.
|
||||
private static volatile int sCurrentUserId = UserHandle.USER_NULL;
|
||||
@ -1162,6 +1161,21 @@ 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,
|
||||
@ -1311,12 +1325,4 @@ public class LockPatternUtils {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageSwitch(int newPageIndex) {
|
||||
if (!isCameraOrAdd(newPageIndex)) {
|
||||
if (DEBUG) Log.d(TAG, "Setting sticky widget index: " + newPageIndex);
|
||||
mLockPatternUtils.setStickyWidgetIndex(newPageIndex);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
@ -737,6 +729,7 @@ public class KeyguardHostView extends KeyguardViewBase {
|
||||
@Override
|
||||
public void onScreenTurnedOff() {
|
||||
if (DEBUG) Log.d(TAG, "screen off, instance " + Integer.toHexString(hashCode()));
|
||||
saveStickyWidgetIndex();
|
||||
showPrimarySecurityScreen(true);
|
||||
getSecurityView(mCurrentSecuritySelection).onPause();
|
||||
}
|
||||
@ -859,8 +852,7 @@ public class KeyguardHostView extends KeyguardViewBase {
|
||||
slider.showHandle(true);
|
||||
slider.showChallenge(true);
|
||||
}
|
||||
View v = mAppWidgetContainer.getChildAt(mAppWidgetContainer.getCurrentPage());
|
||||
if (v instanceof CameraWidgetFrame) {
|
||||
if (isCameraPage(mAppWidgetContainer.getCurrentPage())) {
|
||||
mAppWidgetContainer.scrollLeft();
|
||||
}
|
||||
}
|
||||
@ -1050,6 +1042,8 @@ 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 = mTransportState;
|
||||
@ -1058,6 +1052,7 @@ public class KeyguardHostView extends KeyguardViewBase {
|
||||
|
||||
@Override
|
||||
public void onRestoreInstanceState(Parcelable state) {
|
||||
if (DEBUG) Log.d(TAG, "onRestoreInstanceState");
|
||||
if (!(state instanceof SavedState)) {
|
||||
super.onRestoreInstanceState(state);
|
||||
return;
|
||||
@ -1068,70 +1063,82 @@ public class KeyguardHostView extends KeyguardViewBase {
|
||||
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() {
|
||||
boolean music = mTransportControl.isMusicPlaying() || mTransportState == TRANSPORT_VISIBLE;
|
||||
if (music) {
|
||||
boolean isMusicPlaying =
|
||||
mTransportControl.isMusicPlaying() || mTransportState == TRANSPORT_VISIBLE;
|
||||
if (isMusicPlaying) {
|
||||
mTransportState = TRANSPORT_VISIBLE;
|
||||
} else if (mTransportState == TRANSPORT_VISIBLE) {
|
||||
mTransportState = TRANSPORT_INVISIBLE;
|
||||
}
|
||||
int pageToShow = getAppropriateWidgetPage();
|
||||
int pageToShow = getAppropriateWidgetPage(isMusicPlaying);
|
||||
mAppWidgetContainer.setCurrentPage(pageToShow);
|
||||
}
|
||||
|
||||
private boolean isCameraOrAdd(int pageIndex) {
|
||||
private boolean isCameraPage(int 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)
|
||||
|
||||
boolean music = mTransportControl.isMusicPlaying() || mTransportState == TRANSPORT_VISIBLE;
|
||||
// if music playing, show transport
|
||||
if (music) {
|
||||
if (isMusicPlaying) {
|
||||
if (DEBUG) Log.d(TAG, "Music playing, show transport");
|
||||
return mAppWidgetContainer.indexOfChild(mTransportControl);
|
||||
}
|
||||
|
||||
// if multi-user applicable, show it
|
||||
UserManager userManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
|
||||
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 we have a valid sticky widget, show it
|
||||
int stickyWidgetIndex = mLockPatternUtils.getStickyAppWidgetIndex();
|
||||
if (stickyWidgetIndex > -1
|
||||
&& stickyWidgetIndex < mAppWidgetContainer.getChildCount()
|
||||
&& !isCameraOrAdd(stickyWidgetIndex)) {
|
||||
if (DEBUG) Log.d(TAG, "Sticky widget found, show it");
|
||||
&& !isAddPage(stickyWidgetIndex)
|
||||
&& !isCameraPage(stickyWidgetIndex)) {
|
||||
if (DEBUG) Log.d(TAG, "Valid sticky widget found, show page " + stickyWidgetIndex);
|
||||
return stickyWidgetIndex;
|
||||
}
|
||||
|
||||
// if we have a status view, show it
|
||||
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)
|
||||
// else show the right-most widget (except for camera)
|
||||
int rightMost = mAppWidgetContainer.getChildCount() - 1;
|
||||
if (mAppWidgetContainer.getChildAt(rightMost) instanceof CameraWidgetFrame) {
|
||||
if (isCameraPage(rightMost)) {
|
||||
rightMost--;
|
||||
}
|
||||
if (DEBUG) Log.d(TAG, "Show right-most");
|
||||
if (DEBUG) Log.d(TAG, "Show right-most page " + 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() {
|
||||
// if there are multiple users, we need to add the multi-user switcher widget to the
|
||||
// keyguard.
|
||||
// if there are multiple users, we need to enable to multi-user switcher
|
||||
UserManager mUm = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
|
||||
List<UserInfo> users = mUm.getUsers(true);
|
||||
|
||||
|
@ -116,7 +116,6 @@ public class KeyguardWidgetPager extends PagedView implements PagedView.PageSwit
|
||||
if (mCallbacks != null) {
|
||||
mCallbacks.onUserActivityTimeoutChanged();
|
||||
mCallbacks.userActivity();
|
||||
mCallbacks.onPageSwitch(newPageIndex);
|
||||
}
|
||||
KeyguardWidgetFrame oldWidgetPage = getWidgetPageAt(oldPageIndex);
|
||||
if (oldWidgetPage != null) {
|
||||
@ -156,7 +155,6 @@ public class KeyguardWidgetPager extends PagedView implements PagedView.PageSwit
|
||||
public interface Callbacks {
|
||||
public void userActivity();
|
||||
public void onUserActivityTimeoutChanged();
|
||||
public void onPageSwitch(int newPageIndex);
|
||||
}
|
||||
|
||||
public void addWidget(View widget) {
|
||||
|
Reference in New Issue
Block a user