Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PROTOTYPE: add font switching option #257

Draft
wants to merge 2 commits into
base: improve_themes
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 105 additions & 18 deletions app/src/main/java/com/sduduzog/slimlauncher/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ class MainActivity :
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, s: String?) {
if (
s.equals(getString(R.string.prefs_settings_key_theme), true) ||
s.equals(getString(R.string.prefs_settings_key_dark_mode), true)
s.equals(getString(R.string.prefs_settings_key_dark_mode), true) ||
s.equals(getString(R.string.prefs_settings_key_font), true)
) {
recreate()
}
Expand Down Expand Up @@ -156,8 +157,9 @@ class MainActivity :
@StyleRes
fun getUserSelectedThemeRes(): Int {
settings = getSharedPreferences(getString(R.string.prefs_settings), MODE_PRIVATE)
val active = settings.getInt(getString(R.string.prefs_settings_key_theme), 0)
return resolveTheme(active)
val themeId = settings.getInt(getString(R.string.prefs_settings_key_theme), 0)
val fontId = settings.getInt(getString(R.string.prefs_settings_key_font), 0)
return resolveTheme(themeId, fontId)
}

fun getDarkMode(): Int {
Expand All @@ -176,21 +178,106 @@ class MainActivity :

companion object {
@StyleRes
fun resolveTheme(i: Int): Int {
return when (i) {
1 -> R.style.AppThemeDark
2 -> R.style.AppGreyTheme
3 -> R.style.AppTealTheme
4 -> R.style.AppCandyTheme
5 -> R.style.AppPinkTheme
6 -> R.style.AppThemeLight
7 -> R.style.AppDarculaTheme
8 -> R.style.AppGruvBoxDarkTheme
9 -> R.style.AppBlackOrangeTheme
10 -> R.style.AppBlackRedTheme
11 -> R.style.AppBlackCyanTheme
12 -> R.style.AppBlackBlueTheme
else -> R.style.AppTheme
fun resolveTheme(theme: Int, font: Int): Int {
return when (theme) {
1 -> when (font) {
1 -> R.style.AppThemeDark
2 -> R.style.AppThemeDarkSerif
3 -> R.style.AppThemeDarkMono
4 -> R.style.AppThemeDarkCursive
else -> R.style.AppThemeDarkUbuntu
}
2 -> when (font) {
1 -> R.style.AppGreyTheme
2 -> R.style.AppGreyThemeSerif
3 -> R.style.AppGreyThemeMono
4 -> R.style.AppGreyThemeCursive
else -> R.style.AppGreyThemeUbuntu
}
3 -> when (font) {
1 -> R.style.AppTealTheme
2 -> R.style.AppTealThemeSerif
3 -> R.style.AppTealThemeMono
4 -> R.style.AppTealThemeCursive
else -> R.style.AppTealThemeUbuntu
}
4 -> when (font) {
1 -> R.style.AppCandyTheme
2 -> R.style.AppCandyThemeSerif
3 -> R.style.AppCandyThemeMono
4 -> R.style.AppCandyThemeCursive
else -> R.style.AppCandyThemeUbuntu
}
5 -> when (font) {
1 -> R.style.AppPinkTheme
2 -> R.style.AppPinkThemeSerif
3 -> R.style.AppPinkThemeMono
4 -> R.style.AppPinkThemeCursive
else -> R.style.AppPinkThemeUbuntu
}
6 -> when (font) {
1 -> R.style.AppThemeLight
2 -> R.style.AppThemeLightSerif
3 -> R.style.AppThemeLightMono
4 -> R.style.AppThemeLightCursive
else -> R.style.AppThemeLightUbuntu
}
7 -> when (font) {
1 -> R.style.AppDarculaTheme
2 -> R.style.AppDarculaThemeSerif
3 -> R.style.AppDarculaThemeMono
4 -> R.style.AppDarculaThemeCursive
else -> R.style.AppDarculaThemeUbuntu
}
8 -> when (font) {
1 -> R.style.AppGruvBoxDarkTheme
2 -> R.style.AppGruvBoxDarkThemeSerif
3 -> R.style.AppGruvBoxDarkThemeMono
4 -> R.style.AppGruvBoxDarkThemeCursive
else -> R.style.AppGruvBoxDarkThemeUbuntu
}
9 -> when (font) {
1 -> R.style.AppBlackOrangeTheme
2 -> R.style.AppBlackOrangeThemeSerif
3 -> R.style.AppBlackOrangeThemeMono
4 -> R.style.AppBlackOrangeThemeCursive
else -> R.style.AppBlackOrangeThemeUbuntu
}
10 -> when (font) {
1 -> R.style.AppBlackRedTheme
2 -> R.style.AppBlackRedThemeSerif
3 -> R.style.AppBlackRedThemeMono
4 -> R.style.AppBlackRedThemeCursive
else -> R.style.AppBlackRedThemeUbuntu
}
11 -> when (font) {
1 -> R.style.AppBlackCyanTheme
2 -> R.style.AppBlackCyanThemeSerif
3 -> R.style.AppBlackCyanThemeMono
4 -> R.style.AppBlackCyanThemeCursive
else -> R.style.AppBlackCyanThemeUbuntu
}
12 -> when (font) {
1 -> R.style.AppBlackBlueTheme
2 -> R.style.AppBlackBlueThemeSerif
3 -> R.style.AppBlackBlueThemeMono
4 -> R.style.AppBlackBlueThemeCursive
else -> R.style.AppBlackBlueThemeUbuntu
}
13 -> when (font) {
1 -> R.style.AppBlackLilacTheme
2 -> R.style.AppBlackLilacThemeSerif
3 -> R.style.AppBlackLilacThemeMono
4 -> R.style.AppBlackLilacThemeCursive
else -> R.style.AppBlackLilacThemeUbuntu
}
else -> when (font) {
1 -> R.style.AppTheme
2 -> R.style.AppThemeSerif
3 -> R.style.AppThemeMono
4 -> R.style.AppThemeCursive
else -> R.style.AppThemeUbuntu
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.sduduzog.slimlauncher.ui.dialogs

import android.app.AlertDialog
import android.app.Dialog
import android.content.Context.MODE_PRIVATE
import android.content.SharedPreferences
import android.os.Bundle
import androidx.core.content.edit
import androidx.fragment.app.DialogFragment
import com.sduduzog.slimlauncher.R

class ChooseFontDialog : DialogFragment() {

private lateinit var settings: SharedPreferences

override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val builder = AlertDialog.Builder(requireContext())
settings = requireContext().getSharedPreferences(
getString(R.string.prefs_settings),
MODE_PRIVATE
)

// if not set, use setting 1 (Ubuntu) as default, because that was the
// previous app version's default
val active = settings.getInt(getString(R.string.prefs_settings_key_font), 0)
builder.setTitle(R.string.choose_font_dialog_title)
builder.setSingleChoiceItems(R.array.font_array, active) { dialogInterface, i ->
dialogInterface.dismiss()
settings.edit {
putInt(getString(R.string.prefs_settings_key_font), i)
}
}
return builder.create()
}

companion object {
fun getInstance(): ChooseFontDialog {
return ChooseFontDialog()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import com.sduduzog.slimlauncher.ui.dialogs.ChooseAlignmentDialog
import com.sduduzog.slimlauncher.ui.dialogs.ChooseClockTypeDialog
import com.sduduzog.slimlauncher.ui.dialogs.ChooseDarkModeDialog
import com.sduduzog.slimlauncher.ui.dialogs.ChooseDateFormatDialog
import com.sduduzog.slimlauncher.ui.dialogs.ChooseFontDialog
import com.sduduzog.slimlauncher.ui.dialogs.ChooseLead0ModifDialog
import com.sduduzog.slimlauncher.ui.dialogs.ChooseSearchBarPositionDialog
import com.sduduzog.slimlauncher.ui.dialogs.ChooseTimeFormatDialog
Expand Down Expand Up @@ -77,6 +78,12 @@ class OptionsFragment : BaseFragment(), SharedPreferences.OnSharedPreferenceChan
}
updateDarkModeSubtitle()

fragment.optionsFragmentFont.setOnClickListener {
val dialog = ChooseFontDialog.getInstance()
dialog.showNow(childFragmentManager, "FONT_CHOOSER")
}
updateFontSubtitle()

fragment.optionsFragmentChooseTimeFormat.setOnClickListener {
val dialog = ChooseTimeFormatDialog.getInstance()
dialog.showNow(childFragmentManager, "TIME_FORMAT_CHOOSER")
Expand Down Expand Up @@ -230,6 +237,15 @@ class OptionsFragment : BaseFragment(), SharedPreferences.OnSharedPreferenceChan
createTitleAndSubtitleText(requireContext(), title, subtitle)
}

private fun updateFontSubtitle() {
val fragment = OptionsFragmentBinding.bind(requireView())
val position = settings.getInt(getString(R.string.prefs_settings_key_font), 0)
val title = getText(R.string.options_fragment_font)
val subtitle = resources.getTextArray(R.array.font_array)[position]
fragment.optionsFragmentFont.text =
createTitleAndSubtitleText(requireContext(), title, subtitle)
}

private fun updateTimeFormatSubtitle() {
val fragment = OptionsFragmentBinding.bind(requireView())
val position = settings.getInt(getString(R.string.prefs_settings_key_time_format), 0)
Expand Down Expand Up @@ -261,6 +277,12 @@ class OptionsFragment : BaseFragment(), SharedPreferences.OnSharedPreferenceChan
if (s.equals(getString(R.string.prefs_settings_key_theme), true)) {
updateThemeSubtitle()
}
if (s.equals(getString(R.string.prefs_settings_key_dark_mode), true)) {
updateDarkModeSubtitle()
}
if (s.equals(getString(R.string.prefs_settings_key_font), true)) {
updateFontSubtitle()
}
if (s.equals(getString(R.string.prefs_settings_key_time_format), true)) {
updateTimeFormatSubtitle()
}
Expand Down
7 changes: 4 additions & 3 deletions app/src/main/java/com/sduduzog/slimlauncher/utils/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ import android.graphics.Rect
import android.os.Build
import android.text.SpannableStringBuilder
import android.text.Spanned
import android.text.style.TextAppearanceSpan
import android.text.style.RelativeSizeSpan
import android.util.DisplayMetrics
import android.view.WindowInsets
import androidx.annotation.StringRes
import com.jkuester.unlauncher.datastore.AlignmentFormat
import com.sduduzog.slimlauncher.R
// import android.text.style.TextAppearanceSpan

private fun isAppDefaultLauncher(context: Context?): Boolean {
val intent = Intent(Intent.ACTION_MAIN)
Expand Down Expand Up @@ -98,13 +99,13 @@ fun createTitleAndSubtitleText(
): CharSequence {
val spanBuilder = SpannableStringBuilder("$title\n$subtitle")
spanBuilder.setSpan(
TextAppearanceSpan(context, R.style.TextAppearance_AppCompat_Large),
RelativeSizeSpan(0.8F),
0,
title.length,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
)
spanBuilder.setSpan(
TextAppearanceSpan(context, R.style.TextAppearance_AppCompat_Small),
RelativeSizeSpan(0.6F),
title.length + 1,
title.length + 1 + subtitle.length,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
Expand Down
13 changes: 12 additions & 1 deletion app/src/main/res/layout/options_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,17 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/options_fragment_change_theme" />

<TextView
android:id="@+id/options_fragment_font"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_list_items"
android:layout_width="match_parent"
android:text="@string/options_fragment_font"
android:textAppearance="@style/TextAppearance.AppCompat"
android:textSize="@dimen/font_size_customize_options"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/options_fragment_dark_mode" />

<androidx.appcompat.widget.SwitchCompat
android:id="@+id/options_fragment_auto_device_theme_wallpaper"
android:layout_width="match_parent"
Expand All @@ -127,7 +138,7 @@
android:textAppearance="@style/TextAppearance.AppCompat"
android:textSize="@dimen/font_size_customize_options"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/options_fragment_dark_mode" />
app:layout_constraintTop_toBottomOf="@+id/options_fragment_font" />

<TextView
android:id="@+id/options_fragment_choose_alignment"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
<item>Rot</item>
<item>Türkis</item>
<item>Blau</item>
<item>Flieder</item>
</string-array>
<string-array name="dark_mode_array">
<item>Systemvorgabe</item>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<item>Rouge</item>
<item>Cyan</item>
<item>Bleu</item>
<item>Lilas</item>
</string-array>
<string-array name="dark_mode_array">
<item>Système</item>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-it/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<item>Rosso</item>
<item>Ciano</item>
<item>Blu</item>
<item>Lillà</item>
</string-array>
<string-array name="dark_mode_array">
<item>Predefinito</item>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-nb/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<item>Rød</item>
<item>Turkis</item>
<item>Blå</item>
<item>Syrin</item>
</string-array>
<string-array name="time_format_array">
<item>Systeeminstellingen volgen</item>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-night/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@
<color name="primaryColorDark">#000000</color>
<color name="primaryColorLight">#808080</color>
<color name="redAccentColor">#CF0000</color>
<color name="lilacAccentColor">#6000CF</color>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-nl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<item>Rood</item>
<item>Turkoois</item>
<item>Blauw</item>
<item>Sering</item>
</string-array>
<string-array name="dark_mode_array">
<item>System standaard</item>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-notnight/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@
<color name="primaryColorDark">#C0C0C0</color>
<color name="primaryColorLight">#FFFFFF</color>
<color name="redAccentColor">#FF3030</color>
<color name="lilacAccentColor">#8020EF</color>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<item>красная</item>
<item>Бирюзовая</item>
<item>Синий</item>
<item>Сире́нь</item>
</string-array>
<string-array name="time_format_array">
<item>по умолчанию</item>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-uk/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<item>Червоний</item>
<item>Бірюзовий</item>
<item>Синій</item>
<item>Бузо́к</item>
</string-array>
<string-array name="time_format_array">
<item>Системний</item>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<item>红色</item>
<item>青色</item>
<item>蓝色</item>
<item>丁香</item>
</string-array>
<string-array name="time_format_array">
<item>跟随系统设置</item>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-zh-rTW/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<item>紅色</item>
<item>青色</item>
<item>藍色</item>
<item>丁香</item>
</string-array>
<string-array name="time_format_array">
<item>根據系統設置</item>
Expand Down
Loading
Loading