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
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index a58cddd..d2d1d02 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -43,6 +43,7 @@
 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 @@
         }
     }
 
-    private Runnable mUpdateOrientationRunnable = new Runnable() {
-        public void run() {
-            setOrientation();
-        }
-    };
+    private RotationPrefChangeHandler mRotationPrefChangeHandler;
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
@@ -479,6 +476,8 @@
         // 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,
@@ -498,16 +497,6 @@
     }
 
     @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 @@
             LauncherAppState.getInstance().setLauncher(null);
         }
 
+        if (mRotationPrefChangeHandler != null) {
+            mSharedPrefs.unregisterOnSharedPreferenceChangeListener(mRotationPrefChangeHandler);
+        }
+
         try {
             mAppWidgetHost.stopListening();
         } catch (NullPointerException ex) {
@@ -2744,13 +2737,10 @@
      * 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 @@
             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 {