@@ -84,6 +84,9 @@ public class KeyguardHostView extends KeyguardViewBase {
8484 private KeyguardSecurityModel mSecurityModel ;
8585 private KeyguardViewStateManager mViewStateManager ;
8686
87+ int mLocalStickyWidget = -1 ;
88+ boolean mPersitentStickyWidgetLoaded = false ;
89+
8790 private Rect mTempRect = new Rect ();
8891
8992 /*package*/ interface TransportCallback {
@@ -111,7 +114,7 @@ public KeyguardHostView(Context context, AttributeSet attrs) {
111114 mAppWidgetManager = AppWidgetManager .getInstance (mContext );
112115 mSecurityModel = new KeyguardSecurityModel (context );
113116
114- mViewStateManager = new KeyguardViewStateManager ();
117+ mViewStateManager = new KeyguardViewStateManager (this );
115118 }
116119
117120 @ Override
@@ -1206,6 +1209,37 @@ private boolean isAddPage(int pageIndex) {
12061209 return v != null && v .getId () == R .id .keyguard_add_widget ;
12071210 }
12081211
1212+ private boolean isMusicPage (int pageIndex ) {
1213+ return pageIndex >= 0 && pageIndex == getWidgetPosition (R .id .keyguard_transport_control );
1214+ }
1215+
1216+ private int getStickyWidget () {
1217+ // The first time we query the persistent state. From that point, we use a locally updated
1218+ // notion of the sticky widget page.
1219+ if (!mPersitentStickyWidgetLoaded ) {
1220+ mLocalStickyWidget = mLockPatternUtils .getStickyAppWidgetIndex ();
1221+ mPersitentStickyWidgetLoaded = true ;
1222+ }
1223+ return mLocalStickyWidget ;
1224+ }
1225+
1226+ public void updateStickyWidget (int index ) {
1227+ if (index < 0 || index >= mAppWidgetContainer .getChildCount ()) {
1228+ return ;
1229+ }
1230+ if (isAddPage (index )) {
1231+ return ;
1232+ }
1233+ if (isCameraPage (index )) {
1234+ return ;
1235+ }
1236+ if (isMusicPage (index )) {
1237+ return ;
1238+ }
1239+
1240+ mLocalStickyWidget = index ;
1241+ }
1242+
12091243 private int getAppropriateWidgetPage (boolean isMusicPlaying ) {
12101244 // assumes at least one widget (besides camera + add)
12111245
@@ -1216,7 +1250,7 @@ private int getAppropriateWidgetPage(boolean isMusicPlaying) {
12161250 }
12171251
12181252 // if we have a valid sticky widget, show it
1219- int stickyWidgetIndex = mLockPatternUtils . getStickyAppWidgetIndex ();
1253+ int stickyWidgetIndex = getStickyWidget ();
12201254 if (stickyWidgetIndex > -1
12211255 && stickyWidgetIndex < mAppWidgetContainer .getChildCount ()
12221256 && !isAddPage (stickyWidgetIndex )
@@ -1235,18 +1269,10 @@ private int getAppropriateWidgetPage(boolean isMusicPlaying) {
12351269 }
12361270
12371271 private void saveStickyWidgetIndex () {
1238- int stickyWidgetIndex = mAppWidgetContainer .getCurrentPage ();
1239- if (isAddPage (stickyWidgetIndex )) {
1240- stickyWidgetIndex ++;
1241- }
1242- if (isCameraPage (stickyWidgetIndex )) {
1243- stickyWidgetIndex --;
1244- }
1245- if (stickyWidgetIndex < 0 || stickyWidgetIndex >= mAppWidgetContainer .getChildCount ()) {
1246- stickyWidgetIndex = -1 ;
1272+ if (DEBUG ) Log .d (TAG , "saveStickyWidgetIndex: " + mLocalStickyWidget );
1273+ if (mPersitentStickyWidgetLoaded && mLocalStickyWidget >= 0 ) {
1274+ mLockPatternUtils .setStickyAppWidgetIndex (mLocalStickyWidget );
12471275 }
1248- if (DEBUG ) Log .d (TAG , "saveStickyWidgetIndex: " + stickyWidgetIndex );
1249- mLockPatternUtils .setStickyAppWidgetIndex (stickyWidgetIndex );
12501276 }
12511277
12521278 private void enableUserSelectorIfNecessary () {
0 commit comments