Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8fab6189 authored by Steve Kondik's avatar Steve Kondik Committed by Michael Bestas
Browse files

settings: Animation scale seekbars

 * Use a seekbar preference to allow setting arbitrary animation scale values

Change-Id: I4ceaf0dc74e6e044e36cf3652bfc1efb33890380
parent 13ccd1c4
Loading
Loading
Loading
Loading
+48 −0
Original line number Diff line number Diff line
<?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>
+9 −12
Original line number Diff line number Diff line
@@ -235,26 +235,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"
+94 −0
Original line number Diff line number Diff line
/*
 * 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) {
    }
}
+31 −20
Original line number Diff line number Diff line
@@ -55,6 +55,7 @@ import android.hardware.usb.UsbManager;
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;
@@ -83,7 +84,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";

    /**
@@ -246,9 +248,9 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
    private ListPreference mLogdSize;
    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;

@@ -410,9 +412,9 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
        mWifiAllowScansWithTraffic = findAndInitSwitchPref(WIFI_ALLOW_SCAN_WITH_TRAFFIC_KEY);
        mLogdSize = addListPreference(SELECT_LOGD_SIZE_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);
        mOpenGLTraces = addListPreference(OPENGL_TRACES_KEY);
        mSimulateColorSpace = addListPreference(SIMULATE_COLOR_SPACE);
@@ -465,6 +467,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) {
@@ -1409,23 +1419,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) {
        }
    }
@@ -1436,7 +1436,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);
@@ -1639,6 +1640,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()) {