Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pip mode #29

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/pandroid/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
</activity>
<activity
android:name=".app.GameActivity"
android:configChanges="screenSize|screenLayout|orientation|density|uiMode">
android:supportsPictureInPicture="true"
android:configChanges="screenSize|screenLayout|smallestScreenSize|orientation|density|uiMode">
</activity>
<activity
android:name=".app.editor.CodeEditorActivity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
import android.widget.FrameLayout;
import android.widget.Toast;
import androidx.annotation.Nullable;
import android.app.PictureInPictureParams;
import android.content.res.Configuration;
import android.util.DisplayMetrics;
import android.util.Rational;
import com.panda3ds.pandroid.AlberDriver;
import com.panda3ds.pandroid.R;
import com.panda3ds.pandroid.app.game.AlberInputListener;
Expand Down Expand Up @@ -73,11 +77,51 @@ protected void onResume() {
InputHandler.reset();
InputHandler.setMotionDeadZone(InputMap.getDeadZone());
InputHandler.setEventListener(inputListener);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
setPictureInPictureParams(new PictureInPictureParams.Builder().setAutoEnterEnabled(true).build());
}

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
getTheme().applyStyle(R.style.GameActivityNavigationBar, true);
}
}

@Override
public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode, Configuration newConfig) {
super.onPictureInPictureModeChanged(isInPictureInPictureMode, newConfig);
if (isInPictureInPictureMode) {
if (drawerFragment.isOpened()) {
drawerFragment.close();
}
findViewById(R.id.overlay_controller).setVisibility(View.GONE);
} else {
if (GlobalConfig.get(GlobalConfig.KEY_SCREEN_GAMEPAD_VISIBLE)) {
findViewById(R.id.overlay_controller).setVisibility(View.VISIBLE);
}
}
}

@Override
public void onUserLeaveHint() {
super.onUserLeaveHint();
DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);

int widthPixels = displayMetrics.widthPixels;
int heightPixels = displayMetrics.heightPixels;

// Calculate aspect ratio
float aspectRatio = (float) widthPixels / (float) heightPixels;

if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) {
Rational aspectRatioRational = new Rational(widthPixels, heightPixels);
PictureInPictureParams.Builder pipBuilder = new PictureInPictureParams.Builder();
pipBuilder.setAspectRatio(aspectRatioRational);
enterPictureInPictureMode(pipBuilder.build());
}
}

@Override
protected void onPause() {
super.onPause();
Expand Down
Loading