mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-24 04:58:45 +00:00
Improve behaviour of media send flow in landscape.
This commit is contained in:
committed by
Greyson Parrelli
parent
a712622891
commit
a086305c38
@@ -123,7 +123,7 @@ public class Camera1Fragment extends LoggingFragment implements CameraFragment,
|
||||
|
||||
view.addOnLayoutChangeListener((v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> {
|
||||
// Let's assume portrait for now, so 9:16
|
||||
float aspectRatio = 9f / 16f;
|
||||
float aspectRatio = CameraFragment.getAspectRatioForOrientation(getResources().getConfiguration().orientation);
|
||||
float width = right - left;
|
||||
float height = Math.min((1f / aspectRatio) * width, bottom - top);
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.thoughtcrime.securesms.mediasend;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.res.Configuration;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
@@ -14,6 +15,8 @@ import java.io.FileDescriptor;
|
||||
|
||||
public interface CameraFragment {
|
||||
|
||||
float PORTRAIT_ASPECT_RATIO = 9 / 16f;
|
||||
|
||||
@SuppressLint("RestrictedApi")
|
||||
static Fragment newInstance() {
|
||||
if (CameraXUtil.isSupported()) {
|
||||
@@ -32,6 +35,14 @@ public interface CameraFragment {
|
||||
}
|
||||
}
|
||||
|
||||
static float getAspectRatioForOrientation(int orientation) {
|
||||
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
|
||||
return PORTRAIT_ASPECT_RATIO;
|
||||
} else {
|
||||
return 1f / PORTRAIT_ASPECT_RATIO;
|
||||
}
|
||||
}
|
||||
|
||||
void presentHud(int selectedMediaCount);
|
||||
void fadeOutControls(@NonNull Runnable onEndAction);
|
||||
void fadeInControls();
|
||||
|
||||
@@ -126,7 +126,7 @@ public class CameraXFragment extends LoggingFragment implements CameraFragment {
|
||||
|
||||
view.addOnLayoutChangeListener((v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> {
|
||||
// Let's assume portrait for now, so 9:16
|
||||
float aspectRatio = 9f / 16f;
|
||||
float aspectRatio = CameraFragment.getAspectRatioForOrientation(getResources().getConfiguration().orientation);
|
||||
float width = right - left;
|
||||
float height = Math.min((1f / aspectRatio) * width, bottom - top);
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import static android.app.Activity.RESULT_OK;
|
||||
|
||||
import android.Manifest;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.Paint;
|
||||
@@ -74,6 +75,8 @@ public final class ImageEditorFragment extends Fragment implements ImageEditorHu
|
||||
|
||||
private static final String TAG = Log.tag(ImageEditorFragment.class);
|
||||
|
||||
private static final float PORTRAIT_ASPECT_RATIO = 9 / 16f;
|
||||
|
||||
private static final String KEY_IMAGE_URI = "image_uri";
|
||||
private static final String KEY_MODE = "mode";
|
||||
|
||||
@@ -159,6 +162,12 @@ public final class ImageEditorFragment extends Fragment implements ImageEditorHu
|
||||
imageEditorHud.setMode(mode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfigurationChanged(@NonNull Configuration newConfig) {
|
||||
super.onConfigurationChanged(newConfig);
|
||||
updateViewPortScaling(imageEditorHud.getMode(), imageEditorHud.getMode(), newConfig.orientation, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -390,16 +399,7 @@ public final class ImageEditorFragment extends Fragment implements ImageEditorHu
|
||||
|
||||
controller.onTouchEventsNeeded(mode != ImageEditorHudV2.Mode.NONE);
|
||||
|
||||
boolean shouldScaleViewPortForCurrentMode = shouldScaleViewPort(mode);
|
||||
boolean shouldScaleViewPortForPreviousMode = shouldScaleViewPort(previousMode);
|
||||
|
||||
if (shouldScaleViewPortForCurrentMode != shouldScaleViewPortForPreviousMode) {
|
||||
if (shouldScaleViewPortForCurrentMode) {
|
||||
scaleViewPortForDrawing();
|
||||
} else {
|
||||
restoreViewPortScaling();
|
||||
}
|
||||
}
|
||||
updateViewPortScaling(mode, previousMode, getResources().getConfiguration().orientation, false);
|
||||
|
||||
if (mode != ImageEditorHudV2.Mode.CROP) {
|
||||
imageEditorView.getModel().doneCrop();
|
||||
@@ -448,6 +448,24 @@ public final class ImageEditorFragment extends Fragment implements ImageEditorHu
|
||||
}
|
||||
}
|
||||
|
||||
private void updateViewPortScaling(
|
||||
@NonNull ImageEditorHudV2.Mode mode,
|
||||
@NonNull ImageEditorHudV2.Mode previousMode,
|
||||
int orientation,
|
||||
boolean force)
|
||||
{
|
||||
boolean shouldScaleViewPortForCurrentMode = shouldScaleViewPort(mode);
|
||||
boolean shouldScaleViewPortForPreviousMode = shouldScaleViewPort(previousMode);
|
||||
|
||||
if (shouldScaleViewPortForCurrentMode != shouldScaleViewPortForPreviousMode || force) {
|
||||
if (shouldScaleViewPortForCurrentMode) {
|
||||
scaleViewPortForDrawing(orientation);
|
||||
} else {
|
||||
restoreViewPortScaling(orientation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onColorChange(int color) {
|
||||
imageEditorView.setDrawingBrushColor(color);
|
||||
@@ -613,42 +631,70 @@ public final class ImageEditorFragment extends Fragment implements ImageEditorHu
|
||||
|
||||
private ResizeAnimation resizeAnimation;
|
||||
|
||||
private void scaleViewPortForDrawing() {
|
||||
private void scaleViewPortForDrawing(int orientation) {
|
||||
if (resizeAnimation != null) {
|
||||
resizeAnimation.cancel();
|
||||
}
|
||||
|
||||
float aspectRatio = 9 / 16f;
|
||||
int targetWidth = requireView().getMeasuredWidth() - ViewUtil.dpToPx(32);
|
||||
float aspectRatio = getAspectRatioForOrientation(orientation);
|
||||
int targetWidth = getWidthForOrientation(orientation) - ViewUtil.dpToPx(32);
|
||||
int targetHeight = (int) ((1 / aspectRatio) * targetWidth);
|
||||
int maxHeight = getHeightForOrientation(orientation) - HUD_PROTECTION;
|
||||
|
||||
int maxHeight = getResources().getDisplayMetrics().heightPixels - HUD_PROTECTION;
|
||||
if (targetHeight > maxHeight) {
|
||||
targetHeight = maxHeight;
|
||||
targetWidth = Math.round(targetHeight * aspectRatio);
|
||||
}
|
||||
|
||||
if (targetWidth < requireView().getMeasuredWidth()) {
|
||||
resizeAnimation = new ResizeAnimation(imageEditorView, targetWidth, targetHeight);
|
||||
resizeAnimation.setDuration(250);
|
||||
imageEditorView.startAnimation(resizeAnimation);
|
||||
}
|
||||
resizeAnimation = new ResizeAnimation(imageEditorView, targetWidth, targetHeight);
|
||||
resizeAnimation.setDuration(250);
|
||||
imageEditorView.startAnimation(resizeAnimation);
|
||||
}
|
||||
|
||||
private void restoreViewPortScaling() {
|
||||
private void restoreViewPortScaling(int orientation) {
|
||||
if (resizeAnimation != null) {
|
||||
resizeAnimation.cancel();
|
||||
}
|
||||
|
||||
float aspectRatio = 9 / 16f;
|
||||
int targetWidth = requireView().getMeasuredWidth();
|
||||
int targetHeight = (int) ((1 / aspectRatio) * targetWidth);
|
||||
int maxHeight = getHeightForOrientation(orientation);
|
||||
float aspectRatio = getAspectRatioForOrientation(orientation);
|
||||
int targetWidth = getWidthForOrientation(orientation);
|
||||
int targetHeight = (int) ((1 / aspectRatio) * targetWidth);
|
||||
|
||||
if (targetHeight > maxHeight) {
|
||||
targetHeight = maxHeight;
|
||||
targetWidth = Math.round(targetHeight * aspectRatio);
|
||||
}
|
||||
|
||||
resizeAnimation = new ResizeAnimation(imageEditorView, targetWidth, targetHeight);
|
||||
resizeAnimation.setDuration(250);
|
||||
imageEditorView.startAnimation(resizeAnimation);
|
||||
}
|
||||
|
||||
private int getHeightForOrientation(int orientation) {
|
||||
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
|
||||
return Math.max(getResources().getDisplayMetrics().heightPixels, getResources().getDisplayMetrics().widthPixels);
|
||||
} else {
|
||||
return Math.min(getResources().getDisplayMetrics().heightPixels, getResources().getDisplayMetrics().widthPixels);
|
||||
}
|
||||
}
|
||||
|
||||
private int getWidthForOrientation(int orientation) {
|
||||
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
|
||||
return Math.min(getResources().getDisplayMetrics().heightPixels, getResources().getDisplayMetrics().widthPixels);
|
||||
} else {
|
||||
return Math.max(getResources().getDisplayMetrics().heightPixels, getResources().getDisplayMetrics().widthPixels);
|
||||
}
|
||||
}
|
||||
|
||||
private float getAspectRatioForOrientation(int orientation) {
|
||||
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
|
||||
return PORTRAIT_ASPECT_RATIO;
|
||||
} else {
|
||||
return 1f / PORTRAIT_ASPECT_RATIO;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean shouldScaleViewPort(@NonNull ImageEditorHudV2.Mode mode) {
|
||||
return mode != ImageEditorHudV2.Mode.NONE && mode != ImageEditorHudV2.Mode.CROP;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user