[Android Software Development] Geeks Empire:
​

Picture in Picture Mode (PinP) introduced on Android 8 (API 26) for All Android devices.

Its most used functionality is to shoa w preview of some data like Video Players, Maps & etc.

But there is also an option to add Custom Action & with this, you can do whatever you want to do.

[YOUTUBE]t_7fajxnGlo[/YOUTUBE]

# Let Start #​

- Create new Android Studio Project, then open AndroidManifest.xml to add PinP attributes.

(I suggest to create specific Activity to handle PinP)

<activity
android:name=".PictureInPicture.PinP"
android:label="@string/title_activity_pin_p"
[B][COLOR="Blue"]android:resizeableActivity="true"
android:supportsPictureInPicture="true"[/COLOR][/B]
android:theme="@android:style/Theme.DeviceDefault.Wallpaper.NoTitleBar" />
<!-- I used Wallpaper theme cause in my case I want to have transparent background that shows home launcher wallpaper -->

- Now Open your PinP Activity, PinP.java

The layout your design for this activity will show inside PinP Window.

(Here I set 3 ImageViews to load icons of selected apps that I load from a saved file)

To enter PinP Mode your need only to call this activity.enterPictureInPictureMode(); But you should add some functionality to it. READ COMMENTS IN CODE

public void enterPinP(){
[COLOR="Red"]//load packageNames from saved file[/COLOR]
List<String> appShortcutsPackageName = Arrays.asList(functionsClass.readFileLine(".autoSuper"));

[COLOR="red"]//set icon of apps to imageView[/COLOR]
imageViewOne.setImageBitmap(appIconBitmap(appShortcutsPackageName.get(0)));
imageViewTwo.setImageBitmap(appIconBitmap(appShortcutsPackageName.get(1)));
imageViewThree.setImageBitmap(appIconBitmap(appShortcutsPackageName.get(2)));

[COLOR="red"]//get main intent of apps[/COLOR]
Intent intentOne = getPackageManager().getLaunchIntentForPackage(appShortcutsPackageName.get(0)).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Intent intentTwo = getPackageManager().getLaunchIntentForPackage(appShortcutsPackageName.get(1)).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Intent intentThree = getPackageManager().getLaunchIntentForPackage(appShortcutsPackageName.get(2)).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

[COLOR="red"]//create pending intent for actions on PinP Window [/COLOR]
[COLOR="red"]//you can also [b]getService()[/b] & [b]getBroadcast()[/b] [/COLOR]
final PendingIntent pendingIntentOne = PendingIntent.getActivity(getApplicationContext(), 333, intentOne,0);
final PendingIntent pendingIntentTwo = PendingIntent.getActivity(getApplicationContext(), 666, intentTwo,0);
final PendingIntent pendingIntentThree = PendingIntent.getActivity(getApplicationContext(), 999, intentThree,0);

[COLOR="red"]//here I add icon from resource to indicate where to click on PinP Window[/COLOR]
final Icon oneIcon = Icon.createWithResource(getApplicationContext(), R.drawable.ic_click);
final Icon twoIcon = Icon.createWithResource(getApplicationContext(), R.drawable.ic_click);
final Icon threeIcon = Icon.createWithResource(getApplicationContext(), R.drawable.ic_click);

[COLOR="red"]//remote actions to handle click from PinP Window[/COLOR]
final ArrayList<RemoteAction> remoteActions = new ArrayList<>();
remoteActions.add(new RemoteAction(oneIcon, appName(appShortcutsPackageName.get(0)), appName(appShortcutsPackageName.get(0)), pendingIntentOne));
remoteActions.add(new RemoteAction(twoIcon, appName(appShortcutsPackageName.get(1)), appName(appShortcutsPackageName.get(1)), pendingIntentTwo));
remoteActions.add(new RemoteAction(threeIcon, appName(appShortcutsPackageName.get(2)), appName(appShortcutsPackageName.get(2)), pendingIntentThree));

//
final PictureInPictureParams.Builder pictureInPictureParamsBuilder = new PictureInPictureParams.Builder();
pictureInPictureParamsBuilder.setActions(remoteActions);
pictureInPictureParamsBuilder.setAspectRatio(new Rational(50, 100));

PictureInPictureParams pictureInPictureParams = pictureInPictureParamsBuilder.build();

[B][COLOR="red"]//This is Main Functions. That you can Call from any Activity [/COLOR]
[COLOR="RoyalBlue"]enterPictureInPictureMode(pictureInPictureParams);[/COLOR][/B]
}

So wherever you call this function, it will enter to Picture in Picture Mode.

For Example, when click a button or @onPause() to continue showing some data.

I call it from onCreate(Bundle bundle) cause I create an activity specific for PinP Mode.

Also, you can recognize whenever your activity enter full screen mode Or PinP by overriding this functions

It is good way to add/remove views If you are using same activity for both full screen and PinP mode.

@Override
public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode, Configuration configuration) {
super.onPictureInPictureModeChanged(isInPictureInPictureMode, configuration);
if (isInPictureInPictureMode){
//picture in picture mode
}
else {
//full screen mode
}
}

Note: Limited amount of RemoteActions can be set for PinP Mode that you can get it from activity.getMaxNumPictureInPictureActions();

Oo. Download | PinP Shortcuts .oO

Super Shortcuts | Available in Beta Stage

Feel Free to Ask for Promo Code

[IMG="geeks"]https://img.xda-cdn.com/ecTRQ0jFnETW73vt2H-3fQtmFTg=/https%3A%2F%2Flh3.googleusercontent.com%2F5RM5FsviY5rVG2r5NgU1fnvDe5LS0Nd-X8_KBcKZ6GbFxso80uAvEsYBuRxOJzpKlbjMHu8T%3Dw576-h324-p-rw[/IMG]

Thanks for Support my Projects​

Don't forget to Hit Thanks​