Merge "Increase lock screen timeout when on custom widget page." into jb-mr1-dev
This commit is contained in:
@@ -65,6 +65,7 @@ public class KeyguardHostView extends KeyguardViewBase {
|
||||
private static final String KEYGUARD_WIDGET_PREFS = "keyguard_widget_prefs";
|
||||
|
||||
private AppWidgetHost mAppWidgetHost;
|
||||
private KeyguardWidgetRegion mAppWidgetRegion;
|
||||
private KeyguardWidgetPager mAppWidgetContainer;
|
||||
private ViewFlipper mSecurityViewContainer;
|
||||
private KeyguardSelectorView mKeyguardSelectorView;
|
||||
@@ -142,9 +143,11 @@ public class KeyguardHostView extends KeyguardViewBase {
|
||||
|
||||
@Override
|
||||
protected void onFinishInflate() {
|
||||
mAppWidgetRegion = (KeyguardWidgetRegion) findViewById(R.id.kg_widget_region);
|
||||
mAppWidgetRegion.setVisibility(VISIBLE);
|
||||
mAppWidgetRegion.setCallbacks(mWidgetCallbacks);
|
||||
|
||||
mAppWidgetContainer = (KeyguardWidgetPager) findViewById(R.id.app_widget_container);
|
||||
KeyguardWidgetRegion kgwr = (KeyguardWidgetRegion) findViewById(R.id.kg_widget_region);
|
||||
kgwr.setVisibility(VISIBLE);
|
||||
mSecurityViewContainer = (ViewFlipper) findViewById(R.id.view_flipper);
|
||||
mKeyguardSelectorView = (KeyguardSelectorView) findViewById(R.id.keyguard_selector_view);
|
||||
|
||||
@@ -209,6 +212,33 @@ public class KeyguardHostView extends KeyguardViewBase {
|
||||
mAppWidgetContainer.addWidget(view);
|
||||
}
|
||||
|
||||
private KeyguardWidgetRegion.Callbacks mWidgetCallbacks
|
||||
= new KeyguardWidgetRegion.Callbacks() {
|
||||
@Override
|
||||
public void userActivity() {
|
||||
if (mViewMediatorCallback != null) {
|
||||
mViewMediatorCallback.userActivity();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUserActivityTimeoutChanged() {
|
||||
if (mViewMediatorCallback != null) {
|
||||
mViewMediatorCallback.onUserActivityTimeoutChanged();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public long getUserActivityTimeout() {
|
||||
// Currently only considering user activity timeouts needed by widgets.
|
||||
// Could also take into account longer timeouts for certain security views.
|
||||
if (mAppWidgetRegion != null) {
|
||||
return mAppWidgetRegion.getUserActivityTimeout();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
private KeyguardSecurityCallback mCallback = new KeyguardSecurityCallback() {
|
||||
|
||||
public void userActivity(long timeout) {
|
||||
|
||||
@@ -137,6 +137,12 @@ public abstract class KeyguardViewBase extends LinearLayout {
|
||||
*/
|
||||
abstract public void cleanUp();
|
||||
|
||||
/**
|
||||
* Gets the desired user activity timeout in milliseconds, or -1 if the
|
||||
* default should be used.
|
||||
*/
|
||||
abstract public long getUserActivityTimeout();
|
||||
|
||||
@Override
|
||||
public boolean dispatchKeyEvent(KeyEvent event) {
|
||||
if (interceptMediaKey(event)) {
|
||||
@@ -250,5 +256,4 @@ public abstract class KeyguardViewBase extends LinearLayout {
|
||||
KeyguardViewMediator.ViewMediatorCallback viewMediatorCallback) {
|
||||
mViewMediatorCallback = viewMediatorCallback;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -184,12 +184,13 @@ public class KeyguardViewManager {
|
||||
lp.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
|
||||
}
|
||||
lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_DISABLE_USER_ACTIVITY;
|
||||
lp.userActivityTimeout = KeyguardViewMediator.AWAKE_INTERVAL_DEFAULT_MS;
|
||||
lp.setTitle(isActivity ? "KeyguardMock" : "Keyguard");
|
||||
mWindowLayoutParams = lp;
|
||||
mViewManager.addView(mKeyguardHost, lp);
|
||||
}
|
||||
|
||||
inflateKeyguardView(options);
|
||||
updateUserActivityTimeoutInWindowLayoutParams();
|
||||
mViewManager.updateViewLayout(mKeyguardHost, mWindowLayoutParams);
|
||||
|
||||
mKeyguardHost.restoreHierarchyState(mStateContainer);
|
||||
@@ -224,6 +225,25 @@ public class KeyguardViewManager {
|
||||
}
|
||||
}
|
||||
|
||||
public void updateUserActivityTimeout() {
|
||||
updateUserActivityTimeoutInWindowLayoutParams();
|
||||
mViewManager.updateViewLayout(mKeyguardHost, mWindowLayoutParams);
|
||||
}
|
||||
|
||||
private void updateUserActivityTimeoutInWindowLayoutParams() {
|
||||
// Use the user activity timeout requested by the keyguard view, if any.
|
||||
if (mKeyguardView != null) {
|
||||
long timeout = mKeyguardView.getUserActivityTimeout();
|
||||
if (timeout >= 0) {
|
||||
mWindowLayoutParams.userActivityTimeout = timeout;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise, use the default timeout.
|
||||
mWindowLayoutParams.userActivityTimeout = KeyguardViewMediator.AWAKE_INTERVAL_DEFAULT_MS;
|
||||
}
|
||||
|
||||
private void maybeEnableScreenRotation(boolean enableScreenRotation) {
|
||||
// TODO: move this outside
|
||||
if (enableScreenRotation) {
|
||||
|
||||
@@ -259,9 +259,14 @@ public class KeyguardViewMediator {
|
||||
void wakeUp();
|
||||
|
||||
/**
|
||||
* Reports user activity and requests that the screen stay on for the specified
|
||||
* amount of time.
|
||||
* @param millis The amount of time in millis.
|
||||
* Reports user activity and requests that the screen stay on.
|
||||
*/
|
||||
void userActivity();
|
||||
|
||||
/**
|
||||
* Reports user activity and requests that the screen stay on for at least
|
||||
* the specified amount of time.
|
||||
* @param millis The amount of time in millis. This value is currently ignored.
|
||||
*/
|
||||
void userActivity(long millis);
|
||||
|
||||
@@ -284,6 +289,12 @@ public class KeyguardViewMediator {
|
||||
* @param needsInput
|
||||
*/
|
||||
void setNeedsInput(boolean needsInput);
|
||||
|
||||
/**
|
||||
* Tell view mediator that the keyguard view's desired user activity timeout
|
||||
* has changed and needs to be reapplied to the window.
|
||||
*/
|
||||
void onUserActivityTimeoutChanged();
|
||||
}
|
||||
|
||||
KeyguardUpdateMonitorCallback mUpdateCallback = new KeyguardUpdateMonitorCallback() {
|
||||
@@ -400,6 +411,10 @@ public class KeyguardViewMediator {
|
||||
KeyguardViewMediator.this.wakeUp();
|
||||
}
|
||||
|
||||
public void userActivity() {
|
||||
KeyguardViewMediator.this.userActivity();
|
||||
}
|
||||
|
||||
public void userActivity(long holdMs) {
|
||||
KeyguardViewMediator.this.userActivity(holdMs);
|
||||
}
|
||||
@@ -416,6 +431,11 @@ public class KeyguardViewMediator {
|
||||
public void setNeedsInput(boolean needsInput) {
|
||||
mKeyguardViewManager.setNeedsInput(needsInput);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUserActivityTimeoutChanged() {
|
||||
mKeyguardViewManager.updateUserActivityTimeout();
|
||||
}
|
||||
};
|
||||
|
||||
public void wakeUp() {
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
package com.android.internal.policy.impl.keyguard;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.PowerManager;
|
||||
import android.os.SystemClock;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@@ -31,7 +29,9 @@ public class KeyguardWidgetRegion extends LinearLayout implements PageSwitchList
|
||||
KeyguardGlowStripView mRightStrip;
|
||||
KeyguardWidgetPager mPager;
|
||||
private int mPage = 0;
|
||||
private PowerManager mPowerManager;
|
||||
private Callbacks mCallbacks;
|
||||
|
||||
private static final long CUSTOM_WIDGET_USER_ACTIVITY_TIMEOUT = 30000;
|
||||
|
||||
public KeyguardWidgetRegion(Context context) {
|
||||
this(context, null, 0);
|
||||
@@ -43,7 +43,6 @@ public class KeyguardWidgetRegion extends LinearLayout implements PageSwitchList
|
||||
|
||||
public KeyguardWidgetRegion(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
mPowerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -75,9 +74,10 @@ public class KeyguardWidgetRegion extends LinearLayout implements PageSwitchList
|
||||
@Override
|
||||
public void onPageSwitch(View newPage, int newPageIndex) {
|
||||
boolean showingStatusWidget = false;
|
||||
if ((newPage instanceof ViewGroup)) {
|
||||
if (newPage instanceof ViewGroup) {
|
||||
ViewGroup vg = (ViewGroup) newPage;
|
||||
if (vg.getChildAt(0) instanceof KeyguardStatusView) {
|
||||
View view = vg.getChildAt(0);
|
||||
if (view instanceof KeyguardStatusView) {
|
||||
showingStatusWidget = true;
|
||||
}
|
||||
}
|
||||
@@ -91,8 +91,33 @@ public class KeyguardWidgetRegion extends LinearLayout implements PageSwitchList
|
||||
|
||||
// Extend the display timeout if the user switches pages
|
||||
if (mPage != newPageIndex) {
|
||||
mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
|
||||
mPage = newPageIndex;
|
||||
if (mCallbacks != null) {
|
||||
mCallbacks.onUserActivityTimeoutChanged();
|
||||
mCallbacks.userActivity();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public long getUserActivityTimeout() {
|
||||
View page = mPager.getPageAt(mPage);
|
||||
if (page instanceof ViewGroup) {
|
||||
ViewGroup vg = (ViewGroup) page;
|
||||
View view = vg.getChildAt(0);
|
||||
if (!(view instanceof KeyguardStatusView)
|
||||
&& !(view instanceof KeyguardMultiUserSelectorView)) {
|
||||
return CUSTOM_WIDGET_USER_ACTIVITY_TIMEOUT;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public void setCallbacks(Callbacks callbacks) {
|
||||
mCallbacks = callbacks;
|
||||
}
|
||||
|
||||
public interface Callbacks {
|
||||
public void userActivity();
|
||||
public void onUserActivityTimeoutChanged();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user