mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-21 13:55:58 +00:00
feat(apps): add icon packs, per-app icons and an Appearance panel (#2207)
* feat(apps): add an Appearance panel to the Apps page A Palette button in the Apps header opens a panel for icon size, spacing and hiding app names. * feat(apps): support icon packs and per-app icons The Appearance panel gains an Icon pack choice. Packs are found through the ADW and Nova theme intents and must ship an appfilter.xml in res/xml, res/raw or assets. Work profile apps keep their badge. Apps a pack does not cover are drawn on its iconback, iconmask, iconupon and scale tags when it has them, and keep their system icon otherwise. For packs with an iconback, App color background paints that plate in each app's main color instead of the pack's own. With a pack selected, an app's long-press menu offers Change icon, which opens a searchable picker listing icons that match the app first. Reset icon removes one choice, and Reset in the panel removes them all. Calendar apps use the pack's icon for today's date. * feat(apps): translate the Appearance panel and icon strings Adds the 19 new strings to all 32 languages, reusing each language's existing wording where it has one. Icon size and spacing labels are kept short to fit the panel's tabs. * fix(apps): finish loading custom icons before marking them loaded Two app list refreshes can start together on resume. The second one could see the overrides as loaded before the first had read them, and build the list without custom icons.
This commit is contained in:
1 parent
dacfee64ab
commit
b1b6ab7931
47 files changed
+1475
-23
No files matched your search
@@ -0,0 +1,26 @@
|
||||
package com.droiddeck.launcher
|
||||
|
||||
import com.droiddeck.launcher.ui.iconMatches
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Test
|
||||
|
||||
class HomeIconsTest {
|
||||
@Test fun aChoiceSurvivesEncoding() {
|
||||
val choice = HomeIcons.Choice("com.pack", "chrome_alt")
|
||||
assertEquals("com.app/.Main#10" to choice, HomeIcons.decode(HomeIcons.encode("com.app/.Main#10", choice)))
|
||||
}
|
||||
|
||||
@Test fun aDamagedEntryIsDropped() {
|
||||
assertNull(HomeIcons.decode("com.app/.Main"))
|
||||
assertNull(HomeIcons.decode("com.app/.Main\t\tchrome"))
|
||||
}
|
||||
|
||||
@Test fun iconsNamedLikeTheAppComeFirst() {
|
||||
assertEquals(listOf("google_chrome", "alarm", "zoom"), iconMatches(listOf("alarm", "google_chrome", "zoom"), "Chrome", ""))
|
||||
}
|
||||
|
||||
@Test fun aSearchIgnoresCaseAndSeparators() {
|
||||
assertEquals(listOf("google_chrome"), iconMatches(listOf("alarm", "google_chrome"), "Chrome", "Google Ch"))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
package com.droiddeck.launcher
|
||||
|
||||
import android.graphics.Color
|
||||
import android.util.Xml
|
||||
import androidx.core.graphics.createBitmap
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
import org.robolectric.annotation.GraphicsMode
|
||||
import java.io.StringReader
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [33])
|
||||
@GraphicsMode(GraphicsMode.Mode.NATIVE)
|
||||
class IconPackTest {
|
||||
private fun filter(xml: String) = IconPack.parse(Xml.newPullParser().also { it.setInput(StringReader(xml)) })
|
||||
|
||||
private fun parse(xml: String) = filter(xml).icons
|
||||
|
||||
private fun plate(xml: String) = filter(xml).plate
|
||||
|
||||
private fun solid(color: Int) = createBitmap(10, 10).also { it.eraseColor(color) }
|
||||
|
||||
@Test fun plateTagsAreReadFromTheFilter() {
|
||||
val xml = """<resources>
|
||||
<iconback img1="back" img2="other" />
|
||||
<iconmask img1="mask" />
|
||||
<iconupon img1="upon" />
|
||||
<scale factor="0.75" />
|
||||
<item component="ComponentInfo{com.example/com.example.Main}" drawable="main" />
|
||||
</resources>"""
|
||||
assertEquals(IconPack.Plate("back", "mask", "upon", 0.75f), plate(xml))
|
||||
}
|
||||
|
||||
@Test fun aPackWithoutPlateImagesHasNoPlateEvenWithAScale() {
|
||||
assertNull(plate("""<resources><iconback img1="" /><scale factor="1.0" /></resources>"""))
|
||||
}
|
||||
|
||||
@Test fun anInvalidScaleLeavesTheIconFullSize() {
|
||||
assertEquals(1f, plate("""<resources><iconback img1="back" /><scale factor="big" /></resources>""")?.scale)
|
||||
}
|
||||
|
||||
@Test fun theMaskCutsTheIconWhereItIsOpaqueAndTheBackShowsThrough() {
|
||||
val mask = createBitmap(10, 10).also { it.setPixel(0, 0, Color.BLACK) }
|
||||
val out = IconPack.compose(solid(Color.RED), solid(Color.BLUE), mask, null, 1f)
|
||||
assertEquals(Color.BLUE, out.getPixel(0, 0))
|
||||
assertEquals(Color.RED, out.getPixel(5, 5))
|
||||
}
|
||||
|
||||
@Test fun theScaleShrinksTheIconOntoTheBack() {
|
||||
val out = IconPack.compose(solid(Color.RED), solid(Color.BLUE), null, null, 0.5f)
|
||||
assertEquals(Color.BLUE, out.getPixel(1, 1))
|
||||
assertEquals(Color.RED, out.getPixel(5, 5))
|
||||
}
|
||||
|
||||
@Test fun anAppColorRepaintsTheBackInsideItsShape() {
|
||||
val back = createBitmap(10, 10).also { it.setPixel(5, 5, Color.WHITE) }
|
||||
val out = IconPack.compose(createBitmap(10, 10), back, null, null, 1f, Color.GREEN)
|
||||
assertEquals(Color.GREEN, out.getPixel(5, 5))
|
||||
assertEquals(Color.TRANSPARENT, out.getPixel(0, 0))
|
||||
}
|
||||
|
||||
@Test fun theUponImageDrawsOverEverything() {
|
||||
val out = IconPack.compose(solid(Color.RED), solid(Color.BLUE), null, solid(Color.GREEN), 1f)
|
||||
assertEquals(Color.GREEN, out.getPixel(5, 5))
|
||||
}
|
||||
|
||||
@Test fun drawableXmlNamesAreDistinctAndInOrder() {
|
||||
val xml = """<resources><category title="All" /><item drawable="b" /><item drawable="a" /><item drawable="b" /><item /></resources>"""
|
||||
assertEquals(listOf("b", "a"), IconPack.parseNames(Xml.newPullParser().also { it.setInput(StringReader(xml)) }))
|
||||
}
|
||||
|
||||
@Test fun aClassNameStartingWithADotIsExpandedWithThePackage() {
|
||||
assertEquals("com.example.app/com.example.app.Main", IconPack.componentKey("ComponentInfo{com.example.app/.Main}"))
|
||||
}
|
||||
|
||||
@Test fun entriesWithoutAUsableComponentOrDrawableAreSkipped() {
|
||||
val icons = parse(
|
||||
"""<resources>
|
||||
<item component="ComponentInfo{com.example/}" drawable="b" />
|
||||
<item component="ComponentInfo{}" drawable="c" />
|
||||
<item component="ComponentInfo{com.example/com.example.Main}" drawable="" />
|
||||
<item drawable="d" />
|
||||
<item component="ComponentInfo{com.example/com.example.Main}" />
|
||||
</resources>""",
|
||||
)
|
||||
assertTrue(icons.toString(), icons.isEmpty())
|
||||
}
|
||||
|
||||
@Test fun theFirstEntryForAComponentWins() {
|
||||
val icons = parse(
|
||||
"""<resources>
|
||||
<item component="ComponentInfo{com.example/com.example.Main}" drawable="first" />
|
||||
<item component="ComponentInfo{com.example/com.example.Main}" drawable="second" />
|
||||
</resources>""",
|
||||
)
|
||||
assertEquals("first", icons["com.example/com.example.Main"])
|
||||
}
|
||||
|
||||
@Test fun aCalendarTriesTodaysIconBeforeItsStaticOne() {
|
||||
val filter = filter(
|
||||
"""<resources>
|
||||
<calendar component="ComponentInfo{com.example/com.example.Cal}" prefix="calendar_" />
|
||||
<item component="ComponentInfo{com.example/com.example.Cal}" drawable="cal" />
|
||||
<item component="ComponentInfo{com.example/com.example.Main}" drawable="main" />
|
||||
</resources>""",
|
||||
)
|
||||
assertEquals(listOf("calendar_7", "cal"), filter.names("com.example/com.example.Cal", 7))
|
||||
assertEquals(listOf("main"), filter.names("com.example/com.example.Main", 7))
|
||||
}
|
||||
|
||||
@Test fun tagsThatAreNotItemsAreIgnored() {
|
||||
val icons = parse(
|
||||
"""<resources>
|
||||
<iconback img1="back" />
|
||||
<scale factor="0.8" />
|
||||
<calendar component="ComponentInfo{com.example/com.example.Cal}" prefix="calendar_" />
|
||||
<item component="ComponentInfo{com.example/com.example.Main}" drawable="main" />
|
||||
</resources>""",
|
||||
)
|
||||
assertEquals(mapOf("com.example/com.example.Main" to "main"), icons)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import android.content.Context
|
||||
import androidx.test.core.app.ApplicationProvider
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [33])
|
||||
class AppsGridTest {
|
||||
@Test fun anUnknownStoredGridValueFallsBackToTheDefault() {
|
||||
val context: Context = ApplicationProvider.getApplicationContext()
|
||||
context.getSharedPreferences("home_launcher", Context.MODE_PRIVATE).edit().putInt("grid_icon", 999).putInt("grid_spacing", 7).commit()
|
||||
AppsGrid.load(context)
|
||||
assertEquals(AppsGrid.MEDIUM, AppsGrid.iconDp)
|
||||
assertEquals(AppsGrid.NORMAL, AppsGrid.spacing)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user