diff options
author | Steve Kondik <shade@chemlab.org> | 2014-05-01 22:43:12 -0700 |
---|---|---|
committer | Michael Bestas <mikeioannina@gmail.com> | 2015-12-28 16:28:28 +0200 |
commit | 87ab41314d6211151d39b2cdec3ba87826037515 (patch) | |
tree | 19a60c63e89096b9976fec88cd83b897c51d831c | |
parent | fcb4673ddb3d34e0ad7217c1bec0630149e59564 (diff) | |
download | packages_apps_Settings-87ab41314d6211151d39b2cdec3ba87826037515.zip packages_apps_Settings-87ab41314d6211151d39b2cdec3ba87826037515.tar.gz packages_apps_Settings-87ab41314d6211151d39b2cdec3ba87826037515.tar.bz2 |
settings: Animation scale seekbars
* Use a seekbar preference to allow setting arbitrary animation scale values
Change-Id: I4ceaf0dc74e6e044e36cf3652bfc1efb33890380
-rw-r--r-- | res/layout/preference_dialog_animation_scale.xml | 48 | ||||
-rw-r--r-- | res/xml/development_prefs.xml | 21 | ||||
-rw-r--r-- | src/com/android/settings/AnimationScalePreference.java | 94 | ||||
-rw-r--r-- | src/com/android/settings/DevelopmentSettings.java | 51 |
4 files changed, 182 insertions, 32 deletions
diff --git a/res/layout/preference_dialog_animation_scale.xml b/res/layout/preference_dialog_animation_scale.xml new file mode 100644 index 0000000..bd1d3ef --- /dev/null +++ b/res/layout/preference_dialog_animation_scale.xml @@ -0,0 +1,48 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2014 The CyanogenMod 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. +--> + +<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:settings="http://schemas.android.com/apk/res/com.android.settings" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:padding="12dp"> + + <!-- Static height enough to accommodate the text views in their biggest possible size, + without having the dialog resize itself at any point. --> + <LinearLayout android:id="@+id/container" + android:orientation="vertical" + android:layout_width="match_parent" + android:layout_height="64dp" + android:gravity="center_horizontal|center_vertical"> + + <TextView android:id="@+id/scale" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:textAppearance="?android:textAppearanceLarge" /> + + </LinearLayout> + + <com.android.settings.IntervalSeekBar android:id="@+id/scale_seekbar" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:padding="8dp" + android:layout_below="@+id/container" + settings:min="0" + settings:max="10" + settings:defaultValue="1.0" + settings:digits="1" /> + +</RelativeLayout> diff --git a/res/xml/development_prefs.xml b/res/xml/development_prefs.xml index 59db17f..e74a921 100644 --- a/res/xml/development_prefs.xml +++ b/res/xml/development_prefs.xml @@ -256,26 +256,23 @@ android:title="@string/force_rtl_layout_all_locales" android:summary="@string/force_rtl_layout_all_locales_summary"/> - <ListPreference + <com.android.settings.AnimationScalePreference android:key="window_animation_scale" android:title="@string/window_animation_scale_title" - android:persistent="false" - android:entries="@array/window_animation_scale_entries" - android:entryValues="@array/window_animation_scale_values" /> + android:dialogTitle="@string/window_animation_scale_title" + android:persistent="false" /> - <ListPreference + <com.android.settings.AnimationScalePreference android:key="transition_animation_scale" android:title="@string/transition_animation_scale_title" - android:persistent="false" - android:entries="@array/transition_animation_scale_entries" - android:entryValues="@array/transition_animation_scale_values" /> + android:dialogTitle="@string/transition_animation_scale_title" + android:persistent="false" /> - <ListPreference + <com.android.settings.AnimationScalePreference android:key="animator_duration_scale" android:title="@string/animator_duration_scale_title" - android:persistent="false" - android:entries="@array/animator_duration_scale_entries" - android:entryValues="@array/animator_duration_scale_values" /> + android:dialogTitle="@string/animator_duration_scale_title" + android:persistent="false" /> <ListPreference android:key="overlay_display_devices" diff --git a/src/com/android/settings/AnimationScalePreference.java b/src/com/android/settings/AnimationScalePreference.java new file mode 100644 index 0000000..d1c5877 --- /dev/null +++ b/src/com/android/settings/AnimationScalePreference.java @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2014 The CyanogenMod 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 android.content.Context; +import android.preference.DialogPreference; +import android.util.AttributeSet; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.SeekBar; +import android.widget.TextView; + +public class AnimationScalePreference extends DialogPreference + implements SeekBar.OnSeekBarChangeListener { + + private TextView mScaleText; + private IntervalSeekBar mSeekBar; + + private float mScale = 1.0f; + + public AnimationScalePreference(Context context, AttributeSet attrs) { + super(context, attrs); + + setPositiveButtonText(android.R.string.ok); + setNegativeButtonText(android.R.string.cancel); + + setDialogLayoutResource(R.layout.preference_dialog_fontsize); + } + + @Override + protected View onCreateDialogView() { + LayoutInflater inflater = + (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); + View view = inflater.inflate(R.layout.preference_dialog_animation_scale, null); + + mScaleText = (TextView) view.findViewById(R.id.scale); + mScaleText.setText(String.valueOf(mScale) + "x"); + + mSeekBar = (IntervalSeekBar) view.findViewById(R.id.scale_seekbar); + mSeekBar.setProgressFloat(mScale); + mSeekBar.setOnSeekBarChangeListener(this); + + return view; + } + + public void setScale(float scale) { + mScale = scale; + setSummary(String.valueOf(scale) + "x"); + } + + @Override + protected void onDialogClosed(boolean positiveResult) { + if (positiveResult) { + callChangeListener(mSeekBar.getProgressFloat()); + } + } + + @Override + protected void onClick() { + // Ignore this until an explicit call to click() + } + + public void click() { + super.onClick(); + } + + @Override + public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { + mScaleText.setText(String.valueOf(mSeekBar.getProgressFloat()) + "x"); + } + + // Not used + @Override + public void onStartTrackingTouch(SeekBar seekBar) { + } + + @Override + public void onStopTrackingTouch(SeekBar seekBar) { + } +} diff --git a/src/com/android/settings/DevelopmentSettings.java b/src/com/android/settings/DevelopmentSettings.java index 24fe2bb..b6c57b3 100644 --- a/src/com/android/settings/DevelopmentSettings.java +++ b/src/com/android/settings/DevelopmentSettings.java @@ -60,6 +60,7 @@ import android.os.UserManager; import android.preference.ListPreference; import android.preference.Preference; import android.preference.Preference.OnPreferenceChangeListener; +import android.preference.Preference.OnPreferenceClickListener; import android.preference.PreferenceGroup; import android.preference.PreferenceScreen; import android.preference.SwitchPreference; @@ -93,7 +94,8 @@ import java.util.List; */ public class DevelopmentSettings extends SettingsPreferenceFragment implements DialogInterface.OnClickListener, DialogInterface.OnDismissListener, - OnPreferenceChangeListener, SwitchBar.OnSwitchChangeListener, Indexable { + OnPreferenceChangeListener, SwitchBar.OnSwitchChangeListener, Indexable, + OnPreferenceClickListener { private static final String TAG = "DevelopmentSettings"; /** @@ -262,9 +264,9 @@ public class DevelopmentSettings extends SettingsPreferenceFragment private ListPreference mUsbConfiguration; private ListPreference mTrackFrameTime; private ListPreference mShowNonRectClip; - private ListPreference mWindowAnimationScale; - private ListPreference mTransitionAnimationScale; - private ListPreference mAnimatorDurationScale; + private AnimationScalePreference mWindowAnimationScale; + private AnimationScalePreference mTransitionAnimationScale; + private AnimationScalePreference mAnimatorDurationScale; private ListPreference mOverlayDisplayDevices; private ListPreference mOpenGLTraces; @@ -420,9 +422,9 @@ public class DevelopmentSettings extends SettingsPreferenceFragment mLogdSize = addListPreference(SELECT_LOGD_SIZE_KEY); mUsbConfiguration = addListPreference(USB_CONFIGURATION_KEY); - mWindowAnimationScale = addListPreference(WINDOW_ANIMATION_SCALE_KEY); - mTransitionAnimationScale = addListPreference(TRANSITION_ANIMATION_SCALE_KEY); - mAnimatorDurationScale = addListPreference(ANIMATOR_DURATION_SCALE_KEY); + mWindowAnimationScale = findAndInitAnimationScalePreference(WINDOW_ANIMATION_SCALE_KEY); + mTransitionAnimationScale = findAndInitAnimationScalePreference(TRANSITION_ANIMATION_SCALE_KEY); + mAnimatorDurationScale = findAndInitAnimationScalePreference(ANIMATOR_DURATION_SCALE_KEY); mOverlayDisplayDevices = addListPreference(OVERLAY_DISPLAY_DEVICES_KEY); mEnableMultiWindow = findAndInitSwitchPref(ENABLE_MULTI_WINDOW_KEY); if (!showEnableMultiWindowPreference()) { @@ -494,6 +496,14 @@ public class DevelopmentSettings extends SettingsPreferenceFragment } } + private AnimationScalePreference findAndInitAnimationScalePreference(String key) { + AnimationScalePreference pref = (AnimationScalePreference) findPreference(key); + pref.setOnPreferenceChangeListener(this); + pref.setOnPreferenceClickListener(this); + mAllPrefs.add(pref); + return pref; + } + private SwitchPreference findAndInitSwitchPref(String key) { SwitchPreference pref = (SwitchPreference) findPreference(key); if (pref == null) { @@ -1595,23 +1605,13 @@ public class DevelopmentSettings extends SettingsPreferenceFragment getActivity().getContentResolver(), Settings.Global.ALWAYS_FINISH_ACTIVITIES, 0) != 0); } - private void updateAnimationScaleValue(int which, ListPreference pref) { + private void updateAnimationScaleValue(int which, AnimationScalePreference pref) { try { float scale = mWindowManager.getAnimationScale(which); if (scale != 1) { mHaveDebugSettings = true; } - CharSequence[] values = pref.getEntryValues(); - for (int i=0; i<values.length; i++) { - float val = Float.parseFloat(values[i].toString()); - if (scale <= val) { - pref.setValueIndex(i); - pref.setSummary(pref.getEntries()[i]); - return; - } - } - pref.setValueIndex(values.length-1); - pref.setSummary(pref.getEntries()[0]); + pref.setScale(scale); } catch (RemoteException e) { } } @@ -1622,7 +1622,8 @@ public class DevelopmentSettings extends SettingsPreferenceFragment updateAnimationScaleValue(2, mAnimatorDurationScale); } - private void writeAnimationScaleOption(int which, ListPreference pref, Object newValue) { + private void writeAnimationScaleOption(int which, AnimationScalePreference pref, + Object newValue) { try { float scale = newValue != null ? Float.parseFloat(newValue.toString()) : 1; mWindowManager.setAnimationScale(which, scale); @@ -1837,6 +1838,16 @@ public class DevelopmentSettings extends SettingsPreferenceFragment } @Override + public boolean onPreferenceClick(Preference preference) { + if (preference == mWindowAnimationScale || + preference == mTransitionAnimationScale || + preference == mAnimatorDurationScale) { + ((AnimationScalePreference) preference).click(); + } + return false; + } + + @Override public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { if (Utils.isMonkeyRunning()) { return false; |