mirror of
https://github.com/LittleTurtle2333/SimplicityTools.git
synced 2026-07-12 11:21:18 +08:00
重构大移动类型功能,使其自适应
This commit is contained in:
@@ -2,16 +2,18 @@ package com.lt2333.simplicitytools.hook.app.systemui
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.res.Resources
|
import android.content.res.Resources
|
||||||
|
import android.graphics.Typeface
|
||||||
|
import android.util.TypedValue
|
||||||
import android.view.Gravity
|
import android.view.Gravity
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.FrameLayout
|
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
import android.widget.LinearLayout
|
import android.widget.LinearLayout
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import cn.fkj233.ui.activity.dp2px
|
|
||||||
import com.lt2333.simplicitytools.util.hasEnable
|
import com.lt2333.simplicitytools.util.hasEnable
|
||||||
import com.lt2333.simplicitytools.util.hookAfterMethod
|
import com.lt2333.simplicitytools.util.hookAfterMethod
|
||||||
|
import com.lt2333.simplicitytools.util.hookBeforeMethod
|
||||||
import de.robv.android.xposed.IXposedHookLoadPackage
|
import de.robv.android.xposed.IXposedHookLoadPackage
|
||||||
|
import de.robv.android.xposed.XposedHelpers
|
||||||
import de.robv.android.xposed.callbacks.XC_LoadPackage
|
import de.robv.android.xposed.callbacks.XC_LoadPackage
|
||||||
|
|
||||||
|
|
||||||
@@ -25,58 +27,89 @@ class StatusBarBigMobileTypeIcon : IXposedHookLoadPackage {
|
|||||||
val StatusBarMobileView = it.thisObject as ViewGroup
|
val StatusBarMobileView = it.thisObject as ViewGroup
|
||||||
val context: Context = StatusBarMobileView.context
|
val context: Context = StatusBarMobileView.context
|
||||||
val res: Resources = context.resources
|
val res: Resources = context.resources
|
||||||
|
|
||||||
|
//获取组件
|
||||||
val mobile_container_left_ID: Int =
|
val mobile_container_left_ID: Int =
|
||||||
res.getIdentifier("mobile_container_left", "id", "com.android.systemui")
|
res.getIdentifier("mobile_container_left", "id", "com.android.systemui")
|
||||||
|
val mobile_container_left =
|
||||||
|
StatusBarMobileView.findViewById<ViewGroup>(mobile_container_left_ID)
|
||||||
|
|
||||||
|
val mobile_type_ID: Int =
|
||||||
|
res.getIdentifier("mobile_type", "id", "com.android.systemui")
|
||||||
|
val mobile_type = StatusBarMobileView.findViewById<TextView>(mobile_type_ID)
|
||||||
|
|
||||||
val mobile_left_mobile_inout_ID: Int = res.getIdentifier(
|
val mobile_left_mobile_inout_ID: Int = res.getIdentifier(
|
||||||
"mobile_left_mobile_inout",
|
"mobile_left_mobile_inout",
|
||||||
"id",
|
"id",
|
||||||
"com.android.systemui"
|
"com.android.systemui"
|
||||||
)
|
)
|
||||||
|
val mobile_left_mobile_inout =
|
||||||
|
StatusBarMobileView.findViewById<ImageView>(mobile_left_mobile_inout_ID)
|
||||||
|
|
||||||
|
|
||||||
|
//获取插入位置
|
||||||
val mobile_container_right_ID: Int = res.getIdentifier(
|
val mobile_container_right_ID: Int = res.getIdentifier(
|
||||||
"mobile_container_right",
|
"mobile_container_right",
|
||||||
"id",
|
"id",
|
||||||
"com.android.systemui"
|
"com.android.systemui"
|
||||||
)
|
)
|
||||||
val mobile_type_ID: Int =
|
|
||||||
res.getIdentifier("mobile_type", "id", "com.android.systemui")
|
|
||||||
val TextAppearance_StatusBar_Carrier_ID: Int = res.getIdentifier(
|
|
||||||
"TextAppearance.StatusBar.Carrier",
|
|
||||||
"style",
|
|
||||||
"com.android.systemui"
|
|
||||||
)
|
|
||||||
|
|
||||||
//获取mobile_container_left并在父布局中删除
|
|
||||||
val mobile_container_left =
|
|
||||||
StatusBarMobileView.findViewById<ViewGroup>(mobile_container_left_ID)
|
|
||||||
val mobile_container_left_fl =
|
|
||||||
mobile_container_left.layoutParams as LinearLayout.LayoutParams
|
|
||||||
(mobile_container_left.parent as ViewGroup).removeView(mobile_container_left)
|
|
||||||
//获取mobile_container_right的父布局,并在mobile_container_right前添加mobile_container_left
|
|
||||||
val mobile_container_right =
|
val mobile_container_right =
|
||||||
StatusBarMobileView.findViewById<ViewGroup>(mobile_container_right_ID)
|
StatusBarMobileView.findViewById<ViewGroup>(mobile_container_right_ID)
|
||||||
val RightParentLayout = mobile_container_right.parent as ViewGroup
|
val RightParentLayout = mobile_container_right.parent as ViewGroup
|
||||||
val mobile_container_right_Index =
|
val mobile_container_right_Index =
|
||||||
RightParentLayout.indexOfChild(mobile_container_left)
|
RightParentLayout.indexOfChild(mobile_container_right)
|
||||||
RightParentLayout.addView(
|
|
||||||
mobile_container_left,
|
//创建新布局
|
||||||
mobile_container_right_Index - 1
|
val newLinearLayoutLP = LinearLayout.LayoutParams(
|
||||||
|
LinearLayout.LayoutParams.WRAP_CONTENT,
|
||||||
|
LinearLayout.LayoutParams.MATCH_PARENT
|
||||||
)
|
)
|
||||||
mobile_container_left_fl.topMargin = dp2px(context, 1.5f)
|
val newLinearlayout = LinearLayout(context).also {
|
||||||
mobile_container_left.layoutParams = mobile_container_left_fl
|
it.layoutParams = newLinearLayoutLP
|
||||||
val mobile_type = StatusBarMobileView.findViewById<TextView>(mobile_type_ID)
|
it.id = mobile_container_left_ID
|
||||||
mobile_type.setTextAppearance(TextAppearance_StatusBar_Carrier_ID)
|
}
|
||||||
val mobile_type_fl = mobile_type.layoutParams as FrameLayout.LayoutParams
|
XposedHelpers.setObjectField(it.thisObject, "mMobileLeftContainer", newLinearlayout)
|
||||||
mobile_type_fl.width = dp2px(context, 25f)
|
RightParentLayout.addView(
|
||||||
mobile_type_fl.gravity = Gravity.CENTER or Gravity.START
|
newLinearlayout,
|
||||||
mobile_type.layoutParams = mobile_type_fl
|
mobile_container_right_Index
|
||||||
val mobile_left_mobile_inout =
|
)
|
||||||
StatusBarMobileView.findViewById<ImageView>(mobile_left_mobile_inout_ID)
|
|
||||||
val mobile_left_mobile_inout_fl =
|
//将组件插入新的布局
|
||||||
mobile_left_mobile_inout.layoutParams as FrameLayout.LayoutParams
|
(mobile_type.parent as ViewGroup).removeView(mobile_type)
|
||||||
mobile_left_mobile_inout_fl.width = dp2px(context, 8f)
|
(mobile_left_mobile_inout.parent as ViewGroup).removeView(mobile_left_mobile_inout)
|
||||||
mobile_left_mobile_inout_fl.marginStart = dp2px(context, 16f)
|
(mobile_container_left.parent as ViewGroup).removeView(mobile_container_left)
|
||||||
mobile_left_mobile_inout_fl.bottomMargin = dp2px(context, 3f)
|
|
||||||
mobile_left_mobile_inout.layoutParams = mobile_left_mobile_inout_fl
|
|
||||||
|
newLinearlayout.addView(mobile_type) //类型
|
||||||
|
val mobile_type_lp = LinearLayout.LayoutParams(
|
||||||
|
LinearLayout.LayoutParams.WRAP_CONTENT,
|
||||||
|
LinearLayout.LayoutParams.WRAP_CONTENT
|
||||||
|
).also {
|
||||||
|
it.gravity = Gravity.CENTER_VERTICAL
|
||||||
|
}
|
||||||
|
mobile_type.also {
|
||||||
|
it.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12.5F)
|
||||||
|
it.typeface = Typeface.DEFAULT_BOLD
|
||||||
|
it.layoutParams = mobile_type_lp
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
newLinearlayout.addView(mobile_left_mobile_inout) //箭头
|
||||||
|
val mobile_left_mobile_inout_lp = LinearLayout.LayoutParams(
|
||||||
|
LinearLayout.LayoutParams.WRAP_CONTENT,
|
||||||
|
LinearLayout.LayoutParams.MATCH_PARENT
|
||||||
|
)
|
||||||
|
mobile_left_mobile_inout.also {
|
||||||
|
it.layoutParams = mobile_left_mobile_inout_lp
|
||||||
|
}
|
||||||
|
|
||||||
|
//屏蔽更新布局
|
||||||
|
"com.android.systemui.statusbar.StatusBarMobileView".hookBeforeMethod(
|
||||||
|
lpparam.classLoader,
|
||||||
|
"updateMobileTypeLayout", String::class.java
|
||||||
|
) {
|
||||||
|
it.result = null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user