From b62f8d32b7fdf6b7930083faeec7e8d81f5f9417 Mon Sep 17 00:00:00 2001 From: vanitasvitae Date: Sat, 12 Nov 2016 15:36:56 +0100 Subject: [PATCH 1/2] Added option to control screen rotation --- .../activity/AboutActivity.java | 1 - .../activity/SettingsActivity.java | 12 +++++++++-- .../ui/theme/ThemedActivity.java | 13 ++++++++++++ .../diaspora_android/util/AppSettings.java | 12 +++++++++++ .../ic_screen_rotation_black_24px.xml | 18 +++++++++++++++++ .../main/res/values/strings-preferences.xml | 20 +++++++++++++++++++ app/src/main/res/xml/preferences__master.xml | 9 +++++++++ 7 files changed, 82 insertions(+), 3 deletions(-) create mode 100644 app/src/main/res/drawable/ic_screen_rotation_black_24px.xml 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..37d84334 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_PORTRAIT); + } else { + setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_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"/> + + From 8ede0ea304f80236fc04a67fe3d1a8a73da61dbe Mon Sep 17 00:00:00 2001 From: vanitasvitae Date: Sun, 20 Nov 2016 15:49:01 +0100 Subject: [PATCH 2/2] Fixed rotation --- .../github/dfa/diaspora_android/ui/theme/ThemedActivity.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 37d84334..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 @@ -83,9 +83,9 @@ public abstract class ThemedActivity extends AppCompatActivity { 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_PORTRAIT); + setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT); } else { - setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); + setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE); } } }