mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-02-27 23:36:47 +00:00
Chaning the behavior of settings activity.
> Making all twoState prefs backed by content provider > Using the stadard intent defined in N for settings > Using SharedPrefsListener instead of LauncherProvider Change-Id: I8272f54aa780bc0436e3d0aa89096a4bd2a9194f
This commit is contained in:
@@ -85,8 +85,11 @@
|
||||
<activity
|
||||
android:name="com.android.launcher3.SettingsActivity"
|
||||
android:label="@string/settings_button_text"
|
||||
android:autoRemoveFromRecents="true"
|
||||
android:process=":settings_process">
|
||||
android:autoRemoveFromRecents="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.APPLICATION_PREFERENCES" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<!-- Intent received used to install shortcuts from other applications -->
|
||||
|
||||
@@ -43,6 +43,7 @@ import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.IntentSender;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
@@ -374,11 +375,7 @@ public class Launcher extends Activity
|
||||
}
|
||||
}
|
||||
|
||||
private Runnable mUpdateOrientationRunnable = new Runnable() {
|
||||
public void run() {
|
||||
setOrientation();
|
||||
}
|
||||
};
|
||||
private RotationPrefChangeHandler mRotationPrefChangeHandler;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@@ -479,6 +476,8 @@ public class Launcher extends Activity
|
||||
// if the user has specifically allowed rotation.
|
||||
if (!mRotationEnabled) {
|
||||
mRotationEnabled = Utilities.isAllowRotationPrefEnabled(getApplicationContext());
|
||||
mRotationPrefChangeHandler = new RotationPrefChangeHandler();
|
||||
mSharedPrefs.registerOnSharedPreferenceChangeListener(mRotationPrefChangeHandler);
|
||||
}
|
||||
|
||||
// On large interfaces, or on devices that a user has specifically enabled screen rotation,
|
||||
@@ -497,16 +496,6 @@ public class Launcher extends Activity
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSettingsChanged(String settings, boolean value) {
|
||||
if (Utilities.ALLOW_ROTATION_PREFERENCE_KEY.equals(settings)) {
|
||||
mRotationEnabled = value;
|
||||
if (!waitUntilResume(mUpdateOrientationRunnable, true)) {
|
||||
mUpdateOrientationRunnable.run();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExtractedColorsChanged() {
|
||||
loadExtractedColorsAndColorItems();
|
||||
@@ -1997,6 +1986,10 @@ public class Launcher extends Activity
|
||||
LauncherAppState.getInstance().setLauncher(null);
|
||||
}
|
||||
|
||||
if (mRotationPrefChangeHandler != null) {
|
||||
mSharedPrefs.unregisterOnSharedPreferenceChangeListener(mRotationPrefChangeHandler);
|
||||
}
|
||||
|
||||
try {
|
||||
mAppWidgetHost.stopListening();
|
||||
} catch (NullPointerException ex) {
|
||||
@@ -2744,13 +2737,10 @@ public class Launcher extends Activity
|
||||
* Event handler for a click on the settings button that appears after a long press
|
||||
* on the home screen.
|
||||
*/
|
||||
protected void onClickSettingsButton(View v) {
|
||||
private void onClickSettingsButton(View v) {
|
||||
if (LOGD) Log.d(TAG, "onClickSettingsButton");
|
||||
if (mLauncherCallbacks != null) {
|
||||
mLauncherCallbacks.onClickSettingsButton(v);
|
||||
} else {
|
||||
startActivity(new Intent(this, SettingsActivity.class));
|
||||
}
|
||||
startActivity(new Intent(Utilities.ACTION_APPLICATION_PREFERENCES)
|
||||
.setPackage(getPackageName()));
|
||||
}
|
||||
|
||||
public View.OnTouchListener getHapticFeedbackTouchListener() {
|
||||
@@ -4698,6 +4688,25 @@ public class Launcher extends Activity
|
||||
return Collections.EMPTY_LIST;
|
||||
}
|
||||
}
|
||||
|
||||
private class RotationPrefChangeHandler implements OnSharedPreferenceChangeListener, Runnable {
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(
|
||||
SharedPreferences sharedPreferences, String key) {
|
||||
if (Utilities.ALLOW_ROTATION_PREFERENCE_KEY.equals(key)) {
|
||||
mRotationEnabled = Utilities.isAllowRotationPrefEnabled(getApplicationContext());
|
||||
if (!waitUntilResume(this, true)) {
|
||||
run();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
setOrientation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
interface DebugIntents {
|
||||
|
||||
@@ -76,8 +76,6 @@ public interface LauncherCallbacks {
|
||||
public void onInteractionBegin();
|
||||
public void onInteractionEnd();
|
||||
|
||||
@Deprecated
|
||||
public void onClickSettingsButton(View v);
|
||||
@Deprecated
|
||||
public void onWorkspaceLockedChanged();
|
||||
|
||||
|
||||
@@ -280,17 +280,6 @@ public class LauncherProvider extends ContentProvider {
|
||||
case LauncherSettings.Settings.METHOD_SET_BOOLEAN: {
|
||||
final boolean value = extras.getBoolean(LauncherSettings.Settings.EXTRA_VALUE);
|
||||
Utilities.getPrefs(getContext()).edit().putBoolean(arg, value).apply();
|
||||
new MainThreadExecutor().execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
synchronized (LISTENER_LOCK) {
|
||||
if (mListener != null) {
|
||||
mListener.onSettingsChanged(arg, value);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
if (extras.getBoolean(LauncherSettings.Settings.NOTIFY_BACKUP)) {
|
||||
LauncherBackupAgentHelper.dataChanged(getContext());
|
||||
}
|
||||
|
||||
@@ -9,8 +9,6 @@ public interface LauncherProviderChangeListener {
|
||||
|
||||
public void onLauncherProviderChange();
|
||||
|
||||
public void onSettingsChanged(String settings, boolean value);
|
||||
|
||||
public void onExtractedColorsChanged();
|
||||
|
||||
public void onAppWidgetHostReset();
|
||||
|
||||
@@ -17,11 +17,13 @@
|
||||
package com.android.launcher3;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.preference.Preference;
|
||||
import android.preference.Preference.OnPreferenceChangeListener;
|
||||
import android.preference.PreferenceFragment;
|
||||
import android.preference.SwitchPreference;
|
||||
import android.preference.PreferenceScreen;
|
||||
import android.preference.TwoStatePreference;
|
||||
|
||||
/**
|
||||
* Settings activity for Launcher. Currently implements the following setting: Allow rotation
|
||||
@@ -47,19 +49,13 @@ public class SettingsActivity extends Activity {
|
||||
super.onCreate(savedInstanceState);
|
||||
addPreferencesFromResource(R.xml.launcher_preferences);
|
||||
|
||||
SwitchPreference pref = (SwitchPreference) findPreference(
|
||||
Utilities.ALLOW_ROTATION_PREFERENCE_KEY);
|
||||
pref.setPersistent(false);
|
||||
|
||||
Bundle extras = new Bundle();
|
||||
extras.putBoolean(LauncherSettings.Settings.EXTRA_DEFAULT_VALUE, false);
|
||||
Bundle value = getActivity().getContentResolver().call(
|
||||
LauncherSettings.Settings.CONTENT_URI,
|
||||
LauncherSettings.Settings.METHOD_GET_BOOLEAN,
|
||||
Utilities.ALLOW_ROTATION_PREFERENCE_KEY, extras);
|
||||
pref.setChecked(value.getBoolean(LauncherSettings.Settings.EXTRA_VALUE));
|
||||
|
||||
pref.setOnPreferenceChangeListener(this);
|
||||
PreferenceScreen screen = getPreferenceScreen();
|
||||
for (int i = screen.getPreferenceCount() - 1; i >= 0; i--) {
|
||||
Preference pref = screen.getPreference(i);
|
||||
if (pref instanceof TwoStatePreference) {
|
||||
setBooleanPrefUsingContentProvider((TwoStatePreference) pref);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -72,5 +68,30 @@ public class SettingsActivity extends Activity {
|
||||
preference.getKey(), extras);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void setBooleanPrefUsingContentProvider(final TwoStatePreference pref) {
|
||||
pref.setPersistent(false);
|
||||
pref.setEnabled(false);
|
||||
|
||||
new AsyncTask<Void, Void, Boolean>() {
|
||||
@Override
|
||||
protected Boolean doInBackground(Void... params) {
|
||||
Bundle extras = new Bundle();
|
||||
extras.putBoolean(LauncherSettings.Settings.EXTRA_DEFAULT_VALUE, false);
|
||||
Bundle value = getActivity().getContentResolver().call(
|
||||
LauncherSettings.Settings.CONTENT_URI,
|
||||
LauncherSettings.Settings.METHOD_GET_BOOLEAN,
|
||||
pref.getKey(), extras);
|
||||
return value.getBoolean(LauncherSettings.Settings.EXTRA_VALUE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Boolean aBoolean) {
|
||||
pref.setChecked(aBoolean);
|
||||
pref.setEnabled(true);
|
||||
pref.setOnPreferenceChangeListener(LauncherSettingsFragment.this);
|
||||
}
|
||||
}.execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,6 +173,10 @@ public final class Utilities {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Use Intent.ACTION_APPLICATION_PREFERENCES when N SDK is available.
|
||||
public static final String ACTION_APPLICATION_PREFERENCES
|
||||
= "android.intent.action.APPLICATION_PREFERENCES";
|
||||
|
||||
public static Bitmap createIconBitmap(Cursor c, int iconIndex, Context context) {
|
||||
byte[] data = c.getBlob(iconIndex);
|
||||
try {
|
||||
|
||||
@@ -126,10 +126,6 @@ public class LauncherExtension extends Launcher {
|
||||
public void bindAllApplications(ArrayList<AppInfo> apps) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClickSettingsButton(View v) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWorkspaceLockedChanged() {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user