PIP: Handle layoutDirection changes
Bug: 30145777, Bug: 28826668 Change-Id: I43c39b3d3dff279c0a61f8d5872819457ccad4d4
This commit is contained in:
@@ -388,7 +388,7 @@
|
|||||||
android:theme="@style/PipTheme"
|
android:theme="@style/PipTheme"
|
||||||
android:launchMode="singleTop"
|
android:launchMode="singleTop"
|
||||||
android:taskAffinity=""
|
android:taskAffinity=""
|
||||||
android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"
|
android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation|locale|layoutDirection"
|
||||||
android:resizeableActivity="true"
|
android:resizeableActivity="true"
|
||||||
android:supportsPictureInPicture="true"
|
android:supportsPictureInPicture="true"
|
||||||
androidprv:alwaysFocusable="true"
|
androidprv:alwaysFocusable="true"
|
||||||
@@ -398,7 +398,7 @@
|
|||||||
android:exported="true"
|
android:exported="true"
|
||||||
android:theme="@style/PipTheme"
|
android:theme="@style/PipTheme"
|
||||||
android:taskAffinity=""
|
android:taskAffinity=""
|
||||||
android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"
|
android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation|locale|layoutDirection"
|
||||||
android:resizeableActivity="true"
|
android:resizeableActivity="true"
|
||||||
android:supportsPictureInPicture="true"
|
android:supportsPictureInPicture="true"
|
||||||
android:excludeFromRecents="true" />
|
android:excludeFromRecents="true" />
|
||||||
|
|||||||
21
packages/SystemUI/res/values-ldrtl/config.xml
Normal file
21
packages/SystemUI/res/values-ldrtl/config.xml
Normal file
@@ -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>
|
||||||
@@ -196,7 +196,23 @@ public class PipManager {
|
|||||||
}
|
}
|
||||||
mInitialized = true;
|
mInitialized = true;
|
||||||
mContext = context;
|
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(
|
mDefaultPipBounds = Rect.unflattenFromString(res.getString(
|
||||||
com.android.internal.R.string.config_defaultPictureInPictureBounds));
|
com.android.internal.R.string.config_defaultPictureInPictureBounds));
|
||||||
mSettingsPipBounds = Rect.unflattenFromString(res.getString(
|
mSettingsPipBounds = Rect.unflattenFromString(res.getString(
|
||||||
@@ -209,25 +225,19 @@ public class PipManager {
|
|||||||
R.string.pip_recents_focused_bounds));
|
R.string.pip_recents_focused_bounds));
|
||||||
mRecentsFocusChangedAnimationDurationMs = res.getInteger(
|
mRecentsFocusChangedAnimationDurationMs = res.getInteger(
|
||||||
R.integer.recents_tv_pip_focus_anim_duration);
|
R.integer.recents_tv_pip_focus_anim_duration);
|
||||||
mPipBounds = mDefaultPipBounds;
|
|
||||||
|
|
||||||
mActivityManager = ActivityManagerNative.getDefault();
|
// Reset the PIP bounds and apply. PIP bounds can be changed by two reasons.
|
||||||
SystemServicesProxy.getInstance(context).registerTaskStackListener(mTaskStackListener);
|
// 1. Configuration changed due to the language change (RTL <-> RTL)
|
||||||
IntentFilter intentFilter = new IntentFilter();
|
// 2. SystemUI restarts after the crash
|
||||||
intentFilter.addAction(Intent.ACTION_MEDIA_RESOURCE_GRANTED);
|
mPipBounds = isSettingsShown() ? mSettingsPipBounds : mDefaultPipBounds;
|
||||||
mContext.registerReceiver(mBroadcastReceiver, intentFilter);
|
resizePinnedStack(getPinnedStackInfo() == null ? STATE_NO_PIP : STATE_PIP_OVERLAY);
|
||||||
mOnboardingShown = Prefs.getBoolean(
|
|
||||||
mContext, TV_PICTURE_IN_PICTURE_ONBOARDING_SHOWN, false);
|
|
||||||
|
|
||||||
mPipRecentsOverlayManager = new PipRecentsOverlayManager(context);
|
|
||||||
mMediaSessionManager =
|
|
||||||
(MediaSessionManager) mContext.getSystemService(Context.MEDIA_SESSION_SERVICE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the PIP per configuration changed.
|
* Updates the PIP per configuration changed.
|
||||||
*/
|
*/
|
||||||
void onConfigurationChanged() {
|
void onConfigurationChanged() {
|
||||||
|
loadConfigurationsAndApply();
|
||||||
mPipRecentsOverlayManager.onConfigurationChanged(mContext);
|
mPipRecentsOverlayManager.onConfigurationChanged(mContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -443,6 +453,16 @@ public class PipManager {
|
|||||||
return mState != STATE_NO_PIP;
|
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) {
|
private void handleMediaResourceGranted(String[] packageNames) {
|
||||||
if (mState == STATE_NO_PIP) {
|
if (mState == STATE_NO_PIP) {
|
||||||
mLastPackagesResourceGranted = packageNames;
|
mLastPackagesResourceGranted = packageNames;
|
||||||
@@ -525,7 +545,18 @@ public class PipManager {
|
|||||||
return PLAYBACK_STATE_UNAVAILABLE;
|
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) {
|
for (Pair<String, String> componentName : sSettingsPackageAndClassNamePairList) {
|
||||||
String packageName = componentName.first;
|
String packageName = componentName.first;
|
||||||
if (topActivity.getPackageName().equals(packageName)) {
|
if (topActivity.getPackageName().equals(packageName)) {
|
||||||
@@ -544,16 +575,10 @@ public class PipManager {
|
|||||||
if (mState != STATE_NO_PIP) {
|
if (mState != STATE_NO_PIP) {
|
||||||
boolean hasPip = false;
|
boolean hasPip = false;
|
||||||
|
|
||||||
StackInfo stackInfo = null;
|
StackInfo stackInfo = getPinnedStackInfo();
|
||||||
try {
|
if (stackInfo == null || stackInfo.taskIds == null) {
|
||||||
stackInfo = mActivityManager.getStackInfo(PINNED_STACK_ID);
|
Log.w(TAG, "There is nothing in pinned stack");
|
||||||
if (stackInfo == null) {
|
closePipInternal(false);
|
||||||
Log.w(TAG, "There is no pinned stack");
|
|
||||||
closePipInternal(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
Log.e(TAG, "getStackInfo failed", e);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (int i = stackInfo.taskIds.length - 1; i >= 0; --i) {
|
for (int i = stackInfo.taskIds.length - 1; i >= 0; --i) {
|
||||||
@@ -570,20 +595,10 @@ public class PipManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mState == STATE_PIP_OVERLAY) {
|
if (mState == STATE_PIP_OVERLAY) {
|
||||||
try {
|
Rect bounds = isSettingsShown() ? mSettingsPipBounds : mDefaultPipBounds;
|
||||||
List<RunningTaskInfo> runningTasks = mActivityManager.getTasks(1, 0);
|
if (mPipBounds != bounds) {
|
||||||
if (runningTasks == null || runningTasks.size() == 0) {
|
mPipBounds = bounds;
|
||||||
return;
|
resizePinnedStack(STATE_PIP_OVERLAY);
|
||||||
}
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -591,15 +606,9 @@ public class PipManager {
|
|||||||
@Override
|
@Override
|
||||||
public void onActivityPinned() {
|
public void onActivityPinned() {
|
||||||
if (DEBUG) Log.d(TAG, "onActivityPinned()");
|
if (DEBUG) Log.d(TAG, "onActivityPinned()");
|
||||||
StackInfo stackInfo = null;
|
StackInfo stackInfo = getPinnedStackInfo();
|
||||||
try {
|
if (stackInfo == null) {
|
||||||
stackInfo = mActivityManager.getStackInfo(PINNED_STACK_ID);
|
Log.w(TAG, "Cannot find pinned stack");
|
||||||
if (stackInfo == null) {
|
|
||||||
Log.w(TAG, "Cannot find pinned stack");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
Log.e(TAG, "getStackInfo failed", e);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (DEBUG) Log.d(TAG, "PINNED_STACK:" + stackInfo);
|
if (DEBUG) Log.d(TAG, "PINNED_STACK:" + stackInfo);
|
||||||
|
|||||||
Reference in New Issue
Block a user