Refactor settings hierarchy and clump all volumes in one dialog.
Bug:2362077 Bug:2312836 Bug:2166486 Split Sound and Display into separate top-level settings. All volume settings (including Alarm volume) now in one Volume dialog. Remove some sub-texts to reduce clutter.
This commit is contained in:
177
src/com/android/settings/DisplaySettings.java
Normal file
177
src/com/android/settings/DisplaySettings.java
Normal file
@@ -0,0 +1,177 @@
|
||||
/*
|
||||
* Copyright (C) 2010 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.settings;
|
||||
|
||||
import static android.provider.Settings.System.SCREEN_OFF_TIMEOUT;
|
||||
|
||||
import com.android.settings.bluetooth.DockEventReceiver;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.media.AudioManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.IMountService;
|
||||
import android.os.RemoteException;
|
||||
import android.os.ServiceManager;
|
||||
import android.preference.CheckBoxPreference;
|
||||
import android.preference.ListPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceActivity;
|
||||
import android.preference.PreferenceGroup;
|
||||
import android.preference.PreferenceScreen;
|
||||
import android.provider.Settings;
|
||||
import android.provider.Settings.SettingNotFoundException;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.util.Log;
|
||||
import android.view.IWindowManager;
|
||||
|
||||
public class DisplaySettings extends PreferenceActivity implements
|
||||
Preference.OnPreferenceChangeListener {
|
||||
private static final String TAG = "DisplaySettings";
|
||||
|
||||
/** If there is no setting in the provider, use this. */
|
||||
private static final int FALLBACK_SCREEN_TIMEOUT_VALUE = 30000;
|
||||
|
||||
private static final String KEY_SCREEN_TIMEOUT = "screen_timeout";
|
||||
private static final String KEY_ANIMATIONS = "animations";
|
||||
private static final String KEY_ACCELEROMETER = "accelerometer";
|
||||
|
||||
private ListPreference mAnimations;
|
||||
private CheckBoxPreference mAccelerometer;
|
||||
private float[] mAnimationScales;
|
||||
|
||||
private IWindowManager mWindowManager;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
ContentResolver resolver = getContentResolver();
|
||||
mWindowManager = IWindowManager.Stub.asInterface(ServiceManager.getService("window"));
|
||||
|
||||
addPreferencesFromResource(R.xml.display_settings);
|
||||
|
||||
mAnimations = (ListPreference) findPreference(KEY_ANIMATIONS);
|
||||
mAnimations.setOnPreferenceChangeListener(this);
|
||||
mAccelerometer = (CheckBoxPreference) findPreference(KEY_ACCELEROMETER);
|
||||
mAccelerometer.setPersistent(false);
|
||||
|
||||
ListPreference screenTimeoutPreference =
|
||||
(ListPreference) findPreference(KEY_SCREEN_TIMEOUT);
|
||||
screenTimeoutPreference.setValue(String.valueOf(Settings.System.getInt(
|
||||
resolver, SCREEN_OFF_TIMEOUT, FALLBACK_SCREEN_TIMEOUT_VALUE)));
|
||||
screenTimeoutPreference.setOnPreferenceChangeListener(this);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
||||
updateState(true);
|
||||
}
|
||||
|
||||
private void updateState(boolean force) {
|
||||
int animations = 0;
|
||||
try {
|
||||
mAnimationScales = mWindowManager.getAnimationScales();
|
||||
} catch (RemoteException e) {
|
||||
}
|
||||
if (mAnimationScales != null) {
|
||||
if (mAnimationScales.length >= 1) {
|
||||
animations = ((int)(mAnimationScales[0]+.5f)) % 10;
|
||||
}
|
||||
if (mAnimationScales.length >= 2) {
|
||||
animations += (((int)(mAnimationScales[1]+.5f)) & 0x7) * 10;
|
||||
}
|
||||
}
|
||||
int idx = 0;
|
||||
int best = 0;
|
||||
CharSequence[] aents = mAnimations.getEntryValues();
|
||||
for (int i=0; i<aents.length; i++) {
|
||||
int val = Integer.parseInt(aents[i].toString());
|
||||
if (val <= animations && val > best) {
|
||||
best = val;
|
||||
idx = i;
|
||||
}
|
||||
}
|
||||
mAnimations.setValueIndex(idx);
|
||||
updateAnimationsSummary(mAnimations.getValue());
|
||||
mAccelerometer.setChecked(Settings.System.getInt(
|
||||
getContentResolver(),
|
||||
Settings.System.ACCELEROMETER_ROTATION, 0) != 0);
|
||||
}
|
||||
|
||||
private void updateAnimationsSummary(Object value) {
|
||||
CharSequence[] summaries = getResources().getTextArray(R.array.animations_summaries);
|
||||
CharSequence[] values = mAnimations.getEntryValues();
|
||||
for (int i=0; i<values.length; i++) {
|
||||
//Log.i("foo", "Comparing entry "+ values[i] + " to current "
|
||||
// + mAnimations.getValue());
|
||||
if (values[i].equals(value)) {
|
||||
mAnimations.setSummary(summaries[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
|
||||
if (preference == mAccelerometer) {
|
||||
Settings.System.putInt(getContentResolver(),
|
||||
Settings.System.ACCELEROMETER_ROTATION,
|
||||
mAccelerometer.isChecked() ? 1 : 0);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean onPreferenceChange(Preference preference, Object objValue) {
|
||||
final String key = preference.getKey();
|
||||
if (KEY_ANIMATIONS.equals(key)) {
|
||||
try {
|
||||
int value = Integer.parseInt((String) objValue);
|
||||
if (mAnimationScales.length >= 1) {
|
||||
mAnimationScales[0] = value%10;
|
||||
}
|
||||
if (mAnimationScales.length >= 2) {
|
||||
mAnimationScales[1] = (value/10)%10;
|
||||
}
|
||||
try {
|
||||
mWindowManager.setAnimationScales(mAnimationScales);
|
||||
} catch (RemoteException e) {
|
||||
}
|
||||
updateAnimationsSummary(objValue);
|
||||
} catch (NumberFormatException e) {
|
||||
Log.e(TAG, "could not persist animation setting", e);
|
||||
}
|
||||
|
||||
}
|
||||
if (KEY_SCREEN_TIMEOUT.equals(key)) {
|
||||
int value = Integer.parseInt((String) objValue);
|
||||
try {
|
||||
Settings.System.putInt(getContentResolver(),
|
||||
SCREEN_OFF_TIMEOUT, value);
|
||||
} catch (NumberFormatException e) {
|
||||
Log.e(TAG, "could not persist screen timeout setting", e);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user