1
0
Fork 0
mirror of https://github.com/gsantner/dandelion synced 2025-09-10 10:49:42 +02: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.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;

View file

@ -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";

View file

@ -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);
}
}
}

View file

@ -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);
}
}