Skip to content

Commit 6ec1460

Browse files
committed
Fix: Applying icon shape directly
1 parent 26298bb commit 6ec1460

File tree

5 files changed

+130
-20
lines changed

5 files changed

+130
-20
lines changed

Omega/src/com/neoapps/neolauncher/icons/IconShape.kt

Lines changed: 110 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ package com.neoapps.neolauncher.icons
2020

2121
import android.content.Context
2222
import android.graphics.Path
23+
import android.graphics.PathIterator
2324
import android.graphics.PointF
2425
import android.util.Log
2526
import com.android.launcher3.R
2627
import com.android.launcher3.Utilities
28+
import com.android.launcher3.shapes.IconShapeModel
2729

2830
open class IconShape(
2931
private val topLeft: Corner,
@@ -368,6 +370,47 @@ open class IconShape(
368370
}
369371
}
370372

373+
open fun toPathString(): String {
374+
val path = getMaskPath()
375+
return pathToSvgString(path)
376+
}
377+
378+
open fun getFolderRadiusRatio(): Float {
379+
val avgScale = (topLeft.scale.x + topLeft.scale.y +
380+
topRight.scale.x + topRight.scale.y +
381+
bottomLeft.scale.x + bottomLeft.scale.y +
382+
bottomRight.scale.x + bottomRight.scale.y) / 8f
383+
return avgScale
384+
}
385+
386+
open fun getShapeRadius(): Float {
387+
return when (this) {
388+
is Circle -> 26f
389+
is Square -> 17.33f
390+
is SharpSquare -> 0f
391+
is RoundedSquare -> 20f
392+
is Squircle -> 26f
393+
is Sammy -> 26f
394+
is Teardrop -> 22f
395+
is Cylinder -> 24f
396+
is Cupertino -> 16f
397+
is Hexagon -> 15f
398+
is Octagon -> 18f
399+
is Egg -> 23f
400+
else -> 26f // Default for custom shapes
401+
}
402+
}
403+
404+
fun toIconShapeModel(key: String, titleId: Int): IconShapeModel {
405+
return IconShapeModel(
406+
key = key,
407+
titleId = titleId,
408+
pathString = toPathString(),
409+
folderRadiusRatio = getFolderRadiusRatio(),
410+
shapeRadius = getShapeRadius()
411+
)
412+
}
413+
371414
companion object {
372415

373416
fun fromString(context: Context, value: String): IconShape {
@@ -380,20 +423,21 @@ open class IconShape(
380423
}
381424

382425
fun fromString(value: String): IconShape = when (value) {
383-
"circle" -> Circle
384-
"square" -> Square
385-
"sharpSquare" -> SharpSquare
426+
// TODO add constants instead of string literals
427+
"circle" -> Circle
428+
"square" -> Square
429+
"sharpSquare" -> SharpSquare
386430
"roundedSquare" -> RoundedSquare
387-
"squircle" -> Squircle
388-
"sammy" -> Sammy
389-
"teardrop" -> Teardrop
390-
"cylinder" -> Cylinder
391-
"cupertino" -> Cupertino
392-
"hexagon" -> Hexagon
393-
"octagon" -> Octagon
394-
"egg" -> Egg
395-
"" -> Circle
396-
else -> runCatching { parseCustomShape(value) }.getOrDefault(Circle)
431+
"squircle" -> Squircle
432+
"sammy" -> Sammy
433+
"teardrop" -> Teardrop
434+
"cylinder" -> Cylinder
435+
"cupertino" -> Cupertino
436+
"hexagon" -> Hexagon
437+
"octagon" -> Octagon
438+
"egg" -> Egg
439+
"" -> Circle
440+
else -> runCatching { parseCustomShape(value) }.getOrDefault(Circle)
397441
}
398442

399443
private fun parseCustomShape(value: String): IconShape {
@@ -408,6 +452,59 @@ open class IconShape(
408452
)
409453
}
410454

455+
private fun pathToSvgString(path: Path): String {
456+
return buildString {
457+
val points = FloatArray(8)
458+
val iterator = path.pathIterator
459+
460+
while (iterator.hasNext()) {
461+
when (iterator.next(points, 0)) {
462+
PathIterator.VERB_MOVE -> {
463+
append("M${points[0]} ${points[1]} ")
464+
}
465+
466+
PathIterator.VERB_LINE -> {
467+
append("L${points[0]} ${points[1]} ")
468+
}
469+
470+
PathIterator.VERB_CONIC -> {
471+
append("C${points[0]} ${points[1]} ")
472+
append("${points[2]} ${points[3]} ")
473+
append("${points[4]} ${points[5]} ")
474+
}
475+
476+
PathIterator.VERB_QUAD -> {
477+
append("Q${points[0]} ${points[1]} ")
478+
append("${points[2]} ${points[3]} ")
479+
}
480+
481+
PathIterator.VERB_CLOSE -> append("Z ")
482+
}
483+
}
484+
}.trim()
485+
}
486+
487+
fun getAllShapeModels(): Array<IconShapeModel> {
488+
return arrayOf(
489+
// TODO use constants instead of string literals for keys
490+
Circle.toIconShapeModel("circle", R.string.circle_shape_title),
491+
Square.toIconShapeModel("square", R.string.square_shape_title),
492+
SharpSquare.toIconShapeModel("sharp_square", R.string.sharp_square_shape_title),
493+
RoundedSquare.toIconShapeModel(
494+
"rounded_square",
495+
R.string.rounded_square_shape_title
496+
),
497+
Squircle.toIconShapeModel("squircle", R.string.squircle_shape_title),
498+
Sammy.toIconShapeModel("sammy", R.string.sammy_shape_title),
499+
Teardrop.toIconShapeModel("teardrop", R.string.teardrop_shape_title),
500+
Cylinder.toIconShapeModel("cylinder", R.string.cylinder_shape_title),
501+
Cupertino.toIconShapeModel("cupertino", R.string.cupertino_shape_title),
502+
Hexagon.toIconShapeModel("hexagon", R.string.hexagon_shape_title),
503+
Octagon.toIconShapeModel("octagon", R.string.octagon_shape_title),
504+
Egg.toIconShapeModel("egg", R.string.egg_shape_title)
505+
)
506+
}
507+
411508
fun isCustomShape(iconShape: IconShape): Boolean {
412509
return try {
413510
parseCustomShape(iconShape.toString())

Omega/src/com/neoapps/neolauncher/preferences/NeoPrefs.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,13 +1258,11 @@ class NeoPrefs private constructor(val context: Context) {
12581258
)
12591259

12601260
init {
1261-
val iconShape = IconShape.fromString(context, profileIconShape.getValue())
1262-
initializeIconShape(iconShape)
12631261
profileIconShape.get()
1264-
.drop(1)
12651262
.distinctUntilChanged()
12661263
.onEach { shape ->
1267-
initializeIconShape(IconShape.fromString(context, shape))
1264+
val iconShape = IconShape.fromString(context, profileIconShape.getValue())
1265+
initializeIconShape(iconShape)
12681266
ThemeManager.INSTANCE.get(context)
12691267
LauncherAppState.getInstance(context).model.reloadIfActive()
12701268
}

res/values/strings.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,5 +570,15 @@
570570
<string name="seven_sided_cookie_shape_title">7-sided cookie</string>
571571
<!-- label for arch shape option in customization picker -->
572572
<string name="arch_shape_title">Arch</string>
573+
<string name="sharp_square_shape_title">Sharp Square</string>
574+
<string name="rounded_square_shape_title">Rounded Square</string>
575+
<string name="squircle_shape_title">Squircle</string>
576+
<string name="sammy_shape_title">Samsung</string>
577+
<string name="teardrop_shape_title">Teardrop</string>
578+
<string name="cylinder_shape_title">Cylinder</string>
579+
<string name="cupertino_shape_title">iOS (Cupertino)</string>
580+
<string name="hexagon_shape_title">Hexagon</string>
581+
<string name="octagon_shape_title">Octagon</string>
582+
<string name="egg_shape_title">Egg</string>
573583

574584
</resources>

src/com/android/launcher3/graphics/ThemeManager.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import com.android.launcher3.dagger.LauncherAppComponent
2727
import com.android.launcher3.dagger.LauncherAppSingleton
2828
import com.android.launcher3.graphics.ShapeDelegate.Companion.DEFAULT_PATH_SIZE_INT
2929
import com.android.launcher3.graphics.ShapeDelegate.Companion.pickBestShape
30+
import com.android.launcher3.graphics.ThemeManager.Companion.createIconShape
3031
import com.android.launcher3.graphics.theme.IconThemeFactory
3132
import com.android.launcher3.graphics.theme.ThemePreference
3233
import com.android.launcher3.graphics.theme.ThemePreference.Companion.MONO_THEME_VALUE
@@ -172,6 +173,7 @@ constructor(
172173
}
173174

174175
return IconState(
176+
key = shapeModel?.key ?: "",
175177
iconMask = iconMask,
176178
folderRadius = folderRadius,
177179
themeController = iconControllerFactory,
@@ -183,6 +185,7 @@ constructor(
183185
}
184186

185187
data class IconState(
188+
val key: String,
186189
val iconMask: String,
187190
val folderRadius: Float,
188191
val themeController: IconThemeController?,
@@ -193,7 +196,7 @@ constructor(
193196
val folderShape: ShapeDelegate,
194197
val shapeRadius: Float,
195198
) {
196-
fun toUniqueId() = "$themeCode,$isCircle"
199+
fun toUniqueId() = "$key,$themeCode,$isCircle"
197200

198201
val iconShapeInfo = IconShapeInfo.fromPath(iconShape.getPath(), DEFAULT_PATH_SIZE_INT)
199202
val folderShapeInfo = IconShapeInfo.fromPath(folderShape.getPath(), DEFAULT_PATH_SIZE_INT)

src/com/android/launcher3/shapes/ShapesProvider.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package com.android.launcher3.shapes
1919
import com.android.launcher3.Flags as LauncherFlags
2020
import com.android.launcher3.R
2121
import com.android.systemui.shared.Flags
22+
import com.neoapps.neolauncher.icons.IconShape
2223

2324
object ShapesProvider {
2425
private const val CIRCLE_PATH = "M50 0A50 50,0,1,1,50 100A50 50,0,1,1,50 0"
@@ -37,7 +38,8 @@ object ShapesProvider {
3738
const val ARCH_KEY = "arch"
3839

3940
val iconShapes: Array<IconShapeModel> =
40-
if (Flags.newCustomizationPickerUi() && LauncherFlags.enableLauncherIconShapes()) {
41+
IconShape.getAllShapeModels()
42+
/*if (Flags.newCustomizationPickerUi() && LauncherFlags.enableLauncherIconShapes()) {
4143
arrayOf(
4244
IconShapeModel(
4345
key = CIRCLE_KEY,
@@ -79,5 +81,5 @@ object ShapesProvider {
7981
pathString = CIRCLE_PATH,
8082
)
8183
)
82-
}
84+
}*/
8385
}

0 commit comments

Comments
 (0)