This repository has been archived by the owner on Jul 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Optimize the method to determine whether to run Xiaomi system
- Loading branch information
Showing
29 changed files
with
223 additions
and
178 deletions.
There are no files selected for viewing
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
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
2 changes: 1 addition & 1 deletion
2
...pdate/logic/adapter/CustomArrayAdapter.kt → ...te/activity/adapter/CustomArrayAdapter.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
2 changes: 1 addition & 1 deletion
2
...iew/CustomMaterialAutoCompleteTextView.kt → ...iew/CustomMaterialAutoCompleteTextView.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
2 changes: 1 addition & 1 deletion
2
...a/update/logic/viewModel/MainViewModel.kt → ...pdate/activity/viewModel/MainViewModel.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
2 changes: 1 addition & 1 deletion
2
...lin/top/yukonga/update/MainApplication.kt → ...nga/update/application/MainApplication.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
35 changes: 0 additions & 35 deletions
35
app/src/main/kotlin/top/yukonga/update/logic/UpdaterExtensions.kt
This file was deleted.
Oops, something went wrong.
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
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
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
15 changes: 15 additions & 0 deletions
15
app/src/main/kotlin/top/yukonga/update/logic/utils/AndroidUtils.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,15 @@ | ||
package top.yukonga.update.logic.utils | ||
|
||
import android.os.Build | ||
|
||
object AndroidUtils { | ||
|
||
fun atLeastAndroidP(): Boolean = Build.VERSION.SDK_INT >= Build.VERSION_CODES.P | ||
|
||
fun atLeastAndroidQ(): Boolean = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q | ||
|
||
fun atLeastAndroidR(): Boolean = Build.VERSION.SDK_INT >= Build.VERSION_CODES.R | ||
|
||
fun atLeastAndroidT(): Boolean = Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
app/src/main/kotlin/top/yukonga/update/logic/utils/AnimUtils.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,38 @@ | ||
package top.yukonga.update.logic.utils | ||
|
||
import android.graphics.Typeface | ||
import android.view.View | ||
import android.widget.TextView | ||
import androidx.core.view.isVisible | ||
|
||
object AnimUtils { | ||
fun TextView.setTextAnimation(text: CharSequence?, duration: Long = 300, completion: (() -> Unit)? = null) { | ||
if (!this.text.contentEquals(text) || !this.isVisible) { | ||
fadOutAnimation(duration) { | ||
this.text = text | ||
fadInAnimation(duration) { | ||
completion?.invoke() | ||
} | ||
} | ||
this.typeface = Typeface.MONOSPACE | ||
} | ||
} | ||
|
||
// ViewExtensions | ||
|
||
fun View.fadOutAnimation(duration: Long = 300, visibility: Int = View.GONE, completion: (() -> Unit)? = null) { | ||
animate().alpha(0f).setDuration(duration).withEndAction { | ||
this.visibility = visibility | ||
completion?.invoke() | ||
} | ||
} | ||
|
||
fun View.fadInAnimation(duration: Long = 300, completion: (() -> Unit)? = null) { | ||
alpha = 0f | ||
visibility = View.VISIBLE | ||
animate().alpha(1f).setDuration(duration).withEndAction { | ||
completion?.invoke() | ||
} | ||
|
||
} | ||
} |
88 changes: 0 additions & 88 deletions
88
app/src/main/kotlin/top/yukonga/update/logic/utils/AppUtils.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,102 +1,14 @@ | ||
package top.yukonga.update.logic.utils | ||
|
||
import android.annotation.SuppressLint | ||
import android.content.res.Configuration | ||
import android.content.res.Resources.getSystem | ||
import android.os.Build | ||
import android.os.Environment | ||
import android.text.TextUtils | ||
import android.util.TypedValue | ||
import android.view.HapticFeedbackConstants | ||
import android.view.View | ||
import java.io.BufferedReader | ||
import java.io.File | ||
import java.io.FileInputStream | ||
import java.io.IOException | ||
import java.io.InputStreamReader | ||
import java.util.Properties | ||
|
||
object AppUtils { | ||
|
||
fun hapticConfirm(view: View) { | ||
if (atLeastAndroidR()) view.performHapticFeedback(HapticFeedbackConstants.CONFIRM) | ||
else view.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY) | ||
} | ||
|
||
fun hapticReject(view: View) { | ||
if (atLeastAndroidR()) view.performHapticFeedback(HapticFeedbackConstants.REJECT) | ||
else view.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY) | ||
} | ||
|
||
fun atLeastAndroidP(): Boolean = Build.VERSION.SDK_INT >= Build.VERSION_CODES.P | ||
|
||
fun atLeastAndroidQ(): Boolean = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q | ||
|
||
fun atLeastAndroidR(): Boolean = Build.VERSION.SDK_INT >= Build.VERSION_CODES.R | ||
|
||
fun atLeastAndroidT(): Boolean = Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU | ||
|
||
fun isXiaomi(): Boolean = getProp("ro.miui.ui.version.code").isNotEmpty() && getProp("ro.miui.ui.version.name").isNotEmpty() | ||
|
||
fun isHyperOS(): Boolean = if (isXiaomi()) getProp("ro.miui.ui.version.code").toInt() >= 816 else false | ||
|
||
fun isTablet(): Boolean = | ||
getSystem().configuration.smallestScreenWidthDp >= 600 || getProp("ro.build.characteristics") == "tablet" || (getSystem().configuration.screenLayout and Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE | ||
|
||
fun isLandscape(): Boolean = getSystem().configuration.orientation == Configuration.ORIENTATION_LANDSCAPE | ||
|
||
val Int.dp: Int get() = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, this.toFloat(), getSystem().displayMetrics).toInt() | ||
|
||
val Int.px: Int get() = (this / getSystem().displayMetrics.density + 0.5f).toInt() | ||
|
||
fun getProp(name: String): String { | ||
var prop = getPropByShell(name) | ||
if (!TextUtils.isEmpty(prop)) return prop | ||
prop = getPropByStream(name) | ||
if (!TextUtils.isEmpty(prop)) return prop | ||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) return getPropByReflect(name) | ||
return prop | ||
} | ||
|
||
private fun getPropByShell(propName: String): String { | ||
var input: BufferedReader? = null | ||
try { | ||
val p = Runtime.getRuntime().exec("getprop $propName") | ||
input = BufferedReader(InputStreamReader(p.inputStream), 1024) | ||
val ret = input.readLine() | ||
if (ret != null) return ret | ||
} catch (ignore: IOException) { | ||
} finally { | ||
if (input != null) { | ||
try { | ||
input.close() | ||
} catch (_: IOException) { | ||
} | ||
} | ||
} | ||
return "" | ||
} | ||
|
||
private fun getPropByStream(key: String): String { | ||
try { | ||
val prop = Properties() | ||
val iS = FileInputStream( | ||
File(Environment.getRootDirectory(), "build.prop") | ||
) | ||
prop.load(iS) | ||
return prop.getProperty(key, "") | ||
} catch (_: Exception) { | ||
} | ||
return "" | ||
} | ||
|
||
private fun getPropByReflect(key: String): String { | ||
try { | ||
@SuppressLint("PrivateApi") val clz = Class.forName("android.os.SystemProperties") | ||
val getMethod = clz.getMethod("get", String::class.java, String::class.java) | ||
return getMethod.invoke(clz, key, "") as String | ||
} catch (_: Exception) { | ||
} | ||
return "" | ||
} | ||
} |
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
18 changes: 18 additions & 0 deletions
18
app/src/main/kotlin/top/yukonga/update/logic/utils/HapticUtils.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,18 @@ | ||
package top.yukonga.update.logic.utils | ||
|
||
import android.view.HapticFeedbackConstants | ||
import android.view.View | ||
|
||
object HapticUtils { | ||
|
||
fun hapticConfirm(view: View) { | ||
if (AndroidUtils.atLeastAndroidR()) view.performHapticFeedback(HapticFeedbackConstants.CONFIRM) | ||
else view.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY) | ||
} | ||
|
||
fun hapticReject(view: View) { | ||
if (AndroidUtils.atLeastAndroidR()) view.performHapticFeedback(HapticFeedbackConstants.REJECT) | ||
else view.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY) | ||
} | ||
|
||
} |
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
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
Oops, something went wrong.