Browse Source

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

master
wangwanlei 10 months ago
parent
commit
a3d65bb7a5
1 changed files with 21 additions and 2 deletions
  1. 21
    2
      app/src/main/java/com/xhly/manageapp/AppAdapter.kt

+ 21
- 2
app/src/main/java/com/xhly/manageapp/AppAdapter.kt View File

1
 package com.xhly.manageapp
1
 package com.xhly.manageapp
2
 
2
 
3
+import android.annotation.SuppressLint
4
+import android.app.ActivityManager
3
 import android.content.Context
5
 import android.content.Context
4
 import android.view.LayoutInflater
6
 import android.view.LayoutInflater
5
 import android.view.ViewGroup
7
 import android.view.ViewGroup
8
+import android.widget.Toast
9
+import androidx.appcompat.content.res.AppCompatResources
6
 import androidx.recyclerview.widget.RecyclerView
10
 import androidx.recyclerview.widget.RecyclerView
11
+import com.hjq.toast.Toaster
7
 import com.xhly.corelib.bean.AppInfo
12
 import com.xhly.corelib.bean.AppInfo
13
+import com.xhly.corelib.utils.LogShow
8
 import com.xhly.manageapp.databinding.ItemAppBinding
14
 import com.xhly.manageapp.databinding.ItemAppBinding
9
 import java.util.Calendar
15
 import java.util.Calendar
10
 
16
 
21
         return data.size+2
27
         return data.size+2
22
     }
28
     }
23
 
29
 
30
+
24
     override fun onBindViewHolder(holder: AppViewHolder, position: Int) {
31
     override fun onBindViewHolder(holder: AppViewHolder, position: Int) {
25
         if (position==data.size){
32
         if (position==data.size){
26
-            context.resources.getDrawable(R.drawable.icon_speed,null)
33
+            AppCompatResources.getDrawable(context,R.drawable.icon_speed)
27
                 ?.let { holder.mBinding.itemCv.setImageDrawable(it) }
34
                 ?.let { holder.mBinding.itemCv.setImageDrawable(it) }
28
             holder.mBinding.itemCv.setText(context.getString(R.string.speed))
35
             holder.mBinding.itemCv.setText(context.getString(R.string.speed))
29
             holder.mBinding.itemCv.setOnClickListener {
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
         }else if (position==data.size+1){
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
                 ?.let { holder.mBinding.itemCv.setImageDrawable(it) }
53
                 ?.let { holder.mBinding.itemCv.setImageDrawable(it) }
35
             holder.mBinding.itemCv.setText(context.getString(R.string.clear))
54
             holder.mBinding.itemCv.setText(context.getString(R.string.clear))
36
             holder.mBinding.itemCv.setOnClickListener {
55
             holder.mBinding.itemCv.setOnClickListener {

Loading…
Cancel
Save