summaryrefslogtreecommitdiffstats
path: root/src/com/android/settings/Utils.java
diff options
context:
space:
mode:
authorDanny Baumann <dannybaumann@web.de>2013-11-22 11:21:21 +0100
committerAdnan Begovic <adnan@cyngn.com>2015-10-29 17:36:28 -0700
commit088e98e29a2301fa804f9f3f69cbbdb74c337b4f (patch)
treee3e99eafbb47bcda6e929c8af9a04fe9d2c2ddc9 /src/com/android/settings/Utils.java
parent00c04247dd6c13e80a4480899af354426ffb6c8a (diff)
downloadpackages_apps_Settings-088e98e29a2301fa804f9f3f69cbbdb74c337b4f.zip
packages_apps_Settings-088e98e29a2301fa804f9f3f69cbbdb74c337b4f.tar.gz
packages_apps_Settings-088e98e29a2301fa804f9f3f69cbbdb74c337b4f.tar.bz2
Settings : Add back navigation bar customization.
Change-Id: I6431a611f3107fd1022df11362d1d2aa27b2f436
Diffstat (limited to 'src/com/android/settings/Utils.java')
-rw-r--r--src/com/android/settings/Utils.java37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/com/android/settings/Utils.java b/src/com/android/settings/Utils.java
index b1170c8..0834c8d 100644
--- a/src/com/android/settings/Utils.java
+++ b/src/com/android/settings/Utils.java
@@ -17,6 +17,7 @@
package com.android.settings;
import android.annotation.Nullable;
+import android.app.Activity;
import android.app.ActivityManager;
import android.app.ActivityManagerNative;
import android.app.AlertDialog;
@@ -31,6 +32,7 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
+import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.IPackageManager;
import android.content.pm.IntentFilterVerificationInfo;
@@ -40,6 +42,7 @@ import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ResolveInfo;
import android.content.pm.Signature;
import android.content.pm.UserInfo;
+import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.Resources.NotFoundException;
import android.content.res.TypedArray;
@@ -81,6 +84,8 @@ import android.util.ArraySet;
import android.util.Log;
import android.util.SparseArray;
import android.view.LayoutInflater;
+import android.view.DisplayInfo;
+import android.view.Surface;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
@@ -1422,4 +1427,36 @@ public final class Utils {
}
}
+ /**
+ * Locks the activity orientation to the current device orientation
+ * @param activity
+ */
+ public static void lockCurrentOrientation(Activity activity) {
+ int currentRotation = activity.getWindowManager().getDefaultDisplay().getRotation();
+ int orientation = activity.getResources().getConfiguration().orientation;
+ int frozenRotation = 0;
+ switch (currentRotation) {
+ case Surface.ROTATION_0:
+ frozenRotation = orientation == Configuration.ORIENTATION_LANDSCAPE
+ ? ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
+ : ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
+ break;
+ case Surface.ROTATION_90:
+ frozenRotation = orientation == Configuration.ORIENTATION_PORTRAIT
+ ? ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT
+ : ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
+ break;
+ case Surface.ROTATION_180:
+ frozenRotation = orientation == Configuration.ORIENTATION_LANDSCAPE
+ ? ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
+ : ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
+ break;
+ case Surface.ROTATION_270:
+ frozenRotation = orientation == Configuration.ORIENTATION_PORTRAIT
+ ? ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
+ : ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
+ break;
+ }
+ activity.setRequestedOrientation(frozenRotation);
+ }
}