mirror of
https://github.com/LittleTurtle2333/SimplicityTools.git
synced 2026-07-12 11:21:18 +08:00
Compare commits
9 Commits
4f20d364c6
...
3d2e315113
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3d2e315113 | ||
|
|
3fbfaa218f | ||
|
|
51759aa199 | ||
|
|
7449d6e890 | ||
|
|
1b625d07eb | ||
|
|
d47aa371ab | ||
|
|
dae0b60c40 | ||
|
|
74df408148 | ||
|
|
62d2666c41 |
@@ -19,6 +19,9 @@ object SystemUIHooker : YukiBaseHooker() {
|
|||||||
loadHooker(MaximumNumberOfNotificationIconsForT) //通知图标上限
|
loadHooker(MaximumNumberOfNotificationIconsForT) //通知图标上限
|
||||||
loadHooker(StatusBarNetworkSpeedRefreshSpeedForT) //状态栏网速秒刷新
|
loadHooker(StatusBarNetworkSpeedRefreshSpeedForT) //状态栏网速秒刷新
|
||||||
loadHooker(StatusBarTimeCustomizationForT) //状态栏时钟自定义
|
loadHooker(StatusBarTimeCustomizationForT) //状态栏时钟自定义
|
||||||
|
loadHooker(RemoveTheLeftSideOfTheLockScreenForT) //移除锁屏负一屏功能
|
||||||
|
loadHooker(RemoveLockScreenCameraForT) //移除锁屏相机功能
|
||||||
|
loadHooker(NotificationWeatherForT) //通知面板天气
|
||||||
}
|
}
|
||||||
|
|
||||||
Build.VERSION_CODES.S -> {
|
Build.VERSION_CODES.S -> {
|
||||||
|
|||||||
@@ -0,0 +1,202 @@
|
|||||||
|
package com.lt2333.simplicitytools.hooks.rules.t.systemui
|
||||||
|
|
||||||
|
import android.content.ComponentName
|
||||||
|
import android.content.Intent
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import android.widget.LinearLayout
|
||||||
|
import android.widget.TextView
|
||||||
|
import android.widget.Toast
|
||||||
|
import androidx.constraintlayout.widget.ConstraintLayout
|
||||||
|
import cn.fkj233.ui.activity.dp2px
|
||||||
|
import com.highcapable.yukihookapi.hook.entity.YukiBaseHooker
|
||||||
|
import com.highcapable.yukihookapi.hook.factory.constructor
|
||||||
|
import com.highcapable.yukihookapi.hook.factory.current
|
||||||
|
import com.highcapable.yukihookapi.hook.factory.toClass
|
||||||
|
import com.lt2333.simplicitytools.utils.SystemProperties
|
||||||
|
import com.lt2333.simplicitytools.utils.XSPUtils
|
||||||
|
import com.lt2333.simplicitytools.utils.hasEnable
|
||||||
|
import com.lt2333.simplicitytools.views.WeatherView
|
||||||
|
|
||||||
|
object NotificationWeatherForT : YukiBaseHooker() {
|
||||||
|
override fun onHook() = hasEnable("notification_weather") {
|
||||||
|
var mWeatherView: TextView? = null
|
||||||
|
var mConstraintLayout: ConstraintLayout? = null
|
||||||
|
val isDisplayCity = XSPUtils.getBoolean("notification_weather_city", false)
|
||||||
|
"com.android.systemui.qs.MiuiNotificationHeaderView".hook {
|
||||||
|
injectMember {
|
||||||
|
method { name = "onFinishInflate" }
|
||||||
|
afterHook {
|
||||||
|
val viewGroup = instance<ViewGroup>()
|
||||||
|
val context = viewGroup.context
|
||||||
|
|
||||||
|
// MIUI编译时间大于 2022-03-12 00:00:00 且为内测版
|
||||||
|
if (SystemProperties[context, "ro.build.date.utc"].toInt() >= 1647014400 &&
|
||||||
|
!SystemProperties[context, "ro.build.version.incremental"].endsWith("XM")
|
||||||
|
) {
|
||||||
|
//获取原组件
|
||||||
|
val bigTimeId =
|
||||||
|
context.resources.getIdentifier("big_time", "id", context.packageName)
|
||||||
|
val bigTime: TextView = viewGroup.findViewById(bigTimeId)
|
||||||
|
|
||||||
|
val dateTimeId =
|
||||||
|
context.resources.getIdentifier("date_time", "id", context.packageName)
|
||||||
|
val dateTime: TextView = viewGroup.findViewById(dateTimeId)
|
||||||
|
|
||||||
|
//创建新布局
|
||||||
|
val mConstraintLayoutLp = LinearLayout.LayoutParams(
|
||||||
|
LinearLayout.LayoutParams.MATCH_PARENT,
|
||||||
|
LinearLayout.LayoutParams.WRAP_CONTENT
|
||||||
|
).also {
|
||||||
|
it.topMargin = context.resources.getDimensionPixelSize(
|
||||||
|
context.resources.getIdentifier(
|
||||||
|
"qs_control_header_tiles_margin_top",
|
||||||
|
"dimen",
|
||||||
|
context.packageName
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
mConstraintLayout =
|
||||||
|
ConstraintLayout(context).also { it.layoutParams = mConstraintLayoutLp }
|
||||||
|
|
||||||
|
(bigTime.parent as ViewGroup).addView(mConstraintLayout, 0)
|
||||||
|
|
||||||
|
|
||||||
|
//从原布局中删除组件
|
||||||
|
(bigTime.parent as ViewGroup).removeView(bigTime)
|
||||||
|
(dateTime.parent as ViewGroup).removeView(dateTime)
|
||||||
|
|
||||||
|
|
||||||
|
//添加组件至新布局
|
||||||
|
mConstraintLayout!!.addView(bigTime)
|
||||||
|
mConstraintLayout!!.addView(dateTime)
|
||||||
|
|
||||||
|
//组件属性
|
||||||
|
|
||||||
|
val dateTimeLp = ConstraintLayout.LayoutParams(
|
||||||
|
ConstraintLayout.LayoutParams.WRAP_CONTENT,
|
||||||
|
ConstraintLayout.LayoutParams.WRAP_CONTENT
|
||||||
|
).also {
|
||||||
|
it.startToEnd = bigTimeId
|
||||||
|
it.bottomToBottom = 0
|
||||||
|
it.marginStart = context.resources.getDimensionPixelSize(
|
||||||
|
context.resources.getIdentifier(
|
||||||
|
"notification_panel_time_date_space",
|
||||||
|
"dimen",
|
||||||
|
context.packageName
|
||||||
|
)
|
||||||
|
)
|
||||||
|
it.bottomMargin = dp2px(context, 5f)
|
||||||
|
}
|
||||||
|
dateTime.layoutParams = dateTimeLp
|
||||||
|
|
||||||
|
|
||||||
|
//创建天气组件
|
||||||
|
mWeatherView = WeatherView(context, isDisplayCity).apply {
|
||||||
|
setTextAppearance(
|
||||||
|
context.resources.getIdentifier(
|
||||||
|
"TextAppearance.QSControl.Date",
|
||||||
|
"style",
|
||||||
|
context.packageName
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
}
|
||||||
|
mConstraintLayout!!.addView(mWeatherView)
|
||||||
|
|
||||||
|
val mweatherviewLp = ConstraintLayout.LayoutParams(
|
||||||
|
ConstraintLayout.LayoutParams.WRAP_CONTENT,
|
||||||
|
ConstraintLayout.LayoutParams.WRAP_CONTENT
|
||||||
|
).also {
|
||||||
|
it.startToEnd = bigTimeId
|
||||||
|
it.bottomToTop = dateTimeId
|
||||||
|
it.marginStart = context.resources.getDimensionPixelSize(
|
||||||
|
context.resources.getIdentifier(
|
||||||
|
"notification_panel_time_date_space",
|
||||||
|
"dimen",
|
||||||
|
context.packageName
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
(mWeatherView as WeatherView).layoutParams = mweatherviewLp
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
val layoutParam = "androidx.constraintlayout.widget.ConstraintLayout\$LayoutParams".toClass()
|
||||||
|
.constructor {
|
||||||
|
paramCount = 2
|
||||||
|
}.get().newInstance<ViewGroup.MarginLayoutParams>(
|
||||||
|
ViewGroup.LayoutParams.WRAP_CONTENT,
|
||||||
|
ViewGroup.LayoutParams.WRAP_CONTENT
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
layoutParam?.current()?.field { name = "bottomToTop" }?.set(context.resources.getIdentifier("date_time", "id", context.packageName))
|
||||||
|
layoutParam?.current()?.field { name = "startToEnd" }?.set(context.resources.getIdentifier("big_time", "id", context.packageName))
|
||||||
|
|
||||||
|
layoutParam?.marginStart = context.resources.getDimensionPixelSize(
|
||||||
|
context.resources.getIdentifier(
|
||||||
|
"notification_panel_time_date_space",
|
||||||
|
"dimen",
|
||||||
|
context.packageName
|
||||||
|
)
|
||||||
|
)
|
||||||
|
mWeatherView = WeatherView(context, isDisplayCity).apply {
|
||||||
|
setTextAppearance(
|
||||||
|
context.resources.getIdentifier(
|
||||||
|
"TextAppearance.QSControl.Date",
|
||||||
|
"style",
|
||||||
|
context.packageName
|
||||||
|
)
|
||||||
|
)
|
||||||
|
layoutParams = layoutParam
|
||||||
|
}
|
||||||
|
viewGroup.addView(mWeatherView)
|
||||||
|
}
|
||||||
|
|
||||||
|
(mWeatherView as WeatherView).setOnClickListener {
|
||||||
|
try {
|
||||||
|
val intent = Intent().apply {
|
||||||
|
flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||||
|
component = ComponentName(
|
||||||
|
"com.miui.weather2",
|
||||||
|
"com.miui.weather2.ActivityWeatherMain"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
context.startActivity(intent)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Toast.makeText(context, "启动失败", Toast.LENGTH_LONG).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
injectMember {
|
||||||
|
method { name = "updateLayout" }
|
||||||
|
afterHook {
|
||||||
|
val viewGroup = instance<ViewGroup>()
|
||||||
|
val context = viewGroup.context
|
||||||
|
val mOrientation = viewGroup.current().field { name = "mOrientation" }.int()
|
||||||
|
// MIUI编译时间大于 2022-03-12 00:00:00 且为内测版
|
||||||
|
if (SystemProperties[context, "ro.build.date.utc"].toInt() >= 1647014400 && !SystemProperties[context, "ro.build.version.incremental"].endsWith(
|
||||||
|
"DEV"
|
||||||
|
) && !SystemProperties[context, "ro.build.version.incremental"].endsWith("XM")
|
||||||
|
) {
|
||||||
|
if (mOrientation == 1) {
|
||||||
|
mConstraintLayout!!.visibility = View.VISIBLE
|
||||||
|
} else {
|
||||||
|
mConstraintLayout!!.visibility = View.GONE
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (mOrientation == 1) {
|
||||||
|
mWeatherView!!.visibility = View.VISIBLE
|
||||||
|
} else {
|
||||||
|
mWeatherView!!.visibility = View.GONE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package com.lt2333.simplicitytools.hooks.rules.t.systemui
|
||||||
|
|
||||||
|
import android.view.View
|
||||||
|
import android.widget.LinearLayout
|
||||||
|
import com.highcapable.yukihookapi.hook.entity.YukiBaseHooker
|
||||||
|
import com.highcapable.yukihookapi.hook.factory.current
|
||||||
|
import com.lt2333.simplicitytools.utils.hasEnable
|
||||||
|
|
||||||
|
object RemoveLockScreenCameraForT : YukiBaseHooker() {
|
||||||
|
override fun onHook() {
|
||||||
|
"com.android.systemui.statusbar.phone.KeyguardBottomAreaView".hook {
|
||||||
|
injectMember {
|
||||||
|
method { name = "onFinishInflate" }
|
||||||
|
afterHook {
|
||||||
|
hasEnable("remove_lock_screen_camera") {
|
||||||
|
instance.current().field { name = "mRightAffordanceViewLayout" }
|
||||||
|
.cast<LinearLayout>()?.visibility = View.GONE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package com.lt2333.simplicitytools.hooks.rules.t.systemui
|
||||||
|
|
||||||
|
import com.highcapable.yukihookapi.hook.entity.YukiBaseHooker
|
||||||
|
import com.lt2333.simplicitytools.utils.hasEnable
|
||||||
|
|
||||||
|
object RemoveTheLeftSideOfTheLockScreenForT : YukiBaseHooker() {
|
||||||
|
override fun onHook() {
|
||||||
|
"com.android.keyguard.negative.MiuiKeyguardMoveLeftViewContainer".hook {
|
||||||
|
injectMember {
|
||||||
|
method { name = "inflateLeftView" }
|
||||||
|
beforeHook {
|
||||||
|
hasEnable("remove_the_left_side_of_the_lock_screen") {
|
||||||
|
resultNull()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,12 +3,15 @@ package com.lt2333.simplicitytools.hooks.rules.t.systemui
|
|||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
|
import android.provider.Settings
|
||||||
import android.util.TypedValue
|
import android.util.TypedValue
|
||||||
|
import android.view.Gravity
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import com.highcapable.yukihookapi.hook.entity.YukiBaseHooker
|
import com.highcapable.yukihookapi.hook.entity.YukiBaseHooker
|
||||||
import com.highcapable.yukihookapi.hook.factory.current
|
import com.highcapable.yukihookapi.hook.factory.current
|
||||||
import com.lt2333.simplicitytools.utils.XSPUtils
|
import com.lt2333.simplicitytools.utils.XSPUtils
|
||||||
import java.lang.reflect.Method
|
import java.lang.reflect.Method
|
||||||
|
import java.text.SimpleDateFormat
|
||||||
import java.util.Calendar
|
import java.util.Calendar
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
import java.util.Timer
|
import java.util.Timer
|
||||||
@@ -42,7 +45,84 @@ object StatusBarTimeCustomizationForT : YukiBaseHooker() {
|
|||||||
override fun onHook() {
|
override fun onHook() {
|
||||||
when (getMode) {
|
when (getMode) {
|
||||||
//预设模式
|
//预设模式
|
||||||
1 -> {}
|
1 -> {
|
||||||
|
var c: Context? = null
|
||||||
|
|
||||||
|
"com.android.systemui.statusbar.views.MiuiClock".hook {
|
||||||
|
injectMember {
|
||||||
|
constructor {
|
||||||
|
paramCount = 3
|
||||||
|
}
|
||||||
|
afterHook {
|
||||||
|
try {
|
||||||
|
c = this.args[0] as Context
|
||||||
|
val textV = instance<TextView>()
|
||||||
|
if (textV.resources.getResourceEntryName(textV.id) != "clock") return@afterHook
|
||||||
|
textV.isSingleLine = false
|
||||||
|
if (isDoubleLine) {
|
||||||
|
str = "\n"
|
||||||
|
var clockDoubleLineSize = 7F
|
||||||
|
if (getClockDoubleSize != 0) {
|
||||||
|
clockDoubleLineSize = getClockDoubleSize.toFloat()
|
||||||
|
}
|
||||||
|
textV.setTextSize(
|
||||||
|
TypedValue.COMPLEX_UNIT_DIP,
|
||||||
|
clockDoubleLineSize
|
||||||
|
)
|
||||||
|
textV.setLineSpacing(0F, 0.8F)
|
||||||
|
} else {
|
||||||
|
if (getClockSize != 0) {
|
||||||
|
val clockSize = getClockSize.toFloat()
|
||||||
|
textV.setTextSize(TypedValue.COMPLEX_UNIT_DIP, clockSize)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val d: Method = textV.javaClass.getDeclaredMethod("updateTime")
|
||||||
|
val r = Runnable {
|
||||||
|
d.isAccessible = true
|
||||||
|
d.invoke(textV)
|
||||||
|
}
|
||||||
|
|
||||||
|
class T : TimerTask() {
|
||||||
|
override fun run() {
|
||||||
|
Handler(textV.context.mainLooper).post(r)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Timer().scheduleAtFixedRate(
|
||||||
|
T(), 1000 - System.currentTimeMillis() % 1000, 1000
|
||||||
|
)
|
||||||
|
|
||||||
|
if (isCenterAlign) {
|
||||||
|
try {
|
||||||
|
if (textV.resources.getResourceEntryName(textV.id) == "clock") {
|
||||||
|
c = this.args[0] as Context
|
||||||
|
textV.gravity = Gravity.CENTER
|
||||||
|
}
|
||||||
|
} catch (_: Exception) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (_: Exception) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
injectMember {
|
||||||
|
method { name = "updateTime" }
|
||||||
|
afterHook {
|
||||||
|
try {
|
||||||
|
val textV = instance<TextView>()
|
||||||
|
if (textV.resources.getResourceEntryName(textV.id) == "clock") {
|
||||||
|
val t = Settings.System.getString(
|
||||||
|
c!!.contentResolver, Settings.System.TIME_12_24
|
||||||
|
)
|
||||||
|
val is24 = t == "24"
|
||||||
|
nowTime = Calendar.getInstance().time
|
||||||
|
textV.text = getDate(c!!) + str + getTime(c!!, is24)
|
||||||
|
}
|
||||||
|
} catch (_: Exception) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
//极客模式
|
//极客模式
|
||||||
2 -> {
|
2 -> {
|
||||||
var c: Context? = null
|
var c: Context? = null
|
||||||
@@ -75,13 +155,20 @@ object StatusBarTimeCustomizationForT : YukiBaseHooker() {
|
|||||||
Timer().scheduleAtFixedRate(
|
Timer().scheduleAtFixedRate(
|
||||||
T(), 1000 - System.currentTimeMillis() % 1000, 1000
|
T(), 1000 - System.currentTimeMillis() % 1000, 1000
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (isGeekCenterAlign) {
|
||||||
|
try {
|
||||||
|
if (textV.resources.getResourceEntryName(textV.id) == "clock") {
|
||||||
|
c = this.args[0] as Context
|
||||||
|
textV.gravity = Gravity.CENTER
|
||||||
|
}
|
||||||
|
} catch (_: Exception) {
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (_: Exception) {
|
} catch (_: Exception) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
"com.android.systemui.statusbar.views.MiuiClock".hook {
|
|
||||||
injectMember {
|
injectMember {
|
||||||
method { name = "updateTime" }
|
method { name = "updateTime" }
|
||||||
beforeHook {
|
beforeHook {
|
||||||
@@ -92,9 +179,11 @@ object StatusBarTimeCustomizationForT : YukiBaseHooker() {
|
|||||||
val formatSb = StringBuilder(getGeekFormat.toString())
|
val formatSb = StringBuilder(getGeekFormat.toString())
|
||||||
|
|
||||||
val mMiuiStatusBarClockController =
|
val mMiuiStatusBarClockController =
|
||||||
textV.current().field { name = "mMiuiStatusBarClockController" }
|
textV.current()
|
||||||
|
.field { name = "mMiuiStatusBarClockController" }
|
||||||
val mCalendar =
|
val mCalendar =
|
||||||
mMiuiStatusBarClockController.current()?.method { name = "getCalendar" }?.call()
|
mMiuiStatusBarClockController.current()
|
||||||
|
?.method { name = "getCalendar" }?.call()
|
||||||
mCalendar?.current {
|
mCalendar?.current {
|
||||||
method {
|
method {
|
||||||
name = "setTimeInMillis"
|
name = "setTimeInMillis"
|
||||||
@@ -117,4 +206,145 @@ object StatusBarTimeCustomizationForT : YukiBaseHooker() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@SuppressLint("SimpleDateFormat")
|
||||||
|
private fun getDate(context: Context): String {
|
||||||
|
var datePattern = ""
|
||||||
|
val isZh = isZh(context)
|
||||||
|
|
||||||
|
if (isYear) {
|
||||||
|
if (isZh) {
|
||||||
|
datePattern += "YY年"
|
||||||
|
} else {
|
||||||
|
datePattern += "YY"
|
||||||
|
if (isMonth || isDay) datePattern += "/"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isMonth) {
|
||||||
|
if (isZh) {
|
||||||
|
datePattern += "M月"
|
||||||
|
} else {
|
||||||
|
datePattern += "M"
|
||||||
|
if (isDay) datePattern += "/"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isDay) {
|
||||||
|
datePattern += if (isZh) {
|
||||||
|
"d日"
|
||||||
|
} else {
|
||||||
|
"d"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isWeek) {
|
||||||
|
if (!isHideSpace) datePattern = "$datePattern "
|
||||||
|
datePattern += "E"
|
||||||
|
if (!isDoubleLine) {
|
||||||
|
if (!isHideSpace) datePattern = "$datePattern "
|
||||||
|
}
|
||||||
|
}
|
||||||
|
datePattern = SimpleDateFormat(datePattern).format(nowTime)
|
||||||
|
return datePattern
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressLint("SimpleDateFormat")
|
||||||
|
private fun getTime(context: Context, t: Boolean): String {
|
||||||
|
var timePattern = ""
|
||||||
|
val isZh = isZh(context)
|
||||||
|
timePattern += if (t) "HH:mm" else "h:mm"
|
||||||
|
if (isSecond) timePattern += ":ss"
|
||||||
|
timePattern = SimpleDateFormat(timePattern).format(nowTime)
|
||||||
|
if (isZh) timePattern = getPeriod(isZh) + timePattern else timePattern += getPeriod(isZh)
|
||||||
|
timePattern = getDoubleHour() + timePattern
|
||||||
|
return timePattern
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressLint("SimpleDateFormat")
|
||||||
|
private fun getPeriod(isZh: Boolean): String {
|
||||||
|
var period = ""
|
||||||
|
if (isPeriod) {
|
||||||
|
if (isZh) {
|
||||||
|
when (SimpleDateFormat("HH").format(nowTime)) {
|
||||||
|
"00", "01", "02", "03", "04", "05" -> {
|
||||||
|
period = "凌晨"
|
||||||
|
}
|
||||||
|
"06", "07", "08", "09", "10", "11" -> {
|
||||||
|
period = "上午"
|
||||||
|
}
|
||||||
|
"12" -> {
|
||||||
|
period = "中午"
|
||||||
|
}
|
||||||
|
"13", "14", "15", "16", "17" -> {
|
||||||
|
period = "下午"
|
||||||
|
}
|
||||||
|
"18" -> {
|
||||||
|
period = "傍晚"
|
||||||
|
}
|
||||||
|
"19", "20", "21", "22", "23" -> {
|
||||||
|
period = "晚上"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
period = SimpleDateFormat("a").format(nowTime)
|
||||||
|
if (!isHideSpace) {
|
||||||
|
period = " $period"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return period
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressLint("SimpleDateFormat")
|
||||||
|
private fun getDoubleHour(): String {
|
||||||
|
var doubleHour = ""
|
||||||
|
if (isDoubleHour) {
|
||||||
|
when (SimpleDateFormat("HH").format(nowTime)) {
|
||||||
|
"23", "00" -> {
|
||||||
|
doubleHour = "子时"
|
||||||
|
}
|
||||||
|
"01", "02" -> {
|
||||||
|
doubleHour = "丑时"
|
||||||
|
}
|
||||||
|
"03", "04" -> {
|
||||||
|
doubleHour = "寅时"
|
||||||
|
}
|
||||||
|
"05", "06" -> {
|
||||||
|
doubleHour = "卯时"
|
||||||
|
}
|
||||||
|
"07", "08" -> {
|
||||||
|
doubleHour = "辰时"
|
||||||
|
}
|
||||||
|
"09", "10" -> {
|
||||||
|
doubleHour = "巳时"
|
||||||
|
}
|
||||||
|
"11", "12" -> {
|
||||||
|
doubleHour = "午时"
|
||||||
|
}
|
||||||
|
"13", "14" -> {
|
||||||
|
doubleHour = "未时"
|
||||||
|
}
|
||||||
|
"15", "16" -> {
|
||||||
|
doubleHour = "申时"
|
||||||
|
}
|
||||||
|
"17", "18" -> {
|
||||||
|
doubleHour = "酉时"
|
||||||
|
}
|
||||||
|
"19", "20" -> {
|
||||||
|
doubleHour = "戌时"
|
||||||
|
}
|
||||||
|
"21", "22" -> {
|
||||||
|
doubleHour = "亥时"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!isHideSpace) {
|
||||||
|
doubleHour += " "
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return doubleHour
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun isZh(context: Context): Boolean {
|
||||||
|
val locale = context.resources.configuration.locale
|
||||||
|
val language = locale.language
|
||||||
|
return language.endsWith("zh")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package com.lt2333.simplicitytools.utils
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
|
import android.content.Context
|
||||||
|
|
||||||
|
object SystemProperties {
|
||||||
|
@SuppressLint("PrivateApi")
|
||||||
|
operator fun get(context: Context, key: String?): String {
|
||||||
|
var ret = ""
|
||||||
|
try {
|
||||||
|
val cl = context.classLoader
|
||||||
|
val systemProperties = cl.loadClass("android.os.SystemProperties")
|
||||||
|
//参数类型
|
||||||
|
val paramTypes: Array<Class<*>?> = arrayOfNulls(1)
|
||||||
|
paramTypes[0] = String::class.java
|
||||||
|
val get = systemProperties.getMethod("get", *paramTypes)
|
||||||
|
//参数
|
||||||
|
val params = arrayOfNulls<Any>(1)
|
||||||
|
params[0] = key
|
||||||
|
ret = get.invoke(systemProperties, *params) as String
|
||||||
|
} catch (iAE: IllegalArgumentException) {
|
||||||
|
throw iAE
|
||||||
|
} catch (e: Exception) {
|
||||||
|
ret = ""
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,98 @@
|
|||||||
|
package com.lt2333.simplicitytools.views
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
|
import android.content.ComponentName
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.database.ContentObserver
|
||||||
|
import android.net.Uri
|
||||||
|
import android.os.Handler
|
||||||
|
import android.os.Looper
|
||||||
|
import android.os.Message
|
||||||
|
import android.text.TextUtils
|
||||||
|
import android.widget.Toast
|
||||||
|
|
||||||
|
@SuppressLint("ViewConstructor", "SetTextI18n")
|
||||||
|
class WeatherData(val context: Context?, private val showCity: Boolean) {
|
||||||
|
|
||||||
|
private val mContext: Context
|
||||||
|
private val WEATHER_URI = Uri.parse("content://weather/weather")
|
||||||
|
private val mHandler: Handler
|
||||||
|
private val mWeatherObserver: ContentObserver?
|
||||||
|
private val mWeatherRunnable: WeatherRunnable
|
||||||
|
var weatherData: String = "\n"
|
||||||
|
var callBacks: () -> Unit = {}
|
||||||
|
|
||||||
|
init {
|
||||||
|
mHandler =
|
||||||
|
object : Handler(Looper.getMainLooper()) {
|
||||||
|
override fun handleMessage(message: Message) {
|
||||||
|
val str = message.obj as String
|
||||||
|
weatherData = if (TextUtils.isEmpty(str)) "\n" else "$str\n"
|
||||||
|
callBacks()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mWeatherObserver = WeatherContentObserver(mHandler)
|
||||||
|
mContext = context!!
|
||||||
|
mWeatherRunnable = WeatherRunnable()
|
||||||
|
context.contentResolver.registerContentObserver(WEATHER_URI, true, mWeatherObserver)
|
||||||
|
updateWeatherInfo()
|
||||||
|
}
|
||||||
|
|
||||||
|
private inner class WeatherContentObserver(handler: Handler?) : ContentObserver(handler) {
|
||||||
|
override fun onChange(z: Boolean) {
|
||||||
|
updateWeatherInfo()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inner class WeatherRunnable : Runnable {
|
||||||
|
override fun run() {
|
||||||
|
var str = ""
|
||||||
|
try {
|
||||||
|
val query = mContext.contentResolver.query(WEATHER_URI, null, null, null, null)
|
||||||
|
if (query != null) {
|
||||||
|
if (query.moveToFirst()) {
|
||||||
|
str = if (showCity) {
|
||||||
|
query.getString(query.getColumnIndexOrThrow("city_name")) + " " + query.getString(query.getColumnIndexOrThrow("description")) + " " + query.getString(query.getColumnIndexOrThrow("temperature"))
|
||||||
|
} else {
|
||||||
|
query.getString(query.getColumnIndexOrThrow("description")) + " " + query.getString(query.getColumnIndexOrThrow("temperature"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
query.close()
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
|
||||||
|
}
|
||||||
|
val obtainMessage2 = mHandler.obtainMessage()
|
||||||
|
obtainMessage2.what = 100
|
||||||
|
obtainMessage2.obj = str
|
||||||
|
mHandler.sendMessage(obtainMessage2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun updateWeatherInfo() {
|
||||||
|
mHandler.removeCallbacks(mWeatherRunnable)
|
||||||
|
mHandler.postDelayed(mWeatherRunnable, 200)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onDetachedFromWindow() {
|
||||||
|
if (mWeatherObserver != null) {
|
||||||
|
mContext.contentResolver.unregisterContentObserver(mWeatherObserver)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun startWeatherApp() {
|
||||||
|
try {
|
||||||
|
val intent = Intent().apply {
|
||||||
|
flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||||
|
component = ComponentName(
|
||||||
|
"com.miui.weather2",
|
||||||
|
"com.miui.weather2.ActivityWeatherMain"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
mContext.startActivity(intent)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Toast.makeText(context, "启动失败", Toast.LENGTH_LONG).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
package com.lt2333.simplicitytools.views
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
|
import android.content.Context
|
||||||
|
import android.database.ContentObserver
|
||||||
|
import android.net.Uri
|
||||||
|
import android.os.Handler
|
||||||
|
import android.os.Looper
|
||||||
|
import android.os.Message
|
||||||
|
import android.text.TextUtils
|
||||||
|
import android.widget.TextView
|
||||||
|
|
||||||
|
@SuppressLint("ViewConstructor")
|
||||||
|
class WeatherView(context: Context?, private val showCity: Boolean) : TextView(context) {
|
||||||
|
|
||||||
|
private val mContext: Context
|
||||||
|
private val weatherUri = Uri.parse("content://weather/weather")
|
||||||
|
private val mHandler: Handler
|
||||||
|
private val mWeatherObserver: ContentObserver?
|
||||||
|
private val mWeatherRunnable: WeatherRunnable
|
||||||
|
|
||||||
|
init {
|
||||||
|
mHandler =
|
||||||
|
object : Handler(Looper.getMainLooper()) {
|
||||||
|
override fun handleMessage(message: Message) {
|
||||||
|
val str = message.obj as String
|
||||||
|
this@WeatherView.text = if (TextUtils.isEmpty(str)) " " else str
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mWeatherObserver = WeatherContentObserver(mHandler)
|
||||||
|
mContext = context!!
|
||||||
|
mWeatherRunnable = WeatherRunnable()
|
||||||
|
context.contentResolver.registerContentObserver(weatherUri, true, mWeatherObserver)
|
||||||
|
updateWeatherInfo()
|
||||||
|
}
|
||||||
|
|
||||||
|
private inner class WeatherContentObserver(handler: Handler?) : ContentObserver(handler) {
|
||||||
|
override fun onChange(z: Boolean) {
|
||||||
|
updateWeatherInfo()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inner class WeatherRunnable : Runnable {
|
||||||
|
override fun run() {
|
||||||
|
var str = ""
|
||||||
|
try {
|
||||||
|
val query = mContext.contentResolver.query(weatherUri, null, null, null, null)
|
||||||
|
if (query != null) {
|
||||||
|
if (query.moveToFirst()) {
|
||||||
|
str = if (showCity) {
|
||||||
|
query.getString(query.getColumnIndexOrThrow("city_name")) + " " + query.getString(query.getColumnIndexOrThrow("description")) + " " + query.getString(query.getColumnIndexOrThrow("temperature"))
|
||||||
|
} else {
|
||||||
|
query.getString(query.getColumnIndexOrThrow("description")) + " " + query.getString(query.getColumnIndexOrThrow("temperature"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
query.close()
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
|
||||||
|
}
|
||||||
|
val obtainMessage2 = mHandler.obtainMessage()
|
||||||
|
obtainMessage2.what = 100
|
||||||
|
obtainMessage2.obj = str
|
||||||
|
mHandler.sendMessage(obtainMessage2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun updateWeatherInfo() {
|
||||||
|
mHandler.removeCallbacks(mWeatherRunnable)
|
||||||
|
mHandler.postDelayed(mWeatherRunnable, 200)
|
||||||
|
}
|
||||||
|
|
||||||
|
public override fun onDetachedFromWindow() {
|
||||||
|
super.onDetachedFromWindow()
|
||||||
|
if (mWeatherObserver != null) {
|
||||||
|
mContext.contentResolver.unregisterContentObserver(mWeatherObserver)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user