4141import android .view .LayoutInflater ;
4242import android .view .MotionEvent ;
4343import android .view .View ;
44+ import android .view .ViewGroup ;
45+ import android .view .ViewGroup .LayoutParams ;
4446import android .view .WindowManager ;
4547import android .view .animation .AnimationUtils ;
4648import android .widget .RemoteViews .OnClickHandler ;
5456import java .util .List ;
5557
5658public class KeyguardHostView extends KeyguardViewBase {
59+ private static final String TAG = "KeyguardViewHost" ;
60+
5761 // Use this to debug all of keyguard
5862 public static boolean DEBUG ;
5963
6064 static final int APPWIDGET_HOST_ID = 0x4B455947 ;
6165 private static final String KEYGUARD_WIDGET_PREFS = "keyguard_widget_prefs" ;
6266
63- private static final String TAG = "KeyguardViewHost" ;
6467 private AppWidgetHost mAppWidgetHost ;
6568 private KeyguardWidgetPager mAppWidgetContainer ;
6669 private ViewFlipper mSecurityViewContainer ;
@@ -77,6 +80,12 @@ public class KeyguardHostView extends KeyguardViewBase {
7780 private KeyguardSecurityModel mSecurityModel ;
7881
7982 private Rect mTempRect = new Rect ();
83+ private KeyguardTransportControlView mTransportControl ;
84+
85+ /*package*/ interface TransportCallback {
86+ void hide ();
87+ void show ();
88+ }
8089
8190 public KeyguardHostView (Context context ) {
8291 this (context , null );
@@ -111,11 +120,56 @@ protected void dispatchDraw(Canvas canvas) {
111120 mViewMediatorCallback .keyguardDoneDrawing ();
112121 }
113122
123+ private int getWidgetPosition (int id ) {
124+ final int children = mAppWidgetContainer .getChildCount ();
125+ for (int i = 0 ; i < children ; i ++) {
126+ if (mAppWidgetContainer .getChildAt (i ).getId () == id ) {
127+ return i ;
128+ }
129+ }
130+ return -1 ;
131+ }
132+
114133 @ Override
115134 protected void onFinishInflate () {
116135 mAppWidgetContainer = (KeyguardWidgetPager ) findViewById (R .id .app_widget_container );
117136 mAppWidgetContainer .setVisibility (VISIBLE );
118137 mSecurityViewContainer = (ViewFlipper ) findViewById (R .id .view_flipper );
138+
139+ // This code manages showing/hiding the transport control. We keep it around and only
140+ // add it to the hierarchy if it needs to be present.
141+ mTransportControl =
142+ (KeyguardTransportControlView ) findViewById (R .id .keyguard_transport_control );
143+ if (mTransportControl != null ) {
144+ mTransportControl .setKeyguardCallback (new TransportCallback () {
145+ @ Override
146+ public void hide () {
147+ int page = getWidgetPosition (R .id .keyguard_transport_control );
148+ if (page != -1 ) {
149+ if (page == mAppWidgetContainer .getCurrentPage ()) {
150+ // Switch back to clock view if music was showing.
151+ mAppWidgetContainer
152+ .setCurrentPage (getWidgetPosition (R .id .keyguard_status_view ));
153+ }
154+ mAppWidgetContainer .removeView (mTransportControl );
155+ // XXX keep view attached to hierarchy so we still get show/hide events
156+ // from AudioManager
157+ KeyguardHostView .this .addView (mTransportControl );
158+ mTransportControl .setVisibility (View .GONE );
159+ }
160+ }
161+
162+ @ Override
163+ public void show () {
164+ if (getWidgetPosition (R .id .keyguard_transport_control ) == -1 ) {
165+ KeyguardHostView .this .removeView (mTransportControl );
166+ mAppWidgetContainer .addView (mTransportControl ,
167+ getWidgetPosition (R .id .keyguard_status_view ) + 1 );
168+ mTransportControl .setVisibility (View .VISIBLE );
169+ }
170+ }
171+ });
172+ }
119173 updateSecurityViews ();
120174 }
121175
@@ -423,6 +477,7 @@ public void run() {
423477 @ Override
424478 public void reset () {
425479 mIsVerifyUnlockOnly = false ;
480+ mAppWidgetContainer .setCurrentPage (getWidgetPosition (R .id .keyguard_status_view ));
426481 requestFocus ();
427482 }
428483
@@ -639,8 +694,8 @@ private void inflateAndAddUserSelectorWidgetIfNecessary() {
639694 KeyguardWidgetFrame userswitcher = (KeyguardWidgetFrame )
640695 LayoutInflater .from (mContext ).inflate (R .layout .keyguard_multi_user_selector_widget ,
641696 mAppWidgetContainer , false );
642- // add the switcher in the first position
643- mAppWidgetContainer .addView (userswitcher , 0 );
697+ // add the switcher to the left of status view
698+ mAppWidgetContainer .addView (userswitcher , getWidgetPosition ( R . id . keyguard_status_view ) );
644699 }
645700 }
646701
0 commit comments