-
-
Notifications
You must be signed in to change notification settings - Fork 385
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Init theme class and complete color class and reset class
- Loading branch information
1 parent
bdb631e
commit c0b767c
Showing
3 changed files
with
98 additions
and
2 deletions.
There are no files selected for viewing
48 changes: 47 additions & 1 deletion
48
app/src/main/java/com/osfans/trime/settings/components/ColorPickerDialog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
48 changes: 47 additions & 1 deletion
48
app/src/main/java/com/osfans/trime/settings/components/ResetAssetsDialog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
4 changes: 4 additions & 0 deletions
4
app/src/main/java/com/osfans/trime/settings/components/ThemePickerDialog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.osfans.trime.settings.components | ||
|
||
class ThemePickerDialog { | ||
} |