mirror of
				https://github.com/fankes/MIUINativeNotifyIcon.git
				synced 2025-10-26 15:39:21 +08:00 
			
		
		
		
	Added notify icon custom corner function
This commit is contained in:
		| @@ -36,6 +36,7 @@ object DataConst { | ||||
|     val ENABLE_NOTIFY_ICON_FIX_NOTIFY = PrefsData("_notify_icon_fix_notify", true) | ||||
|     val ENABLE_HOOK_STATUS_ICON_COUNT = PrefsData("_enable_hook_status_icon_count", true) | ||||
|     val ENABLE_NOTIFY_ICON_FIX_AUTO = PrefsData("_enable_notify_icon_fix_auto", true) | ||||
|     val NOTIFY_ICON_CORNER = PrefsData("_notify_icon_corner", 15) | ||||
|     val NOTIFY_ICON_DATAS = PrefsData("_notify_icon_datas", "") | ||||
|     val NOTIFY_ICON_FIX_AUTO_TIME = PrefsData("_notify_icon_fix_auto_time", "07:00") | ||||
|     val HOOK_STATUS_ICON_COUNT = PrefsData("_hook_status_icon_count", 5) | ||||
|   | ||||
| @@ -438,6 +438,9 @@ object SystemUIHooker : YukiBaseHooker() { | ||||
|             /** 旧版风格反色 */ | ||||
|             val oldStyle = if (context.isNotSystemInDarkMode) 0xFF707070.toInt() else Color.WHITE | ||||
|  | ||||
|             /** 通知图标边框圆角大小 */ | ||||
|             val iconCorner = prefs.get(DataConst.NOTIFY_ICON_CORNER) | ||||
|  | ||||
|             /** 通知图标原始颜色 */ | ||||
|             val iconColor = notifyInstance.notification.color | ||||
|  | ||||
| @@ -485,7 +488,8 @@ object SystemUIHooker : YukiBaseHooker() { | ||||
|                     /** Android 12 设置图标外圈颜色 */ | ||||
|                     if (isUseAndroid12Style && customIconColor != 0) | ||||
|                         background = DrawableBuilder() | ||||
|                             .rounded() | ||||
|                             .rectangle() | ||||
|                             .cornerRadius(iconCorner.dp(context)) | ||||
|                             .solidColor(if (context.isSystemInDarkMode) customIconColor.brighter else customIconColor) | ||||
|                             .build() | ||||
|                     /** 设置原生的背景边距 */ | ||||
| @@ -504,7 +508,8 @@ object SystemUIHooker : YukiBaseHooker() { | ||||
|                         (if (hasIconColor) iconColor else context.systemAccentColor).also { | ||||
|                             if (isUseAndroid12Style) | ||||
|                                 background = DrawableBuilder() | ||||
|                                     .rounded() | ||||
|                                     .rectangle() | ||||
|                                     .cornerRadius(iconCorner.dp(context)) | ||||
|                                     .solidColor(if (context.isSystemInDarkMode) it.brighter else it) | ||||
|                                     .build() | ||||
|                         } | ||||
|   | ||||
| @@ -26,6 +26,7 @@ package com.fankes.miui.notify.ui.activity | ||||
|  | ||||
| import android.content.ComponentName | ||||
| import android.content.pm.PackageManager | ||||
| import android.widget.SeekBar | ||||
| import androidx.core.view.isGone | ||||
| import androidx.core.view.isVisible | ||||
| import com.fankes.miui.notify.BuildConfig | ||||
| @@ -151,6 +152,8 @@ class MainActivity : BaseActivity<ActivityMainBinding>() { | ||||
|         binding.statusIconCountItem.isVisible = modulePrefs.get(DataConst.ENABLE_MODULE) | ||||
|         binding.notifyIconConfigItem.isVisible = modulePrefs.get(DataConst.ENABLE_MODULE) | ||||
|         binding.notifyIconFixButton.isVisible = modulePrefs.get(DataConst.ENABLE_NOTIFY_ICON_FIX) | ||||
|         binding.notifyIconCustomCornerItem.isVisible = modulePrefs.get(DataConst.ENABLE_NOTIFY_ICON_FIX) && | ||||
|                 modulePrefs.get(DataConst.ENABLE_NOTIFY_ICON_FORCE_APP_ICON).not() | ||||
|         binding.notifyIconForceAppIconItem.isVisible = modulePrefs.get(DataConst.ENABLE_NOTIFY_ICON_FIX) | ||||
|         binding.notifyIconFixNotifyItem.isVisible = modulePrefs.get(DataConst.ENABLE_NOTIFY_ICON_FIX) | ||||
|         binding.notifyIconAutoSyncItem.isVisible = modulePrefs.get(DataConst.ENABLE_NOTIFY_ICON_FIX) | ||||
| @@ -165,6 +168,8 @@ class MainActivity : BaseActivity<ActivityMainBinding>() { | ||||
|         binding.notifyIconForceAppIconSwitch.isChecked = modulePrefs.get(DataConst.ENABLE_NOTIFY_ICON_FORCE_APP_ICON) | ||||
|         binding.notifyIconFixNotifySwitch.isChecked = modulePrefs.get(DataConst.ENABLE_NOTIFY_ICON_FIX_NOTIFY) | ||||
|         binding.notifyIconAutoSyncSwitch.isChecked = modulePrefs.get(DataConst.ENABLE_NOTIFY_ICON_FIX_AUTO) | ||||
|         binding.notifyIconCustomCornerSeekbar.progress = modulePrefs.get(DataConst.NOTIFY_ICON_CORNER) | ||||
|         binding.notifyIconCustomCornerText.text = "${modulePrefs.get(DataConst.NOTIFY_ICON_CORNER)} dp" | ||||
|         binding.statusIconCountText.text = statusBarIconCount.toString() | ||||
|         binding.notifyIconAutoSyncText.text = notifyIconAutoSyncTime | ||||
|         binding.moduleEnableSwitch.setOnCheckedChangeListener { btn, b -> | ||||
| @@ -205,6 +210,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() { | ||||
|             if (btn.isPressed.not()) return@setOnCheckedChangeListener | ||||
|             modulePrefs.put(DataConst.ENABLE_NOTIFY_ICON_FIX, b) | ||||
|             binding.notifyIconFixButton.isVisible = b | ||||
|             binding.notifyIconCustomCornerItem.isVisible = b && modulePrefs.get(DataConst.ENABLE_NOTIFY_ICON_FORCE_APP_ICON).not() | ||||
|             binding.notifyIconForceAppIconItem.isVisible = b | ||||
|             binding.notifyIconFixNotifyItem.isVisible = b | ||||
|             binding.notifyIconAutoSyncItem.isVisible = b | ||||
| @@ -213,6 +219,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() { | ||||
|         binding.notifyIconForceAppIconSwitch.setOnCheckedChangeListener { btn, b -> | ||||
|             if (btn.isPressed.not()) return@setOnCheckedChangeListener | ||||
|             fun saveState() { | ||||
|                 binding.notifyIconCustomCornerItem.isVisible = b.not() | ||||
|                 modulePrefs.put(DataConst.ENABLE_NOTIFY_ICON_FORCE_APP_ICON, b) | ||||
|                 SystemUITool.refreshSystemUI(context = this) | ||||
|             } | ||||
| @@ -237,6 +244,18 @@ class MainActivity : BaseActivity<ActivityMainBinding>() { | ||||
|             binding.notifyIconAutoSyncChildItem.isVisible = b | ||||
|             SystemUITool.refreshSystemUI(context = this, isRefreshCacheOnly = true) | ||||
|         } | ||||
|         binding.notifyIconCustomCornerSeekbar.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { | ||||
|             override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) { | ||||
|                 binding.notifyIconCustomCornerText.text = "$progress dp" | ||||
|             } | ||||
|  | ||||
|             override fun onStopTrackingTouch(seekBar: SeekBar) { | ||||
|                 modulePrefs.put(DataConst.NOTIFY_ICON_CORNER, seekBar.progress) | ||||
|                 SystemUITool.refreshSystemUI(context = this@MainActivity) | ||||
|             } | ||||
|  | ||||
|             override fun onStartTrackingTouch(seekBar: SeekBar?) {} | ||||
|         }) | ||||
|         /** 通知图标优化名单按钮点击事件 */ | ||||
|         binding.notifyIconFixButton.setOnClickListener { navigate<ConfigureActivity>() } | ||||
|         /** 设置警告 */ | ||||
|   | ||||
| @@ -465,15 +465,13 @@ | ||||
|                 android:elevation="0dp" | ||||
|                 android:gravity="center" | ||||
|                 android:orientation="vertical" | ||||
|                 android:paddingLeft="10dp" | ||||
|                 android:paddingTop="15dp" | ||||
|                 android:paddingRight="10dp"> | ||||
|                 android:paddingTop="15dp"> | ||||
|  | ||||
|                 <LinearLayout | ||||
|                     android:layout_width="match_parent" | ||||
|                     android:layout_height="wrap_content" | ||||
|                     android:layout_marginLeft="5dp" | ||||
|                     android:layout_marginRight="5dp" | ||||
|                     android:layout_marginLeft="15dp" | ||||
|                     android:layout_marginRight="15dp" | ||||
|                     android:gravity="center|start"> | ||||
|  | ||||
|                     <ImageView | ||||
| @@ -496,8 +494,8 @@ | ||||
|                     android:id="@+id/notify_icon_fix_switch" | ||||
|                     android:layout_width="match_parent" | ||||
|                     android:layout_height="wrap_content" | ||||
|                     android:layout_marginLeft="5dp" | ||||
|                     android:layout_marginRight="5dp" | ||||
|                     android:layout_marginLeft="15dp" | ||||
|                     android:layout_marginRight="15dp" | ||||
|                     android:text="启用通知图标优化" | ||||
|                     android:textColor="@color/colorTextGray" | ||||
|                     android:textSize="15sp" /> | ||||
| @@ -506,8 +504,8 @@ | ||||
|                     android:id="@+id/notify_icon_fix_button" | ||||
|                     android:layout_width="match_parent" | ||||
|                     android:layout_height="wrap_content" | ||||
|                     android:layout_marginLeft="3dp" | ||||
|                     android:layout_marginRight="3dp" | ||||
|                     android:layout_marginLeft="13dp" | ||||
|                     android:layout_marginRight="13dp" | ||||
|                     android:layout_marginBottom="10dp" | ||||
|                     android:background="@drawable/bg_button_round" | ||||
|                     android:gravity="center" | ||||
| @@ -520,8 +518,8 @@ | ||||
|                 <TextView | ||||
|                     android:layout_width="match_parent" | ||||
|                     android:layout_height="wrap_content" | ||||
|                     android:layout_marginLeft="5dp" | ||||
|                     android:layout_marginRight="5dp" | ||||
|                     android:layout_marginLeft="15dp" | ||||
|                     android:layout_marginRight="15dp" | ||||
|                     android:layout_marginBottom="10dp" | ||||
|                     android:alpha="0.6" | ||||
|                     android:lineSpacingExtra="6dp" | ||||
| @@ -532,8 +530,8 @@ | ||||
|                 <TextView | ||||
|                     android:layout_width="match_parent" | ||||
|                     android:layout_height="wrap_content" | ||||
|                     android:layout_marginLeft="5dp" | ||||
|                     android:layout_marginRight="5dp" | ||||
|                     android:layout_marginLeft="15dp" | ||||
|                     android:layout_marginRight="15dp" | ||||
|                     android:layout_marginBottom="10dp" | ||||
|                     android:alpha="0.6" | ||||
|                     android:lineSpacingExtra="6dp" | ||||
| @@ -541,12 +539,91 @@ | ||||
|                     android:textColor="@color/colorTextDark" | ||||
|                     android:textSize="12sp" /> | ||||
|  | ||||
|                 <LinearLayout | ||||
|                     android:id="@+id/notify_icon_custom_corner_item" | ||||
|                     android:layout_width="match_parent" | ||||
|                     android:layout_height="wrap_content" | ||||
|                     android:layout_marginBottom="10dp" | ||||
|                     android:orientation="vertical"> | ||||
|  | ||||
|                     <TextView | ||||
|                         android:layout_width="match_parent" | ||||
|                         android:layout_height="30dp" | ||||
|                         android:layout_marginLeft="15dp" | ||||
|                         android:layout_marginRight="15dp" | ||||
|                         android:layout_marginBottom="5dp" | ||||
|                         android:gravity="center|start" | ||||
|                         android:text="调整通知栏中的图标边框圆角大小" | ||||
|                         android:textAllCaps="false" | ||||
|                         android:textColor="@color/colorTextGray" | ||||
|                         android:textSize="15sp" /> | ||||
|  | ||||
|                     <androidx.appcompat.widget.AppCompatSeekBar | ||||
|                         android:id="@+id/notify_icon_custom_corner_seekbar" | ||||
|                         android:layout_width="match_parent" | ||||
|                         android:layout_height="40dp" | ||||
|                         android:layout_marginTop="5dp" | ||||
|                         android:max="15" | ||||
|                         android:min="0" | ||||
|                         android:paddingLeft="5dp" | ||||
|                         android:paddingRight="5dp" | ||||
|                         android:progress="15" /> | ||||
|  | ||||
|                     <LinearLayout | ||||
|                         android:layout_width="match_parent" | ||||
|                         android:layout_height="wrap_content" | ||||
|                         android:layout_marginLeft="15dp" | ||||
|                         android:layout_marginRight="15dp" | ||||
|                         android:gravity="center" | ||||
|                         android:orientation="horizontal" | ||||
|                         android:paddingTop="5dp" | ||||
|                         android:paddingBottom="15dp"> | ||||
|  | ||||
|                         <TextView | ||||
|                             android:layout_width="wrap_content" | ||||
|                             android:layout_height="wrap_content" | ||||
|                             android:layout_marginEnd="5dp" | ||||
|                             android:alpha="0.75" | ||||
|                             android:ellipsize="end" | ||||
|                             android:gravity="center" | ||||
|                             android:maxWidth="100dp" | ||||
|                             android:singleLine="true" | ||||
|                             android:text="当前" | ||||
|                             android:textColor="@color/colorTextGray" | ||||
|                             android:textSize="13.5sp" /> | ||||
|  | ||||
|                         <TextView | ||||
|                             android:id="@+id/notify_icon_custom_corner_text" | ||||
|                             android:layout_width="wrap_content" | ||||
|                             android:layout_height="wrap_content" | ||||
|                             android:ellipsize="end" | ||||
|                             android:gravity="center" | ||||
|                             android:maxWidth="100dp" | ||||
|                             android:singleLine="true" | ||||
|                             android:text="15 dp" | ||||
|                             android:textColor="@color/colorTextGray" | ||||
|                             android:textSize="15sp" | ||||
|                             android:textStyle="bold" /> | ||||
|                     </LinearLayout> | ||||
|  | ||||
|                     <TextView | ||||
|                         android:layout_width="match_parent" | ||||
|                         android:layout_height="wrap_content" | ||||
|                         android:layout_marginLeft="15dp" | ||||
|                         android:layout_marginRight="15dp" | ||||
|                         android:alpha="0.6" | ||||
|                         android:lineSpacingExtra="6dp" | ||||
|                         android:text="你可以拖拽滑动条来调整通知栏中图标的边框圆角大小,仅支持 Android 12 风格以及 MIUI 经典样式的通知图标。" | ||||
|                         android:textColor="@color/colorTextDark" | ||||
|                         android:textSize="12sp" /> | ||||
|                 </LinearLayout> | ||||
|  | ||||
|                 <LinearLayout | ||||
|                     android:id="@+id/notify_icon_force_app_icon_item" | ||||
|                     android:layout_width="match_parent" | ||||
|                     android:layout_height="wrap_content" | ||||
|                     android:layout_marginLeft="5dp" | ||||
|                     android:layout_marginRight="5dp" | ||||
|                     android:layout_marginLeft="15dp" | ||||
|                     android:layout_marginRight="15dp" | ||||
|                     android:orientation="vertical"> | ||||
|  | ||||
|                     <com.fankes.miui.notify.ui.view.MaterialSwitch | ||||
| @@ -573,8 +650,8 @@ | ||||
|                     android:id="@+id/notify_icon_fix_notify_item" | ||||
|                     android:layout_width="match_parent" | ||||
|                     android:layout_height="wrap_content" | ||||
|                     android:layout_marginLeft="5dp" | ||||
|                     android:layout_marginRight="5dp" | ||||
|                     android:layout_marginLeft="15dp" | ||||
|                     android:layout_marginRight="15dp" | ||||
|                     android:orientation="vertical"> | ||||
|  | ||||
|                     <com.fankes.miui.notify.ui.view.MaterialSwitch | ||||
| @@ -601,8 +678,8 @@ | ||||
|                     android:id="@+id/notify_icon_auto_sync_item" | ||||
|                     android:layout_width="match_parent" | ||||
|                     android:layout_height="wrap_content" | ||||
|                     android:layout_marginLeft="5dp" | ||||
|                     android:layout_marginRight="5dp" | ||||
|                     android:layout_marginLeft="15dp" | ||||
|                     android:layout_marginRight="15dp" | ||||
|                     android:animateLayoutChanges="true" | ||||
|                     android:orientation="vertical"> | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user