Add shortcut as google language (en_US), added subset of settings to backup

This commit is contained in:
Kieran W 2025-02-08 16:53:02 +00:00
parent a3bfa5a58f
commit 4c88f24af3
5 changed files with 47 additions and 20 deletions

View File

@ -1,5 +1,6 @@
package com.fredhappyface.ewesticker
import android.content.Context
import android.content.SharedPreferences
import android.inputmethodservice.InputMethodService
import android.os.Build
@ -47,6 +48,7 @@ class ImageKeyboard : InputMethodService(), StickerClickListener {
// onCreate
// Shared Preferences
private lateinit var sharedPreferences: SharedPreferences
private lateinit var backupSharedPreferences: SharedPreferences
private var restoreOnClose = false
private var vertical = false
private var scroll = false
@ -107,13 +109,14 @@ class ImageKeyboard : InputMethodService(), StickerClickListener {
Coil.setImageLoader(imageLoader)
// Shared Preferences
this.sharedPreferences = PreferenceManager.getDefaultSharedPreferences(baseContext)
this.restoreOnClose = this.sharedPreferences.getBoolean("restoreOnClose", false)
this.vertical = this.sharedPreferences.getBoolean("vertical", false)
this.scroll = this.sharedPreferences.getBoolean("scroll", false)
this.vibrate = this.sharedPreferences.getBoolean("vibrate", true)
this.insensitiveSort = this.sharedPreferences.getBoolean("insensitiveSort", false)
this.backupSharedPreferences = this.getSharedPreferences("backup_prefs", Context.MODE_PRIVATE)
this.restoreOnClose = this.backupSharedPreferences.getBoolean("restoreOnClose", false)
this.vertical = this.backupSharedPreferences.getBoolean("vertical", false)
this.scroll = this.backupSharedPreferences.getBoolean("scroll", false)
this.vibrate = this.backupSharedPreferences.getBoolean("vibrate", true)
this.insensitiveSort = this.backupSharedPreferences.getBoolean("insensitiveSort", false)
this.iconsPerX = this.sharedPreferences.getInt("iconsPerX", 3)
this.iconsPerX = this.backupSharedPreferences.getInt("iconsPerX", 3)
this.totalIconPadding =
(resources.getDimension(R.dimen.sticker_padding) * 2 * (this.iconsPerX + 1)).toInt()
// Constants
@ -123,7 +126,7 @@ class ImageKeyboard : InputMethodService(), StickerClickListener {
if (this.vertical) {
(resources.displayMetrics.widthPixels - this.totalIconPadding) / this.iconsPerX.toFloat()
} else {
(this.sharedPreferences.getInt("iconSize", 80) * scale)
(this.backupSharedPreferences.getInt("iconSize", 80) * scale)
}
).toInt()
this.toaster = Toaster(baseContext)
@ -419,7 +422,7 @@ class ImageKeyboard : InputMethodService(), StickerClickListener {
private fun createPackIcons() {
this.packsList.removeAllViewsInLayout()
// Back button
if (this.sharedPreferences.getBoolean("showBackButton", true)) {
if (this.backupSharedPreferences.getBoolean("showBackButton", true)) {
val backButton = addPackButton("__back__")
backButton.load(getDrawable(R.drawable.arrow_back_circle))
backButton.setOnClickListener {
@ -428,7 +431,7 @@ class ImageKeyboard : InputMethodService(), StickerClickListener {
}
// Search
if (this.sharedPreferences.getBoolean("showSearchButton", true)) {
if (this.backupSharedPreferences.getBoolean("showSearchButton", true)) {
val searchButton = addPackButton("__search__")
searchButton.load(getDrawable(R.drawable.search_circle))
searchButton.setOnClickListener {

View File

@ -1,6 +1,7 @@
package com.fredhappyface.ewesticker
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.content.SharedPreferences
import android.content.pm.PackageManager
@ -28,6 +29,7 @@ import java.util.Calendar
class MainActivity : AppCompatActivity() {
// onCreate
private lateinit var sharedPreferences: SharedPreferences
private lateinit var backupSharedPreferences: SharedPreferences
private lateinit var contextView: View
private lateinit var toaster: Toaster
@ -50,6 +52,7 @@ class MainActivity : AppCompatActivity() {
// Set late-init attrs
this.sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this)
this.backupSharedPreferences = this.getSharedPreferences("backup_prefs", Context.MODE_PRIVATE)
this.contextView = findViewById(R.id.activityMainRoot)
this.toaster = Toaster(baseContext)
refreshStickerDirPath()
@ -194,12 +197,12 @@ class MainActivity : AppCompatActivity() {
callback: (Boolean) -> Unit,
) {
compoundButton.isChecked =
this.sharedPreferences.getBoolean(sharedPrefKey, sharedPrefDefault)
this.backupSharedPreferences.getBoolean(sharedPrefKey, sharedPrefDefault)
callback(compoundButton.isChecked)
compoundButton.setOnCheckedChangeListener { _: CompoundButton?, isChecked: Boolean ->
showChangedPrefText()
callback(compoundButton.isChecked)
val editor = this.sharedPreferences.edit()
val editor = this.backupSharedPreferences.edit()
editor.putBoolean(sharedPrefKey, isChecked)
editor.apply()
}
@ -223,9 +226,9 @@ class MainActivity : AppCompatActivity() {
multiplier: Int = 1,
) {
seekBarLabel.text =
this.sharedPreferences.getInt(sharedPrefKey, sharedPrefDefault).toString()
this.backupSharedPreferences.getInt(sharedPrefKey, sharedPrefDefault).toString()
seekBar.progress =
this.sharedPreferences.getInt(sharedPrefKey, sharedPrefDefault) / multiplier
this.backupSharedPreferences.getInt(sharedPrefKey, sharedPrefDefault) / multiplier
seekBar.setOnSeekBarChangeListener(
object : OnSeekBarChangeListener {
var progressMultiplier = sharedPrefDefault
@ -236,7 +239,7 @@ class MainActivity : AppCompatActivity() {
override fun onStartTrackingTouch(seekBar: SeekBar) {}
override fun onStopTrackingTouch(seekBar: SeekBar) {
val editor = sharedPreferences.edit()
val editor = backupSharedPreferences.edit()
editor.putInt(sharedPrefKey, progressMultiplier)
editor.apply()
showChangedPrefText()

View File

@ -3,9 +3,18 @@
See https://developer.android.com/about/versions/12/backup-restore#xml-changes
for details.
-->
<data-extraction-rules>
<data-extraction-rules>\
<cloud-backup>
<!--
<!-- Include the backup SharedPreferences file -->
<include domain="sharedpref" path="backup_prefs.xml"/>
</cloud-backup>
<device-transfer>
<!-- Include the backup SharedPreferences file for device transfer -->
<include domain="sharedpref" path="backup_prefs.xml"/>
</device-transfer>
<!--
<cloud-backup>
The domain can be file, database, sharedpref, external or root.
Examples:
@ -23,8 +32,8 @@
<exclude domain="external" path="file_to_exclude"/>
<include domain="root" path="file_to_include"/>
<exclude domain="root" path="file_to_exclude"/>
-->
</cloud-backup>
-->
<!--
<device-transfer>
<include .../>

View File

@ -1,2 +1,6 @@
<!--suppress CheckTagEmptyBody -->
<full-backup-content></full-backup-content>
<?xml version="1.0" encoding="utf-8"?>
<full-backup-content>
<!-- Include specific files or directories -->
<include domain="sharedpref" path="backup_prefs.xml"/>
</full-backup-content>

View File

@ -1,2 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<input-method />
<input-method xmlns:android="http://schemas.android.com/apk/res/android">
<subtype
android:icon="@drawable/ic_launcher_mono"
android:label="@string/app_name"
android:imeSubtypeLocale="en_US"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="KeyCharacterMap:Special_Symbols"
/>
</input-method>