Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
494364ffa2 | ||
|
|
80a56c01c9 | ||
|
|
043e1e0c4a | ||
|
|
d82d488189 | ||
|
|
8894271daa | ||
|
|
3cb262617c | ||
|
|
0959f36587 | ||
|
|
8aba905d9c | ||
|
|
60d00afcfd | ||
|
|
74becdd355 | ||
|
|
4771d2928a | ||
|
|
1f9116d666 | ||
|
|
4e48615b5a | ||
|
|
f92276da15 | ||
|
|
9d444ae2d0 | ||
|
|
d814125a66 | ||
|
|
c9744a1994 |
No files matched your search
@@ -494,6 +494,8 @@ dependencies {
|
||||
implementation libs.kdrag0n.colorkt
|
||||
implementation libs.coil.compose
|
||||
implementation libs.xdrop.fuzzywuzzy
|
||||
// Flexera Launcher: encodes the QR code on the About screen. Nothing else of it is used.
|
||||
implementation libs.zxing.core
|
||||
|
||||
implementation libs.bundles.opto
|
||||
implementation libs.androidx.datastore.preferences
|
||||
|
||||
+87
-18
@@ -5,17 +5,20 @@
|
||||
.DESCRIPTION
|
||||
One command per release. It
|
||||
1. writes the new version to flexera/version.properties and commits it,
|
||||
2. builds the signed release APK,
|
||||
2. builds the signed release APK, compiling the Kotlin code from scratch,
|
||||
3. checks that the APK is signed with the release key (not the debug key),
|
||||
4. creates the release "v<version>" in https://git.mariosem.es/msemes/Flexera-Launcher-Releases
|
||||
and attaches the APK, and
|
||||
5. tags the source commit it was built from.
|
||||
4. installs the APK on the running Android emulator, starts it and looks for a crash,
|
||||
5. creates the release "v<version>" in https://git.mariosem.es/msemes/Flexera-Launcher-Releases,
|
||||
6. attaches the APK to it, and
|
||||
7. tags the source commit it was built from.
|
||||
|
||||
Installed copies of the app look at that repository once a day (app.flexera.update.FlexeraUpdater)
|
||||
and offer the new version.
|
||||
and offer the new version. A release that crashes at start would therefore reach the phone on
|
||||
its own, which is why step 4 exists and why nothing is published when it fails.
|
||||
|
||||
Needs: keystore.properties and the keystore it names in the project root (both are git-ignored;
|
||||
without them the script stops), and the git login for git.mariosem.es that git already has stored.
|
||||
without them the script stops), the git login for git.mariosem.es that git already has stored,
|
||||
and a running emulator for step 4 (start it with: emulator.exe -avd Flexera_Launcher_A17).
|
||||
|
||||
.PARAMETER Version
|
||||
The new version, as major.minor.patch (for example 0.2.0). Must be higher than the last release.
|
||||
@@ -26,8 +29,15 @@
|
||||
.PARAMETER NotesFile
|
||||
A text file with the notes, as an alternative to -Notes.
|
||||
|
||||
.PARAMETER BuildOnly
|
||||
Stop after step 4, without publishing. Try the APK by hand, then run the script again with
|
||||
-SkipBuild to publish that same file.
|
||||
|
||||
.PARAMETER SkipBuild
|
||||
Publish the APK that is already in build\outputs instead of building again.
|
||||
Use the APK that is already in build\outputs instead of building again.
|
||||
|
||||
.PARAMETER NoSmokeTest
|
||||
Skip step 4. Only for a machine without an emulator; try the APK on a phone yourself first.
|
||||
|
||||
.PARAMETER AllowDirty
|
||||
Release even though there are uncommitted changes. The APK then matches no commit exactly.
|
||||
@@ -37,12 +47,18 @@
|
||||
|
||||
.EXAMPLE
|
||||
.\flexera\release.ps1 -Version 0.2.0 -Notes "The alphabet follows the finger more closely."
|
||||
|
||||
.EXAMPLE
|
||||
.\flexera\release.ps1 -Version 0.2.0 -BuildOnly
|
||||
.\flexera\release.ps1 -Version 0.2.0 -SkipBuild -Notes "The alphabet follows the finger more closely."
|
||||
#>
|
||||
param(
|
||||
[Parameter(Mandatory = $true)][string]$Version,
|
||||
[string]$Notes = "",
|
||||
[string]$NotesFile,
|
||||
[switch]$BuildOnly,
|
||||
[switch]$SkipBuild,
|
||||
[switch]$NoSmokeTest,
|
||||
[switch]$AllowDirty,
|
||||
[switch]$PushSource
|
||||
)
|
||||
@@ -53,8 +69,13 @@ $Server = 'https://git.mariosem.es'
|
||||
$GitHost = 'git.mariosem.es'
|
||||
$ReleaseRepository = 'msemes/Flexera-Launcher-Releases'
|
||||
$Api = "$Server/api/v1/repos/$ReleaseRepository"
|
||||
$VariantDir = 'lawnWithQuickstepGithubRelease'
|
||||
$Variant = 'LawnWithQuickstepGithubRelease'
|
||||
$AppId = 'com.sema.flexeralauncher'
|
||||
$HomeActivity = "$AppId/app.lawnchair.LawnchairLauncher"
|
||||
$JavaHome = 'C:\Program Files\Android\Android Studio\jbr'
|
||||
$Adb = Join-Path $env:LOCALAPPDATA 'Android\Sdk\platform-tools\adb.exe'
|
||||
$SmokeTestSeconds = 25
|
||||
|
||||
$Root = Split-Path -Parent $PSScriptRoot
|
||||
Set-Location $Root
|
||||
@@ -89,7 +110,7 @@ function Read-Response($response, [string]$what) {
|
||||
|
||||
# --- 1. Version ----------------------------------------------------------------------------------
|
||||
|
||||
Step "1/6 Version $Version"
|
||||
Step "1/7 Version $Version"
|
||||
|
||||
if ($Version -notmatch '^\d+\.\d{1,2}\.\d{1,2}$') {
|
||||
throw "Version must look like 0.2.0 (major.minor.patch, minor and patch below 100), got '$Version'."
|
||||
@@ -136,21 +157,30 @@ if ($current -ne $Version) {
|
||||
$apk = Join-Path $Root "build\outputs\apk\lawnWithQuickstepGithub\release\FlexeraLauncher.$Version.github.release.apk"
|
||||
|
||||
if ($SkipBuild) {
|
||||
Step "2/6 Build skipped"
|
||||
Step "2/7 Build skipped"
|
||||
} else {
|
||||
Step "2/6 Building the release APK (this takes a while)"
|
||||
Step "2/7 Building the release APK (about 15 minutes)"
|
||||
if (-not (Test-Path (Join-Path $Root 'keystore.properties'))) {
|
||||
throw "keystore.properties is missing, so the APK would be signed with the debug key and could not update an installed copy."
|
||||
}
|
||||
# A release compiles its Kotlin code from scratch. Compiled output reused from an earlier
|
||||
# build has produced an APK that crashed at start after a preference class had changed
|
||||
# (NoSuchFieldError: $stable), so nothing compiled earlier is trusted here.
|
||||
Remove-Item -Recurse -Force (Join-Path $Root "build\intermediates\built_in_kotlinc\$VariantDir") -ErrorAction SilentlyContinue
|
||||
Get-ChildItem (Join-Path $Root 'build\kotlin') -Directory -Filter "compile${Variant}Kotlin*" -ErrorAction SilentlyContinue |
|
||||
Remove-Item -Recurse -Force
|
||||
$env:JAVA_HOME = $JavaHome
|
||||
cmd /c ".\gradlew.bat assemble$Variant --console=plain"
|
||||
# "2>&1" inside cmd: Gradle prints compiler warnings on its error stream. If this script's
|
||||
# output is piped or sent to a file, PowerShell would otherwise take the first such line
|
||||
# for an error and stop the build. Only the exit code says whether the build failed.
|
||||
cmd /c ".\gradlew.bat assemble$Variant --no-build-cache --console=plain 2>&1"
|
||||
if ($LASTEXITCODE -ne 0) { throw "The build failed." }
|
||||
}
|
||||
if (-not (Test-Path $apk)) { throw "Expected the APK at $apk, but it is not there." }
|
||||
|
||||
# --- 3. Signature --------------------------------------------------------------------------------
|
||||
|
||||
Step "3/6 Checking the signature"
|
||||
Step "3/7 Checking the signature"
|
||||
|
||||
$apksigner = Get-ChildItem (Join-Path $env:LOCALAPPDATA 'Android\Sdk\build-tools') -Recurse -Filter 'apksigner.bat' |
|
||||
Sort-Object FullName | Select-Object -Last 1
|
||||
@@ -163,17 +193,56 @@ if ($signer -match 'Android Debug') { throw "The APK is signed with the debug ke
|
||||
Write-Host $signer
|
||||
Write-Host ("APK: {0} ({1:N1} MB)" -f (Split-Path $apk -Leaf), ((Get-Item $apk).Length / 1MB))
|
||||
|
||||
# --- 4. Release ----------------------------------------------------------------------------------
|
||||
# --- 4. Start it once ----------------------------------------------------------------------------
|
||||
|
||||
Step "4/6 Creating release v$Version in $ReleaseRepository"
|
||||
if ($NoSmokeTest) {
|
||||
Step "4/7 Start-up check skipped"
|
||||
Write-Warning "This APK has not been started anywhere. Try it on a phone before publishing."
|
||||
} else {
|
||||
Step "4/7 Starting the APK on the emulator"
|
||||
|
||||
$emulator = & $Adb devices | Where-Object { $_ -match '^(emulator-\d+)\s+device$' } |
|
||||
ForEach-Object { $Matches[1] } | Select-Object -First 1
|
||||
if (-not $emulator) {
|
||||
throw "No running emulator found. Start one (emulator.exe -avd Flexera_Launcher_A17) and run this again with -SkipBuild, or pass -NoSmokeTest."
|
||||
}
|
||||
|
||||
$install = & $Adb -s $emulator install -r $apk
|
||||
if ($LASTEXITCODE -ne 0 -or -not ($install -match 'Success')) {
|
||||
throw "Could not install the APK on $emulator. If an older build signed with another key is installed there, uninstall it first: adb uninstall $AppId"
|
||||
}
|
||||
& $Adb -s $emulator logcat -b crash -c
|
||||
& $Adb -s $emulator shell am start -n $HomeActivity | Out-Null
|
||||
Write-Host "Installed on $emulator and started; watching for $SmokeTestSeconds seconds..."
|
||||
Start-Sleep -Seconds $SmokeTestSeconds
|
||||
|
||||
$crashes = & $Adb -s $emulator logcat -b crash -d
|
||||
$ours = $crashes | Where-Object { $_ -match "Process: $([regex]::Escape($AppId))(,|\s|$)" }
|
||||
$alive = & $Adb -s $emulator shell pidof $AppId
|
||||
if ($ours -or -not $alive) {
|
||||
$crashes | Select-Object -First 12 | ForEach-Object { Write-Host $_ }
|
||||
throw "The app crashed or is not running after start. Nothing was published."
|
||||
}
|
||||
Write-Host "No crash, and the app is running."
|
||||
}
|
||||
|
||||
if ($BuildOnly) {
|
||||
Write-Host "`nBuilt and checked, not published: $apk" -ForegroundColor Green
|
||||
Write-Host "Publish this file with: .\flexera\release.ps1 -Version $Version -SkipBuild -Notes `"...`""
|
||||
return
|
||||
}
|
||||
|
||||
# --- 5. Release ----------------------------------------------------------------------------------
|
||||
|
||||
Step "5/7 Creating release v$Version in $ReleaseRepository"
|
||||
|
||||
$body = @{ tag_name = "v$Version"; name = "Flexera Launcher $Version"; body = $Notes; draft = $false; prerelease = $false } | ConvertTo-Json
|
||||
$content = New-Object System.Net.Http.StringContent($body, [Text.Encoding]::UTF8, 'application/json')
|
||||
$release = Read-Response ($client.PostAsync("$Api/releases", $content).Result) 'Creating the release'
|
||||
|
||||
# --- 5. APK --------------------------------------------------------------------------------------
|
||||
# --- 6. APK --------------------------------------------------------------------------------------
|
||||
|
||||
Step "5/6 Uploading the APK"
|
||||
Step "6/7 Uploading the APK"
|
||||
|
||||
$assetName = "FlexeraLauncher-$Version.apk"
|
||||
$stream = [IO.File]::OpenRead($apk)
|
||||
@@ -193,9 +262,9 @@ try {
|
||||
}
|
||||
Write-Host "Uploaded: $($asset.browser_download_url)"
|
||||
|
||||
# --- 6. Source tag -------------------------------------------------------------------------------
|
||||
# --- 7. Source tag -------------------------------------------------------------------------------
|
||||
|
||||
Step "6/6 Tagging the source"
|
||||
Step "7/7 Tagging the source"
|
||||
|
||||
git tag -a "v$Version" -m "Flexera Launcher $Version"
|
||||
if ($LASTEXITCODE -ne 0) { Write-Warning "Could not create the tag v$Version (does it exist already?)." }
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<!-- Drawer list (PRD AD-2, AD-3). Rows are sized for thumb taps; 48dp is Android's minimum target. -->
|
||||
<dimen name="flexera_drawer_row_height">64dp</dimen>
|
||||
<!-- Smaller than a home-screen icon, so rows have air between them. -->
|
||||
<dimen name="flexera_drawer_row_icon_size">46dp</dimen>
|
||||
<dimen name="flexera_drawer_row_icon_gap">20dp</dimen>
|
||||
<dimen name="flexera_drawer_row_text_size">17sp</dimen>
|
||||
<!-- Drawer list (PRD AD-2, AD-3). A compact list, at the owner's request: more apps within a
|
||||
thumb's reach. The row stays just above 48dp, Android's minimum for a tap target.
|
||||
(First version: 64dp rows, 46dp icons, 17sp names.) -->
|
||||
<dimen name="flexera_drawer_row_height">50dp</dimen>
|
||||
<!-- Well under a home-screen icon, so rows have air between them. -->
|
||||
<dimen name="flexera_drawer_row_icon_size">34dp</dimen>
|
||||
<dimen name="flexera_drawer_row_icon_gap">16dp</dimen>
|
||||
<dimen name="flexera_drawer_row_text_size">15sp</dimen>
|
||||
<!-- Row padding on the edge without the wave alphabet. The search bar lines up with it. -->
|
||||
<dimen name="flexera_drawer_row_padding_start">24dp</dimen>
|
||||
<!-- Row padding on the wave alphabet's edge, which is the end edge unless the owner moves it
|
||||
@@ -18,24 +20,47 @@
|
||||
<!-- Where the letters rest, measured from the edge. -->
|
||||
<dimen name="flexera_wave_edge_inset">16dp</dimen>
|
||||
<dimen name="flexera_wave_letter_size">12sp</dimen>
|
||||
<!-- Letters never sit further apart than this, however few there are. -->
|
||||
<dimen name="flexera_wave_max_spacing">30dp</dimen>
|
||||
<!-- Letters never sit further apart than this, however few there are. Close together, a
|
||||
little closer than Niagara Launcher's, so a whole alphabet is about 83 mm tall and fits
|
||||
the stretch of edge a thumb covers without shifting the grip. (First version: 30dp,
|
||||
which spread the alphabet over the whole edge.) -->
|
||||
<dimen name="flexera_wave_max_spacing">20dp</dimen>
|
||||
<!-- The stretch of edge kept for the alphabet is as tall as 26 letters and sits low: its end
|
||||
this far above the navigation bar (on top of the vertical margin). The letters that
|
||||
exist are centred in it. -->
|
||||
<dimen name="flexera_wave_bottom_offset">40dp</dimen>
|
||||
<dimen name="flexera_wave_vertical_margin">16dp</dimen>
|
||||
<!-- How far before the finger the wave's peak sits, so the thumb never covers the letter. -->
|
||||
<dimen name="flexera_wave_finger_gap">52dp</dimen>
|
||||
<!-- How far beyond the finger the wave's peak sits, so the thumb never covers the selected
|
||||
letter. A thumb hides about 11 mm (70dp) to each side of the point it touches; the
|
||||
letter's centre has to clear that by its own half width and a margin. At 52dp, the
|
||||
first value, the letter sat under the thumb. -->
|
||||
<dimen name="flexera_wave_finger_gap">104dp</dimen>
|
||||
<!-- The smallest bulge, used when the finger is right on the edge. -->
|
||||
<dimen name="flexera_wave_min_reach">60dp</dimen>
|
||||
<!-- How far up and down the edge the bulge spreads. -->
|
||||
<dimen name="flexera_wave_width">56dp</dimen>
|
||||
<dimen name="flexera_wave_min_reach">96dp</dimen>
|
||||
<!-- How far up and down the edge the bulge spreads, at the least: wide, so that about five
|
||||
letters on each side of the finger ride the wave and curve around the thumb, as in
|
||||
Niagara Launcher. A taller wave is wider (WaveAlphabetView.WAVE_WIDTH_SHARE_OF_REACH). -->
|
||||
<dimen name="flexera_wave_width">104dp</dimen>
|
||||
<!-- The wave's peak never comes closer than this to the opposite edge of the screen. It
|
||||
leaves room for the bubble beyond the peak. -->
|
||||
<dimen name="flexera_wave_far_margin">66dp</dimen>
|
||||
<!-- The bubble with the selected letter: its size, how far beyond the wave's peak its
|
||||
centre sits, and how close it may come to a screen edge. -->
|
||||
<dimen name="flexera_wave_bubble_radius">20dp</dimen>
|
||||
<dimen name="flexera_wave_bubble_gap">38dp</dimen>
|
||||
<dimen name="flexera_wave_bubble_text_size">22sp</dimen>
|
||||
<dimen name="flexera_wave_bubble_edge_margin">6dp</dimen>
|
||||
<dimen name="flexera_wave_bubble_shadow_radius">6dp</dimen>
|
||||
|
||||
<!-- Swipe up and hold (PRD AD-17): a pause only counts once the swipe has travelled this far. -->
|
||||
<dimen name="flexera_hold_min_swipe">72dp</dimen>
|
||||
<!-- Swipe up and hold (PRD AD-17): a pause only counts once the swipe has travelled this far.
|
||||
Enough to tell a hold from a hesitant start, short enough that a small swipe counts. -->
|
||||
<dimen name="flexera_hold_min_swipe">32dp</dimen>
|
||||
|
||||
<!-- Soft shadow behind white drawer text, for readability over light wallpaper. -->
|
||||
<dimen name="flexera_drawer_text_shadow_radius">3dp</dimen>
|
||||
<dimen name="flexera_drawer_text_shadow_dy">1dp</dimen>
|
||||
|
||||
<dimen name="flexera_drawer_header_height">44dp</dimen>
|
||||
<dimen name="flexera_drawer_header_padding_bottom">6dp</dimen>
|
||||
<dimen name="flexera_drawer_header_text_size">14sp</dimen>
|
||||
<dimen name="flexera_drawer_header_height">34dp</dimen>
|
||||
<dimen name="flexera_drawer_header_padding_bottom">4dp</dimen>
|
||||
<dimen name="flexera_drawer_header_text_size">12sp</dimen>
|
||||
</resources>
|
||||
@@ -2,4 +2,8 @@
|
||||
<resources>
|
||||
<!-- The wave alphabet view inside the drawer (app.flexera.drawer.WaveAlphabetView). -->
|
||||
<item name="flexera_wave_alphabet" type="id" />
|
||||
<!-- View tag that marks an app row of the drawer list (FlexeraDrawer.styleAppRow). -->
|
||||
<item name="flexera_drawer_row" type="id" />
|
||||
<!-- View tag on a drawer row: set while the row shows a notification preview under the app name. -->
|
||||
<item name="flexera_notification_preview" type="id" />
|
||||
</resources>
|
||||
@@ -27,6 +27,41 @@
|
||||
<string name="flexera_about_built_on_title">Lawnchair</string>
|
||||
<string name="flexera_about_built_on_body">Flexera Launcher is a modified version of Lawnchair, the open-source launcher made by the Lawnchair team. Lawnchair is itself based on Launcher3 from the Android Open Source Project.</string>
|
||||
<string name="flexera_about_lawnchair_source">Lawnchair source code</string>
|
||||
<!-- Import of a Smart Launcher backup (app.flexera.backup) -->
|
||||
<string name="flexera_import_smart_launcher">Import from Smart Launcher</string>
|
||||
<string name="flexera_import_smart_launcher_description">Home screens, folders and widgets from a Smart Launcher backup file (.slbk)</string>
|
||||
<string name="flexera_import_found">In this backup</string>
|
||||
<string name="flexera_import_screens">Home screens</string>
|
||||
<string name="flexera_import_screens_value">%1$d, on a grid of %2$d by %3$d</string>
|
||||
<string name="flexera_import_apps">Apps on the home screens</string>
|
||||
<string name="flexera_import_folders">Folders</string>
|
||||
<plurals name="flexera_import_folders_value">
|
||||
<item quantity="one">%1$d, holding %2$d app</item>
|
||||
<item quantity="other">%1$d, holding %2$d apps</item>
|
||||
</plurals>
|
||||
<string name="flexera_import_widgets">Widgets</string>
|
||||
<string name="flexera_import_widgets_value">%1$d. Each arrives in its place as “tap to set up”: Android asks you to allow it again, and its own settings start fresh.</string>
|
||||
<string name="flexera_import_left_out">Left out</string>
|
||||
<string name="flexera_import_own_widgets">Widgets of Smart Launcher itself</string>
|
||||
<plurals name="flexera_import_own_widgets_value">
|
||||
<item quantity="one">%1$d. It exists only inside Smart Launcher, so its place stays empty.</item>
|
||||
<item quantity="other">%1$d. They exist only inside Smart Launcher, so their places stay empty.</item>
|
||||
</plurals>
|
||||
<string name="flexera_import_skipped">Other items</string>
|
||||
<plurals name="flexera_import_skipped_value">
|
||||
<item quantity="one">%1$d that this launcher cannot show or place</item>
|
||||
<item quantity="other">%1$d that this launcher cannot show or place</item>
|
||||
</plurals>
|
||||
<string name="flexera_import_effect">What importing does</string>
|
||||
<string name="flexera_import_effect_title">Replaces your current home screens</string>
|
||||
<string name="flexera_import_effect_body">The home screens you have now are removed. The grid takes the size it has in the backup and the dock is switched off, because Smart Launcher has none; both can be changed again in Settings. Icons of apps that are not installed on this phone are dropped. Make a backup first if you want to be able to go back.</string>
|
||||
<string name="flexera_import_action">Import</string>
|
||||
<string name="flexera_import_done">Imported</string>
|
||||
<string name="flexera_import_failed">The import failed</string>
|
||||
<string name="flexera_import_unreadable">This is not a Smart Launcher backup that can be read</string>
|
||||
<string name="flexera_about_share">Share</string>
|
||||
<string name="flexera_about_share_title">Scan to get Flexera Launcher</string>
|
||||
<string name="flexera_about_share_qr_description">QR code that opens the download page</string>
|
||||
<string name="flexera_about_privacy">Privacy</string>
|
||||
<string name="flexera_about_privacy_title">Nothing about you leaves your phone</string>
|
||||
<string name="flexera_about_privacy_body">Flexera Launcher goes online for one thing: asking its release page whether a newer version exists, about once a day, and downloading that version when you ask. It sends nothing about you, your apps or your phone.</string>
|
||||
@@ -39,10 +74,15 @@
|
||||
<!-- The drawer's wave alphabet -->
|
||||
<!-- Read by screen readers as the name of the alphabet strip, followed by the current letter -->
|
||||
<string name="flexera_alphabet_description">Alphabet</string>
|
||||
<string name="flexera_alphabet_search">Search</string>
|
||||
<!-- App drawer settings (app.flexera.ui.FlexeraDrawerSettings) -->
|
||||
<string name="flexera_notification_previews">Notification previews</string>
|
||||
<string name="flexera_notification_previews_description">Show an app\'s latest notification under its name in the app list. Works when notification dots are on (Settings, General).</string>
|
||||
<string name="flexera_alphabet_heading">Alphabet</string>
|
||||
<string name="flexera_alphabet_on_left">Alphabet on the left edge</string>
|
||||
<string name="flexera_alphabet_on_left_description">For left-handed use. The letters normally sit on the right edge.</string>
|
||||
<string name="flexera_scrub_from_home">Scrub from the home screen</string>
|
||||
<string name="flexera_scrub_from_home_description">Slide up or down along the alphabet\'s edge of the home screen to open the app list at a letter. Swipe up and hold does the same from anywhere.</string>
|
||||
|
||||
<!-- Updates section of the About screen (app.flexera.update.FlexeraUpdater) -->
|
||||
<string name="flexera_update_heading">Updates</string>
|
||||
@@ -50,7 +90,15 @@
|
||||
<string name="flexera_update_check_idle">Flexera Launcher also checks on its own, once a day</string>
|
||||
<string name="flexera_update_checking">Checking for updates…</string>
|
||||
<string name="flexera_update_up_to_date">You have the latest version</string>
|
||||
<string name="flexera_update_check_failed">Couldn\'t reach the update server. Check your connection, then tap to try again.</string>
|
||||
<!-- Why a check for updates failed. %1$s is the update server's name, such as git.example.org -->
|
||||
<string name="flexera_update_failed_no_permission">Android does not let Flexera Launcher use the network on this phone. Allow it in the phone\'s settings for this app, under Permissions, Network, then tap to try again.</string>
|
||||
<string name="flexera_update_failed_not_found">This phone could not find %1$s. Check the connection and any VPN or private DNS, then tap to try again.</string>
|
||||
<string name="flexera_update_failed_no_answer">%1$s did not answer. Check the connection and any VPN, then tap to try again.</string>
|
||||
<string name="flexera_update_failed_not_secure">A secure connection to %1$s could not be made. Check the phone\'s date and time and any VPN, then tap to try again.</string>
|
||||
<string name="flexera_update_failed_server_error">%1$s answered with an error. Tap to try again later.</string>
|
||||
<string name="flexera_update_failed_bad_answer">The answer from %1$s could not be read. Tap to try again later.</string>
|
||||
<!-- %1$s is the error in the system\'s own words, for whoever looks for the cause -->
|
||||
<string name="flexera_update_failed_detail">Details: %1$s</string>
|
||||
<!-- %1$s is a version number such as 0.2.0 -->
|
||||
<string name="flexera_update_download">Download version %1$s</string>
|
||||
<!-- %1$s is a file size such as 24 MB -->
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package app.flexera
|
||||
|
||||
import android.app.Activity
|
||||
import android.app.role.RoleManager
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import android.util.Log
|
||||
import com.android.launcher3.util.ApiWrapper
|
||||
|
||||
/**
|
||||
* First-run step (PRD SI-1): the first time the launcher is opened while another app is the
|
||||
* phone's home app, ask Android to offer Flexera Launcher as the default.
|
||||
*
|
||||
* Android shows its own dialog for this. It is asked once only. If the owner declines, Launcher3
|
||||
* shows a short hint about Android's settings, and the launcher's own settings keep a reminder
|
||||
* that leads to the same choice, so there is no need to ask again.
|
||||
*/
|
||||
object FlexeraFirstRun {
|
||||
|
||||
private const val TAG = "FlexeraFirstRun"
|
||||
private const val PREFS = "flexera_first_run"
|
||||
private const val KEY_ASKED_DEFAULT_HOME = "asked_default_home"
|
||||
|
||||
/**
|
||||
* Call once the launcher has finished resuming (its onDeferredResumed), not earlier: the
|
||||
* launcher cancels any request for a result that is pending at that point. Does nothing
|
||||
* after the first time.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun askToBecomeDefaultHome(activity: Activity) {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) return
|
||||
val prefs = activity.getSharedPreferences(PREFS, Context.MODE_PRIVATE)
|
||||
if (prefs.getBoolean(KEY_ASKED_DEFAULT_HOME, false)) return
|
||||
|
||||
val roles = activity.getSystemService(RoleManager::class.java) ?: return
|
||||
if (!roles.isRoleAvailable(RoleManager.ROLE_HOME)) return
|
||||
prefs.edit().putBoolean(KEY_ASKED_DEFAULT_HOME, true).apply()
|
||||
if (roles.isRoleHeld(RoleManager.ROLE_HOME)) return
|
||||
|
||||
try {
|
||||
// Launcher3's own way of asking: Android's consent dialog, then a short hint about
|
||||
// Android's settings if the owner declines.
|
||||
ApiWrapper.INSTANCE.get(activity).assignDefaultHomeRole(activity)
|
||||
} catch (e: Exception) {
|
||||
Log.w(TAG, "Could not ask to become the default home app", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,619 @@
|
||||
package app.flexera.backup
|
||||
|
||||
import android.content.ComponentName
|
||||
import android.content.ContentValues
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.LauncherApps
|
||||
import android.database.sqlite.SQLiteDatabase
|
||||
import android.net.Uri
|
||||
import android.os.Process
|
||||
import android.util.Log
|
||||
import app.lawnchair.DeviceProfileOverrides
|
||||
import app.lawnchair.backup.LawnchairBackup
|
||||
import app.lawnchair.preferences.PreferenceManager
|
||||
import app.lawnchair.preferences2.PreferenceManager2
|
||||
import com.android.launcher3.GridType
|
||||
import com.android.launcher3.InvariantDeviceProfile
|
||||
import com.android.launcher3.LauncherSettings.Favorites
|
||||
import com.android.launcher3.model.DatabaseHelper
|
||||
import com.android.launcher3.model.DeviceGridState
|
||||
import com.android.launcher3.model.ModelDbController
|
||||
import com.android.launcher3.pm.UserCache
|
||||
import com.android.launcher3.provider.RestoreDbTask
|
||||
import com.android.launcher3.shortcuts.ShortcutKey
|
||||
import com.android.launcher3.shortcuts.ShortcutRequest
|
||||
import java.io.File
|
||||
import java.io.FileInputStream
|
||||
import java.io.FileOutputStream
|
||||
import java.net.URISyntaxException
|
||||
import java.util.UUID
|
||||
import java.util.zip.ZipInputStream
|
||||
import javax.xml.parsers.DocumentBuilderFactory
|
||||
import kotlin.math.max
|
||||
import kotlin.math.roundToInt
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.json.JSONObject
|
||||
|
||||
/**
|
||||
* Imports the home screens of a Smart Launcher backup: icons, folders and widgets, each in the
|
||||
* place it had, on a grid of the same size and, like Smart Launcher, without a dock.
|
||||
*
|
||||
* A backup (a .slbk file) is a zip of Smart Launcher's own files. Two of them matter here:
|
||||
* - `databases/ginlemon.flower.db`, a SQLite database. Its table `HomeItem` has one row per
|
||||
* thing on a home screen (screen, cell, size) that points either at a `Launchable`, which
|
||||
* `Action` describes with an ordinary Android intent, or at a `Widget` with its provider.
|
||||
* A folder is a launchable too; its members are the launchables that name it as their parent.
|
||||
* - the preferences file under `shared_prefs/`, where `launcher_profile_#0` holds the grid.
|
||||
*
|
||||
* The format is not documented. This follows one real backup, of Smart Launcher's data
|
||||
* version 64, and refuses a file in which it does not find these tables.
|
||||
*
|
||||
* What cannot come along is said to the owner before the import ([Info]): Smart Launcher's own
|
||||
* widgets, which exist only inside Smart Launcher, and items of other profiles. A widget that
|
||||
* does come along arrives as "tap to set up": Android has every launcher ask for its widgets
|
||||
* itself, and keeps a widget's settings with the launcher that made it.
|
||||
*
|
||||
* The layout is handed to Launcher3 the way Lawnchair's Nova import hands over its own
|
||||
* (see [app.lawnchair.backup.NovaBackupConverter]): as a database of Launcher3's own shape,
|
||||
* which Launcher3's restore code then takes in.
|
||||
*/
|
||||
class SmartLauncherBackupConverter(
|
||||
private val context: Context,
|
||||
private val uri: Uri,
|
||||
) {
|
||||
|
||||
/** What a backup holds, for the owner to see before agreeing to the import. */
|
||||
data class Info(
|
||||
val columns: Int,
|
||||
val rows: Int,
|
||||
val screens: Int,
|
||||
val apps: Int,
|
||||
val folders: Int,
|
||||
val appsInFolders: Int,
|
||||
val widgets: Int,
|
||||
/** Smart Launcher's own widgets, which stay behind. */
|
||||
val ownWidgets: Int,
|
||||
/** Other things that stay behind: no usable target, another profile, or no free cells. */
|
||||
val skipped: Int,
|
||||
)
|
||||
|
||||
/** Where a thing sits on the home screens, in whole cells. */
|
||||
private data class Place(val screen: Int, val x: Int, val y: Int, val width: Int, val height: Int)
|
||||
|
||||
/** An icon: an app, or a shortcut into an app ([shortcutId] with [packageName]). */
|
||||
private data class Icon(
|
||||
val title: String?,
|
||||
val intentUri: String,
|
||||
val packageName: String?,
|
||||
val shortcutId: String?,
|
||||
)
|
||||
|
||||
private sealed interface HomeThing {
|
||||
val place: Place
|
||||
}
|
||||
|
||||
private data class HomeIcon(override val place: Place, val icon: Icon) : HomeThing
|
||||
private data class HomeFolder(override val place: Place, val title: String?, val icons: List<Icon>) : HomeThing
|
||||
private data class HomeWidget(override val place: Place, val provider: String) : HomeThing
|
||||
|
||||
private data class Layout(
|
||||
val columns: Int,
|
||||
val rows: Int,
|
||||
val showLabels: Boolean?,
|
||||
val things: List<HomeThing>,
|
||||
val ownWidgets: Int,
|
||||
val skipped: Int,
|
||||
) {
|
||||
val info: Info
|
||||
get() = Info(
|
||||
columns = columns,
|
||||
rows = rows,
|
||||
screens = things.map { it.place.screen }.distinct().size,
|
||||
apps = things.count { it is HomeIcon },
|
||||
folders = things.count { it is HomeFolder },
|
||||
appsInFolders = things.sumOf { (it as? HomeFolder)?.icons?.size ?: 0 },
|
||||
widgets = things.count { it is HomeWidget },
|
||||
ownWidgets = ownWidgets,
|
||||
skipped = skipped,
|
||||
)
|
||||
}
|
||||
|
||||
/** Reads the backup and says what is in it. Throws if it is not a backup this can read. */
|
||||
suspend fun parseInfo(): Info = withContext(Dispatchers.IO) {
|
||||
withUnpackedBackup { dir -> readLayout(dir).info }
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces the home screens with the backup's. The launcher has to be restarted afterwards
|
||||
* to show them.
|
||||
*/
|
||||
suspend fun convertAndRestore() {
|
||||
val layout = withContext(Dispatchers.IO) { withUnpackedBackup { dir -> readLayout(dir) } }
|
||||
|
||||
withContext(Dispatchers.IO) {
|
||||
val tempDir = newTempDir()
|
||||
try {
|
||||
val staged = File(tempDir, STAGED_DB)
|
||||
val shortcuts = writeLauncherDb(layout, staged)
|
||||
applyGrid(layout)
|
||||
|
||||
val restored = context.getDatabasePath(LawnchairBackup.RESTORED_DB_FILE_NAME)
|
||||
restored.parentFile?.mkdirs()
|
||||
staged.copyTo(restored, overwrite = true)
|
||||
// Opening the controller moves the restored file into place; the restore task
|
||||
// then marks every item as freshly restored, which is what makes Launcher3 ask
|
||||
// for the widgets anew and drop icons of apps that are not installed.
|
||||
check(RestoreDbTask.performRestore(context, ModelDbController(context))) {
|
||||
"Launcher3 did not accept the converted layout"
|
||||
}
|
||||
pinShortcuts(shortcuts)
|
||||
} finally {
|
||||
tempDir.deleteRecursively()
|
||||
}
|
||||
}
|
||||
|
||||
// Settings that make the result match the source: no dock, because Smart Launcher has
|
||||
// none, and labels as they were. Last, so that a failed import changes nothing.
|
||||
val prefs2 = PreferenceManager2.getInstance(context)
|
||||
prefs2.isHotseatEnabled.set(false)
|
||||
layout.showLabels?.let { prefs2.showIconLabelsOnHomeScreen.set(it) }
|
||||
}
|
||||
|
||||
// ---- Reading the backup ------------------------------------------------------------------
|
||||
|
||||
private fun <T> withUnpackedBackup(block: (File) -> T): T {
|
||||
val dir = newTempDir()
|
||||
try {
|
||||
unpack(dir)
|
||||
return block(dir)
|
||||
} finally {
|
||||
dir.deleteRecursively()
|
||||
}
|
||||
}
|
||||
|
||||
private fun newTempDir(): File =
|
||||
File(context.cacheDir, "$TEMP_DIR_PREFIX${UUID.randomUUID()}").apply { mkdirs() }
|
||||
|
||||
/**
|
||||
* Unpacks the database and the preference files, and nothing else, into [dir]. Entry names
|
||||
* come from the file and are not trusted: only the two known places are accepted, each file
|
||||
* lands under its bare name, and a file of unreasonable size ends the import.
|
||||
*/
|
||||
private fun unpack(dir: File) {
|
||||
val descriptor = context.contentResolver.openFileDescriptor(uri, "r")
|
||||
?: error("Cannot open the backup file")
|
||||
descriptor.use {
|
||||
ZipInputStream(FileInputStream(it.fileDescriptor)).use { zip ->
|
||||
var entry = zip.nextEntry
|
||||
while (entry != null) {
|
||||
val name = entry.name
|
||||
val target = when {
|
||||
entry.isDirectory -> null
|
||||
name == SL_DB_ENTRY -> File(dir, SL_DB)
|
||||
name.startsWith(SL_PREFS_DIR) && name.endsWith(".xml") ->
|
||||
File(dir, PREFS_PREFIX + File(name).name)
|
||||
else -> null
|
||||
}
|
||||
if (target != null) {
|
||||
require(target.canonicalPath.startsWith(dir.canonicalPath + File.separator)) {
|
||||
"Backup entry outside the import folder: $name"
|
||||
}
|
||||
FileOutputStream(target).use { out ->
|
||||
val buffer = ByteArray(64 * 1024)
|
||||
var total = 0L
|
||||
while (true) {
|
||||
val read = zip.read(buffer)
|
||||
if (read < 0) break
|
||||
total += read
|
||||
require(total <= MAX_ENTRY_BYTES) { "Backup entry too large: $name" }
|
||||
out.write(buffer, 0, read)
|
||||
}
|
||||
}
|
||||
}
|
||||
entry = zip.nextEntry
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun readLayout(dir: File): Layout {
|
||||
val dbFile = File(dir, SL_DB)
|
||||
require(dbFile.exists()) { "No Smart Launcher database in this file" }
|
||||
val grid = readGrid(dir)
|
||||
|
||||
SQLiteDatabase.openDatabase(dbFile.absolutePath, null, SQLiteDatabase.OPEN_READONLY).use { db ->
|
||||
for (table in listOf(T_HOME, T_LAUNCHABLE, T_ACTION, T_WIDGET)) {
|
||||
require(tableExists(db, table)) { "Smart Launcher database without table $table" }
|
||||
}
|
||||
return readHomeScreens(db, grid)
|
||||
}
|
||||
}
|
||||
|
||||
private data class Grid(val columns: Int, val rows: Int, val showLabels: Boolean?)
|
||||
|
||||
/** The home grid from the preferences, or null where a backup does not state it. */
|
||||
private fun readGrid(dir: File): Grid? {
|
||||
val files = dir.listFiles { file -> file.name.startsWith(PREFS_PREFIX) } ?: return null
|
||||
for (file in files) {
|
||||
try {
|
||||
val document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(file)
|
||||
val strings = document.documentElement.getElementsByTagName("string")
|
||||
for (i in 0 until strings.length) {
|
||||
val node = strings.item(i)
|
||||
val name = node.attributes?.getNamedItem("name")?.nodeValue ?: continue
|
||||
if (!name.startsWith(SL_PROFILE_KEY_PREFIX)) continue
|
||||
val settings = JSONObject(node.textContent).optJSONObject("gridUserSettings") ?: continue
|
||||
val columns = settings.optInt("columns", 0)
|
||||
val rows = settings.optInt("rows", 0)
|
||||
if (columns in 1..MAX_GRID && rows in 1..MAX_GRID) {
|
||||
val labels = if (settings.has("hasLabel")) settings.optBoolean("hasLabel") else null
|
||||
return Grid(columns, rows, labels)
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.w(TAG, "Unreadable preference file in backup: ${file.name}", e)
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
private fun readHomeScreens(db: SQLiteDatabase, grid: Grid?): Layout {
|
||||
data class Row(
|
||||
val launchable: Long?,
|
||||
val widget: Long?,
|
||||
val screen: Int,
|
||||
val x: Int,
|
||||
val y: Int,
|
||||
val width: Int,
|
||||
val height: Int,
|
||||
)
|
||||
|
||||
// Smart Launcher can keep more than one arrangement ("configId"); the first is the one
|
||||
// in use on a phone held upright.
|
||||
val rows = ArrayList<Row>()
|
||||
db.rawQuery(
|
||||
"SELECT idLaunchable, idWidget, screen, cellX, cellY, spanX, spanY FROM $T_HOME " +
|
||||
"WHERE configId = (SELECT MIN(configId) FROM $T_HOME) ORDER BY zIndex, id",
|
||||
null,
|
||||
).use { c ->
|
||||
while (c.moveToNext()) {
|
||||
rows.add(
|
||||
Row(
|
||||
launchable = if (c.isNull(0)) null else c.getLong(0),
|
||||
widget = if (c.isNull(1)) null else c.getLong(1),
|
||||
screen = c.getInt(2),
|
||||
x = c.getDouble(3).roundToInt(),
|
||||
y = c.getDouble(4).roundToInt(),
|
||||
width = c.getDouble(5).roundToInt().coerceAtLeast(1),
|
||||
height = c.getDouble(6).roundToInt().coerceAtLeast(1),
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
val columns = grid?.columns ?: max(MIN_GRID, rows.maxOfOrNull { it.x + it.width } ?: 0)
|
||||
val gridRows = grid?.rows ?: max(MIN_GRID, rows.maxOfOrNull { it.y + it.height } ?: 0)
|
||||
// Launcher3 numbers its screens from 0 without gaps, left to right.
|
||||
val screenIndex = rows.map { it.screen }.distinct().sorted().withIndex().associate { it.value to it.index }
|
||||
val taken = HashSet<Triple<Int, Int, Int>>()
|
||||
|
||||
val things = ArrayList<HomeThing>()
|
||||
var ownWidgets = 0
|
||||
var skipped = 0
|
||||
for (row in rows) {
|
||||
val screen = screenIndex.getValue(row.screen)
|
||||
val place = Place(screen, row.x, row.y, row.width, row.height)
|
||||
val cells = cellsOf(place)
|
||||
// Launcher3 keeps one thing per cell and nothing outside the grid.
|
||||
val fits = row.x >= 0 && row.y >= 0 && row.x + row.width <= columns &&
|
||||
row.y + row.height <= gridRows && cells.none { it in taken }
|
||||
|
||||
val read: HomeThing? = when {
|
||||
row.widget != null -> readWidgetProvider(db, row.widget)?.let { HomeWidget(place, it) }
|
||||
row.launchable != null -> readLaunchable(db, row.launchable, place)
|
||||
else -> null
|
||||
}
|
||||
when {
|
||||
// The only widgets without a provider this can use are Smart Launcher's own.
|
||||
read == null && row.widget != null -> ownWidgets++
|
||||
read == null || !fits -> skipped++
|
||||
else -> {
|
||||
things.add(read)
|
||||
taken.addAll(cells)
|
||||
}
|
||||
}
|
||||
}
|
||||
return Layout(columns, gridRows, grid?.showLabels, things, ownWidgets, skipped)
|
||||
}
|
||||
|
||||
private fun cellsOf(place: Place): List<Triple<Int, Int, Int>> = buildList {
|
||||
for (x in place.x until place.x + place.width) {
|
||||
for (y in place.y until place.y + place.height) {
|
||||
add(Triple(place.screen, x, y))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** The provider of an ordinary app widget, or null for one of Smart Launcher's own. */
|
||||
private fun readWidgetProvider(db: SQLiteDatabase, id: Long): String? =
|
||||
db.rawQuery("SELECT type, provider, userId FROM $T_WIDGET WHERE id = ?", arrayOf(id.toString())).use { c ->
|
||||
if (!c.moveToFirst()) {
|
||||
null
|
||||
} else {
|
||||
val type = c.getInt(0)
|
||||
val provider = if (c.isNull(1)) null else c.getString(1)
|
||||
val user = if (c.isNull(2)) OWNER_USER else c.getInt(2)
|
||||
val component = provider?.let(ComponentName::unflattenFromString)
|
||||
if (type != SL_WIDGET_TYPE_APP || component == null || user != OWNER_USER) {
|
||||
null
|
||||
} else {
|
||||
component.flattenToString()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** The icon or folder behind a launchable, or null if it has no target this can use. */
|
||||
private fun readLaunchable(db: SQLiteDatabase, id: Long, place: Place): HomeThing? {
|
||||
val action = readAction(db, id) ?: return null
|
||||
if (action.type != SL_ACTION_TYPE_FOLDER) {
|
||||
return action.toIcon()?.let { HomeIcon(place, it) }
|
||||
}
|
||||
val icons = ArrayList<Icon>()
|
||||
db.rawQuery(
|
||||
"SELECT id FROM $T_LAUNCHABLE WHERE idParentFolderLaunchable = ? ORDER BY position, id",
|
||||
arrayOf(id.toString()),
|
||||
).use { c ->
|
||||
while (c.moveToNext()) {
|
||||
readAction(db, c.getLong(0))?.takeIf { it.type != SL_ACTION_TYPE_FOLDER }?.toIcon()?.let(icons::add)
|
||||
}
|
||||
}
|
||||
// Launcher3 has no use for a folder with nothing in it.
|
||||
return if (icons.isEmpty()) null else HomeFolder(place, action.label, icons)
|
||||
}
|
||||
|
||||
private data class Action(
|
||||
val type: Int,
|
||||
val intentUri: String?,
|
||||
val user: Int,
|
||||
val label: String?,
|
||||
val shortcutId: String?,
|
||||
) {
|
||||
/** Launcher3's form of this action, if it opens an app or one of an app's shortcuts. */
|
||||
fun toIcon(): Icon? {
|
||||
// Icons of a work profile or a second user are left out; -1 means "no user", as on folders.
|
||||
if (user != OWNER_USER && user != NO_USER) return null
|
||||
val intent = try {
|
||||
Intent.parseUri(intentUri ?: return null, 0)
|
||||
} catch (_: URISyntaxException) {
|
||||
return null
|
||||
}
|
||||
val component = intent.component
|
||||
val packageName = component?.packageName ?: intent.`package`
|
||||
return when {
|
||||
!shortcutId.isNullOrEmpty() && packageName != null ->
|
||||
Icon(label, ShortcutKey.makeIntent(shortcutId, packageName).toUri(0), packageName, shortcutId)
|
||||
|
||||
component != null -> Icon(label, launchIntentFor(component).toUri(0), packageName, null)
|
||||
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** The first action of a launchable, which is what a tap does. */
|
||||
private fun readAction(db: SQLiteDatabase, launchable: Long): Action? =
|
||||
db.rawQuery(
|
||||
"SELECT type, intentUri, userId, label, deepShortcutId FROM $T_ACTION " +
|
||||
"WHERE idLaunchable = ? ORDER BY actionId LIMIT 1",
|
||||
arrayOf(launchable.toString()),
|
||||
).use { c ->
|
||||
if (!c.moveToFirst()) {
|
||||
null
|
||||
} else {
|
||||
Action(
|
||||
type = c.getInt(0),
|
||||
intentUri = if (c.isNull(1)) null else c.getString(1),
|
||||
user = if (c.isNull(2)) OWNER_USER else c.getInt(2),
|
||||
label = if (c.isNull(3)) null else c.getString(3),
|
||||
shortcutId = if (c.isNull(4)) null else c.getString(4),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun tableExists(db: SQLiteDatabase, table: String): Boolean =
|
||||
db.rawQuery("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = ?", arrayOf(table)).use {
|
||||
it.moveToFirst()
|
||||
}
|
||||
|
||||
// ---- Writing Launcher3's layout ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Writes [layout] as a Launcher3 database at [target]. Returns the app shortcuts in it, by
|
||||
* package, which the launcher has to pin before it may show them.
|
||||
*/
|
||||
private fun writeLauncherDb(layout: Layout, target: File): Map<String, Set<String>> {
|
||||
val profileId = UserCache.INSTANCE.get(context).getSerialNumberForUser(Process.myUserHandle())
|
||||
val shortcuts = HashMap<String, MutableSet<String>>()
|
||||
val now = System.currentTimeMillis()
|
||||
var nextId = 1
|
||||
|
||||
SQLiteDatabase.openOrCreateDatabase(target, null).use { db ->
|
||||
db.version = DatabaseHelper.SCHEMA_VERSION
|
||||
Favorites.addTableToDb(db, profileId, false)
|
||||
|
||||
fun insert(
|
||||
container: Int,
|
||||
place: Place?,
|
||||
rank: Int,
|
||||
itemType: Int,
|
||||
title: String? = null,
|
||||
intentUri: String? = null,
|
||||
provider: String? = null,
|
||||
): Int {
|
||||
val id = nextId++
|
||||
db.insertOrThrow(
|
||||
Favorites.TABLE_NAME,
|
||||
null,
|
||||
ContentValues().apply {
|
||||
put(Favorites._ID, id)
|
||||
put(Favorites.TITLE, title)
|
||||
put(Favorites.INTENT, intentUri)
|
||||
put(Favorites.CONTAINER, container)
|
||||
put(Favorites.SCREEN, place?.screen ?: 0)
|
||||
put(Favorites.CELLX, place?.x ?: 0)
|
||||
put(Favorites.CELLY, place?.y ?: 0)
|
||||
put(Favorites.SPANX, place?.width ?: 1)
|
||||
put(Favorites.SPANY, place?.height ?: 1)
|
||||
put(Favorites.ITEM_TYPE, itemType)
|
||||
put(Favorites.APPWIDGET_ID, -1)
|
||||
put(Favorites.APPWIDGET_PROVIDER, provider)
|
||||
put(Favorites.MODIFIED, now)
|
||||
put(Favorites.RESTORED, 0)
|
||||
put(Favorites.PROFILE_ID, profileId)
|
||||
put(Favorites.RANK, rank)
|
||||
put(Favorites.OPTIONS, 0)
|
||||
put(Favorites.APPWIDGET_SOURCE, -1)
|
||||
},
|
||||
)
|
||||
return id
|
||||
}
|
||||
|
||||
fun insertIcon(icon: Icon, container: Int, place: Place?, rank: Int) {
|
||||
val isShortcut = icon.shortcutId != null && icon.packageName != null
|
||||
if (isShortcut) {
|
||||
shortcuts.getOrPut(icon.packageName!!) { HashSet() }.add(icon.shortcutId!!)
|
||||
}
|
||||
insert(
|
||||
container = container,
|
||||
place = place,
|
||||
rank = rank,
|
||||
itemType = if (isShortcut) Favorites.ITEM_TYPE_DEEP_SHORTCUT else Favorites.ITEM_TYPE_APPLICATION,
|
||||
title = icon.title,
|
||||
intentUri = icon.intentUri,
|
||||
)
|
||||
}
|
||||
|
||||
db.beginTransaction()
|
||||
try {
|
||||
for (thing in layout.things) {
|
||||
when (thing) {
|
||||
is HomeIcon -> insertIcon(thing.icon, Favorites.CONTAINER_DESKTOP, thing.place, 0)
|
||||
|
||||
is HomeFolder -> {
|
||||
val folder = insert(
|
||||
container = Favorites.CONTAINER_DESKTOP,
|
||||
place = thing.place,
|
||||
rank = 0,
|
||||
itemType = Favorites.ITEM_TYPE_FOLDER,
|
||||
title = thing.title,
|
||||
)
|
||||
thing.icons.forEachIndexed { rank, icon -> insertIcon(icon, folder, null, rank) }
|
||||
}
|
||||
|
||||
is HomeWidget -> insert(
|
||||
container = Favorites.CONTAINER_DESKTOP,
|
||||
place = thing.place,
|
||||
rank = 0,
|
||||
itemType = Favorites.ITEM_TYPE_APPWIDGET,
|
||||
provider = thing.provider,
|
||||
)
|
||||
}
|
||||
}
|
||||
db.setTransactionSuccessful()
|
||||
} finally {
|
||||
db.endTransaction()
|
||||
}
|
||||
}
|
||||
return shortcuts
|
||||
}
|
||||
|
||||
/** Makes the home grid the size of the backup's, in every place the launcher keeps it. */
|
||||
private fun applyGrid(layout: Layout) {
|
||||
val prefs = PreferenceManager.getInstance(context)
|
||||
val hotseat = prefs.hotseatColumns.get()
|
||||
val gridInfo = DeviceProfileOverrides.DBGridInfo(
|
||||
numHotseatColumns = hotseat,
|
||||
numRows = layout.rows,
|
||||
numColumns = layout.columns,
|
||||
)
|
||||
val gridState = DeviceGridState(
|
||||
layout.columns,
|
||||
layout.rows,
|
||||
hotseat,
|
||||
InvariantDeviceProfile.TYPE_PHONE,
|
||||
gridInfo.dbFile,
|
||||
GridType.GRID_TYPE_ANY,
|
||||
)
|
||||
gridState.writeToPrefs(context, true)
|
||||
gridState.writeToPrefs(context)
|
||||
InvariantDeviceProfile.INSTANCE.get(context).dbFile = gridInfo.dbFile
|
||||
prefs.sp.edit()
|
||||
.putInt(prefs.workspaceColumns.key, layout.columns)
|
||||
.putInt(prefs.workspaceRows.key, layout.rows)
|
||||
.commit()
|
||||
}
|
||||
|
||||
/** Pins the imported app shortcuts, keeping whatever the launcher has pinned already. */
|
||||
private fun pinShortcuts(shortcuts: Map<String, Set<String>>) {
|
||||
if (shortcuts.isEmpty()) return
|
||||
val launcherApps = context.getSystemService(LauncherApps::class.java) ?: return
|
||||
val user = Process.myUserHandle()
|
||||
for ((packageName, ids) in shortcuts) {
|
||||
val pinned = LinkedHashSet<String>()
|
||||
val current = ShortcutRequest(context, user)
|
||||
.forPackage(packageName)
|
||||
.query(ShortcutRequest.PINNED or LauncherApps.ShortcutQuery.FLAG_GET_KEY_FIELDS_ONLY)
|
||||
if (current.wasSuccess()) current.mapTo(pinned) { it.id }
|
||||
pinned.addAll(ids)
|
||||
try {
|
||||
launcherApps.pinShortcuts(packageName, pinned.toList(), user)
|
||||
} catch (e: SecurityException) {
|
||||
Log.w(TAG, "Could not pin the imported shortcuts of $packageName", e)
|
||||
} catch (e: IllegalStateException) {
|
||||
Log.w(TAG, "Could not pin the imported shortcuts of $packageName", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val TAG = "SmartLauncherImport"
|
||||
|
||||
const val SL_DB_ENTRY = "databases/ginlemon.flower.db"
|
||||
const val SL_PREFS_DIR = "shared_prefs/"
|
||||
const val SL_PROFILE_KEY_PREFIX = "launcher_profile_"
|
||||
const val T_HOME = "HomeItem"
|
||||
const val T_LAUNCHABLE = "Launchable"
|
||||
const val T_ACTION = "Action"
|
||||
const val T_WIDGET = "Widget"
|
||||
|
||||
/** `Action.type` of a folder; every other type seen opens an app. */
|
||||
const val SL_ACTION_TYPE_FOLDER = 9
|
||||
|
||||
/** `Widget.type` of an ordinary app widget; the other types are Smart Launcher's own. */
|
||||
const val SL_WIDGET_TYPE_APP = 1
|
||||
|
||||
/** Smart Launcher's user ids: the phone's owner, and "no user" on folders. */
|
||||
const val OWNER_USER = 0
|
||||
const val NO_USER = -1
|
||||
|
||||
const val TEMP_DIR_PREFIX = "smartlauncher_"
|
||||
const val SL_DB = "smartlauncher.db"
|
||||
const val PREFS_PREFIX = "prefs_"
|
||||
const val STAGED_DB = "workspace.db"
|
||||
|
||||
/** Far above any real backup's database; a larger entry is not a backup. */
|
||||
const val MAX_ENTRY_BYTES = 64L * 1024 * 1024
|
||||
|
||||
const val MIN_GRID = 4
|
||||
const val MAX_GRID = 20
|
||||
|
||||
/** The intent Launcher3 itself stores for an app icon. */
|
||||
fun launchIntentFor(component: ComponentName): Intent =
|
||||
Intent(Intent.ACTION_MAIN)
|
||||
.addCategory(Intent.CATEGORY_LAUNCHER)
|
||||
.setComponent(component)
|
||||
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,198 @@
|
||||
package app.flexera.backup
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.widget.Toast
|
||||
import androidx.activity.compose.LocalOnBackPressedDispatcherOwner
|
||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.DisposableEffect
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.pluralStringResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.core.net.toUri
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import androidx.navigation.NavGraphBuilder
|
||||
import androidx.navigation.compose.composable
|
||||
import androidx.navigation.toRoute
|
||||
import app.flexera.backup.SmartLauncherImportViewModel.Event
|
||||
import app.flexera.backup.SmartLauncherImportViewModel.State
|
||||
import app.lawnchair.ui.preferences.LocalIsExpandedScreen
|
||||
import app.lawnchair.ui.preferences.LocalNavController
|
||||
import app.lawnchair.ui.preferences.components.layout.PreferenceGroup
|
||||
import app.lawnchair.ui.preferences.components.layout.PreferenceLayout
|
||||
import app.lawnchair.ui.preferences.components.layout.PreferenceTemplate
|
||||
import app.lawnchair.ui.preferences.navigation.ImportSmartLauncherBackup
|
||||
import app.lawnchair.util.BackHandler
|
||||
import app.lawnchair.util.restartLauncher
|
||||
import com.android.launcher3.R
|
||||
import java.util.Base64
|
||||
|
||||
/**
|
||||
* The screen between choosing a Smart Launcher backup and importing it. It says what the file
|
||||
* holds, what will not come along and what the import replaces, and waits for the owner's word.
|
||||
*/
|
||||
fun NavGraphBuilder.smartLauncherImportGraph() {
|
||||
composable<ImportSmartLauncherBackup> { entry ->
|
||||
val route: ImportSmartLauncherBackup = entry.toRoute()
|
||||
val backup = remember { String(Base64.getDecoder().decode(route.base64Uri)).toUri() }
|
||||
val viewModel: SmartLauncherImportViewModel = viewModel()
|
||||
DisposableEffect(Unit) {
|
||||
viewModel.open(backup)
|
||||
onDispose { }
|
||||
}
|
||||
SmartLauncherImportScreen(viewModel)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun SmartLauncherImportScreen(viewModel: SmartLauncherImportViewModel) {
|
||||
val context = LocalContext.current
|
||||
val state by viewModel.state.collectAsStateWithLifecycle()
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
viewModel.events.collect { event ->
|
||||
when (event) {
|
||||
Event.Imported -> {
|
||||
Toast.makeText(context, R.string.flexera_import_done, Toast.LENGTH_SHORT).show()
|
||||
restartLauncher(context)
|
||||
}
|
||||
|
||||
Event.Failed -> Toast.makeText(context, R.string.flexera_import_failed, Toast.LENGTH_LONG).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PreferenceLayout(
|
||||
label = stringResource(id = R.string.flexera_import_smart_launcher),
|
||||
backArrowVisible = !LocalIsExpandedScreen.current,
|
||||
) {
|
||||
when (val current = state) {
|
||||
State.Reading -> Box(modifier = Modifier.fillMaxSize()) {
|
||||
CircularProgressIndicator(modifier = Modifier.align(Alignment.Center))
|
||||
}
|
||||
|
||||
State.Unreadable -> {
|
||||
val back = LocalOnBackPressedDispatcherOwner.current?.onBackPressedDispatcher
|
||||
LaunchedEffect(Unit) {
|
||||
Toast.makeText(context, R.string.flexera_import_unreadable, Toast.LENGTH_LONG).show()
|
||||
back?.onBackPressed()
|
||||
}
|
||||
}
|
||||
|
||||
is State.Ready -> {
|
||||
// Leaving in the middle of an import would leave the home screens half replaced.
|
||||
if (current.importing) BackHandler {}
|
||||
BackupContents(current.info)
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(top = 8.dp)
|
||||
.padding(horizontal = 16.dp),
|
||||
) {
|
||||
Button(
|
||||
onClick = viewModel::import,
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
enabled = !current.importing,
|
||||
) {
|
||||
Text(text = stringResource(id = R.string.flexera_import_action))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun BackupContents(info: SmartLauncherBackupConverter.Info) {
|
||||
PreferenceGroup(heading = stringResource(id = R.string.flexera_import_found)) {
|
||||
InfoRow(
|
||||
R.string.flexera_import_screens,
|
||||
stringResource(id = R.string.flexera_import_screens_value, info.screens, info.columns, info.rows),
|
||||
)
|
||||
if (info.apps > 0) InfoRow(R.string.flexera_import_apps, info.apps.toString())
|
||||
if (info.folders > 0) {
|
||||
InfoRow(
|
||||
R.string.flexera_import_folders,
|
||||
pluralStringResource(
|
||||
id = R.plurals.flexera_import_folders_value,
|
||||
count = info.appsInFolders,
|
||||
info.folders,
|
||||
info.appsInFolders,
|
||||
),
|
||||
)
|
||||
}
|
||||
if (info.widgets > 0) {
|
||||
InfoRow(R.string.flexera_import_widgets, stringResource(id = R.string.flexera_import_widgets_value, info.widgets))
|
||||
}
|
||||
}
|
||||
if (info.ownWidgets > 0 || info.skipped > 0) {
|
||||
PreferenceGroup(heading = stringResource(id = R.string.flexera_import_left_out)) {
|
||||
if (info.ownWidgets > 0) {
|
||||
InfoRow(
|
||||
R.string.flexera_import_own_widgets,
|
||||
pluralStringResource(
|
||||
id = R.plurals.flexera_import_own_widgets_value,
|
||||
count = info.ownWidgets,
|
||||
info.ownWidgets,
|
||||
),
|
||||
)
|
||||
}
|
||||
if (info.skipped > 0) {
|
||||
InfoRow(
|
||||
R.string.flexera_import_skipped,
|
||||
pluralStringResource(id = R.plurals.flexera_import_skipped_value, count = info.skipped, info.skipped),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
PreferenceGroup(heading = stringResource(id = R.string.flexera_import_effect)) {
|
||||
PreferenceTemplate(
|
||||
title = { Text(text = stringResource(id = R.string.flexera_import_effect_title)) },
|
||||
description = { Text(text = stringResource(id = R.string.flexera_import_effect_body)) },
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun InfoRow(labelRes: Int, value: String) {
|
||||
PreferenceTemplate(
|
||||
title = { Text(text = stringResource(id = labelRes)) },
|
||||
description = { Text(text = value) },
|
||||
)
|
||||
}
|
||||
|
||||
/** Returns an action that lets the owner pick a backup file and then opens the import screen for it. */
|
||||
@Composable
|
||||
fun smartLauncherImportOpener(): () -> Unit {
|
||||
val navController = LocalNavController.current
|
||||
val request = rememberLauncherForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
||||
if (result.resultCode != Activity.RESULT_OK) return@rememberLauncherForActivityResult
|
||||
val uri = result.data?.data ?: return@rememberLauncherForActivityResult
|
||||
val base64Uri = Base64.getEncoder().encodeToString(uri.toString().toByteArray())
|
||||
navController.navigate(ImportSmartLauncherBackup(base64Uri))
|
||||
}
|
||||
return {
|
||||
// A .slbk file has no file type Android knows, so every file is offered.
|
||||
request.launch(
|
||||
Intent(Intent.ACTION_OPEN_DOCUMENT)
|
||||
.addCategory(Intent.CATEGORY_OPENABLE)
|
||||
.setType("*/*"),
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package app.flexera.backup
|
||||
|
||||
import android.app.Application
|
||||
import android.net.Uri
|
||||
import android.util.Log
|
||||
import androidx.lifecycle.AndroidViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import kotlinx.coroutines.channels.Channel
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.flow.receiveAsFlow
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
/**
|
||||
* Holds one Smart Launcher import: reads the chosen backup, shows what is in it, and on the
|
||||
* owner's word replaces the home screens with it. Same shape as Lawnchair's view model for a
|
||||
* Nova backup.
|
||||
*/
|
||||
internal class SmartLauncherImportViewModel(application: Application) : AndroidViewModel(application) {
|
||||
|
||||
sealed interface Event {
|
||||
data object Imported : Event
|
||||
data object Failed : Event
|
||||
}
|
||||
|
||||
sealed interface State {
|
||||
data object Reading : State
|
||||
data object Unreadable : State
|
||||
data class Ready(val info: SmartLauncherBackupConverter.Info, val importing: Boolean = false) : State
|
||||
}
|
||||
|
||||
private var converter: SmartLauncherBackupConverter? = null
|
||||
|
||||
private val mutableState = MutableStateFlow<State>(State.Reading)
|
||||
val state: StateFlow<State> = mutableState.asStateFlow()
|
||||
|
||||
private val eventChannel = Channel<Event>(Channel.BUFFERED)
|
||||
val events = eventChannel.receiveAsFlow()
|
||||
|
||||
fun open(backup: Uri) {
|
||||
if (converter != null) return
|
||||
val converter = SmartLauncherBackupConverter(getApplication(), backup).also { converter = it }
|
||||
viewModelScope.launch {
|
||||
mutableState.value = try {
|
||||
State.Ready(converter.parseInfo())
|
||||
} catch (t: Throwable) {
|
||||
Log.e(TAG, "Not a Smart Launcher backup this can read", t)
|
||||
State.Unreadable
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun import() {
|
||||
val ready = mutableState.value as? State.Ready ?: return
|
||||
val converter = converter ?: return
|
||||
if (ready.importing) return
|
||||
viewModelScope.launch {
|
||||
mutableState.value = ready.copy(importing = true)
|
||||
try {
|
||||
converter.convertAndRestore()
|
||||
eventChannel.send(Event.Imported)
|
||||
} catch (t: Throwable) {
|
||||
Log.e(TAG, "Import failed", t)
|
||||
mutableState.value = ready.copy(importing = false)
|
||||
eventChannel.send(Event.Failed)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val TAG = "SmartLauncherImport"
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package app.flexera.drawer
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Color
|
||||
import android.graphics.Point
|
||||
import android.graphics.Rect
|
||||
import android.os.Build
|
||||
import android.util.TypedValue
|
||||
@@ -15,7 +16,10 @@ import com.android.launcher3.BubbleTextView
|
||||
import com.android.launcher3.R
|
||||
import com.android.launcher3.allapps.ActivityAllAppsContainerView
|
||||
import com.android.launcher3.allapps.BaseAllAppsAdapter.AdapterItem
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.android.launcher3.views.BaseDragLayer
|
||||
import kotlin.math.max
|
||||
import kotlin.math.min
|
||||
|
||||
/**
|
||||
* Flexera Launcher's app drawer: a single-column alphabetical list with letter headers
|
||||
@@ -86,9 +90,13 @@ object FlexeraDrawer {
|
||||
@JvmStatic
|
||||
fun styleAppRow(icon: BubbleTextView) {
|
||||
val res = icon.resources
|
||||
icon.layoutParams.height = res.getDimensionPixelSize(R.dimen.flexera_drawer_row_height)
|
||||
// Other icons share the "all apps" display type (search results, for one); this tag
|
||||
// tells list rows apart from them.
|
||||
icon.setTag(R.id.flexera_drawer_row, true)
|
||||
val textSize = res.getDimension(R.dimen.flexera_drawer_row_text_size)
|
||||
icon.layoutParams.height = rowHeight(icon.context)
|
||||
icon.compoundDrawablePadding = res.getDimensionPixelSize(R.dimen.flexera_drawer_row_icon_gap)
|
||||
icon.setTextSize(TypedValue.COMPLEX_UNIT_PX, res.getDimension(R.dimen.flexera_drawer_row_text_size))
|
||||
icon.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize)
|
||||
applySidePadding(icon)
|
||||
// The drawer has no background, so names sit directly on the dimmed wallpaper: white,
|
||||
// with a soft shadow to stay readable over light areas.
|
||||
@@ -104,12 +112,85 @@ object FlexeraDrawer {
|
||||
/** Shadow behind white drawer text. */
|
||||
const val TEXT_SHADOW_COLOR = 0x73000000
|
||||
|
||||
/**
|
||||
* How tall an app row is. The row has to hold the name with a notification preview under
|
||||
* it (PRD AD-11). At the usual font size the set height does; with a large system font
|
||||
* the row grows instead.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun rowHeight(context: Context): Int {
|
||||
val res = context.resources
|
||||
return max(
|
||||
res.getDimensionPixelSize(R.dimen.flexera_drawer_row_height),
|
||||
(res.getDimension(R.dimen.flexera_drawer_row_text_size) * ROW_HEIGHT_IN_TEXT_SIZES).toInt(),
|
||||
)
|
||||
}
|
||||
|
||||
/** The least a row's height may be, in name text sizes: two lines of text and some air. */
|
||||
private const val ROW_HEIGHT_IN_TEXT_SIZES = 2.4f
|
||||
|
||||
/**
|
||||
* What lies between the open drawer and the blurred wallpaper: black at 78%, whatever the
|
||||
* theme and the wallpaper. Lawnchair's backdrop is a grey at 40%, which over a light
|
||||
* wallpaper leaves a light grey behind the drawer's white names.
|
||||
*/
|
||||
const val BACKDROP_COLOR = 0xC7000000.toInt()
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
const val KEEP_SEARCH_FIELD_BACKGROUND = true
|
||||
|
||||
/**
|
||||
* Moves the search field up with the list, so that it scrolls away like the list's first
|
||||
* row and comes back when the list is at its top. The field is not a row of the list: it
|
||||
* lies over the list's top padding and is shifted by as much as the list has scrolled.
|
||||
* While a search is on, and where the drawer does not use this (work tabs, a hidden or a
|
||||
* floating search field), the field stays in place.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun moveSearchFieldWithList(appsView: ActivityAllAppsContainerView<*>) {
|
||||
val field = appsView.searchView ?: return
|
||||
val list = appsView.activeRecyclerView
|
||||
val scrolled = if (list == null || appsView.isSearching || !appsView.flexeraSearchFieldScrolls()) {
|
||||
0
|
||||
} else {
|
||||
scrolledFromTop(list)
|
||||
}
|
||||
// The field and the list's rows vanish at the same line, the top of the drawer's
|
||||
// content, which is the lower edge of the status bar. The rows are cut there by the
|
||||
// list's own top edge; the field is cut here, and travels no further than it takes to
|
||||
// be all above that line.
|
||||
val line = appsView.paddingTop
|
||||
val moved = min(scrolled, max(0, field.bottom - line))
|
||||
field.translationY = -moved.toFloat()
|
||||
val hidden = line - (field.top - moved)
|
||||
if (hidden > 0) {
|
||||
// The view copies the rectangle, so one scratch rectangle serves every call.
|
||||
fieldClip.set(0, hidden, field.width, max(hidden, field.height))
|
||||
field.clipBounds = fieldClip
|
||||
} else {
|
||||
field.clipBounds = null
|
||||
}
|
||||
}
|
||||
|
||||
private val fieldClip = Rect()
|
||||
|
||||
/**
|
||||
* How far [list] has scrolled from its top, in pixels, for as long as its first row is
|
||||
* still attached; after that, simply "far". Counting rows is exact, which the list's own
|
||||
* scroll offset, an estimate from row heights, is not.
|
||||
*/
|
||||
private fun scrolledFromTop(list: RecyclerView): Int {
|
||||
val first = list.getChildAt(0) ?: return 0
|
||||
return if (list.getChildAdapterPosition(first) == 0) {
|
||||
max(0, list.paddingTop - first.top)
|
||||
} else {
|
||||
Int.MAX_VALUE
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Where the drawer panel sits for a given all-apps progress (0 = open, 1 = closed). Launcher3
|
||||
* slides the panel up from the bottom; here it stays in place and fades (see
|
||||
@@ -196,21 +277,73 @@ object FlexeraDrawer {
|
||||
appsView: ActivityAllAppsContainerView<*>,
|
||||
dragLayer: BaseDragLayer<*>,
|
||||
ev: MotionEvent,
|
||||
) = scrubFromSwipe(appsView, dragLayer, ev.x, ev.y)
|
||||
|
||||
/** The same, for a finger position ([x], [y]) in the drag layer's coordinates. */
|
||||
@JvmStatic
|
||||
fun scrubFromSwipe(
|
||||
appsView: ActivityAllAppsContainerView<*>,
|
||||
dragLayer: BaseDragLayer<*>,
|
||||
x: Float,
|
||||
y: Float,
|
||||
) {
|
||||
val wave = waveAlphabet(appsView) ?: return
|
||||
val bounds = Rect()
|
||||
dragLayer.getDescendantRectRelativeToSelf(wave, bounds)
|
||||
val x = ev.x - bounds.left
|
||||
val y = ev.y - bounds.top
|
||||
if (wave.isScrubbing) wave.moveScrub(x, y) else wave.beginScrub(x, y)
|
||||
val offset = layoutOffset(wave, dragLayer)
|
||||
if (wave.isScrubbing) wave.moveScrub(x - offset.x, y - offset.y) else wave.beginScrub(x - offset.x, y - offset.y)
|
||||
}
|
||||
|
||||
/**
|
||||
* True when [ev], given in the drag layer's coordinates, lands where the wave alphabet's
|
||||
* strip will be once the drawer is open. Scrub from home (PRD AD-10) starts there.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun isOnHomeEdge(
|
||||
appsView: ActivityAllAppsContainerView<*>,
|
||||
dragLayer: BaseDragLayer<*>,
|
||||
ev: MotionEvent,
|
||||
): Boolean {
|
||||
val wave = waveAlphabet(appsView) ?: return false
|
||||
val offset = layoutOffset(wave, dragLayer)
|
||||
return wave.isOnStripBand(ev.x - offset.x, ev.y - offset.y)
|
||||
}
|
||||
|
||||
/**
|
||||
* Where [view] sits inside [ancestor] going by layout alone. A closed drawer is parked
|
||||
* off-screen with a translation; this ignores it, giving the place the view has when the
|
||||
* drawer is open.
|
||||
*/
|
||||
private fun layoutOffset(view: View, ancestor: View): Point {
|
||||
val offset = Point()
|
||||
var current: View? = view
|
||||
while (current != null && current !== ancestor) {
|
||||
offset.x += current.left
|
||||
offset.y += current.top
|
||||
current = current.parent as? View
|
||||
}
|
||||
return offset
|
||||
}
|
||||
|
||||
/**
|
||||
* A scrub that started from a swipe and ends sooner than this was not meant as one: nobody
|
||||
* reads a letter and means it in a fifth of a second. The swipe opens the plain list.
|
||||
*/
|
||||
const val MIN_SCRUB_MS = 200L
|
||||
|
||||
/** Ends a scrub started by [scrubFromSwipe]; the drawer stays open at the chosen letter. */
|
||||
@JvmStatic
|
||||
fun endScrubFromSwipe(appsView: ActivityAllAppsContainerView<*>) {
|
||||
waveAlphabet(appsView)?.endScrub()
|
||||
}
|
||||
|
||||
/**
|
||||
* Ends a scrub started by [scrubFromSwipe] and undoes it, so the drawer opens the way an
|
||||
* ordinary swipe up leaves it.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun cancelScrubFromSwipe(appsView: ActivityAllAppsContainerView<*>) {
|
||||
waveAlphabet(appsView)?.cancelScrub()
|
||||
}
|
||||
|
||||
/**
|
||||
* A letter header. It carries its letter so that the adapter's diffing notices when the
|
||||
* header at a position changes, for example after an app is installed or removed.
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
package app.flexera.drawer
|
||||
|
||||
import android.os.SystemClock
|
||||
import android.view.MotionEvent
|
||||
import android.view.ViewConfiguration
|
||||
import app.lawnchair.preferences.PreferenceManager
|
||||
import com.android.launcher3.AbstractFloatingView
|
||||
import com.android.launcher3.Launcher
|
||||
import com.android.launcher3.LauncherState
|
||||
import com.android.launcher3.Utilities
|
||||
import com.android.launcher3.util.TouchController
|
||||
import kotlin.math.abs
|
||||
|
||||
/**
|
||||
* Scrub from home (PRD AD-10). With the setting on, a vertical slide that starts on the home
|
||||
* screen's edge, where the drawer's alphabet sits, opens the drawer and scrubs it in the same
|
||||
* 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.
|
||||
*/
|
||||
class FlexeraEdgeScrubController(private val launcher: Launcher) : TouchController {
|
||||
|
||||
private val touchSlop = ViewConfiguration.get(launcher).scaledTouchSlop
|
||||
private val prefs = PreferenceManager.getInstance(launcher)
|
||||
|
||||
/** The current touch started on the edge and may still turn into a scrub. */
|
||||
private var candidate = false
|
||||
private var scrubbing = false
|
||||
private var scrubStartTime = 0L
|
||||
private var downX = 0f
|
||||
private var downY = 0f
|
||||
|
||||
override fun onControllerInterceptTouchEvent(ev: MotionEvent): Boolean {
|
||||
when (ev.actionMasked) {
|
||||
MotionEvent.ACTION_DOWN -> {
|
||||
scrubbing = false
|
||||
candidate = canStart(ev)
|
||||
downX = ev.x
|
||||
downY = ev.y
|
||||
}
|
||||
|
||||
MotionEvent.ACTION_MOVE -> if (candidate) {
|
||||
val dx = abs(ev.x - downX)
|
||||
val dy = abs(ev.y - downY)
|
||||
when {
|
||||
// A long press picked something up, or the finger went sideways: not ours.
|
||||
launcher.dragController.isDragging || (dx > touchSlop && dx >= dy) -> candidate = false
|
||||
|
||||
dy > touchSlop && dy > dx * VERTICAL_BIAS -> {
|
||||
candidate = false
|
||||
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.
|
||||
openDrawer()
|
||||
FlexeraDrawer.scrubFromSwipe(launcher.appsView, launcher.dragLayer, ev)
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> candidate = false
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
override fun onControllerTouchEvent(ev: MotionEvent): Boolean {
|
||||
if (!scrubbing) return false
|
||||
when (ev.actionMasked) {
|
||||
MotionEvent.ACTION_MOVE ->
|
||||
FlexeraDrawer.scrubFromSwipe(launcher.appsView, launcher.dragLayer, ev)
|
||||
|
||||
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {
|
||||
scrubbing = false
|
||||
if (SystemClock.uptimeMillis() - scrubStartTime < FlexeraDrawer.MIN_SCRUB_MS) {
|
||||
// A flick up that happened to start on the edge: open the plain list.
|
||||
FlexeraDrawer.cancelScrubFromSwipe(launcher.appsView)
|
||||
} else {
|
||||
FlexeraDrawer.endScrubFromSwipe(launcher.appsView)
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the drawer in [OPEN_MS]. Asking the state manager to go there would take the
|
||||
* drawer's own 600 ms, far too slow for a list that the finger is already scrubbing.
|
||||
*/
|
||||
private fun openDrawer() {
|
||||
launcher.stateManager.createAnimationToNewWorkspace(LauncherState.ALL_APPS, OPEN_MS).apply {
|
||||
dispatchOnStart()
|
||||
start()
|
||||
}
|
||||
}
|
||||
|
||||
private fun canStart(ev: MotionEvent): Boolean =
|
||||
prefs.flexeraScrubFromHome.get() &&
|
||||
(ev.edgeFlags and Utilities.EDGE_NAV_BAR) == 0 &&
|
||||
launcher.isInState(LauncherState.NORMAL) &&
|
||||
AbstractFloatingView.getTopOpenView(launcher) == null &&
|
||||
FlexeraDrawer.isOnHomeEdge(launcher.appsView, launcher.dragLayer, ev)
|
||||
|
||||
override fun dump(): String = "FlexeraEdgeScrubController candidate=$candidate scrubbing=$scrubbing"
|
||||
|
||||
private companion object {
|
||||
/** A slide counts as vertical when it has moved this many times further up or down than sideways. */
|
||||
const val VERTICAL_BIAS = 2f
|
||||
|
||||
/** How long the drawer takes to open under a scrub; the same as after swipe up and hold. */
|
||||
const val OPEN_MS = 120L
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
package app.flexera.drawer
|
||||
|
||||
import android.app.Notification
|
||||
import android.service.notification.StatusBarNotification
|
||||
import android.text.SpannableStringBuilder
|
||||
import android.text.Spanned
|
||||
import android.text.TextUtils
|
||||
import android.text.style.ForegroundColorSpan
|
||||
import android.text.style.RelativeSizeSpan
|
||||
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
|
||||
|
||||
/**
|
||||
* Inline notification previews (PRD AD-11): in the drawer list, a row whose app has
|
||||
* notifications shows the latest one under the app name, smaller and dimmer.
|
||||
*
|
||||
* It rides on what Launcher3 already has for notification dots. The same notification access
|
||||
* 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.
|
||||
*
|
||||
* 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].
|
||||
*/
|
||||
object FlexeraNotificationPreview {
|
||||
|
||||
private class Preview(val text: String, val postTime: Long)
|
||||
|
||||
/** Latest text per notification key, for the notifications that currently show a dot. */
|
||||
private val previews = ConcurrentHashMap<String, Preview>()
|
||||
|
||||
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()
|
||||
|
||||
@JvmStatic
|
||||
fun onPosted(sbn: StatusBarNotification) {
|
||||
val text = previewText(sbn)
|
||||
if (text == null) previews.remove(sbn.key) else previews[sbn.key] = Preview(text, sbn.postTime)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun onRemoved(sbn: StatusBarNotification) {
|
||||
previews.remove(sbn.key)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun onFullRefresh(active: List<StatusBarNotification>) {
|
||||
previews.clear()
|
||||
active.forEach(::onPosted)
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
@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
|
||||
|
||||
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
|
||||
}
|
||||
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.
|
||||
|
||||
// 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) {
|
||||
TextUtils.ellipsize(name, icon.paint, width.toFloat(), TextUtils.TruncateAt.END)
|
||||
} else {
|
||||
name
|
||||
}
|
||||
val label = SpannableStringBuilder(firstLine).append('\n')
|
||||
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)
|
||||
}
|
||||
|
||||
private fun isEnabled(icon: BubbleTextView): Boolean =
|
||||
PreferenceManager.getInstance(icon.context).flexeraNotificationPreviews.get()
|
||||
|
||||
/** The text of the newest of the app's notifications that has any text. */
|
||||
private fun latest(dot: DotInfo): String? {
|
||||
var newest: Preview? = null
|
||||
for (key in dot.notificationKeys) {
|
||||
val candidate = previews[key.notificationKey] ?: continue
|
||||
if (newest == null || candidate.postTime > newest.postTime) newest = candidate
|
||||
}
|
||||
return newest?.text
|
||||
}
|
||||
|
||||
/** "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
|
||||
val title = extras.getCharSequence(Notification.EXTRA_TITLE).oneLine()
|
||||
val text = extras.getCharSequence(Notification.EXTRA_TEXT).oneLine()
|
||||
val combined = when {
|
||||
title.isEmpty() -> text
|
||||
text.isEmpty() -> title
|
||||
else -> "$title: $text"
|
||||
}
|
||||
return combined.take(MAX_LENGTH).ifEmpty { null }
|
||||
}
|
||||
|
||||
private fun CharSequence?.oneLine(): String =
|
||||
this?.toString()?.replace('\n', ' ')?.trim().orEmpty()
|
||||
}
|
||||
@@ -24,6 +24,8 @@ import androidx.core.view.doOnNextLayout
|
||||
import androidx.customview.widget.ExploreByTouchHelper
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import app.lawnchair.preferences2.PreferenceManager2
|
||||
import app.lawnchair.preferences2.firstCached
|
||||
import com.android.launcher3.R
|
||||
import com.android.launcher3.allapps.ActivityAllAppsContainerView
|
||||
import kotlin.math.abs
|
||||
@@ -35,13 +37,17 @@ import kotlin.math.roundToInt
|
||||
/**
|
||||
* The wave alphabet: a strip of letters down one edge of the drawer (PRD AD-4 to AD-6).
|
||||
*
|
||||
* Only letters that have apps are shown. Touching the strip and sliding along it jumps the list
|
||||
* Only letters that have apps are shown, under a magnifier that stands for the search field at
|
||||
* the top of the list. Touching the strip and sliding along it jumps the list
|
||||
* to the letter under the finger, with a haptic tick on every change. While the finger is down,
|
||||
* the letters near it bulge away from the edge in a wave, and the wave reaches further the
|
||||
* further the finger moves in from the edge, so the current letter always sits beside the thumb
|
||||
* instead of under it.
|
||||
* the letters near it bulge away from the edge in a wide wave that curves around the thumb.
|
||||
* The wave's peak, where the current letter is, stays a thumb's width beyond the finger however
|
||||
* far in from the edge the finger is, and just beyond the peak a bubble shows that letter
|
||||
* large. The look follows Niagara Launcher's alphabet, the owner's reference.
|
||||
*
|
||||
* The strip sits on the right edge unless the owner moves it to the left (PRD AD-15).
|
||||
* The strip sits on the right edge unless the owner moves it to the left (PRD AD-15), and low
|
||||
* on that edge, with its letters close together, so that the first letter is as easy to reach
|
||||
* as the last.
|
||||
*
|
||||
* The view covers the whole drawer so it has room to draw the wave, but it only takes touches
|
||||
* that start on the strip; every other touch falls through to the list underneath.
|
||||
@@ -58,7 +64,8 @@ class WaveAlphabetView(
|
||||
private val appsView: ActivityAllAppsContainerView<*>,
|
||||
) : View(context) {
|
||||
|
||||
private data class Letter(val label: String, val adapterPosition: Int)
|
||||
/** One stop on the strip: a letter, or the search field at the top of the list ([isSearch]). */
|
||||
private data class Letter(val label: String, val adapterPosition: Int, val isSearch: Boolean = false)
|
||||
|
||||
private val res = context.resources
|
||||
private val onLeft = FlexeraDrawer.alphabetOnLeft(context)
|
||||
@@ -66,10 +73,16 @@ class WaveAlphabetView(
|
||||
private val edgeInset = res.getDimension(R.dimen.flexera_wave_edge_inset)
|
||||
private val maxSpacing = res.getDimension(R.dimen.flexera_wave_max_spacing)
|
||||
private val verticalMargin = res.getDimension(R.dimen.flexera_wave_vertical_margin)
|
||||
private val bottomOffset = res.getDimension(R.dimen.flexera_wave_bottom_offset)
|
||||
private val fingerGap = res.getDimension(R.dimen.flexera_wave_finger_gap)
|
||||
private val minReach = res.getDimension(R.dimen.flexera_wave_min_reach)
|
||||
private val waveWidth = res.getDimension(R.dimen.flexera_wave_width)
|
||||
private val farMargin = res.getDimension(R.dimen.flexera_wave_far_margin)
|
||||
private val letterSize = res.getDimension(R.dimen.flexera_wave_letter_size)
|
||||
private val headerHeight = res.getDimensionPixelSize(R.dimen.flexera_drawer_header_height)
|
||||
|
||||
/** The section name Launcher3 gives the work profile's info card, an "i" in a circle. */
|
||||
private val workInfoSection = res.getString(R.string.work_profile_edu_section)
|
||||
|
||||
// The drawer has no background, so the letters are white like the app names: slightly
|
||||
// dimmed at rest, full white near the finger.
|
||||
@@ -88,6 +101,43 @@ class WaveAlphabetView(
|
||||
}
|
||||
private val boldTypeface = 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 {
|
||||
style = Paint.Style.STROKE
|
||||
strokeCap = Paint.Cap.ROUND
|
||||
setShadowLayer(
|
||||
res.getDimension(R.dimen.flexera_drawer_text_shadow_radius),
|
||||
0f,
|
||||
res.getDimension(R.dimen.flexera_drawer_text_shadow_dy),
|
||||
FlexeraDrawer.TEXT_SHADOW_COLOR,
|
||||
)
|
||||
}
|
||||
private val plainMarkPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
|
||||
style = Paint.Style.STROKE
|
||||
strokeCap = Paint.Cap.ROUND
|
||||
}
|
||||
|
||||
// The bubble that shows the selected letter large, beyond the wave's peak: a light disc
|
||||
// with a dark letter, the one thing on the dark drawer that is not white on dark.
|
||||
private val bubbleRadius = res.getDimension(R.dimen.flexera_wave_bubble_radius)
|
||||
private val bubbleGap = res.getDimension(R.dimen.flexera_wave_bubble_gap)
|
||||
private val bubbleTextSize = res.getDimension(R.dimen.flexera_wave_bubble_text_size)
|
||||
private val bubbleEdgeMargin = res.getDimension(R.dimen.flexera_wave_bubble_edge_margin)
|
||||
private val bubblePaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
|
||||
color = BUBBLE_COLOR
|
||||
setShadowLayer(
|
||||
res.getDimension(R.dimen.flexera_wave_bubble_shadow_radius),
|
||||
0f,
|
||||
res.getDimension(R.dimen.flexera_drawer_text_shadow_dy),
|
||||
BUBBLE_SHADOW_COLOR,
|
||||
)
|
||||
}
|
||||
private val bubbleTextPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
|
||||
color = BUBBLE_TEXT_COLOR
|
||||
textAlign = Paint.Align.CENTER
|
||||
typeface = boldTypeface
|
||||
}
|
||||
|
||||
private var letters: List<Letter> = emptyList()
|
||||
private var letterYs = FloatArray(0)
|
||||
private var stripTop = 0f
|
||||
@@ -129,15 +179,24 @@ 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, and Private Space uses a long badge string; neither is a letter.
|
||||
if (label.isEmpty() || label.length > 2) continue
|
||||
// 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
|
||||
if (result.isNotEmpty() && result.last().label == label) continue
|
||||
result.add(Letter(label, section.position))
|
||||
}
|
||||
// The search field is the list's first row in all but name, and scrolls away with it.
|
||||
// A magnifier above the letters says it is there and jumps back to it.
|
||||
if (result.isNotEmpty() && hasSearchField()) result.add(0, Letter("", 0, isSearch = true))
|
||||
return result
|
||||
}
|
||||
|
||||
private fun hasSearchField(): Boolean =
|
||||
!PreferenceManager2.getInstance(context).hideAppDrawerSearchBar.firstCached()
|
||||
|
||||
private fun refreshIfChanged() {
|
||||
// Any new layout may have moved the list; keep the search field riding on it.
|
||||
FlexeraDrawer.moveSearchFieldWithList(appsView)
|
||||
val searching = appsView.isSearching
|
||||
val fresh = readLetters()
|
||||
if (fresh != letters || searching != wasSearching) {
|
||||
@@ -157,7 +216,8 @@ class WaveAlphabetView(
|
||||
appsView.activeRecyclerView?.let { rv ->
|
||||
getLocationInWindow(location)
|
||||
rv.getLocationInWindow(otherLocation)
|
||||
top = (otherLocation[1] - location[1]).toFloat().coerceAtLeast(0f)
|
||||
// The list's rows start below its top padding, which holds the search field.
|
||||
top = (otherLocation[1] - location[1] + rv.paddingTop).toFloat().coerceAtLeast(0f)
|
||||
}
|
||||
val bottomInset = rootWindowInsets?.systemWindowInsetBottom ?: 0
|
||||
val availableTop = top + verticalMargin
|
||||
@@ -172,8 +232,15 @@ class WaveAlphabetView(
|
||||
} else {
|
||||
val spacing = min(maxSpacing, (availableBottom - availableTop) / count)
|
||||
val blockHeight = spacing * count
|
||||
// Few letters: keep the block in the middle of the edge, where a thumb rests.
|
||||
stripTop = availableTop + (availableBottom - availableTop - blockHeight) / 2f
|
||||
// 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
|
||||
for (i in 0 until count) {
|
||||
letterYs[i] = stripTop + spacing * (i + 0.5f)
|
||||
@@ -218,27 +285,39 @@ class WaveAlphabetView(
|
||||
if (layoutDirty) computeLayout()
|
||||
if (letters.isEmpty()) return
|
||||
|
||||
// On the left edge the wave reaches out over the icons and names, so darken the list
|
||||
// under it for as long as the finger is down. On the right it crosses empty space.
|
||||
if (onLeft && press > 0f) {
|
||||
canvas.drawColor(Color.argb((LEFT_SCRUB_DIM * press * 255).toInt(), 0, 0, 0))
|
||||
}
|
||||
|
||||
// Where the letters rest, and which way "away from the edge" points.
|
||||
val baseX = if (onLeft) edgeInset else width - edgeInset
|
||||
val inward = if (onLeft) 1f else -1f
|
||||
// The wave's peak sits a fixed gap before the finger, so it reaches further out the
|
||||
// further the finger is from the edge.
|
||||
// The wave's peak sits a fixed gap beyond the finger, on the side away from the edge,
|
||||
// which is the side the thumb leaves uncovered. So the wave reaches further out the
|
||||
// further the finger is from the edge, up to nearly the whole width of the screen.
|
||||
val fingerDistance = (fingerX - baseX) * inward
|
||||
val reach = (fingerDistance + fingerGap).coerceIn(minReach, width * 0.7f) * press
|
||||
val maxReach = max(minReach + 1f, width - edgeInset - farMargin)
|
||||
val fullReach = (fingerDistance + fingerGap).coerceIn(minReach, maxReach)
|
||||
val reach = fullReach * press
|
||||
// The wave is wide: several letters on each side of the finger ride it, so they curve
|
||||
// around the whole thumb and stay readable above and below it. A wave that reaches
|
||||
// far out is wider still, which keeps its shape.
|
||||
val spread = max(waveWidth, fullReach * WAVE_WIDTH_SHARE_OF_REACH)
|
||||
|
||||
// Darken the list a little while scrubbing, so the eye goes to the letters, and more
|
||||
// where the wave lies over icons and names: from the right edge that is once it reaches
|
||||
// well into the screen, as after swipe up and hold; from the left edge it is at once.
|
||||
if (press > 0f) {
|
||||
val reachShare = ((fullReach - minReach) / (maxReach - minReach)).coerceIn(0f, 1f)
|
||||
val overList = if (onLeft) 1f else SCRUB_DIM_AT_EDGE + (1f - SCRUB_DIM_AT_EDGE) * reachShare
|
||||
val dim = (SCRUB_DIM * press * overList * 255).toInt()
|
||||
if (dim > 0) canvas.drawColor(Color.argb(dim, 0, 0, 0))
|
||||
}
|
||||
|
||||
for (i in letters.indices) {
|
||||
val y = letterYs[i]
|
||||
val nearness = if (press > 0f) bell((y - fingerY) / waveWidth) else 0f
|
||||
val nearness = if (press > 0f) bell((y - fingerY) / spread) else 0f
|
||||
val isSelected = i == selected && press > 0f
|
||||
|
||||
val scale = 1f + (if (isSelected) SELECTED_GROWTH else NEAR_GROWTH) * nearness * press
|
||||
paint.textSize = restingLetterSize * scale
|
||||
// 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.color = if (isSelected) {
|
||||
activeColor
|
||||
@@ -248,9 +327,49 @@ class WaveAlphabetView(
|
||||
|
||||
val x = baseX + inward * reach * nearness
|
||||
// Centre the glyph on the letter's line.
|
||||
val baseline = y - (paint.descent() + paint.ascent()) / 2f
|
||||
canvas.drawText(letters[i].label, x, baseline, paint)
|
||||
if (letters[i].isSearch) {
|
||||
drawSearchMark(canvas, x, y, paint.textSize * SEARCH_MARK_IN_LETTER_SIZES, paint.color, true)
|
||||
} else {
|
||||
val baseline = y - (paint.descent() + paint.ascent()) / 2f
|
||||
canvas.drawText(letters[i].label, x, baseline, paint)
|
||||
}
|
||||
}
|
||||
|
||||
// The selected letter, large, in a bubble just beyond the wave's peak and level with
|
||||
// the finger: the furthest thing from the thumb, so the thumb cannot hide it.
|
||||
if (press > 0f && selected in letters.indices) {
|
||||
val edgeRoom = bubbleRadius + bubbleEdgeMargin
|
||||
val cx = (baseX + inward * (reach + bubbleGap * press)).coerceIn(edgeRoom, max(edgeRoom, width - edgeRoom))
|
||||
val alpha = (press * 255).toInt()
|
||||
bubblePaint.alpha = alpha
|
||||
canvas.drawCircle(cx, fingerY, bubbleRadius * press, bubblePaint)
|
||||
bubbleTextPaint.alpha = alpha
|
||||
bubbleTextPaint.textSize = bubbleTextSize * press
|
||||
if (letters[selected].isSearch) {
|
||||
drawSearchMark(canvas, cx, fingerY, bubbleTextPaint.textSize, bubbleTextPaint.color, false)
|
||||
} else {
|
||||
val baseline = fingerY - (bubbleTextPaint.descent() + bubbleTextPaint.ascent()) / 2f
|
||||
canvas.drawText(letters[selected].label, cx, baseline, bubbleTextPaint)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws a magnifier, the mark for the search field, [size] across and centred on
|
||||
* ([cx], [cy]): a ring with a short handle. Drawn by hand so that its line weight
|
||||
* matches letters of any size.
|
||||
*/
|
||||
private fun drawSearchMark(canvas: Canvas, cx: Float, cy: Float, size: Float, color: Int, shadow: Boolean) {
|
||||
val stroke = if (shadow) markPaint else plainMarkPaint
|
||||
stroke.color = color
|
||||
stroke.strokeWidth = size * 0.12f
|
||||
val radius = size * 0.29f
|
||||
val ringX = cx - size * 0.09f
|
||||
val ringY = cy - size * 0.09f
|
||||
canvas.drawCircle(ringX, ringY, radius, stroke)
|
||||
val rim = radius * 0.7071f
|
||||
val handle = size * 0.27f
|
||||
canvas.drawLine(ringX + rim, ringY + rim, ringX + rim + handle, ringY + rim + handle, stroke)
|
||||
}
|
||||
|
||||
private fun bell(distance: Float): Float = exp(-distance * distance)
|
||||
@@ -258,9 +377,16 @@ class WaveAlphabetView(
|
||||
// ---- Touch -------------------------------------------------------------------------------
|
||||
|
||||
/** True when a touch at this point, in this view's coordinates, starts a scrub. */
|
||||
fun isOnStrip(x: Float, y: Float): Boolean {
|
||||
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.
|
||||
*/
|
||||
fun isOnStripBand(x: Float, y: Float): Boolean {
|
||||
if (layoutDirty) computeLayout()
|
||||
if (letters.isEmpty() || !appsView.isInAllApps || appsView.isSearching) return false
|
||||
if (letters.isEmpty()) return false
|
||||
val onEdge = if (onLeft) x <= touchWidth else x >= width - touchWidth
|
||||
return onEdge && y >= stripTop - verticalMargin && y <= stripBottom + verticalMargin
|
||||
}
|
||||
@@ -300,6 +426,27 @@ class WaveAlphabetView(
|
||||
moveScrub(x, y)
|
||||
}
|
||||
|
||||
/**
|
||||
* Ends a scrub that began with the drawer closed and undoes it: the list goes to where a
|
||||
* drawer opened by a plain swipe stands, which is the top unless the owner has the drawer
|
||||
* remember its place. For a scrub that turns out to have been started by mistake.
|
||||
*
|
||||
* The list is not asked where it stood before the scrub. A closed drawer has been told to
|
||||
* go back to the top but lays its rows out again only when it opens, so until then the
|
||||
* rows still report the place the drawer was left at.
|
||||
*/
|
||||
fun cancelScrub() {
|
||||
if (!scrubbing) return
|
||||
endScrub()
|
||||
val rv = appsView.activeRecyclerView ?: return
|
||||
rv.stopScroll()
|
||||
if (PreferenceManager2.getInstance(context).rememberPosition.firstCached()) {
|
||||
rv.restoreScrollPosition()
|
||||
} else {
|
||||
rv.scrollToTop()
|
||||
}
|
||||
}
|
||||
|
||||
/** Moves the finger of a scrub started with [beginScrub]. */
|
||||
fun moveScrub(x: Float, y: Float) {
|
||||
if (!scrubbing || letters.isEmpty()) return
|
||||
@@ -311,7 +458,7 @@ class WaveAlphabetView(
|
||||
if (index != selected) {
|
||||
selected = index
|
||||
performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
|
||||
scrollListTo(letters[index].adapterPosition)
|
||||
scrollListTo(index)
|
||||
}
|
||||
invalidate()
|
||||
}
|
||||
@@ -325,10 +472,31 @@ class WaveAlphabetView(
|
||||
|
||||
val isScrubbing: Boolean get() = scrubbing
|
||||
|
||||
private fun scrollListTo(adapterPosition: Int) {
|
||||
/**
|
||||
* Brings the group of the letter at [index] to the middle of the screen, where the thumb
|
||||
* is, instead of to the top: the group's middle on the list's middle, though a long group
|
||||
* keeps its header in view. Near either end of the list the list simply stops at its end.
|
||||
* The magnifier goes to the very top, where the search field is.
|
||||
*/
|
||||
private fun scrollListTo(index: Int) {
|
||||
val rv = appsView.activeRecyclerView ?: return
|
||||
val layoutManager = rv.layoutManager as? LinearLayoutManager ?: return
|
||||
rv.stopScroll()
|
||||
(rv.layoutManager as? LinearLayoutManager)?.scrollToPositionWithOffset(adapterPosition, 0)
|
||||
val letter = letters[index]
|
||||
if (letter.isSearch) {
|
||||
layoutManager.scrollToPositionWithOffset(0, 0)
|
||||
return
|
||||
}
|
||||
val groupEnd = letters.getOrNull(index + 1)?.adapterPosition
|
||||
?: 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)
|
||||
layoutManager.scrollToPositionWithOffset(
|
||||
letter.adapterPosition,
|
||||
(top - rv.paddingTop).toInt().coerceAtLeast(0),
|
||||
)
|
||||
}
|
||||
|
||||
private fun animatePress(target: Float, durationMs: Long) {
|
||||
@@ -389,7 +557,7 @@ class WaveAlphabetView(
|
||||
|
||||
private fun jumpTo(index: Int) {
|
||||
val rv = appsView.activeRecyclerView ?: return
|
||||
scrollListTo(letters[index].adapterPosition)
|
||||
scrollListTo(index)
|
||||
rv.doOnNextLayout {
|
||||
chosenIndex = index
|
||||
chosenAtPosition = firstVisiblePosition()
|
||||
@@ -414,7 +582,9 @@ class WaveAlphabetView(
|
||||
if (!stripVisible()) return
|
||||
|
||||
val index = currentIndex()
|
||||
node.stateDescription = letters[index].label
|
||||
node.stateDescription = letters[index].let {
|
||||
if (it.isSearch) context.getString(R.string.flexera_alphabet_search) else it.label
|
||||
}
|
||||
node.setRangeInfo(
|
||||
AccessibilityNodeInfoCompat.RangeInfoCompat.obtain(
|
||||
AccessibilityNodeInfoCompat.RangeInfoCompat.RANGE_TYPE_INT,
|
||||
@@ -443,14 +613,32 @@ class WaveAlphabetView(
|
||||
}
|
||||
|
||||
private companion object {
|
||||
/** How much larger than its resting size the selected letter grows. */
|
||||
const val SELECTED_GROWTH = 1.5f
|
||||
/** Where a chosen letter's group is centred, and the highest its header may go, as shares of the list's height. */
|
||||
const val GROUP_MIDDLE = 0.5f
|
||||
const val GROUP_HIGHEST_TOP = 0.22f
|
||||
|
||||
/** How much its neighbours grow, tapering with distance from the finger. */
|
||||
const val NEAR_GROWTH = 0.5f
|
||||
/** The magnifier's size next to a letter of the same text size. */
|
||||
const val SEARCH_MARK_IN_LETTER_SIZES = 1.1f
|
||||
|
||||
/** How dark the list gets under a scrub from the left edge (0 = unchanged, 1 = black). */
|
||||
const val LEFT_SCRUB_DIM = 0.55f
|
||||
/** How many letters a whole alphabet has; the stretch of edge kept for the strip is sized for it. */
|
||||
const val FULL_ALPHABET = 26
|
||||
|
||||
/** How much larger than its resting size the selected letter is in the wave itself. */
|
||||
const val SELECTED_GROWTH = 0.25f
|
||||
|
||||
/** The bubble: a near-white disc, its letter near-black, a soft shadow under it. */
|
||||
const val BUBBLE_COLOR = 0xFFF1F1F4.toInt()
|
||||
const val BUBBLE_TEXT_COLOR = 0xFF17181C.toInt()
|
||||
const val BUBBLE_SHADOW_COLOR = 0x66000000
|
||||
|
||||
/** The wave's spread up and down the edge, as a share of how far it reaches out. */
|
||||
const val WAVE_WIDTH_SHARE_OF_REACH = 0.36f
|
||||
|
||||
/** How dark the list gets under a wave that lies fully over it (0 = unchanged, 1 = black). */
|
||||
const val SCRUB_DIM = 0.55f
|
||||
|
||||
/** The share of [SCRUB_DIM] applied when the wave stays at the right edge, clear of the list. */
|
||||
const val SCRUB_DIM_AT_EDGE = 0.35f
|
||||
|
||||
/** The tallest a resting letter may be, as a share of the vertical room it has. */
|
||||
const val MAX_LETTER_SHARE_OF_SLOT = 0.85f
|
||||
|
||||
@@ -4,6 +4,7 @@ import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.provider.Settings
|
||||
import android.text.format.Formatter
|
||||
import androidx.compose.foundation.Canvas
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
@@ -17,6 +18,7 @@ import androidx.compose.foundation.layout.requiredSize
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.lazy.LazyListScope
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.LinearProgressIndicator
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
@@ -30,9 +32,14 @@ import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.geometry.Offset
|
||||
import androidx.compose.ui.geometry.Size
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.semantics.contentDescription
|
||||
import androidx.compose.ui.semantics.semantics
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.core.net.toUri
|
||||
@@ -40,6 +47,7 @@ import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.LifecycleEventObserver
|
||||
import androidx.lifecycle.compose.LocalLifecycleOwner
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import app.flexera.update.CheckProblem
|
||||
import app.flexera.update.FlexeraRelease
|
||||
import app.flexera.update.FlexeraUpdater
|
||||
import app.flexera.update.UpdateFailure
|
||||
@@ -54,6 +62,9 @@ import app.lawnchair.ui.preferences.components.layout.PreferenceTemplate
|
||||
import app.lawnchair.ui.preferences.navigation.AboutLicenses
|
||||
import com.android.launcher3.BuildConfig
|
||||
import com.android.launcher3.R
|
||||
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel
|
||||
import com.google.zxing.qrcode.encoder.Encoder
|
||||
import kotlin.math.floor
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
@@ -62,6 +73,12 @@ private const val LAWNCHAIR_SOURCE_URL = "https://github.com/LawnchairLauncher/l
|
||||
/** Release notes longer than this are cut off; the full text is on the release page. */
|
||||
private const val MAX_NOTES_LENGTH = 600
|
||||
|
||||
/** Large enough to scan from another phone held at arm's length. */
|
||||
private val QR_CODE_SIZE = 220.dp
|
||||
|
||||
/** The blank border around a QR code, in modules; the standard asks for four. */
|
||||
private const val QR_QUIET_ZONE_MODULES = 4
|
||||
|
||||
/**
|
||||
* Flexera Launcher's About screen.
|
||||
*
|
||||
@@ -178,6 +195,9 @@ fun FlexeraAbout(modifier: Modifier = Modifier) {
|
||||
item { PreferenceGroupHeading(stringResource(id = R.string.flexera_update_heading)) }
|
||||
groupRows(updateRows)
|
||||
|
||||
item { PreferenceGroupHeading(stringResource(id = R.string.flexera_about_share)) }
|
||||
item { PreferenceGroupItem { ShareCard(FlexeraUpdater.RELEASES_PAGE_URL) } }
|
||||
|
||||
item { PreferenceGroupHeading(stringResource(id = R.string.flexera_about_built_on)) }
|
||||
groupRows(
|
||||
listOf<@Composable () -> Unit>(
|
||||
@@ -275,7 +295,7 @@ private fun UpdateStatusRow(state: UpdateState) {
|
||||
if (release == null) {
|
||||
ClickablePreference(
|
||||
label = stringResource(id = R.string.flexera_update_check),
|
||||
subtitle = stringResource(id = R.string.flexera_update_check_failed),
|
||||
subtitle = checkFailureText(state),
|
||||
onClick = { FlexeraUpdater.check(context) },
|
||||
)
|
||||
} else {
|
||||
@@ -295,6 +315,90 @@ private fun UpdateStatusRow(state: UpdateState) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* What the owner holds up for someone who wants the app: a QR code that opens the release page,
|
||||
* with the address under it for anyone who would rather type it.
|
||||
*/
|
||||
@Composable
|
||||
private fun ShareCard(url: String) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 16.dp, vertical = 20.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
) {
|
||||
QrCode(
|
||||
text = url,
|
||||
description = stringResource(id = R.string.flexera_about_share_qr_description),
|
||||
modifier = Modifier.size(QR_CODE_SIZE),
|
||||
)
|
||||
Spacer(Modifier.height(16.dp))
|
||||
Text(
|
||||
text = stringResource(id = R.string.flexera_about_share_title),
|
||||
style = MaterialTheme.typography.titleMedium,
|
||||
textAlign = TextAlign.Center,
|
||||
)
|
||||
Spacer(Modifier.height(4.dp))
|
||||
Text(
|
||||
text = url.removePrefix("https://"),
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
textAlign = TextAlign.Center,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A QR code for [text], made on the phone. It is black on white in every theme, with the blank
|
||||
* border the standard asks for, because that is what scanners read most reliably.
|
||||
*/
|
||||
@Composable
|
||||
private fun QrCode(text: String, description: String, modifier: Modifier = Modifier) {
|
||||
val modules = remember(text) { Encoder.encode(text, ErrorCorrectionLevel.M).matrix }
|
||||
Canvas(
|
||||
modifier = modifier
|
||||
.clip(RoundedCornerShape(12.dp))
|
||||
.semantics { contentDescription = description },
|
||||
) {
|
||||
drawRect(Color.White)
|
||||
// Whole pixels per module, so neighbouring modules join without a seam.
|
||||
val count = modules.width + 2 * QR_QUIET_ZONE_MODULES
|
||||
val module = floor(size.minDimension / count)
|
||||
val left = floor((size.width - module * count) / 2f) + module * QR_QUIET_ZONE_MODULES
|
||||
val top = floor((size.height - module * count) / 2f) + module * QR_QUIET_ZONE_MODULES
|
||||
for (y in 0 until modules.height) {
|
||||
for (x in 0 until modules.width) {
|
||||
if (modules.get(x, y).toInt() == 1) {
|
||||
drawRect(
|
||||
color = Color.Black,
|
||||
topLeft = Offset(left + x * module, top + y * module),
|
||||
size = Size(module, module),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Says why a check for updates failed and what to do about it, then the error's own words, which
|
||||
* are what someone looking for the cause will ask for.
|
||||
*/
|
||||
@Composable
|
||||
private fun checkFailureText(state: UpdateState.Failed): String {
|
||||
val host = FlexeraUpdater.SERVER_HOST
|
||||
val reason = when (state.problem) {
|
||||
CheckProblem.NO_PERMISSION -> stringResource(id = R.string.flexera_update_failed_no_permission)
|
||||
CheckProblem.SERVER_NOT_FOUND -> stringResource(id = R.string.flexera_update_failed_not_found, host)
|
||||
CheckProblem.NOT_SECURE -> stringResource(id = R.string.flexera_update_failed_not_secure, host)
|
||||
CheckProblem.SERVER_ERROR -> stringResource(id = R.string.flexera_update_failed_server_error, host)
|
||||
CheckProblem.BAD_ANSWER -> stringResource(id = R.string.flexera_update_failed_bad_answer, host)
|
||||
CheckProblem.NO_ANSWER, null -> stringResource(id = R.string.flexera_update_failed_no_answer, host)
|
||||
}
|
||||
val detail = state.detail ?: return reason
|
||||
return reason + "\n" + stringResource(id = R.string.flexera_update_failed_detail, detail)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun downloadSizeText(context: Context, release: FlexeraRelease): String =
|
||||
if (release.apkSize > 0) {
|
||||
|
||||
@@ -49,6 +49,11 @@ fun FlexeraDrawerSettings(modifier: Modifier = Modifier) {
|
||||
label = stringResource(id = R.string.suggestion_pref_screen_title),
|
||||
destination = Predictions,
|
||||
)
|
||||
SwitchPreference(
|
||||
label = stringResource(id = R.string.flexera_notification_previews),
|
||||
description = stringResource(id = R.string.flexera_notification_previews_description),
|
||||
adapter = prefs.flexeraNotificationPreviews.getAdapter(),
|
||||
)
|
||||
SwitchPreference(
|
||||
label = stringResource(id = R.string.pref_all_apps_remember_position_title),
|
||||
description = stringResource(id = R.string.pref_all_apps_remember_position_description),
|
||||
@@ -61,6 +66,11 @@ fun FlexeraDrawerSettings(modifier: Modifier = Modifier) {
|
||||
description = stringResource(id = R.string.flexera_alphabet_on_left_description),
|
||||
adapter = prefs.flexeraAlphabetOnLeft.getAdapter(),
|
||||
)
|
||||
SwitchPreference(
|
||||
label = stringResource(id = R.string.flexera_scrub_from_home),
|
||||
description = stringResource(id = R.string.flexera_scrub_from_home_description),
|
||||
adapter = prefs.flexeraScrubFromHome.getAdapter(),
|
||||
)
|
||||
}
|
||||
// No background colour or opacity here: the drawer is transparent with white text, and a
|
||||
// light panel behind white text would make the list unreadable.
|
||||
|
||||
@@ -24,6 +24,8 @@ import java.io.File
|
||||
import java.io.IOException
|
||||
import java.net.HttpURLConnection
|
||||
import java.net.URL
|
||||
import java.net.UnknownHostException
|
||||
import javax.net.ssl.SSLException
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
@@ -31,6 +33,7 @@ import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.launch
|
||||
import org.json.JSONException
|
||||
import org.json.JSONObject
|
||||
|
||||
/** One published version of Flexera Launcher. */
|
||||
@@ -56,6 +59,31 @@ enum class UpdateFailure {
|
||||
WRONG_FILE,
|
||||
}
|
||||
|
||||
/**
|
||||
* Why a check for updates failed, as far as the phone can tell. The About screen says it in
|
||||
* words, because "could not reach the server" alone leaves the owner guessing between the
|
||||
* connection, a VPN, the server and the phone's own settings.
|
||||
*/
|
||||
enum class CheckProblem {
|
||||
/** Android does not let this app use the network (a per-app switch on some systems). */
|
||||
NO_PERMISSION,
|
||||
|
||||
/** The server's name could not be looked up. */
|
||||
SERVER_NOT_FOUND,
|
||||
|
||||
/** The server was found but did not answer in time, or refused the connection. */
|
||||
NO_ANSWER,
|
||||
|
||||
/** The encrypted connection could not be set up. */
|
||||
NOT_SECURE,
|
||||
|
||||
/** The server answered, with an error. */
|
||||
SERVER_ERROR,
|
||||
|
||||
/** The server answered with something that is not a release. */
|
||||
BAD_ANSWER,
|
||||
}
|
||||
|
||||
/** Where the updater currently stands. The About screen shows one row per state. */
|
||||
sealed interface UpdateState {
|
||||
/** Nothing has been checked since the launcher started. */
|
||||
@@ -72,8 +100,17 @@ sealed interface UpdateState {
|
||||
|
||||
data class ReadyToInstall(val release: FlexeraRelease, val file: File) : UpdateState
|
||||
|
||||
/** [release] is set when the failure happened after a newer version had been found. */
|
||||
data class Failed(val failure: UpdateFailure, val release: FlexeraRelease? = null) : UpdateState
|
||||
/**
|
||||
* [release] is set when the failure happened after a newer version had been found. For a
|
||||
* failed check, [problem] says why and [detail] carries the error's own words, for
|
||||
* whoever has to find the cause.
|
||||
*/
|
||||
data class Failed(
|
||||
val failure: UpdateFailure,
|
||||
val release: FlexeraRelease? = null,
|
||||
val problem: CheckProblem? = null,
|
||||
val detail: String? = null,
|
||||
) : UpdateState
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -188,8 +225,9 @@ object FlexeraUpdater {
|
||||
|
||||
val release = result.getOrElse { error ->
|
||||
Log.w(TAG, "Update check failed", error)
|
||||
// A failed background check must not wipe out an update that is already waiting.
|
||||
mutableState.value = if (automatic && before.holdsRelease()) before else UpdateState.Failed(UpdateFailure.CHECK)
|
||||
// A background check that fails stays quiet: the About screen keeps what it showed
|
||||
// before, including an update that is already waiting. It tries again in an hour.
|
||||
mutableState.value = if (automatic) before else failedCheck(error)
|
||||
return@launch
|
||||
}
|
||||
|
||||
@@ -301,8 +339,33 @@ object FlexeraUpdater {
|
||||
private fun isBusy(): Boolean =
|
||||
mutableState.value.let { it is UpdateState.Checking || it is UpdateState.Downloading }
|
||||
|
||||
private fun UpdateState.holdsRelease(): Boolean =
|
||||
this is UpdateState.Available || this is UpdateState.ReadyToInstall
|
||||
/** The server's name without the scheme, for messages. */
|
||||
@JvmField
|
||||
val SERVER_HOST: String = SERVER.substringAfter("://")
|
||||
|
||||
private class NoNetworkPermissionException : IOException("This app has no network permission")
|
||||
private class ServerErrorException(status: Int) : IOException("The server answered HTTP $status")
|
||||
private class BadAnswerException(message: String) : IOException(message)
|
||||
|
||||
/** Turns the error of a failed check into a state that says what kind of failure it was. */
|
||||
private fun failedCheck(error: Throwable): UpdateState.Failed {
|
||||
val problem = when (error) {
|
||||
is NoNetworkPermissionException, is SecurityException -> CheckProblem.NO_PERMISSION
|
||||
is UnknownHostException -> CheckProblem.SERVER_NOT_FOUND
|
||||
is SSLException -> CheckProblem.NOT_SECURE
|
||||
is ServerErrorException -> CheckProblem.SERVER_ERROR
|
||||
is BadAnswerException, is JSONException -> CheckProblem.BAD_ANSWER
|
||||
else -> CheckProblem.NO_ANSWER
|
||||
}
|
||||
// Android's own error classes keep their names in a release build; this file's are
|
||||
// renamed by the shrinker, and their messages say everything anyway.
|
||||
val name = error.javaClass.name.takeIf { it.startsWith("java") || it.startsWith("android") || it.startsWith("org.json") }
|
||||
?.substringAfterLast('.')
|
||||
val detail = listOfNotNull(name, error.message).joinToString(": ").take(MAX_DETAIL_LENGTH)
|
||||
return UpdateState.Failed(UpdateFailure.CHECK, problem = problem, detail = detail.ifEmpty { null })
|
||||
}
|
||||
|
||||
private const val MAX_DETAIL_LENGTH = 200
|
||||
|
||||
/** Returns the latest published release, or null when nothing has been published yet. */
|
||||
private fun fetchLatestRelease(context: Context): FlexeraRelease? {
|
||||
@@ -310,7 +373,7 @@ object FlexeraUpdater {
|
||||
try {
|
||||
val status = connection.responseCode
|
||||
if (status == HttpURLConnection.HTTP_NOT_FOUND) return null
|
||||
if (status != HttpURLConnection.HTTP_OK) throw IOException("Update server answered HTTP $status")
|
||||
if (status != HttpURLConnection.HTTP_OK) throw ServerErrorException(status)
|
||||
|
||||
val json = JSONObject(connection.inputStream.bufferedReader().use { it.readText() })
|
||||
val tag = json.getString("tag_name")
|
||||
@@ -328,7 +391,7 @@ object FlexeraUpdater {
|
||||
apkSize = asset.optLong("size", 0L),
|
||||
)
|
||||
}
|
||||
throw IOException("Release $tag has no APK attached")
|
||||
throw BadAnswerException("Release $tag has no APK attached")
|
||||
} finally {
|
||||
connection.disconnect()
|
||||
}
|
||||
@@ -375,7 +438,7 @@ object FlexeraUpdater {
|
||||
}
|
||||
|
||||
private fun open(context: Context, url: String): HttpURLConnection {
|
||||
if (!FlexeraNetwork.hasInternetPermission(context)) throw IOException("No INTERNET permission")
|
||||
if (!FlexeraNetwork.hasInternetPermission(context)) throw NoNetworkPermissionException()
|
||||
return (URL(url).openConnection() as HttpURLConnection).apply {
|
||||
connectTimeout = CONNECT_TIMEOUT_MS
|
||||
readTimeout = READ_TIMEOUT_MS
|
||||
|
||||
@@ -2,4 +2,4 @@
|
||||
# build.gradle reads this and derives the Android version code from it
|
||||
# (major * 10000 + minor * 100 + patch), so the name and the code can never disagree.
|
||||
# flexera/release.ps1 raises it for every release.
|
||||
versionName=0.1.0
|
||||
versionName=0.6.1
|
||||
@@ -128,6 +128,8 @@ coil-compose = "io.coil-kt:coil-compose:2.7.0"
|
||||
google-material = "com.google.android.material:material:1.14.0"
|
||||
hoko-blur = "io.github.hokofly:hoko-blur:1.5.5"
|
||||
javax-inject = "javax.inject:javax.inject:1"
|
||||
# Flexera Launcher: QR code on the About screen (app.flexera.ui.FlexeraAbout).
|
||||
zxing-core = "com.google.zxing:core:3.5.3"
|
||||
kdrag0n-colorkt = "dev.kdrag0n:colorkt:1.0.5"
|
||||
leakcanary-android = "com.squareup.leakcanary:leakcanary-android:2.14"
|
||||
leakcanary-androidstudio = "com.android.tools.studio.leakcanary:leakcanary:1.0.0"
|
||||
|
||||
@@ -308,7 +308,9 @@ class LawnchairLauncher : QuickstepLauncher() {
|
||||
|
||||
override fun createTouchControllers(): Array<TouchController> {
|
||||
val verticalSwipeController = VerticalSwipeTouchController(this, gestureController)
|
||||
return arrayOf<TouchController>(verticalSwipeController) + super.createTouchControllers()
|
||||
// Flexera Launcher: scrub from home (PRD AD-10) gets the first look at touches on the alphabet's edge.
|
||||
val edgeScrubController = app.flexera.drawer.FlexeraEdgeScrubController(this)
|
||||
return arrayOf<TouchController>(edgeScrubController, verticalSwipeController) + super.createTouchControllers()
|
||||
}
|
||||
|
||||
override fun handleHomeTap() {
|
||||
@@ -467,6 +469,14 @@ class LawnchairLauncher : QuickstepLauncher() {
|
||||
return ActivityOptionsWrapper(options, callback)
|
||||
}
|
||||
|
||||
override fun onDeferredResumed() {
|
||||
super.onDeferredResumed()
|
||||
// Flexera Launcher: on first run, ask to become the default home app (PRD SI-1). It has
|
||||
// to wait until here. Quickstep cancels any request for a result that is already pending
|
||||
// when the launcher finishes resuming, which is what the call above does.
|
||||
app.flexera.FlexeraFirstRun.askToBecomeDefaultHome(this)
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
restartIfPending()
|
||||
|
||||
@@ -217,6 +217,13 @@ class PreferenceManager @Inject constructor(
|
||||
// Flexera Launcher: which screen edge the drawer's wave alphabet sits on (PRD AD-15).
|
||||
val flexeraAlphabetOnLeft = BoolPref("pref_flexeraAlphabetOnLeft", false, recreate)
|
||||
|
||||
// Flexera Launcher: whether a slide along the home screen's edge opens the drawer at a letter (PRD AD-10).
|
||||
// On unless switched off, by the owner's decision of 12 November 2026.
|
||||
val flexeraScrubFromHome = BoolPref("pref_flexeraScrubFromHome", true)
|
||||
|
||||
// Flexera Launcher: whether drawer rows show the app's latest notification under its name (PRD AD-11).
|
||||
val flexeraNotificationPreviews = BoolPref("pref_flexeraNotificationPreviews", true, recreate)
|
||||
|
||||
override fun close() {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
@@ -40,6 +40,12 @@ fun BackupAndRestorePreference(
|
||||
subtitle = stringResource(R.string.restore_nova_backup_description),
|
||||
onClick = restoreNovaBackupOpener(),
|
||||
)
|
||||
// Flexera Launcher: home screens from a Smart Launcher backup (app.flexera.backup).
|
||||
ClickablePreference(
|
||||
label = stringResource(R.string.flexera_import_smart_launcher),
|
||||
subtitle = stringResource(R.string.flexera_import_smart_launcher_description),
|
||||
onClick = app.flexera.backup.smartLauncherImportOpener(),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import androidx.navigation.compose.composable
|
||||
import androidx.navigation.navDeepLink
|
||||
import androidx.navigation.toRoute
|
||||
import app.lawnchair.backup.ui.CreateBackupScreen
|
||||
import app.flexera.backup.smartLauncherImportGraph
|
||||
import app.lawnchair.backup.ui.restoreBackupGraph
|
||||
import app.lawnchair.backup.ui.restoreNovaBackupGraph
|
||||
import app.lawnchair.preferences.BasePreferenceManager
|
||||
@@ -252,5 +253,6 @@ fun PreferenceNavigation(
|
||||
|
||||
restoreBackupGraph()
|
||||
restoreNovaBackupGraph()
|
||||
smartLauncherImportGraph() // Flexera Launcher: Smart Launcher import
|
||||
}
|
||||
}
|
||||
@@ -224,3 +224,8 @@ data class RestoreBackup(val base64Uri: String) : PreferenceRoute
|
||||
|
||||
@Serializable
|
||||
data class RestoreNovaBackup(val base64Uri: String) : PreferenceRoute
|
||||
|
||||
// Flexera Launcher: import of a Smart Launcher backup (app.flexera.backup). The route has to
|
||||
// be declared here because PreferenceRoute is sealed.
|
||||
@Serializable
|
||||
data class ImportSmartLauncherBackup(val base64Uri: String) : PreferenceRoute
|
||||
@@ -3,6 +3,7 @@ package app.lawnchair.views
|
||||
import android.content.Context
|
||||
import android.graphics.Color
|
||||
import android.util.AttributeSet
|
||||
import app.flexera.drawer.FlexeraDrawer
|
||||
import app.lawnchair.preferences.PreferenceManager
|
||||
import com.android.launcher3.R
|
||||
import com.android.launcher3.util.SystemUiController
|
||||
@@ -24,7 +25,10 @@ class LawnchairScrimView(context: Context, attrs: AttributeSet?) : ScrimView(con
|
||||
val threshold = STATUS_BAR_COLOR_FORCE_UPDATE_THRESHOLD
|
||||
val forceChange = visibility == VISIBLE &&
|
||||
alpha > threshold &&
|
||||
Color.alpha(mBackgroundColor) / (255f * drawerOpacity) > threshold
|
||||
// Flexera Launcher: the scrim is at full strength when it reaches the alpha of the
|
||||
// drawer's backdrop. Lawnchair measured against its drawer opacity setting, which
|
||||
// is 0 here.
|
||||
Color.alpha(mBackgroundColor) / Color.alpha(FlexeraDrawer.BACKDROP_COLOR).toFloat() > threshold
|
||||
with(systemUiController) {
|
||||
if (forceChange) {
|
||||
updateUiState(SystemUiController.UI_STATE_SCRIM_VIEW, !isScrimDark)
|
||||
@@ -34,9 +38,8 @@ class LawnchairScrimView(context: Context, attrs: AttributeSet?) : ScrimView(con
|
||||
}
|
||||
}
|
||||
|
||||
override fun isScrimDark() = if (drawerOpacity <= 0.3f) {
|
||||
!Themes.getAttrBoolean(context, R.attr.isWorkspaceDarkText)
|
||||
} else {
|
||||
super.isScrimDark()
|
||||
}
|
||||
// Flexera Launcher: judged by the scrim's own colour, as Launcher3 does. Lawnchair went by
|
||||
// the wallpaper here because its drawer scrim could be see-through; this drawer's backdrop
|
||||
// is always dark, and the status bar icons over it have to be light.
|
||||
override fun isScrimDark() = super.isScrimDark()
|
||||
}
|
||||
@@ -219,6 +219,9 @@ public class AllAppsState extends LauncherState {
|
||||
} else {
|
||||
backgroundColor = ColorTokens.AllAppsScrimColor.resolveColor(launcher);
|
||||
}
|
||||
// Flexera Launcher: the drawer's backdrop is dark whatever the theme and the wallpaper,
|
||||
// so that the white names on it stay readable.
|
||||
backgroundColor = app.flexera.drawer.FlexeraDrawer.BACKDROP_COLOR;
|
||||
return new ScrimColors(backgroundColor, /* foregroundColor */ Color.TRANSPARENT);
|
||||
}
|
||||
}
|
||||
+67
-28
@@ -17,6 +17,7 @@
|
||||
package com.android.launcher3.uioverrides.touchcontrollers;
|
||||
|
||||
import static com.android.app.animation.Interpolators.ACCELERATE_DECELERATE;
|
||||
import static com.android.app.animation.Interpolators.DECELERATE;
|
||||
import static com.android.launcher3.LauncherAnimUtils.SCRIM_COLORS;
|
||||
import static com.android.launcher3.LauncherAnimUtils.newSingleUseCancelListener;
|
||||
import static com.android.launcher3.LauncherState.ALL_APPS;
|
||||
@@ -35,6 +36,7 @@ import android.animation.AnimatorSet;
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.animation.ValueAnimator;
|
||||
import android.graphics.PointF;
|
||||
import android.os.SystemClock;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.ViewConfiguration;
|
||||
|
||||
@@ -81,10 +83,23 @@ public class NoButtonNavbarToOverviewTouchController extends PortraitStatesTouch
|
||||
private boolean mDidTouchStartInNavBar;
|
||||
|
||||
// Flexera Launcher: swipe up and hold hands the same touch to the wave alphabet (PRD AD-17).
|
||||
// "Started" is set when the pause is detected and the drawer begins to finish opening;
|
||||
// "ready" is set once it is fully open and the alphabet can take the finger's position.
|
||||
// "Started" is set when the pause is detected: the alphabet takes the finger at once, while
|
||||
// the drawer finishes opening under it. "Drawer open" is set when that has finished.
|
||||
private boolean mFlexeraScrubStarted;
|
||||
private boolean mFlexeraScrubReady;
|
||||
private boolean mFlexeraDrawerOpen;
|
||||
// Where the finger was at the last drag event, in the drag layer's coordinates.
|
||||
private float mFlexeraLastX;
|
||||
private float mFlexeraLastY;
|
||||
// How long the drawer takes to finish opening once a hold is detected. Short, because the
|
||||
// alphabet is already following the finger and the list has to be readable behind it.
|
||||
private static final long FLEXERA_HOLD_OPEN_MS = 120;
|
||||
// A finger that has not moved for this long is holding. Swipe to recents waits twice as
|
||||
// long; here a false alarm only opens the drawer the swipe was opening anyway.
|
||||
private static final long FLEXERA_HOLD_STILL_MS = 150;
|
||||
// A finger that lifts sooner than this after the hold was noticed was not holding; see
|
||||
// onDragEnd. Too short a time to have read the letter and meant it.
|
||||
private static final long FLEXERA_MIN_HOLD_MS = app.flexera.drawer.FlexeraDrawer.MIN_SCRUB_MS;
|
||||
private long mFlexeraScrubStartTime;
|
||||
private boolean mStartedOverview;
|
||||
private boolean mReachedOverview;
|
||||
// The last recorded displacement before we reached overview.
|
||||
@@ -117,11 +132,17 @@ public class NoButtonNavbarToOverviewTouchController extends PortraitStatesTouch
|
||||
protected boolean canInterceptTouch(MotionEvent ev) {
|
||||
mIsTrackpadSwipe = isTrackpadMotionEvent(ev);
|
||||
mLauncher.setCanShowAllAppsEducationView(!mIsTrackpadSwipe);
|
||||
if (!mIsTrackpadSwipe && DisplayController.getNavigationMode(mLauncher)
|
||||
== THREE_BUTTONS) {
|
||||
boolean threeButtons = !mIsTrackpadSwipe
|
||||
&& DisplayController.getNavigationMode(mLauncher) == THREE_BUTTONS;
|
||||
// Flexera Launcher: with three-button navigation this controller used to stand aside
|
||||
// completely. It now still takes the ordinary swipe up from the home screen, so that
|
||||
// swipe up and hold (PRD AD-17) works in that mode too. Everything else is left to the
|
||||
// controllers after it, as before.
|
||||
if (threeButtons && !mLauncher.isInState(NORMAL)) {
|
||||
return false;
|
||||
}
|
||||
mDidTouchStartInNavBar = (ev.getEdgeFlags() & EDGE_NAV_BAR) != 0;
|
||||
// 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;
|
||||
// Reset touch slop multiplier to default 1.0f if one-handed-mode is not active
|
||||
@@ -171,9 +192,10 @@ public class NoButtonNavbarToOverviewTouchController extends PortraitStatesTouch
|
||||
|
||||
// Flexera Launcher: a pause during an ordinary swipe up to the drawer starts a scrub.
|
||||
mFlexeraScrubStarted = false;
|
||||
mFlexeraScrubReady = false;
|
||||
mFlexeraDrawerOpen = false;
|
||||
if (flexeraHoldToScrub()) {
|
||||
mMotionPauseDetector.setOnMotionPauseListener(this::onFlexeraHoldDetected);
|
||||
mMotionPauseDetector.setForcePauseTimeout(FLEXERA_HOLD_STILL_MS);
|
||||
}
|
||||
|
||||
if (mFromState == NORMAL && mToState == HINT_STATE) {
|
||||
@@ -213,8 +235,15 @@ public class NoButtonNavbarToOverviewTouchController extends PortraitStatesTouch
|
||||
if (mFlexeraScrubStarted) {
|
||||
// Flexera Launcher: lifting the finger ends the scrub and leaves the drawer open at
|
||||
// the chosen letter. If the drawer is still opening, its end callback finishes up.
|
||||
app.flexera.drawer.FlexeraDrawer.endScrubFromSwipe(mLauncher.getAppsView());
|
||||
if (mFlexeraScrubReady) {
|
||||
if (SystemClock.uptimeMillis() - mFlexeraScrubStartTime < FLEXERA_MIN_HOLD_MS) {
|
||||
// The finger left almost as soon as the hold was noticed, so it was not
|
||||
// holding: an ordinary swipe slowed down at its end. Open the drawer the way
|
||||
// that swipe would have, with the list where it was.
|
||||
app.flexera.drawer.FlexeraDrawer.cancelScrubFromSwipe(mLauncher.getAppsView());
|
||||
} else {
|
||||
app.flexera.drawer.FlexeraDrawer.endScrubFromSwipe(mLauncher.getAppsView());
|
||||
}
|
||||
if (mFlexeraDrawerOpen) {
|
||||
onSwipeInteractionCompleted(ALL_APPS);
|
||||
}
|
||||
} else if (mStartedOverview) {
|
||||
@@ -282,26 +311,34 @@ public class NoButtonNavbarToOverviewTouchController extends PortraitStatesTouch
|
||||
}
|
||||
|
||||
/**
|
||||
* Flexera Launcher: the finger paused part-way through a swipe up. Finish opening the drawer
|
||||
* and, once it is open, let the same touch scrub the wave alphabet. This mirrors
|
||||
* {@link #onMotionPauseDetected()}, which does the same hand-over to Overview.
|
||||
* Flexera Launcher: the finger paused part-way through a swipe up. From this moment the same
|
||||
* touch scrubs the wave alphabet, with no wait: the alphabet takes the finger where it is,
|
||||
* and the drawer finishes opening under it.
|
||||
*/
|
||||
private void onFlexeraHoldDetected() {
|
||||
if (mCurrentAnimation == null || mFlexeraScrubStarted || !flexeraHoldToScrub()) {
|
||||
return;
|
||||
}
|
||||
mCurrentAnimation.getTarget().addListener(newSingleUseCancelListener(() ->
|
||||
mLauncher.getStateManager().goToState(ALL_APPS, true, forSuccessCallback(() -> {
|
||||
mFlexeraScrubReady = true;
|
||||
if (!mDetector.isDraggingState()) {
|
||||
// The finger lifted while the drawer was still opening.
|
||||
onSwipeInteractionCompleted(ALL_APPS);
|
||||
}
|
||||
}))));
|
||||
|
||||
mCurrentAnimation.getTarget().removeListener(mClearStateOnCancelListener);
|
||||
mCurrentAnimation.dispatchOnCancel();
|
||||
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.
|
||||
mCurrentAnimation.setEndAction(() -> {
|
||||
mFlexeraDrawerOpen = true;
|
||||
if (!mDetector.isDraggingState()) {
|
||||
// The finger lifted while the drawer was still opening.
|
||||
onSwipeInteractionCompleted(ALL_APPS);
|
||||
}
|
||||
});
|
||||
ValueAnimator anim = mCurrentAnimation.getAnimationPlayer();
|
||||
anim.setFloatValues(
|
||||
Utilities.boundToRange(mCurrentAnimation.getProgressFraction(), 0f, 1f), 1f);
|
||||
anim.setDuration(FLEXERA_HOLD_OPEN_MS).setInterpolator(DECELERATE);
|
||||
mCurrentAnimation.dispatchOnStart();
|
||||
anim.start();
|
||||
VibratorWrapper.INSTANCE.get(mLauncher).vibrate(OVERVIEW_HAPTIC);
|
||||
}
|
||||
|
||||
@@ -320,13 +357,15 @@ public class NoButtonNavbarToOverviewTouchController extends PortraitStatesTouch
|
||||
|
||||
@Override
|
||||
public boolean onDrag(float yDisplacement, float xDisplacement, MotionEvent event) {
|
||||
// Flexera Launcher: remembered so that a hold, which can be noticed between two touch
|
||||
// events, knows where the finger is.
|
||||
mFlexeraLastX = event.getX();
|
||||
mFlexeraLastY = event.getY();
|
||||
if (mFlexeraScrubStarted) {
|
||||
// Flexera Launcher: the swipe has become a scrub; the finger now moves the alphabet,
|
||||
// not the drawer. Until the drawer has finished opening there is nothing to move yet.
|
||||
if (mFlexeraScrubReady) {
|
||||
app.flexera.drawer.FlexeraDrawer.scrubFromSwipe(
|
||||
mLauncher.getAppsView(), mLauncher.getDragLayer(), event);
|
||||
}
|
||||
// not the drawer.
|
||||
app.flexera.drawer.FlexeraDrawer.scrubFromSwipe(
|
||||
mLauncher.getAppsView(), mLauncher.getDragLayer(), mFlexeraLastX, mFlexeraLastY);
|
||||
return true;
|
||||
}
|
||||
if (mStartedOverview) {
|
||||
|
||||
@@ -76,6 +76,9 @@ public class MotionPauseDetector {
|
||||
private boolean mDisallowPause;
|
||||
// Time at which speed became < mSpeedSlow (only used if mMakePauseHarderToTrigger == true).
|
||||
private long mSlowStartTime;
|
||||
// Flexera Launcher: how long without motion counts as a pause. A gesture may shorten it
|
||||
// (see setForcePauseTimeout); clear() puts the stock value back.
|
||||
private long mForcePauseTimeoutMs = FORCE_PAUSE_TIMEOUT;
|
||||
|
||||
public MotionPauseDetector(Context context) {
|
||||
this(context, false);
|
||||
@@ -122,6 +125,15 @@ public class MotionPauseDetector {
|
||||
mIsTrackpadGesture = isTrackpadGesture;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flexera Launcher: sets how long the finger must stay still before that alone counts as a
|
||||
* pause, for the gesture in progress. Swipe up and hold (PRD AD-17) uses a shorter time
|
||||
* than the stock 300 ms, so the alphabet answers a hold without a noticeable wait.
|
||||
*/
|
||||
public void setForcePauseTimeout(long timeoutMs) {
|
||||
mForcePauseTimeoutMs = timeoutMs;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param disallowPause If true, we will not detect any pauses until this is set to false again.
|
||||
*/
|
||||
@@ -153,7 +165,7 @@ public class MotionPauseDetector {
|
||||
? TEST_HARNESS_TRIGGER_TIMEOUT
|
||||
: mMakePauseHarderToTrigger
|
||||
? HARDER_TRIGGER_TIMEOUT
|
||||
: FORCE_PAUSE_TIMEOUT;
|
||||
: mForcePauseTimeoutMs;
|
||||
mForcePauseTimeout.setAlarm(timeoutMs);
|
||||
float newVelocity = mVelocityProvider.addMotionEvent(ev, ev.getPointerId(pointerIndex));
|
||||
if (mPreviousVelocity != null) {
|
||||
@@ -262,6 +274,7 @@ public class MotionPauseDetector {
|
||||
mIsTrackpadGesture = false;
|
||||
mIsPaused = mHasEverBeenPaused = false;
|
||||
mSlowStartTime = 0;
|
||||
mForcePauseTimeoutMs = FORCE_PAUSE_TIMEOUT;
|
||||
mForcePauseTimeout.cancelAlarm();
|
||||
}
|
||||
|
||||
|
||||
@@ -1413,6 +1413,11 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver,
|
||||
setContentDescription(itemInfo.contentDescription);
|
||||
}
|
||||
}
|
||||
// Flexera Launcher: a row in the drawer list shows its app's latest notification
|
||||
// under the app name (PRD AD-11).
|
||||
if (mDisplay == DISPLAY_ALL_APPS) {
|
||||
app.flexera.drawer.FlexeraNotificationPreview.apply(this, itemInfo, mDotInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -192,6 +192,8 @@ public class ActivityAllAppsContainerView<T extends Context & ActivityContext>
|
||||
protected View mSearchContainer;
|
||||
protected SearchUiManager mSearchUiManager;
|
||||
protected boolean mUsingTabs;
|
||||
// Flexera Launcher: see replaceAppsRVContainer.
|
||||
private boolean mFlexeraSearchFieldScrolls;
|
||||
protected RecyclerViewFastScroller mTouchHandler;
|
||||
|
||||
/** {@code true} when rendered view is in search state instead of the scroll state. */
|
||||
@@ -849,9 +851,28 @@ public class ActivityAllAppsContainerView<T extends Context & ActivityContext>
|
||||
layoutBelowSearchContainer(getSearchRecyclerView(), /* tabs= */ false);
|
||||
}
|
||||
|
||||
// Flexera Launcher: the search field scrolls away with the list. For that the list
|
||||
// starts at the top of the drawer, not under the field, and keeps the field's room as
|
||||
// top padding (AdapterHolder.applyPadding); FlexeraDrawer.moveSearchFieldWithList then
|
||||
// moves the field as the list scrolls. Work tabs sit between the two and stay put, so
|
||||
// with tabs the field stays where it is, as before.
|
||||
mFlexeraSearchFieldScrolls =
|
||||
!showTabs && !isAppDrawerSearchBarHidden() && !isSearchBarFloating();
|
||||
if (mFlexeraSearchFieldScrolls
|
||||
&& rvContainer.getLayoutParams() instanceof RelativeLayout.LayoutParams lp) {
|
||||
lp.removeRule(RelativeLayout.ALIGN_TOP);
|
||||
lp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
|
||||
lp.topMargin = 0;
|
||||
}
|
||||
|
||||
updateSearchResultsVisibility();
|
||||
}
|
||||
|
||||
/** Flexera Launcher: true while the search field scrolls away with the list. */
|
||||
public boolean flexeraSearchFieldScrolls() {
|
||||
return mFlexeraSearchFieldScrolls;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up header rows and hides the header shell when neither tabs nor visible row content
|
||||
* requires it, keeping adapter top padding consistent with that visibility.
|
||||
@@ -917,6 +938,8 @@ public class ActivityAllAppsContainerView<T extends Context & ActivityContext>
|
||||
}
|
||||
|
||||
protected void updateHeaderScroll(int scrolledOffset) {
|
||||
// Flexera Launcher: the search field moves up with the list.
|
||||
app.flexera.drawer.FlexeraDrawer.moveSearchFieldWithList(this);
|
||||
if (isAppDrawerSearchBarHidden() && !mUsingTabs)
|
||||
return;
|
||||
|
||||
@@ -1421,6 +1444,11 @@ public class ActivityAllAppsContainerView<T extends Context & ActivityContext>
|
||||
setPadding(grid.allAppsLeftRightMargin, topPadding, grid.allAppsLeftRightMargin, 0);
|
||||
}
|
||||
InsettableFrameLayout.dispatchInsets(this, insets);
|
||||
// Flexera Launcher: the list's top padding follows the search field's place, which the
|
||||
// line above may just have changed.
|
||||
if (mFlexeraSearchFieldScrolls) {
|
||||
mAH.get(AdapterHolder.MAIN).applyPadding();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1905,7 +1933,17 @@ public class ActivityAllAppsContainerView<T extends Context & ActivityContext>
|
||||
if (isSearchBarFloating()) {
|
||||
bottomOffset += mSearchContainer.getHeight();
|
||||
}
|
||||
mRecyclerView.setPadding(mPadding.left, mPadding.top, mPadding.right,
|
||||
int top = mPadding.top;
|
||||
// Flexera Launcher: the room the search field takes at the top of the list, now
|
||||
// that the list starts above the field (see replaceAppsRVContainer): the
|
||||
// field's own distance from the top, and what used to be kept under its top edge.
|
||||
if (mFlexeraSearchFieldScrolls && isMain()) {
|
||||
top += getResources().getDimensionPixelSize(R.dimen.all_apps_header_top_margin);
|
||||
if (mSearchContainer.getLayoutParams() instanceof MarginLayoutParams field) {
|
||||
top += field.topMargin;
|
||||
}
|
||||
}
|
||||
mRecyclerView.setPadding(mPadding.left, top, mPadding.right,
|
||||
mPadding.bottom + bottomOffset);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,13 +129,23 @@ public class NotificationListener extends NotificationListenerService {
|
||||
switch (message.what) {
|
||||
case MSG_NOTIFICATION_POSTED: {
|
||||
StatusBarNotification sbn = (StatusBarNotification) message.obj;
|
||||
mUiHandler.obtainMessage(notificationIsValidForUI(sbn)
|
||||
// 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).
|
||||
boolean validForUi = notificationIsValidForUI(sbn);
|
||||
if (validForUi) {
|
||||
app.flexera.drawer.FlexeraNotificationPreview.onPosted(sbn);
|
||||
} else {
|
||||
app.flexera.drawer.FlexeraNotificationPreview.onRemoved(sbn);
|
||||
}
|
||||
mUiHandler.obtainMessage(validForUi
|
||||
? MSG_NOTIFICATION_POSTED : MSG_NOTIFICATION_REMOVED,
|
||||
toKeyPair(sbn)).sendToTarget();
|
||||
return true;
|
||||
}
|
||||
case MSG_NOTIFICATION_REMOVED: {
|
||||
StatusBarNotification sbn = (StatusBarNotification) message.obj;
|
||||
// Flexera Launcher: drop the notification's preview text with its dot.
|
||||
app.flexera.drawer.FlexeraNotificationPreview.onRemoved(sbn);
|
||||
mUiHandler.obtainMessage(MSG_NOTIFICATION_REMOVED,
|
||||
toKeyPair(sbn)).sendToTarget();
|
||||
|
||||
@@ -158,6 +168,8 @@ public class NotificationListener extends NotificationListenerService {
|
||||
} else {
|
||||
activeNotifications = new ArrayList<>();
|
||||
}
|
||||
// Flexera Launcher: rebuild the preview texts from the same list as the dots.
|
||||
app.flexera.drawer.FlexeraNotificationPreview.onFullRefresh(activeNotifications);
|
||||
|
||||
mUiHandler.obtainMessage(message.what, activeNotifications).sendToTarget();
|
||||
return true;
|
||||
|
||||
@@ -102,9 +102,11 @@ public class PopupDataProvider implements NotificationListener.NotificationsChan
|
||||
dotInfo = new DotInfo();
|
||||
mPackageUserToDotInfos.put(postedPackageUserKey, dotInfo);
|
||||
}
|
||||
if (dotInfo.addOrUpdateNotificationKey(notificationKey)) {
|
||||
updateNotificationDots(postedPackageUserKey::equals);
|
||||
}
|
||||
// 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);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -21,6 +21,7 @@ import android.appwidget.AppWidgetManager.OPTION_APPWIDGET_SIZES
|
||||
import android.appwidget.AppWidgetProviderInfo
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.util.SizeF
|
||||
import com.android.launcher3.dagger.ApplicationContext
|
||||
import com.android.launcher3.util.Executors
|
||||
@@ -46,13 +47,24 @@ open class WidgetSizeHandler @Inject constructor(@ApplicationContext private val
|
||||
spanY: Int,
|
||||
) {
|
||||
Executors.UI_HELPER_EXECUTOR.execute {
|
||||
val widgetManager = AppWidgetManager.getInstance(context)
|
||||
val sizeOptions = WidgetSizes.getWidgetSizeOptions(context, info.provider, spanX, spanY)
|
||||
if (
|
||||
sizeOptions.getWidgetSizeList() !=
|
||||
widgetManager.getAppWidgetOptions(widgetId).getWidgetSizeList()
|
||||
)
|
||||
widgetManager.updateAppWidgetOptions(widgetId, sizeOptions)
|
||||
// Flexera Launcher: a widget that still waits for "tap to set up" has an id that
|
||||
// Android has reserved but not yet tied to a provider. Android answers a size
|
||||
// update for such an id with a NullPointerException of its own (seen on Android 17:
|
||||
// AppWidgetServiceImpl.updateAppWidgetOptions), which arrives here and used to end
|
||||
// the launcher whenever the grid reloaded with such a widget on a home screen. That
|
||||
// is the normal state after a layout import, so the answer is logged and dropped;
|
||||
// the size is sent again when the widget is set up.
|
||||
try {
|
||||
val widgetManager = AppWidgetManager.getInstance(context)
|
||||
val sizeOptions = WidgetSizes.getWidgetSizeOptions(context, info.provider, spanX, spanY)
|
||||
if (
|
||||
sizeOptions.getWidgetSizeList() !=
|
||||
widgetManager.getAppWidgetOptions(widgetId).getWidgetSizeList()
|
||||
)
|
||||
widgetManager.updateAppWidgetOptions(widgetId, sizeOptions)
|
||||
} catch (e: RuntimeException) {
|
||||
Log.w("WidgetSizeHandler", "Android refused the size of widget $widgetId", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -121,6 +121,12 @@ public class PersonalWorkSlidingTabStrip extends LinearLayout implements PageInd
|
||||
*/
|
||||
public static int getTabWidth(Context context, int totalWidth) {
|
||||
DeviceProfile grid = ActivityContext.lookupContext(context).getDeviceProfile();
|
||||
// Flexera Launcher: the one-column drawer list has no left and right icon to span. The
|
||||
// grid maths below would make the tabs and the work info card one icon wide, so line
|
||||
// them up with the search bar instead.
|
||||
if (grid.numShownAllAppsColumns == app.flexera.drawer.FlexeraDrawer.COLUMNS) {
|
||||
return totalWidth - 2 * app.flexera.drawer.FlexeraDrawer.rowStartPadding(context);
|
||||
}
|
||||
int iconPadding = totalWidth / grid.numShownAllAppsColumns
|
||||
- grid.getAllAppsProfile().getIconSizePx();
|
||||
return totalWidth - iconPadding;
|
||||
|
||||
Reference in new issue
Block a user