blob: 27763f5456fdf9e12104a8d0e3dcc40d0dfc957e [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;
20import android.content.Context;
Rahul Chaturvedi799aa042015-06-01 21:26:41 -040021import android.content.Intent;
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -070022import android.os.Bundle;
Rahul Chaturvedi799aa042015-06-01 21:26:41 -040023import android.preference.Preference;
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -070024import android.preference.PreferenceFragment;
Rahul Chaturvedi799aa042015-06-01 21:26:41 -040025import android.preference.PreferenceScreen;
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -070026
27/**
Rahul Chaturvedi799aa042015-06-01 21:26:41 -040028 * Settings activity for Launcher. Currently implements the following setting: Allow rotation
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -070029 */
30public 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 Chaturvedi7fc77ca2015-05-19 18:02:16 -070046 @Override
47 public void onCreate(Bundle savedInstanceState) {
48 super.onCreate(savedInstanceState);
Rahul Chaturvedi799aa042015-06-01 21:26:41 -040049 getPreferenceManager().setSharedPreferencesMode(Context.MODE_MULTI_PROCESS);
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -070050 getPreferenceManager().setSharedPreferencesName(LauncherFiles.ROTATION_PREF_FILE);
51 addPreferencesFromResource(R.xml.launcher_preferences);
52 }
Rahul Chaturvedi799aa042015-06-01 21:26:41 -040053
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 Chaturvedi7fc77ca2015-05-19 18:02:16 -070066 }
67}