diff --git a/app/src/main/java/com/github/dfa/diaspora_android/activity/AboutActivity.java b/app/src/main/java/com/github/dfa/diaspora_android/activity/AboutActivity.java
index 96f7e00d..acae4d9e 100644
--- a/app/src/main/java/com/github/dfa/diaspora_android/activity/AboutActivity.java
+++ b/app/src/main/java/com/github/dfa/diaspora_android/activity/AboutActivity.java
@@ -52,7 +52,6 @@ import com.github.dfa.diaspora_android.ui.theme.ThemedActivity;
import com.github.dfa.diaspora_android.ui.theme.ThemedFragment;
import com.github.dfa.diaspora_android.util.AppLog;
import com.github.dfa.diaspora_android.util.AppSettings;
-import com.github.dfa.diaspora_android.util.DiasporaUrlHelper;
import com.github.dfa.diaspora_android.util.Helpers;
import java.util.Observable;
diff --git a/app/src/main/java/com/github/dfa/diaspora_android/activity/SettingsActivity.java b/app/src/main/java/com/github/dfa/diaspora_android/activity/SettingsActivity.java
index 2e10b627..557593de 100644
--- a/app/src/main/java/com/github/dfa/diaspora_android/activity/SettingsActivity.java
+++ b/app/src/main/java/com/github/dfa/diaspora_android/activity/SettingsActivity.java
@@ -43,7 +43,7 @@ import uz.shift.colorpicker.OnColorChangedListener;
* Created by vanitas on 24.10.16.
*/
-public class SettingsActivity extends ThemedActivity {
+public class SettingsActivity extends ThemedActivity implements SharedPreferences.OnSharedPreferenceChangeListener {
//Toolbar
@BindView(R.id.settings__appbar)
@@ -68,7 +68,7 @@ public class SettingsActivity extends ThemedActivity {
SettingsActivity.this.onBackPressed();
}
});
-
+ getAppSettings().registerPrefAppPreferenceChangedListener(this);
oldProxySettings = getAppSettings().getProxySettings();
showFragment(SettingsFragmentMaster.TAG, false);
}
@@ -126,6 +126,7 @@ public class SettingsActivity extends ThemedActivity {
ProxyHandler.getInstance().updateProxySettings(this);
}
}
+ getAppSettings().unregisterPrefAppPreferenceChangedListener(this);
super.onStop();
}
@@ -150,6 +151,13 @@ public class SettingsActivity extends ThemedActivity {
return (ThemedPreferenceFragment) getFragmentManager().findFragmentById(R.id.settings__fragment_container);
}
+ @Override
+ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String s) {
+ if(s.equals(getString(R.string.pref_key__screen_rotation))) {
+ this.updateScreenRotation();
+ }
+ }
+
public static class SettingsFragmentMaster extends ThemedPreferenceFragment {
public static final String TAG = "com.github.dfa.diaspora_android.settings.SettingsFragmentMaster";
diff --git a/app/src/main/java/com/github/dfa/diaspora_android/ui/theme/ThemedActivity.java b/app/src/main/java/com/github/dfa/diaspora_android/ui/theme/ThemedActivity.java
index c01236c4..118f0604 100644
--- a/app/src/main/java/com/github/dfa/diaspora_android/ui/theme/ThemedActivity.java
+++ b/app/src/main/java/com/github/dfa/diaspora_android/ui/theme/ThemedActivity.java
@@ -20,6 +20,7 @@ package com.github.dfa.diaspora_android.ui.theme;
import android.annotation.TargetApi;
import android.app.ActivityManager;
+import android.content.pm.ActivityInfo;
import android.graphics.drawable.BitmapDrawable;
import android.os.Build;
import android.support.v7.app.AppCompatActivity;
@@ -46,6 +47,7 @@ public abstract class ThemedActivity extends AppCompatActivity {
updateStatusBarColor();
updateRecentAppColor();
applyColorToViews();
+ updateScreenRotation();
}
protected abstract void applyColorToViews();
@@ -75,4 +77,15 @@ public abstract class ThemedActivity extends AppCompatActivity {
}
}
}
+
+ protected void updateScreenRotation() {
+ String rotation = getAppSettings().getScreenRotation();
+ if (rotation.equals(getString(R.string.rotation_val_auto))) {
+ setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
+ } else if (rotation.equals(getString(R.string.rotation_val_portrait))) {
+ setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
+ } else {
+ setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
+ }
+ }
}
diff --git a/app/src/main/java/com/github/dfa/diaspora_android/util/AppSettings.java b/app/src/main/java/com/github/dfa/diaspora_android/util/AppSettings.java
index 57e651f9..f4734e63 100644
--- a/app/src/main/java/com/github/dfa/diaspora_android/util/AppSettings.java
+++ b/app/src/main/java/com/github/dfa/diaspora_android/util/AppSettings.java
@@ -402,6 +402,10 @@ public class AppSettings {
return getBoolean(prefApp, R.string.pref_key__topbar_stream_shortcut, false);
}
+ public String getScreenRotation() {
+ return getString(prefApp, R.string.pref_key__screen_rotation, "auto");
+ }
+
public void setPrimaryColorSettings(int base, int shade) {
setInt(prefApp, R.string.pref_key__primary_color_base, base);
setInt(prefApp, R.string.pref_key__primary_color_shade, shade);
@@ -437,4 +441,12 @@ public class AppSettings {
public boolean isExtendedNotificationsActivated() {
return getBoolean(prefApp, R.string.pref_key__extended_notifications, false);
}
+
+ public void registerPrefAppPreferenceChangedListener(SharedPreferences.OnSharedPreferenceChangeListener listener) {
+ prefApp.registerOnSharedPreferenceChangeListener(listener);
+ }
+
+ public void unregisterPrefAppPreferenceChangedListener(SharedPreferences.OnSharedPreferenceChangeListener listener) {
+ prefApp.unregisterOnSharedPreferenceChangeListener(listener);
+ }
}
\ No newline at end of file
diff --git a/app/src/main/res/drawable/ic_screen_rotation_black_24px.xml b/app/src/main/res/drawable/ic_screen_rotation_black_24px.xml
new file mode 100644
index 00000000..9163901e
--- /dev/null
+++ b/app/src/main/res/drawable/ic_screen_rotation_black_24px.xml
@@ -0,0 +1,18 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values/strings-preferences.xml b/app/src/main/res/values/strings-preferences.xml
index e1651112..dc4c45b8 100644
--- a/app/src/main/res/values/strings-preferences.xml
+++ b/app/src/main/res/values/strings-preferences.xml
@@ -33,6 +33,7 @@
Top toolbar loads stream
Click an empty space in the top toolbar to open the stream
+ pref_key__screen_rotation
pref_key__visibility_navslider__exit
@@ -112,6 +113,25 @@
Load images
Toggle image loading to eg. safe mobile data
+
+ Screen rotation
+ Control automatic screen rotation
+ auto
+ portrait
+ landscape
+ Automatic
+ Portrait
+ Landscape
+
+ - @string/rotation_val_auto
+ - @string/rotation_val_portrait
+ - @string/rotation_val_landscape
+
+
+ - @string/rotation_auto
+ - @string/rotation_portrait
+ - @string/rotation_landscape
+
Load Tor Preset
Load proxy settings for Tor (Orbot) HTTP Proxy
diff --git a/app/src/main/res/xml/preferences__master.xml b/app/src/main/res/xml/preferences__master.xml
index 0e149c44..70e9ec76 100644
--- a/app/src/main/res/xml/preferences__master.xml
+++ b/app/src/main/res/xml/preferences__master.xml
@@ -67,6 +67,15 @@
android:title="@string/pref_title__topbar_stream_shortcut"
android:icon="@drawable/ic_touch_app_black_24px"/>
+
+