Create IconPackSettings Composable
This commit is contained in:
@@ -28,5 +28,11 @@
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name="ch.deletescape.lawnchair.settings.activities.IconPackSettingsActivity" android:theme="@style/Theme.Lawnchair">
|
||||
<intent-filter>
|
||||
<action android:name="ch.deletescape.lawnchair.settings.activities.IconPackSettingsActivity" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
</manifest>
|
||||
@@ -17,4 +17,8 @@
|
||||
|
||||
<Preference android:title="Icon Pack" android:fragment="ch.deletescape.lawnchair.settings.fragments.IconPackSettingsFragment" />
|
||||
|
||||
<Preference android:title="Icon Pack (Jetpack Compose)">
|
||||
<intent android:action="ch.deletescape.lawnchair.settings.activities.IconPackSettingsActivity" />
|
||||
</Preference>
|
||||
|
||||
</androidx.preference.PreferenceScreen>
|
||||
|
||||
+138
@@ -0,0 +1,138 @@
|
||||
package ch.deletescape.lawnchair.settings.activities
|
||||
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.os.Bundle
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.appcompat.content.res.AppCompatResources
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.*
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.outlined.ArrowBack
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.asImageBitmap
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.core.graphics.drawable.toBitmap
|
||||
import ch.deletescape.lawnchair.settings.ui.theme.LawnchairTheme
|
||||
import com.android.launcher3.R
|
||||
|
||||
class IconPackSettingsActivity : AppCompatActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContent {
|
||||
LawnchairTheme {
|
||||
Surface(
|
||||
color = MaterialTheme.colors.background,
|
||||
modifier = Modifier.fillMaxHeight()
|
||||
) {
|
||||
IconPackSettings()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
data class IconPackInfo(val name: String, val packageName: String, val icon: Drawable)
|
||||
|
||||
val dataSet by lazy {
|
||||
listOf(
|
||||
IconPackInfo(
|
||||
"System Icons",
|
||||
"",
|
||||
AppCompatResources.getDrawable(applicationContext, R.drawable.ic_launcher_home)!!
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun IconPackSettings() {
|
||||
var selectedIconPackPackageName by remember { mutableStateOf("") }
|
||||
Column {
|
||||
TopAppBar(
|
||||
title = { Text(text = "Icon Packs") },
|
||||
backgroundColor = MaterialTheme.colors.background,
|
||||
navigationIcon = {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.padding(start = 4.dp)
|
||||
.height(40.dp)
|
||||
.width(40.dp)
|
||||
.clip(shape = RoundedCornerShape(20.dp))
|
||||
.clickable { finish() },
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Icon(
|
||||
Icons.Outlined.ArrowBack,
|
||||
"Back",
|
||||
modifier = Modifier,
|
||||
MaterialTheme.colors.onBackground
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
IconPackList(
|
||||
dataSet,
|
||||
selectedIconPackPackageName,
|
||||
onSelectionChange = { selectedIconPackPackageName = it })
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun IconPackList(
|
||||
iconPacks: List<IconPackInfo>,
|
||||
selectedIconPackPackageName: String,
|
||||
modifier: Modifier = Modifier,
|
||||
onSelectionChange: (String) -> Unit
|
||||
) {
|
||||
Box(modifier) {
|
||||
LazyColumn(Modifier.fillMaxWidth()) {
|
||||
items(iconPacks) { iconPack ->
|
||||
IconPackListItem(iconPack, selectedIconPackPackageName, onSelectionChange)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun IconPackListItem(
|
||||
iconPack: IconPackInfo,
|
||||
selectedIconPackPackageName: String,
|
||||
onSelectionChange: (String) -> Unit
|
||||
) {
|
||||
fun select() {
|
||||
onSelectionChange(iconPack.packageName)
|
||||
}
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(56.dp)
|
||||
.clickable { select() }
|
||||
.padding(start = 16.dp)
|
||||
) {
|
||||
RadioButton(
|
||||
selected = iconPack.packageName == selectedIconPackPackageName,
|
||||
{ select() })
|
||||
Image(
|
||||
iconPack.icon.toBitmap().asImageBitmap(),
|
||||
iconPack.name,
|
||||
modifier = Modifier
|
||||
.padding(start = 32.dp)
|
||||
.width(36.dp)
|
||||
.height(36.dp)
|
||||
)
|
||||
Text(
|
||||
modifier = Modifier.padding(start = 16.dp),
|
||||
text = iconPack.name,
|
||||
style = MaterialTheme.typography.body1
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package ch.deletescape.lawnchair.settings.ui.theme
|
||||
|
||||
import androidx.compose.ui.graphics.Color
|
||||
|
||||
val Purple200 = Color(0xFFBB86FC)
|
||||
val Purple500 = Color(0xFF6200EE)
|
||||
val Purple700 = Color(0xFF3700B3)
|
||||
val Teal200 = Color(0xFF03DAC5)
|
||||
@@ -0,0 +1,11 @@
|
||||
package ch.deletescape.lawnchair.settings.ui.theme
|
||||
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.Shapes
|
||||
import androidx.compose.ui.unit.dp
|
||||
|
||||
val Shapes = Shapes(
|
||||
small = RoundedCornerShape(4.dp),
|
||||
medium = RoundedCornerShape(4.dp),
|
||||
large = RoundedCornerShape(0.dp)
|
||||
)
|
||||
@@ -0,0 +1,47 @@
|
||||
package ch.deletescape.lawnchair.settings.ui.theme
|
||||
|
||||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.material.MaterialTheme
|
||||
import androidx.compose.material.darkColors
|
||||
import androidx.compose.material.lightColors
|
||||
import androidx.compose.runtime.Composable
|
||||
|
||||
private val DarkColorPalette = darkColors(
|
||||
primary = Purple200,
|
||||
primaryVariant = Purple500,
|
||||
secondary = Purple200
|
||||
)
|
||||
|
||||
private val LightColorPalette = lightColors(
|
||||
primary = Purple500,
|
||||
primaryVariant = Purple700,
|
||||
secondary = Purple500
|
||||
|
||||
/* Other default colors to override
|
||||
background = Color.White,
|
||||
surface = Color.White,
|
||||
onPrimary = Color.White,
|
||||
onSecondary = Color.Black,
|
||||
onBackground = Color.Black,
|
||||
onSurface = Color.Black,
|
||||
*/
|
||||
)
|
||||
|
||||
@Composable
|
||||
fun LawnchairTheme(
|
||||
darkTheme: Boolean = isSystemInDarkTheme(),
|
||||
content: @Composable() () -> Unit
|
||||
) {
|
||||
val colors = if (darkTheme) {
|
||||
DarkColorPalette
|
||||
} else {
|
||||
LightColorPalette
|
||||
}
|
||||
|
||||
MaterialTheme(
|
||||
colors = colors,
|
||||
typography = Typography,
|
||||
shapes = Shapes,
|
||||
content = content
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package ch.deletescape.lawnchair.settings.ui.theme
|
||||
|
||||
import androidx.compose.material.Typography
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.text.font.FontFamily
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.sp
|
||||
|
||||
// Set of Material typography styles to start with
|
||||
val Typography = Typography(
|
||||
body1 = TextStyle(
|
||||
fontFamily = FontFamily.Default,
|
||||
fontWeight = FontWeight.Normal,
|
||||
fontSize = 16.sp
|
||||
)
|
||||
/* Other default text styles to override
|
||||
button = TextStyle(
|
||||
fontFamily = FontFamily.Default,
|
||||
fontWeight = FontWeight.W500,
|
||||
fontSize = 14.sp
|
||||
),
|
||||
caption = TextStyle(
|
||||
fontFamily = FontFamily.Default,
|
||||
fontWeight = FontWeight.Normal,
|
||||
fontSize = 12.sp
|
||||
)
|
||||
*/
|
||||
)
|
||||
Reference in New Issue
Block a user