Rahul Chaturvedi | 7fc77ca | 2015-05-19 18:02:16 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.launcher3; |
| 18 | |
| 19 | import android.app.Activity; |
Rahul Chaturvedi | 7fc77ca | 2015-05-19 18:02:16 -0700 | [diff] [blame] | 20 | import android.os.Bundle; |
Rahul Chaturvedi | 799aa04 | 2015-06-01 21:26:41 -0400 | [diff] [blame] | 21 | import android.preference.Preference; |
Sunny Goyal | 7779d62 | 2015-06-11 16:18:39 -0700 | [diff] [blame^] | 22 | import android.preference.Preference.OnPreferenceChangeListener; |
Rahul Chaturvedi | 7fc77ca | 2015-05-19 18:02:16 -0700 | [diff] [blame] | 23 | import android.preference.PreferenceFragment; |
Sunny Goyal | 7779d62 | 2015-06-11 16:18:39 -0700 | [diff] [blame^] | 24 | import android.preference.SwitchPreference; |
Rahul Chaturvedi | 7fc77ca | 2015-05-19 18:02:16 -0700 | [diff] [blame] | 25 | |
| 26 | /** |
Rahul Chaturvedi | 799aa04 | 2015-06-01 21:26:41 -0400 | [diff] [blame] | 27 | * Settings activity for Launcher. Currently implements the following setting: Allow rotation |
Rahul Chaturvedi | 7fc77ca | 2015-05-19 18:02:16 -0700 | [diff] [blame] | 28 | */ |
| 29 | public class SettingsActivity extends Activity { |
| 30 | @Override |
| 31 | protected void onCreate(Bundle savedInstanceState) { |
| 32 | super.onCreate(savedInstanceState); |
| 33 | |
| 34 | // Display the fragment as the main content. |
| 35 | getFragmentManager().beginTransaction() |
| 36 | .replace(android.R.id.content, new LauncherSettingsFragment()) |
| 37 | .commit(); |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * This fragment shows the launcher preferences. |
| 42 | */ |
Sunny Goyal | 7779d62 | 2015-06-11 16:18:39 -0700 | [diff] [blame^] | 43 | public static class LauncherSettingsFragment extends PreferenceFragment |
| 44 | implements OnPreferenceChangeListener { |
Rahul Chaturvedi | 7fc77ca | 2015-05-19 18:02:16 -0700 | [diff] [blame] | 45 | @Override |
| 46 | public void onCreate(Bundle savedInstanceState) { |
| 47 | super.onCreate(savedInstanceState); |
Rahul Chaturvedi | 7fc77ca | 2015-05-19 18:02:16 -0700 | [diff] [blame] | 48 | addPreferencesFromResource(R.xml.launcher_preferences); |
Sunny Goyal | 7779d62 | 2015-06-11 16:18:39 -0700 | [diff] [blame^] | 49 | |
| 50 | SwitchPreference pref = (SwitchPreference) findPreference( |
| 51 | Utilities.ALLOW_ROTATION_PREFERENCE_KEY); |
| 52 | pref.setPersistent(false); |
| 53 | |
| 54 | Bundle extras = new Bundle(); |
| 55 | extras.putBoolean(LauncherSettings.Settings.EXTRA_DEFAULT_VALUE, false); |
| 56 | Bundle value = getActivity().getContentResolver().call( |
| 57 | LauncherSettings.Settings.CONTENT_URI, |
| 58 | LauncherSettings.Settings.METHOD_GET_BOOLEAN, |
| 59 | Utilities.ALLOW_ROTATION_PREFERENCE_KEY, extras); |
| 60 | pref.setChecked(value.getBoolean(LauncherSettings.Settings.EXTRA_VALUE)); |
| 61 | |
| 62 | pref.setOnPreferenceChangeListener(this); |
Rahul Chaturvedi | 7fc77ca | 2015-05-19 18:02:16 -0700 | [diff] [blame] | 63 | } |
Rahul Chaturvedi | 799aa04 | 2015-06-01 21:26:41 -0400 | [diff] [blame] | 64 | |
| 65 | @Override |
Sunny Goyal | 7779d62 | 2015-06-11 16:18:39 -0700 | [diff] [blame^] | 66 | public boolean onPreferenceChange(Preference preference, Object newValue) { |
| 67 | Bundle extras = new Bundle(); |
| 68 | extras.putBoolean(LauncherSettings.Settings.EXTRA_VALUE, (Boolean) newValue); |
| 69 | getActivity().getContentResolver().call( |
| 70 | LauncherSettings.Settings.CONTENT_URI, |
| 71 | LauncherSettings.Settings.METHOD_SET_BOOLEAN, |
| 72 | preference.getKey(), extras); |
Rahul Chaturvedi | 799aa04 | 2015-06-01 21:26:41 -0400 | [diff] [blame] | 73 | return true; |
| 74 | } |
Rahul Chaturvedi | 7fc77ca | 2015-05-19 18:02:16 -0700 | [diff] [blame] | 75 | } |
| 76 | } |