From 2b352738f50483d86133fb7daa3d0a057841dc9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B9=8C=E5=A0=86=E5=B0=8F=E9=80=8F=E6=98=8E?= Date: Tue, 22 Mar 2022 20:15:15 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=E5=A4=A7=E7=A7=BB=E5=8A=A8?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E5=8A=9F=E8=83=BD=EF=BC=8C=E4=BD=BF=E5=85=B6?= =?UTF-8?q?=E8=87=AA=E9=80=82=E5=BA=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../systemui/StatusBarBigMobileTypeIcon.kt | 107 ++++++++++++------ 1 file changed, 70 insertions(+), 37 deletions(-) diff --git a/app/src/main/java/com/lt2333/simplicitytools/hook/app/systemui/StatusBarBigMobileTypeIcon.kt b/app/src/main/java/com/lt2333/simplicitytools/hook/app/systemui/StatusBarBigMobileTypeIcon.kt index d7104b00..78839fce 100644 --- a/app/src/main/java/com/lt2333/simplicitytools/hook/app/systemui/StatusBarBigMobileTypeIcon.kt +++ b/app/src/main/java/com/lt2333/simplicitytools/hook/app/systemui/StatusBarBigMobileTypeIcon.kt @@ -2,16 +2,18 @@ package com.lt2333.simplicitytools.hook.app.systemui import android.content.Context import android.content.res.Resources +import android.graphics.Typeface +import android.util.TypedValue import android.view.Gravity import android.view.ViewGroup -import android.widget.FrameLayout import android.widget.ImageView import android.widget.LinearLayout import android.widget.TextView -import cn.fkj233.ui.activity.dp2px import com.lt2333.simplicitytools.util.hasEnable import com.lt2333.simplicitytools.util.hookAfterMethod +import com.lt2333.simplicitytools.util.hookBeforeMethod import de.robv.android.xposed.IXposedHookLoadPackage +import de.robv.android.xposed.XposedHelpers import de.robv.android.xposed.callbacks.XC_LoadPackage @@ -25,58 +27,89 @@ class StatusBarBigMobileTypeIcon : IXposedHookLoadPackage { val StatusBarMobileView = it.thisObject as ViewGroup val context: Context = StatusBarMobileView.context val res: Resources = context.resources + + //获取组件 val mobile_container_left_ID: Int = res.getIdentifier("mobile_container_left", "id", "com.android.systemui") + val mobile_container_left = + StatusBarMobileView.findViewById(mobile_container_left_ID) + + val mobile_type_ID: Int = + res.getIdentifier("mobile_type", "id", "com.android.systemui") + val mobile_type = StatusBarMobileView.findViewById(mobile_type_ID) + val mobile_left_mobile_inout_ID: Int = res.getIdentifier( "mobile_left_mobile_inout", "id", "com.android.systemui" ) + val mobile_left_mobile_inout = + StatusBarMobileView.findViewById(mobile_left_mobile_inout_ID) + + + //获取插入位置 val mobile_container_right_ID: Int = res.getIdentifier( "mobile_container_right", "id", "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(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 = StatusBarMobileView.findViewById(mobile_container_right_ID) val RightParentLayout = mobile_container_right.parent as ViewGroup val mobile_container_right_Index = - RightParentLayout.indexOfChild(mobile_container_left) - RightParentLayout.addView( - mobile_container_left, - mobile_container_right_Index - 1 + RightParentLayout.indexOfChild(mobile_container_right) + + //创建新布局 + val newLinearLayoutLP = LinearLayout.LayoutParams( + LinearLayout.LayoutParams.WRAP_CONTENT, + LinearLayout.LayoutParams.MATCH_PARENT ) - mobile_container_left_fl.topMargin = dp2px(context, 1.5f) - mobile_container_left.layoutParams = mobile_container_left_fl - val mobile_type = StatusBarMobileView.findViewById(mobile_type_ID) - mobile_type.setTextAppearance(TextAppearance_StatusBar_Carrier_ID) - val mobile_type_fl = mobile_type.layoutParams as FrameLayout.LayoutParams - mobile_type_fl.width = dp2px(context, 25f) - mobile_type_fl.gravity = Gravity.CENTER or Gravity.START - mobile_type.layoutParams = mobile_type_fl - val mobile_left_mobile_inout = - StatusBarMobileView.findViewById(mobile_left_mobile_inout_ID) - val mobile_left_mobile_inout_fl = - mobile_left_mobile_inout.layoutParams as FrameLayout.LayoutParams - mobile_left_mobile_inout_fl.width = dp2px(context, 8f) - mobile_left_mobile_inout_fl.marginStart = dp2px(context, 16f) - mobile_left_mobile_inout_fl.bottomMargin = dp2px(context, 3f) - mobile_left_mobile_inout.layoutParams = mobile_left_mobile_inout_fl + val newLinearlayout = LinearLayout(context).also { + it.layoutParams = newLinearLayoutLP + it.id = mobile_container_left_ID + } + XposedHelpers.setObjectField(it.thisObject, "mMobileLeftContainer", newLinearlayout) + RightParentLayout.addView( + newLinearlayout, + mobile_container_right_Index + ) + + //将组件插入新的布局 + (mobile_type.parent as ViewGroup).removeView(mobile_type) + (mobile_left_mobile_inout.parent as ViewGroup).removeView(mobile_left_mobile_inout) + (mobile_container_left.parent as ViewGroup).removeView(mobile_container_left) + + + 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 + } } } }