Material 3 theme [WIP]

This commit is contained in:
MM20
2021-12-04 12:24:16 +01:00
parent d7f549795a
commit 0e1ca1c1f9
95 changed files with 1154 additions and 902 deletions
+1 -1
View File
@@ -50,7 +50,7 @@
android:parentActivityName=".ui.legacy.activity.LauncherActivity"
android:screenOrientation="portrait"
android:taskAffinity="de.mm20.launcher2.settings"
android:theme="@style/SettingsTheme">
android:theme="@style/SettingsTheme.DefaultColors">
<intent-filter>
<action android:name="android.intent.action.APPLICATION_PREFERENCES" />
<category android:name="android.intent.category.DEFAULT" />
@@ -11,12 +11,18 @@ import de.mm20.launcher2.fragment.PreferencesCalendarFragment
import de.mm20.launcher2.fragment.PreferencesMainFragment
import de.mm20.launcher2.fragment.PreferencesServicesFragment
import de.mm20.launcher2.fragment.PreferencesWeatherFragment
import de.mm20.launcher2.preferences.ColorSchemes
import de.mm20.launcher2.preferences.LauncherPreferences
import de.mm20.launcher2.ui.legacy.activity.LauncherActivity
class SettingsActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
when(LauncherPreferences.instance.colorScheme) {
ColorSchemes.BLACK -> setTheme(R.style.SettingsTheme_BlackWhiteColors)
else -> setTheme(R.style.SettingsTheme_DefaultColors)
}
if (savedInstanceState == null) {
val fragment = getStartFragment()
setupActionBar()
@@ -32,7 +38,6 @@ class SettingsActivity : AppCompatActivity() {
.replace(android.R.id.content, fragment)
.commit()
}
findViewById<View>(android.R.id.content)?.setBackgroundColor(getColor(R.color.settings_window_background))
}
override fun onSaveInstanceState(outState: Bundle) {
@@ -1,21 +1,26 @@
package de.mm20.launcher2.fragment
import android.annotation.SuppressLint
import android.content.Intent
import android.content.pm.PackageManager
import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.FileProvider
import androidx.lifecycle.lifecycleScope
import androidx.preference.Preference
import androidx.preference.PreferenceCategory
import androidx.preference.PreferenceFragmentCompat
import com.afollestad.materialdialogs.MaterialDialog
import com.google.android.material.snackbar.Snackbar
import de.mm20.launcher2.R
import de.mm20.launcher2.crashreporter.CrashReporter
import de.mm20.launcher2.debug.DebugInformationDumper
import de.mm20.launcher2.ktx.tryStartActivity
import de.mm20.launcher2.licenses.AppLicense
import de.mm20.launcher2.licenses.OpenSourceLicenses
import kotlinx.coroutines.launch
import java.io.File
class PreferencesAboutFragment : PreferenceFragmentCompat() {
@@ -96,14 +101,27 @@ class PreferencesAboutFragment : PreferenceFragmentCompat() {
findPreference<Preference>("export_debug")?.setOnPreferenceClickListener {
lifecycleScope.launch {
val path = DebugInformationDumper().dump(requireContext())
Toast.makeText(
activity,
Snackbar.make(
requireView(),
getString(
R.string.debug_export_information_file,
path
),
Toast.LENGTH_SHORT
).show()
Snackbar.LENGTH_LONG
)
.setAction(R.string.menu_share) {
val context = requireContext()
context.tryStartActivity(Intent(Intent.ACTION_SEND).apply {
type = "text/plain"
putExtra(
Intent.EXTRA_STREAM, FileProvider.getUriForFile(
context,
context.applicationContext.packageName + ".fileprovider",
File(path)
)
)
})
}.show()
}
true
}
@@ -1,7 +1,5 @@
package de.mm20.launcher2.fragment
import android.Manifest
import android.app.WallpaperManager
import android.content.Intent
import android.graphics.drawable.ColorDrawable
import android.os.Build
@@ -11,7 +9,6 @@ import android.widget.LinearLayout
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.app.ActivityCompat
import androidx.lifecycle.lifecycleScope
import androidx.preference.ListPreference
import androidx.preference.Preference
@@ -23,7 +20,6 @@ import de.mm20.launcher2.R
import de.mm20.launcher2.icons.IconPackManager
import de.mm20.launcher2.icons.IconRepository
import de.mm20.launcher2.icons.LauncherIcon
import de.mm20.launcher2.ktx.checkPermission
import de.mm20.launcher2.preferences.IconShape
import de.mm20.launcher2.preferences.LauncherPreferences
import de.mm20.launcher2.preferences.Themes
@@ -48,6 +44,11 @@ class PreferencesAppearanceFragment : PreferenceFragmentCompat() {
true
}
findPreference<Preference>("card_background")?.setOnPreferenceChangeListener { _, newValue ->
requireActivity().recreate()
true
}
findPreference<Preference>("wallpaper")?.setOnPreferenceClickListener {
requireContext().startActivity(Intent.createChooser(Intent(Intent.ACTION_SET_WALLPAPER), null))
true
@@ -79,18 +80,18 @@ class PreferencesAppearanceFragment : PreferenceFragmentCompat() {
}
setOnPreferenceChangeListener { _, newValue ->
val index = (newValue as String).toInt()
iconRepository.clearCache()
if (index == -1) iconPackManager.selectIconPack("")
else {
iconPackManager.selectIconPack(packs[index].packageName)
}
iconRepository.recreate()
true
}
}
}
findPreference<Preference>("legacy_icon_bg")?.setOnPreferenceChangeListener { _, _ ->
iconRepository.clearCache()
iconRepository.recreate()
true
}
@@ -6,23 +6,15 @@ import android.app.WallpaperManager
import android.graphics.*
import android.os.Bundle
import android.view.View
import android.view.ViewOutlineProvider
import androidx.core.content.res.ResourcesCompat
import androidx.core.view.doOnNextLayout
import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import de.mm20.launcher2.R
import de.mm20.launcher2.ktx.dp
import de.mm20.launcher2.ktx.translate
import de.mm20.launcher2.preferences.CardBackground
import de.mm20.launcher2.preferences.LauncherPreferences
import kotlinx.android.synthetic.main.fragment_card_settings.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.io.File
import kotlin.math.roundToInt
class PreferencesCardFragment : Fragment(R.layout.fragment_card_settings) {
@@ -68,18 +60,6 @@ class PreferencesCardFragment : Fragment(R.layout.fragment_card_settings) {
true
}
}
findPreference<Preference>("card_background")?.let {
it.setOnPreferenceChangeListener { preference, newValue ->
val background = CardBackground.byValue(newValue as String)
var color = when (background) {
CardBackground.BLACK -> context.getColor(R.color.cardview_background_black)
else -> context.getColor(R.color.cardview_background)
}
color = color and ((previewCard.backgroundOpacity shl 24) or 0xFFFFFF)
previewCard.setCardBackgroundColor(color)
true
}
}
}
childFragmentManager.beginTransaction()
@@ -89,8 +69,6 @@ class PreferencesCardFragment : Fragment(R.layout.fragment_card_settings) {
}
private var blurBitmap: Bitmap? = null
private var animator: Animator? = null
override fun onStart() {
super.onStart()
@@ -9,6 +9,7 @@
android:id="@+id/frameLayout"
android:layout_width="match_parent"
android:layout_height="232dp"
android:background="?colorPrimaryContainer"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
@@ -8,6 +8,15 @@
app:key="theme"
app:summary="%s"
app:title="@string/preference_theme" />
<ListPreference
app:key="card_background"
android:defaultValue="0"
app:summary="%s"
app:title="@string/preference_screen_colors"
app:entries="@array/preference_card_background_entries"
app:entryValues="@array/preference_card_background_values"
/>
<Preference
app:key="cards"
app:summary="@string/preference_cards_summary"
@@ -24,13 +24,4 @@
app:min="0"
app:updatesContinuously="true" />
<ListPreference
app:key="card_background"
android:defaultValue="0"
app:summary="%s"
app:title="@string/preference_card_background"
app:entries="@array/preference_card_background_entries"
app:entryValues="@array/preference_card_background_values"
/>
</PreferenceScreen>