diff options
author | Adam Powell <adamp@google.com> | 2012-10-01 14:02:13 -0700 |
---|---|---|
committer | Adam Powell <adamp@google.com> | 2012-10-01 14:05:32 -0700 |
commit | 2ee6a2a83262d05a566bd713d238e89edfd33a29 (patch) | |
tree | b4f012d7b159f07757ad5def4ce842e9c6d1a662 | |
parent | c56e5600501a5c376dc13e6a99fcec7782fc8718 (diff) | |
download | frameworks_base-2ee6a2a83262d05a566bd713d238e89edfd33a29.zip frameworks_base-2ee6a2a83262d05a566bd713d238e89edfd33a29.tar.gz frameworks_base-2ee6a2a83262d05a566bd713d238e89edfd33a29.tar.bz2 |
MediaRouter/Wifi Display improvements
* Don't select the default route on initialization in a process
* Add "connecting" state to MediaRouteButton
Bug 7258981
Bug 7262522
Change-Id: I5cd39b09843783b7e1e17620ca33193f0f3b8fca
24 files changed, 129 insertions, 24 deletions
diff --git a/core/java/android/app/MediaRouteButton.java b/core/java/android/app/MediaRouteButton.java index a9ccef0..3ecafc3 100644 --- a/core/java/android/app/MediaRouteButton.java +++ b/core/java/android/app/MediaRouteButton.java @@ -50,6 +50,7 @@ public class MediaRouteButton extends View { private boolean mRemoteActive; private boolean mToggleMode; private boolean mCheatSheetEnabled; + private boolean mIsConnecting; private int mMinWidth; private int mMinHeight; @@ -57,6 +58,10 @@ public class MediaRouteButton extends View { private OnClickListener mExtendedSettingsClickListener; private MediaRouteChooserDialogFragment mDialogFragment; + private static final int[] CHECKED_STATE_SET = { + R.attr.state_checked + }; + private static final int[] ACTIVATED_STATE_SET = { R.attr.state_activated }; @@ -210,10 +215,21 @@ public class MediaRouteButton extends View { } void updateRemoteIndicator() { - final boolean isRemote = - mRouter.getSelectedRoute(mRouteTypes) != mRouter.getSystemAudioRoute(); + final RouteInfo selected = mRouter.getSelectedRoute(mRouteTypes); + final boolean isRemote = selected != mRouter.getSystemAudioRoute(); + final boolean isConnecting = selected.getStatusCode() == RouteInfo.STATUS_CONNECTING; + + boolean needsRefresh = false; if (mRemoteActive != isRemote) { mRemoteActive = isRemote; + needsRefresh = true; + } + if (mIsConnecting != isConnecting) { + mIsConnecting = isConnecting; + needsRefresh = true; + } + + if (needsRefresh) { refreshDrawableState(); } } @@ -248,7 +264,14 @@ public class MediaRouteButton extends View { @Override protected int[] onCreateDrawableState(int extraSpace) { final int[] drawableState = super.onCreateDrawableState(extraSpace + 1); - if (mRemoteActive) { + + // Technically we should be handling this more completely, but these + // are implementation details here. Checked is used to express the connecting + // drawable state and it's mutually exclusive with activated for the purposes + // of state selection here. + if (mIsConnecting) { + mergeDrawableStates(drawableState, CHECKED_STATE_SET); + } else if (mRemoteActive) { mergeDrawableStates(drawableState, ACTIVATED_STATE_SET); } return drawableState; @@ -426,6 +449,11 @@ public class MediaRouteButton extends View { } @Override + public void onRouteChanged(MediaRouter router, RouteInfo info) { + updateRemoteIndicator(); + } + + @Override public void onRouteAdded(MediaRouter router, RouteInfo info) { updateRouteCount(); } diff --git a/core/res/res/drawable-hdpi/ic_media_route_on_0_holo_dark.png b/core/res/res/drawable-hdpi/ic_media_route_on_0_holo_dark.png Binary files differnew file mode 100644 index 0000000..10fc8da --- /dev/null +++ b/core/res/res/drawable-hdpi/ic_media_route_on_0_holo_dark.png diff --git a/core/res/res/drawable-hdpi/ic_media_route_on_0_holo_light.png b/core/res/res/drawable-hdpi/ic_media_route_on_0_holo_light.png Binary files differnew file mode 100644 index 0000000..a0e5060 --- /dev/null +++ b/core/res/res/drawable-hdpi/ic_media_route_on_0_holo_light.png diff --git a/core/res/res/drawable-hdpi/ic_media_route_on_1_holo_dark.png b/core/res/res/drawable-hdpi/ic_media_route_on_1_holo_dark.png Binary files differnew file mode 100644 index 0000000..8364a36 --- /dev/null +++ b/core/res/res/drawable-hdpi/ic_media_route_on_1_holo_dark.png diff --git a/core/res/res/drawable-hdpi/ic_media_route_on_1_holo_light.png b/core/res/res/drawable-hdpi/ic_media_route_on_1_holo_light.png Binary files differnew file mode 100644 index 0000000..44b89e1 --- /dev/null +++ b/core/res/res/drawable-hdpi/ic_media_route_on_1_holo_light.png diff --git a/core/res/res/drawable-hdpi/ic_media_route_on_2_holo_dark.png b/core/res/res/drawable-hdpi/ic_media_route_on_2_holo_dark.png Binary files differnew file mode 100644 index 0000000..770bf78 --- /dev/null +++ b/core/res/res/drawable-hdpi/ic_media_route_on_2_holo_dark.png diff --git a/core/res/res/drawable-hdpi/ic_media_route_on_2_holo_light.png b/core/res/res/drawable-hdpi/ic_media_route_on_2_holo_light.png Binary files differnew file mode 100644 index 0000000..2a2467b --- /dev/null +++ b/core/res/res/drawable-hdpi/ic_media_route_on_2_holo_light.png diff --git a/core/res/res/drawable-mdpi/ic_media_route_on_0_holo_dark.png b/core/res/res/drawable-mdpi/ic_media_route_on_0_holo_dark.png Binary files differnew file mode 100644 index 0000000..fb2ac25 --- /dev/null +++ b/core/res/res/drawable-mdpi/ic_media_route_on_0_holo_dark.png diff --git a/core/res/res/drawable-mdpi/ic_media_route_on_0_holo_light.png b/core/res/res/drawable-mdpi/ic_media_route_on_0_holo_light.png Binary files differnew file mode 100644 index 0000000..0c20091 --- /dev/null +++ b/core/res/res/drawable-mdpi/ic_media_route_on_0_holo_light.png diff --git a/core/res/res/drawable-mdpi/ic_media_route_on_1_holo_dark.png b/core/res/res/drawable-mdpi/ic_media_route_on_1_holo_dark.png Binary files differnew file mode 100644 index 0000000..2f70cee --- /dev/null +++ b/core/res/res/drawable-mdpi/ic_media_route_on_1_holo_dark.png diff --git a/core/res/res/drawable-mdpi/ic_media_route_on_1_holo_light.png b/core/res/res/drawable-mdpi/ic_media_route_on_1_holo_light.png Binary files differnew file mode 100644 index 0000000..0b76d8e --- /dev/null +++ b/core/res/res/drawable-mdpi/ic_media_route_on_1_holo_light.png diff --git a/core/res/res/drawable-mdpi/ic_media_route_on_2_holo_dark.png b/core/res/res/drawable-mdpi/ic_media_route_on_2_holo_dark.png Binary files differnew file mode 100644 index 0000000..ae7b105 --- /dev/null +++ b/core/res/res/drawable-mdpi/ic_media_route_on_2_holo_dark.png diff --git a/core/res/res/drawable-mdpi/ic_media_route_on_2_holo_light.png b/core/res/res/drawable-mdpi/ic_media_route_on_2_holo_light.png Binary files differnew file mode 100644 index 0000000..8d37b99 --- /dev/null +++ b/core/res/res/drawable-mdpi/ic_media_route_on_2_holo_light.png diff --git a/core/res/res/drawable-xhdpi/ic_media_route_on_0_holo_dark.png b/core/res/res/drawable-xhdpi/ic_media_route_on_0_holo_dark.png Binary files differnew file mode 100644 index 0000000..483b612 --- /dev/null +++ b/core/res/res/drawable-xhdpi/ic_media_route_on_0_holo_dark.png diff --git a/core/res/res/drawable-xhdpi/ic_media_route_on_0_holo_light.png b/core/res/res/drawable-xhdpi/ic_media_route_on_0_holo_light.png Binary files differnew file mode 100644 index 0000000..c3507dc --- /dev/null +++ b/core/res/res/drawable-xhdpi/ic_media_route_on_0_holo_light.png diff --git a/core/res/res/drawable-xhdpi/ic_media_route_on_1_holo_dark.png b/core/res/res/drawable-xhdpi/ic_media_route_on_1_holo_dark.png Binary files differnew file mode 100644 index 0000000..24c6519 --- /dev/null +++ b/core/res/res/drawable-xhdpi/ic_media_route_on_1_holo_dark.png diff --git a/core/res/res/drawable-xhdpi/ic_media_route_on_1_holo_light.png b/core/res/res/drawable-xhdpi/ic_media_route_on_1_holo_light.png Binary files differnew file mode 100644 index 0000000..2be0380 --- /dev/null +++ b/core/res/res/drawable-xhdpi/ic_media_route_on_1_holo_light.png diff --git a/core/res/res/drawable-xhdpi/ic_media_route_on_2_holo_dark.png b/core/res/res/drawable-xhdpi/ic_media_route_on_2_holo_dark.png Binary files differnew file mode 100644 index 0000000..4fd69bd --- /dev/null +++ b/core/res/res/drawable-xhdpi/ic_media_route_on_2_holo_dark.png diff --git a/core/res/res/drawable-xhdpi/ic_media_route_on_2_holo_light.png b/core/res/res/drawable-xhdpi/ic_media_route_on_2_holo_light.png Binary files differnew file mode 100644 index 0000000..5158856 --- /dev/null +++ b/core/res/res/drawable-xhdpi/ic_media_route_on_2_holo_light.png diff --git a/core/res/res/drawable/ic_media_route_connecting_holo_dark.xml b/core/res/res/drawable/ic_media_route_connecting_holo_dark.xml new file mode 100644 index 0000000..36e01f6 --- /dev/null +++ b/core/res/res/drawable/ic_media_route_connecting_holo_dark.xml @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/* + * Copyright 2012, The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +--> +<animation-list + xmlns:android="http://schemas.android.com/apk/res/android" + android:oneshot="false"> + <item android:drawable="@drawable/ic_media_route_on_0_holo_dark" android:duration="500" /> + <item android:drawable="@drawable/ic_media_route_on_1_holo_dark" android:duration="500" /> + <item android:drawable="@drawable/ic_media_route_on_2_holo_dark" android:duration="500" /> + <item android:drawable="@drawable/ic_media_route_on_holo_dark" android:duration="500" /> + <item android:drawable="@drawable/ic_media_route_on_2_holo_dark" android:duration="500" /> + <item android:drawable="@drawable/ic_media_route_on_1_holo_dark" android:duration="500" /> +</animation-list> diff --git a/core/res/res/drawable/ic_media_route_connecting_holo_light.xml b/core/res/res/drawable/ic_media_route_connecting_holo_light.xml new file mode 100644 index 0000000..6683db8 --- /dev/null +++ b/core/res/res/drawable/ic_media_route_connecting_holo_light.xml @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/* + * Copyright 2012, The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +--> +<animation-list + xmlns:android="http://schemas.android.com/apk/res/android" + android:oneshot="false"> + <item android:drawable="@drawable/ic_media_route_on_0_holo_light" android:duration="500" /> + <item android:drawable="@drawable/ic_media_route_on_1_holo_light" android:duration="500" /> + <item android:drawable="@drawable/ic_media_route_on_2_holo_light" android:duration="500" /> + <item android:drawable="@drawable/ic_media_route_on_holo_light" android:duration="500" /> + <item android:drawable="@drawable/ic_media_route_on_2_holo_light" android:duration="500" /> + <item android:drawable="@drawable/ic_media_route_on_1_holo_light" android:duration="500" /> +</animation-list> diff --git a/core/res/res/drawable/ic_media_route_holo_dark.xml b/core/res/res/drawable/ic_media_route_holo_dark.xml index 0b267d7..b4c1fac 100644 --- a/core/res/res/drawable/ic_media_route_holo_dark.xml +++ b/core/res/res/drawable/ic_media_route_holo_dark.xml @@ -15,6 +15,7 @@ --> <selector xmlns:android="http://schemas.android.com/apk/res/android"> + <item android:state_checked="true" android:state_enabled="true" android:drawable="@android:drawable/ic_media_route_connecting_holo_dark" /> <item android:state_activated="true" android:state_enabled="true" android:drawable="@android:drawable/ic_media_route_on_holo_dark" /> <item android:state_enabled="true" android:drawable="@android:drawable/ic_media_route_off_holo_dark" /> <item android:drawable="@android:drawable/ic_media_route_disabled_holo_dark" /> diff --git a/core/res/res/drawable/ic_media_route_holo_light.xml b/core/res/res/drawable/ic_media_route_holo_light.xml index 377253a..553721d 100644 --- a/core/res/res/drawable/ic_media_route_holo_light.xml +++ b/core/res/res/drawable/ic_media_route_holo_light.xml @@ -15,6 +15,7 @@ --> <selector xmlns:android="http://schemas.android.com/apk/res/android"> + <item android:state_checked="true" android:state_enabled="true" android:drawable="@android:drawable/ic_media_route_connecting_holo_light" /> <item android:state_activated="true" android:state_enabled="true" android:drawable="@android:drawable/ic_media_route_on_holo_light" /> <item android:state_enabled="true" android:drawable="@android:drawable/ic_media_route_off_holo_light" /> <item android:drawable="@android:drawable/ic_media_route_disabled_holo_light" /> diff --git a/media/java/android/media/MediaRouter.java b/media/java/android/media/MediaRouter.java index 36c9c70..e5b9637 100644 --- a/media/java/android/media/MediaRouter.java +++ b/media/java/android/media/MediaRouter.java @@ -105,8 +105,13 @@ public class MediaRouter { mDefaultAudioVideo = new RouteInfo(mSystemCategory); mDefaultAudioVideo.mNameResId = com.android.internal.R.string.default_audio_route_name; mDefaultAudioVideo.mSupportedTypes = ROUTE_TYPE_LIVE_AUDIO | ROUTE_TYPE_LIVE_VIDEO; - addRoute(mDefaultAudioVideo); + addRouteStatic(mDefaultAudioVideo); + // This will select the active wifi display route if there is one. + updateWifiDisplayStatus(mDisplayService.getWifiDisplayStatus()); + + appContext.registerReceiver(new WifiDisplayStatusChangedReceiver(), + new IntentFilter(DisplayManager.ACTION_WIFI_DISPLAY_STATUS_CHANGED)); appContext.registerReceiver(new VolumeChangeReceiver(), new IntentFilter(AudioManager.VOLUME_CHANGED_ACTION)); @@ -116,13 +121,17 @@ public class MediaRouter { } catch (RemoteException e) { } if (newAudioRoutes != null) { + // This will select the active BT route if there is one and the current + // selected route is the default system route, or if there is no selected + // route yet. updateAudioRoutes(newAudioRoutes); } - updateWifiDisplayStatus(mDisplayService.getWifiDisplayStatus()); - - appContext.registerReceiver(new WifiDisplayStatusChangedReceiver(), - new IntentFilter(DisplayManager.ACTION_WIFI_DISPLAY_STATUS_CHANGED)); + // Select the default route if the above didn't sync us up + // appropriately with relevant system state. + if (mSelectedRoute == null) { + selectRouteStatic(mDefaultAudioVideo.getSupportedTypes(), mDefaultAudioVideo); + } } void updateAudioRoutes(AudioRoutesInfo newRoutes) { @@ -159,7 +168,7 @@ public class MediaRouter { info.mName = mCurAudioRoutesInfo.mBluetoothName; info.mSupportedTypes = ROUTE_TYPE_LIVE_AUDIO; sStatic.mBluetoothA2dpRoute = info; - addRoute(sStatic.mBluetoothA2dpRoute); + addRouteStatic(sStatic.mBluetoothA2dpRoute); } else { sStatic.mBluetoothA2dpRoute.mName = mCurAudioRoutesInfo.mBluetoothName; dispatchRouteChanged(sStatic.mBluetoothA2dpRoute); @@ -175,7 +184,8 @@ public class MediaRouter { mSelectedRoute == mBluetoothA2dpRoute) { selectRouteStatic(ROUTE_TYPE_LIVE_AUDIO, mDefaultAudioVideo); } else if (mCurAudioRoutesInfo.mMainType == AudioRoutesInfo.MAIN_SPEAKER && - mSelectedRoute == mDefaultAudioVideo && a2dpEnabled) { + (mSelectedRoute == mDefaultAudioVideo || mSelectedRoute == null) && + a2dpEnabled) { selectRouteStatic(ROUTE_TYPE_LIVE_AUDIO, mBluetoothA2dpRoute); } } @@ -393,22 +403,21 @@ public class MediaRouter { * @see #removeUserRoute(UserRouteInfo) */ public void addUserRoute(UserRouteInfo info) { - addRoute(info); + addRouteStatic(info); } /** * @hide Framework use only */ public void addRouteInt(RouteInfo info) { - addRoute(info); + addRouteStatic(info); } - static void addRoute(RouteInfo info) { + static void addRouteStatic(RouteInfo info) { final RouteCategory cat = info.getCategory(); if (!sStatic.mCategories.contains(cat)) { sStatic.mCategories.add(cat); } - final boolean onlyRoute = sStatic.mRoutes.isEmpty(); if (cat.isGroupable() && !(info instanceof RouteGroup)) { // Enforce that any added route in a groupable category must be in a group. final RouteGroup group = new RouteGroup(info.getCategory()); @@ -422,10 +431,6 @@ public class MediaRouter { sStatic.mRoutes.add(info); dispatchRouteAdded(info); } - - if (onlyRoute) { - selectRouteStatic(info.getSupportedTypes(), info); - } } /** @@ -693,18 +698,25 @@ public class MediaRouter { oldStatus.getRememberedDisplays() : new WifiDisplay[0]; WifiDisplay[] newDisplays = newStatus.getRememberedDisplays(); WifiDisplay[] availableDisplays = newStatus.getAvailableDisplays(); + WifiDisplay activeDisplay = newStatus.getActiveDisplay(); for (int i = 0; i < newDisplays.length; i++) { final WifiDisplay d = newDisplays[i]; final WifiDisplay oldRemembered = findMatchingDisplay(d, oldDisplays); if (oldRemembered == null) { - addRoute(makeWifiDisplayRoute(d)); + addRouteStatic(makeWifiDisplayRoute(d)); needScan = true; } else { final boolean available = findMatchingDisplay(d, availableDisplays) != null; final RouteInfo route = findWifiDisplayRoute(d); updateWifiDisplayRoute(route, d, available, newStatus); } + if (d.equals(activeDisplay)) { + final RouteInfo activeRoute = findWifiDisplayRoute(d); + if (activeRoute != null) { + selectRouteStatic(activeRoute.getSupportedTypes(), activeRoute); + } + } } for (int i = 0; i < oldDisplays.length; i++) { final WifiDisplay d = oldDisplays[i]; @@ -840,11 +852,11 @@ public class MediaRouter { // A predetermined connection status that can override mStatus private int mStatusCode; - static final int STATUS_NONE = 0; - static final int STATUS_SCANNING = 1; - static final int STATUS_CONNECTING = 2; - static final int STATUS_AVAILABLE = 3; - static final int STATUS_NOT_AVAILABLE = 4; + /** @hide */ public static final int STATUS_NONE = 0; + /** @hide */ public static final int STATUS_SCANNING = 1; + /** @hide */ public static final int STATUS_CONNECTING = 2; + /** @hide */ public static final int STATUS_AVAILABLE = 3; + /** @hide */ public static final int STATUS_NOT_AVAILABLE = 4; private Object mTag; @@ -941,6 +953,13 @@ public class MediaRouter { } /** + * @hide + */ + public int getStatusCode() { + return mStatusCode; + } + + /** * @return A media type flag set describing which types this route supports. */ public int getSupportedTypes() { |