Skip to content

Commit c8e8a7f

Browse files
committed
Fix bugs
1 parent 96238f2 commit c8e8a7f

File tree

100 files changed

+15407
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+15407
-1
lines changed

.idea/caches/build_file_checksums.ser

586 Bytes
Binary file not shown.

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
package com.balaganovrocks.yourmastercleaner.adapter;
2+
3+
import android.content.Context;
4+
import android.os.Handler;
5+
import android.view.LayoutInflater;
6+
import android.view.View;
7+
import android.view.ViewGroup;
8+
import android.widget.BaseAdapter;
9+
import android.widget.ImageView;
10+
import android.widget.TextView;
11+
12+
import com.balaganovrocks.yourmastercleaner.fragment.AutoStartFragment;
13+
import com.balaganovrocks.yourmastercleaner.R;
14+
import com.balaganovrocks.yourmastercleaner.model.AutoStartInfo;
15+
import com.balaganovrocks.yourmastercleaner.utils.ShellUtils;
16+
import com.balaganovrocks.yourmastercleaner.utils.T;
17+
18+
import java.util.ArrayList;
19+
import java.util.List;
20+
21+
public class AutoStartAdapter extends BaseAdapter {
22+
23+
public List<AutoStartInfo> mlistAppInfo;
24+
LayoutInflater infater = null;
25+
private Context mContext;
26+
public static List<Integer> clearIds;
27+
private Handler mHandler;
28+
29+
public AutoStartAdapter(Context context, List<AutoStartInfo> apps, Handler mHandler) {
30+
infater = LayoutInflater.from(context);
31+
mContext = context;
32+
clearIds = new ArrayList<Integer>();
33+
this.mlistAppInfo = apps;
34+
this.mHandler = mHandler;
35+
}
36+
37+
@Override
38+
public int getCount() {
39+
// TODO Auto-generated method stub
40+
return mlistAppInfo.size();
41+
}
42+
43+
@Override
44+
public Object getItem(int position) {
45+
// TODO Auto-generated method stub
46+
return mlistAppInfo.get(position);
47+
}
48+
49+
@Override
50+
public long getItemId(int position) {
51+
// TODO Auto-generated method stub
52+
return position;
53+
}
54+
55+
@Override
56+
public View getView(int position, View convertView, ViewGroup parent) {
57+
ViewHolder holder = null;
58+
if (convertView == null) {
59+
convertView = infater.inflate(R.layout.listview_auto_start,
60+
null);
61+
holder = new ViewHolder();
62+
holder.appIcon = (ImageView) convertView
63+
.findViewById(R.id.app_icon);
64+
holder.appName = (TextView) convertView
65+
.findViewById(R.id.app_name);
66+
holder.size = (TextView) convertView
67+
.findViewById(R.id.app_size);
68+
holder.disable_switch = (TextView) convertView
69+
.findViewById(R.id.disable_switch);
70+
71+
convertView.setTag(holder);
72+
} else {
73+
holder = (ViewHolder) convertView.getTag();
74+
}
75+
final AutoStartInfo item = (AutoStartInfo) getItem(position);
76+
if (item != null) {
77+
holder.appIcon.setImageDrawable(item.getIcon());
78+
holder.appName.setText(item.getLabel());
79+
if (item.isEnable()) {
80+
holder.disable_switch.setBackgroundResource(R.drawable.switch_on);
81+
holder.disable_switch.setText("已开启");
82+
} else {
83+
holder.disable_switch.setBackgroundResource(R.drawable.switch_off);
84+
holder.disable_switch.setText("已禁止");
85+
}
86+
// holder.size.setText(Formatter.formatShortFileSize(mContext, item.getCacheSize()));
87+
88+
holder.disable_switch.setOnClickListener(new View.OnClickListener() {
89+
@Override
90+
public void onClick(View v) {
91+
92+
93+
if (ShellUtils.checkRootPermission()) {
94+
95+
if (item.isEnable()) {
96+
97+
98+
diasableApp(item);
99+
} else {
100+
101+
enableApp(item);
102+
}
103+
104+
} else {
105+
106+
T.showLong(mContext, "该功能需要获取系统root权限,点击允许获取root权限");
107+
108+
}
109+
110+
}
111+
});
112+
holder.packageName = item.getPackageName();
113+
}
114+
115+
116+
return convertView;
117+
}
118+
119+
private void diasableApp(AutoStartInfo item) {
120+
String packageReceiverList[] = item.getPackageReceiver().toString().split(";");
121+
122+
List<String> mSring = new ArrayList<>();
123+
for (int j = 0; j < packageReceiverList.length; j++) {
124+
String cmd = "pm disable " + packageReceiverList[j];
125+
//部分receiver包含$符号,需要做进一步处理,用"$"替换掉$
126+
cmd = cmd.replace("$", "\"" + "$" + "\"");
127+
//执行命令
128+
mSring.add(cmd);
129+
130+
}
131+
ShellUtils.CommandResult mCommandResult = ShellUtils.execCommand(mSring, true, true);
132+
133+
if (mCommandResult.result == 0) {
134+
T.showLong(mContext, item.getLabel() + "已禁止");
135+
item.setEnable(false);
136+
notifyDataSetChanged();
137+
if (mHandler != null) {
138+
mHandler.sendEmptyMessage(AutoStartFragment.REFRESH_BT);
139+
}
140+
} else {
141+
T.showLong(mContext, item.getLabel() + "禁止失败");
142+
}
143+
144+
// T.showLong(mContext, mCommandResult.result + "" + mCommandResult.errorMsg + mCommandResult.successMsg);
145+
}
146+
147+
private void enableApp(AutoStartInfo item) {
148+
String packageReceiverList[] = item.getPackageReceiver().toString().split(";");
149+
150+
List<String> mSring = new ArrayList<>();
151+
for (int j = 0; j < packageReceiverList.length; j++) {
152+
String cmd = "pm enable " + packageReceiverList[j];
153+
//部分receiver包含$符号,需要做进一步处理,用"$"替换掉$
154+
cmd = cmd.replace("$", "\"" + "$" + "\"");
155+
//执行命令
156+
mSring.add(cmd);
157+
158+
}
159+
ShellUtils.CommandResult mCommandResult = ShellUtils.execCommand(mSring, true, true);
160+
161+
if (mCommandResult.result == 0) {
162+
T.showLong(mContext, item.getLabel() + "已开启");
163+
item.setEnable(true);
164+
notifyDataSetChanged();
165+
if (mHandler != null) {
166+
mHandler.sendEmptyMessage(AutoStartFragment.REFRESH_BT);
167+
}
168+
} else {
169+
T.showLong(mContext, item.getLabel() + "开启失败");
170+
}
171+
// T.showLong(mContext, mCommandResult.result + "" + mCommandResult.errorMsg + mCommandResult.successMsg);
172+
}
173+
174+
class ViewHolder {
175+
ImageView appIcon;
176+
TextView appName;
177+
TextView size;
178+
TextView disable_switch;
179+
180+
String packageName;
181+
}
182+
183+
}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
package com.balaganovrocks.yourmastercleaner.adapter;
2+
3+
import android.content.Context;
4+
import android.view.LayoutInflater;
5+
import android.view.View;
6+
import android.view.ViewGroup;
7+
import android.widget.BaseAdapter;
8+
import android.widget.ImageView;
9+
import android.widget.RadioButton;
10+
import android.widget.RelativeLayout;
11+
import android.widget.TextView;
12+
13+
import com.balaganovrocks.yourmastercleaner.R;
14+
import com.balaganovrocks.yourmastercleaner.bean.AppProcessInfo;
15+
import com.balaganovrocks.yourmastercleaner.utils.StorageUtil;
16+
17+
import java.util.ArrayList;
18+
import java.util.List;
19+
20+
public class ClearMemoryAdapter extends BaseAdapter {
21+
22+
public List<AppProcessInfo> mlistAppInfo;
23+
LayoutInflater infater = null;
24+
private Context mContext;
25+
public static List<Integer> clearIds;
26+
27+
public ClearMemoryAdapter(Context context, List<AppProcessInfo> apps) {
28+
infater = LayoutInflater.from(context);
29+
mContext = context;
30+
clearIds = new ArrayList<Integer>();
31+
this.mlistAppInfo = apps;
32+
}
33+
34+
@Override
35+
public int getCount() {
36+
// TODO Auto-generated method stub
37+
return mlistAppInfo.size();
38+
}
39+
40+
@Override
41+
public Object getItem(int position) {
42+
// TODO Auto-generated method stub
43+
return mlistAppInfo.get(position);
44+
}
45+
46+
@Override
47+
public long getItemId(int position) {
48+
// TODO Auto-generated method stub
49+
return position;
50+
}
51+
52+
@Override
53+
public View getView(int position, View convertView, ViewGroup parent) {
54+
ViewHolder holder = null;
55+
if (convertView == null) {
56+
convertView = infater.inflate(R.layout.listview_memory_clean,
57+
null);
58+
holder = new ViewHolder();
59+
holder.appIcon = (ImageView) convertView
60+
.findViewById(R.id.image);
61+
holder.appName = (TextView) convertView
62+
.findViewById(R.id.name);
63+
holder.memory = (TextView) convertView
64+
.findViewById(R.id.memory);
65+
66+
holder.cb = (RadioButton) convertView
67+
.findViewById(R.id.choice_radio);
68+
convertView.setTag(holder);
69+
} else {
70+
holder = (ViewHolder) convertView.getTag();
71+
}
72+
final AppProcessInfo appInfo = (AppProcessInfo) getItem(position);
73+
holder.appIcon.setImageDrawable(appInfo.icon);
74+
holder.appName.setText(appInfo.appName);
75+
holder.memory.setText(StorageUtil.convertStorage(appInfo.memory));
76+
if (appInfo.checked) {
77+
holder.cb.setChecked(true);
78+
} else {
79+
holder.cb.setChecked(false);
80+
}
81+
holder.cb.setOnClickListener(new View.OnClickListener() {
82+
@Override
83+
public void onClick(View v) {
84+
if (appInfo.checked) {
85+
appInfo.checked = false;
86+
} else {
87+
appInfo.checked = true;
88+
}
89+
notifyDataSetChanged();
90+
}
91+
});
92+
93+
return convertView;
94+
}
95+
96+
class ViewHolder {
97+
ImageView appIcon;
98+
TextView appName;
99+
TextView memory;
100+
TextView tvProcessMemSize;
101+
RelativeLayout cb_rl;
102+
RadioButton cb;
103+
104+
public RadioButton getCb() {
105+
return cb;
106+
}
107+
108+
public void setCb(RadioButton cb) {
109+
this.cb = cb;
110+
}
111+
}
112+
113+
}

0 commit comments

Comments
 (0)