Skip to content

Commit 4cd01e6

Browse files
committed
1.0.2
支援辨識并隱藏系統應用
1 parent 72dd0a3 commit 4cd01e6

File tree

15 files changed

+92
-9
lines changed

15 files changed

+92
-9
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
.externalNativeBuild
99
.cxx
1010
local.properties
11-
app/release
11+
.\app\release

app/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ android {
1212
minSdk 26
1313
targetSdk 33
1414
versionCode 1
15-
versionName "1.0.1"
15+
versionName "1.0.2"
1616

1717
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1818
}

app/src/main/java/com/happymax/fcmpushviewer/AppInfo.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ package com.happymax.fcmpushviewer
22

33
import android.graphics.drawable.Drawable
44

5-
class AppInfo(val appName:String, val packageName:String, val icon:Drawable?) {
5+
class AppInfo(val appName:String, val packageName:String, val icon:Drawable?, val systemApp:Boolean) {
66
}

app/src/main/java/com/happymax/fcmpushviewer/AppInfoListAdapter.kt

+5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class AppInfoListAdapter(val list: List<AppInfo>) :
1717
val appIconImageView: ImageView = view.findViewById(R.id.AppIconImageView)
1818
val appNameTextView: TextView = view.findViewById(R.id.AppNameTextView)
1919
val packageNameTextView: TextView = view.findViewById(R.id.PackageNameTextView)
20+
val AndroidIcon:ImageView = view.findViewById(R.id.AndroidIcon)
2021
}
2122

2223
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
@@ -46,6 +47,10 @@ class AppInfoListAdapter(val list: List<AppInfo>) :
4647
holder.appNameTextView.text = appInfo.appName
4748
holder.packageNameTextView.text = appInfo.packageName
4849
holder.appIconImageView.setImageDrawable(appInfo.icon)
50+
if(appInfo.systemApp)
51+
holder.AndroidIcon.visibility = View.VISIBLE
52+
else
53+
holder.AndroidIcon.visibility = View.INVISIBLE
4954
}
5055

5156
override fun getItemCount(): Int {

app/src/main/java/com/happymax/fcmpushviewer/MainActivity.kt

+46-6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package com.happymax.fcmpushviewer
33
import android.content.ComponentName
44
import android.content.Context
55
import android.content.Intent
6+
import android.content.SharedPreferences
7+
import android.content.pm.ApplicationInfo
68
import android.content.pm.PackageManager
79
import android.graphics.drawable.Drawable
810
import android.os.Bundle
@@ -26,21 +28,26 @@ class MainActivity : AppCompatActivity() {
2628
private lateinit var mSearchView: SearchView
2729
private lateinit var recyclerView: RecyclerView
2830
private lateinit var swipeRefresh: SwipeRefreshLayout
31+
private lateinit var sharedPreferences: SharedPreferences
2932
private val appList = ArrayList<AppInfo>()
33+
private var hideSystemApp:Boolean = false
3034

3135
override fun onCreate(savedInstanceState: Bundle?) {
3236
super.onCreate(savedInstanceState)
3337
setContentView(R.layout.activity_main)
38+
sharedPreferences = getSharedPreferences("settings", Context.MODE_PRIVATE)
3439
val toolbar: Toolbar = findViewById(R.id.toolBar)
3540
setSupportActionBar(toolbar)
3641
recyclerView = findViewById<RecyclerView>(R.id.recyclerView)
3742

3843
swipeRefresh = findViewById<SwipeRefreshLayout>(R.id.swipeRefresh)
3944
swipeRefresh.setColorSchemeResources(R.color.purple_500)
4045
swipeRefresh.setOnRefreshListener {
41-
getAppList()
46+
getAppList(hideSystemApp)
4247
}
43-
getAppList()
48+
49+
hideSystemApp = sharedPreferences.getBoolean("HideSystemApp", false)
50+
getAppList(hideSystemApp)
4451
}
4552

4653
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
@@ -98,7 +105,33 @@ class MainActivity : AppCompatActivity() {
98105
})
99106

100107
}
101-
108+
val checkItem = menu?.findItem(R.id.HideSystemApp)
109+
if(checkItem != null){
110+
hideSystemApp = sharedPreferences.getBoolean("HideSystemApp", false)
111+
checkItem.isChecked = hideSystemApp
112+
checkItem.setOnMenuItemClickListener(object : MenuItem.OnMenuItemClickListener{
113+
override fun onMenuItemClick(item: MenuItem): Boolean {
114+
if(!item.isChecked){
115+
//Hide System App
116+
getAppList(true)
117+
hideSystemApp = true
118+
val editor = sharedPreferences.edit()
119+
editor.putBoolean("HideSystemApp", true)
120+
editor.apply()
121+
item.isChecked = true
122+
}
123+
else{
124+
getAppList(false)
125+
hideSystemApp = false
126+
val editor = sharedPreferences.edit()
127+
editor.putBoolean("HideSystemApp", false)
128+
editor.apply()
129+
item.isChecked = false
130+
}
131+
return true;
132+
}
133+
})
134+
}
102135
return true
103136
}
104137

@@ -117,6 +150,9 @@ class MainActivity : AppCompatActivity() {
117150
intent.setComponent(comp)
118151
startActivity(intent)
119152
}
153+
R.id.HideSystemApp -> {
154+
155+
}
120156
}
121157
return true
122158
}
@@ -133,7 +169,7 @@ class MainActivity : AppCompatActivity() {
133169
}
134170
}
135171

136-
private fun getAppList(){
172+
private fun getAppList(hideSystemApp:Boolean = false){
137173
appList.clear()
138174

139175
thread {
@@ -145,8 +181,12 @@ class MainActivity : AppCompatActivity() {
145181
val appName = packageInfo.applicationInfo.loadLabel(packageManager).toString()
146182
val packageName = packageInfo.packageName
147183
var icon:Drawable? = packageInfo.applicationInfo.loadIcon(packageManager);
148-
val appInfo = AppInfo(appName, packageName, icon)
149-
appList.add(appInfo)
184+
val isSystemApp = (packageInfo.applicationInfo.flags and ApplicationInfo.FLAG_SYSTEM) != 0
185+
if(!(hideSystemApp && isSystemApp)){
186+
val appInfo = AppInfo(appName, packageName, icon, isSystemApp)
187+
appList.add(appInfo)
188+
}
189+
150190
break
151191
}
152192
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<vector android:autoMirrored="true" android:height="24dp"
2+
android:tint="@color/foreground" android:viewportHeight="24"
3+
android:viewportWidth="24" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
4+
<path android:fillColor="@color/foreground" android:pathData="M17.6,9.48l1.84,-3.18c0.16,-0.31 0.04,-0.69 -0.26,-0.85c-0.29,-0.15 -0.65,-0.06 -0.83,0.22l-1.88,3.24c-2.86,-1.21 -6.08,-1.21 -8.94,0L5.65,5.67c-0.19,-0.29 -0.58,-0.38 -0.87,-0.2C4.5,5.65 4.41,6.01 4.56,6.3L6.4,9.48C3.3,11.25 1.28,14.44 1,18h22C22.72,14.44 20.7,11.25 17.6,9.48zM7,15.25c-0.69,0 -1.25,-0.56 -1.25,-1.25c0,-0.69 0.56,-1.25 1.25,-1.25S8.25,13.31 8.25,14C8.25,14.69 7.69,15.25 7,15.25zM17,15.25c-0.69,0 -1.25,-0.56 -1.25,-1.25c0,-0.69 0.56,-1.25 1.25,-1.25s1.25,0.56 1.25,1.25C18.25,14.69 17.69,15.25 17,15.25z"/>
5+
</vector>

app/src/main/res/layout/applist_item.xml

+10
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@
4141
android:textSize="12sp"
4242
app:layout_constraintStart_toEndOf="@+id/AppIconImageView"
4343
app:layout_constraintTop_toBottomOf="@+id/AppNameTextView" />
44+
45+
<ImageView
46+
android:id="@+id/AndroidIcon"
47+
android:src="@drawable/baseline_android"
48+
android:layout_width="25dp"
49+
android:layout_height="25dp"
50+
app:layout_constraintEnd_toEndOf="parent"
51+
app:layout_constraintTop_toTopOf="parent"
52+
android:layout_marginHorizontal="10dp"
53+
android:layout_marginVertical="4dp" />
4454
</androidx.constraintlayout.widget.ConstraintLayout>
4555

4656
</com.google.android.material.card.MaterialCardView>

app/src/main/res/menu/activity_main_toolbar.xml

+6
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,10 @@
1616
android:icon="@drawable/baseline_cloud_sync"
1717
android:title="@string/toolbar_openGcmDiagnostics"
1818
app:showAsAction="never" />
19+
<item
20+
android:id="@+id/HideSystemApp"
21+
android:checkable="true"
22+
android:icon="@drawable/baseline_android"
23+
android:title="@string/toolbar_hideSystemApp"
24+
app:showAsAction="never" />
1925
</menu>
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<color name="purple_200">#FFBB86FC</color>
4+
<color name="purple_500">#FF6200EE</color>
5+
<color name="purple_700">#FF3700B3</color>
6+
<color name="teal_200">#FF03DAC5</color>
7+
<color name="teal_700">#FF018786</color>
8+
<color name="black">#FF000000</color>
9+
<color name="white">#FFFFFFFF</color>
10+
<color name="foreground">#FFFFFFFF</color>
11+
</resources>

app/src/main/res/values-zh-rCN/strings.xml

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<string name="toolbar_search">搜索</string>
55
<string name="toolbar_help">帮助</string>
66
<string name="toolbar_openGcmDiagnostics">打开FCM诊断</string>
7+
<string name="toolbar_hideSystemApp">隐藏系统应用</string>
78
<string name="shortcut_shortlabel_GcmDiagnostics">FCM</string>
89
<string name="shortcut_longlabel_GcmDiagnostics">FCM诊断</string>
910
<string name="shortcut_disable_GcmDiagnostics">FCM不可用</string>

app/src/main/res/values-zh-rHK/strings.xml

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<string name="toolbar_search">搜索</string>
55
<string name="toolbar_help">幫助</string>
66
<string name="toolbar_openGcmDiagnostics">打開FCM診斷</string>
7+
<string name="toolbar_hideSystemApp">隱藏系統應用</string>
78
<string name="shortcut_shortlabel_GcmDiagnostics">FCM</string>
89
<string name="shortcut_longlabel_GcmDiagnostics">FCM診斷</string>
910
<string name="shortcut_disable_GcmDiagnostics">FCM不可用</string>

app/src/main/res/values-zh-rMO/strings.xml

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<string name="toolbar_search">搜索</string>
55
<string name="toolbar_help">幫助</string>
66
<string name="toolbar_openGcmDiagnostics">打開FCM診斷</string>
7+
<string name="toolbar_hideSystemApp">隱藏系統應用</string>
78
<string name="shortcut_shortlabel_GcmDiagnostics">FCM</string>
89
<string name="shortcut_longlabel_GcmDiagnostics">FCM診斷</string>
910
<string name="shortcut_disable_GcmDiagnostics">FCM不可用</string>

app/src/main/res/values-zh-rTW/strings.xml

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<string name="toolbar_search">搜索</string>
55
<string name="toolbar_help">幫助</string>
66
<string name="toolbar_openGcmDiagnostics">打開FCM診斷</string>
7+
<string name="toolbar_hideSystemApp">隱藏系統應用</string>
78
<string name="shortcut_shortlabel_GcmDiagnostics">FCM</string>
89
<string name="shortcut_longlabel_GcmDiagnostics">FCM診斷</string>
910
<string name="shortcut_disable_GcmDiagnostics">FCM不可用</string>

app/src/main/res/values/colors.xml

+1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@
77
<color name="teal_700">#FF018786</color>
88
<color name="black">#FF000000</color>
99
<color name="white">#FFFFFFFF</color>
10+
<color name="foreground">#FF000000</color>
1011
</resources>

app/src/main/res/values/strings.xml

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<string name="toolbar_search">Search</string>
44
<string name="toolbar_help">Help</string>
55
<string name="toolbar_openGcmDiagnostics">FCM Diagnostics</string>
6+
<string name="toolbar_hideSystemApp">Hide System App</string>
67
<string name="shortcut_shortlabel_GcmDiagnostics">FCM</string>
78
<string name="shortcut_longlabel_GcmDiagnostics">FCM Diagnostics</string>
89
<string name="shortcut_disable_GcmDiagnostics">FCM Unavailable</string>

0 commit comments

Comments
 (0)