Merge "Revert "Add discrete contrast UI slider in the setting"" into udc-dev

This commit is contained in:
Lucas Dupin
2023-03-03 18:45:22 +00:00
committed by Android (Google) Code Review
8 changed files with 0 additions and 485 deletions

View File

@@ -1,104 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2022 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.
-->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeightSmall"
android:gravity="center_vertical"
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
android:clickable="false"
android:orientation="horizontal">
<include layout="@layout/settingslib_icon_frame"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="16dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@android:id/title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceListItem"
android:textColor="?android:attr/textColorPrimary"
android:ellipsize="marquee"
android:hyphenationFrequency="normalFast"
android:lineBreakWordStyle="phrase"
android:fadingEdge="horizontal"/>
<LinearLayout
android:id="@android:id/widget_frame"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:orientation="vertical"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layoutDirection="ltr"
android:orientation="vertical">
<com.android.settings.accessibility.ContrastLevelSeekBar
android:id="@*android:id/seekbar"
android:minHeight="?android:attr/listPreferredItemHeightSmall"
android:paddingStart="0dp"
android:paddingEnd="0dp"
android:layout_gravity="center_vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="@+id/left_text"
android:text="@string/accessibility_contrast_level_left_label"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?android:attr/textColorSecondary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:maxLines="1"
android:textAlignment="viewStart" />
<TextView
android:id="@+id/right_text"
android:text="@string/accessibility_contrast_level_right_label"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?android:attr/textColorSecondary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:maxLines="1"
android:textAlignment="viewEnd" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>

View File

@@ -220,10 +220,6 @@
<dimen name="accessibility_qs_tooltip_margin">20dp</dimen>
<dimen name="accessibility_qs_tooltip_margin_top">27dp</dimen>
<!-- Contrast level slider -->
<dimen name="contrast_level_seekbar_center_marker_height">14dp</dimen>
<dimen name="contrast_level_seekbar_center_marker_width">1dp</dimen>
<!-- Restricted icon in switch bar -->
<dimen name="restricted_icon_margin_end">16dp</dimen>
<!-- Restricted icon size in switch bar -->

View File

@@ -4386,12 +4386,6 @@
<string name="accessibility_disable_animations">Remove animations</string>
<!-- Summary for the accessibility preference for disabling animations. [CHAR LIMIT=60] -->
<string name="accessibility_disable_animations_summary">Reduce movement on the screen</string>
<!-- Title for the accessibility preference for the contrast level slider. [CHAR LIMIT=35] -->
<string name="accessibility_contrast_level_title">Contrast Level</string>
<!-- 'Low' text at the left of the contrast level slider. [CHAR LIMIT=20] -->
<string name="accessibility_contrast_level_left_label">Standard</string>
<!-- 'High' text at the right of the contrast level slider. [CHAR LIMIT=20] -->
<string name="accessibility_contrast_level_right_label">High</string>
<!-- Title for the accessibility preference for primary mono. [CHAR LIMIT=35] -->
<string name="accessibility_toggle_primary_mono_title">Mono audio</string>
<!-- Summary for the accessibility preference for primary mono. [CHAR LIMIT=60] -->

View File

@@ -64,11 +64,6 @@
android:title="@string/accessibility_toggle_large_pointer_icon_title"
settings:controller="com.android.settings.accessibility.LargePointerIconPreferenceController"/>
<com.android.settings.accessibility.ContrastLevelSeekBarPreference
android:key="seekbar_color_contrast"
android:persistent="false"
android:title="@string/accessibility_contrast_level_title"/>
<PreferenceCategory
android:key="experimental_category"
android:persistent="false"

View File

@@ -1,118 +0,0 @@
/*
* Copyright (C) 2022 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.accessibility;
import static android.view.HapticFeedbackConstants.CLOCK_TICK;
import static com.android.settings.Utils.isNightMode;
import static com.android.settings.accessibility.ContrastLevelSeekBarPreference.CONTRAST_SLIDER_TICKS;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.os.UserHandle;
import android.provider.Settings;
import android.util.AttributeSet;
import android.widget.SeekBar;
import com.android.settings.R;
/**
* A custom seekbar for the contrast level setting.
*
* Adds a center line indicator between left and right, which snaps to if close.
* Updates the Settings.Secure.CONTRAST_LEVEL setting on progress changed.
*
* TODO(b/266071578): remove this class and replace this with the final UI
*/
public class ContrastLevelSeekBar extends SeekBar {
private final Context mContext;
private int mLastProgress = -1;
private final Paint mMarkerPaint;
private final Rect mMarkerRect;
private final OnSeekBarChangeListener mProxySeekBarListener = new OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar seekBar) { }
@Override
public void onStartTrackingTouch(SeekBar seekBar) { }
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if (!fromUser || progress == mLastProgress) return;
seekBar.performHapticFeedback(CLOCK_TICK);
mLastProgress = progress;
// rescale progress from [0, 1, 2] to [0, 0.5, 1]
final float contrastLevel = (float) progress / CONTRAST_SLIDER_TICKS;
Settings.Secure.putFloatForUser(mContext.getContentResolver(),
Settings.Secure.CONTRAST_LEVEL, contrastLevel, UserHandle.USER_CURRENT);
}
};
public ContrastLevelSeekBar(Context context, AttributeSet attrs) {
this(context, attrs, com.android.internal.R.attr.seekBarStyle);
}
public ContrastLevelSeekBar(Context context, AttributeSet attrs, int defStyleAttr) {
this(context, attrs, defStyleAttr, 0 /* defStyleRes */);
}
public ContrastLevelSeekBar(
Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
mContext = context;
Resources res = getResources();
mMarkerRect = new Rect(0 /* left */, 0 /* top */,
res.getDimensionPixelSize(R.dimen.contrast_level_seekbar_center_marker_width),
res.getDimensionPixelSize(R.dimen.contrast_level_seekbar_center_marker_height));
mMarkerPaint = new Paint();
// the might be a better colour for the markers, but this slider is temporary anyway
mMarkerPaint.setColor(isNightMode(context) ? Color.WHITE : Color.BLACK);
mMarkerPaint.setStyle(Paint.Style.FILL);
// Remove the progress colour
setProgressTintList(ColorStateList.valueOf(Color.TRANSPARENT));
super.setOnSeekBarChangeListener(mProxySeekBarListener);
}
@Override
public void setOnSeekBarChangeListener(OnSeekBarChangeListener listener) { }
// Note: the superclass AbsSeekBar.onDraw is synchronized.
@Override
protected synchronized void onDraw(Canvas canvas) {
// Draw a marker at the center of the seekbar
int seekBarCenter = (getHeight() - getPaddingBottom()) / 2;
float sliderWidth = getWidth() - mMarkerRect.right - getPaddingEnd();
canvas.save();
canvas.translate(sliderWidth / 2f,
seekBarCenter - (mMarkerRect.bottom / 2f));
canvas.drawRect(mMarkerRect, mMarkerPaint);
canvas.restore();
super.onDraw(canvas);
}
}

View File

@@ -1,73 +0,0 @@
/*
* Copyright (C) 2022 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.accessibility;
import android.content.Context;
import android.os.UserHandle;
import android.provider.Settings;
import android.util.AttributeSet;
import androidx.core.content.res.TypedArrayUtils;
import androidx.preference.PreferenceViewHolder;
import com.android.settings.R;
import com.android.settings.widget.SeekBarPreference;
/** A slider preference that directly controls the contrast level **/
public class ContrastLevelSeekBarPreference extends SeekBarPreference {
/**
* The number of ticks of the slider (the more ticks, the more continuous the slider feels).
*/
public static final int CONTRAST_SLIDER_TICKS = 2;
private final Context mContext;
private ContrastLevelSeekBar mSeekBar;
public ContrastLevelSeekBarPreference(Context context, AttributeSet attrs) {
super(context, attrs, TypedArrayUtils.getAttr(context,
R.attr.preferenceStyle,
android.R.attr.preferenceStyle));
mContext = context;
setLayoutResource(R.layout.preference_contrast_level_slider);
}
@Override
public void onBindViewHolder(PreferenceViewHolder view) {
super.onBindViewHolder(view);
mSeekBar = (ContrastLevelSeekBar) view.findViewById(
com.android.internal.R.id.seekbar);
init();
}
private void init() {
if (mSeekBar == null) {
return;
}
final float contrastLevel = Settings.Secure.getFloatForUser(
mContext.getContentResolver(), Settings.Secure.CONTRAST_LEVEL,
0.f /* default */, UserHandle.USER_CURRENT);
mSeekBar.setMax(CONTRAST_SLIDER_TICKS);
// Rescale contrast from [0, 0.5, 1] to [0, 1, 2]
int progress = Math.max(0, Math.round(contrastLevel * CONTRAST_SLIDER_TICKS));
mSeekBar.setProgress(progress);
mSeekBar.setEnabled(isEnabled());
}
}

View File

@@ -1,69 +0,0 @@
/*
* Copyright (C) 2022 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.accessibility;
import static com.android.settings.accessibility.ContrastLevelSeekBarPreference.CONTRAST_SLIDER_TICKS;
import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import androidx.preference.PreferenceViewHolder;
import com.android.settings.testutils.shadow.ShadowInteractionJankMonitor;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
@RunWith(RobolectricTestRunner.class)
@Config(shadows = {ShadowInteractionJankMonitor.class})
public class ContrastLevelSeekBarPreferenceTest {
private Context mContext;
private AttributeSet mAttrs;
private PreferenceViewHolder mHolder;
private ContrastLevelSeekBar mSeekBar;
private ContrastLevelSeekBarPreference mSeekBarPreference;
@Before
public void setUp() {
mContext = RuntimeEnvironment.application;
mSeekBarPreference = new ContrastLevelSeekBarPreference(mContext, mAttrs);
LayoutInflater inflater = LayoutInflater.from(mContext);
final View view =
inflater.inflate(mSeekBarPreference.getLayoutResource(),
new LinearLayout(mContext), false);
mHolder = PreferenceViewHolder.createInstanceForTests(view);
mSeekBar = view.findViewById(com.android.internal.R.id.seekbar);
}
@Test
public void seekBarPreferenceOnBindViewHolder_shouldInitSeekBarValue() {
mSeekBarPreference.onBindViewHolder(mHolder);
assertThat(mSeekBar.getMax()).isEqualTo(CONTRAST_SLIDER_TICKS);
assertThat(mSeekBar.getProgress()).isEqualTo(0);
}
}

View File

@@ -1,106 +0,0 @@
/*
* Copyright (C) 2022 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.accessibility;
import static android.view.HapticFeedbackConstants.CLOCK_TICK;
import static android.view.HapticFeedbackConstants.CONTEXT_CLICK;
import static com.android.settings.accessibility.ContrastLevelSeekBarPreference.CONTRAST_SLIDER_TICKS;
import static com.google.common.truth.Truth.assertThat;
import static org.robolectric.Shadows.shadowOf;
import android.content.Context;
import android.os.UserHandle;
import android.provider.Settings;
import android.widget.SeekBar;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
@RunWith(RobolectricTestRunner.class)
public class ContrastLevelSeekBarTest {
private Context mContext;
private ContrastLevelSeekBar mSeekBar;
private SeekBar.OnSeekBarChangeListener mProxySeekBarListener;
@Before
public void setUp() {
mContext = RuntimeEnvironment.application;
mSeekBar = new ContrastLevelSeekBar(mContext, null);
mProxySeekBarListener = shadowOf(mSeekBar).getOnSeekBarChangeListener();
}
@Test
public void onProgressChanged_minimumValue_shouldModifyContrast() {
// Assign the test value of SeekBar progress
mProxySeekBarListener.onProgressChanged(mSeekBar, 0, true);
assertThat(Settings.Secure.getFloatForUser(
mContext.getContentResolver(), Settings.Secure.CONTRAST_LEVEL,
-10f, UserHandle.USER_CURRENT)).isEqualTo(0);
}
@Test
public void onProgressChanged_centerValue_shouldModifyContrast() {
// Assign the test value of SeekBar progress
mProxySeekBarListener.onProgressChanged(mSeekBar, CONTRAST_SLIDER_TICKS / 2, true);
assertThat(Settings.Secure.getFloatForUser(
mContext.getContentResolver(), Settings.Secure.CONTRAST_LEVEL,
-10f, UserHandle.USER_CURRENT)).isWithin(1e-8f).of(0.5f);
}
@Test
public void onProgressChanged_maximumValue_shouldModifyContrast() {
// Assign the test value of SeekBar progress
mProxySeekBarListener.onProgressChanged(mSeekBar, CONTRAST_SLIDER_TICKS, true);
assertThat(Settings.Secure.getFloatForUser(
mContext.getContentResolver(), Settings.Secure.CONTRAST_LEVEL,
-10f, UserHandle.USER_CURRENT)).isEqualTo(1);
}
@Test
public void onProgressChanged_minimumValue_clockTickFeedbackPerformed() {
mSeekBar.performHapticFeedback(CONTEXT_CLICK);
mProxySeekBarListener.onProgressChanged(mSeekBar, 0, true);
assertThat(shadowOf(mSeekBar).lastHapticFeedbackPerformed()).isEqualTo(CLOCK_TICK);
}
@Test
public void onProgressChanged_centerValue_clockTickFeedbackPerformed() {
mSeekBar.performHapticFeedback(CONTEXT_CLICK);
mProxySeekBarListener.onProgressChanged(mSeekBar, CONTRAST_SLIDER_TICKS / 2, true);
assertThat(shadowOf(mSeekBar).lastHapticFeedbackPerformed()).isEqualTo(CLOCK_TICK);
}
@Test
public void onProgressChanged_maximumValue_clockTickFeedbackPerformed() {
mSeekBar.performHapticFeedback(CONTEXT_CLICK);
mProxySeekBarListener.onProgressChanged(mSeekBar, CONTRAST_SLIDER_TICKS, true);
assertThat(shadowOf(mSeekBar).lastHapticFeedbackPerformed()).isEqualTo(CLOCK_TICK);
}
}