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; 20 import android.os.Bundle; 21 import android.preference.Preference; 22 import android.preference.Preference.OnPreferenceChangeListener; 23 import android.preference.PreferenceFragment; 24 import android.preference.SwitchPreference; 25 26 /** 27 * Settings activity for Launcher. Currently implements the following setting: Allow rotation 28 */ 29 public class SettingsActivity extends Activity { 30 @Override onCreate(Bundle savedInstanceState)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 */ 43 public static class LauncherSettingsFragment extends PreferenceFragment 44 implements OnPreferenceChangeListener { 45 @Override onCreate(Bundle savedInstanceState)46 public void onCreate(Bundle savedInstanceState) { 47 super.onCreate(savedInstanceState); 48 addPreferencesFromResource(R.xml.launcher_preferences); 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); 63 } 64 65 @Override onPreferenceChange(Preference preference, Object newValue)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); 73 return true; 74 } 75 } 76 } 77