Lock orientation

pull/209/head
M66B 2 years ago
parent 2e58059bca
commit 82e7dc3b47

@ -22,6 +22,7 @@ package eu.faircode.email;
import static android.app.ActionBar.DISPLAY_SHOW_CUSTOM;
import static android.app.Activity.RESULT_OK;
import android.app.Activity;
import android.app.RecoverableSecurityException;
import android.content.BroadcastReceiver;
import android.content.Context;
@ -30,6 +31,7 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.content.IntentSender;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.graphics.Rect;
@ -85,6 +87,8 @@ public class FragmentBase extends Fragment {
private int scrollToResid = 0;
private int scrollToOffset = 0;
private Integer orientation = null;
private static final int REQUEST_ATTACHMENT = 51;
private static final int REQUEST_ATTACHMENTS = 52;
private static final int REQUEST_RECOVERABLE_PERMISSION = 53;
@ -409,9 +413,22 @@ public class FragmentBase extends Fragment {
@Override
public void onDestroy() {
Log.i("Destroy " + this);
if (orientation != null) {
Activity activity = getActivity();
if (activity != null)
activity.setRequestedOrientation(orientation);
}
super.onDestroy();
}
protected void lockOrientation() {
Activity activity = getActivity();
if (activity != null) {
orientation = activity.getRequestedOrientation();
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
}
}
@Override
public void setHasOptionsMenu(boolean hasMenu) {
super.setHasOptionsMenu(!isPane() && hasMenu);

@ -22,8 +22,10 @@ package eu.faircode.email;
import static android.app.Activity.RESULT_CANCELED;
import static android.app.Activity.RESULT_OK;
import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import androidx.annotation.NonNull;
@ -42,6 +44,7 @@ public class FragmentDialogBase extends DialogFragment {
private LifecycleRegistry registry;
private String targetRequestKey;
private int targetRequestCode;
private Integer orientation = null;
public String getRequestKey() {
return Helper.getRequestKey(this);
@ -110,13 +113,6 @@ public class FragmentDialogBase extends DialogFragment {
Log.d("Pause " + this);
}
@Override
public void onDestroy() {
registry.setCurrentState(Lifecycle.State.DESTROYED);
super.onDestroy();
Log.i("Destroy " + this);
}
@Override
public void onStart() {
registry.setCurrentState(Lifecycle.State.STARTED);
@ -135,6 +131,26 @@ public class FragmentDialogBase extends DialogFragment {
Log.d("Stop " + this);
}
@Override
public void onDestroy() {
registry.setCurrentState(Lifecycle.State.DESTROYED);
if (orientation != null) {
Activity activity = getActivity();
if (activity != null)
activity.setRequestedOrientation(orientation);
}
super.onDestroy();
Log.i("Destroy " + this);
}
protected void lockOrientation() {
Activity activity = getActivity();
if (activity != null) {
orientation = activity.getRequestedOrientation();
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
String action = (data == null ? null : data.getAction());

@ -73,6 +73,12 @@ public class FragmentDialogInsertLink extends FragmentDialogBase {
private static final int METADATA_READ_TIMEOUT = 15 * 1000; // milliseconds
private static final int REQUEST_SEND = 1;
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
lockOrientation();
}
@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
outState.putString("fair:link", etLink == null ? null : etLink.getText().toString());

@ -106,6 +106,8 @@ public class FragmentGmail extends FragmentBase {
pop = args.getBoolean("pop", false);
recent = args.getBoolean("recent", false);
update = args.getBoolean("update", true);
lockOrientation();
}
@Override

@ -153,6 +153,8 @@ public class FragmentOAuth extends FragmentBase {
pop = args.getBoolean("pop", false);
recent = args.getBoolean("recent", false);
update = args.getBoolean("update", true);
lockOrientation();
}
@Override

@ -119,6 +119,8 @@ public class FragmentQuickSetup extends FragmentBase {
Bundle args = getArguments();
update = args.getBoolean("update", true);
lockOrientation();
}
@Override

Loading…
Cancel
Save