mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-28 02:37:46 +00:00
Enable media gallery fullscreen mode (#813)
* feat: Enable fullscreen mode on the media gallery screen * Move `fitsSystemWindows` attribute to root view * Rename for clarity * Update fullscreen flag * Set system bars behaviour for api >= 30
This commit is contained in:
parent
8ea0690e3a
commit
366b5abdc8
@ -27,6 +27,8 @@ import android.os.Build;
|
||||
import android.os.Build.VERSION;
|
||||
import android.os.Build.VERSION_CODES;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.view.GestureDetector;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
@ -36,6 +38,8 @@ import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
import android.view.WindowInsets;
|
||||
import android.view.WindowInsetsController;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
@ -92,6 +96,8 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity im
|
||||
|
||||
private final static String TAG = MediaPreviewActivity.class.getSimpleName();
|
||||
|
||||
private static final int UI_ANIMATION_DELAY = 300;
|
||||
|
||||
public static final String ADDRESS_EXTRA = "address";
|
||||
public static final String DATE_EXTRA = "date";
|
||||
public static final String SIZE_EXTRA = "size";
|
||||
@ -99,6 +105,7 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity im
|
||||
public static final String OUTGOING_EXTRA = "outgoing";
|
||||
public static final String LEFT_IS_RECENT_EXTRA = "left_is_recent";
|
||||
|
||||
private View rootContainer;
|
||||
private ViewPager mediaPager;
|
||||
private View detailsContainer;
|
||||
private TextView caption;
|
||||
@ -118,6 +125,26 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity im
|
||||
|
||||
private int restartItem = -1;
|
||||
|
||||
private boolean isFullscreen = false;
|
||||
private final Handler hideHandler = new Handler(Looper.myLooper());
|
||||
private final Runnable showRunnable = () -> {
|
||||
getSupportActionBar().show();
|
||||
};
|
||||
private final Runnable hideRunnable = () -> {
|
||||
if (VERSION.SDK_INT >= 30) {
|
||||
rootContainer.getWindowInsetsController().hide(WindowInsets.Type.statusBars() | WindowInsets.Type.navigationBars());
|
||||
rootContainer.getWindowInsetsController().setSystemBarsBehavior(WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE);
|
||||
} else {
|
||||
rootContainer.setSystemUiVisibility(
|
||||
View.SYSTEM_UI_FLAG_LOW_PROFILE |
|
||||
View.SYSTEM_UI_FLAG_FULLSCREEN |
|
||||
View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
|
||||
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY |
|
||||
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
|
||||
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
|
||||
}
|
||||
};
|
||||
|
||||
public static Intent getPreviewIntent(Context context, Slide slide, MmsMessageRecord mms, Recipient threadRecipient) {
|
||||
Intent previewIntent = null;
|
||||
if (MediaPreviewActivity.isContentTypeSupported(slide.getContentType()) && slide.getUri() != null) {
|
||||
@ -147,6 +174,32 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity im
|
||||
initializeObservers();
|
||||
}
|
||||
|
||||
private void toggleFullscreen() {
|
||||
if (isFullscreen) {
|
||||
exitFullscreen();
|
||||
} else {
|
||||
enterFullscreen();
|
||||
}
|
||||
}
|
||||
|
||||
private void enterFullscreen() {
|
||||
getSupportActionBar().hide();
|
||||
isFullscreen = true;
|
||||
hideHandler.removeCallbacks(showRunnable);
|
||||
hideHandler.postDelayed(hideRunnable, UI_ANIMATION_DELAY);
|
||||
}
|
||||
|
||||
private void exitFullscreen() {
|
||||
if (Build.VERSION.SDK_INT >= 30) {
|
||||
rootContainer.getWindowInsetsController().show(WindowInsets.Type.statusBars() | WindowInsets.Type.navigationBars());
|
||||
} else {
|
||||
rootContainer.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
|
||||
}
|
||||
isFullscreen = false;
|
||||
hideHandler.removeCallbacks(hideRunnable);
|
||||
hideHandler.postDelayed(showRunnable, UI_ANIMATION_DELAY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean dispatchTouchEvent(MotionEvent ev) {
|
||||
clickDetector.onTouchEvent(ev);
|
||||
@ -223,6 +276,7 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity im
|
||||
}
|
||||
|
||||
private void initializeViews() {
|
||||
rootContainer = findViewById(R.id.media_preview_root);
|
||||
mediaPager = findViewById(R.id.media_pager);
|
||||
mediaPager.setOffscreenPageLimit(1);
|
||||
|
||||
@ -295,12 +349,13 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity im
|
||||
}
|
||||
});
|
||||
|
||||
clickDetector = new GestureDetector(new GestureDetector.SimpleOnGestureListener() {
|
||||
clickDetector = new GestureDetector(this, new GestureDetector.SimpleOnGestureListener() {
|
||||
@Override
|
||||
public boolean onSingleTapUp(MotionEvent e) {
|
||||
if (e.getY() < detailsContainer.getTop()) {
|
||||
detailsContainer.setVisibility(detailsContainer.getVisibility() == View.VISIBLE ? View.GONE : View.VISIBLE);
|
||||
}
|
||||
toggleFullscreen();
|
||||
return super.onSingleTapUp(e);
|
||||
}
|
||||
});
|
||||
|
@ -4,8 +4,10 @@
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/media_preview_root"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
android:layout_height="match_parent"
|
||||
android:fitsSystemWindows="true">
|
||||
|
||||
<com.google.android.material.appbar.AppBarLayout
|
||||
style="@style/Widget.Session.AppBarLayout"
|
||||
@ -24,7 +26,7 @@
|
||||
android:id="@+id/media_pager"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:clickable="true"/>
|
||||
android:clickable="true" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/media_preview_details_container"
|
||||
|
Loading…
x
Reference in New Issue
Block a user