Finish migrating Settings to Jetpack Compose
This commit is contained in:
1 parent
9c296e24b7
commit
3fec1d33e5
43 files changed
+133
-917
No files matched your search
@@ -1,5 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
<?xml version="1.0" encoding="utf-8"?><!--
|
||||
/*
|
||||
**
|
||||
** Copyright 2017, The Android Open Source Project
|
||||
@@ -18,27 +17,16 @@
|
||||
*/
|
||||
-->
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<application
|
||||
android:name="ch.deletescape.lawnchair.LawnchairApp">
|
||||
<activity android:name="ch.deletescape.lawnchair.settings.activities.SettingsActivity"
|
||||
android:autoRemoveFromRecents="true" android:label="@string/settings_button_text"
|
||||
<application android:name="ch.deletescape.lawnchair.ui.LawnchairApp">
|
||||
<activity
|
||||
android:name="ch.deletescape.lawnchair.ui.preferences.PreferenceActivity"
|
||||
android:autoRemoveFromRecents="true"
|
||||
android:label="@string/settings_button_text"
|
||||
android:theme="@style/Theme.Lawnchair">
|
||||
<intent-filter android:priority="1">
|
||||
<action android:name="android.intent.action.APPLICATION_PREFERENCES" />
|
||||
<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>
|
||||
<activity android:name="ch.deletescape.lawnchair.compose.ui.preferences.PreferenceActivity" android:theme="@style/Theme.Lawnchair">
|
||||
<intent-filter>
|
||||
<action android:name="ch.deletescape.lawnchair.compose.ui.preferences.PreferenceActivity" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
</manifest>
|
||||
@@ -35,4 +35,5 @@
|
||||
<string name="allow_empty_pages_label">Allow Empty Pages</string>
|
||||
<string name="colored_generated_icon_backgrounds_label">Make Colored Backgrounds</string>
|
||||
<string name="colored_generated_icon_backgrounds_description">For generated Adaptive icons.</string>
|
||||
<string name="notification_dots">Notification Dots</string>
|
||||
</resources>
|
||||
@@ -1,192 +0,0 @@
|
||||
package ch.deletescape.lawnchair.settings.activities
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.compose.animation.Crossfade
|
||||
import androidx.compose.animation.core.animateDp
|
||||
import androidx.compose.animation.core.updateTransition
|
||||
import androidx.compose.foundation.BorderStroke
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.*
|
||||
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.Color
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.zIndex
|
||||
import ch.deletescape.lawnchair.compose.ui.theme.LawnchairTheme
|
||||
|
||||
private enum class TabPage {
|
||||
HomeScreen, Dock, AppDrawer
|
||||
}
|
||||
|
||||
class GridSettingsActivity : AppCompatActivity() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContent {
|
||||
LawnchairTheme {
|
||||
Surface(
|
||||
color = MaterialTheme.colors.background,
|
||||
modifier = Modifier.fillMaxHeight()
|
||||
) {
|
||||
Root()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun Root() {
|
||||
var tabPage by remember { mutableStateOf(TabPage.HomeScreen) }
|
||||
|
||||
Column {
|
||||
TopAppBar(
|
||||
title = { Text(text = "Grid") },
|
||||
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
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
TabBar(tabPage = tabPage, onTabSelected = { tabPage = it })
|
||||
Crossfade(targetState = tabPage) { tabPage ->
|
||||
when (tabPage) {
|
||||
TabPage.HomeScreen -> HomeScreenGridSettings()
|
||||
TabPage.Dock -> Text("tab 2")
|
||||
TabPage.AppDrawer -> Text("tab 3")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun HomeScreenGridSettings() {
|
||||
SliderSetting()
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun TabBar(
|
||||
tabPage: TabPage,
|
||||
onTabSelected: (tabPage: TabPage) -> Unit
|
||||
) {
|
||||
Box(modifier = Modifier
|
||||
.padding(16.dp)
|
||||
.fillMaxWidth()
|
||||
.height(36.dp).zIndex(1f)) {
|
||||
TabRow(
|
||||
selectedTabIndex = tabPage.ordinal,
|
||||
modifier = Modifier
|
||||
.fillMaxSize().zIndex(2f),
|
||||
divider = {},
|
||||
backgroundColor = Color.Transparent,
|
||||
indicator = { tabPositions -> TabIndicator(tabPositions, tabPage) }) {
|
||||
Tab(
|
||||
title = "Home",
|
||||
onClick = { onTabSelected(TabPage.HomeScreen) }
|
||||
)
|
||||
Tab(
|
||||
title = "Dock",
|
||||
onClick = { onTabSelected(TabPage.Dock) }
|
||||
)
|
||||
Tab(
|
||||
title = "Drawer",
|
||||
onClick = { onTabSelected(TabPage.AppDrawer) }
|
||||
)
|
||||
}
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.border(BorderStroke(1.dp, Color.LightGray), RoundedCornerShape(8.dp))
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun TabIndicator(
|
||||
tabPositions: List<TabPosition>,
|
||||
tabPage: TabPage
|
||||
) {
|
||||
val transition = updateTransition(tabPage)
|
||||
val indicatorLeft by transition.animateDp { page -> tabPositions[page.ordinal].left }
|
||||
val indicatorRight by transition.animateDp { page -> tabPositions[page.ordinal].right }
|
||||
Box(
|
||||
Modifier
|
||||
.fillMaxSize()
|
||||
.wrapContentSize(align = Alignment.BottomStart)
|
||||
.offset(x = indicatorLeft)
|
||||
.width(indicatorRight - indicatorLeft)
|
||||
.fillMaxSize()
|
||||
.border(
|
||||
BorderStroke(1.dp, MaterialTheme.colors.primary),
|
||||
RoundedCornerShape(8.dp)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun Tab(
|
||||
title: String,
|
||||
onClick: () -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
Row(
|
||||
modifier = modifier
|
||||
.clip(RoundedCornerShape(8.dp))
|
||||
.clickable(onClick = onClick),
|
||||
horizontalArrangement = Arrangement.Center,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Text(text = title)
|
||||
}
|
||||
}
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
fun SliderSetting() {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(start = 16.dp, end = 16.dp)
|
||||
) {
|
||||
Text(text = "Test")
|
||||
Slider(value = 50F, onValueChange = {}, modifier = Modifier.fillMaxWidth())
|
||||
}
|
||||
}
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
fun Preview() {
|
||||
LawnchairTheme {
|
||||
Surface(
|
||||
color = MaterialTheme.colors.background,
|
||||
modifier = Modifier.fillMaxHeight()
|
||||
) {
|
||||
Root()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-166
@@ -1,166 +0,0 @@
|
||||
package ch.deletescape.lawnchair.settings.activities
|
||||
|
||||
import android.content.Intent
|
||||
import android.content.SharedPreferences
|
||||
import android.content.pm.ResolveInfo
|
||||
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.compose.ui.theme.LawnchairTheme
|
||||
import ch.deletescape.lawnchair.sharedprefs.LawnchairPreferences
|
||||
import com.android.launcher3.R
|
||||
import com.android.launcher3.Utilities
|
||||
|
||||
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)
|
||||
|
||||
private fun getIconPacks(): MutableMap<String, IconPackInfo> {
|
||||
val pm = this.packageManager
|
||||
val iconPacks: MutableMap<String, IconPackInfo> = HashMap()
|
||||
val list: MutableList<ResolveInfo> = pm.queryIntentActivities(Intent("com.novalauncher.THEME"), 0)
|
||||
|
||||
list.addAll(pm.queryIntentActivities(Intent("org.adw.launcher.icons.ACTION_PICK_ICON"), 0))
|
||||
list.addAll(pm.queryIntentActivities(Intent("com.dlto.atom.launcher.THEME"), 0))
|
||||
list.addAll(pm.queryIntentActivities(Intent("android.intent.action.MAIN").addCategory("com.anddoes.launcher.THEME"), 0))
|
||||
|
||||
iconPacks["system"] = IconPackInfo(
|
||||
"System Icons",
|
||||
"",
|
||||
AppCompatResources.getDrawable(this, R.drawable.ic_launcher_home)!!
|
||||
)
|
||||
|
||||
for (info in list) {
|
||||
iconPacks[info.activityInfo.packageName] = IconPackInfo(
|
||||
info.loadLabel(pm).toString(),
|
||||
info.activityInfo.packageName,
|
||||
info.loadIcon(pm)
|
||||
)
|
||||
}
|
||||
|
||||
return iconPacks
|
||||
}
|
||||
|
||||
private val sharedPref: SharedPreferences by lazy { Utilities.getPrefs(this) }
|
||||
private val dbSelectedIconPackPackageName by lazy { sharedPref.getString(LawnchairPreferences.ICON_PACK_PACKAGE, "")!! }
|
||||
|
||||
@Composable
|
||||
fun IconPackSettings() {
|
||||
var selectedIconPackPackageName by remember { mutableStateOf(dbSelectedIconPackPackageName) }
|
||||
|
||||
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(
|
||||
getIconPacks(),
|
||||
selectedIconPackPackageName,
|
||||
onSelectionChange = { selectedIconPackPackageName = it })
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun IconPackList(
|
||||
iconPacks: MutableMap<String, IconPackInfo>,
|
||||
selectedIconPackPackageName: String,
|
||||
modifier: Modifier = Modifier,
|
||||
onSelectionChange: (String) -> Unit
|
||||
) {
|
||||
Box(modifier) {
|
||||
LazyColumn(Modifier.fillMaxWidth()) {
|
||||
items(iconPacks.values.toList()) { iconPack ->
|
||||
IconPackListItem(iconPack, selectedIconPackPackageName, onSelectionChange)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun IconPackListItem(
|
||||
iconPack: IconPackInfo,
|
||||
selectedIconPackPackageName: String,
|
||||
onSelectionChange: (String) -> Unit
|
||||
) {
|
||||
fun select() {
|
||||
onSelectionChange(iconPack.packageName)
|
||||
sharedPref.edit().putString(LawnchairPreferences.ICON_PACK_PACKAGE, iconPack.packageName).apply()
|
||||
}
|
||||
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
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
package ch.deletescape.lawnchair.settings.activities
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import androidx.preference.Preference
|
||||
import androidx.preference.PreferenceFragmentCompat
|
||||
import ch.deletescape.lawnchair.settings.fragments.SettingsFragment
|
||||
import ch.deletescape.lawnchair.settings.interfaces.TitledFragment
|
||||
import com.android.launcher3.R
|
||||
import com.google.android.material.appbar.MaterialToolbar
|
||||
|
||||
class SettingsActivity : AppCompatActivity(),
|
||||
PreferenceFragmentCompat.OnPreferenceStartFragmentCallback {
|
||||
private lateinit var topAppBar: MaterialToolbar
|
||||
private val context = this
|
||||
|
||||
private val fragmentListener = object : FragmentManager.FragmentLifecycleCallbacks() {
|
||||
override fun onFragmentViewCreated(
|
||||
fm: FragmentManager,
|
||||
fragment: Fragment,
|
||||
v: View,
|
||||
savedInstanceState: Bundle?
|
||||
) {
|
||||
if (fragment is SettingsFragment) {
|
||||
topAppBar.navigationIcon = null
|
||||
} else if (topAppBar.navigationIcon == null) {
|
||||
topAppBar.navigationIcon = ContextCompat.getDrawable(context, R.drawable.ic_back)
|
||||
}
|
||||
topAppBar.title = (fragment as? TitledFragment)?.title
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.settings_activity)
|
||||
topAppBar = findViewById(R.id.top_app_bar)
|
||||
topAppBar.setNavigationOnClickListener {
|
||||
supportFragmentManager.popBackStack()
|
||||
}
|
||||
supportFragmentManager.registerFragmentLifecycleCallbacks(fragmentListener, false)
|
||||
supportFragmentManager
|
||||
.beginTransaction()
|
||||
.replace(R.id.content, SettingsFragment())
|
||||
.commit()
|
||||
}
|
||||
|
||||
override fun onPreferenceStartFragment(
|
||||
caller: PreferenceFragmentCompat,
|
||||
pref: Preference
|
||||
): Boolean {
|
||||
val args = pref.extras
|
||||
val fragment = supportFragmentManager.fragmentFactory.instantiate(
|
||||
classLoader,
|
||||
pref.fragment
|
||||
)
|
||||
fragment.arguments = args
|
||||
fragment.setTargetFragment(caller, 0)
|
||||
supportFragmentManager.beginTransaction()
|
||||
.replace(R.id.content, fragment)
|
||||
.addToBackStack(null)
|
||||
.commit()
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
package ch.deletescape.lawnchair.settings.fragments
|
||||
|
||||
import com.android.launcher3.R
|
||||
|
||||
class AppDrawerSettingsFragment : BasePreferenceFragment(R.xml.app_drawer_settings, false, true) {
|
||||
override val title: String
|
||||
get() = "App Drawer"
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
package ch.deletescape.lawnchair.settings.fragments
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.preference.PreferenceFragmentCompat
|
||||
import ch.deletescape.lawnchair.settings.interfaces.TitledFragment
|
||||
import com.android.launcher3.LauncherFiles
|
||||
import com.google.android.material.transition.MaterialSharedAxis
|
||||
|
||||
abstract class BasePreferenceFragment(
|
||||
var preferenceResource: Int,
|
||||
var hasChild: Boolean,
|
||||
var hasParent: Boolean
|
||||
) : PreferenceFragmentCompat(),
|
||||
TitledFragment {
|
||||
|
||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||
setPreferencesFromResource(preferenceResource, rootKey)
|
||||
preferenceManager.sharedPreferencesName = LauncherFiles.SHARED_PREFERENCES_KEY
|
||||
|
||||
if (hasChild) {
|
||||
exitTransition = MaterialSharedAxis(MaterialSharedAxis.Z, true)
|
||||
reenterTransition = MaterialSharedAxis(MaterialSharedAxis.Z, false)
|
||||
}
|
||||
|
||||
if (hasParent) {
|
||||
enterTransition = MaterialSharedAxis(MaterialSharedAxis.Z, true)
|
||||
returnTransition = MaterialSharedAxis(MaterialSharedAxis.Z, false)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
package ch.deletescape.lawnchair.settings.fragments
|
||||
|
||||
import com.android.launcher3.R
|
||||
|
||||
class DockSettingsFragment : BasePreferenceFragment(R.xml.dock_settings, false, true) {
|
||||
override val title: String
|
||||
get() = "Dock"
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
package ch.deletescape.lawnchair.settings.fragments
|
||||
|
||||
import com.android.launcher3.R
|
||||
|
||||
class GeneralSettingsFragment : BasePreferenceFragment(R.xml.general_settings, true, true) {
|
||||
override val title: String
|
||||
get() = "General"
|
||||
}
|
||||
-8
@@ -1,8 +0,0 @@
|
||||
package ch.deletescape.lawnchair.settings.fragments
|
||||
|
||||
import com.android.launcher3.R
|
||||
|
||||
class HomeScreenSettingsFragment : BasePreferenceFragment(R.xml.home_screen_settings, false, true) {
|
||||
override val title: String
|
||||
get() = "Home Screen"
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
package ch.deletescape.lawnchair.settings.fragments
|
||||
|
||||
import com.android.launcher3.R
|
||||
|
||||
class SettingsFragment : BasePreferenceFragment(R.xml.settings, true, false) {
|
||||
override val title: String
|
||||
get() = "Settings"
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
package ch.deletescape.lawnchair.settings.interfaces
|
||||
|
||||
interface TitledFragment {
|
||||
val title: String
|
||||
}
|
||||
@@ -1,267 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2015 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package ch.deletescape.lawnchair.settings.ui;
|
||||
|
||||
import static androidx.core.view.accessibility.AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS;
|
||||
|
||||
import static com.android.launcher3.SessionCommitReceiver.ADD_ICON_PREFERENCE_KEY;
|
||||
import static com.android.launcher3.states.RotationHelper.ALLOW_ROTATION_PREFERENCE_KEY;
|
||||
import static com.android.launcher3.states.RotationHelper.getAllowRotationDefaultValue;
|
||||
import static com.android.launcher3.util.SecureSettingsObserver.newNotificationSettingsObserver;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceFragmentCompat;
|
||||
import androidx.preference.PreferenceFragmentCompat.OnPreferenceStartFragmentCallback;
|
||||
import androidx.preference.PreferenceFragmentCompat.OnPreferenceStartScreenCallback;
|
||||
import androidx.preference.PreferenceGroup.PreferencePositionCallback;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.android.launcher3.LauncherFiles;
|
||||
import com.android.launcher3.R;
|
||||
import com.android.launcher3.Utilities;
|
||||
import com.android.launcher3.config.FeatureFlags;
|
||||
import com.android.launcher3.settings.NotificationDotsPreference;
|
||||
import com.android.launcher3.settings.PreferenceHighlighter;
|
||||
import com.android.launcher3.uioverrides.plugins.PluginManagerWrapper;
|
||||
import com.android.launcher3.util.SecureSettingsObserver;
|
||||
|
||||
/**
|
||||
* Settings activity for Launcher. Currently implements the following setting: Allow rotation
|
||||
*/
|
||||
public class SettingsActivity extends FragmentActivity
|
||||
implements OnPreferenceStartFragmentCallback, OnPreferenceStartScreenCallback,
|
||||
SharedPreferences.OnSharedPreferenceChangeListener{
|
||||
|
||||
private static final String DEVELOPER_OPTIONS_KEY = "pref_developer_options";
|
||||
private static final String FLAGS_PREFERENCE_KEY = "flag_toggler";
|
||||
|
||||
private static final String NOTIFICATION_DOTS_PREFERENCE_KEY = "pref_icon_badging";
|
||||
/** Hidden field Settings.Secure.ENABLED_NOTIFICATION_LISTENERS */
|
||||
private static final String NOTIFICATION_ENABLED_LISTENERS = "enabled_notification_listeners";
|
||||
|
||||
public static final String EXTRA_FRAGMENT_ARG_KEY = ":settings:fragment_args_key";
|
||||
public static final String EXTRA_SHOW_FRAGMENT_ARGS = ":settings:show_fragment_args";
|
||||
private static final int DELAY_HIGHLIGHT_DURATION_MILLIS = 600;
|
||||
public static final String SAVE_HIGHLIGHTED_KEY = "android:preference_highlighted";
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
if (savedInstanceState == null) {
|
||||
Bundle args = new Bundle();
|
||||
String prefKey = getIntent().getStringExtra(EXTRA_FRAGMENT_ARG_KEY);
|
||||
if (!TextUtils.isEmpty(prefKey)) {
|
||||
args.putString(EXTRA_FRAGMENT_ARG_KEY, prefKey);
|
||||
}
|
||||
|
||||
final FragmentManager fm = getSupportFragmentManager();
|
||||
final Fragment f = fm.getFragmentFactory().instantiate(getClassLoader(),
|
||||
getString(R.string.settings_fragment_name));
|
||||
f.setArguments(args);
|
||||
// Display the fragment as the main content.
|
||||
fm.beginTransaction().replace(android.R.id.content, f).commit();
|
||||
}
|
||||
Utilities.getPrefs(getApplicationContext()).registerOnSharedPreferenceChangeListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { }
|
||||
|
||||
private boolean startFragment(String fragment, Bundle args, String key) {
|
||||
if (Utilities.ATLEAST_P && getSupportFragmentManager().isStateSaved()) {
|
||||
// Sometimes onClick can come after onPause because of being posted on the handler.
|
||||
// Skip starting new fragments in that case.
|
||||
return false;
|
||||
}
|
||||
final FragmentManager fm = getSupportFragmentManager();
|
||||
final Fragment f = fm.getFragmentFactory().instantiate(getClassLoader(), fragment);
|
||||
f.setArguments(args);
|
||||
if (f instanceof DialogFragment) {
|
||||
((DialogFragment) f).show(getSupportFragmentManager(), key);
|
||||
} else {
|
||||
fm.beginTransaction().replace(android.R.id.content, f).addToBackStack(key).commit();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceStartFragment(
|
||||
PreferenceFragmentCompat preferenceFragment, Preference pref) {
|
||||
return startFragment(pref.getFragment(), pref.getExtras(), pref.getKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceStartScreen(PreferenceFragmentCompat caller, PreferenceScreen pref) {
|
||||
Bundle args = new Bundle();
|
||||
args.putString(PreferenceFragmentCompat.ARG_PREFERENCE_ROOT, pref.getKey());
|
||||
return startFragment(getString(R.string.settings_fragment_name), args, pref.getKey());
|
||||
}
|
||||
|
||||
/**
|
||||
* This fragment shows the launcher preferences.
|
||||
*/
|
||||
public static class LauncherSettingsFragment extends PreferenceFragmentCompat {
|
||||
|
||||
private SecureSettingsObserver mNotificationDotsObserver;
|
||||
|
||||
private String mHighLightKey;
|
||||
private boolean mPreferenceHighlighted = false;
|
||||
|
||||
@Override
|
||||
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
||||
final Bundle args = getArguments();
|
||||
mHighLightKey = args == null ? null : args.getString(EXTRA_FRAGMENT_ARG_KEY);
|
||||
if (rootKey == null && !TextUtils.isEmpty(mHighLightKey)) {
|
||||
rootKey = getParentKeyForPref(mHighLightKey);
|
||||
}
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
mPreferenceHighlighted = savedInstanceState.getBoolean(SAVE_HIGHLIGHTED_KEY);
|
||||
}
|
||||
|
||||
getPreferenceManager().setSharedPreferencesName(LauncherFiles.SHARED_PREFERENCES_KEY);
|
||||
setPreferencesFromResource(R.xml.settings, rootKey);
|
||||
|
||||
PreferenceScreen screen = getPreferenceScreen();
|
||||
for (int i = screen.getPreferenceCount() - 1; i >= 0; i--) {
|
||||
Preference preference = screen.getPreference(i);
|
||||
if (!initPreference(preference)) {
|
||||
screen.removePreference(preference);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putBoolean(SAVE_HIGHLIGHTED_KEY, mPreferenceHighlighted);
|
||||
}
|
||||
|
||||
protected String getParentKeyForPref(String key) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes a preference. This is called for every preference. Returning false here
|
||||
* will remove that preference from the list.
|
||||
*/
|
||||
protected boolean initPreference(Preference preference) {
|
||||
switch (preference.getKey()) {
|
||||
case NOTIFICATION_DOTS_PREFERENCE_KEY:
|
||||
if (!Utilities.ATLEAST_OREO ||
|
||||
!getResources().getBoolean(R.bool.notification_dots_enabled)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Listen to system notification dot settings while this UI is active.
|
||||
mNotificationDotsObserver = newNotificationSettingsObserver(
|
||||
getActivity(), (NotificationDotsPreference) preference);
|
||||
mNotificationDotsObserver.register();
|
||||
// Also listen if notification permission changes
|
||||
mNotificationDotsObserver.getResolver().registerContentObserver(
|
||||
Settings.Secure.getUriFor(NOTIFICATION_ENABLED_LISTENERS), false,
|
||||
mNotificationDotsObserver);
|
||||
mNotificationDotsObserver.dispatchOnChange();
|
||||
return true;
|
||||
|
||||
case ADD_ICON_PREFERENCE_KEY:
|
||||
return Utilities.ATLEAST_OREO;
|
||||
|
||||
case ALLOW_ROTATION_PREFERENCE_KEY:
|
||||
if (getResources().getBoolean(R.bool.allow_rotation)) {
|
||||
// Launcher supports rotation by default. No need to show this setting.
|
||||
return false;
|
||||
}
|
||||
// Initialize the UI once
|
||||
preference.setDefaultValue(getAllowRotationDefaultValue());
|
||||
return true;
|
||||
|
||||
case FLAGS_PREFERENCE_KEY:
|
||||
// Only show flag toggler UI if this build variant implements that.
|
||||
return FeatureFlags.showFlagTogglerUi(getContext());
|
||||
|
||||
case DEVELOPER_OPTIONS_KEY:
|
||||
// Show if plugins are enabled or flag UI is enabled.
|
||||
return FeatureFlags.showFlagTogglerUi(getContext()) ||
|
||||
PluginManagerWrapper.hasPlugins(getContext());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
if (isAdded() && !mPreferenceHighlighted) {
|
||||
PreferenceHighlighter highlighter = createHighlighter();
|
||||
if (highlighter != null) {
|
||||
getView().postDelayed(highlighter, DELAY_HIGHLIGHT_DURATION_MILLIS);
|
||||
mPreferenceHighlighted = true;
|
||||
} else {
|
||||
requestAccessibilityFocus(getListView());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private PreferenceHighlighter createHighlighter() {
|
||||
if (TextUtils.isEmpty(mHighLightKey)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
PreferenceScreen screen = getPreferenceScreen();
|
||||
if (screen == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
RecyclerView list = getListView();
|
||||
PreferencePositionCallback callback = (PreferencePositionCallback) list.getAdapter();
|
||||
int position = callback.getPreferenceAdapterPosition(mHighLightKey);
|
||||
return position >= 0 ? new PreferenceHighlighter(list, position) : null;
|
||||
}
|
||||
|
||||
private void requestAccessibilityFocus(@NonNull final RecyclerView rv) {
|
||||
rv.post(() -> {
|
||||
if (!rv.hasFocus() && rv.getChildCount() > 0) {
|
||||
rv.getChildAt(0)
|
||||
.performAccessibilityAction(ACTION_ACCESSIBILITY_FOCUS, null);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
if (mNotificationDotsObserver != null) {
|
||||
mNotificationDotsObserver.unregister();
|
||||
mNotificationDotsObserver = null;
|
||||
}
|
||||
super.onDestroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
-68
@@ -1,68 +0,0 @@
|
||||
package ch.deletescape.lawnchair.settings.ui.preferences
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import android.util.AttributeSet
|
||||
import android.util.Log
|
||||
import android.widget.SeekBar
|
||||
import android.widget.TextView
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.preference.Preference
|
||||
import androidx.preference.PreferenceViewHolder
|
||||
import androidx.preference.SeekBarPreference
|
||||
import com.android.launcher3.R
|
||||
|
||||
class CustomSeekBarPreference(context: Context, attrs: AttributeSet? = null) : Preference(context, attrs), Preference.OnPreferenceChangeListener {
|
||||
|
||||
private val minValue: Int
|
||||
private val maxValue: Int
|
||||
private val snapEvery: Int
|
||||
private val asPercentages: Boolean
|
||||
|
||||
private var displayedValue: Int = 0
|
||||
private var realValue: Double = 0.0
|
||||
|
||||
init {
|
||||
widgetLayoutResource = R.layout.custom_seek_bar_preference
|
||||
layoutResource = R.layout.custom_seek_bar_preference
|
||||
context.obtainStyledAttributes(attrs, R.styleable.CustomSeekBarPreference).apply {
|
||||
minValue = this.getInt(R.styleable.CustomSeekBarPreference_minValue, 0)
|
||||
maxValue = this.getInt(R.styleable.CustomSeekBarPreference_maxValue, 100)
|
||||
snapEvery = this.getInt(R.styleable.CustomSeekBarPreference_snapEvery, 1)
|
||||
asPercentages = this.getBoolean(R.styleable.CustomSeekBarPreference_asPercentages, false)
|
||||
recycle()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(view: PreferenceViewHolder?) {
|
||||
super.onBindViewHolder(view)
|
||||
onPreferenceChangeListener = this
|
||||
|
||||
val seekBar: SeekBar = view?.findViewById(R.id.seek_bar) as SeekBar
|
||||
val valueView: TextView = view.findViewById(R.id.value_view) as TextView
|
||||
|
||||
seekBar.max = (maxValue - minValue) / snapEvery
|
||||
|
||||
seekBar.setOnSeekBarChangeListener(object: SeekBar.OnSeekBarChangeListener {
|
||||
override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
|
||||
displayedValue = progress * snapEvery + minValue
|
||||
realValue = if (asPercentages) displayedValue.toDouble() / 100 else displayedValue.toDouble()
|
||||
valueView.text = if (asPercentages) "$displayedValue%" else "$displayedValue"
|
||||
}
|
||||
|
||||
override fun onStartTrackingTouch(seekBar: SeekBar?) {
|
||||
|
||||
}
|
||||
|
||||
override fun onStopTrackingTouch(seekBar: SeekBar?) {
|
||||
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
override fun onPreferenceChange(preference: Preference?, newValue: Any?): Boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package ch.deletescape.lawnchair.sharedprefs
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import com.android.launcher3.Utilities
|
||||
|
||||
class PrefManager(context: Context) {
|
||||
val sp: SharedPreferences = Utilities.getPrefs(context)
|
||||
private val lp = LawnchairPreferences
|
||||
var iconPackPackage by StringPrefDelegate(lp.ICON_PACK_PACKAGE, "")
|
||||
var allowRotation by BoolPrefDelegate("pref_allowRotation", true)
|
||||
var wrapAdaptiveIcons by BoolPrefDelegate(lp.WRAP_ADAPTIVE_ICONS, false)
|
||||
var addIconToHome by BoolPrefDelegate("pref_add_icon_to_home", true)
|
||||
var hotseatColumns by FloatPrefDelegate(lp.HOTSEAT_COLUMNS, 5F)
|
||||
var workspaceColumns by FloatPrefDelegate(lp.WORKSPACE_COLUMNS, 5F)
|
||||
var workspaceRows by FloatPrefDelegate(lp.WORKSPACE_ROWS, 7F)
|
||||
var folderColumns by FloatPrefDelegate(lp.FOLDER_COLUMNS, 3F)
|
||||
var folderRows by FloatPrefDelegate(lp.FOLDER_ROWS, 4F)
|
||||
var iconSizeFactor by FloatPrefDelegate(lp.ICON_SIZE_FACTOR, 1F)
|
||||
var textSizeFactor by FloatPrefDelegate(lp.TEXT_SIZE_FACTOR, 1F)
|
||||
var allAppsIconSizeFactor by FloatPrefDelegate(lp.ALL_APPS_ICON_SIZE_FACTOR, 1F)
|
||||
var allAppsTextSizeFactor by FloatPrefDelegate(lp.ALL_APPS_TEXT_SIZE_FACTOR, 1F)
|
||||
var allAppsColumns by FloatPrefDelegate(lp.ALL_APPS_COLUMNS, 5F)
|
||||
var allowEmptyPages by BoolPrefDelegate(lp.ALLOW_EMPTY_PAGES, false)
|
||||
var makeColoredBackgrounds by BoolPrefDelegate(lp.MAKE_COLORED_BACKGROUNDS, false)
|
||||
}
|
||||
+3
-6
@@ -15,7 +15,7 @@
|
||||
* along with Lawnchair Launcher. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package ch.deletescape.lawnchair
|
||||
package ch.deletescape.lawnchair.ui
|
||||
|
||||
import android.app.Activity
|
||||
import android.app.Application
|
||||
@@ -36,7 +36,8 @@ class LawnchairApp : Application() {
|
||||
val recentsEnabled by lazy { checkRecentsComponent() }
|
||||
val TAG = "LawnchairApp"
|
||||
|
||||
init {}
|
||||
init {
|
||||
}
|
||||
|
||||
fun onLauncherAppStateCreated() {
|
||||
registerActivityLifecycleCallbacks(activityHandler)
|
||||
@@ -50,10 +51,6 @@ class LawnchairApp : Application() {
|
||||
}*/
|
||||
}
|
||||
|
||||
override fun onConfigurationChanged(newConfig: Configuration) {
|
||||
super.onConfigurationChanged(newConfig)
|
||||
}
|
||||
|
||||
class ActivityHandler : ActivityLifecycleCallbacks {
|
||||
|
||||
val activities = HashSet<Activity>()
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package ch.deletescape.lawnchair.compose.ui.preferences
|
||||
package ch.deletescape.lawnchair.ui.preferences
|
||||
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.runtime.Composable
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package ch.deletescape.lawnchair.compose.ui.preferences
|
||||
package ch.deletescape.lawnchair.ui.preferences
|
||||
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.runtime.Composable
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package ch.deletescape.lawnchair.compose.ui.preferences
|
||||
package ch.deletescape.lawnchair.ui.preferences
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.res.stringResource
|
||||
+2
-1
@@ -1,4 +1,4 @@
|
||||
package ch.deletescape.lawnchair.compose.ui.preferences
|
||||
package ch.deletescape.lawnchair.ui.preferences
|
||||
|
||||
import android.os.Build
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
@@ -19,6 +19,7 @@ fun GeneralPreferences(navController: NavController, interactor: PreferenceInter
|
||||
label = stringResource(id = R.string.home_screen_rotation_label),
|
||||
description = stringResource(id = R.string.home_screen_rotaton_description)
|
||||
)
|
||||
NotificationDotsPreference(interactor)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
SwitchPreference(
|
||||
checked = interactor.wrapAdaptiveIcons.value,
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package ch.deletescape.lawnchair.compose.ui.preferences
|
||||
package ch.deletescape.lawnchair.ui.preferences
|
||||
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.runtime.Composable
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
package ch.deletescape.lawnchair.compose.ui.preferences
|
||||
package ch.deletescape.lawnchair.ui.preferences
|
||||
|
||||
import android.graphics.drawable.Drawable
|
||||
import androidx.compose.foundation.Image
|
||||
@@ -19,7 +19,7 @@ import androidx.core.graphics.drawable.toBitmap
|
||||
data class IconPackInfo(val name: String, val packageName: String, val icon: Drawable)
|
||||
|
||||
@Composable
|
||||
fun IconPackPreferences(interactor: PreferenceInteractor) {
|
||||
fun IconPackPreference(interactor: PreferenceInteractor) {
|
||||
Box {
|
||||
LazyColumn(Modifier.fillMaxWidth()) {
|
||||
items(interactor.getIconPacks().values.toList()) { iconPack ->
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package ch.deletescape.lawnchair.compose.ui.preferences
|
||||
package ch.deletescape.lawnchair.ui.preferences
|
||||
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.*
|
||||
@@ -0,0 +1,55 @@
|
||||
package ch.deletescape.lawnchair.ui.preferences
|
||||
|
||||
import android.content.ComponentName
|
||||
import android.content.Intent
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.material.MaterialTheme
|
||||
import androidx.compose.material.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.core.os.bundleOf
|
||||
import com.android.launcher3.R
|
||||
import com.android.launcher3.notification.NotificationListener
|
||||
import android.provider.Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS as actionNotificationListenerSettings
|
||||
|
||||
@Composable
|
||||
fun NotificationDotsPreference(interactor: PreferenceInteractor) {
|
||||
val context = LocalContext.current
|
||||
val extraFragmentArgKey = ":settings:fragment_args_key"
|
||||
val extraShowFragmentArgs = ":settings:show_fragment_args"
|
||||
|
||||
fun onClick() {
|
||||
val intent = if (interactor.notificationDotsEnabled.value) {
|
||||
Intent("android.settings.NOTIFICATION_SETTINGS")
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
.putExtra(extraFragmentArgKey, "notification_badging")
|
||||
} else {
|
||||
val cn = ComponentName(context, NotificationListener::class.java)
|
||||
val showFragmentArgs = bundleOf(extraFragmentArgKey to cn.flattenToString())
|
||||
Intent(actionNotificationListenerSettings)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
.putExtra(extraFragmentArgKey, cn.flattenToString())
|
||||
.putExtra(extraShowFragmentArgs, showFragmentArgs)
|
||||
}
|
||||
context.startActivity(intent)
|
||||
}
|
||||
|
||||
Column(
|
||||
verticalArrangement = Arrangement.Center,
|
||||
modifier = Modifier
|
||||
.height(48.dp)
|
||||
.fillMaxWidth()
|
||||
.clickable { onClick() }
|
||||
.padding(start = 16.dp, end = 16.dp),
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(id = R.string.notification_dots),
|
||||
style = MaterialTheme.typography.subtitle1,
|
||||
color = MaterialTheme.colors.onBackground
|
||||
)
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -1,10 +1,10 @@
|
||||
package ch.deletescape.lawnchair.compose.ui.preferences
|
||||
package ch.deletescape.lawnchair.ui.preferences
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.compose.animation.ExperimentalAnimationApi
|
||||
import ch.deletescape.lawnchair.compose.ui.theme.LawnchairTheme
|
||||
import ch.deletescape.lawnchair.ui.theme.LawnchairTheme
|
||||
|
||||
class PreferenceActivity : ComponentActivity() {
|
||||
@ExperimentalAnimationApi
|
||||
+1
-3
@@ -1,4 +1,4 @@
|
||||
package ch.deletescape.lawnchair.compose.ui.preferences
|
||||
package ch.deletescape.lawnchair.ui.preferences
|
||||
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.clickable
|
||||
@@ -8,11 +8,9 @@ import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import kotlin.random.Random
|
||||
|
||||
@Composable
|
||||
fun PreferenceCategoryLink(titleResId: Int, onClick: () -> Unit, subtitleResId: Int?, iconResId: Int?) {
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package ch.deletescape.lawnchair.compose.ui.preferences
|
||||
package ch.deletescape.lawnchair.ui.preferences
|
||||
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.items
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package ch.deletescape.lawnchair.compose.ui.preferences
|
||||
package ch.deletescape.lawnchair.ui.preferences
|
||||
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.material.*
|
||||
+2
-1
@@ -1,4 +1,4 @@
|
||||
package ch.deletescape.lawnchair.compose.ui.preferences
|
||||
package ch.deletescape.lawnchair.ui.preferences
|
||||
|
||||
import androidx.compose.runtime.State
|
||||
|
||||
@@ -19,6 +19,7 @@ interface PreferenceInteractor {
|
||||
val allAppsColumns: State<Float>
|
||||
val allowEmptyPages: State<Boolean>
|
||||
val makeColoredBackgrounds: State<Boolean>
|
||||
val notificationDotsEnabled: State<Boolean>
|
||||
|
||||
fun setIconPackPackage(iconPackPackage: String)
|
||||
fun setAllowRotation(allowRotation: Boolean)
|
||||
+15
-3
@@ -1,8 +1,10 @@
|
||||
package ch.deletescape.lawnchair.compose.ui.preferences
|
||||
package ch.deletescape.lawnchair.ui.preferences
|
||||
|
||||
import android.app.Application
|
||||
import android.content.ComponentName
|
||||
import android.content.Intent
|
||||
import android.content.pm.ResolveInfo
|
||||
import android.provider.Settings.Secure.getString
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.appcompat.content.res.AppCompatResources
|
||||
@@ -20,11 +22,19 @@ import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import androidx.navigation.compose.NavHost
|
||||
import androidx.navigation.compose.composable
|
||||
import androidx.navigation.compose.rememberNavController
|
||||
import ch.deletescape.lawnchair.sharedprefs.PrefManager
|
||||
import ch.deletescape.lawnchair.util.preferences.PrefManager
|
||||
import com.android.launcher3.R
|
||||
import com.android.launcher3.notification.NotificationListener
|
||||
|
||||
class PreferenceViewModel(application: Application) : AndroidViewModel(application), PreferenceInteractor {
|
||||
private val pm = PrefManager(application)
|
||||
private val enabledNotificationListeners: String? by lazy {
|
||||
getString(
|
||||
application.contentResolver,
|
||||
"enabled_notification_listeners"
|
||||
)
|
||||
}
|
||||
private val lawnchairNotificationListener = ComponentName(application, NotificationListener::class.java)
|
||||
|
||||
override val iconPackPackage: MutableState<String> = mutableStateOf(pm.iconPackPackage)
|
||||
override val allowRotation: MutableState<Boolean> = mutableStateOf(pm.allowRotation)
|
||||
@@ -42,6 +52,8 @@ class PreferenceViewModel(application: Application) : AndroidViewModel(applicati
|
||||
override val allAppsColumns: MutableState<Float> = mutableStateOf(pm.allAppsColumns)
|
||||
override val allowEmptyPages: MutableState<Boolean> = mutableStateOf(pm.allowEmptyPages)
|
||||
override val makeColoredBackgrounds: MutableState<Boolean> = mutableStateOf(pm.makeColoredBackgrounds)
|
||||
override val notificationDotsEnabled: MutableState<Boolean> =
|
||||
mutableStateOf(enabledNotificationListeners?.contains(lawnchairNotificationListener.flattenToString()) == true)
|
||||
|
||||
override fun setIconPackPackage(iconPackPackage: String) {
|
||||
pm.iconPackPackage = iconPackPackage
|
||||
@@ -220,7 +232,7 @@ fun Settings(interactor: PreferenceInteractor = viewModel<PreferenceViewModel>()
|
||||
NavHost(navController = navController, startDestination = Screen.Top.route) {
|
||||
composable(route = Screen.Top.route) { PreferenceCategoryList(navController) }
|
||||
composable(route = Screen.HomeScreenSettings.route) { HomeScreenPreferences(interactor = interactor) }
|
||||
composable(route = Screen.IconPackSettings.route) { IconPackPreferences(interactor = interactor) }
|
||||
composable(route = Screen.IconPackSettings.route) { IconPackPreference(interactor = interactor) }
|
||||
composable(route = Screen.DockSettings.route) { DockPreferences(interactor = interactor) }
|
||||
composable(route = Screen.AppDrawerSettings.route) { AppDrawerPreferences(interactor = interactor) }
|
||||
composable(route = Screen.FolderSettings.route) { FolderPreferences(interactor = interactor) }
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package ch.deletescape.lawnchair.compose.ui.preferences
|
||||
package ch.deletescape.lawnchair.ui.preferences
|
||||
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.material.*
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package ch.deletescape.lawnchair.compose.ui.preferences
|
||||
package ch.deletescape.lawnchair.ui.preferences
|
||||
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.material.*
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package ch.deletescape.lawnchair.compose.ui.preferences
|
||||
package ch.deletescape.lawnchair.ui.preferences
|
||||
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.animation.ExperimentalAnimationApi
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package ch.deletescape.lawnchair.compose.ui.theme
|
||||
package ch.deletescape.lawnchair.ui.theme
|
||||
|
||||
import androidx.compose.ui.graphics.Color
|
||||
|
||||
File renamed without changes.
+1
-1
@@ -1,4 +1,4 @@
|
||||
package ch.deletescape.lawnchair.compose.ui.theme
|
||||
package ch.deletescape.lawnchair.ui.theme
|
||||
|
||||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.material.MaterialTheme
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package ch.deletescape.lawnchair.compose.ui.theme
|
||||
package ch.deletescape.lawnchair.ui.theme
|
||||
|
||||
import androidx.compose.material.Typography
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package ch.deletescape.lawnchair.sharedprefs
|
||||
package ch.deletescape.lawnchair.util.preferences
|
||||
|
||||
import kotlin.properties.ReadWriteProperty
|
||||
import kotlin.reflect.KProperty
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package ch.deletescape.lawnchair.sharedprefs
|
||||
package ch.deletescape.lawnchair.util.preferences
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
@@ -0,0 +1,26 @@
|
||||
package ch.deletescape.lawnchair.util.preferences
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import com.android.launcher3.Utilities
|
||||
|
||||
class PrefManager(context: Context) {
|
||||
val sp: SharedPreferences = Utilities.getPrefs(context)
|
||||
private val lp = LawnchairPreferences
|
||||
var iconPackPackage by StringPrefDelegate(LawnchairPreferences.ICON_PACK_PACKAGE, "")
|
||||
var allowRotation by BoolPrefDelegate("pref_allowRotation", true)
|
||||
var wrapAdaptiveIcons by BoolPrefDelegate(LawnchairPreferences.WRAP_ADAPTIVE_ICONS, false)
|
||||
var addIconToHome by BoolPrefDelegate("pref_add_icon_to_home", true)
|
||||
var hotseatColumns by FloatPrefDelegate(LawnchairPreferences.HOTSEAT_COLUMNS, 5F)
|
||||
var workspaceColumns by FloatPrefDelegate(LawnchairPreferences.WORKSPACE_COLUMNS, 5F)
|
||||
var workspaceRows by FloatPrefDelegate(LawnchairPreferences.WORKSPACE_ROWS, 7F)
|
||||
var folderColumns by FloatPrefDelegate(LawnchairPreferences.FOLDER_COLUMNS, 3F)
|
||||
var folderRows by FloatPrefDelegate(LawnchairPreferences.FOLDER_ROWS, 4F)
|
||||
var iconSizeFactor by FloatPrefDelegate(LawnchairPreferences.ICON_SIZE_FACTOR, 1F)
|
||||
var textSizeFactor by FloatPrefDelegate(LawnchairPreferences.TEXT_SIZE_FACTOR, 1F)
|
||||
var allAppsIconSizeFactor by FloatPrefDelegate(LawnchairPreferences.ALL_APPS_ICON_SIZE_FACTOR, 1F)
|
||||
var allAppsTextSizeFactor by FloatPrefDelegate(LawnchairPreferences.ALL_APPS_TEXT_SIZE_FACTOR, 1F)
|
||||
var allAppsColumns by FloatPrefDelegate(LawnchairPreferences.ALL_APPS_COLUMNS, 5F)
|
||||
var allowEmptyPages by BoolPrefDelegate(LawnchairPreferences.ALLOW_EMPTY_PAGES, false)
|
||||
var makeColoredBackgrounds by BoolPrefDelegate(LawnchairPreferences.MAKE_COLORED_BACKGROUNDS, false)
|
||||
}
|
||||
@@ -62,7 +62,7 @@ import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
||||
import ch.deletescape.lawnchair.sharedprefs.LawnchairPreferences;
|
||||
import ch.deletescape.lawnchair.util.preferences.LawnchairPreferences;
|
||||
|
||||
public class InvariantDeviceProfile {
|
||||
|
||||
|
||||
@@ -200,7 +200,7 @@ import java.util.function.Predicate;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import ch.deletescape.lawnchair.sharedprefs.LawnchairPreferences;
|
||||
import ch.deletescape.lawnchair.util.preferences.LawnchairPreferences;
|
||||
|
||||
/**
|
||||
* Default launcher application.
|
||||
|
||||
@@ -118,7 +118,7 @@ import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import ch.deletescape.lawnchair.sharedprefs.LawnchairPreferences;
|
||||
import ch.deletescape.lawnchair.util.preferences.LawnchairPreferences;
|
||||
|
||||
/**
|
||||
* The workspace is a wide area with a wallpaper and a finite number of pages.
|
||||
|
||||
Reference in new issue
Block a user