@@ -67,6 +67,7 @@ public class KeyguardHostView extends KeyguardViewBase {
6767 private AppWidgetHost mAppWidgetHost ;
6868 private KeyguardWidgetPager mAppWidgetContainer ;
6969 private ViewFlipper mSecurityViewContainer ;
70+ private KeyguardTransportControlView mTransportControl ;
7071 private boolean mEnableMenuKey ;
7172 private boolean mIsVerifyUnlockOnly ;
7273 private boolean mEnableFallback ; // TODO: This should get the value from KeyguardPatternView
@@ -80,7 +81,6 @@ public class KeyguardHostView extends KeyguardViewBase {
8081 private KeyguardSecurityModel mSecurityModel ;
8182
8283 private Rect mTempRect = new Rect ();
83- private KeyguardTransportControlView mTransportControl ;
8484
8585 /*package*/ interface TransportCallback {
8686 void hide ();
@@ -145,45 +145,7 @@ protected void onFinishInflate() {
145145 kgwr .setVisibility (VISIBLE );
146146 mSecurityViewContainer = (ViewFlipper ) findViewById (R .id .view_flipper );
147147
148- // This code manages showing/hiding the transport control. We keep it around and only
149- // add it to the hierarchy if it needs to be present.
150- mTransportControl =
151- (KeyguardTransportControlView ) findViewById (R .id .keyguard_transport_control );
152- if (mTransportControl != null ) {
153- mTransportControl .setKeyguardCallback (new TransportCallback () {
154- boolean mSticky = false ;
155- @ Override
156- public void hide () {
157- int page = getWidgetPosition (R .id .keyguard_transport_control );
158- if (page != -1 && !mSticky ) {
159- if (page == mAppWidgetContainer .getCurrentPage ()) {
160- // Switch back to clock view if music was showing.
161- mAppWidgetContainer
162- .setCurrentPage (getWidgetPosition (R .id .keyguard_status_view ));
163- }
164- mAppWidgetContainer .removeView (mTransportControl );
165- // XXX keep view attached to hierarchy so we still get show/hide events
166- // from AudioManager
167- KeyguardHostView .this .addView (mTransportControl );
168- mTransportControl .setVisibility (View .GONE );
169- showAppropriateWidgetPage ();
170- }
171- }
172-
173- @ Override
174- public void show () {
175- if (getWidgetPosition (R .id .keyguard_transport_control ) == -1 ) {
176- KeyguardHostView .this .removeView (mTransportControl );
177- mAppWidgetContainer .addView (mTransportControl ,
178- getWidgetPosition (R .id .keyguard_status_view ) + 1 );
179- mTransportControl .setVisibility (View .VISIBLE );
180- // Once shown, leave it showing
181- mSticky = true ;
182- showAppropriateWidgetPage ();
183- }
184- }
185- });
186- }
148+ addDefaultWidgets ();
187149 updateSecurityViews ();
188150 setSystemUiVisibility (getSystemUiVisibility () | View .STATUS_BAR_DISABLE_BACK );
189151 }
@@ -702,6 +664,52 @@ private void addWidget(int appId) {
702664 }
703665 }
704666
667+ private void addDefaultWidgets () {
668+ LayoutInflater inflater = LayoutInflater .from (mContext );
669+ inflater .inflate (R .layout .keyguard_status_view , mAppWidgetContainer , true );
670+ inflater .inflate (R .layout .keyguard_transport_control_view , mAppWidgetContainer , true );
671+
672+ mTransportControl =
673+ (KeyguardTransportControlView ) findViewById (R .id .keyguard_transport_control );
674+
675+
676+ // This code manages showing/hiding the transport control. We keep it around and only
677+ // add it to the hierarchy if it needs to be present.
678+ if (mTransportControl != null ) {
679+ mTransportControl .setKeyguardCallback (new TransportCallback () {
680+ boolean mSticky = false ;
681+ @ Override
682+ public void hide () {
683+ int page = getWidgetPosition (R .id .keyguard_transport_control );
684+ if (page != -1 && !mSticky ) {
685+ if (page == mAppWidgetContainer .getCurrentPage ()) {
686+ // Switch back to clock view if music was showing.
687+ mAppWidgetContainer
688+ .setCurrentPage (getWidgetPosition (R .id .keyguard_status_view ));
689+ }
690+ mAppWidgetContainer .removeView (mTransportControl );
691+ // XXX keep view attached to hierarchy so we still get show/hide events
692+ // from AudioManager
693+ KeyguardHostView .this .addView (mTransportControl );
694+ mTransportControl .setVisibility (View .GONE );
695+ }
696+ }
697+
698+ @ Override
699+ public void show () {
700+ if (getWidgetPosition (R .id .keyguard_transport_control ) == -1 ) {
701+ KeyguardHostView .this .removeView (mTransportControl );
702+ mAppWidgetContainer .addView (mTransportControl ,
703+ getWidgetPosition (R .id .keyguard_status_view ) + 1 );
704+ mTransportControl .setVisibility (View .VISIBLE );
705+ // Once shown, leave it showing
706+ mSticky = true ;
707+ }
708+ }
709+ });
710+ }
711+ }
712+
705713 private void maybePopulateWidgets () {
706714 DevicePolicyManager dpm =
707715 (DevicePolicyManager ) mContext .getSystemService (Context .DEVICE_POLICY_SERVICE );
0 commit comments