Merge "Implement "sticky" widget logic." into jb-mr1-lockscreen-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
011717d064
@ -150,6 +150,7 @@ 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;
|
||||||
@ -1310,4 +1311,12 @@ 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,6 +249,14 @@ 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
|
||||||
@ -712,7 +720,7 @@ public class KeyguardHostView extends KeyguardViewBase {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onScreenTurnedOn() {
|
public void onScreenTurnedOn() {
|
||||||
if (DEBUG) Log.d(TAG, "screen on");
|
if (DEBUG) Log.d(TAG, "screen on, instance " + Integer.toHexString(hashCode()));
|
||||||
showPrimarySecurityScreen(false);
|
showPrimarySecurityScreen(false);
|
||||||
getSecurityView(mCurrentSecuritySelection).onResume();
|
getSecurityView(mCurrentSecuritySelection).onResume();
|
||||||
|
|
||||||
@ -728,7 +736,7 @@ public class KeyguardHostView extends KeyguardViewBase {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onScreenTurnedOff() {
|
public void onScreenTurnedOff() {
|
||||||
if (DEBUG) Log.d(TAG, "screen off");
|
if (DEBUG) Log.d(TAG, "screen off, instance " + Integer.toHexString(hashCode()));
|
||||||
showPrimarySecurityScreen(true);
|
showPrimarySecurityScreen(true);
|
||||||
getSecurityView(mCurrentSecuritySelection).onPause();
|
getSecurityView(mCurrentSecuritySelection).onPause();
|
||||||
}
|
}
|
||||||
@ -849,6 +857,7 @@ public class KeyguardHostView extends KeyguardViewBase {
|
|||||||
SlidingChallengeLayout slider = locateSlider();
|
SlidingChallengeLayout slider = locateSlider();
|
||||||
if (slider != null) {
|
if (slider != null) {
|
||||||
slider.showHandle(true);
|
slider.showHandle(true);
|
||||||
|
slider.showChallenge(true);
|
||||||
}
|
}
|
||||||
View v = mAppWidgetContainer.getChildAt(mAppWidgetContainer.getCurrentPage());
|
View v = mAppWidgetContainer.getChildAt(mAppWidgetContainer.getCurrentPage());
|
||||||
if (v instanceof CameraWidgetFrame) {
|
if (v instanceof CameraWidgetFrame) {
|
||||||
@ -1060,41 +1069,66 @@ public class KeyguardHostView extends KeyguardViewBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void showAppropriateWidgetPage() {
|
private void showAppropriateWidgetPage() {
|
||||||
|
boolean music = mTransportControl.isMusicPlaying() || mTransportState == TRANSPORT_VISIBLE;
|
||||||
// The following sets the priority for showing widgets. Transport should be shown if
|
if (music) {
|
||||||
// music is playing, followed by the multi-user widget if enabled, followed by the
|
|
||||||
// status widget.
|
|
||||||
final int pageToShow;
|
|
||||||
if (mTransportControl.isMusicPlaying() || mTransportState == TRANSPORT_VISIBLE) {
|
|
||||||
mTransportState = TRANSPORT_VISIBLE;
|
mTransportState = TRANSPORT_VISIBLE;
|
||||||
pageToShow = mAppWidgetContainer.indexOfChild(mTransportControl);
|
} else if (mTransportState == TRANSPORT_VISIBLE) {
|
||||||
} else {
|
mTransportState = TRANSPORT_INVISIBLE;
|
||||||
UserManager mUm = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
|
|
||||||
final View multiUserView = findViewById(R.id.keyguard_multi_user_selector);
|
|
||||||
final int multiUserPosition = mAppWidgetContainer.indexOfChild(multiUserView);
|
|
||||||
if (multiUserPosition != -1 && mUm.getUsers(true).size() > 1) {
|
|
||||||
pageToShow = multiUserPosition;
|
|
||||||
} else {
|
|
||||||
final View statusView = findViewById(R.id.keyguard_status_view);
|
|
||||||
int statusViewIndex = mAppWidgetContainer.indexOfChild(statusView);
|
|
||||||
if (statusViewIndex == -1) {
|
|
||||||
// TEMP code for default page
|
|
||||||
if (mAppWidgetContainer.getChildCount() > 2) {
|
|
||||||
pageToShow = mAppWidgetContainer.getChildCount() - 2;
|
|
||||||
} else {
|
|
||||||
pageToShow = 0;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
pageToShow = mAppWidgetContainer.indexOfChild(statusView);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (mTransportState == TRANSPORT_VISIBLE) {
|
|
||||||
mTransportState = TRANSPORT_INVISIBLE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
int pageToShow = getAppropriateWidgetPage();
|
||||||
mAppWidgetContainer.setCurrentPage(pageToShow);
|
mAppWidgetContainer.setCurrentPage(pageToShow);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isCameraOrAdd(int pageIndex) {
|
||||||
|
View v = mAppWidgetContainer.getChildAt(pageIndex);
|
||||||
|
return v.getId() == R.id.keyguard_add_widget || v instanceof CameraWidgetFrame;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getAppropriateWidgetPage() {
|
||||||
|
// assumes at least one widget (besides camera + add)
|
||||||
|
|
||||||
|
boolean music = mTransportControl.isMusicPlaying() || mTransportState == TRANSPORT_VISIBLE;
|
||||||
|
// if music playing, show transport
|
||||||
|
if (music) {
|
||||||
|
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 (stickyWidgetIndex > -1
|
||||||
|
&& stickyWidgetIndex < mAppWidgetContainer.getChildCount()
|
||||||
|
&& !isCameraOrAdd(stickyWidgetIndex)) {
|
||||||
|
if (DEBUG) Log.d(TAG, "Sticky widget found, show it");
|
||||||
|
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)
|
||||||
|
int rightMost = mAppWidgetContainer.getChildCount() - 1;
|
||||||
|
if (mAppWidgetContainer.getChildAt(rightMost) instanceof CameraWidgetFrame) {
|
||||||
|
rightMost--;
|
||||||
|
}
|
||||||
|
if (DEBUG) Log.d(TAG, "Show right-most");
|
||||||
|
return rightMost;
|
||||||
|
}
|
||||||
|
|
||||||
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 add the multi-user switcher widget to the
|
||||||
// keyguard.
|
// keyguard.
|
||||||
|
@ -110,6 +110,7 @@ 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) {
|
||||||
@ -149,6 +150,7 @@ 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