android.app.PictureInPictureParams

Here are the examples of the java api android.app.PictureInPictureParams taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

8 Examples 7

19 Source : WebRtcCallActivity.java
with GNU General Public License v3.0
from mollyim

private boolean enterPipModeIfPossible() {
    if (viewModel.canEnterPipMode() && isSystemPipEnabledAndAvailable()) {
        PictureInPictureParams params = new PictureInPictureParams.Builder().setAspectRatio(new Rational(9, 16)).build();
        enterPictureInPictureMode(params);
        CallParticipantsListDialog.dismiss(getSupportFragmentManager());
        return true;
    }
    return false;
}

19 Source : BrowserActivity.java
with GNU General Public License v3.0
from antest1

@Override
public void onUserLeaveHint() {
    boolean pipEnabled = sharedPref.getBoolean(PREF_PIP_MODE, false);
    if (supportsPiPMode() && pipEnabled) {
        PictureInPictureParams params = new PictureInPictureParams.Builder().setAspectRatio(new Rational(1200, 720)).build();
        enterPictureInPictureMode(params);
    }
}

18 Source : VideoPlayerActivity.java
with GNU General Public License v3.0
from vidit135g

@Override
protected void onPause() {
    super.onPause();
    if (player.getPlayWhenReady() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        PictureInPictureParams params = new PictureInPictureParams.Builder().build();
        enterPictureInPictureMode(params);
    }
}

18 Source : MainActivity.java
with Apache License 2.0
from RealMoMo

@Override
public boolean enterPictureInPictureMode(@NonNull PictureInPictureParams params) {
    return super.enterPictureInPictureMode(params);
}

18 Source : MediaPlayer.java
with Apache License 2.0
from ExploiTR

@Override
public void onBackPressed() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && getPackageManager().hreplacedystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE)) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            PictureInPictureParams params = new PictureInPictureParams.Builder().setAspectRatio(new Rational(16, 9)).build();
            enterPictureInPictureMode(params);
        } else {
            enterPictureInPictureMode();
        }
    } else {
        superFinish();
    }
}

14 Source : VideoPlayActivity.java
with GNU Affero General Public License v3.0
from sschueller

@RequiresApi(api = Build.VERSION_CODES.O)
public void enterPipMode() {
    final FragmentManager fragmentManager = getSupportFragmentManager();
    final VideoPlayerFragment videoPlayerFragment = (VideoPlayerFragment) fragmentManager.findFragmentById(R.id.video_player_fragment);
    if (videoPlayerFragment.getVideoAspectRatio() == 0) {
        Log.i(TAG, "impossible to switch to pip");
    } else {
        Rational rational = new Rational((int) (videoPlayerFragment.getVideoAspectRatio() * 100), 100);
        PictureInPictureParams mParams = new PictureInPictureParams.Builder().setAspectRatio(rational).build();
        enterPictureInPictureMode(mParams);
    }
}

14 Source : PreviewActivity.java
with GNU General Public License v3.0
from fython

@RequiresApi(Build.VERSION_CODES.O)
public clreplaced PreviewActivity extends Activity {

    public static final String EXTRA_SHARE_INTENT = BuildConfig.APPLICATION_ID + ".extra.SHARE_INTENT";

    public static final String EXTRA_DELETE_INTENT = BuildConfig.APPLICATION_ID + ".extra.DELETE_INTENT";

    public static final String EXTRA_EDIT_INTENT = BuildConfig.APPLICATION_ID + ".extra.EDIT_INTENT";

    public static final String EXTRA_NOTIFICATION_KEY = BuildConfig.APPLICATION_ID + ".extra.NOTIFICATION_KEY";

    public static final String ACTION_SHARE = BuildConfig.APPLICATION_ID + ".action.PREVIEW_ACTION_SHARE";

    public static final String ACTION_DELETE = BuildConfig.APPLICATION_ID + ".action.PREVIEW_ACTION_DELETE";

    public static final String ACTION_EDIT = BuildConfig.APPLICATION_ID + ".action.PREVIEW_ACTION_EDIT";

    private static final String TAG = "PreviewActivity";

    private PictureInPictureParams mPIPParams;

    private ImageView mImageView;

    private Uri mImageUri;

    private PendingIntent mShareIntent, mDeleteIntent, mEditIntent;

    private String mNotificationKey;

    private CompletableFuture mImageLoadFuture;

    private final RemoteActionReceiver mRemoteActionReceiver = new RemoteActionReceiver();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        final Intent intent = getIntent();
        if (intent == null || intent.getData() == null) {
            Log.e(TAG, "Intent is null.");
            if (!isFinishing()) {
                finish();
            }
            return;
        }
        mImageUri = intent.getData();
        mShareIntent = intent.getParcelableExtra(EXTRA_SHARE_INTENT);
        mDeleteIntent = intent.getParcelableExtra(EXTRA_DELETE_INTENT);
        mEditIntent = intent.getParcelableExtra(EXTRA_EDIT_INTENT);
        mNotificationKey = intent.getStringExtra(EXTRA_NOTIFICATION_KEY);
        setContentView(R.layout.layout_preview);
        mImageView = findViewById(R.id.image_view);
        if (mPIPParams == null) {
            updatePictureInPictureParams();
        }
        if (!isInPictureInPictureMode()) {
            enterPictureInPictureMode(mPIPParams);
        }
        loadImage();
        final IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(ACTION_SHARE);
        intentFilter.addAction(ACTION_DELETE);
        intentFilter.addAction(ACTION_EDIT);
        registerReceiver(mRemoteActionReceiver, intentFilter);
    }

    private void loadImage() {
        mImageView.setImageBitmap(null);
        InputStream input = null;
        if (mImageUri.toString().startsWith("content://")) {
            try {
                input = getContentResolver().openInputStream(mImageUri);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        } else {
            throw new IllegalArgumentException("Unsupported uri: " + mImageUri);
        }
        if (input == null) {
            Log.e(TAG, "Cannot open input stream for " + mImageUri);
            if (!isFinishing()) {
                finish();
            }
            return;
        }
        final InputStream is = input;
        if (mImageLoadFuture != null) {
            try {
                mImageLoadFuture.cancel(true);
            } catch (Exception ignored) {
            }
        }
        mImageLoadFuture = CompletableFuture.supplyAsync(() -> BitmapFactory.decodeStream(is)).whenCompleteAsync((bitmap, err) -> {
            if (err != null) {
                err.printStackTrace();
                if (!isFinishing()) {
                    finish();
                }
                return;
            }
            updatePictureInPictureParams(new Rational(bitmap.getWidth(), bitmap.getHeight()));
            mImageView.setImageBitmap(bitmap);
        }, Executors.mainThread());
    }

    @Override
    protected void onDestroy() {
        Log.d(TAG, "PreviewActivity: onDestroy");
        super.onDestroy();
        if (mImageLoadFuture != null) {
            mImageLoadFuture.cancel(true);
        }
        sendBroadcast(new Intent(ScreenshotDecorator.ACTION_CANCEL_NOTIFICATION).putExtra("key", mNotificationKey));
        try {
            unregisterReceiver(mRemoteActionReceiver);
        } catch (Exception ignored) {
        }
    }

    @Override
    public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode, Configuration newConfig) {
        if (!isInPictureInPictureMode) {
            final Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setDataAndType(mImageUri, "image/*");
            startActivity(intent);
            if (!isFinishing()) {
                finish();
            }
        }
    }

    private void updatePictureInPictureParams() {
        updatePictureInPictureParams(null);
    }

    private synchronized void updatePictureInPictureParams(@Nullable Rational aspect) {
        if (aspect == null) {
            aspect = ScreenUtils.getDefaultDisplayRational(this);
        }
        final List<RemoteAction> remoteActions = new ArrayList<>();
        if (mShareIntent != null) {
            final RemoteAction shareAction = new RemoteAction(Icon.createWithResource(this, R.drawable.ic_share_white_24dp), getString(R.string.action_share_screenshot), getString(R.string.action_share_screenshot), PendingIntent.getBroadcast(this, 0, new Intent(ACTION_SHARE), PendingIntent.FLAG_UPDATE_CURRENT));
            remoteActions.add(shareAction);
        }
        if (mDeleteIntent != null) {
            final RemoteAction deleteAction = new RemoteAction(Icon.createWithResource(this, R.drawable.ic_delete_white_24dp), getString(R.string.action_delete_screenshot), getString(R.string.action_delete_screenshot), PendingIntent.getBroadcast(this, 0, new Intent(ACTION_DELETE), PendingIntent.FLAG_UPDATE_CURRENT));
            remoteActions.add(deleteAction);
        }
        if (mEditIntent != null) {
            final RemoteAction editAction = new RemoteAction(Icon.createWithResource(this, R.drawable.ic_edit_white_24dp), getString(R.string.action_edit), getString(R.string.action_edit), PendingIntent.getBroadcast(this, 0, new Intent(ACTION_EDIT), PendingIntent.FLAG_UPDATE_CURRENT));
            remoteActions.add(editAction);
        }
        mPIPParams = new PictureInPictureParams.Builder().setAspectRatio(aspect).setActions(remoteActions).build();
        if (isInPictureInPictureMode()) {
            setPictureInPictureParams(mPIPParams);
        }
    }

    private final clreplaced RemoteActionReceiver extends BroadcastReceiver {

        private static final String TAG = "RemoteActionReceiver";

        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent == null || intent.getAction() == null) {
                Log.e(TAG, "onReceive intent should not be null and contain an action.");
                return;
            }
            switch(intent.getAction()) {
                case ACTION_SHARE:
                    {
                        try {
                            mShareIntent.send();
                            if (!isFinishing()) {
                                finish();
                            }
                        } catch (PendingIntent.CanceledException e) {
                            e.printStackTrace();
                        }
                        break;
                    }
                case ACTION_DELETE:
                    {
                        try {
                            mDeleteIntent.send();
                            if (!isFinishing()) {
                                finish();
                            }
                        } catch (PendingIntent.CanceledException e) {
                            e.printStackTrace();
                        }
                        break;
                    }
                case ACTION_EDIT:
                    {
                        try {
                            mEditIntent.send();
                            if (!isFinishing()) {
                                finish();
                            }
                        } catch (PendingIntent.CanceledException e) {
                            e.printStackTrace();
                        }
                        break;
                    }
            }
        }
    }
}

7 Source : VideoPlayActivity.java
with GNU Affero General Public License v3.0
from sschueller

// This can only be called when in entering pip mode which can't happen if the device doesn't support pip mode.
@SuppressLint("NewApi")
public void makePipControls() {
    FragmentManager fragmentManager = getSupportFragmentManager();
    VideoPlayerFragment videoPlayerFragment = (VideoPlayerFragment) fragmentManager.findFragmentById(R.id.video_player_fragment);
    ArrayList<RemoteAction> actions = new ArrayList<>();
    Intent actionIntent = new Intent(getString(R.string.app_background_audio));
    PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), REQUEST_CODE, actionIntent, 0);
    @SuppressLint({ "NewApi", "LocalSuppress" })
    Icon icon = Icon.createWithResource(getApplicationContext(), android.R.drawable.stat_sys_speakerphone);
    @SuppressLint({ "NewApi", "LocalSuppress" })
    RemoteAction remoteAction = new RemoteAction(icon, "close pip", "from pip window custom command", pendingIntent);
    actions.add(remoteAction);
    actionIntent = new Intent(ACTION_STOP);
    pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), REQUEST_CODE, actionIntent, 0);
    icon = Icon.createWithResource(getApplicationContext(), com.google.android.exoplayer2.ui.R.drawable.exo_notification_stop);
    remoteAction = new RemoteAction(icon, "play", "stop the media", pendingIntent);
    actions.add(remoteAction);
    replacedert videoPlayerFragment != null;
    if (videoPlayerFragment.isPaused()) {
        Log.e(TAG, "setting actions with play button");
        actionIntent = new Intent(ACTION_PLAY);
        pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), REQUEST_CODE, actionIntent, 0);
        icon = Icon.createWithResource(getApplicationContext(), com.google.android.exoplayer2.ui.R.drawable.exo_notification_play);
        remoteAction = new RemoteAction(icon, "play", "play the media", pendingIntent);
    } else {
        Log.e(TAG, "setting actions with pause button");
        actionIntent = new Intent(ACTION_PAUSE);
        pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), REQUEST_CODE, actionIntent, 0);
        icon = Icon.createWithResource(getApplicationContext(), com.google.android.exoplayer2.ui.R.drawable.exo_notification_pause);
        remoteAction = new RemoteAction(icon, "pause", "pause the media", pendingIntent);
    }
    actions.add(remoteAction);
    // add custom actions to pip window
    PictureInPictureParams params = new PictureInPictureParams.Builder().setActions(actions).build();
    setPictureInPictureParams(params);
}