1
0
Fork 0
mirror of https://github.com/gsantner/dandelion synced 2024-11-25 13:52:08 +01:00

Merge pull request #125 from Diaspora-for-Android/rotation-option

Added option to control screen rotation (Fix #92)
This commit is contained in:
vanitasvitae 2016-11-20 15:49:46 +01:00 committed by GitHub
commit 3a4f41f758
7 changed files with 82 additions and 3 deletions

View file

@ -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.ui.theme.ThemedFragment;
import com.github.dfa.diaspora_android.util.AppLog; import com.github.dfa.diaspora_android.util.AppLog;
import com.github.dfa.diaspora_android.util.AppSettings; 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 com.github.dfa.diaspora_android.util.Helpers;
import java.util.Observable; import java.util.Observable;

View file

@ -43,7 +43,7 @@ import uz.shift.colorpicker.OnColorChangedListener;
* Created by vanitas on 24.10.16. * Created by vanitas on 24.10.16.
*/ */
public class SettingsActivity extends ThemedActivity { public class SettingsActivity extends ThemedActivity implements SharedPreferences.OnSharedPreferenceChangeListener {
//Toolbar //Toolbar
@BindView(R.id.settings__appbar) @BindView(R.id.settings__appbar)
@ -68,7 +68,7 @@ public class SettingsActivity extends ThemedActivity {
SettingsActivity.this.onBackPressed(); SettingsActivity.this.onBackPressed();
} }
}); });
getAppSettings().registerPrefAppPreferenceChangedListener(this);
oldProxySettings = getAppSettings().getProxySettings(); oldProxySettings = getAppSettings().getProxySettings();
showFragment(SettingsFragmentMaster.TAG, false); showFragment(SettingsFragmentMaster.TAG, false);
} }
@ -126,6 +126,7 @@ public class SettingsActivity extends ThemedActivity {
ProxyHandler.getInstance().updateProxySettings(this); ProxyHandler.getInstance().updateProxySettings(this);
} }
} }
getAppSettings().unregisterPrefAppPreferenceChangedListener(this);
super.onStop(); super.onStop();
} }
@ -150,6 +151,13 @@ public class SettingsActivity extends ThemedActivity {
return (ThemedPreferenceFragment) getFragmentManager().findFragmentById(R.id.settings__fragment_container); 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 class SettingsFragmentMaster extends ThemedPreferenceFragment {
public static final String TAG = "com.github.dfa.diaspora_android.settings.SettingsFragmentMaster"; public static final String TAG = "com.github.dfa.diaspora_android.settings.SettingsFragmentMaster";

View file

@ -20,6 +20,7 @@ package com.github.dfa.diaspora_android.ui.theme;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.app.ActivityManager; import android.app.ActivityManager;
import android.content.pm.ActivityInfo;
import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.BitmapDrawable;
import android.os.Build; import android.os.Build;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
@ -46,6 +47,7 @@ public abstract class ThemedActivity extends AppCompatActivity {
updateStatusBarColor(); updateStatusBarColor();
updateRecentAppColor(); updateRecentAppColor();
applyColorToViews(); applyColorToViews();
updateScreenRotation();
} }
protected abstract void applyColorToViews(); 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);
}
}
} }

View file

@ -402,6 +402,10 @@ public class AppSettings {
return getBoolean(prefApp, R.string.pref_key__topbar_stream_shortcut, false); 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) { 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_base, base);
setInt(prefApp, R.string.pref_key__primary_color_shade, shade); setInt(prefApp, R.string.pref_key__primary_color_shade, shade);
@ -437,4 +441,12 @@ public class AppSettings {
public boolean isExtendedNotificationsActivated() { public boolean isExtendedNotificationsActivated() {
return getBoolean(prefApp, R.string.pref_key__extended_notifications, false); 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);
}
} }

View file

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M0 0h24v24H0z" />
<path
android:fillColor="#000000"
android:pathData="M16.48 2.52c3.27 1.55 5.61 4.72 5.97 8.48h1.5C23.44 4.84 18.29 0 12 0l-.66 .03
3.81 3.81 1.33-1.32zm-6.25-.77c-.59-.59-1.54-.59-2.12 0L1.75 8.11c-.59 .59 -.59
1.54 0 2.12l12.02 12.02c.59 .59 1.54 .59 2.12 0l6.36-6.36c.59-.59 .59 -1.54
0-2.12L10.23 1.75zm4.6 19.44L2.81 9.17l6.36-6.36 12.02 12.02-6.36 6.36zm-7.31
.29 C4.25 19.94 1.91 16.76 1.55 13H.05C.56 19.16 5.71 24 12
24l.66-.03-3.81-3.81-1.33 1.32z" />
</vector>

View file

@ -33,6 +33,7 @@
<!-- Operability --> <!-- Operability -->
<string name="pref_title__topbar_stream_shortcut">Top toolbar loads stream</string> <string name="pref_title__topbar_stream_shortcut">Top toolbar loads stream</string>
<string name="pref_desc__topbar_stream_shortcut">Click an empty space in the top toolbar to open the stream</string> <string name="pref_desc__topbar_stream_shortcut">Click an empty space in the top toolbar to open the stream</string>
<string name="pref_key__screen_rotation" translatable="false">pref_key__screen_rotation</string>
<!-- Navigiation Slider --> <!-- Navigiation Slider -->
<string name="pref_key__visibility_nav__exit" translatable="false">pref_key__visibility_navslider__exit</string> <string name="pref_key__visibility_nav__exit" translatable="false">pref_key__visibility_navslider__exit</string>
@ -112,6 +113,25 @@
<string name="pref_title__load_images">Load images</string> <string name="pref_title__load_images">Load images</string>
<string name="pref_desc__load_images">Toggle image loading to eg. safe mobile data</string> <string name="pref_desc__load_images">Toggle image loading to eg. safe mobile data</string>
<!-- Rotate Screen -->
<string name="pref_title__screen_rotation">Screen rotation</string>
<string name="pref_desc__screen_rotation">Control automatic screen rotation</string>
<string name="rotation_val_auto" translatable="false">auto</string>
<string name="rotation_val_portrait" translatable="false">portrait</string>
<string name="rotation_val_landscape" translatable="false">landscape</string>
<string name="rotation_auto">Automatic</string>
<string name="rotation_portrait">Portrait</string>
<string name="rotation_landscape">Landscape</string>
<array name="pref_entries_values__screen_rotation" translatable="false">
<item>@string/rotation_val_auto</item>
<item>@string/rotation_val_portrait</item>
<item>@string/rotation_val_landscape</item>
</array>
<array name="pref_entries__screen_rotation" translatable="false">
<item>@string/rotation_auto</item>
<item>@string/rotation_portrait</item>
<item>@string/rotation_landscape</item>
</array>
<!-- Proxy --> <!-- Proxy -->
<string name="pref_title__http_proxy_load_tor_preset">Load Tor Preset</string> <string name="pref_title__http_proxy_load_tor_preset">Load Tor Preset</string>
<string name="pref_desc__http_proxy_load_tor_preset">Load proxy settings for Tor (Orbot) HTTP Proxy</string> <string name="pref_desc__http_proxy_load_tor_preset">Load proxy settings for Tor (Orbot) HTTP Proxy</string>

View file

@ -67,6 +67,15 @@
android:title="@string/pref_title__topbar_stream_shortcut" android:title="@string/pref_title__topbar_stream_shortcut"
android:icon="@drawable/ic_touch_app_black_24px"/> android:icon="@drawable/ic_touch_app_black_24px"/>
<ListPreference
android:defaultValue="@string/rotation_val_auto"
android:key="@string/pref_key__screen_rotation"
android:title="@string/pref_title__screen_rotation"
android:summary="@string/pref_desc__screen_rotation"
android:entries="@array/pref_entries__screen_rotation"
android:entryValues="@array/pref_entries_values__screen_rotation"
android:icon="@drawable/ic_screen_rotation_black_24px"/>
</com.github.dfa.diaspora_android.ui.theme.ThemedPreferenceCategory> </com.github.dfa.diaspora_android.ui.theme.ThemedPreferenceCategory>
<!-- Diaspora Pod Settings --> <!-- Diaspora Pod Settings -->