From 2133b884752ae4ee7d4db004bd37e63bff68d8a3 Mon Sep 17 00:00:00 2001 From: David Schachter Date: Thu, 26 Nov 2026 12:32:40 -0800 Subject: [PATCH 1/2] style: spotless reformat of layout_title_subtitle, no functional change Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Vh2DAZWMkFWJh7CY7P4kCH --- .../main/res/layout/layout_title_subtitle.xml | 87 +++++++++---------- 1 file changed, 39 insertions(+), 48 deletions(-) diff --git a/common/src/main/res/layout/layout_title_subtitle.xml b/common/src/main/res/layout/layout_title_subtitle.xml index 2c6b905531..c7fe27930b 100644 --- a/common/src/main/res/layout/layout_title_subtitle.xml +++ b/common/src/main/res/layout/layout_title_subtitle.xml @@ -1,52 +1,43 @@ - + - + - + - + - \ No newline at end of file + From 8874bbe812ff855db07181a96fe9dfe89ba52d9f Mon Sep 17 00:00:00 2001 From: David Schachter Date: Thu, 26 Nov 2026 12:32:40 -0800 Subject: [PATCH 2/2] ADFA-7290: Show every line of a wrapped permission card title At font scale 2.0, an onboarding permission card whose title wraps showed only its last line ("Install packages" read "packages"). The title was capped at one line with bottom gravity, so it kept one line's height and drew the bottom of the wrapped text. It now takes the lines it needs. OnboardingPermissionItemLayoutTest lays the card out at 2x font scale on a 360dp phone and checks that both wrapping titles get the height their lines need. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Vh2DAZWMkFWJh7CY7P4kCH --- .../OnboardingPermissionItemLayoutTest.kt | 105 ++++++++++++++++++ .../main/res/layout/layout_title_subtitle.xml | 2 - 2 files changed, 105 insertions(+), 2 deletions(-) create mode 100644 app/src/test/java/com/itsaky/androidide/adapters/onboarding/OnboardingPermissionItemLayoutTest.kt diff --git a/app/src/test/java/com/itsaky/androidide/adapters/onboarding/OnboardingPermissionItemLayoutTest.kt b/app/src/test/java/com/itsaky/androidide/adapters/onboarding/OnboardingPermissionItemLayoutTest.kt new file mode 100644 index 0000000000..03dc1c069c --- /dev/null +++ b/app/src/test/java/com/itsaky/androidide/adapters/onboarding/OnboardingPermissionItemLayoutTest.kt @@ -0,0 +1,105 @@ +/* + * This file is part of AndroidIDE. + * + * AndroidIDE is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * AndroidIDE is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with AndroidIDE. If not, see . + */ + +package com.itsaky.androidide.adapters.onboarding + +import android.Manifest +import android.content.Context +import android.text.StaticLayout +import android.view.View +import android.widget.FrameLayout +import android.widget.TextView +import androidx.appcompat.view.ContextThemeWrapper +import androidx.test.core.app.ApplicationProvider +import com.google.common.truth.Truth.assertWithMessage +import com.itsaky.androidide.R +import com.itsaky.androidide.models.OnboardingPermissionItem +import org.junit.Test +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner +import org.robolectric.annotation.Config +import org.robolectric.annotation.GraphicsMode + +/** + * A permission card's title at 2x font scale (ADFA-7290). A title capped at one line with bottom + * gravity kept one line's height and showed the wrapped text's last line: "Install packages" read + * "packages". Native graphics, so the text is measured with real fonts. + */ +@RunWith(RobolectricTestRunner::class) +@GraphicsMode(GraphicsMode.Mode.NATIVE) +class OnboardingPermissionItemLayoutTest { + private val themed: Context = + ContextThemeWrapper(ApplicationProvider.getApplicationContext(), R.style.Theme_AndroidIDE) + + /** The card for [title], bound by the real adapter and laid out at [width] px. */ + private fun laidOutTitle( + title: Int, + width: Int, + ): TextView { + val adapter = + OnboardingPermissionsAdapter( + listOf( + OnboardingPermissionItem( + Manifest.permission.REQUEST_INSTALL_PACKAGES, + title, + R.string.permission_desc_install_packages, + isGranted = false, + ), + ), + requestPermission = {}, + ) + val holder = adapter.onCreateViewHolder(FrameLayout(themed), 0) + adapter.onBindViewHolder(holder, 0) + + val card = holder.binding.root + card.measure( + View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY), + View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), + ) + card.layout(0, 0, width, card.measuredHeight) + return holder.binding.infoContent.title + } + + /** The title's text laid out at the title's own width with no line cap: what it takes to show it all. */ + private fun uncapped(title: TextView): StaticLayout { + val text = title.text + return StaticLayout.Builder + .obtain(text, 0, text.length, title.paint, title.width - title.compoundPaddingLeft - title.compoundPaddingRight) + .setLineSpacing(title.lineSpacingExtra, title.lineSpacingMultiplier) + .setIncludePad(title.includeFontPadding) + .build() + } + + @Test + @Config(fontScale = 2.0f, qualifiers = "w360dp-h640dp-xhdpi") + fun `a title that wraps at 2x font scale shows every line`() { + // The whole width of a 360dp phone, wider than the card gets on the screen, so a title that + // wraps here wraps on the device too. + val width = themed.resources.displayMetrics.widthPixels + for (res in listOf(R.string.permission_title_install_packages, R.string.permission_title_overlay_window)) { + val title = laidOutTitle(res, width) + val needed = uncapped(title) + + assertWithMessage("\"%s\" has to wrap at %spx for this test to mean anything", title.text, width) + .that(needed.lineCount) + .isGreaterThan(1) + assertWithMessage("\"%s\" needs %spx for its %s lines", title.text, needed.height, needed.lineCount) + .that(title.height - title.compoundPaddingTop - title.compoundPaddingBottom) + .isAtLeast(needed.height) + } + } +} diff --git a/common/src/main/res/layout/layout_title_subtitle.xml b/common/src/main/res/layout/layout_title_subtitle.xml index c7fe27930b..c8e2ce207a 100644 --- a/common/src/main/res/layout/layout_title_subtitle.xml +++ b/common/src/main/res/layout/layout_title_subtitle.xml @@ -19,8 +19,6 @@ android:layout_marginTop="8dp" android:layout_marginStart="16dp" android:layout_marginEnd="16dp" - android:gravity="bottom|start" - android:maxLines="1" android:textAppearance="@style/TextAppearance.Material3.TitleMedium" app:layout_constraintBottom_toTopOf="@id/description" app:layout_constraintEnd_toEndOf="parent"