@@ -249,6 +249,14 @@ public void onUserActivityTimeoutChanged() {
249249 mViewMediatorCallback .onUserActivityTimeoutChanged ();
250250 }
251251 }
252+
253+ @ Override
254+ public void onPageSwitch (int newPageIndex ) {
255+ if (!isCameraOrAdd (newPageIndex )) {
256+ if (DEBUG ) Log .d (TAG , "Setting sticky widget index: " + newPageIndex );
257+ mLockPatternUtils .setStickyWidgetIndex (newPageIndex );
258+ }
259+ }
252260 };
253261
254262 @ Override
@@ -712,7 +720,7 @@ private void showSecurityScreen(SecurityMode securityMode) {
712720
713721 @ Override
714722 public void onScreenTurnedOn () {
715- if (DEBUG ) Log .d (TAG , "screen on" );
723+ if (DEBUG ) Log .d (TAG , "screen on, instance " + Integer . toHexString ( hashCode ()) );
716724 showPrimarySecurityScreen (false );
717725 getSecurityView (mCurrentSecuritySelection ).onResume ();
718726
@@ -728,7 +736,7 @@ public void onScreenTurnedOn() {
728736
729737 @ Override
730738 public void onScreenTurnedOff () {
731- if (DEBUG ) Log .d (TAG , "screen off" );
739+ if (DEBUG ) Log .d (TAG , "screen off, instance " + Integer . toHexString ( hashCode ()) );
732740 showPrimarySecurityScreen (true );
733741 getSecurityView (mCurrentSecuritySelection ).onPause ();
734742 }
@@ -849,6 +857,7 @@ public void onCameraLaunched() {
849857 SlidingChallengeLayout slider = locateSlider ();
850858 if (slider != null ) {
851859 slider .showHandle (true );
860+ slider .showChallenge (true );
852861 }
853862 View v = mAppWidgetContainer .getChildAt (mAppWidgetContainer .getCurrentPage ());
854863 if (v instanceof CameraWidgetFrame ) {
@@ -1060,41 +1069,66 @@ public void onRestoreInstanceState(Parcelable state) {
10601069 }
10611070
10621071 private void showAppropriateWidgetPage () {
1063-
1064- // The following sets the priority for showing widgets. Transport should be shown if
1065- // music is playing, followed by the multi-user widget if enabled, followed by the
1066- // status widget.
1067- final int pageToShow ;
1068- if (mTransportControl .isMusicPlaying () || mTransportState == TRANSPORT_VISIBLE ) {
1072+ boolean music = mTransportControl .isMusicPlaying () || mTransportState == TRANSPORT_VISIBLE ;
1073+ if (music ) {
10691074 mTransportState = TRANSPORT_VISIBLE ;
1070- pageToShow = mAppWidgetContainer .indexOfChild (mTransportControl );
1071- } else {
1072- UserManager mUm = (UserManager ) mContext .getSystemService (Context .USER_SERVICE );
1073- final View multiUserView = findViewById (R .id .keyguard_multi_user_selector );
1074- final int multiUserPosition = mAppWidgetContainer .indexOfChild (multiUserView );
1075- if (multiUserPosition != -1 && mUm .getUsers (true ).size () > 1 ) {
1076- pageToShow = multiUserPosition ;
1077- } else {
1078- final View statusView = findViewById (R .id .keyguard_status_view );
1079- int statusViewIndex = mAppWidgetContainer .indexOfChild (statusView );
1080- if (statusViewIndex == -1 ) {
1081- // TEMP code for default page
1082- if (mAppWidgetContainer .getChildCount () > 2 ) {
1083- pageToShow = mAppWidgetContainer .getChildCount () - 2 ;
1084- } else {
1085- pageToShow = 0 ;
1086- }
1087- } else {
1088- pageToShow = mAppWidgetContainer .indexOfChild (statusView );
1089- }
1090- }
1091- if (mTransportState == TRANSPORT_VISIBLE ) {
1092- mTransportState = TRANSPORT_INVISIBLE ;
1093- }
1075+ } else if (mTransportState == TRANSPORT_VISIBLE ) {
1076+ mTransportState = TRANSPORT_INVISIBLE ;
10941077 }
1078+ int pageToShow = getAppropriateWidgetPage ();
10951079 mAppWidgetContainer .setCurrentPage (pageToShow );
10961080 }
10971081
1082+ private boolean isCameraOrAdd (int pageIndex ) {
1083+ View v = mAppWidgetContainer .getChildAt (pageIndex );
1084+ return v .getId () == R .id .keyguard_add_widget || v instanceof CameraWidgetFrame ;
1085+ }
1086+
1087+ private int getAppropriateWidgetPage () {
1088+ // assumes at least one widget (besides camera + add)
1089+
1090+ boolean music = mTransportControl .isMusicPlaying () || mTransportState == TRANSPORT_VISIBLE ;
1091+ // if music playing, show transport
1092+ if (music ) {
1093+ if (DEBUG ) Log .d (TAG , "Music playing, show transport" );
1094+ return mAppWidgetContainer .indexOfChild (mTransportControl );
1095+ }
1096+
1097+ // if multi-user applicable, show it
1098+ UserManager userManager = (UserManager ) mContext .getSystemService (Context .USER_SERVICE );
1099+ View multiUserView = findViewById (R .id .keyguard_multi_user_selector );
1100+ int multiUserPosition = mAppWidgetContainer .indexOfChild (multiUserView );
1101+ if (multiUserPosition != -1 && userManager .getUsers (true ).size () > 1 ) {
1102+ if (DEBUG ) Log .d (TAG , "Multi-user applicable, show it" );
1103+ return multiUserPosition ;
1104+ }
1105+
1106+ // if we have a sticky widget, show it
1107+ int stickyWidgetIndex = mLockPatternUtils .getStickyWidgetIndex ();
1108+ if (stickyWidgetIndex > -1
1109+ && stickyWidgetIndex < mAppWidgetContainer .getChildCount ()
1110+ && !isCameraOrAdd (stickyWidgetIndex )) {
1111+ if (DEBUG ) Log .d (TAG , "Sticky widget found, show it" );
1112+ return stickyWidgetIndex ;
1113+ }
1114+
1115+ // if we have a status view, show it
1116+ View statusView = findViewById (R .id .keyguard_status_view );
1117+ int statusViewIndex = mAppWidgetContainer .indexOfChild (statusView );
1118+ if (statusViewIndex > -1 ) {
1119+ if (DEBUG ) Log .d (TAG , "Status widget found, show it" );
1120+ return mAppWidgetContainer .indexOfChild (statusView );
1121+ }
1122+
1123+ // else the right-most (except for camera)
1124+ int rightMost = mAppWidgetContainer .getChildCount () - 1 ;
1125+ if (mAppWidgetContainer .getChildAt (rightMost ) instanceof CameraWidgetFrame ) {
1126+ rightMost --;
1127+ }
1128+ if (DEBUG ) Log .d (TAG , "Show right-most" );
1129+ return rightMost ;
1130+ }
1131+
10981132 private void enableUserSelectorIfNecessary () {
10991133 // if there are multiple users, we need to add the multi-user switcher widget to the
11001134 // keyguard.
0 commit comments