Use a broadcast receiver instead of a settings observer.

Settings observer doesn't work if a setting is modified in another
process, hence we instead register a receiver which listens for a signal
from the settings process that the rotation preference has changed.

Change-Id: I570e3c67bb64a32347e84ca00a8ac31d9010eac3
This commit is contained in:
Rahul Chaturvedi
2015-06-01 21:26:41 -04:00
parent 091f0ffd92
commit 799aa04f2f
5 changed files with 67 additions and 29 deletions

View File

@@ -18,12 +18,14 @@ package com.android.launcher3;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.preference.PreferenceScreen;
/**
* Settings activity for Launcher. Currently implements the following setting:
* LockToPortrait
* Settings activity for Launcher. Currently implements the following setting: Allow rotation
*/
public class SettingsActivity extends Activity {
@Override
@@ -41,13 +43,25 @@ public class SettingsActivity extends Activity {
*/
@SuppressWarnings("WeakerAccess")
public static class LauncherSettingsFragment extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getPreferenceManager().setSharedPreferencesMode(Context.MODE_PRIVATE);
getPreferenceManager().setSharedPreferencesMode(Context.MODE_MULTI_PROCESS);
getPreferenceManager().setSharedPreferencesName(LauncherFiles.ROTATION_PREF_FILE);
addPreferencesFromResource(R.xml.launcher_preferences);
}
@Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen,
Preference preference) {
boolean allowRotation = getPreferenceManager().getSharedPreferences().getBoolean(
Utilities.ALLOW_ROTATION_PREFERENCE_KEY, false);
Intent rotationSetting = new Intent(Utilities.SCREEN_ROTATION_SETTING_INTENT);
String launchBroadcastPermission = getResources().getString(
R.string.receive_update_orientation_broadcasts_permission);
rotationSetting.putExtra(Utilities.SCREEN_ROTATION_SETTING_EXTRA, allowRotation);
getActivity().sendBroadcast(rotationSetting, launchBroadcastPermission);
return true;
}
}
}