Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 745bad9d authored by Sunny Goyal's avatar Sunny Goyal
Browse files

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
parent f8a2ba27
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -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 -->
+30 −21
Original line number Diff line number Diff line
@@ -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 {
+0 −2
Original line number Diff line number Diff line
@@ -76,8 +76,6 @@ public interface LauncherCallbacks {
    public void onInteractionBegin();
    public void onInteractionEnd();

    @Deprecated
    public void onClickSettingsButton(View v);
    @Deprecated
    public void onWorkspaceLockedChanged();

+0 −11
Original line number Diff line number Diff line
@@ -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());
                }
+0 −2
Original line number Diff line number Diff line
@@ -9,8 +9,6 @@ public interface LauncherProviderChangeListener {

    public void onLauncherProviderChange();

    public void onSettingsChanged(String settings, boolean value);

    public void onExtractedColorsChanged();

    public void onAppWidgetHostReset();
Loading