@@ -82,6 +82,9 @@ public class KeyguardHostView extends KeyguardViewBase {
8282 private KeyguardSecurityModel mSecurityModel ;
8383 private KeyguardViewStateManager mViewStateManager ;
8484
85+ int mLocalStickyWidget = -1 ;
86+ boolean mPersitentStickyWidgetLoaded = false ;
87+
8588 private Rect mTempRect = new Rect ();
8689
8790 /*package*/ interface TransportCallback {
@@ -109,7 +112,7 @@ public KeyguardHostView(Context context, AttributeSet attrs) {
109112 mAppWidgetManager = AppWidgetManager .getInstance (mContext );
110113 mSecurityModel = new KeyguardSecurityModel (context );
111114
112- mViewStateManager = new KeyguardViewStateManager ();
115+ mViewStateManager = new KeyguardViewStateManager (this );
113116 }
114117
115118 @ Override
@@ -1169,6 +1172,37 @@ private boolean isAddPage(int pageIndex) {
11691172 return v != null && v .getId () == R .id .keyguard_add_widget ;
11701173 }
11711174
1175+ private boolean isMusicPage (int pageIndex ) {
1176+ return pageIndex >= 0 && pageIndex == getWidgetPosition (R .id .keyguard_transport_control );
1177+ }
1178+
1179+ private int getStickyWidget () {
1180+ // The first time we query the persistent state. From that point, we use a locally updated
1181+ // notion of the sticky widget page.
1182+ if (!mPersitentStickyWidgetLoaded ) {
1183+ mLocalStickyWidget = mLockPatternUtils .getStickyAppWidgetIndex ();
1184+ mPersitentStickyWidgetLoaded = true ;
1185+ }
1186+ return mLocalStickyWidget ;
1187+ }
1188+
1189+ public void updateStickyWidget (int index ) {
1190+ if (index < 0 || index >= mAppWidgetContainer .getChildCount ()) {
1191+ return ;
1192+ }
1193+ if (isAddPage (index )) {
1194+ return ;
1195+ }
1196+ if (isCameraPage (index )) {
1197+ return ;
1198+ }
1199+ if (isMusicPage (index )) {
1200+ return ;
1201+ }
1202+
1203+ mLocalStickyWidget = index ;
1204+ }
1205+
11721206 private int getAppropriateWidgetPage (boolean isMusicPlaying ) {
11731207 // assumes at least one widget (besides camera + add)
11741208
@@ -1179,7 +1213,7 @@ private int getAppropriateWidgetPage(boolean isMusicPlaying) {
11791213 }
11801214
11811215 // if we have a valid sticky widget, show it
1182- int stickyWidgetIndex = mLockPatternUtils . getStickyAppWidgetIndex ();
1216+ int stickyWidgetIndex = getStickyWidget ();
11831217 if (stickyWidgetIndex > -1
11841218 && stickyWidgetIndex < mAppWidgetContainer .getChildCount ()
11851219 && !isAddPage (stickyWidgetIndex )
@@ -1198,18 +1232,10 @@ private int getAppropriateWidgetPage(boolean isMusicPlaying) {
11981232 }
11991233
12001234 private void saveStickyWidgetIndex () {
1201- int stickyWidgetIndex = mAppWidgetContainer .getCurrentPage ();
1202- if (isAddPage (stickyWidgetIndex )) {
1203- stickyWidgetIndex ++;
1204- }
1205- if (isCameraPage (stickyWidgetIndex )) {
1206- stickyWidgetIndex --;
1207- }
1208- if (stickyWidgetIndex < 0 || stickyWidgetIndex >= mAppWidgetContainer .getChildCount ()) {
1209- stickyWidgetIndex = -1 ;
1235+ if (DEBUG ) Log .d (TAG , "saveStickyWidgetIndex: " + mLocalStickyWidget );
1236+ if (mPersitentStickyWidgetLoaded && mLocalStickyWidget >= 0 ) {
1237+ mLockPatternUtils .setStickyAppWidgetIndex (mLocalStickyWidget );
12101238 }
1211- if (DEBUG ) Log .d (TAG , "saveStickyWidgetIndex: " + stickyWidgetIndex );
1212- mLockPatternUtils .setStickyAppWidgetIndex (stickyWidgetIndex );
12131239 }
12141240
12151241 private void enableUserSelectorIfNecessary () {
0 commit comments