From a8f21a94b093171c084678a03cbe7403f9b23452 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Thu, 14 Oct 2021 20:57:22 +0800 Subject: New option: Pinch to Zoom Video. --- .../activities/ViewImageOrGifActivity.java | 4 +++- .../activities/ViewVideoActivity.java | 25 ++++++++++++++++++++++ .../utils/SharedPreferencesUtils.java | 1 + 3 files changed, 29 insertions(+), 1 deletion(-) (limited to 'app/src/main/java/ml') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewImageOrGifActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewImageOrGifActivity.java index d07e8c69..e5d5f72b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewImageOrGifActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewImageOrGifActivity.java @@ -292,7 +292,9 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa // Fixes #383 // Not having a background will cause visual glitches on some devices. FrameLayout slidablePanel = findViewById(R.id.slidable_panel); - slidablePanel.setBackgroundColor(getResources().getColor(android.R.color.black)); + if (slidablePanel != null) { + slidablePanel.setBackgroundColor(getResources().getColor(android.R.color.black)); + } } private void loadImage() { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java index 5a473d29..09d9850b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java @@ -7,6 +7,7 @@ import android.content.pm.ActivityInfo; import android.content.pm.PackageManager; import android.content.res.Configuration; import android.content.res.Resources; +import android.graphics.Matrix; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.media.AudioManager; @@ -57,6 +58,7 @@ import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.video.VideoListener; import com.google.android.material.bottomappbar.BottomAppBar; import com.google.android.material.snackbar.Snackbar; +import com.otaliastudios.zoom.ZoomEngine; import com.otaliastudios.zoom.ZoomSurfaceView; import org.apache.commons.io.FilenameUtils; @@ -69,6 +71,7 @@ import javax.inject.Named; import app.futured.hauler.DragDirection; import app.futured.hauler.HaulerView; +import app.futured.hauler.LockableNestedScrollView; import butterknife.BindView; import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.FetchGfycatOrRedgifsVideoLinks; @@ -147,6 +150,8 @@ public class ViewVideoActivity extends AppCompatActivity { TextView titleTextView; @BindView(R.id.download_image_view_exo_playback_control_view) ImageView downloadImageView; + @BindView(R.id.lockable_nested_scroll_view_view_video_activity) + LockableNestedScrollView nestedScrollView; private Uri mVideoUri; private SimpleExoPlayer player; @@ -371,7 +376,27 @@ public class ViewVideoActivity extends AppCompatActivity { } }); + if (mSharedPreferences.getBoolean(SharedPreferencesUtils.PINCH_TO_ZOOM_VIDEO, false)) { + zoomSurfaceView.getEngine().addListener(new ZoomEngine.Listener() { + @Override + public void onUpdate(@NonNull ZoomEngine zoomEngine, @NonNull Matrix matrix) { + if (zoomEngine.getZoom() < 1.00001) { + haulerView.setDragEnabled(true); + nestedScrollView.setScrollEnabled(true); + } else { + haulerView.setDragEnabled(false); + nestedScrollView.setScrollEnabled(false); + } + } + @Override + public void onIdle(@NonNull ZoomEngine zoomEngine) { + + } + }); + } else { + zoomSurfaceView.setZoomEnabled(false); + } zoomSurfaceView.setOnClickListener(view -> { if (playerControlView.isVisible()) { playerControlView.hide(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java index 9cc3c839..285c8d58 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java @@ -194,6 +194,7 @@ public class SharedPreferencesUtils { public static final String LOOP_VIDEO = "loop_video"; public static final String DEFAULT_PLAYBACK_SPEED = "default_playback_speed"; public static final String LEGACY_AUTOPLAY_VIDEO_CONTROLLER_UI = "legacy_autoplay_video_controller_ui"; + public static final String PINCH_TO_ZOOM_VIDEO = "pinch_to_zoom_video"; public static final String DEFAULT_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit_preferences"; public static final String MAIN_PAGE_TABS_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.main_page_tabs"; -- cgit v1.2.3