Skip to content

Commit ff2aa0b

Browse files
author
Jim Miller
committed
Initial pass at adding Music control to new keyguard.
- View is now added or removed based on AudioManager status - Reduced depth of hierarchy by making KeyguardTransportControl a KeyguardWidgetFrame - Return to the status view when we return to keyguard (onScreenTurnedOn) Change-Id: Id7f9310ce4e7daf663471117564e5670f61b1471
1 parent d428e95 commit ff2aa0b

File tree

10 files changed

+613
-12
lines changed

10 files changed

+613
-12
lines changed

core/res/res/layout-land/keyguard_host_view.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535

3636
<!-- TODO: Remove this once supported as a widget -->
3737
<include layout="@layout/keyguard_status_view"/>
38+
<include layout="@layout/keyguard_transport_control_view"/>
39+
3840
</com.android.internal.policy.impl.keyguard.KeyguardWidgetPager>
3941

4042

core/res/res/layout-sw600dp-land/keyguard_host_view.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
<!-- TODO: Remove this once supported as a widget -->
3737
<include layout="@layout/keyguard_status_view"/>
38+
<include layout="@layout/keyguard_transport_control_view"/>
3839

3940
</com.android.internal.policy.impl.keyguard.KeyguardWidgetPager>
4041

core/res/res/layout-sw600dp-port/keyguard_host_view.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
android:orientation="vertical"
2626
android:layout_width="match_parent"
2727
android:layout_height="match_parent"
28-
android:gravity="center_horizontal"
29-
android:clipChildren="false">
28+
android:gravity="center_horizontal">
3029

3130
<com.android.internal.policy.impl.keyguard.KeyguardWidgetPager
3231
android:id="@+id/app_widget_container"
@@ -37,6 +36,7 @@
3736

3837
<!-- TODO: Remove this once supported as a widget -->
3938
<include layout="@layout/keyguard_status_view"/>
39+
<include layout="@layout/keyguard_transport_control_view"/>
4040

4141
</com.android.internal.policy.impl.keyguard.KeyguardWidgetPager>
4242

core/res/res/layout/keyguard_selector_view.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
android:visibility="gone">
3535
<!-- TODO: Remove this when supported as a widget -->
3636
<include layout="@layout/keyguard_status_view"/>
37+
<include layout="@layout/keyguard_transport_control_view"/>
3738
</com.android.internal.policy.impl.keyguard.KeyguardWidgetPager>
3839

3940
<RelativeLayout

core/res/res/layout/keyguard_status_view.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
xmlns:android="http://schemas.android.com/apk/res/android"
2323
android:layout_width="wrap_content"
2424
android:layout_height="wrap_content"
25+
android:id="@+id/keyguard_status_view"
2526
android:gravity="center_horizontal">
2627

2728
<com.android.internal.policy.impl.keyguard.KeyguardStatusView

core/res/res/layout/keyguard_transport_control.xml renamed to core/res/res/layout/keyguard_transport_control_view.xml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,20 @@
1414
limitations under the License.
1515
-->
1616

17-
<!-- Note: This file is meant to be included in various password unlock screens. As such,
18-
LayoutParams (layout_*) for TransportControlView should *NOT* be specified here,
19-
but rather as include tags for this file or the layout will break. -->
20-
<com.android.internal.widget.TransportControlView
17+
<!-- This is a view to control music playback in keyguard. -->
18+
<com.android.internal.policy.impl.keyguard.KeyguardTransportControlView
2119
xmlns:android="http://schemas.android.com/apk/res/android"
22-
android:id="@+id/transport_controls">
20+
android:layout_width="wrap_content"
21+
android:layout_height="wrap_content"
22+
android:gravity="center_horizontal"
23+
android:id="@+id/keyguard_transport_control">
2324

2425
<!-- FrameLayout used as scrim to show between album art and buttons -->
2526
<FrameLayout
2627
android:layout_width="match_parent"
2728
android:layout_height="match_parent"
2829
android:foreground="@drawable/ic_lockscreen_player_background">
29-
<!-- We use ImageView for its cropping features, otherwise could be android:background -->
30+
<!-- Use ImageView for its cropping features; otherwise could be android:background -->
3031
<ImageView
3132
android:id="@+id/albumart"
3233
android:layout_width="match_parent"
@@ -107,4 +108,4 @@
107108
</LinearLayout>
108109
</LinearLayout>
109110

110-
</com.android.internal.widget.TransportControlView>
111+
</com.android.internal.policy.impl.keyguard.KeyguardTransportControlView>

core/res/res/values/symbols.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,6 +1343,8 @@
13431343
<java-symbol type="id" name="keyguard_user_name" />
13441344
<java-symbol type="id" name="keyguard_active_user" />
13451345
<java-symbol type="id" name="keyguard_inactive_users" />
1346+
<java-symbol type="id" name="keyguard_transport_control" />
1347+
<java-symbol type="id" name="keyguard_status_view" />
13461348
<java-symbol type="integer" name="config_carDockRotation" />
13471349
<java-symbol type="integer" name="config_defaultUiModeType" />
13481350
<java-symbol type="integer" name="config_deskDockRotation" />

policy/src/com/android/internal/policy/impl/keyguard/KeyguardHostView.java

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
import android.view.LayoutInflater;
4242
import android.view.MotionEvent;
4343
import android.view.View;
44+
import android.view.ViewGroup;
45+
import android.view.ViewGroup.LayoutParams;
4446
import android.view.WindowManager;
4547
import android.view.animation.AnimationUtils;
4648
import android.widget.RemoteViews.OnClickHandler;
@@ -54,13 +56,14 @@
5456
import java.util.List;
5557

5658
public 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

Comments
 (0)