Code Format

This commit is contained in:
Stefan Schueller 2020-07-05 13:16:50 +02:00
parent f84fcb4ba5
commit ded16379f1

View File

@ -61,7 +61,6 @@ import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction; import androidx.fragment.app.FragmentTransaction;
//import static net.schueller.peertube.helper.Constants.BACKGROUND_PLAY_PREF_KEY;
import static com.google.android.exoplayer2.ui.PlayerNotificationManager.ACTION_PAUSE; import static com.google.android.exoplayer2.ui.PlayerNotificationManager.ACTION_PAUSE;
import static com.google.android.exoplayer2.ui.PlayerNotificationManager.ACTION_PLAY; import static com.google.android.exoplayer2.ui.PlayerNotificationManager.ACTION_PLAY;
import static com.google.android.exoplayer2.ui.PlayerNotificationManager.ACTION_STOP; import static com.google.android.exoplayer2.ui.PlayerNotificationManager.ACTION_STOP;
@ -76,6 +75,7 @@ public class VideoPlayActivity extends AppCompatActivity {
private static boolean floatMode = false; private static boolean floatMode = false;
private static final int REQUEST_CODE = 101; private static final int REQUEST_CODE = 101;
private BroadcastReceiver receiver; private BroadcastReceiver receiver;
//This can only be called when in entering pip mode which can't happen if the device doesn't support pip mode. //This can only be called when in entering pip mode which can't happen if the device doesn't support pip mode.
@SuppressLint("NewApi") @SuppressLint("NewApi")
public void makePipControls() { public void makePipControls() {
@ -96,15 +96,15 @@ public class VideoPlayActivity extends AppCompatActivity {
remoteAction = new RemoteAction(icon, "play", "stop the media", pendingIntent); remoteAction = new RemoteAction(icon, "play", "stop the media", pendingIntent);
actions.add(remoteAction); actions.add(remoteAction);
if (videoPlayerFragment.isPaused()){ if (videoPlayerFragment.isPaused()) {
Log.e(TAG,"setting actions with play button"); Log.e(TAG, "setting actions with play button");
actionIntent = new Intent(ACTION_PLAY); actionIntent = new Intent(ACTION_PLAY);
pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), REQUEST_CODE, actionIntent, 0); pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), REQUEST_CODE, actionIntent, 0);
icon = Icon.createWithResource(getApplicationContext(), com.google.android.exoplayer2.ui.R.drawable.exo_notification_play); icon = Icon.createWithResource(getApplicationContext(), com.google.android.exoplayer2.ui.R.drawable.exo_notification_play);
remoteAction = new RemoteAction(icon, "play", "play the media", pendingIntent); remoteAction = new RemoteAction(icon, "play", "play the media", pendingIntent);
actions.add(remoteAction); actions.add(remoteAction);
} else { } else {
Log.e(TAG,"setting actions with pause button"); Log.e(TAG, "setting actions with pause button");
actionIntent = new Intent(ACTION_PAUSE); actionIntent = new Intent(ACTION_PAUSE);
pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), REQUEST_CODE, actionIntent, 0); pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), REQUEST_CODE, actionIntent, 0);
icon = Icon.createWithResource(getApplicationContext(), com.google.android.exoplayer2.ui.R.drawable.exo_notification_pause); icon = Icon.createWithResource(getApplicationContext(), com.google.android.exoplayer2.ui.R.drawable.exo_notification_pause);
@ -161,11 +161,11 @@ public class VideoPlayActivity extends AppCompatActivity {
registerReceiver(receiver, filter); registerReceiver(receiver, filter);
Log.v(TAG, "switched to pip "); Log.v(TAG, "switched to pip ");
floatMode=true; floatMode = true;
videoPlayerFragment.showControls(false); videoPlayerFragment.showControls(false);
} }
public void changedToNormalMode(){ public void changedToNormalMode() {
FragmentManager fragmentManager = getSupportFragmentManager(); FragmentManager fragmentManager = getSupportFragmentManager();
VideoPlayerFragment videoPlayerFragment = (VideoPlayerFragment) fragmentManager.findFragmentById(R.id.video_player_fragment); VideoPlayerFragment videoPlayerFragment = (VideoPlayerFragment) fragmentManager.findFragmentById(R.id.video_player_fragment);
@ -173,8 +173,8 @@ public class VideoPlayActivity extends AppCompatActivity {
if (receiver != null) { if (receiver != null) {
unregisterReceiver(receiver); unregisterReceiver(receiver);
} }
Log.v(TAG,"switched to normal"); Log.v(TAG, "switched to normal");
floatMode=false; floatMode = false;
} }
@Override @Override
@ -199,17 +199,17 @@ public class VideoPlayActivity extends AppCompatActivity {
assert videoPlayerFragment != null; assert videoPlayerFragment != null;
String playingVideo = videoPlayerFragment.getVideoUuid(); String playingVideo = videoPlayerFragment.getVideoUuid();
Log.v(TAG, "oncreate click: " + videoUuid +" is trying to replace: "+playingVideo); Log.v(TAG, "oncreate click: " + videoUuid + " is trying to replace: " + playingVideo);
if (TextUtils.isEmpty(playingVideo)){ if (TextUtils.isEmpty(playingVideo)) {
Log.v(TAG,"oncreate no video currently playing"); Log.v(TAG, "oncreate no video currently playing");
videoPlayerFragment.start(videoUuid); videoPlayerFragment.start(videoUuid);
} else if(!playingVideo.equals(videoUuid)){ } else if (!playingVideo.equals(videoUuid)) {
Log.v(TAG,"oncreate different video playing currently"); Log.v(TAG, "oncreate different video playing currently");
videoPlayerFragment.stopVideo(); videoPlayerFragment.stopVideo();
videoPlayerFragment.start(videoUuid); videoPlayerFragment.start(videoUuid);
} else { } else {
Log.v(TAG,"oncreate same video playing currently"); Log.v(TAG, "oncreate same video playing currently");
} }
// if we are in landscape set the video to fullscreen // if we are in landscape set the video to fullscreen
@ -227,18 +227,18 @@ public class VideoPlayActivity extends AppCompatActivity {
getSupportFragmentManager().findFragmentById(R.id.video_player_fragment); getSupportFragmentManager().findFragmentById(R.id.video_player_fragment);
assert videoPlayerFragment != null; assert videoPlayerFragment != null;
String videoUuid = intent.getStringExtra(VideoListActivity.EXTRA_VIDEOID); String videoUuid = intent.getStringExtra(VideoListActivity.EXTRA_VIDEOID);
Log.v(TAG, "new intent click: " + videoUuid +" is trying to replace: "+videoPlayerFragment.getVideoUuid()); Log.v(TAG, "new intent click: " + videoUuid + " is trying to replace: " + videoPlayerFragment.getVideoUuid());
String playingVideo = videoPlayerFragment.getVideoUuid(); String playingVideo = videoPlayerFragment.getVideoUuid();
if (TextUtils.isEmpty(playingVideo)){ if (TextUtils.isEmpty(playingVideo)) {
Log.v(TAG,"new intent no video currently playing"); Log.v(TAG, "new intent no video currently playing");
videoPlayerFragment.start(videoUuid); videoPlayerFragment.start(videoUuid);
} else if(!playingVideo.equals(videoUuid)){ } else if (!playingVideo.equals(videoUuid)) {
Log.v(TAG,"new intent different video playing currently"); Log.v(TAG, "new intent different video playing currently");
videoPlayerFragment.stopVideo(); videoPlayerFragment.stopVideo();
videoPlayerFragment.start(videoUuid); videoPlayerFragment.start(videoUuid);
} else { } else {
Log.v(TAG,"new intent same video playing currently"); Log.v(TAG, "new intent same video playing currently");
} }
// if we are in landscape set the video to fullscreen // if we are in landscape set the video to fullscreen
@ -337,25 +337,25 @@ public class VideoPlayActivity extends AppCompatActivity {
@SuppressLint("NewApi") @SuppressLint("NewApi")
@Override @Override
public void onUserLeaveHint () { public void onUserLeaveHint() {
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
FragmentManager fragmentManager = getSupportFragmentManager(); FragmentManager fragmentManager = getSupportFragmentManager();
VideoPlayerFragment videoPlayerFragment = (VideoPlayerFragment) fragmentManager.findFragmentById(R.id.video_player_fragment); VideoPlayerFragment videoPlayerFragment = (VideoPlayerFragment) fragmentManager.findFragmentById(R.id.video_player_fragment);
String backgroundBehavior = sharedPref.getString("pref_background_behavior","backgroundStop"); String backgroundBehavior = sharedPref.getString("pref_background_behavior", "backgroundStop");
switch(backgroundBehavior){ switch (backgroundBehavior) {
case "backgroundStop": case "backgroundStop":
Log.v(TAG,"stop the video"); Log.v(TAG, "stop the video");
videoPlayerFragment.pauseVideo(); videoPlayerFragment.pauseVideo();
stopService(new Intent(this, VideoPlayerService.class)); stopService(new Intent(this, VideoPlayerService.class));
super.onBackPressed(); super.onBackPressed();
break; break;
case "backgroundAudio": case "backgroundAudio":
Log.v(TAG,"play the Audio"); Log.v(TAG, "play the Audio");
super.onBackPressed(); super.onBackPressed();
break; break;
case "backgroundFloat": case "backgroundFloat":
Log.v(TAG,"play in floating video"); Log.v(TAG, "play in floating video");
//canEnterPIPMode makes sure API level is high enough //canEnterPIPMode makes sure API level is high enough
if (canEnterPipMode(this)) { if (canEnterPipMode(this)) {
Log.v(TAG, "enabling pip"); Log.v(TAG, "enabling pip");
@ -368,7 +368,7 @@ public class VideoPlayActivity extends AppCompatActivity {
Log.v(TAG, "onUserLeaveHint()..."); Log.v(TAG, "onUserLeaveHint()...");
} }
// @RequiresApi(api = Build.VERSION_CODES.O) // @RequiresApi(api = Build.VERSION_CODES.O)
@SuppressLint("NewApi") @SuppressLint("NewApi")
public void onBackPressed() { public void onBackPressed() {
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
@ -376,8 +376,8 @@ public class VideoPlayActivity extends AppCompatActivity {
getSupportFragmentManager().findFragmentById(R.id.video_player_fragment); getSupportFragmentManager().findFragmentById(R.id.video_player_fragment);
//copying Youtube behavior to have back button exit full screen. //copying Youtube behavior to have back button exit full screen.
if (videoPlayerFragment.getIsFullscreen()){ if (videoPlayerFragment.getIsFullscreen()) {
Log.v(TAG,"exiting full screen"); Log.v(TAG, "exiting full screen");
videoPlayerFragment.fullScreenToggle(); videoPlayerFragment.fullScreenToggle();
return; return;
} }
@ -386,24 +386,24 @@ public class VideoPlayActivity extends AppCompatActivity {
videoPlayerFragment.pauseVideo(); videoPlayerFragment.pauseVideo();
} }
String backgroundBehavior = sharedPref.getString("pref_background_behavior","backgroundStop"); String backgroundBehavior = sharedPref.getString("pref_background_behavior", "backgroundStop");
// Log.v(TAG,"backgroundBehavior: " + backgroundBehavior); // Log.v(TAG,"backgroundBehavior: " + backgroundBehavior);
switch (backgroundBehavior){ switch (backgroundBehavior) {
case "backgroundStop": case "backgroundStop":
Log.v(TAG,"stop the video"); Log.v(TAG, "stop the video");
videoPlayerFragment.pauseVideo(); videoPlayerFragment.pauseVideo();
stopService(new Intent(this, VideoPlayerService.class)); stopService(new Intent(this, VideoPlayerService.class));
super.onBackPressed(); super.onBackPressed();
break; break;
case "backgroundAudio": case "backgroundAudio":
Log.v(TAG,"play the Audio"); Log.v(TAG, "play the Audio");
super.onBackPressed(); super.onBackPressed();
break; break;
case "backgroundFloat": case "backgroundFloat":
Log.v(TAG,"play in floating video"); Log.v(TAG, "play in floating video");
//canEnterPIPMode makes sure API level is high enough //canEnterPIPMode makes sure API level is high enough
if (canEnterPipMode(this)) { if (canEnterPipMode(this)) {
Log.v(TAG, "enabling pip"); Log.v(TAG, "enabling pip");
@ -412,13 +412,13 @@ public class VideoPlayActivity extends AppCompatActivity {
Intent intentSettings = new Intent(this, VideoListActivity.class); Intent intentSettings = new Intent(this, VideoListActivity.class);
this.startActivity(intentSettings); this.startActivity(intentSettings);
} else { } else {
Log.v(TAG,"Unable to enter PIP mode"); Log.v(TAG, "Unable to enter PIP mode");
super.onBackPressed(); super.onBackPressed();
} }
break; break;
default: default:
// Deal with bad entries from older version // Deal with bad entries from older version
Log.v(TAG,"No setting, fallback"); Log.v(TAG, "No setting, fallback");
super.onBackPressed(); super.onBackPressed();
break; break;
} }
@ -426,18 +426,18 @@ public class VideoPlayActivity extends AppCompatActivity {
} }
public boolean canEnterPipMode(Context context) { public boolean canEnterPipMode(Context context) {
Log.v(TAG,"api version "+Build.VERSION.SDK_INT); Log.v(TAG, "api version " + Build.VERSION.SDK_INT);
if (Build.VERSION.SDK_INT<28){ if (Build.VERSION.SDK_INT < 28) {
return false; return false;
} }
AppOpsManager appOpsManager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE); AppOpsManager appOpsManager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
return (AppOpsManager.MODE_ALLOWED== appOpsManager.checkOpNoThrow(AppOpsManager.OPSTR_PICTURE_IN_PICTURE, android.os.Process.myUid(), context.getPackageName())); return (AppOpsManager.MODE_ALLOWED == appOpsManager.checkOpNoThrow(AppOpsManager.OPSTR_PICTURE_IN_PICTURE, android.os.Process.myUid(), context.getPackageName()));
} }
@RequiresApi(api = Build.VERSION_CODES.O) @RequiresApi(api = Build.VERSION_CODES.O)
public void enterPipMode() { public void enterPipMode() {
Rational rational = new Rational(239, 100); Rational rational = new Rational(239, 100);
Log.v(TAG,rational.toString()); Log.v(TAG, rational.toString());
PictureInPictureParams mParams = PictureInPictureParams mParams =
new PictureInPictureParams.Builder() new PictureInPictureParams.Builder()
.setAspectRatio(rational) .setAspectRatio(rational)
@ -448,17 +448,17 @@ public class VideoPlayActivity extends AppCompatActivity {
} }
@Override @Override
public void onPictureInPictureModeChanged (boolean isInPictureInPictureMode, Configuration newConfig) { public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode, Configuration newConfig) {
FragmentManager fragmentManager = getSupportFragmentManager(); FragmentManager fragmentManager = getSupportFragmentManager();
VideoPlayerFragment videoPlayerFragment = (VideoPlayerFragment) fragmentManager.findFragmentById(R.id.video_player_fragment); VideoPlayerFragment videoPlayerFragment = (VideoPlayerFragment) fragmentManager.findFragmentById(R.id.video_player_fragment);
if (isInPictureInPictureMode) { if (isInPictureInPictureMode) {
changedToPipMode(); changedToPipMode();
Log.v(TAG,"switched to pip "); Log.v(TAG, "switched to pip ");
videoPlayerFragment.useController(false); videoPlayerFragment.useController(false);
} else { } else {
changedToNormalMode(); changedToNormalMode();
Log.v(TAG,"switched to normal"); Log.v(TAG, "switched to normal");
videoPlayerFragment.useController(true); videoPlayerFragment.useController(true);
} }
} }