4848import android .view .WindowManager ;
4949import android .view .animation .AnimationUtils ;
5050import android .widget .RemoteViews .OnClickHandler ;
51- import android .widget .TextView ;
5251
5352import com .android .internal .R ;
5453import com .android .internal .policy .impl .keyguard .KeyguardSecurityModel .SecurityMode ;
@@ -144,7 +143,7 @@ protected void dispatchDraw(Canvas canvas) {
144143 private int getWidgetPosition (int id ) {
145144 final int children = mAppWidgetContainer .getChildCount ();
146145 for (int i = 0 ; i < children ; i ++) {
147- if (mAppWidgetContainer .getChildAt ( i ).getId () == id ) {
146+ if (mAppWidgetContainer .getWidgetPageAt ( i ). getContent ( ).getId () == id ) {
148147 return i ;
149148 }
150149 }
@@ -864,7 +863,8 @@ KeyguardSecurityCallback getCallback() {
864863 @ Override
865864 LockPatternUtils getLockPatternUtils () {
866865 return mLockPatternUtils ;
867- }};
866+ }
867+ };
868868
869869 private void addDefaultWidgets () {
870870 LayoutInflater inflater = LayoutInflater .from (mContext );
@@ -906,6 +906,33 @@ public void run() {
906906 initializeTransportControl ();
907907 }
908908
909+ private void removeTransportFromWidgetPager () {
910+ int page = getWidgetPosition (R .id .keyguard_transport_control );
911+ if (page != -1 ) {
912+ mAppWidgetContainer .removeWidget (mTransportControl );
913+
914+ // XXX keep view attached so we still get show/hide events from AudioManager
915+ KeyguardHostView .this .addView (mTransportControl );
916+ mTransportControl .setVisibility (View .GONE );
917+ mTransportState = TRANSPORT_GONE ;
918+ mTransportControl .post (mSwitchPageRunnable );
919+ }
920+ }
921+
922+ private void addTransportToWidgetPager () {
923+ if (getWidgetPosition (R .id .keyguard_transport_control ) == -1 ) {
924+ KeyguardHostView .this .removeView (mTransportControl );
925+ // insert to left of camera if it exists, otherwise after right-most widget
926+ int lastWidget = mAppWidgetContainer .getChildCount () - 1 ;
927+ int position = 0 ; // handle no widget case
928+ if (lastWidget >= 0 ) {
929+ position = isCameraPage (lastWidget ) ? lastWidget : lastWidget + 1 ;
930+ }
931+ mAppWidgetContainer .addWidget (mTransportControl , position );
932+ mTransportControl .setVisibility (View .VISIBLE );
933+ }
934+ }
935+
909936 private void initializeTransportControl () {
910937 mTransportControl =
911938 (KeyguardTransportControlView ) findViewById (R .id .keyguard_transport_control );
@@ -917,24 +944,14 @@ private void initializeTransportControl() {
917944 mTransportControl .setKeyguardCallback (new TransportCallback () {
918945 @ Override
919946 public void onListenerDetached () {
920- int page = getWidgetPosition (R .id .keyguard_transport_control );
921- if (page != -1 ) {
922- mAppWidgetContainer .removeView (mTransportControl );
923- // XXX keep view attached so we still get show/hide events from AudioManager
924- KeyguardHostView .this .addView (mTransportControl );
925- mTransportControl .setVisibility (View .GONE );
926- mTransportState = TRANSPORT_GONE ;
927- mTransportControl .post (mSwitchPageRunnable );
928- }
947+ removeTransportFromWidgetPager ();
948+ mTransportControl .post (mSwitchPageRunnable );
929949 }
930950
931951 @ Override
932952 public void onListenerAttached () {
933- if (getWidgetPosition (R .id .keyguard_transport_control ) == -1 ) {
934- KeyguardHostView .this .removeView (mTransportControl );
935- mAppWidgetContainer .addView (mTransportControl , 0 );
936- mTransportControl .setVisibility (View .VISIBLE );
937- }
953+ // Transport will be added when playstate changes...
954+ mTransportControl .post (mSwitchPageRunnable );
938955 }
939956
940957 @ Override
@@ -1058,6 +1075,7 @@ private void showAppropriateWidgetPage() {
10581075 mTransportControl .isMusicPlaying () || mTransportState == TRANSPORT_VISIBLE ;
10591076 if (isMusicPlaying ) {
10601077 mTransportState = TRANSPORT_VISIBLE ;
1078+ addTransportToWidgetPager ();
10611079 } else if (mTransportState == TRANSPORT_VISIBLE ) {
10621080 mTransportState = TRANSPORT_INVISIBLE ;
10631081 }
@@ -1081,7 +1099,7 @@ private int getAppropriateWidgetPage(boolean isMusicPlaying) {
10811099 // if music playing, show transport
10821100 if (isMusicPlaying ) {
10831101 if (DEBUG ) Log .d (TAG , "Music playing, show transport" );
1084- return mAppWidgetContainer .indexOfChild (mTransportControl );
1102+ return mAppWidgetContainer .getWidgetPageIndex (mTransportControl );
10851103 }
10861104
10871105 // if we have a valid sticky widget, show it
0 commit comments