summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Jaewan Kim <jaewan@google.com> 2016-07-25 01:04:37 +0000
committer android-build-merger <android-build-merger@google.com> 2016-07-25 01:04:37 +0000
commitcdedf154e9a8e7128b1c0e83e6097cf88eb3ec08 (patch)
treeb8033ebc0414c2e7ffc5b6d8c156df0e7299b491
parent5eb62fa5ff3dc06e954450d05a5d8e1c56d3e2af (diff)
parenta474716ffe11409ceca761bf72594eee656d1474 (diff)
PIP: Handle layoutDirection changes am: 73ef3516d2
am: a474716ffe Change-Id: If543450cddf8d138df4b9db8d139e3dde223a3ec
-rw-r--r--packages/SystemUI/AndroidManifest.xml4
-rw-r--r--packages/SystemUI/res/values-ldrtl/config.xml21
-rw-r--r--packages/SystemUI/src/com/android/systemui/tv/pip/PipManager.java103
3 files changed, 79 insertions, 49 deletions
diff --git a/packages/SystemUI/AndroidManifest.xml b/packages/SystemUI/AndroidManifest.xml
index 36fbb6a4d49b..c0a34ae7bb74 100644
--- a/packages/SystemUI/AndroidManifest.xml
+++ b/packages/SystemUI/AndroidManifest.xml
@@ -391,7 +391,7 @@
android:theme="@style/PipTheme"
android:launchMode="singleTop"
android:taskAffinity=""
- android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"
+ android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation|locale|layoutDirection"
android:resizeableActivity="true"
android:supportsPictureInPicture="true"
androidprv:alwaysFocusable="true"
@@ -401,7 +401,7 @@
android:exported="true"
android:theme="@style/PipTheme"
android:taskAffinity=""
- android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"
+ android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation|locale|layoutDirection"
android:resizeableActivity="true"
android:supportsPictureInPicture="true"
android:excludeFromRecents="true" />
diff --git a/packages/SystemUI/res/values-ldrtl/config.xml b/packages/SystemUI/res/values-ldrtl/config.xml
new file mode 100644
index 000000000000..40604c16be9b
--- /dev/null
+++ b/packages/SystemUI/res/values-ldrtl/config.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2016 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.
+-->
+
+<resources>
+ <!-- Bounds [left top right bottom] on screen for picture-in-picture (PIP) windows,
+ when the PIP menu is shown with settings. -->
+ <string translatable="false" name="pip_settings_bounds">"778 54 1258 324"</string>
+</resources>
diff --git a/packages/SystemUI/src/com/android/systemui/tv/pip/PipManager.java b/packages/SystemUI/src/com/android/systemui/tv/pip/PipManager.java
index 5cc2d01fc041..5e4854c24387 100644
--- a/packages/SystemUI/src/com/android/systemui/tv/pip/PipManager.java
+++ b/packages/SystemUI/src/com/android/systemui/tv/pip/PipManager.java
@@ -196,7 +196,23 @@ public class PipManager {
}
mInitialized = true;
mContext = context;
- Resources res = context.getResources();
+
+ mActivityManager = ActivityManagerNative.getDefault();
+ SystemServicesProxy.getInstance(context).registerTaskStackListener(mTaskStackListener);
+ IntentFilter intentFilter = new IntentFilter();
+ intentFilter.addAction(Intent.ACTION_MEDIA_RESOURCE_GRANTED);
+ mContext.registerReceiver(mBroadcastReceiver, intentFilter);
+ mOnboardingShown = Prefs.getBoolean(
+ mContext, TV_PICTURE_IN_PICTURE_ONBOARDING_SHOWN, false);
+
+ loadConfigurationsAndApply();
+ mPipRecentsOverlayManager = new PipRecentsOverlayManager(context);
+ mMediaSessionManager =
+ (MediaSessionManager) mContext.getSystemService(Context.MEDIA_SESSION_SERVICE);
+ }
+
+ private void loadConfigurationsAndApply() {
+ Resources res = mContext.getResources();
mDefaultPipBounds = Rect.unflattenFromString(res.getString(
com.android.internal.R.string.config_defaultPictureInPictureBounds));
mSettingsPipBounds = Rect.unflattenFromString(res.getString(
@@ -209,25 +225,19 @@ public class PipManager {
R.string.pip_recents_focused_bounds));
mRecentsFocusChangedAnimationDurationMs = res.getInteger(
R.integer.recents_tv_pip_focus_anim_duration);
- mPipBounds = mDefaultPipBounds;
- mActivityManager = ActivityManagerNative.getDefault();
- SystemServicesProxy.getInstance(context).registerTaskStackListener(mTaskStackListener);
- IntentFilter intentFilter = new IntentFilter();
- intentFilter.addAction(Intent.ACTION_MEDIA_RESOURCE_GRANTED);
- mContext.registerReceiver(mBroadcastReceiver, intentFilter);
- mOnboardingShown = Prefs.getBoolean(
- mContext, TV_PICTURE_IN_PICTURE_ONBOARDING_SHOWN, false);
-
- mPipRecentsOverlayManager = new PipRecentsOverlayManager(context);
- mMediaSessionManager =
- (MediaSessionManager) mContext.getSystemService(Context.MEDIA_SESSION_SERVICE);
+ // Reset the PIP bounds and apply. PIP bounds can be changed by two reasons.
+ // 1. Configuration changed due to the language change (RTL <-> RTL)
+ // 2. SystemUI restarts after the crash
+ mPipBounds = isSettingsShown() ? mSettingsPipBounds : mDefaultPipBounds;
+ resizePinnedStack(getPinnedStackInfo() == null ? STATE_NO_PIP : STATE_PIP_OVERLAY);
}
/**
* Updates the PIP per configuration changed.
*/
void onConfigurationChanged() {
+ loadConfigurationsAndApply();
mPipRecentsOverlayManager.onConfigurationChanged(mContext);
}
@@ -443,6 +453,16 @@ public class PipManager {
return mState != STATE_NO_PIP;
}
+ private StackInfo getPinnedStackInfo() {
+ StackInfo stackInfo = null;
+ try {
+ stackInfo = mActivityManager.getStackInfo(PINNED_STACK_ID);
+ } catch (RemoteException e) {
+ Log.e(TAG, "getStackInfo failed", e);
+ }
+ return stackInfo;
+ }
+
private void handleMediaResourceGranted(String[] packageNames) {
if (mState == STATE_NO_PIP) {
mLastPackagesResourceGranted = packageNames;
@@ -525,7 +545,18 @@ public class PipManager {
return PLAYBACK_STATE_UNAVAILABLE;
}
- private static boolean isSettingsShown(ComponentName topActivity) {
+ private boolean isSettingsShown() {
+ List<RunningTaskInfo> runningTasks;
+ try {
+ runningTasks = mActivityManager.getTasks(1, 0);
+ if (runningTasks == null || runningTasks.size() == 0) {
+ return false;
+ }
+ } catch (RemoteException e) {
+ Log.d(TAG, "Failed to detect top activity", e);
+ return false;
+ }
+ ComponentName topActivity = runningTasks.get(0).topActivity;
for (Pair<String, String> componentName : sSettingsPackageAndClassNamePairList) {
String packageName = componentName.first;
if (topActivity.getPackageName().equals(packageName)) {
@@ -544,16 +575,10 @@ public class PipManager {
if (mState != STATE_NO_PIP) {
boolean hasPip = false;
- StackInfo stackInfo = null;
- try {
- stackInfo = mActivityManager.getStackInfo(PINNED_STACK_ID);
- if (stackInfo == null) {
- Log.w(TAG, "There is no pinned stack");
- closePipInternal(false);
- return;
- }
- } catch (RemoteException e) {
- Log.e(TAG, "getStackInfo failed", e);
+ StackInfo stackInfo = getPinnedStackInfo();
+ if (stackInfo == null || stackInfo.taskIds == null) {
+ Log.w(TAG, "There is nothing in pinned stack");
+ closePipInternal(false);
return;
}
for (int i = stackInfo.taskIds.length - 1; i >= 0; --i) {
@@ -570,20 +595,10 @@ public class PipManager {
}
}
if (mState == STATE_PIP_OVERLAY) {
- try {
- List<RunningTaskInfo> runningTasks = mActivityManager.getTasks(1, 0);
- if (runningTasks == null || runningTasks.size() == 0) {
- return;
- }
- RunningTaskInfo topTask = runningTasks.get(0);
- Rect bounds = isSettingsShown(topTask.topActivity)
- ? mSettingsPipBounds : mDefaultPipBounds;
- if (mPipBounds != bounds) {
- mPipBounds = bounds;
- resizePinnedStack(STATE_PIP_OVERLAY);
- }
- } catch (RemoteException e) {
- Log.d(TAG, "Failed to detect top activity", e);
+ Rect bounds = isSettingsShown() ? mSettingsPipBounds : mDefaultPipBounds;
+ if (mPipBounds != bounds) {
+ mPipBounds = bounds;
+ resizePinnedStack(STATE_PIP_OVERLAY);
}
}
}
@@ -591,15 +606,9 @@ public class PipManager {
@Override
public void onActivityPinned() {
if (DEBUG) Log.d(TAG, "onActivityPinned()");
- StackInfo stackInfo = null;
- try {
- stackInfo = mActivityManager.getStackInfo(PINNED_STACK_ID);
- if (stackInfo == null) {
- Log.w(TAG, "Cannot find pinned stack");
- return;
- }
- } catch (RemoteException e) {
- Log.e(TAG, "getStackInfo failed", e);
+ StackInfo stackInfo = getPinnedStackInfo();
+ if (stackInfo == null) {
+ Log.w(TAG, "Cannot find pinned stack");
return;
}
if (DEBUG) Log.d(TAG, "PINNED_STACK:" + stackInfo);