From 4efe37ef9c52d665133ca3fad44ff2a762dee1c0 Mon Sep 17 00:00:00 2001 From: TMC Date: Sat, 14 Nov 2026 18:50:49 +0100 Subject: [PATCH] App list: fixes from the pre-release audit - Scrub from home works right after the launcher starts. The home edge band was measured from the alphabet's own view, which has no size until the app list has been shown once (emulator: it now opens at a letter straight after an install). It no longer takes over per-icon swipe gestures on icons at the edge. - Holding to scrub no longer undoes "Remember position", and the remembered place is saved and restored in the same unit. - Notification previews: no text Android itself would hide (secret notifications, and work-profile ones the ranking redacts); right after changes made while the launcher was in the background; also for rows held in the list's view cache; only redrawn when the line changed; read by TalkBack; set through BubbleTextView's own label handling. - Light theme: search results, the empty state and the search field are readable on the always-dark backdrop (emulator). - Hide app is not offered for Private Space apps, where it could not work, and Private Space adds no blank stop to the alphabet. - Canvas-drawn letters follow Android's Bold text setting. - TalkBack list positions ignore the letter headers; the one-column list stays one column on foldables in two-panel mode. Co-Authored-By: Claude Opus 5.5 --- .../src/app/flexera/drawer/FlexeraDrawer.kt | 10 + .../drawer/FlexeraEdgeScrubController.kt | 27 ++- .../drawer/FlexeraNotificationPreview.kt | 170 +++++++++++++--- flexera/src/app/flexera/drawer/HideApp.kt | 8 +- .../app/flexera/drawer/WaveAlphabetView.kt | 192 ++++++++++++++---- .../app/lawnchair/DeviceProfileOverrides.kt | 6 +- .../src/app/lawnchair/LawnchairLauncher.kt | 6 +- .../lawnchair/allapps/AllAppsSearchInput.kt | 7 +- .../app/lawnchair/override/CustomizeDialog.kt | 5 + .../search/LawnchairSearchAdapterProvider.kt | 8 +- .../search/LawnchairSearchUiDelegate.kt | 10 + ...ButtonNavbarToOverviewTouchController.java | 11 +- src/com/android/launcher3/BubbleTextView.java | 10 + .../launcher3/FastScrollRecyclerView.java | 51 ++++- .../launcher3/allapps/AllAppsGridAdapter.java | 10 +- .../launcher3/allapps/AllAppsStore.java | 54 +++++ .../notification/NotificationListener.java | 9 +- .../launcher3/popup/PopupDataProvider.java | 28 ++- 18 files changed, 525 insertions(+), 97 deletions(-) diff --git a/flexera/src/app/flexera/drawer/FlexeraDrawer.kt b/flexera/src/app/flexera/drawer/FlexeraDrawer.kt index 0d259d10d5..ec495b8283 100644 --- a/flexera/src/app/flexera/drawer/FlexeraDrawer.kt +++ b/flexera/src/app/flexera/drawer/FlexeraDrawer.kt @@ -6,6 +6,7 @@ import android.graphics.Point import android.graphics.Rect import android.os.Build import android.util.TypedValue +import android.view.ContextThemeWrapper import android.view.LayoutInflater import android.view.MotionEvent import android.view.View @@ -192,6 +193,15 @@ object FlexeraDrawer { */ const val BACKDROP_COLOR = 0xC7000000.toInt() + /** + * [context] in the dark theme, for views that lie on the drawer's backdrop. The backdrop is + * dark whatever the theme ([BACKDROP_COLOR]), but Lawnchair colours its search field, its + * results, their cards and its "no results" message from the theme, which in the light theme, + * or over a light wallpaper, gives dark text. + */ + @JvmStatic + fun backdropContext(context: Context): Context = ContextThemeWrapper(context, R.style.AppTheme_Dark) + /** * Lawnchair fades the search field's pill out while the owner types, leaving the text on the * drawer's panel. This drawer has no panel, so the pill stays. diff --git a/flexera/src/app/flexera/drawer/FlexeraEdgeScrubController.kt b/flexera/src/app/flexera/drawer/FlexeraEdgeScrubController.kt index 97b26fcfaa..8ab6a9da46 100644 --- a/flexera/src/app/flexera/drawer/FlexeraEdgeScrubController.kt +++ b/flexera/src/app/flexera/drawer/FlexeraEdgeScrubController.kt @@ -17,9 +17,10 @@ import kotlin.math.abs * touch. Nothing is drawn on the home screen; the letters appear with the drawer. * * The edge is shared with page swipes, taps and item drags, so this claims a touch only once it - * has clearly moved up or down, and never while an item is being dragged. A touch that lifts - * again within [FlexeraDrawer.MIN_SCRUB_MS] was a flick, not a scrub, and opens the plain list. - * The setting is on unless the owner switches it off. + * has clearly moved up or down, and never while an item is being dragged. It also leaves alone a + * touch on an icon that the owner gave a swipe up or down of its own, as the home screen's other + * swipes do. A touch that lifts again within [FlexeraDrawer.MIN_SCRUB_MS] was a flick, not a + * scrub, and opens the plain list. The setting is on unless the owner switches it off. */ class FlexeraEdgeScrubController(private val launcher: Launcher) : TouchController { @@ -54,8 +55,9 @@ class FlexeraEdgeScrubController(private val launcher: Launcher) : TouchControll scrubbing = true scrubStartTime = SystemClock.uptimeMillis() // The drawer starts opening and the alphabet takes the finger in the same - // moment. Opening comes first, because its start is when the drawer - // puts its list in place, which must not undo the scrub's first jump. + // moment. Opening comes first: with Remember position on, its start notes + // where the list stands, which a flick sends it back to, so the note must + // be taken before the scrub's first jump. openDrawer() FlexeraDrawer.scrubFromSwipe(launcher.appsView, launcher.dragLayer, ev) return true @@ -103,7 +105,20 @@ class FlexeraEdgeScrubController(private val launcher: Launcher) : TouchControll (ev.edgeFlags and Utilities.EDGE_NAV_BAR) == 0 && launcher.isInState(LauncherState.NORMAL) && AbstractFloatingView.getTopOpenView(launcher) == null && - FlexeraDrawer.isOnHomeEdge(launcher.appsView, launcher.dragLayer, ev) + FlexeraDrawer.isOnHomeEdge(launcher.appsView, launcher.dragLayer, ev) && + !isOnIconWithVerticalSwipe(ev) + + /** + * True when [ev] lands on a home-screen icon that has a swipe up or down of its own. An icon + * in the column next to the edge lies partly on it, and a swipe there is still the icon's: a + * scrub would take the touch away from the icon before its swipe could run. + */ + private fun isOnIconWithVerticalSwipe(ev: MotionEvent): Boolean { + val workspace = launcher.workspace ?: return false + val coord = floatArrayOf(ev.x, ev.y) + launcher.dragLayer.mapCoordInSelfToDescendant(workspace, coord) + return workspace.isTouchOnIconWithSwipeGesture(coord[0], coord[1], true) + } override fun dump(): String = "FlexeraEdgeScrubController candidate=$candidate scrubbing=$scrubbing" diff --git a/flexera/src/app/flexera/drawer/FlexeraNotificationPreview.kt b/flexera/src/app/flexera/drawer/FlexeraNotificationPreview.kt index c09ffecc29..d01b369497 100644 --- a/flexera/src/app/flexera/drawer/FlexeraNotificationPreview.kt +++ b/flexera/src/app/flexera/drawer/FlexeraNotificationPreview.kt @@ -1,18 +1,26 @@ package app.flexera.drawer import android.app.Notification +import android.os.Build +import android.os.Process +import android.service.notification.NotificationListenerService.Ranking +import android.service.notification.NotificationListenerService.RankingMap import android.service.notification.StatusBarNotification import android.text.SpannableStringBuilder import android.text.Spanned +import android.text.TextPaint import android.text.TextUtils -import android.text.style.ForegroundColorSpan +import android.text.style.CharacterStyle import android.text.style.RelativeSizeSpan +import android.text.style.UpdateAppearance +import android.view.accessibility.AccessibilityNodeInfo import app.lawnchair.preferences.PreferenceManager import com.android.launcher3.BubbleTextView import com.android.launcher3.R import com.android.launcher3.dot.DotInfo import com.android.launcher3.model.data.ItemInfo import java.util.concurrent.ConcurrentHashMap +import kotlin.math.roundToInt /** * Inline notification previews (PRD AD-11): in the drawer list, a row whose app has @@ -22,6 +30,10 @@ import java.util.concurrent.ConcurrentHashMap * feeds it, the same filter decides which notifications count, and a row is refreshed whenever * its dot is. Without notification access there are no dots and no previews. * + * It never shows what Android itself would hide. Of another profile's notification, a work + * profile's for one, it shows only what Android shows while that profile is locked, and it shows + * nothing for an app that is paused, or whose profile is. + * * Launcher3's listener hands each notification to [onPosted], [onRemoved] or [onFullRefresh] on * its worker thread; the rows read the stored text on the main thread through [apply]. */ @@ -29,20 +41,26 @@ object FlexeraNotificationPreview { private class Preview(val text: String, val postTime: Long) + /** What [apply] put on a row: the row's whole text, and the preview line in it. */ + private class Shown(val label: CharSequence, val preview: String) + /** Latest text per notification key, for the notifications that currently show a dot. */ private val previews = ConcurrentHashMap() + /** For reading a notification's ranking. Only the listener's worker thread uses it. */ + private val ranking = Ranking() + private const val MAX_LENGTH = 140 /** The preview line's text size as a share of the app name's. */ private const val TEXT_SCALE = 0.78f - /** White at 70%, so the app name stays the stronger of the two lines. */ - private const val TEXT_COLOR = 0xB3FFFFFF.toInt() + /** The preview line's opacity as a share of the app name's, so the name stays the stronger. */ + private const val TEXT_ALPHA = 0.7f @JvmStatic - fun onPosted(sbn: StatusBarNotification) { - val text = previewText(sbn) + fun onPosted(sbn: StatusBarNotification, rankings: RankingMap?) { + val text = previewText(sbn, rankings) if (text == null) previews.remove(sbn.key) else previews[sbn.key] = Preview(text, sbn.postTime) } @@ -52,36 +70,97 @@ object FlexeraNotificationPreview { } @JvmStatic - fun onFullRefresh(active: List) { + fun onFullRefresh(active: List, rankings: RankingMap?) { previews.clear() - active.forEach(::onPosted) + active.forEach { onPosted(it, rankings) } } /** * Sets [icon]'s text for [info]: the app name, plus the latest notification under it when - * [dot] says the app has any. Called for drawer rows whenever their dot state is applied. + * [dot] says the app has any. Called for drawer rows whenever their dot state is applied, and + * when a notification changes without changing its app's dot. */ @JvmStatic fun apply(icon: BubbleTextView, info: ItemInfo, dot: DotInfo?) { // Only rows of the drawer list have room for a second line. if (icon.getTag(R.id.flexera_drawer_row) == null) return val name = info.title ?: return - val preview = if (dot != null && isEnabled(icon)) latest(dot) else null + // Android hides the notifications of a paused app (Focus mode pauses some) and of a paused + // work profile. The row's app shows as disabled then. + val preview = if (dot != null && !info.isDisabled && isEnabled(icon)) latest(dot) else null + val shown = shownOn(icon) if (preview == null) { - if (icon.getTag(R.id.flexera_notification_preview) != null) { - // The row was showing a preview, for this app earlier or for another app before - // the view was reused. Back to the plain one-line name. - icon.setTag(R.id.flexera_notification_preview, null) - icon.setLines(1) - icon.text = name + if (icon.getTag(R.id.flexera_notification_preview) == null) return + // The row was showing a preview, for this app earlier or for another app before the + // view was reused. Back to the plain one-line name. + icon.setTag(R.id.flexera_notification_preview, null) + if (icon.minLines != 1 || icon.maxLines != 1) icon.setLines(1) + if (shown != null) { + // Binding a row puts its name back already, so this is a row that stays bound. + // BubbleTextView sets the name its own way, adding an archived app's cloud mark + // for one. That also resets the description, which can still say how many + // notifications the app has, or how far its download is, so the description is + // kept. + val description = icon.contentDescription + icon.applyLabel(info) + icon.contentDescription = description } return } - // The text is set afresh every time. Binding a row puts the plain name back first, so - // what the row showed before says nothing about what it shows now. + val label = label(icon, name, preview) + // The same text again would still lay the list out and redraw the row, and a notification + // that is updated every second, as a download's is, would keep doing that for nothing. + if (shown != null && TextUtils.equals(shown.label, label)) return + show(icon, label, preview) + } + /** + * Fits the app name to the row's new width. A row bound before its first layout has no width + * yet, so a long name was left whole, and it wraps onto the preview's line until this runs. + */ + @JvmStatic + fun onSizeChanged(icon: BubbleTextView) { + val shown = shownOn(icon) ?: return + val name = (icon.tag as? ItemInfo)?.title ?: return + val label = label(icon, name, shown.preview) + if (!TextUtils.equals(shown.label, label)) show(icon, label, shown.preview) + } + + /** Adds the preview line to the row's description, which is what screen readers read out. */ + @JvmStatic + fun describe(icon: BubbleTextView, node: AccessibilityNodeInfo) { + val shown = shownOn(icon) ?: return + // Without a description they read the row's text, which has the preview in it already. + val description = node.contentDescription + if (description.isNullOrEmpty()) return + node.contentDescription = icon.context.getString( + R.string.flexera_notification_preview_description, + description, + shown.preview, + ) + } + + /** + * What [apply] put on [icon], while it is still there. BubbleTextView puts the plain name back + * whenever it binds the row, and that leaves the mark of an earlier preview behind. + */ + private fun shownOn(icon: BubbleTextView): Shown? = + (icon.getTag(R.id.flexera_notification_preview) as? Shown) + ?.takeIf { TextUtils.equals(icon.text, it.label) } + + private fun show(icon: BubbleTextView, label: CharSequence, preview: String) { + // Setting the number of lines always lays the row out again, so only a row that had the + // other number gets it. + if (icon.minLines != 2 || icon.maxLines != 2) icon.setLines(2) + icon.ellipsize = TextUtils.TruncateAt.END + icon.text = label + icon.setTag(R.id.flexera_notification_preview, Shown(label, preview)) + } + + /** The app name on the first line, the preview under it. */ + private fun label(icon: BubbleTextView, name: CharSequence, preview: String): CharSequence { // Keep a long app name on its own line, so the preview is never pushed off the row. val width = icon.width - icon.compoundPaddingLeft - icon.compoundPaddingRight val firstLine = if (width > 0) { @@ -93,12 +172,8 @@ object FlexeraNotificationPreview { val start = label.length label.append(preview) label.setSpan(RelativeSizeSpan(TEXT_SCALE), start, label.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE) - label.setSpan(ForegroundColorSpan(TEXT_COLOR), start, label.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE) - - icon.setLines(2) - icon.ellipsize = TextUtils.TruncateAt.END - icon.text = label - icon.setTag(R.id.flexera_notification_preview, true) + label.setSpan(DimSpan(), start, label.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE) + return label } private fun isEnabled(icon: BubbleTextView): Boolean = @@ -115,8 +190,13 @@ object FlexeraNotificationPreview { } /** "Title: text" in one line, or whichever of the two the notification has. */ - private fun previewText(sbn: StatusBarNotification): String? { - val extras = sbn.notification.extras ?: return null + private fun previewText(sbn: StatusBarNotification, rankings: RankingMap?): String? { + val notification = if (sbn.user == Process.myUserHandle()) { + sbn.notification + } else { + lockedVersion(sbn, rankings) + } + val extras = notification?.extras ?: return null val title = extras.getCharSequence(Notification.EXTRA_TITLE).oneLine() val text = extras.getCharSequence(Notification.EXTRA_TEXT).oneLine() val combined = when { @@ -127,6 +207,46 @@ object FlexeraNotificationPreview { return combined.take(MAX_LENGTH).ifEmpty { null } } + /** + * The most of another profile's notification, a work profile's for one, that Android shows + * while that profile is locked: nothing if the notification is secret, the version its app + * made for public view if the content is hidden, and the whole notification otherwise. The + * launcher cannot tell whether that profile is locked at the moment, so a preview never shows + * more than this. + */ + private fun lockedVersion(sbn: StatusBarNotification, rankings: RankingMap?): Notification? { + val notification = sbn.notification + // Android sums up the profile's lock screen settings, its admin's rules and the channel's + // setting in the ranking. Apps can read that from Android 12; before, take it that the + // content is hidden. + val override = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && + rankings?.getRanking(sbn.key, ranking) == true + ) { + ranking.lockscreenVisibilityOverride + } else { + Notification.VISIBILITY_PRIVATE + } + return when { + notification.visibility == Notification.VISIBILITY_SECRET || + override == Notification.VISIBILITY_SECRET -> null + override == Notification.VISIBILITY_PRIVATE -> notification.publicVersion + // Without an override, the profile's settings let it show the content while locked, + // even that of a notification its app left private, which is the default. + else -> notification + } + } + private fun CharSequence?.oneLine(): String = this?.toString()?.replace('\n', ' ')?.trim().orEmpty() + + /** + * Draws the preview line in the row's own text colour, at [TEXT_ALPHA] of its opacity. A fixed + * colour would stay when Launcher3 fades or hides the row's text, as it does under an open + * long-press menu; this line fades with the name. + */ + private class DimSpan : CharacterStyle(), UpdateAppearance { + override fun updateDrawState(paint: TextPaint) { + paint.alpha = (paint.alpha * TEXT_ALPHA).roundToInt() + } + } } diff --git a/flexera/src/app/flexera/drawer/HideApp.kt b/flexera/src/app/flexera/drawer/HideApp.kt index 6de740a78a..d207d4ba7f 100644 --- a/flexera/src/app/flexera/drawer/HideApp.kt +++ b/flexera/src/app/flexera/drawer/HideApp.kt @@ -9,6 +9,7 @@ import com.android.launcher3.LauncherSettings.Favorites.CONTAINER_ALL_APPS import com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_APPLICATION import com.android.launcher3.R import com.android.launcher3.model.data.ItemInfo +import com.android.launcher3.pm.UserCache import com.android.launcher3.popup.SystemShortcut import com.android.launcher3.util.ComponentKey import com.android.launcher3.views.Snackbar @@ -27,8 +28,10 @@ object HideApp { /** * Offered for apps in the app list only: hiding does nothing to an icon on the home screen, - * so offering it there would promise something else. Not offered while the home screen is - * locked against changes, like Customize and Uninstall. + * so offering it there would promise something else. Not for apps in Private Space either: + * the list's Private Space section ignores the hidden list, so the app would stay in view + * after the message said it was hidden; locking the space is what hides its apps. Not offered + * while the home screen is locked against changes, like Customize and Uninstall. */ @JvmField val SHORTCUT = SystemShortcut.Factory { launcher: LawnchairLauncher, itemInfo: ItemInfo, originalView: View -> @@ -36,6 +39,7 @@ object HideApp { when { itemInfo.container != CONTAINER_ALL_APPS -> null itemInfo.itemType != ITEM_TYPE_APPLICATION || component == null -> null + UserCache.INSTANCE.get(launcher).getUserInfo(itemInfo.user).isPrivate -> null PreferenceManager2.getInstance(launcher).lockHomeScreen.firstCached() -> null else -> Shortcut(launcher, itemInfo, originalView, ComponentKey(component, itemInfo.user)) } diff --git a/flexera/src/app/flexera/drawer/WaveAlphabetView.kt b/flexera/src/app/flexera/drawer/WaveAlphabetView.kt index ef2daf6c56..87f4a1847b 100644 --- a/flexera/src/app/flexera/drawer/WaveAlphabetView.kt +++ b/flexera/src/app/flexera/drawer/WaveAlphabetView.kt @@ -3,17 +3,20 @@ package app.flexera.drawer import android.animation.ValueAnimator import android.annotation.SuppressLint import android.content.Context +import android.content.res.Configuration import android.graphics.Canvas import android.graphics.Color import android.graphics.Paint import android.graphics.Rect import android.graphics.Typeface +import android.graphics.fonts.FontStyle import android.os.Build import android.os.Bundle import android.view.HapticFeedbackConstants import android.view.MotionEvent import android.view.View import android.view.ViewConfiguration +import android.view.ViewGroup import android.view.ViewTreeObserver import android.view.animation.DecelerateInterpolator import android.widget.SeekBar @@ -104,7 +107,11 @@ class WaveAlphabetView( FlexeraDrawer.TEXT_SHADOW_COLOR, ) } - private val boldTypeface = Typeface.create(Typeface.DEFAULT, Typeface.BOLD) + + // Regular letters, and bold for the selected one and the bubble's. Android's Bold text + // setting makes both heavier, like the app names beside them (see withBoldText). + private var regularTypeface = withBoldText(Typeface.DEFAULT) + private var boldTypeface = withBoldText(Typeface.create(Typeface.DEFAULT, Typeface.BOLD)) // For the magnifier: one stroke with the letters' shadow, one without for the bubble. private val markPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply { @@ -148,6 +155,9 @@ class WaveAlphabetView( private var stripTop = 0f private var stripBottom = 0f + /** How tall the edge was that the letters were last placed on: this view's height, or the one it will have. */ + private var edgeHeight = 0 + /** Letter size at rest. Smaller than [letterSize] when a large font would make letters collide. */ private var restingLetterSize = letterSize private var layoutDirty = true @@ -198,9 +208,10 @@ class WaveAlphabetView( for (section in sections) { val label = section.sectionName?.toString().orEmpty() // Launcher3 repeats the last section once more so its own scroller can reach the - // bottom, Private Space uses a long badge string, and the work profile's info card - // has a section of its own; none of these is a letter. - if (label.isEmpty() || label.length > 2 || label == workInfoSection) continue + // bottom, Private Space names its sections with a badge image drawn over a single + // space, and the work profile's info card has a section of its own; none of these + // is a letter, and neither is a name too long for the strip. + if (label.isBlank() || label.length > 2 || label == workInfoSection) continue if (result.isNotEmpty() && result.last().label == label) continue result.add(Letter(label, section.position)) } @@ -214,14 +225,16 @@ class WaveAlphabetView( !PreferenceManager2.getInstance(context).hideAppDrawerSearchBar.firstCached() private fun refreshIfChanged() { - // Any new layout may have moved the list; keep the search field riding on it. + // Any new layout may have moved the list; keep the search field riding on it. A layout + // also follows new insets, which do not always change this view's size, so the letters + // are placed afresh when they are next needed. FlexeraDrawer.moveSearchFieldWithList(appsView) + layoutDirty = true val searching = appsView.isSearching val fresh = readLetters() if (fresh != letters || searching != wasSearching) { letters = fresh wasSearching = searching - layoutDirty = true accessibility.invalidateRoot() invalidate() } @@ -230,43 +243,37 @@ class WaveAlphabetView( private fun computeLayout() { layoutDirty = false - // The strip runs from where the list starts down to the navigation bar. - var top = 0f - appsView.activeRecyclerView?.let { rv -> - getLocationInWindow(location) - rv.getLocationInWindow(otherLocation) - // The list's rows start below its top padding, which holds the search field. - top = (otherLocation[1] - location[1] + rv.paddingTop).toFloat().coerceAtLeast(0f) + // The strip runs from where the list starts down to the navigation bar. Scrub from home + // begins a scrub while the drawer is still hidden, when its layout is missing (it has + // not been shown since the launcher started) or may be out of date (the screen has + // turned, or the insets have changed). The letters are then placed where they will be + // once it is shown, measured like the finger from where this view was last laid out. + var edgeTop = 0 + edgeHeight = height + if (appsView.visibility != VISIBLE || width == 0 || height == 0) { + (appsView.parent as? View)?.let { dragLayer -> + val frame = expectedFrame(dragLayer) + edgeTop = frame.top - (top + appsView.top) + edgeHeight = frame.height() + } } - val bottomInset = rootWindowInsets?.systemWindowInsetBottom ?: 0 - val availableTop = top + verticalMargin - val availableBottom = height - bottomInset - verticalMargin + val strip = placeStrip(edgeHeight.toFloat(), listTop(), bottomInset()) val count = letters.size letterYs = FloatArray(count) restingLetterSize = letterSize - if (count == 0 || availableBottom <= availableTop) { + if (strip == null) { stripTop = 0f stripBottom = 0f } else { - val spacing = min(maxSpacing, (availableBottom - availableTop) / count) - val blockHeight = spacing * count - // The stretch of edge a whole alphabet would take sits low, where a thumb reaches - // without stretching: its end a little above the navigation bar, its start - // wherever that puts it. The letters there are sit in the middle of that stretch, - // so that a short alphabet is in the middle of the thumb's reach and not at its - // lower end. Only letters that need the whole edge reach up to where the list starts. - val fullCount = FULL_ALPHABET + if (letters.first().isSearch) 1 else 0 - val zoneHeight = max(blockHeight, min(availableBottom - availableTop, spacing * fullCount)) - val zoneBottom = availableBottom - min(bottomOffset, availableBottom - availableTop - zoneHeight) - stripTop = zoneBottom - zoneHeight + (zoneHeight - blockHeight) / 2f - stripBottom = stripTop + blockHeight + stripTop = edgeTop + strip.top + stripBottom = stripTop + strip.spacing * count for (i in 0 until count) { - letterYs[i] = stripTop + spacing * (i + 0.5f) + letterYs[i] = stripTop + strip.spacing * (i + 0.5f) } // With a large system font and a full alphabet, letters at their set size would // overlap their neighbours; shrink them to fit their slot. - restingLetterSize = min(letterSize, spacing * MAX_LETTER_SHARE_OF_SLOT) + restingLetterSize = min(letterSize, strip.spacing * MAX_LETTER_SHARE_OF_SLOT) } // The strip does not reserve the edge for itself: Android's Back swipe starts there, @@ -274,6 +281,59 @@ class WaveAlphabetView( // onTouchEvent. } + /** Where the letters lie along an edge: the first one's slot starts at [top], and each slot is [spacing] tall. */ + private class Placement(val top: Float, val spacing: Float) + + /** + * Places the letters on an edge [height] tall, whose list's rows start [listTop] down it, + * above a navigation bar [bottomInset] tall; null when there are no letters or no room for + * them. The drawer places its letters with this, and scrub from home uses it to find where + * they will be while the drawer is closed. + */ + private fun placeStrip(height: Float, listTop: Float, bottomInset: Float): Placement? { + val count = letters.size + val availableTop = listTop + verticalMargin + val availableBottom = height - bottomInset - verticalMargin + if (count == 0 || availableBottom <= availableTop) return null + val spacing = min(maxSpacing, (availableBottom - availableTop) / count) + val blockHeight = spacing * count + // The stretch of edge a whole alphabet would take sits low, where a thumb reaches + // without stretching: its end a little above the navigation bar, its start + // wherever that puts it. The letters there are sit in the middle of that stretch, + // so that a short alphabet is in the middle of the thumb's reach and not at its + // lower end. Only letters that need the whole edge reach up to where the list starts. + val fullCount = FULL_ALPHABET + if (letters.first().isSearch) 1 else 0 + val zoneHeight = max(blockHeight, min(availableBottom - availableTop, spacing * fullCount)) + val zoneBottom = availableBottom - min(bottomOffset, availableBottom - availableTop - zoneHeight) + return Placement(zoneBottom - zoneHeight + (zoneHeight - blockHeight) / 2f, spacing) + } + + /** Where the list's rows start, in this view's coordinates: below its top padding, which holds the search field. */ + private fun listTop(): Float { + val rv = appsView.activeRecyclerView ?: return 0f + getLocationInWindow(location) + rv.getLocationInWindow(otherLocation) + return (otherLocation[1] - location[1] + rv.paddingTop).toFloat().coerceAtLeast(0f) + } + + private fun bottomInset(): Float = (rootWindowInsets?.systemWindowInsetBottom ?: 0).toFloat() + + /** + * Where this view will be in [dragLayer], the drawer's parent, once the drawer is shown: the + * drawer fills the drag layer within its margins, and this view fills the drawer within its + * padding. The margins and the padding follow the insets while the drawer is hidden; the + * drawer's layout does not. + */ + private fun expectedFrame(dragLayer: View): Rect { + val margins = appsView.layoutParams as? ViewGroup.MarginLayoutParams + return Rect( + (margins?.leftMargin ?: 0) + appsView.paddingLeft, + (margins?.topMargin ?: 0) + appsView.paddingTop, + dragLayer.width - (margins?.rightMargin ?: 0) - appsView.paddingRight, + dragLayer.height - (margins?.bottomMargin ?: 0) - appsView.paddingBottom, + ) + } + override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) { super.onSizeChanged(w, h, oldw, oldh) layoutDirty = true @@ -292,6 +352,16 @@ class WaveAlphabetView( super.onDetachedFromWindow() } + override fun onConfigurationChanged(newConfig: Configuration) { + super.onConfigurationChanged(newConfig) + // Android's Bold text setting is part of the configuration; the letters follow a new + // one as a TextView does. + regularTypeface = withBoldText(Typeface.DEFAULT) + boldTypeface = withBoldText(Typeface.create(Typeface.DEFAULT, Typeface.BOLD)) + bubbleTextPaint.typeface = boldTypeface + invalidate() + } + // ---- Drawing ----------------------------------------------------------------------------- override fun onDraw(canvas: Canvas) { @@ -331,7 +401,7 @@ class WaveAlphabetView( // Letters keep their size in the wave, so close neighbours never collide; the // selected one is bold and a touch larger. Its large copy is in the bubble. paint.textSize = restingLetterSize * (1f + (if (isSelected) SELECTED_GROWTH * press else 0f)) - paint.typeface = if (isSelected) boldTypeface else Typeface.DEFAULT + paint.typeface = if (isSelected) boldTypeface else regularTypeface paint.color = if (isSelected) { activeColor } else { @@ -387,20 +457,52 @@ class WaveAlphabetView( private fun bell(distance: Float): Float = exp(-distance * distance) + /** + * [typeface] made heavier by Android's Bold text setting (Android 12 and newer), as Android + * does for the text of a TextView but not for text drawn on a canvas. + */ + private fun withBoldText(typeface: Typeface): Typeface { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) return typeface + val adjustment = res.configuration.fontWeightAdjustment + if (adjustment == 0 || adjustment == Configuration.FONT_WEIGHT_ADJUSTMENT_UNDEFINED) return typeface + val weight = (typeface.weight + adjustment).coerceIn(FontStyle.FONT_WEIGHT_MIN, FontStyle.FONT_WEIGHT_MAX) + return Typeface.create(typeface, weight, typeface.isItalic) + } + // ---- Touch ------------------------------------------------------------------------------- /** True when a touch at this point, in this view's coordinates, starts a scrub. */ fun isOnStrip(x: Float, y: Float): Boolean = appsView.isInAllApps && !appsView.isSearching && isOnStripBand(x, y) - /** - * True when this point lies on the band along the edge that the letters occupy, whether or - * not the drawer is open. Scrub from home (PRD AD-10) asks this while the drawer is closed. - */ + /** True when this point lies on the band along the edge that the letters occupy. */ fun isOnStripBand(x: Float, y: Float): Boolean = isOnBand(x, y, touchWidth) - /** The same for the home screen, where the band is narrower because nothing shows it. */ - fun isOnHomeBand(x: Float, y: Float): Boolean = isOnBand(x, y, homeTouchWidth) + /** + * The same for the home screen, where the band is narrower because nothing shows it. The + * drawer is closed then: it may not have been laid out since the launcher started, or it + * was last laid out for another screen size or other insets. So the band is worked out + * afresh from the drag layer the drawer fills, with the same maths that places the letters. + */ + fun isOnHomeBand(x: Float, y: Float): Boolean { + // The letters are read afresh as well: a closed drawer lays its list out again only when + // it opens, so a change to the apps may bring no layout that reads them. When the + // launcher starts, its apps arrive after the home screen's first layout; without this + // the band would be missing until something else is laid out, and an app installed or + // removed later would leave it a slot too long or too short. + refreshIfChanged() + val dragLayer = appsView.parent as? View ?: return false + val frame = expectedFrame(dragLayer) + val strip = placeStrip(frame.height().toFloat(), listTop(), bottomInset()) ?: return false + // The point is measured from where this view was last laid out in the drag layer, + // which is the drag layer's corner until the drawer's first layout. + val dragX = x + left + appsView.left + val dragY = y + top + appsView.top + val onEdge = if (onLeft) dragX <= frame.left + homeTouchWidth else dragX >= frame.right - homeTouchWidth + val bandTop = frame.top + strip.top - verticalMargin + val bandBottom = frame.top + strip.top + strip.spacing * letters.size + verticalMargin + return onEdge && dragY >= bandTop && dragY <= bandBottom + } private fun isOnBand(x: Float, y: Float, bandWidth: Float): Boolean { if (layoutDirty) computeLayout() @@ -518,6 +620,9 @@ class WaveAlphabetView( /** Moves the finger of a scrub started with [beginScrub]. */ fun moveScrub(x: Float, y: Float) { if (!scrubbing || letters.isEmpty()) return + // A scrub from home begins while the drawer is hidden. Once the drawer has been laid out, + // the finger is measured from this view's new place, and the letters are placed to match. + if (layoutDirty) computeLayout() fingerX = x fingerY = y.coerceIn(stripTop, stripBottom) @@ -555,12 +660,21 @@ class WaveAlphabetView( layoutManager.scrollToPositionWithOffset(0, 0) return } + // The last letter's group runs to the end of the list, or to where Private Space starts + // if the list has it: the strip has no stop for Private Space, but its rows are not the + // letter's. val groupEnd = letters.getOrNull(index + 1)?.adapterPosition + ?: rv.apps?.fastScrollerSections + ?.firstOrNull { it.position > letter.adapterPosition && it.sectionName.isNullOrBlank() } + ?.position ?: rv.adapter?.itemCount ?: (letter.adapterPosition + 2) val rows = (groupEnd - letter.adapterPosition - 1).coerceAtLeast(1) val groupHeight = headerHeight + rows * FlexeraDrawer.rowHeight(context) - val top = max(rv.height * GROUP_HIGHEST_TOP, rv.height * GROUP_MIDDLE - groupHeight / 2f) + // Before the drawer is first shown its list has no height yet; it will be as tall as + // the edge the letters are placed on. + val listHeight = (if (rv.height > 0) rv.height else edgeHeight).toFloat() + val top = max(listHeight * GROUP_HIGHEST_TOP, listHeight * GROUP_MIDDLE - groupHeight / 2f) layoutManager.scrollToPositionWithOffset( letter.adapterPosition, (top - rv.paddingTop).toInt().coerceAtLeast(0), diff --git a/lawnchair/src/app/lawnchair/DeviceProfileOverrides.kt b/lawnchair/src/app/lawnchair/DeviceProfileOverrides.kt index c20c3671af..2b91001004 100644 --- a/lawnchair/src/app/lawnchair/DeviceProfileOverrides.kt +++ b/lawnchair/src/app/lawnchair/DeviceProfileOverrides.kt @@ -171,9 +171,9 @@ class DeviceProfileOverrides @Inject constructor( if (foldableDatabaseHotseatIcons > 0) { idp.numDatabaseHotseatIcons = foldableDatabaseHotseatIcons } - if (foldableDatabaseAllAppsColumns > 0) { - idp.numDatabaseAllAppsColumns = foldableDatabaseAllAppsColumns - } + // Flexera Launcher: no foldable override for the drawer's columns. Two-panel mode (an + // unfolded foldable) takes them from numDatabaseAllAppsColumns, and the drawer is one + // column there too (set above). // Ensure database can hold enough icons for multi-row / multi-page dock val requiredSlots = idp.numShownHotseatIcons * numHotseatRows * numDockPages diff --git a/lawnchair/src/app/lawnchair/LawnchairLauncher.kt b/lawnchair/src/app/lawnchair/LawnchairLauncher.kt index 05a5acc0ca..506815b27d 100644 --- a/lawnchair/src/app/lawnchair/LawnchairLauncher.kt +++ b/lawnchair/src/app/lawnchair/LawnchairLauncher.kt @@ -120,7 +120,11 @@ class LawnchairLauncher : QuickstepLauncher() { private val rememberPositionStateListener = object : StateManager.StateListener { override fun onStateTransitionStart(toState: LauncherState) { if (toState is AllAppsState) { - mAppsView.activeRecyclerView.restoreScrollPosition() + // Flexera Launcher: note where the list stands rather than send it back to where a + // finger last left it. Nothing moves a closed drawer's list while it remembers its + // place, so the list is still where it was left, a letter chosen on the alphabet + // included. A scrub from a swipe that was a mistake goes back to this note. + mAppsView.activeRecyclerView.saveScrollPosition() } } override fun onStateTransitionComplete(finalState: LauncherState) {} diff --git a/lawnchair/src/app/lawnchair/allapps/AllAppsSearchInput.kt b/lawnchair/src/app/lawnchair/allapps/AllAppsSearchInput.kt index 79e1f3a6d5..851a0edba5 100644 --- a/lawnchair/src/app/lawnchair/allapps/AllAppsSearchInput.kt +++ b/lawnchair/src/app/lawnchair/allapps/AllAppsSearchInput.kt @@ -191,7 +191,7 @@ class AllAppsSearchInput(context: Context, attrs: AttributeSet?) : } // Flexera Launcher: the drawer has no background panel, so the search field keeps - // its own pill while typing; without it the dark text sits on the wallpaper. + // its own pill while typing; without it the text sits on the wallpaper. val backgroundAlpha by animateIntAsState( if ((isFocused || !queryEmpty) && !app.flexera.drawer.FlexeraDrawer.KEEP_SEARCH_FIELD_BACKGROUND) 0 else 100, ) @@ -242,7 +242,10 @@ class AllAppsSearchInput(context: Context, attrs: AttributeSet?) : }, ) - LawnchairTheme { + // Flexera Launcher: dark, as the field is inflated with the dark theme + // (LawnchairSearchUiDelegate). The light scheme's press ripple is dark and did not + // show on the dark pill. + LawnchairTheme(darkTheme = true) { ProvideLifecycleState { LawnQsbUi( state = state, diff --git a/lawnchair/src/app/lawnchair/override/CustomizeDialog.kt b/lawnchair/src/app/lawnchair/override/CustomizeDialog.kt index d796c966fc..99bde80175 100644 --- a/lawnchair/src/app/lawnchair/override/CustomizeDialog.kt +++ b/lawnchair/src/app/lawnchair/override/CustomizeDialog.kt @@ -51,6 +51,7 @@ import app.lawnchair.util.navigationBarsOrDisplayCutoutPadding import com.android.launcher3.LauncherAppState import com.android.launcher3.LauncherState import com.android.launcher3.R +import com.android.launcher3.pm.UserCache import com.android.launcher3.util.ComponentKey import com.google.accompanist.drawablepainter.rememberDrawablePainter import kotlinx.coroutines.launch @@ -190,6 +191,10 @@ fun CustomizeAppDialog( description = componentKey.componentName.flattenToString(), showDescription = showComponentNames, ) { + // Flexera Launcher: no switch for an app in Private Space. The list's Private Space + // section ignores the hidden list, so the app would stay in view; locking the space is + // what hides its apps. "Hide app" (app.flexera.drawer.HideApp) leaves them out too. + if (UserCache.INSTANCE.get(context).getUserInfo(componentKey.user).isPrivate) return@PreferenceGroup val stringKey = componentKey.toString() SwitchPreference( checked = hiddenApps.contains(stringKey), diff --git a/lawnchair/src/app/lawnchair/search/LawnchairSearchAdapterProvider.kt b/lawnchair/src/app/lawnchair/search/LawnchairSearchAdapterProvider.kt index cba5461694..990e82413c 100644 --- a/lawnchair/src/app/lawnchair/search/LawnchairSearchAdapterProvider.kt +++ b/lawnchair/src/app/lawnchair/search/LawnchairSearchAdapterProvider.kt @@ -38,6 +38,11 @@ class LawnchairSearchAdapterProvider( append(SEARCH_RESULT_EMPTY_STATE, R.layout.search_result_empty_state) append(SEARCH_RESULT_SEARCH_SETTINGS, R.layout.search_result_search_settings) } + + // Flexera Launcher: the results lie on the drawer's backdrop, which is dark whatever the theme, + // so they are inflated with the dark theme (FlexeraDrawer.backdropContext). + private val resultContext by lazy { app.flexera.drawer.FlexeraDrawer.backdropContext(appsView.context) } + private var quickLaunchItem: SearchResultView? = null set(value) { field = value @@ -69,7 +74,8 @@ class LawnchairSearchAdapterProvider( parent: ViewGroup?, viewType: Int, ): BaseAllAppsAdapter.ViewHolder { - val view = layoutInflater.inflate(layoutIdMap[viewType], parent, false) + // Flexera Launcher: in the dark theme; see resultContext. + val view = layoutInflater.cloneInContext(resultContext).inflate(layoutIdMap[viewType], parent, false) val grid: DeviceProfile = mLauncher.deviceProfile val leftMargin = grid.allAppsPadding.left val rightMargin = grid.allAppsPadding.right diff --git a/lawnchair/src/app/lawnchair/search/LawnchairSearchUiDelegate.kt b/lawnchair/src/app/lawnchair/search/LawnchairSearchUiDelegate.kt index f956c66b01..39aeb2c7fd 100644 --- a/lawnchair/src/app/lawnchair/search/LawnchairSearchUiDelegate.kt +++ b/lawnchair/src/app/lawnchair/search/LawnchairSearchUiDelegate.kt @@ -1,5 +1,7 @@ package app.lawnchair.search +import android.view.View +import com.android.launcher3.R import com.android.launcher3.allapps.ActivityAllAppsContainerView import com.android.launcher3.allapps.search.AllAppsSearchUiDelegate import com.android.launcher3.allapps.search.SearchAdapterProvider @@ -10,4 +12,12 @@ class LawnchairSearchUiDelegate(private val appsView: ActivityAllAppsContainerVi override fun createMainAdapterProvider(): SearchAdapterProvider<*> { return LawnchairSearchAdapterProvider(ActivityContext.lookupContext(appsView.context), appsView) } + + // Flexera Launcher: the search field lies on the drawer's backdrop, which is dark whatever the + // theme, so it is inflated with the dark theme, like the results (FlexeraDrawer.backdropContext). + // In the light theme its grey placeholder could hardly be read on the pill. The field makes the + // search algorithm with its own context, so the cards and icons the search draws are dark too. + override fun inflateSearchBar(): View = layoutInflater + .cloneInContext(app.flexera.drawer.FlexeraDrawer.backdropContext(appsView.context)) + .inflate(R.layout.search_container_all_apps, appsView, false) } diff --git a/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/NoButtonNavbarToOverviewTouchController.java b/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/NoButtonNavbarToOverviewTouchController.java index 0438abf3c5..5378661e3b 100644 --- a/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/NoButtonNavbarToOverviewTouchController.java +++ b/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/NoButtonNavbarToOverviewTouchController.java @@ -141,7 +141,8 @@ public class NoButtonNavbarToOverviewTouchController extends PortraitStatesTouch if (threeButtons && !mLauncher.isInState(NORMAL)) { return false; } - // The buttons own the navigation bar, so a touch never counts as starting on it. + // Flexera Launcher: the buttons own the navigation bar, so a touch never counts as + // starting on it. mDidTouchStartInNavBar = !threeButtons && (ev.getEdgeFlags() & EDGE_NAV_BAR) != 0; boolean isOneHandedModeActive = (SystemUiProxy.INSTANCE.get(mLauncher) .getLastSystemUiStateFlags() & SYSUI_STATE_ONE_HANDED_ACTIVE) != 0; @@ -321,8 +322,6 @@ public class NoButtonNavbarToOverviewTouchController extends PortraitStatesTouch } mFlexeraScrubStarted = true; mFlexeraScrubStartTime = SystemClock.uptimeMillis(); - app.flexera.drawer.FlexeraDrawer.scrubFromSwipe( - mLauncher.getAppsView(), mLauncher.getDragLayer(), mFlexeraLastX, mFlexeraLastY); // Play the swipe's own animation to its end, as lifting the finger would, only faster. // Going through the state manager instead would take its full 600 ms opening time. @@ -338,6 +337,12 @@ public class NoButtonNavbarToOverviewTouchController extends PortraitStatesTouch Utilities.boundToRange(mCurrentAnimation.getProgressFraction(), 0f, 1f), 1f); anim.setDuration(FLEXERA_HOLD_OPEN_MS).setInterpolator(DECELERATE); mCurrentAnimation.dispatchOnStart(); + // The alphabet takes the finger only after the drawer's start has gone out again, as in + // scrub from home. With Remember position on, the start notes where the list stands, + // which is where a hold let go at once sends it back to, so the note is taken before + // the scrub's first jump. + app.flexera.drawer.FlexeraDrawer.scrubFromSwipe( + mLauncher.getAppsView(), mLauncher.getDragLayer(), mFlexeraLastX, mFlexeraLastY); anim.start(); VibratorWrapper.INSTANCE.get(mLauncher).vibrate(OVERVIEW_HAPTIC); } diff --git a/src/com/android/launcher3/BubbleTextView.java b/src/com/android/launcher3/BubbleTextView.java index 7d8d75f177..18f3c77831 100644 --- a/src/com/android/launcher3/BubbleTextView.java +++ b/src/com/android/launcher3/BubbleTextView.java @@ -659,6 +659,11 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver, AccessibilityNodeInfoCompat.ACTION_CLICK, getContext().getString(R.string.app_unarchiving_action))); } + // Flexera Launcher: screen readers also read a drawer row's notification preview + // (PRD AD-11), which the description alone leaves out. + if (mDisplay == DISPLAY_ALL_APPS) { + app.flexera.drawer.FlexeraNotificationPreview.describe(this, info); + } } /** This is used for testing to forcefully set the display. */ @@ -857,6 +862,11 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver, protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); checkForEllipsis(); + // Flexera Launcher: a drawer row with a notification preview fits the app name to its + // width, which a row bound before its first layout did not know yet (PRD AD-11). + if (mDisplay == DISPLAY_ALL_APPS) { + app.flexera.drawer.FlexeraNotificationPreview.onSizeChanged(this); + } } @Override diff --git a/src/com/android/launcher3/FastScrollRecyclerView.java b/src/com/android/launcher3/FastScrollRecyclerView.java index 976469242e..951442da45 100644 --- a/src/com/android/launcher3/FastScrollRecyclerView.java +++ b/src/com/android/launcher3/FastScrollRecyclerView.java @@ -26,6 +26,7 @@ import android.view.accessibility.AccessibilityNodeInfo; import androidx.annotation.Nullable; import androidx.constraintlayout.widget.ConstraintLayout; +import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import com.android.launcher3.compat.AccessibilityManagerCompat; @@ -47,6 +48,12 @@ public abstract class FastScrollRecyclerView extends RecyclerView { private int savedScrollPosition = RecyclerView.NO_POSITION; + // Flexera Launcher: the saved place once more, as the first item the list had laid out and + // how far that item's top lay from the list's top padding. The list can be sent back to + // this. savedScrollPosition is in pixels, and stays so for the header, which reads it. + private int savedItemPosition = 0; + private int savedItemOffset = 0; + private final PreferenceManager2 pref2; public FastScrollRecyclerView(Context context) { @@ -99,9 +106,22 @@ public abstract class FastScrollRecyclerView extends RecyclerView { * Saved the scroll position */ public void saveScrollPosition() { - savedScrollPosition = PreferenceCacheExtensionsKt.firstCached(pref2.getRememberPosition()) - ? computeVerticalScrollOffset() - : 0; + boolean remember = PreferenceCacheExtensionsKt.firstCached(pref2.getRememberPosition()); + savedScrollPosition = remember ? computeVerticalScrollOffset() : 0; + // Flexera Launcher: note the first item the list has laid out and where its top is, as + // LinearLayoutManager does to restore itself. Without Remember position, or with no + // items laid out, the place is the top. + RecyclerView.LayoutManager layoutManager = getLayoutManager(); + View first = remember && layoutManager != null ? layoutManager.getChildAt(0) : null; + int position = first == null ? RecyclerView.NO_POSITION : layoutManager.getPosition(first); + if (position == RecyclerView.NO_POSITION) { + savedItemPosition = 0; + savedItemOffset = 0; + } else { + savedItemPosition = position; + savedItemOffset = layoutManager.getDecoratedTop(first) - getPaddingTop() + - ((RecyclerView.LayoutParams) first.getLayoutParams()).topMargin; + } } /** @@ -109,10 +129,29 @@ public abstract class FastScrollRecyclerView extends RecyclerView { */ public void restoreScrollPosition() { if (savedScrollPosition != RecyclerView.NO_POSITION) { - scrollToPosition(savedScrollPosition); + // Flexera Launcher: to the saved item, not to the item whose number is the offset. + scrollToSavedItem(); } } + /** + * Flexera Launcher: puts the item noted by saveScrollPosition back where it was. + * scrollToPosition cannot: given the pixel offset, as it was, it sent the list to an + * unrelated item, or nowhere once the offset passed the number of items; given the item, + * it only brings it into view, at whichever end of the list is nearer. + */ + private void scrollToSavedItem() { + if (!(getLayoutManager() instanceof LinearLayoutManager)) { + scrollToPosition(savedItemPosition); + return; + } + // Stop a fling first, as scrollToPosition does. Stopping it saves the place where it + // stopped, so with Remember position on a list that was still moving stays there. + stopScroll(); + ((LinearLayoutManager) getLayoutManager()) + .scrollToPositionWithOffset(savedItemPosition, savedItemOffset); + } + /** * Returns the available scroll height: * AvailableScrollHeight = Total height of the all items - last page height @@ -232,6 +271,8 @@ public abstract class FastScrollRecyclerView extends RecyclerView { mScrollbar.reattachThumbToScroll(); } saveScrollPosition(); - scrollToPosition(savedScrollPosition); + // Flexera Launcher: likewise to the item just noted. That is the top, unless the list + // remembers its place, and then it stays where it is. + scrollToSavedItem(); } } diff --git a/src/com/android/launcher3/allapps/AllAppsGridAdapter.java b/src/com/android/launcher3/allapps/AllAppsGridAdapter.java index 0105523808..60f1d998f6 100644 --- a/src/com/android/launcher3/allapps/AllAppsGridAdapter.java +++ b/src/com/android/launcher3/allapps/AllAppsGridAdapter.java @@ -152,8 +152,11 @@ public class AllAppsGridAdapter extends return; } LayoutParams glp = (LayoutParams) lp; + // Flexera Launcher: no lower than 0, as for the scroll positions above. A letter + // header takes the place of the app before it, and the first header has none. info.setCollectionItemInfo(AccessibilityNodeInfoCompat.CollectionItemInfoCompat.obtain( - cic.getRowIndex() - getRowsNotForAccessibility(glp.getViewAdapterPosition()), + Math.max(0, cic.getRowIndex() + - getRowsNotForAccessibility(glp.getViewAdapterPosition())), cic.getRowSpan(), cic.getColumnIndex(), cic.getColumnSpan(), @@ -168,7 +171,10 @@ public class AllAppsGridAdapter extends */ private int getRowsNotForAccessibility(int adapterPosition) { List items = mApps.getAdapterItems(); - adapterPosition = Math.max(adapterPosition, items.size() - 1); + // Flexera Launcher: min, not max. With max, every position had all of the list's + // non-app rows taken off, a header per letter here, so the positions TalkBack reads + // were too low by that many, and negative near the top. + adapterPosition = Math.min(adapterPosition, items.size() - 1); int extraRows = 0; for (int i = 0; i <= adapterPosition && i < items.size(); i++) { if (!isViewType(items.get(i).viewType, VIEW_TYPE_MASK_ICON)) { diff --git a/src/com/android/launcher3/allapps/AllAppsStore.java b/src/com/android/launcher3/allapps/AllAppsStore.java index e9b59dfbc1..ca56ff3119 100644 --- a/src/com/android/launcher3/allapps/AllAppsStore.java +++ b/src/com/android/launcher3/allapps/AllAppsStore.java @@ -17,6 +17,8 @@ package com.android.launcher3.allapps; import static com.android.launcher3.model.data.AppInfo.COMPONENT_KEY_COMPARATOR; import static com.android.launcher3.model.data.AppInfo.EMPTY_ARRAY; +import static com.android.launcher3.model.data.ItemInfoWithIcon.FLAG_ARCHIVED; +import static com.android.launcher3.model.data.ItemInfoWithIcon.FLAG_SHOW_DOWNLOAD_PROGRESS_MASK; import android.content.Context; import android.os.UserHandle; @@ -26,10 +28,13 @@ import android.view.ViewGroup; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.recyclerview.widget.RecyclerView; import com.android.launcher3.BubbleTextView; +import com.android.launcher3.R; import com.android.launcher3.model.data.AppInfo; import com.android.launcher3.model.data.ItemInfo; +import com.android.launcher3.model.data.ItemInfoWithIcon; import com.android.launcher3.recyclerview.AllAppsRecyclerViewPool; import com.android.launcher3.util.ComponentKey; import com.android.launcher3.util.PackageUserKey; @@ -73,6 +78,33 @@ public class AllAppsStore { private boolean mUpdatePending = false; private final AllAppsRecyclerViewPool mAllAppsRecyclerViewPool = new AllAppsRecyclerViewPool(); + // Flexera Launcher: an app row of the drawer list that scrolls back from the list's cache of + // views is attached again without being bound. Dot and notification preview (PRD AD-11) + // updates reach attached rows only, so a row that has a dot, or should have one now, looks + // at both again whenever it is attached, which is also right after it is bound. Binding + // describes a download, or an archived app, after the dot, so such a row keeps the + // description it has. Rows without a dot are left as bound. + private final RecyclerView.OnChildAttachStateChangeListener mDotRefresher = + new RecyclerView.OnChildAttachStateChangeListener() { + @Override + public void onChildViewAttachedToWindow(@NonNull View view) { + if (view instanceof BubbleTextView icon + && icon.getTag(R.id.flexera_drawer_row) != null + && icon.getTag() instanceof ItemInfoWithIcon info + && (icon.hasDot() || mContext.getDotInfoForItem(info) != null)) { + CharSequence description = icon.getContentDescription(); + icon.applyDotState(info, false /* animate */); + if ((info.runtimeStatusFlags + & (FLAG_ARCHIVED | FLAG_SHOW_DOWNLOAD_PROGRESS_MASK)) != 0) { + icon.setContentDescription(description); + } + } + } + + @Override + public void onChildViewDetachedFromWindow(@NonNull View view) { } + }; + private final T mContext; public AppInfo[] getApps() { @@ -207,11 +239,19 @@ public class AllAppsStore { public void registerIconContainer(ViewGroup container) { if (container != null && !mIconContainers.contains(container)) { mIconContainers.add(container); + // Flexera Launcher: see mDotRefresher. + if (container instanceof RecyclerView list) { + list.addOnChildAttachStateChangeListener(mDotRefresher); + } } } public void unregisterIconContainer(ViewGroup container) { mIconContainers.remove(container); + // Flexera Launcher: see mDotRefresher. + if (container instanceof RecyclerView list) { + list.removeOnChildAttachStateChangeListener(mDotRefresher); + } } public void updateNotificationDots(Predicate updatedDots) { @@ -225,6 +265,20 @@ public class AllAppsStore { }); } + /** + * Flexera Launcher: shows the latest notification text again under the names of the matching + * rows of the drawer list (PRD AD-11), leaving their dots alone. + */ + public void updateNotificationPreviews(Predicate updatedPreviews) { + updateAllIcons((child) -> { + if (child.getTag() instanceof ItemInfo info + && mTempKey.updateFromItemInfo(info) && updatedPreviews.test(mTempKey)) { + app.flexera.drawer.FlexeraNotificationPreview.apply( + child, info, mContext.getDotInfoForItem(info)); + } + }); + } + /** * Sets the AppInfo's associated icon's progress bar. * diff --git a/src/com/android/launcher3/notification/NotificationListener.java b/src/com/android/launcher3/notification/NotificationListener.java index 3f34400fdc..f6fb62731e 100644 --- a/src/com/android/launcher3/notification/NotificationListener.java +++ b/src/com/android/launcher3/notification/NotificationListener.java @@ -130,10 +130,12 @@ public class NotificationListener extends NotificationListenerService { case MSG_NOTIFICATION_POSTED: { StatusBarNotification sbn = (StatusBarNotification) message.obj; // Flexera Launcher: keep the text for the drawer's notification previews in step - // with the dots, before the rows are told to refresh (PRD AD-11). + // with the dots, before the rows are told to refresh (PRD AD-11). The ranking + // tells how much of a work profile's notification Android shows while locked. boolean validForUi = notificationIsValidForUI(sbn); if (validForUi) { - app.flexera.drawer.FlexeraNotificationPreview.onPosted(sbn); + app.flexera.drawer.FlexeraNotificationPreview.onPosted( + sbn, getCurrentRanking()); } else { app.flexera.drawer.FlexeraNotificationPreview.onRemoved(sbn); } @@ -169,7 +171,8 @@ public class NotificationListener extends NotificationListenerService { activeNotifications = new ArrayList<>(); } // Flexera Launcher: rebuild the preview texts from the same list as the dots. - app.flexera.drawer.FlexeraNotificationPreview.onFullRefresh(activeNotifications); + app.flexera.drawer.FlexeraNotificationPreview.onFullRefresh( + activeNotifications, getCurrentRanking()); mUiHandler.obtainMessage(message.what, activeNotifications).sendToTarget(); return true; diff --git a/src/com/android/launcher3/popup/PopupDataProvider.java b/src/com/android/launcher3/popup/PopupDataProvider.java index a0e41ea45a..c5a3041e6a 100644 --- a/src/com/android/launcher3/popup/PopupDataProvider.java +++ b/src/com/android/launcher3/popup/PopupDataProvider.java @@ -94,6 +94,18 @@ public class PopupDataProvider implements NotificationListener.NotificationsChan } } + /** + * Flexera Launcher: shows the latest notification text again under the names of the matching + * apps in the drawer list (PRD AD-11). Dots stay as they are, and only the rows whose text + * changes are redrawn. + */ + private void updateNotificationPreviews(Predicate packages) { + ActivityAllAppsContainerView appsView = mContext.getAppsView(); + if (appsView != null) { + appsView.getAppsStore().updateNotificationPreviews(packages); + } + } + @Override public void onNotificationPosted(PackageUserKey postedPackageUserKey, NotificationKeyData notificationKey) { @@ -102,11 +114,13 @@ public class PopupDataProvider implements NotificationListener.NotificationsChan dotInfo = new DotInfo(); mPackageUserToDotInfos.put(postedPackageUserKey, dotInfo); } - // Flexera Launcher: refresh the app's icons on every posted notification, not only when - // the dot or its count changes. A notification that is updated in place keeps its dot - // but brings new text for the drawer's preview line (PRD AD-11). - dotInfo.addOrUpdateNotificationKey(notificationKey); - updateNotificationDots(postedPackageUserKey::equals); + if (dotInfo.addOrUpdateNotificationKey(notificationKey)) { + updateNotificationDots(postedPackageUserKey::equals); + } else { + // Flexera Launcher: a notification that is updated in place keeps its dot as it is, + // but can bring new text for the drawer's preview line (PRD AD-11). + updateNotificationPreviews(postedPackageUserKey::equals); + } } @Override @@ -155,6 +169,10 @@ public class PopupDataProvider implements NotificationListener.NotificationsChan if (!updatedDots.isEmpty()) { updateNotificationDots(updatedDots::containsKey); } + // Flexera Launcher: while the launcher was in the background, a notification may have + // been updated in place, or swapped for another, leaving its app's count as it was. The + // drawer's preview line would then keep the old text (PRD AD-11). + updateNotificationPreviews(mPackageUserToDotInfos::containsKey); } public void setDeepShortcutMap(HashMap deepShortcutMapCopy) {