Add moveTaskToBack to PiP demo am: 8f10bb853f

Original change: https://googleplex-android-review.googlesource.com/c/platform/development/+/23114477

Change-Id: I24ea54ec4eb4e84614f9f677269eb05074952f20
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Hongwei Wang
2023-05-09 19:43:16 +00:00
committed by Automerger Merge Worker
3 changed files with 49 additions and 7 deletions

View File

@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!--
~ Copyright (C) 2023 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.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M200,760L200,680L760,680L760,760L200,760ZM214,600L480,200L746,600L214,600ZM480,520L480,520L480,520L480,520ZM362,520L598,520L480,344L362,520Z"/>
</vector>

View File

@@ -70,6 +70,7 @@
<string name="enter_content_pip">Enter content PiP</string>
<string name="enter_picture_in_picture">Manually enter PiP</string>
<string name="action_custom_close">Close PiP</string>
<string name="action_move_to_back">Background PiP</string>
<string name="label_current_position">Current position</string>
<string name="label_exit_position">Exit position</string>
<string name="label_position_start">Start</string>

View File

@@ -42,7 +42,6 @@ import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioGroup;
import android.widget.Spinner;
@@ -66,6 +65,7 @@ public class PictureInPicture extends Activity {
private static final int TABLET_BREAK_POINT_DP = 700;
private static final String ACTION_CUSTOM_CLOSE = "demo.pip.custom_close";
private static final String ACTION_MOVE_TO_BACK = "demo.pip.move_to_back";
private final BroadcastReceiver mRemoteActionReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
@@ -73,6 +73,9 @@ public class PictureInPicture extends Activity {
case ACTION_CUSTOM_CLOSE:
finish();
break;
case ACTION_MOVE_TO_BACK:
moveTaskToBack(false /* nonRoot */);
break;
}
}
};
@@ -110,6 +113,7 @@ public class PictureInPicture extends Activity {
private Spinner mAspectRatioSpinner;
private List<RemoteAction> mPipActions;
private RemoteAction mCloseAction;
private RemoteAction mMoveToBackAction;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -264,19 +268,29 @@ public class PictureInPicture extends Activity {
private void setupPipActions() {
final IntentFilter remoteActionFilter = new IntentFilter();
mPipActions = new ArrayList<>();
remoteActionFilter.addAction(ACTION_CUSTOM_CLOSE);
registerReceiver(mRemoteActionReceiver, remoteActionFilter);
final Intent intent = new Intent(ACTION_CUSTOM_CLOSE).setPackage(getPackageName());
final Intent closeIntent = new Intent(ACTION_CUSTOM_CLOSE).setPackage(getPackageName());
mCloseAction = new RemoteAction(
Icon.createWithResource(this, R.drawable.ic_call_end),
getString(R.string.action_custom_close),
getString(R.string.action_custom_close),
PendingIntent.getBroadcast(this, 0 /* requestCode */, intent,
PendingIntent.getBroadcast(this, 0 /* requestCode */, closeIntent,
FLAG_UPDATE_CURRENT | FLAG_IMMUTABLE));
// Add close action as a regular PiP action
mPipActions = new ArrayList<>(1);
mPipActions.add(mCloseAction);
remoteActionFilter.addAction(ACTION_MOVE_TO_BACK);
final Intent backIntent = new Intent(ACTION_MOVE_TO_BACK).setPackage(getPackageName());
mMoveToBackAction = new RemoteAction(
Icon.createWithResource(this, R.drawable.ic_eject),
getString(R.string.action_move_to_back),
getString(R.string.action_move_to_back),
PendingIntent.getBroadcast(this, 0 /* requestCode */, backIntent,
FLAG_UPDATE_CURRENT | FLAG_IMMUTABLE));
mPipActions.add(mMoveToBackAction);
registerReceiver(mRemoteActionReceiver, remoteActionFilter);
}
private void setupPictureInPictureLayout() {