- Cleaned up full screen button and activation
This commit is contained in:
parent
a397822c23
commit
3f0c275cdc
@ -37,6 +37,7 @@ import android.widget.FrameLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
|
||||
import net.schueller.peertube.R;
|
||||
import net.schueller.peertube.fragment.VideoMetaDataFragment;
|
||||
import net.schueller.peertube.fragment.VideoPlayerFragment;
|
||||
|
||||
import java.util.Objects;
|
||||
@ -79,6 +80,11 @@ public class VideoPlayActivity extends AppCompatActivity {
|
||||
assert videoPlayerFragment != null;
|
||||
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);
|
||||
|
||||
// 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();
|
||||
Fragment videoPlayerFragment = fragmentManager.findFragmentById(R.id.video_player_fragment);
|
||||
Fragment videoMetaFragment = fragmentManager.findFragmentById(R.id.video_meta_data_fragment);
|
||||
VideoPlayerFragment videoPlayerFragment = (VideoPlayerFragment) fragmentManager.findFragmentById(R.id.video_player_fragment);
|
||||
VideoMetaDataFragment videoMetaFragment = (VideoMetaDataFragment) fragmentManager.findFragmentById(R.id.video_meta_data_fragment);
|
||||
|
||||
// Checking the orientation of the screen
|
||||
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
||||
if (isLandscape) {
|
||||
assert videoPlayerFragment != null;
|
||||
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) Objects.requireNonNull(videoPlayerFragment.getView()).getLayoutParams();
|
||||
params.width = FrameLayout.LayoutParams.MATCH_PARENT;
|
||||
@ -108,29 +124,26 @@ public class VideoPlayActivity extends AppCompatActivity {
|
||||
.hide(videoMetaFragment)
|
||||
.commit();
|
||||
}
|
||||
videoPlayerFragment.setIsFullscreen(true);
|
||||
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
|
||||
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
|
||||
|
||||
} else {
|
||||
assert videoPlayerFragment != null;
|
||||
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) Objects.requireNonNull(videoPlayerFragment.getView()).getLayoutParams();
|
||||
params.width = FrameLayout.LayoutParams.MATCH_PARENT;
|
||||
params.height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 250, getResources().getDisplayMetrics());
|
||||
videoPlayerFragment.getView().setLayoutParams(params);
|
||||
|
||||
|
||||
if (videoMetaFragment != null) {
|
||||
fragmentManager.beginTransaction()
|
||||
.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out)
|
||||
.show(videoMetaFragment)
|
||||
.commit();
|
||||
}
|
||||
|
||||
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
}
|
||||
videoPlayerFragment.setIsFullscreen(false);
|
||||
}
|
||||
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
|
@ -34,6 +34,7 @@ import android.view.LayoutInflater;
|
||||
import android.view.Surface;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
@ -74,7 +75,6 @@ public class VideoPlayerFragment extends Fragment implements VideoRendererEventL
|
||||
private PlayerView simpleExoPlayerView;
|
||||
private Intent videoPlayerIntent;
|
||||
private Boolean mBound = false;
|
||||
private TextView fullscreenButton;
|
||||
private Boolean isFullscreen = false;
|
||||
private VideoPlayerService mService;
|
||||
private TorrentStream torrentStream;
|
||||
@ -132,6 +132,21 @@ public class VideoPlayerFragment extends Fragment implements VideoRendererEventL
|
||||
simpleExoPlayerView.setControllerShowTimeoutMs(1000);
|
||||
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) {
|
||||
videoPlayerIntent = new Intent(context, VideoPlayerService.class);
|
||||
@ -192,25 +207,7 @@ public class VideoPlayerFragment extends Fragment implements VideoRendererEventL
|
||||
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());
|
||||
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user