GameBar: CustomSeekBarPreference: Adapt to A16/QPR2

This commit is contained in:
Ido Ben-Hur
2025-12-12 22:50:57 +02:00
committed by Joey
parent 87c858068a
commit 715302ad0b
3 changed files with 37 additions and 43 deletions

View File

@@ -117,7 +117,16 @@
android:layout_weight="1" android:layout_weight="1"
android:layout_toEndOf="@id/minus" android:layout_toEndOf="@id/minus"
android:layout_toStartOf="@id/plus" android:layout_toStartOf="@id/plus"
android:layout_centerVertical="true" /> android:layout_centerVertical="true">
<com.google.android.material.slider.Slider
android:id="@+id/slider"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/Theme.MaterialComponents.DayNight"
style="@style/SettingslibSliderStyle.Expressive" />
</LinearLayout>
</RelativeLayout> </RelativeLayout>
</RelativeLayout> </RelativeLayout>

View File

@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2025 Yet Another AOSP 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>
<style name="SettingslibSliderStyle.Expressive" parent="">
<item name="trackColorActive">@color/settingslib_expressive_color_slider_track_active</item>
<item name="trackColorInactive">@color/settingslib_expressive_color_slider_track_inactive</item>
<item name="thumbColor">@color/settingslib_expressive_color_slider_thumb</item>
<item name="tickColorActive">@color/settingslib_expressive_color_slider_track_inactive</item>
<item name="tickColorInactive">@color/settingslib_expressive_color_slider_track_active</item>
<item name="haloColor">@color/settingslib_expressive_color_slider_halo</item>
</style>
</resources>

View File

@@ -127,10 +127,6 @@ public class PartsCustomSeekBarPreference extends Preference implements Slider.O
mValue = mMinValue; mValue = mMinValue;
} }
Context materialContext = new ContextThemeWrapper(context,
com.google.android.material.R.style.Theme_MaterialComponents_DayNight);
mSlider = new Slider(materialContext, attrs);
setLayoutResource(R.layout.preference_custom_seekbar); setLayoutResource(R.layout.preference_custom_seekbar);
} }
@@ -151,25 +147,8 @@ public class PartsCustomSeekBarPreference extends Preference implements Slider.O
@Override @Override
public void onBindViewHolder(PreferenceViewHolder holder) { public void onBindViewHolder(PreferenceViewHolder holder) {
super.onBindViewHolder(holder); super.onBindViewHolder(holder);
try
{
// move our seekbar to the new view we've been given
ViewParent oldContainer = mSlider.getParent();
ViewGroup newContainer = (ViewGroup) holder.findViewById(R.id.seekbar);
if (oldContainer != newContainer) {
// remove the seekbar from the old view
if (oldContainer != null) {
((ViewGroup) oldContainer).removeView(mSlider);
}
// remove the existing seekbar (there may not be one) and add ours
newContainer.removeAllViews();
newContainer.addView(mSlider, ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
}
} catch (Exception ex) {
Log.e(TAG, "Error binding view", ex);
}
mSlider = (Slider) holder.findViewById(R.id.slider);
mSlider.setValueTo(mMaxValue); mSlider.setValueTo(mMaxValue);
mSlider.setValueFrom(mMinValue); mSlider.setValueFrom(mMinValue);
mSlider.setValue(mValue); mSlider.setValue(mValue);
@@ -182,26 +161,6 @@ public class PartsCustomSeekBarPreference extends Preference implements Slider.O
Log.w(TAG, "Step size is zero or invalid: " + mInterval); Log.w(TAG, "Step size is zero or invalid: " + mInterval);
} }
// Set up slider color
mSlider.setTrackActiveTintList(getContext().getColorStateList(
com.android.settingslib.widget.preference.slider.R.color
.settingslib_expressive_color_slider_track_active));
mSlider.setTrackInactiveTintList(getContext().getColorStateList(
com.android.settingslib.widget.preference.slider.R.color
.settingslib_expressive_color_slider_track_inactive));
mSlider.setThumbTintList(getContext().getColorStateList(
com.android.settingslib.widget.preference.slider.R.color
.settingslib_expressive_color_slider_thumb));
mSlider.setHaloTintList(getContext().getColorStateList(
com.android.settingslib.widget.preference.slider.R.color
.settingslib_expressive_color_slider_halo));
mSlider.setTickActiveTintList(getContext().getColorStateList(
com.android.settingslib.widget.preference.slider.R.color
.settingslib_expressive_color_slider_track_active));
mSlider.setTickInactiveTintList(getContext().getColorStateList(
com.android.settingslib.widget.preference.slider.R.color
.settingslib_expressive_color_slider_track_inactive));
// Set up slider size // Set up slider size
if (SettingsThemeHelper.isExpressiveTheme(getContext())) { if (SettingsThemeHelper.isExpressiveTheme(getContext())) {
Resources res = getContext().getResources(); Resources res = getContext().getResources();