Quellcode durchsuchen

1.添加一键加速(当前只有x505f测试有效)功能。

master
wangwanlei vor 10 Monaten
Ursprung
Commit
a3d65bb7a5
1 geänderte Dateien mit 21 neuen und 2 gelöschten Zeilen
  1. 21
    2
      app/src/main/java/com/xhly/manageapp/AppAdapter.kt

+ 21
- 2
app/src/main/java/com/xhly/manageapp/AppAdapter.kt Datei anzeigen

@@ -1,10 +1,16 @@
1 1
 package com.xhly.manageapp
2 2
 
3
+import android.annotation.SuppressLint
4
+import android.app.ActivityManager
3 5
 import android.content.Context
4 6
 import android.view.LayoutInflater
5 7
 import android.view.ViewGroup
8
+import android.widget.Toast
9
+import androidx.appcompat.content.res.AppCompatResources
6 10
 import androidx.recyclerview.widget.RecyclerView
11
+import com.hjq.toast.Toaster
7 12
 import com.xhly.corelib.bean.AppInfo
13
+import com.xhly.corelib.utils.LogShow
8 14
 import com.xhly.manageapp.databinding.ItemAppBinding
9 15
 import java.util.Calendar
10 16
 
@@ -21,16 +27,29 @@ class AppAdapter(var context: Context, var data: ArrayList<AppInfo>) :
21 27
         return data.size+2
22 28
     }
23 29
 
30
+
24 31
     override fun onBindViewHolder(holder: AppViewHolder, position: Int) {
25 32
         if (position==data.size){
26
-            context.resources.getDrawable(R.drawable.icon_speed,null)
33
+            AppCompatResources.getDrawable(context,R.drawable.icon_speed)
27 34
                 ?.let { holder.mBinding.itemCv.setImageDrawable(it) }
28 35
             holder.mBinding.itemCv.setText(context.getString(R.string.speed))
29 36
             holder.mBinding.itemCv.setOnClickListener {
37
+              try {
38
+                  val service : ActivityManager = context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
39
+                  val runningAppProcesses = service.runningAppProcesses
40
+                  runningAppProcesses.forEach {process->
41
+                      LogShow("当前运行应用名称"+process.processName+"|||"+process?.importanceReasonComponent?.packageName)
42
+                      data.filter { it.packageName.equals(process.processName) }.forEach {
43
+                          ManageApplication.killApplicationProcess(it.packageName)
44
+                      }
45
+                  }
46
+                  Toaster.show("加速完成。")
47
+              }catch (e:Exception){
30 48
 
49
+              }
31 50
             }
32 51
         }else if (position==data.size+1){
33
-            context.resources.getDrawable(R.drawable.icon_clear,null)
52
+            AppCompatResources.getDrawable(context,R.drawable.icon_clear)
34 53
                 ?.let { holder.mBinding.itemCv.setImageDrawable(it) }
35 54
             holder.mBinding.itemCv.setText(context.getString(R.string.clear))
36 55
             holder.mBinding.itemCv.setOnClickListener {

Laden…
Abbrechen
Speichern