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; |
| 20 | import android.content.Context; |
Rahul Chaturvedi | 799aa04 | 2015-06-01 21:26:41 -0400 | [diff] [blame^] | 21 | import android.content.Intent; |
Rahul Chaturvedi | 7fc77ca | 2015-05-19 18:02:16 -0700 | [diff] [blame] | 22 | import android.os.Bundle; |
Rahul Chaturvedi | 799aa04 | 2015-06-01 21:26:41 -0400 | [diff] [blame^] | 23 | import android.preference.Preference; |
Rahul Chaturvedi | 7fc77ca | 2015-05-19 18:02:16 -0700 | [diff] [blame] | 24 | import android.preference.PreferenceFragment; |
Rahul Chaturvedi | 799aa04 | 2015-06-01 21:26:41 -0400 | [diff] [blame^] | 25 | import android.preference.PreferenceScreen; |
Rahul Chaturvedi | 7fc77ca | 2015-05-19 18:02:16 -0700 | [diff] [blame] | 26 | |
| 27 | /** |
Rahul Chaturvedi | 799aa04 | 2015-06-01 21:26:41 -0400 | [diff] [blame^] | 28 | * Settings activity for Launcher. Currently implements the following setting: Allow rotation |
Rahul Chaturvedi | 7fc77ca | 2015-05-19 18:02:16 -0700 | [diff] [blame] | 29 | */ |
| 30 | public class SettingsActivity extends Activity { |
| 31 | @Override |
| 32 | protected void onCreate(Bundle savedInstanceState) { |
| 33 | super.onCreate(savedInstanceState); |
| 34 | |
| 35 | // Display the fragment as the main content. |
| 36 | getFragmentManager().beginTransaction() |
| 37 | .replace(android.R.id.content, new LauncherSettingsFragment()) |
| 38 | .commit(); |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * This fragment shows the launcher preferences. |
| 43 | */ |
| 44 | @SuppressWarnings("WeakerAccess") |
| 45 | public static class LauncherSettingsFragment extends PreferenceFragment { |
Rahul Chaturvedi | 7fc77ca | 2015-05-19 18:02:16 -0700 | [diff] [blame] | 46 | @Override |
| 47 | public void onCreate(Bundle savedInstanceState) { |
| 48 | super.onCreate(savedInstanceState); |
Rahul Chaturvedi | 799aa04 | 2015-06-01 21:26:41 -0400 | [diff] [blame^] | 49 | getPreferenceManager().setSharedPreferencesMode(Context.MODE_MULTI_PROCESS); |
Rahul Chaturvedi | 7fc77ca | 2015-05-19 18:02:16 -0700 | [diff] [blame] | 50 | getPreferenceManager().setSharedPreferencesName(LauncherFiles.ROTATION_PREF_FILE); |
| 51 | addPreferencesFromResource(R.xml.launcher_preferences); |
| 52 | } |
Rahul Chaturvedi | 799aa04 | 2015-06-01 21:26:41 -0400 | [diff] [blame^] | 53 | |
| 54 | @Override |
| 55 | public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, |
| 56 | Preference preference) { |
| 57 | boolean allowRotation = getPreferenceManager().getSharedPreferences().getBoolean( |
| 58 | Utilities.ALLOW_ROTATION_PREFERENCE_KEY, false); |
| 59 | Intent rotationSetting = new Intent(Utilities.SCREEN_ROTATION_SETTING_INTENT); |
| 60 | String launchBroadcastPermission = getResources().getString( |
| 61 | R.string.receive_update_orientation_broadcasts_permission); |
| 62 | rotationSetting.putExtra(Utilities.SCREEN_ROTATION_SETTING_EXTRA, allowRotation); |
| 63 | getActivity().sendBroadcast(rotationSetting, launchBroadcastPermission); |
| 64 | return true; |
| 65 | } |
Rahul Chaturvedi | 7fc77ca | 2015-05-19 18:02:16 -0700 | [diff] [blame] | 66 | } |
| 67 | } |