diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml index 0f01f57..814c751 100644 --- a/.idea/deploymentTargetDropDown.xml +++ b/.idea/deploymentTargetDropDown.xml @@ -15,7 +15,7 @@ - + diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 9ff3b48..e003df8 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -37,9 +37,12 @@ android:resource="@xml/key_view" /> - - - + + \ No newline at end of file diff --git a/app/src/main/java/com/timber/soft/newkeyboard/AppInputMethodService.kt b/app/src/main/java/com/timber/soft/newkeyboard/AppInputMethodService.kt index 369cfc0..562331c 100644 --- a/app/src/main/java/com/timber/soft/newkeyboard/AppInputMethodService.kt +++ b/app/src/main/java/com/timber/soft/newkeyboard/AppInputMethodService.kt @@ -136,9 +136,9 @@ class AppInputMethodService : InputMethodService(), OnKeyboardActionListener { } } } - } + // 点击完成 Keyboard.KEYCODE_DONE -> { currentInputConnection.performEditorAction(EditorInfo.IME_ACTION_DONE) } diff --git a/app/src/main/java/com/timber/soft/newkeyboard/activity/ApplyActivity.kt b/app/src/main/java/com/timber/soft/newkeyboard/activity/ApplyActivity.kt index 830f511..8c9ae5b 100644 --- a/app/src/main/java/com/timber/soft/newkeyboard/activity/ApplyActivity.kt +++ b/app/src/main/java/com/timber/soft/newkeyboard/activity/ApplyActivity.kt @@ -3,6 +3,7 @@ package com.timber.soft.newkeyboard.activity import android.content.BroadcastReceiver import android.content.Context import android.content.Intent +import android.content.IntentFilter import android.graphics.Color import android.os.Build import android.os.Bundle @@ -11,13 +12,41 @@ import android.view.View import android.view.inputmethod.InputMethodInfo import android.view.inputmethod.InputMethodManager import androidx.appcompat.app.AppCompatActivity +import com.timber.soft.newkeyboard.R import com.timber.soft.newkeyboard.databinding.ActivityApplyBinding import com.timber.soft.newkeyboard.tools.StatusBarTools -class ApplyActivity : AppCompatActivity() { +class ApplyActivity : AppCompatActivity(), View.OnClickListener { private lateinit var binding: ActivityApplyBinding private lateinit var inputManager: InputMethodManager + private lateinit var listener: BroadcastReceiver + + private fun chooseKeyboard() { + inputManager.showInputMethodPicker() + } + + private fun applyKeyboard() { + Intent(Settings.ACTION_INPUT_METHOD_SETTINGS).apply { + startActivity(this) + } + } + + override fun onClick(v: View?) { + when (v) { + binding.idStep2 -> { + chooseKeyboard() + } + + binding.idStep1 -> { + applyKeyboard() + } + + binding.applyBack -> { + finish() + } + } + } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -33,15 +62,14 @@ class ApplyActivity : AppCompatActivity() { window.statusBarColor = Color.TRANSPARENT } inputManager = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager - binding.applyBack.setOnClickListener() { - finish() - } - binding.idStep1.setOnClickListener() { - applyKeyboard() - } - binding.idStep2.setOnClickListener() { - chooseKeyboard() - } + + updateUi() + listener = StepReceive() + register() + + binding.idStep1.setOnClickListener(this) + binding.idStep2.setOnClickListener(this) + binding.applyBack.setOnClickListener(this) } override fun onResume() { @@ -49,34 +77,9 @@ class ApplyActivity : AppCompatActivity() { updateUi() } - private fun chooseKeyboard() { - inputManager.showInputMethodPicker() - } - - private fun applyKeyboard() { - Intent(Settings.ACTION_INPUT_METHOD_SETTINGS).apply { - startActivity(this) - } - } - - private fun updateUi() { - binding.idStep1.setSelected(isEnable()) - binding.idStep2.setSelected(isChoose()) - } - - private fun isChoose(): Boolean { - Settings.Secure.getString(contentResolver, Settings.Secure.DEFAULT_INPUT_METHOD).let { id -> - return id.startsWith(packageName) - } - } - - private fun isEnable(): Boolean { - for (info: InputMethodInfo in inputManager.enabledInputMethodList) { - if (info.id.startsWith(packageName)) { - return true - } - } - return false + override fun onDestroy() { + super.onDestroy() + unregisterReceiver(listener) } inner class StepReceive : BroadcastReceiver() { @@ -85,4 +88,41 @@ class ApplyActivity : AppCompatActivity() { } } + private fun register() { + registerReceiver(listener, IntentFilter(Intent.ACTION_INPUT_METHOD_CHANGED)) + } + + private fun updateUi() { + if (isEnable()) { + binding.idStep1.setBackgroundResource(R.drawable.shape_theme_set_over) + } else { + binding.idStep1.setBackgroundResource(R.drawable.shape_theme_set) + } + if (isChoose()) { + binding.idStep2.setBackgroundResource(R.drawable.shape_theme_set_over) + } else { + binding.idStep2.setBackgroundResource(R.drawable.shape_theme_set) + } + } + + /** + * 检查是否设置键盘 + */ + private fun isChoose(): Boolean { + Settings.Secure.getString(contentResolver, Settings.Secure.DEFAULT_INPUT_METHOD).let { id -> + return id.startsWith(packageName) + } + } + + /** + * 检查是否启用键盘 + */ + private fun isEnable(): Boolean { + for (info: InputMethodInfo in inputManager.enabledInputMethodList) { + if (info.id.startsWith(packageName)) { + return true + } + } + return false + } } \ No newline at end of file diff --git a/app/src/main/java/com/timber/soft/newkeyboard/activity/DetailsActivity.kt b/app/src/main/java/com/timber/soft/newkeyboard/activity/DetailsActivity.kt index fe32099..e38a0c4 100644 --- a/app/src/main/java/com/timber/soft/newkeyboard/activity/DetailsActivity.kt +++ b/app/src/main/java/com/timber/soft/newkeyboard/activity/DetailsActivity.kt @@ -63,14 +63,12 @@ class DetailsActivity : AppCompatActivity(), ApplyListener { inputManager = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager dataModel = intent.getSerializableExtra("KEY_EXTRA") as DataModel - previewUrl = dataModel.thumb val cacheDir = cacheDir val dataModelUrl = dataModel.zipUrl zipPath = "$cacheDir/$dataModelUrl" - binding.detailsBack.setOnClickListener(View.OnClickListener { finish() }) @@ -134,7 +132,8 @@ class DetailsActivity : AppCompatActivity(), ApplyListener { return } - binding.themeProgressbar.visibility = View.VISIBLE + binding.coverView.visibility = View.VISIBLE + val file = File(zipPath) // 判断缓存中是否存在文件 if (file.exists()) { @@ -298,7 +297,7 @@ class DetailsActivity : AppCompatActivity(), ApplyListener { * 点击设置后的回调接口 */ override fun applyListener(isSuccess: Boolean, str: String) { - binding.themeProgressbar.visibility = View.GONE + binding.coverView.visibility = View.GONE if (isSuccess) { val lastIndexOf: Int = str.lastIndexOf(AppVal.res_path) val substring = str.subSequence(0, lastIndexOf + AppVal.res_path.length).toString() diff --git a/app/src/main/java/com/timber/soft/newkeyboard/view/MyKeyboardView.kt b/app/src/main/java/com/timber/soft/newkeyboard/view/MyKeyboardView.kt index d70439c..c53c9f1 100644 --- a/app/src/main/java/com/timber/soft/newkeyboard/view/MyKeyboardView.kt +++ b/app/src/main/java/com/timber/soft/newkeyboard/view/MyKeyboardView.kt @@ -101,10 +101,7 @@ class MyKeyboardView @JvmOverloads constructor( ) if (press != null) { if (default != null) { - val listDrawable = StateListDrawable().apply { - addState(intArrayOf(android.R.attr.state_pressed), press) - addState(intArrayOf(), default) - } + val listDrawable = getStatus(default,press) functionBackgroundDraw = listDrawable normalBackgroundDraw = listDrawable spBackgroundDraw = listDrawable diff --git a/app/src/main/res/drawable/shape_theme_set_over.xml b/app/src/main/res/drawable/shape_theme_set_over.xml new file mode 100644 index 0000000..9e75a75 --- /dev/null +++ b/app/src/main/res/drawable/shape_theme_set_over.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_details.xml b/app/src/main/res/layout/activity_details.xml index 6f74ca4..2e0b55b 100644 --- a/app/src/main/res/layout/activity_details.xml +++ b/app/src/main/res/layout/activity_details.xml @@ -18,9 +18,9 @@ android:id="@+id/details_back" android:layout_width="33dp" android:layout_height="33dp" + android:layout_marginStart="8dp" android:layout_marginTop="10dp" android:padding="5dp" - android:layout_marginStart="8dp" android:src="@drawable/svg_return" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintTop_toTopOf="parent" /> @@ -52,23 +52,15 @@ android:layout_width="match_parent" android:layout_height="43dp" android:layout_below="@id/theme_image" - android:layout_marginStart="15dp" + android:layout_marginStart="66dp" android:layout_marginTop="64dp" - android:layout_marginEnd="15dp" + android:layout_marginEnd="66dp" android:background="@drawable/shape_theme_set" android:gravity="center" android:text="@string/download_apply" android:textColor="@color/white" android:textSize="15sp" /> - + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 1b30792..869f86b 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -45,8 +45,8 @@ \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index f24d595..2ce8385 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -2,9 +2,6 @@ #FF000000 #FFFFFFFF - - #FFBB86FC - - + #FF888888 \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 510b12c..4a3b954 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -12,4 +12,5 @@ Application successful Application failed, please try again For normal use, please enter the setting to complete the setting steps. + Loading… \ No newline at end of file