Loading res/layout/data_usage_bytes_editor.xml +2 −1 Original line number Diff line number Diff line Loading @@ -36,8 +36,9 @@ <Spinner android:id="@+id/size_spinner" style="@style/SettingslibSpinnerStyle.Expressive" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_height="wrap_content" android:layout_gravity="center_vertical" /> </LinearLayout> src/com/android/settings/datausage/BillingCycleSettings.java +4 −3 Original line number Diff line number Diff line Loading @@ -31,7 +31,6 @@ import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.inputmethod.EditorInfo; import android.widget.ArrayAdapter; import android.widget.EditText; import android.widget.NumberPicker; import android.widget.Spinner; Loading @@ -48,6 +47,7 @@ import com.android.settings.datausage.lib.DataUsageFormatter; import com.android.settings.datausage.lib.NetworkTemplates; import com.android.settings.network.telephony.MobileNetworkUtils; import com.android.settings.search.BaseSearchIndexProvider; import com.android.settings.widget.EnhancedSettingsSpinnerAdapter; import com.android.settingslib.NetworkPolicyEditor; import com.android.settingslib.net.DataUsageController; import com.android.settingslib.search.SearchIndexable; Loading Loading @@ -326,8 +326,9 @@ public class BillingCycleSettings extends DataUsageBaseFragment implements DataUsageFormatter.Companion.getBytesDisplayUnit(getResources(), MIB_IN_BYTES), DataUsageFormatter.Companion.getBytesDisplayUnit(getResources(), GIB_IN_BYTES), }; final ArrayAdapter<String> adapter = new ArrayAdapter<String>( getContext(), android.R.layout.simple_spinner_item, unitNames); EnhancedSettingsSpinnerAdapter.adjustDropDownOffset(type); EnhancedSettingsSpinnerAdapter<String> adapter = new EnhancedSettingsSpinnerAdapter<>(getContext(), unitNames); type.setAdapter(adapter); final boolean unitInGigaBytes = (bytes > 1.5f * GIB_IN_BYTES); Loading src/com/android/settings/widget/EnhancedSettingsSpinnerAdapter.kt 0 → 100644 +52 −0 Original line number Diff line number Diff line /* * Copyright (C) 2025 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.widget import android.content.Context import android.view.View import android.view.ViewGroup import android.view.ViewTreeObserver import android.widget.Spinner import com.android.settingslib.widget.SettingsSpinnerAdapter class EnhancedSettingsSpinnerAdapter<T>(context: Context?, items: Array<T>) : SettingsSpinnerAdapter<T>(context) { init { addAll(items.toList()) } override fun getDropDownView(position: Int, convertView: View?, parent: ViewGroup): View { if (parent is Spinner) { setSelectedPosition(parent.selectedItemPosition) } return super.getDropDownView(position, convertView, parent) } companion object { @JvmStatic fun adjustDropDownOffset(spinner: Spinner) { spinner.viewTreeObserver.addOnGlobalLayoutListener( object : ViewTreeObserver.OnGlobalLayoutListener { override fun onGlobalLayout() { spinner.dropDownVerticalOffset = spinner.height + 2 spinner.viewTreeObserver.removeOnGlobalLayoutListener(this) } } ) } } } Loading
res/layout/data_usage_bytes_editor.xml +2 −1 Original line number Diff line number Diff line Loading @@ -36,8 +36,9 @@ <Spinner android:id="@+id/size_spinner" style="@style/SettingslibSpinnerStyle.Expressive" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_height="wrap_content" android:layout_gravity="center_vertical" /> </LinearLayout>
src/com/android/settings/datausage/BillingCycleSettings.java +4 −3 Original line number Diff line number Diff line Loading @@ -31,7 +31,6 @@ import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.inputmethod.EditorInfo; import android.widget.ArrayAdapter; import android.widget.EditText; import android.widget.NumberPicker; import android.widget.Spinner; Loading @@ -48,6 +47,7 @@ import com.android.settings.datausage.lib.DataUsageFormatter; import com.android.settings.datausage.lib.NetworkTemplates; import com.android.settings.network.telephony.MobileNetworkUtils; import com.android.settings.search.BaseSearchIndexProvider; import com.android.settings.widget.EnhancedSettingsSpinnerAdapter; import com.android.settingslib.NetworkPolicyEditor; import com.android.settingslib.net.DataUsageController; import com.android.settingslib.search.SearchIndexable; Loading Loading @@ -326,8 +326,9 @@ public class BillingCycleSettings extends DataUsageBaseFragment implements DataUsageFormatter.Companion.getBytesDisplayUnit(getResources(), MIB_IN_BYTES), DataUsageFormatter.Companion.getBytesDisplayUnit(getResources(), GIB_IN_BYTES), }; final ArrayAdapter<String> adapter = new ArrayAdapter<String>( getContext(), android.R.layout.simple_spinner_item, unitNames); EnhancedSettingsSpinnerAdapter.adjustDropDownOffset(type); EnhancedSettingsSpinnerAdapter<String> adapter = new EnhancedSettingsSpinnerAdapter<>(getContext(), unitNames); type.setAdapter(adapter); final boolean unitInGigaBytes = (bytes > 1.5f * GIB_IN_BYTES); Loading
src/com/android/settings/widget/EnhancedSettingsSpinnerAdapter.kt 0 → 100644 +52 −0 Original line number Diff line number Diff line /* * Copyright (C) 2025 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.widget import android.content.Context import android.view.View import android.view.ViewGroup import android.view.ViewTreeObserver import android.widget.Spinner import com.android.settingslib.widget.SettingsSpinnerAdapter class EnhancedSettingsSpinnerAdapter<T>(context: Context?, items: Array<T>) : SettingsSpinnerAdapter<T>(context) { init { addAll(items.toList()) } override fun getDropDownView(position: Int, convertView: View?, parent: ViewGroup): View { if (parent is Spinner) { setSelectedPosition(parent.selectedItemPosition) } return super.getDropDownView(position, convertView, parent) } companion object { @JvmStatic fun adjustDropDownOffset(spinner: Spinner) { spinner.viewTreeObserver.addOnGlobalLayoutListener( object : ViewTreeObserver.OnGlobalLayoutListener { override fun onGlobalLayout() { spinner.dropDownVerticalOffset = spinner.height + 2 spinner.viewTreeObserver.removeOnGlobalLayoutListener(this) } } ) } } }