Fix lock orientation change

This commit is contained in:
J-Jamet committed 2018-05-02 14:02:10 +02:00
1 parent 7af28550da
commit 64e9b9fb6d
9 files changed
+36 -34

No files matched your search

@@ -575,7 +575,7 @@ public class EntryEditActivity extends LockingHideActivity
displayMessage(EntryEditActivity.this);
}
SaveDatabaseProgressTaskDialogFragment.stop(getSupportFragmentManager());
SaveDatabaseProgressTaskDialogFragment.stop(EntryEditActivity.this);
});
}
}
@@ -316,7 +316,7 @@ public abstract class ListNodesActivity extends LockingActivity
displayMessage(ListNodesActivity.this);
}
SaveDatabaseProgressTaskDialogFragment.stop(getSupportFragmentManager());
SaveDatabaseProgressTaskDialogFragment.stop(ListNodesActivity.this);
});
}
}
@@ -336,7 +336,7 @@ public abstract class ListNodesActivity extends LockingActivity
displayMessage(ListNodesActivity.this);
}
SaveDatabaseProgressTaskDialogFragment.stop(getSupportFragmentManager());
SaveDatabaseProgressTaskDialogFragment.stop(ListNodesActivity.this);
});
}
}
@@ -376,7 +376,7 @@ public abstract class ListNodesActivity extends LockingActivity
finish();
}
SaveDatabaseProgressTaskDialogFragment.stop(getSupportFragmentManager());
SaveDatabaseProgressTaskDialogFragment.stop(ListNodesActivity.this);
});
}
}
@@ -110,7 +110,7 @@ public class AssignPasswordHelper {
}
// To remove progress task
ProgressTaskDialogFragment.stop(context.getSupportFragmentManager());
ProgressTaskDialogFragment.stop(context);
});
}
}
@@ -55,6 +55,7 @@ import com.getkeepsafe.taptargetview.TapTarget;
import com.getkeepsafe.taptargetview.TapTargetView;
import com.kunzisoft.keepass.R;
import com.kunzisoft.keepass.activities.GroupActivity;
import com.kunzisoft.keepass.activities.ListNodesActivity;
import com.kunzisoft.keepass.activities.LockingActivity;
import com.kunzisoft.keepass.app.App;
import com.kunzisoft.keepass.autofill.AutofillHelper;
@@ -875,7 +876,7 @@ public class PasswordActivity extends StylishActivity
}
// To remove progress task
ProgressTaskDialogFragment.stop(getSupportFragmentManager());
ProgressTaskDialogFragment.stop(PasswordActivity.this);
});
}
}
@@ -71,8 +71,7 @@ public class DatabaseDescriptionPreferenceDialogFragmentCompat extends DatabaseS
if (mActivity != null) {
mActivity.runOnUiThread(() -> {
getPreference().setSummary(descriptionToShow);
SaveDatabaseProgressTaskDialogFragment.stop(
mActivity.getSupportFragmentManager());
SaveDatabaseProgressTaskDialogFragment.stop(mActivity);
});
}
@@ -71,8 +71,7 @@ public class DatabaseNamePreferenceDialogFragmentCompat extends DatabaseSavePref
if (mActivity != null) {
mActivity.runOnUiThread(() -> {
getPreference().setSummary(nameToShow);
SaveDatabaseProgressTaskDialogFragment.stop(
mActivity.getSupportFragmentManager());
SaveDatabaseProgressTaskDialogFragment.stop(mActivity);
});
}
@@ -109,8 +109,7 @@ public class RoundsPreferenceDialogFragmentCompat extends DatabaseSavePreference
if (mActivity != null) {
mActivity.runOnUiThread(() -> {
getPreference().setSummary(String.valueOf(roundsToShow));
SaveDatabaseProgressTaskDialogFragment.stop(
mActivity.getSupportFragmentManager());
SaveDatabaseProgressTaskDialogFragment.stop(mActivity);
});
}
@@ -22,8 +22,6 @@ package com.kunzisoft.keepass.tasks;
import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.StringRes;
@@ -31,12 +29,14 @@ import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.kunzisoft.keepass.R;
import com.kunzisoft.keepass.utils.Util;
public class ProgressTaskDialogFragment extends DialogFragment implements ProgressTaskUpdater{
@@ -81,7 +81,7 @@ public class ProgressTaskDialogFragment extends DialogFragment implements Progre
updateMessage(message);
setCancelable(false);
lockScreenOrientation();
Util.lockScreenOrientation(getActivity());
return builder.create();
}
@@ -89,33 +89,18 @@ public class ProgressTaskDialogFragment extends DialogFragment implements Progre
@Override
public void onDismiss(DialogInterface dialog) {
super.onDismiss(dialog);
unlockScreenOrientation();
Util.unlockScreenOrientation(getActivity());
}
public static void stop(FragmentManager fragmentManager) {
Fragment fragmentTask = fragmentManager.findFragmentByTag(PROGRESS_TASK_DIALOG_TAG);
public static void stop(AppCompatActivity activity) {
Fragment fragmentTask = activity.getSupportFragmentManager().findFragmentByTag(PROGRESS_TASK_DIALOG_TAG);
if (fragmentTask != null) {
ProgressTaskDialogFragment loadingDatabaseDialog = (ProgressTaskDialogFragment) fragmentTask;
loadingDatabaseDialog.dismissAllowingStateLoss();
Util.unlockScreenOrientation(activity);
}
}
private void lockScreenOrientation() {
if (getActivity() != null) {
int currentOrientation = getResources().getConfiguration().orientation;
if (currentOrientation == Configuration.ORIENTATION_PORTRAIT) {
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
} else {
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
}
}
private void unlockScreenOrientation() {
if (getActivity() != null)
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
}
public void setTitle(@StringRes int titleId) {
this.title = titleId;
}
@@ -19,9 +19,12 @@
*/
package com.kunzisoft.keepass.utils;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.graphics.Typeface;
import android.net.Uri;
import android.widget.EditText;
@@ -70,4 +73,20 @@ public class Util {
public static void applyFontVisibilityTo(final Context context, final EditText editText) {
applyFontVisibilityTo(context, (TextView) editText);
}
public static void lockScreenOrientation(Activity activity) {
if (activity != null) {
int currentOrientation = activity.getResources().getConfiguration().orientation;
if (currentOrientation == Configuration.ORIENTATION_PORTRAIT) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
} else {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
}
}
public static void unlockScreenOrientation(Activity activity) {
if (activity != null)
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
}
}