aboutsummaryrefslogtreecommitdiff
path: root/mediarouter
diff options
context:
space:
mode:
authorKyunglyul Hyun <klhyun@google.com>2018-10-23 13:26:52 +0900
committerKyunglyul Hyun <klhyun@google.com>2018-10-23 13:26:52 +0900
commitaf42cd1f000299424265a8b5fb365efb104356c1 (patch)
treeffcd3424a24187f5adaa5be09ace34777e7e9faf /mediarouter
parent099526c20761dab9dafb837aac8baf0c890e4725 (diff)
downloadsupport-af42cd1f000299424265a8b5fb365efb104356c1.tar.gz
MediaRouteButton: Load drawables sequentially
It prevents loading same remote indicator drawables multiple times in the case that two or more MediaRouteButtons present simulatenously. Bug: 73641097 Test: Ran support v7 demos manually and make two MediaRouteActionProviders present and check if the code works as intended Change-Id: I813ebf08c4d66bfc31eb229c9cddce05c1b70504
Diffstat (limited to 'mediarouter')
-rw-r--r--mediarouter/src/main/java/androidx/mediarouter/app/MediaRouteButton.java22
1 files changed, 18 insertions, 4 deletions
diff --git a/mediarouter/src/main/java/androidx/mediarouter/app/MediaRouteButton.java b/mediarouter/src/main/java/androidx/mediarouter/app/MediaRouteButton.java
index 8876d516777..846022f59cd 100644
--- a/mediarouter/src/main/java/androidx/mediarouter/app/MediaRouteButton.java
+++ b/mediarouter/src/main/java/androidx/mediarouter/app/MediaRouteButton.java
@@ -165,7 +165,7 @@ public class MediaRouteButton extends View {
setRemoteIndicatorDrawableInternal(remoteIndicatorStaticState.newDrawable());
} else {
mRemoteIndicatorLoader = new RemoteIndicatorLoader(remoteIndicatorStaticResId);
- mRemoteIndicatorLoader.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
+ mRemoteIndicatorLoader.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
}
}
@@ -484,7 +484,7 @@ public class MediaRouteButton extends View {
}
mRemoteIndicatorLoader = new RemoteIndicatorLoader(mRemoteIndicatorResIdToLoad);
mRemoteIndicatorResIdToLoad = 0;
- mRemoteIndicatorLoader.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
+ mRemoteIndicatorLoader.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
}
}
@@ -640,12 +640,26 @@ public class MediaRouteButton extends View {
@Override
protected Drawable doInBackground(Void... params) {
- return getContext().getResources().getDrawable(mResId);
+ Drawable.ConstantState remoteIndicatorState = sRemoteIndicatorCache.get(mResId);
+ if (remoteIndicatorState == null) {
+ return getContext().getResources().getDrawable(mResId);
+ } else {
+ return null;
+ }
}
@Override
protected void onPostExecute(Drawable remoteIndicator) {
- cacheAndReset(remoteIndicator);
+ if (remoteIndicator != null) {
+ cacheAndReset(remoteIndicator);
+ } else {
+ Drawable.ConstantState remoteIndicatorState = sRemoteIndicatorCache.get(mResId);
+ if (remoteIndicatorState != null) {
+ remoteIndicator = remoteIndicatorState.newDrawable();
+ }
+ mRemoteIndicatorLoader = null;
+ }
+
setRemoteIndicatorDrawableInternal(remoteIndicator);
}