- Cleaned up full screen button and activation

This commit is contained in:
Stefan Schueller 2019-01-06 13:28:07 +01:00
parent a397822c23
commit 3f0c275cdc
2 changed files with 56 additions and 31 deletions

View File

@ -37,6 +37,7 @@ import android.widget.FrameLayout;
import android.widget.RelativeLayout; import android.widget.RelativeLayout;
import net.schueller.peertube.R; import net.schueller.peertube.R;
import net.schueller.peertube.fragment.VideoMetaDataFragment;
import net.schueller.peertube.fragment.VideoPlayerFragment; import net.schueller.peertube.fragment.VideoPlayerFragment;
import java.util.Objects; import java.util.Objects;
@ -79,6 +80,11 @@ public class VideoPlayActivity extends AppCompatActivity {
assert videoPlayerFragment != null; assert videoPlayerFragment != null;
videoPlayerFragment.start(videoUuid); videoPlayerFragment.start(videoUuid);
// if we are in landscape set the video to fullscreen
int orientation = this.getResources().getConfiguration().orientation;
if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
setOrientation(true);
}
} }
@ -89,13 +95,23 @@ public class VideoPlayActivity extends AppCompatActivity {
super.onConfigurationChanged(newConfig); super.onConfigurationChanged(newConfig);
// Checking the orientation changes of the screen
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
setOrientation(true);
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
setOrientation(false);
}
}
private void setOrientation(Boolean isLandscape) {
FragmentManager fragmentManager = getSupportFragmentManager(); FragmentManager fragmentManager = getSupportFragmentManager();
Fragment videoPlayerFragment = fragmentManager.findFragmentById(R.id.video_player_fragment); VideoPlayerFragment videoPlayerFragment = (VideoPlayerFragment) fragmentManager.findFragmentById(R.id.video_player_fragment);
Fragment videoMetaFragment = fragmentManager.findFragmentById(R.id.video_meta_data_fragment); VideoMetaDataFragment videoMetaFragment = (VideoMetaDataFragment) fragmentManager.findFragmentById(R.id.video_meta_data_fragment);
// Checking the orientation of the screen if (isLandscape) {
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
assert videoPlayerFragment != null; assert videoPlayerFragment != null;
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) Objects.requireNonNull(videoPlayerFragment.getView()).getLayoutParams(); RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) Objects.requireNonNull(videoPlayerFragment.getView()).getLayoutParams();
params.width = FrameLayout.LayoutParams.MATCH_PARENT; params.width = FrameLayout.LayoutParams.MATCH_PARENT;
@ -108,29 +124,26 @@ public class VideoPlayActivity extends AppCompatActivity {
.hide(videoMetaFragment) .hide(videoMetaFragment)
.commit(); .commit();
} }
videoPlayerFragment.setIsFullscreen(true);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); } else {
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
assert videoPlayerFragment != null; assert videoPlayerFragment != null;
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) Objects.requireNonNull(videoPlayerFragment.getView()).getLayoutParams(); RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) Objects.requireNonNull(videoPlayerFragment.getView()).getLayoutParams();
params.width = FrameLayout.LayoutParams.MATCH_PARENT; params.width = FrameLayout.LayoutParams.MATCH_PARENT;
params.height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 250, getResources().getDisplayMetrics()); params.height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 250, getResources().getDisplayMetrics());
videoPlayerFragment.getView().setLayoutParams(params); videoPlayerFragment.getView().setLayoutParams(params);
if (videoMetaFragment != null) { if (videoMetaFragment != null) {
fragmentManager.beginTransaction() fragmentManager.beginTransaction()
.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out) .setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out)
.show(videoMetaFragment) .show(videoMetaFragment)
.commit(); .commit();
} }
videoPlayerFragment.setIsFullscreen(false);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
} }
}
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
@Override @Override
protected void onDestroy() { protected void onDestroy() {

View File

@ -34,6 +34,7 @@ import android.view.LayoutInflater;
import android.view.Surface; import android.view.Surface;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
@ -74,7 +75,6 @@ public class VideoPlayerFragment extends Fragment implements VideoRendererEventL
private PlayerView simpleExoPlayerView; private PlayerView simpleExoPlayerView;
private Intent videoPlayerIntent; private Intent videoPlayerIntent;
private Boolean mBound = false; private Boolean mBound = false;
private TextView fullscreenButton;
private Boolean isFullscreen = false; private Boolean isFullscreen = false;
private VideoPlayerService mService; private VideoPlayerService mService;
private TorrentStream torrentStream; private TorrentStream torrentStream;
@ -132,6 +132,21 @@ public class VideoPlayerFragment extends Fragment implements VideoRendererEventL
simpleExoPlayerView.setControllerShowTimeoutMs(1000); simpleExoPlayerView.setControllerShowTimeoutMs(1000);
simpleExoPlayerView.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_FIT); simpleExoPlayerView.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_FIT);
// Full screen Icon
TextView fullscreenButton = activity.findViewById(R.id.exo_fullscreen);
fullscreenButton.setText(R.string.video_expand_icon);
new Iconics.IconicsBuilder().ctx(context).on(fullscreenButton).build();
fullscreenButton.setOnClickListener(view -> {
Log.d(TAG, "Fullscreen");
if (!isFullscreen) {
isFullscreen = true;
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
} else {
isFullscreen = false;
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
});
if (!mBound) { if (!mBound) {
videoPlayerIntent = new Intent(context, VideoPlayerService.class); videoPlayerIntent = new Intent(context, VideoPlayerService.class);
@ -192,25 +207,7 @@ public class VideoPlayerFragment extends Fragment implements VideoRendererEventL
videoMetaDataFragment.updateVideoMeta(video, mService); videoMetaDataFragment.updateVideoMeta(video, mService);
// Full screen Icon
assert activity != null;
fullscreenButton = activity.findViewById(R.id.exo_fullscreen);
fullscreenButton.setText(R.string.video_expand_icon);
new Iconics.IconicsBuilder().ctx(context).on(fullscreenButton).build();
fullscreenButton.setOnClickListener(view -> {
Log.d(TAG, "Fullscreen");
if (!isFullscreen) {
isFullscreen = true;
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
fullscreenButton.setText(R.string.video_compress_icon);
} else {
isFullscreen = false;
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
fullscreenButton.setText(R.string.video_expand_icon);
}
new Iconics.IconicsBuilder().ctx(context).on(fullscreenButton).build();
});
Log.v(TAG, "url : " + video.getFiles().get(0).getFileUrl()); Log.v(TAG, "url : " + video.getFiles().get(0).getFileUrl());
@ -252,6 +249,21 @@ public class VideoPlayerFragment extends Fragment implements VideoRendererEventL
} }
} }
public void setIsFullscreen(Boolean fullscreen) {
isFullscreen = fullscreen;
TextView fullscreenButton = getActivity().findViewById(R.id.exo_fullscreen);
if (fullscreen) {
fullscreenButton.setText(R.string.video_compress_icon);
} else {
fullscreenButton.setText(R.string.video_expand_icon);
}
new Iconics.IconicsBuilder().ctx(getContext()).on(fullscreenButton).build();
}
public Boolean getIsFullscreen() {
return isFullscreen;
}
/** /**
* Torrent Playback * Torrent Playback