2015-05-19 18:02:16 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2015 The Android Open Source Project
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package com.android.launcher3;
|
|
|
|
|
|
|
|
|
|
import android.app.Activity;
|
2016-05-12 15:36:20 -07:00
|
|
|
import android.content.ContentResolver;
|
|
|
|
|
import android.database.ContentObserver;
|
2015-05-19 18:02:16 -07:00
|
|
|
import android.os.Bundle;
|
2016-05-12 15:36:20 -07:00
|
|
|
import android.os.Handler;
|
2017-03-31 20:09:34 -07:00
|
|
|
import android.preference.ListPreference;
|
2015-06-01 21:26:41 -04:00
|
|
|
import android.preference.Preference;
|
2015-05-19 18:02:16 -07:00
|
|
|
import android.preference.PreferenceFragment;
|
2016-05-12 15:36:20 -07:00
|
|
|
import android.provider.Settings;
|
|
|
|
|
import android.provider.Settings.System;
|
2017-03-08 14:25:09 -08:00
|
|
|
import android.support.v4.os.BuildCompat;
|
2015-05-19 18:02:16 -07:00
|
|
|
|
2017-03-31 20:09:34 -07:00
|
|
|
import com.android.launcher3.graphics.IconShapeOverride;
|
|
|
|
|
|
2015-05-19 18:02:16 -07:00
|
|
|
/**
|
2015-06-01 21:26:41 -04:00
|
|
|
* Settings activity for Launcher. Currently implements the following setting: Allow rotation
|
2015-05-19 18:02:16 -07:00
|
|
|
*/
|
|
|
|
|
public class SettingsActivity extends Activity {
|
|
|
|
|
@Override
|
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
|
|
|
|
|
// Display the fragment as the main content.
|
|
|
|
|
getFragmentManager().beginTransaction()
|
|
|
|
|
.replace(android.R.id.content, new LauncherSettingsFragment())
|
|
|
|
|
.commit();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This fragment shows the launcher preferences.
|
|
|
|
|
*/
|
2016-05-12 15:36:20 -07:00
|
|
|
public static class LauncherSettingsFragment extends PreferenceFragment {
|
|
|
|
|
|
|
|
|
|
private SystemDisplayRotationLockObserver mRotationLockObserver;
|
|
|
|
|
|
2015-05-19 18:02:16 -07:00
|
|
|
@Override
|
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
super.onCreate(savedInstanceState);
|
2016-05-12 15:36:20 -07:00
|
|
|
getPreferenceManager().setSharedPreferencesName(LauncherFiles.SHARED_PREFERENCES_KEY);
|
2015-05-19 18:02:16 -07:00
|
|
|
addPreferencesFromResource(R.xml.launcher_preferences);
|
2015-06-11 16:18:39 -07:00
|
|
|
|
2016-05-12 15:36:20 -07:00
|
|
|
// Setup allow rotation preference
|
|
|
|
|
Preference rotationPref = findPreference(Utilities.ALLOW_ROTATION_PREFERENCE_KEY);
|
|
|
|
|
if (getResources().getBoolean(R.bool.allow_rotation)) {
|
|
|
|
|
// Launcher supports rotation by default. No need to show this setting.
|
|
|
|
|
getPreferenceScreen().removePreference(rotationPref);
|
|
|
|
|
} else {
|
2016-06-08 12:00:02 -07:00
|
|
|
ContentResolver resolver = getActivity().getContentResolver();
|
2016-05-12 15:36:20 -07:00
|
|
|
mRotationLockObserver = new SystemDisplayRotationLockObserver(rotationPref, resolver);
|
|
|
|
|
|
|
|
|
|
// Register a content observer to listen for system setting changes while
|
|
|
|
|
// this UI is active.
|
|
|
|
|
resolver.registerContentObserver(
|
|
|
|
|
Settings.System.getUriFor(System.ACCELEROMETER_ROTATION),
|
|
|
|
|
false, mRotationLockObserver);
|
|
|
|
|
|
|
|
|
|
// Initialize the UI once
|
|
|
|
|
mRotationLockObserver.onChange(true);
|
2016-06-08 12:00:02 -07:00
|
|
|
rotationPref.setDefaultValue(Utilities.getAllowRotationDefaultValue(getActivity()));
|
2016-05-02 10:54:12 -07:00
|
|
|
}
|
2017-03-08 14:25:09 -08:00
|
|
|
|
|
|
|
|
if (!BuildCompat.isAtLeastO()) {
|
|
|
|
|
getPreferenceScreen().removePreference(
|
|
|
|
|
findPreference(SessionCommitReceiver.ADD_ICON_PREFERENCE_KEY));
|
|
|
|
|
}
|
2017-03-31 20:09:34 -07:00
|
|
|
|
|
|
|
|
Preference iconShapeOverride = findPreference(IconShapeOverride.KEY_PREFERENCE);
|
|
|
|
|
if (iconShapeOverride != null) {
|
|
|
|
|
if (IconShapeOverride.isSupported(getActivity())) {
|
|
|
|
|
IconShapeOverride.handlePreferenceUi((ListPreference) iconShapeOverride);
|
|
|
|
|
} else {
|
|
|
|
|
getPreferenceScreen().removePreference(iconShapeOverride);
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-05-19 18:02:16 -07:00
|
|
|
}
|
2015-06-01 21:26:41 -04:00
|
|
|
|
|
|
|
|
@Override
|
2016-05-12 15:36:20 -07:00
|
|
|
public void onDestroy() {
|
|
|
|
|
if (mRotationLockObserver != null) {
|
2016-06-08 12:00:02 -07:00
|
|
|
getActivity().getContentResolver().unregisterContentObserver(mRotationLockObserver);
|
2016-05-12 15:36:20 -07:00
|
|
|
mRotationLockObserver = null;
|
|
|
|
|
}
|
|
|
|
|
super.onDestroy();
|
2015-06-01 21:26:41 -04:00
|
|
|
}
|
2016-05-12 15:36:20 -07:00
|
|
|
}
|
2016-05-02 10:54:12 -07:00
|
|
|
|
2016-05-12 15:36:20 -07:00
|
|
|
/**
|
|
|
|
|
* Content observer which listens for system auto-rotate setting changes, and enables/disables
|
|
|
|
|
* the launcher rotation setting accordingly.
|
|
|
|
|
*/
|
|
|
|
|
private static class SystemDisplayRotationLockObserver extends ContentObserver {
|
2016-05-02 10:54:12 -07:00
|
|
|
|
2016-05-12 15:36:20 -07:00
|
|
|
private final Preference mRotationPref;
|
|
|
|
|
private final ContentResolver mResolver;
|
2016-05-02 10:54:12 -07:00
|
|
|
|
2016-05-12 15:36:20 -07:00
|
|
|
public SystemDisplayRotationLockObserver(
|
|
|
|
|
Preference rotationPref, ContentResolver resolver) {
|
|
|
|
|
super(new Handler());
|
|
|
|
|
mRotationPref = rotationPref;
|
|
|
|
|
mResolver = resolver;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onChange(boolean selfChange) {
|
|
|
|
|
boolean enabled = Settings.System.getInt(mResolver,
|
|
|
|
|
Settings.System.ACCELEROMETER_ROTATION, 1) == 1;
|
|
|
|
|
mRotationPref.setEnabled(enabled);
|
|
|
|
|
mRotationPref.setSummary(enabled
|
|
|
|
|
? R.string.allow_rotation_desc : R.string.allow_rotation_blocked_desc);
|
2016-05-02 10:54:12 -07:00
|
|
|
}
|
2015-05-19 18:02:16 -07:00
|
|
|
}
|
|
|
|
|
}
|