Skip to content

Commit

Permalink
Init theme class and complete color class and reset class
Browse files Browse the repository at this point in the history
  • Loading branch information
WhiredPlanck committed Jun 16, 2021
1 parent bdb631e commit c0b767c
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,50 @@
package com.osfans.trime.settings.components

class ColorPickerDialog {
import android.app.AlertDialog
import android.content.Context
import com.osfans.trime.Config
import com.osfans.trime.R
import com.osfans.trime.Trime

/** 顯示配色方案列表
* Show Color Scheme List
* **/
class ColorPickerDialog(
context: Context
) {
val config: Config = Config.get(context)
private var colorKeys: Array<String>
private var checkedColor: Int = 0
var pickerDialog: AlertDialog
private set // 设定方法不向外开放

init {
val colorScheme = config.colorScheme
colorKeys = config.colorKeys
colorKeys.sort()
val colorNames = config.getColorNames(colorKeys)
checkedColor = colorKeys.binarySearch(colorScheme)

pickerDialog = AlertDialog.Builder(context).apply {
setTitle(R.string.pref_colors)
setCancelable(true)
setNegativeButton(android.R.string.cancel, null)
setPositiveButton(android.R.string.ok) { _, _ ->
selectColor()
}
setSingleChoiceItems(
colorNames, checkedColor
) {_, id -> checkedColor = id}
}.create()
}

private fun selectColor() {
if (checkedColor < 0 || checkedColor >= colorKeys.size) return
val colorKey = colorKeys[checkedColor]
config.setColor(colorKey)
Trime.getService()?.initKeyboard() // 立刻重初始化键盘生效
}

/** 调用该方法显示对话框 **/
fun show() = pickerDialog.show()
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,50 @@
package com.osfans.trime.settings.components

class ResetAssetsDialog {
import android.app.AlertDialog
import android.content.Context
import android.widget.Toast
import com.osfans.trime.Config
import com.osfans.trime.R

/** 顯示輸入法內置數據列表,並回廠選中的數據 */
class ResetAssetsDialog(private val context: Context) {
private val config = Config.get(context)
/** 內置數據列表 */
private var assetItems: Array<String?> = Config.list(context, "rime")

/** 列表勾選狀態 */
private var checkedStatus: BooleanArray = BooleanArray(assetItems.size)

/** 回廠對話框 */
var resetDialog: AlertDialog
private set

init {
resetDialog = AlertDialog.Builder(context).apply {
setTitle(R.string.pref_reset)
setCancelable(true)
setNegativeButton(android.R.string.cancel, null)
setPositiveButton(android.R.string.ok) { _, _ ->
selectAssets()
}
setMultiChoiceItems(
assetItems, checkedStatus
) { _, id, isChecked -> checkedStatus[id] = isChecked }
}.create()
}

private fun selectAssets() {
var result = true
for (i in assetItems.indices) {
result = if (checkedStatus[i]) {
config.copyFileOrDir(context, assetItems[i], true)
} else false
}
Toast.makeText(context,
if (result) R.string.reset_success else R.string.reset_failure,
Toast.LENGTH_SHORT).show()
}

/** 彈出對話框 */
fun show() = resetDialog.show()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.osfans.trime.settings.components

class ThemePickerDialog {
}

0 comments on commit c0b767c

Please sign in to comment.