diff --git a/samples/ApiDemos/AndroidManifest.xml b/samples/ApiDemos/AndroidManifest.xml index 030184982..b1175f629 100644 --- a/samples/ApiDemos/AndroidManifest.xml +++ b/samples/ApiDemos/AndroidManifest.xml @@ -285,6 +285,18 @@ + + + + + + + diff --git a/samples/ApiDemos/res/layout/picture_in_picture.xml b/samples/ApiDemos/res/layout/picture_in_picture.xml new file mode 100644 index 000000000..096ee3cf8 --- /dev/null +++ b/samples/ApiDemos/res/layout/picture_in_picture.xml @@ -0,0 +1,32 @@ + + + + + + + + + + diff --git a/samples/ApiDemos/res/values/strings.xml b/samples/ApiDemos/res/values/strings.xml index 288e4774d..30d92ab88 100644 --- a/samples/ApiDemos/res/values/strings.xml +++ b/samples/ApiDemos/res/values/strings.xml @@ -62,6 +62,9 @@ instead of programmatically. Screen Orientation + App/Activity/Picture in Picture + Enter picture-in-picture mode + App/Activity/Translucent Example of how you can make an activity have a translucent background, compositing over diff --git a/samples/ApiDemos/src/com/example/android/apis/app/PictureInPicture.java b/samples/ApiDemos/src/com/example/android/apis/app/PictureInPicture.java new file mode 100644 index 000000000..43f554082 --- /dev/null +++ b/samples/ApiDemos/src/com/example/android/apis/app/PictureInPicture.java @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2018 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. + */ + +package com.example.android.apis.app; + +import android.app.Activity; +import android.os.Bundle; +import android.widget.Button; + +import com.example.android.apis.R; + +public class PictureInPicture extends Activity { + + private Button mEnterPip; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.picture_in_picture); + + mEnterPip = (Button)findViewById(R.id.enter_pip); + mEnterPip.setOnClickListener((v) -> enterPictureInPictureMode()); + } + + @Override + protected void onUserLeaveHint() { + enterPictureInPictureMode(); + } +}