aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util
diff options
context:
space:
mode:
authorDominik Schürmann <dominik@dominikschuermann.de>2015-08-12 21:26:15 +0200
committerDominik Schürmann <dominik@dominikschuermann.de>2015-08-12 21:26:15 +0200
commit01e68e044cf897cc9559157c35a451889b3413aa (patch)
treeb740369787db1a68b8945eff73e650d027f4d69f /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util
parent2edb5349b065b2e5bbae80a7b09c96afa664fc04 (diff)
downloadopen-keychain-01e68e044cf897cc9559157c35a451889b3413aa.tar.gz
open-keychain-01e68e044cf897cc9559157c35a451889b3413aa.tar.bz2
open-keychain-01e68e044cf897cc9559157c35a451889b3413aa.zip
Lock orientation for yubikey operations
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/OrientationUtils.java85
1 files changed, 85 insertions, 0 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/OrientationUtils.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/OrientationUtils.java
new file mode 100644
index 000000000..43ed12429
--- /dev/null
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/OrientationUtils.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) 2015 Dominik Schürmann <dominik@dominikschuermann.de>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package org.sufficientlysecure.keychain.util;
+
+import android.app.Activity;
+import android.content.Context;
+import android.content.pm.ActivityInfo;
+import android.content.res.Configuration;
+import android.view.Display;
+import android.view.Surface;
+import android.view.WindowManager;
+
+/**
+ * Static methods related to device orientation.
+ */
+public class OrientationUtils {
+
+ /**
+ * Locks the device window in landscape mode.
+ */
+ public static void lockOrientationLandscape(Activity activity) {
+ activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
+ }
+
+ /**
+ * Locks the device window in portrait mode.
+ */
+ public static void lockOrientationPortrait(Activity activity) {
+ activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
+ }
+
+ /**
+ * Locks the device window in actual screen mode.
+ */
+ public static void lockOrientation(Activity activity) {
+ Display display = ((WindowManager) activity.getSystemService(Context.WINDOW_SERVICE))
+ .getDefaultDisplay();
+ int rotation = display.getRotation();
+ int tempOrientation = activity.getResources().getConfiguration().orientation;
+ int orientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
+
+ switch (tempOrientation) {
+ case Configuration.ORIENTATION_LANDSCAPE: {
+ if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_90) {
+ orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
+ } else {
+ orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
+ }
+ break;
+ }
+ case Configuration.ORIENTATION_PORTRAIT: {
+ if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_270) {
+ orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
+ } else {
+ orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
+ }
+ break;
+ }
+ }
+ activity.setRequestedOrientation(orientation);
+ }
+
+ /**
+ * Unlocks the device window in user defined screen mode.
+ */
+ public static void unlockOrientation(Activity activity) {
+ activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_USER);
+ }
+
+} \ No newline at end of file