Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

settings: Switch from List preference to Animation Scale Preference #27

Draft
wants to merge 30 commits into
base: 14
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
0fd5b19
Settings: Use seekbar to allow setting arbitrary animation values
hyperb1iss May 2, 2014
8505130
Settings: AnimationScale: Fix force close when not using english
mydongistiny Sep 22, 2018
d05ebf9
settings: move animation preference to different class
kazerine Nov 19, 2020
e2eec4a
Revert "Settings: Contionally enable some haptic feedback option"
NurKeinNeid Jun 21, 2024
20cf514
Revert "Settings: Relax slider haptic feedback"
NurKeinNeid Jun 22, 2024
996d704
Revert "Settings: Use VibratorHelper for custom haptic feedback"
NurKeinNeid Jun 22, 2024
be38da6
Partially revert "Settings: Add haptic feedback on sliders [2/2]"
NurKeinNeid Jun 22, 2024
3b47dcb
Merge tag 'android-14.0.0_r50' of https://android.googlesource.com/pl…
NurKeinNeid Jun 22, 2024
3d2e017
Settings: Allow limiting custom app actions in QS media player [2/2]
idoybh Jun 4, 2024
575f887
Settings: Allow using QS media player time as next & previous [2/2]
idoybh Jun 5, 2024
77346f2
fixup! Implement notificationlight settings
iKeramat May 16, 2024
a81cc8c
Settings: Don't directly call onStart/onStop on dialogs
SebaUbuntu Jun 23, 2024
1bfb828
Settings: Skip auth for WiFi net share when unlocked in the last 60s
idoybh Jun 23, 2024
af335dd
Settings: Add Simplified Chinese translation
ianchb Apr 13, 2024
f06256d
Settings: Changes for LiveDisplay
jhenrique09 Jun 9, 2024
2418139
Settings: Add dialog handling for ApplicationLightPreference
ShionKanagawa Jun 25, 2024
ce003f0
Revert "[Sim UI enhancement] remove the "Tap to show info""
althafvly Jun 27, 2024
ca61195
Partially revert "Remove feedback and bug report stuff"
NurKeinNeid Jun 29, 2024
22e29a4
Settings: Add dialog handling for BrightnessPreference and ButtonBack…
ShionKanagawa Jun 29, 2024
c510286
Revert "Settings: Add toggle for 60Hz refresh rate on battery saver"
NurKeinNeid Jun 30, 2024
f1cdd9b
Merge tag 'android-14.0.0_r53' of https://android.googlesource.com/pl…
NurKeinNeid Jul 3, 2024
2dbdc39
fixup! Implement notificationlight settings
NurKeinNeid Jul 7, 2024
06dd56d
Automatic translation import
lineageos-gerrit Jul 16, 2024
65050d8
Settings: Fix choose pattern size activity theme issues
Dhina17 Jul 15, 2024
8a9358c
ChooseLockPatternSize: Remove header start padding in SuW
Dhina17 Jul 15, 2024
6d7bdcd
Settings: Remove unused pattern sizes layout
Dhina17 Jul 15, 2024
fa06000
Revert "Settings: Suppress notifications sound if screen is ON [2/2]"
NurKeinNeid Jul 27, 2024
5dc569f
Automatic translation import
lineageos-gerrit Aug 1, 2024
a085464
Merge tag 'android-14.0.0_r56' of https://android.googlesource.com/pl…
NurKeinNeid Aug 7, 2024
bd17c07
Revert "Restrict "Turn on wifi automatically" to USA and Canada"
NurKeinNeid Aug 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions res/layout/preference_dialog_animation_scale.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2017 The Pure Nexus 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:minI="0"
settings:maxI="10"
settings:defaultValue="1"
settings:digits="1" />

</RelativeLayout>
28 changes: 28 additions & 0 deletions res/values/evolution_attrs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2019-2022 The Evolution X 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.
-->

<resources>

<!-- Interval seekbar -->
<declare-styleable name="IntervalSeekBar">
<attr name="minI" format="float" />
<attr name="maxI" format="float" />
<attr name="defaultValuePure" format="float" />
<attr name="digits" format="integer" />
</declare-styleable>

</resources>
6 changes: 3 additions & 3 deletions res/xml/development_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -508,19 +508,19 @@
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:entries="@array/window_animation_scale_entries"
android:entryValues="@array/window_animation_scale_values" />

<ListPreference
<com.android.settings.AnimationScalePreference
android:key="transition_animation_scale"
android:title="@string/transition_animation_scale_title"
android:entries="@array/transition_animation_scale_entries"
android:entryValues="@array/transition_animation_scale_values" />

<ListPreference
<com.android.settings.AnimationScalePreference
android:key="animator_duration_scale"
android:title="@string/animator_duration_scale_title"
android:entries="@array/animator_duration_scale_entries"
Expand Down
90 changes: 90 additions & 0 deletions src/com/android/settings/AnimationScalePreference.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* Copyright (C) 2017 The Pure Nexus 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.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.SeekBar;
import android.widget.TextView;

import com.android.settingslib.CustomDialogPreferenceCompat;

public class AnimationScalePreference extends CustomDialogPreferenceCompat
implements SeekBar.OnSeekBarChangeListener {

private TextView mScaleText;
private IntervalSeekBar mSeekBar;

private float mScale = 1f;

public AnimationScalePreference(Context context, AttributeSet attrs) {
super(context, attrs);
setPositiveButtonText(android.R.string.ok);
setNegativeButtonText(android.R.string.cancel);

setDialogLayoutResource(R.layout.preference_dialog_animation_scale);
}

@Override
protected void onBindDialogView(View view) {
super.onBindDialogView(view);

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);
}

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) {
}
}
103 changes: 103 additions & 0 deletions src/com/android/settings/IntervalSeekBar.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
* Copyright (C) 2017 The Pure Nexus 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.content.res.TypedArray;
import android.util.AttributeSet;
import android.util.Log;
import android.widget.SeekBar;

/**
* Custom SeekBar that allows setting both a minimum and maximum value.
* This also handles floating point values (to 2 decimal places) through
* integer conversions.
*/
public class IntervalSeekBar extends SeekBar {
private float mMin;
private float mMax;
private float mDefault;
private float mMultiplier;

public IntervalSeekBar(Context context, AttributeSet attrs) {
super(context, attrs);

TypedArray seekBarType = context.obtainStyledAttributes(attrs,
R.styleable.IntervalSeekBar, 0, 0);

mMax = seekBarType.getFloat(R.styleable.IntervalSeekBar_maxI, 1.5f);
mMin = seekBarType.getFloat(R.styleable.IntervalSeekBar_minI, 0.5f);
mDefault = seekBarType.getFloat(R.styleable.IntervalSeekBar_defaultValuePure, 1.0f);

int digits = seekBarType.getInt(R.styleable.IntervalSeekBar_digits, 0);
mMultiplier = (float) Math.pow(10, digits);

if (mMin > mMax) {
float temp = mMax;
mMax = mMin;
mMin = temp;
}

setMax(convertFloatToProgress(mMax));
setProgressFloat(mDefault);

seekBarType.recycle();
}

/*
* Converts from SeekBar units (which the SeekBar uses), to scale units
* (which are saved).
* This operation is the inverse of setFontScaling.
*/
public float getProgressFloat() {
return (getProgress() / mMultiplier) + mMin;
}

/*
* Converts from scale units (which are saved), to SeekBar units
* (which the SeekBar uses). This also sets the SeekBar progress.
* This operation is the inverse of getProgressFloat.
*/
public void setProgressFloat(float progress) {
setProgress(convertFloatToProgress(progress));
}

private int convertFloatToProgress(float value) {
return Math.round((value - mMin) * mMultiplier);
}

public float getMinimum() {
return mMin;
}

public float getMaximum() {
return mMax;
}

public float getDefault() {
return mDefault;
}

public void setMaximum(float max) {
mMax = max;
setMax(convertFloatToProgress(mMax));
}

public void setMinimum(float min) {
mMin = min;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,22 @@
import android.view.IWindowManager;

import androidx.annotation.VisibleForTesting;
import androidx.preference.ListPreference;
import androidx.preference.Preference;

import com.android.settings.AnimationScalePreference;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.development.DeveloperOptionsPreferenceController;

public class AnimatorDurationScalePreferenceController extends DeveloperOptionsPreferenceController
implements Preference.OnPreferenceChangeListener, PreferenceControllerMixin {
implements Preference.OnPreferenceChangeListener, Preference.OnPreferenceClickListener,
PreferenceControllerMixin {

private static final String ANIMATOR_DURATION_SCALE_KEY = "animator_duration_scale";

@VisibleForTesting
static final int ANIMATOR_DURATION_SCALE_SELECTOR = 2;
@VisibleForTesting
static final float DEFAULT_VALUE = 1;
static final float DEFAULT_VALUE = 1f;

private final IWindowManager mWindowManager;
private final String[] mListValues;
Expand Down Expand Up @@ -88,19 +89,17 @@ private void writeAnimationScaleOption(Object newValue) {
private void updateAnimationScaleValue() {
try {
final float scale = mWindowManager.getAnimationScale(ANIMATOR_DURATION_SCALE_SELECTOR);
int index = 0; // default
for (int i = 0; i < mListValues.length; i++) {
float val = Float.parseFloat(mListValues[i]);
if (scale <= val) {
index = i;
break;
}
}
final ListPreference listPreference = (ListPreference) mPreference;
listPreference.setValue(mListValues[index]);
listPreference.setSummary(mListSummaries[index]);
final AnimationScalePreference durationPreference = (AnimationScalePreference) mPreference;
durationPreference.setOnPreferenceClickListener(this);
durationPreference.setScale(scale);
} catch (RemoteException e) {
// intentional no-op
}
}

@Override
public boolean onPreferenceClick(Preference preference) {
((AnimationScalePreference) preference).click();
return false;
}
}
Loading