Improve behaviour of media send flow in landscape.

This commit is contained in:
Alex Hart
2021-09-07 12:20:58 -03:00
committed by Greyson Parrelli
parent a712622891
commit a086305c38
4 changed files with 82 additions and 25 deletions

View File

@@ -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);

View File

@@ -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();

View File

@@ -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);