Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,11 @@ internal class DiagnosticTroubleCodePreferenceDialogFragment : CoreDialogFragmen
}
)

// Inflated from XML (rather than constructed in code) so it can carry a custom, always-on
// scrollbar thumb on every API level - the theme default is thin and barely visible, and
// it's the only hint that more modules sit below the fold.
val listView =
android.widget.ListView(context).apply {
choiceMode = android.widget.ListView.CHOICE_MODE_MULTIPLE
(LayoutInflater.from(context).inflate(R.layout.dtc_module_list, container, false) as MaxHeightListView).apply {
adapter =
android.widget.ArrayAdapter(
context,
Expand All @@ -256,11 +258,15 @@ internal class DiagnosticTroubleCodePreferenceDialogFragment : CoreDialogFragmen
setItemChecked(index, true)
}
}
// Zero height + weight lets the LinearLayout shrink the list (which scrolls on its own)
// when there are more modules than fit on screen - with WRAP_CONTENT it would claim its
// full height and push the button bar below out of the dialog.
container.addView(
listView,
android.widget.LinearLayout.LayoutParams(
android.widget.LinearLayout.LayoutParams.MATCH_PARENT,
android.widget.LinearLayout.LayoutParams.WRAP_CONTENT
0,
1f
)
)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright 2019-2026, Tomasz Żebrowski
*
* <p>Licensed to the Apache Software Foundation (ASF) under one or more contributor license
* agreements. See the NOTICE file distributed with this work for additional information regarding
* copyright ownership. The ASF licenses this file to You 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
*
* <p>http://www.apache.org/licenses/LICENSE-2.0
*
* <p>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 org.obd.graphs.preferences.dtc

import android.content.Context
import android.util.AttributeSet
import android.widget.ListView

// A ListView that never grows beyond a fraction of the screen height. Inside the DTC module
// picker (an AlertDialog custom view) a plain wrap_content/weighted ListView still claimed the
// whole dialog height when the module list was long, pushing the button bar out of view - an
// explicit cap keeps room for the buttons regardless of how the dialog window gets measured.
class MaxHeightListView
@JvmOverloads
constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = android.R.attr.listViewStyle
) : ListView(context, attrs, defStyleAttr) {
var maxHeightRatio: Float = 0.4f

override fun onMeasure(
widthMeasureSpec: Int,
heightMeasureSpec: Int
) {
val maxHeight = (resources.displayMetrics.heightPixels * maxHeightRatio).toInt()
val size = MeasureSpec.getSize(heightMeasureSpec)
val cappedSpec =
when (MeasureSpec.getMode(heightMeasureSpec)) {
MeasureSpec.UNSPECIFIED -> MeasureSpec.makeMeasureSpec(maxHeight, MeasureSpec.AT_MOST)
MeasureSpec.EXACTLY -> MeasureSpec.makeMeasureSpec(minOf(size, maxHeight), MeasureSpec.EXACTLY)
else -> MeasureSpec.makeMeasureSpec(minOf(size, maxHeight), MeasureSpec.AT_MOST)
}
super.onMeasure(widthMeasureSpec, cappedSpec)
}
}
7 changes: 7 additions & 0 deletions app/src/main/res/drawable/dtc_module_list_scrollbar_thumb.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#9E9E9E" />
<corners android:radius="3dp" />
<size android:width="6dp" />
</shape>
2 changes: 2 additions & 0 deletions app/src/main/res/layout/dialog_dtc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:orientation="horizontal">

<Button
Expand Down Expand Up @@ -98,6 +99,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:baselineAligned="false"
android:orientation="horizontal">

<Button
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/res/layout/dtc_module_list.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<org.obd.graphs.preferences.dtc.MaxHeightListView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:choiceMode="multipleChoice"
android:fadeScrollbars="false"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:scrollbarSize="6dp"
android:scrollbarStyle="insideOverlay"
android:scrollbarThumbVertical="@drawable/dtc_module_list_scrollbar_thumb"
android:scrollbars="vertical" />
Loading