blob: dab71c8627ccf8e6e51ec0aaec3db4f450e79da9 [file] [log] [blame]
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -07001/*
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
17package com.android.launcher3;
18
19import android.app.Activity;
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -070020import android.os.Bundle;
Rahul Chaturvedi799aa042015-06-01 21:26:41 -040021import android.preference.Preference;
Sunny Goyal7779d622015-06-11 16:18:39 -070022import android.preference.Preference.OnPreferenceChangeListener;
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -070023import android.preference.PreferenceFragment;
Sunny Goyal7779d622015-06-11 16:18:39 -070024import android.preference.SwitchPreference;
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -070025
26/**
Rahul Chaturvedi799aa042015-06-01 21:26:41 -040027 * Settings activity for Launcher. Currently implements the following setting: Allow rotation
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -070028 */
29public 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 Goyal7779d622015-06-11 16:18:39 -070043 public static class LauncherSettingsFragment extends PreferenceFragment
44 implements OnPreferenceChangeListener {
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -070045 @Override
46 public void onCreate(Bundle savedInstanceState) {
47 super.onCreate(savedInstanceState);
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -070048 addPreferencesFromResource(R.xml.launcher_preferences);
Sunny Goyal7779d622015-06-11 16:18:39 -070049
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 Chaturvedi7fc77ca2015-05-19 18:02:16 -070063 }
Rahul Chaturvedi799aa042015-06-01 21:26:41 -040064
65 @Override
Sunny Goyal7779d622015-06-11 16:18:39 -070066 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 Chaturvedi799aa042015-06-01 21:26:41 -040073 return true;
74 }
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -070075 }
76}