mirror of
https://gitee.com/zhangsken/AndroidIDE.git
synced 2026-10-16 07:49:44 +08:00
feat: add preference to choose color schemes
This commit is contained in:
@@ -20,22 +20,24 @@ package com.itsaky.androidide.preferences
|
||||
import android.view.LayoutInflater
|
||||
import androidx.preference.Preference
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.itsaky.androidide.resources.R.drawable
|
||||
import com.itsaky.androidide.resources.R.string
|
||||
import com.itsaky.androidide.R
|
||||
import com.itsaky.androidide.databinding.LayoutTextSizeSliderBinding
|
||||
import com.itsaky.androidide.editor.schemes.IDEColorSchemeProvider
|
||||
import com.itsaky.androidide.preferences.internal.AUTO_SAVE
|
||||
import com.itsaky.androidide.preferences.internal.COLOR_SCHEME
|
||||
import com.itsaky.androidide.preferences.internal.COMPLETIONS_MATCH_LOWER
|
||||
import com.itsaky.androidide.preferences.internal.FLAG_PASSWORD
|
||||
import com.itsaky.androidide.preferences.internal.FONT_LIGATURES
|
||||
import com.itsaky.androidide.preferences.internal.FONT_SIZE
|
||||
import com.itsaky.androidide.preferences.internal.PRINTABLE_CHARS
|
||||
import com.itsaky.androidide.preferences.internal.TAB_SIZE
|
||||
import com.itsaky.androidide.preferences.internal.USE_CUSTOM_FONT
|
||||
import com.itsaky.androidide.preferences.internal.USE_ICU
|
||||
import com.itsaky.androidide.preferences.internal.USE_MAGNIFER
|
||||
import com.itsaky.androidide.preferences.internal.USE_SOFT_TAB
|
||||
import com.itsaky.androidide.preferences.internal.USE_CUSTOM_FONT
|
||||
import com.itsaky.androidide.preferences.internal.WORD_WRAP
|
||||
import com.itsaky.androidide.preferences.internal.autoSave
|
||||
import com.itsaky.androidide.preferences.internal.colorScheme
|
||||
import com.itsaky.androidide.preferences.internal.completionsMatchLower
|
||||
import com.itsaky.androidide.preferences.internal.drawEmptyLineWs
|
||||
import com.itsaky.androidide.preferences.internal.drawInnerWs
|
||||
@@ -45,12 +47,15 @@ import com.itsaky.androidide.preferences.internal.drawTrailingWs
|
||||
import com.itsaky.androidide.preferences.internal.fontLigatures
|
||||
import com.itsaky.androidide.preferences.internal.fontSize
|
||||
import com.itsaky.androidide.preferences.internal.tabSize
|
||||
import com.itsaky.androidide.preferences.internal.useCustomFont
|
||||
import com.itsaky.androidide.preferences.internal.useIcu
|
||||
import com.itsaky.androidide.preferences.internal.useMagnifier
|
||||
import com.itsaky.androidide.preferences.internal.useSoftTab
|
||||
import com.itsaky.androidide.preferences.internal.useCustomFont
|
||||
import com.itsaky.androidide.preferences.internal.visiblePasswordFlag
|
||||
import com.itsaky.androidide.preferences.internal.wordwrap
|
||||
import com.itsaky.androidide.resources.R.drawable
|
||||
import com.itsaky.androidide.resources.R.string
|
||||
import kotlinx.parcelize.IgnoredOnParcel
|
||||
import kotlinx.parcelize.Parcelize
|
||||
|
||||
@Parcelize
|
||||
@@ -76,6 +81,7 @@ private class CommonConfigurations(
|
||||
init {
|
||||
addPreference(TextSize())
|
||||
addPreference(TabSize())
|
||||
addPreference(ColorSchemePreference())
|
||||
addPreference(NonPrintablePaintingFlags())
|
||||
addPreference(FontLigatures())
|
||||
addPreference(UseCustomFont())
|
||||
@@ -171,6 +177,36 @@ private class TabSize(
|
||||
}
|
||||
}
|
||||
|
||||
@Parcelize
|
||||
private class ColorSchemePreference(
|
||||
override val key: String = COLOR_SCHEME,
|
||||
override val title: Int = R.string.idepref_editor_colorScheme,
|
||||
override val summary: Int? = R.string.idepref_editor_colorScheme_summary,
|
||||
override val icon: Int? = R.drawable.ic_color_scheme
|
||||
) : SingleChoicePreference() {
|
||||
|
||||
@IgnoredOnParcel private val schemes = IDEColorSchemeProvider.list()
|
||||
|
||||
override fun getChoices(): Array<String> {
|
||||
return schemes.map { it.name }.toTypedArray()
|
||||
}
|
||||
|
||||
override fun getSelectedItem(): Int {
|
||||
return schemes.indexOfFirst { it.key == colorScheme }
|
||||
}
|
||||
|
||||
override fun onItemSelected(position: Int, isSelected: Boolean) {
|
||||
if (isSelected) {
|
||||
colorScheme = schemes[position].key
|
||||
}
|
||||
}
|
||||
|
||||
override fun onConfigureDialog(preference: Preference, dialog: MaterialAlertDialogBuilder) {
|
||||
super.onConfigureDialog(preference, dialog)
|
||||
dialog.setCancelable(true)
|
||||
}
|
||||
}
|
||||
|
||||
@Parcelize
|
||||
private class NonPrintablePaintingFlags(
|
||||
override val key: String = PRINTABLE_CHARS,
|
||||
|
||||
@@ -24,7 +24,7 @@ import io.github.rosemoe.sora.widget.schemes.EditorColorScheme
|
||||
import java.io.File
|
||||
import java.util.TreeSet
|
||||
|
||||
class IDEColorScheme(internal val file: File) : EditorColorScheme() {
|
||||
class IDEColorScheme(internal val file: File, val key: String) : EditorColorScheme() {
|
||||
|
||||
internal val colorIds = mutableMapOf<Int, Int>()
|
||||
internal val editorScheme = mutableMapOf<Int, Int>()
|
||||
|
||||
@@ -23,6 +23,7 @@ import com.itsaky.androidide.utils.Environment
|
||||
import com.itsaky.androidide.utils.ILogger
|
||||
import java.io.File
|
||||
import java.io.FileFilter
|
||||
import java.util.Collections
|
||||
import java.util.Properties
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
import java.util.function.Consumer
|
||||
@@ -86,13 +87,13 @@ object IDEColorSchemeProvider {
|
||||
continue
|
||||
}
|
||||
|
||||
val scheme = IDEColorScheme(File(schemeDir, file))
|
||||
val scheme = IDEColorScheme(File(schemeDir, file), schemeDir.name)
|
||||
scheme.name = name
|
||||
scheme.isDarkScheme = isDark
|
||||
scheme.langs = langs.toTypedArray()
|
||||
schemes[schemeDir.name] = scheme
|
||||
}
|
||||
|
||||
|
||||
currentScheme!!
|
||||
}
|
||||
|
||||
@@ -109,4 +110,8 @@ object IDEColorSchemeProvider {
|
||||
consume(scheme)
|
||||
}
|
||||
}
|
||||
|
||||
fun list(): List<IDEColorScheme> {
|
||||
return this.schemes.values.toList()
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -103,7 +103,7 @@ class SchemeParser(private val resolveFileRef: (String) -> File) {
|
||||
|
||||
fun parse(file: File, name: String, isDark: Boolean, langs: Array<String>): IDEColorScheme {
|
||||
require(file.exists() && file.isFile) { "File does not exist or is not a file" }
|
||||
val scheme = IDEColorScheme(file)
|
||||
val scheme = IDEColorScheme(file, name)
|
||||
scheme.name = name
|
||||
scheme.isDarkScheme = isDark
|
||||
scheme.langs = langs
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
<!--
|
||||
~ This file is part of AndroidIDE.
|
||||
~
|
||||
~ AndroidIDE is free software: you can redistribute it and/or modify
|
||||
~ it under the terms of the GNU General Public License as published by
|
||||
~ the Free Software Foundation, either version 3 of the License, or
|
||||
~ (at your option) any later version.
|
||||
~
|
||||
~ AndroidIDE is distributed in the hope that it will be useful,
|
||||
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
~ GNU General Public License for more details.
|
||||
~
|
||||
~ You should have received a copy of the GNU General Public License
|
||||
~ along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
|
||||
-->
|
||||
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:tint="#FFFFFF"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="@color/primaryIconColor"
|
||||
android:pathData="M12,3c-4.97,0 -9,4.03 -9,9s4.03,9 9,9c0.83,0 1.5,-0.67 1.5,-1.5 0,-0.39 -0.15,-0.74 -0.39,-1.01 -0.23,-0.26 -0.38,-0.61 -0.38,-0.99 0,-0.83 0.67,-1.5 1.5,-1.5L16,16c2.76,0 5,-2.24 5,-5 0,-4.42 -4.03,-8 -9,-8zM6.5,12c-0.83,0 -1.5,-0.67 -1.5,-1.5S5.67,9 6.5,9 8,9.67 8,10.5 7.33,12 6.5,12zM9.5,8C8.67,8 8,7.33 8,6.5S8.67,5 9.5,5s1.5,0.67 1.5,1.5S10.33,8 9.5,8zM14.5,8c-0.83,0 -1.5,-0.67 -1.5,-1.5S13.67,5 14.5,5s1.5,0.67 1.5,1.5S15.33,8 14.5,8zM17.5,12c-0.83,0 -1.5,-0.67 -1.5,-1.5S16.67,9 17.5,9s1.5,0.67 1.5,1.5 -0.67,1.5 -1.5,1.5z" />
|
||||
</vector>
|
||||
@@ -520,4 +520,6 @@
|
||||
<string name="git_clone_failed">Failed to clone git repository</string>
|
||||
<string name="msg_select_attr">Select an attribute from the below list</string>
|
||||
<string name="action_show_hierarchy">Show layout hierarchy</string>
|
||||
<string name="idepref_editor_colorScheme">Color Scheme</string>
|
||||
<string name="idepref_editor_colorScheme_summary">Choose color scheme to use in editor</string>
|
||||
</resources>
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user