From 73ef3516d213b2fb37daeb57edcb26907997d614 Mon Sep 17 00:00:00 2001 From: Jaewan Kim Date: Mon, 18 Jul 2016 13:50:33 +0900 Subject: [PATCH] PIP: Handle layoutDirection changes Bug: 30145777, Bug: 28826668 Change-Id: I43c39b3d3dff279c0a61f8d5872819457ccad4d4 --- packages/SystemUI/AndroidManifest.xml | 4 +- packages/SystemUI/res/values-ldrtl/config.xml | 21 ++++ .../android/systemui/tv/pip/PipManager.java | 103 ++++++++++-------- 3 files changed, 79 insertions(+), 49 deletions(-) create mode 100644 packages/SystemUI/res/values-ldrtl/config.xml diff --git a/packages/SystemUI/AndroidManifest.xml b/packages/SystemUI/AndroidManifest.xml index 20b562cdad75b..bdb103aed7e77 100644 --- a/packages/SystemUI/AndroidManifest.xml +++ b/packages/SystemUI/AndroidManifest.xml @@ -388,7 +388,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" @@ -398,7 +398,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 0000000000000..40604c16be9b4 --- /dev/null +++ b/packages/SystemUI/res/values-ldrtl/config.xml @@ -0,0 +1,21 @@ + + + + + + "778 54 1258 324" + 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 5cc2d01fc041c..5e4854c243879 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 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 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 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);