Do not render ZoomSurfaceView when pinch to to zoom video is disabled.

This commit is contained in:
Docile-Alligator 2023-05-03 23:24:29 +08:00
parent 3c1ecfdee0
commit c3cd162092

View File

@ -61,6 +61,7 @@ import com.google.android.exoplayer2.source.hls.HlsMediaSource;
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector; import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
import com.google.android.exoplayer2.trackselection.TrackSelectionOverride; import com.google.android.exoplayer2.trackselection.TrackSelectionOverride;
import com.google.android.exoplayer2.ui.PlayerControlView; import com.google.android.exoplayer2.ui.PlayerControlView;
import com.google.android.exoplayer2.ui.PlayerView;
import com.google.android.exoplayer2.ui.TrackSelectionDialogBuilder; import com.google.android.exoplayer2.ui.TrackSelectionDialogBuilder;
import com.google.android.exoplayer2.upstream.DataSource; import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DefaultHttpDataSource; import com.google.android.exoplayer2.upstream.DefaultHttpDataSource;
@ -159,10 +160,6 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe
CoordinatorLayout coordinatorLayout; CoordinatorLayout coordinatorLayout;
@BindView(R.id.progress_bar_view_video_activity) @BindView(R.id.progress_bar_view_video_activity)
ProgressBar progressBar; ProgressBar progressBar;
@BindView(R.id.zoom_surface_view_view_video_activity)
ZoomSurfaceView zoomSurfaceView;
@BindView(R.id.player_control_view_view_video_activity)
PlayerControlView playerControlView;
@BindView(R.id.mute_exo_playback_control_view) @BindView(R.id.mute_exo_playback_control_view)
ImageButton muteButton; ImageButton muteButton;
@BindView(R.id.hd_exo_playback_control_view) @BindView(R.id.hd_exo_playback_control_view)
@ -293,7 +290,12 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe
getTheme().applyStyle(ContentFontFamily.valueOf(mSharedPreferences getTheme().applyStyle(ContentFontFamily.valueOf(mSharedPreferences
.getString(SharedPreferencesUtils.CONTENT_FONT_FAMILY_KEY, ContentFontFamily.Default.name())).getResId(), true); .getString(SharedPreferencesUtils.CONTENT_FONT_FAMILY_KEY, ContentFontFamily.Default.name())).getResId(), true);
boolean zoomable = mSharedPreferences.getBoolean(SharedPreferencesUtils.PINCH_TO_ZOOM_VIDEO, false);
if (zoomable) {
setContentView(R.layout.activity_view_video_zoomable);
} else {
setContentView(R.layout.activity_view_video); setContentView(R.layout.activity_view_video);
}
ButterKnife.bind(this); ButterKnife.bind(this);
setVolumeControlStream(AudioManager.STREAM_MUSIC); setVolumeControlStream(AudioManager.STREAM_MUSIC);
@ -406,6 +408,16 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe
String postTitle = intent.getStringExtra(EXTRA_POST_TITLE); String postTitle = intent.getStringExtra(EXTRA_POST_TITLE);
setSmallTitle(postTitle); setSmallTitle(postTitle);
trackSelector = new DefaultTrackSelector(this);
if (videoType == VIDEO_TYPE_NORMAL && isDataSavingMode && dataSavingModeDefaultResolution > 0) {
trackSelector.setParameters(
trackSelector.buildUponParameters()
.setMaxVideoSize(dataSavingModeDefaultResolution, dataSavingModeDefaultResolution));
}
player = new ExoPlayer.Builder(this).setTrackSelector(trackSelector).build();
if (zoomable) {
PlayerControlView playerControlView = findViewById(R.id.player_control_view_view_video_activity);
playerControlView.addVisibilityListener(visibility -> { playerControlView.addVisibilityListener(visibility -> {
switch (visibility) { switch (visibility) {
case View.GONE: case View.GONE:
@ -424,17 +436,9 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
} }
}); });
trackSelector = new DefaultTrackSelector(this);
if (videoType == VIDEO_TYPE_NORMAL && isDataSavingMode && dataSavingModeDefaultResolution > 0) {
trackSelector.setParameters(
trackSelector.buildUponParameters()
.setMaxVideoSize(dataSavingModeDefaultResolution, dataSavingModeDefaultResolution));
}
player = new ExoPlayer.Builder(this).setTrackSelector(trackSelector).build();
playerControlView.setPlayer(player); playerControlView.setPlayer(player);
ZoomSurfaceView zoomSurfaceView = findViewById(R.id.zoom_surface_view_view_video_activity);
player.addListener(new Player.Listener() { player.addListener(new Player.Listener() {
@Override @Override
public void onVideoSizeChanged(VideoSize videoSize) { public void onVideoSizeChanged(VideoSize videoSize) {
@ -452,7 +456,6 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe
} }
}); });
if (mSharedPreferences.getBoolean(SharedPreferencesUtils.PINCH_TO_ZOOM_VIDEO, false)) {
zoomSurfaceView.getEngine().addListener(new ZoomEngine.Listener() { zoomSurfaceView.getEngine().addListener(new ZoomEngine.Listener() {
@Override @Override
public void onUpdate(@NonNull ZoomEngine zoomEngine, @NonNull Matrix matrix) { public void onUpdate(@NonNull ZoomEngine zoomEngine, @NonNull Matrix matrix) {
@ -470,9 +473,6 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe
} }
}); });
} else {
zoomSurfaceView.setZoomEnabled(false);
}
zoomSurfaceView.setOnClickListener(view -> { zoomSurfaceView.setOnClickListener(view -> {
if (playerControlView.isVisible()) { if (playerControlView.isVisible()) {
playerControlView.hide(); playerControlView.hide();
@ -480,6 +480,28 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe
playerControlView.show(); playerControlView.show();
} }
}); });
} else {
PlayerView videoPlayerView = findViewById(R.id.player_view_view_video_activity);
videoPlayerView.setPlayer(player);
videoPlayerView.setControllerVisibilityListener(visibility -> {
switch (visibility) {
case View.GONE:
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE);
break;
case View.VISIBLE:
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}
});
}
if (savedInstanceState == null) { if (savedInstanceState == null) {
mVideoUri = intent.getData(); mVideoUri = intent.getData();