10
10
import android .content .Intent ;
11
11
import android .content .SharedPreferences ;
12
12
import android .content .pm .PackageManager ;
13
- import android .net .Uri ;
14
13
import android .os .AsyncTask ;
15
14
import android .os .Build ;
16
15
import android .os .Bundle ;
24
23
import android .view .View ;
25
24
import android .widget .CompoundButton ;
26
25
import android .widget .Switch ;
27
- import android .widget .TextView ;
28
26
import android .widget .Toast ;
29
27
30
- import com .coderstory .miui_toolkit .tools .hosts ;
28
+ import com .coderstory .miui_toolkit .tools .HostsHelper ;
31
29
30
+ import java .io .File ;
32
31
import java .io .IOException ;
33
32
import java .util .HashMap ;
34
33
import java .util .Map ;
@@ -73,6 +72,7 @@ public void onClick(DialogInterface dialog, int which) {
73
72
}).create ();
74
73
builder .show ();
75
74
}
75
+
76
76
}
77
77
78
78
/*初始化每一个布局上的按钮的状态并绑定事件
@@ -82,6 +82,7 @@ private void loadSettings(MainActivity mainActivity) {
82
82
Boolean SetValue ;
83
83
Switch SwitchBtn ;
84
84
85
+
85
86
//移除搜索框
86
87
SetValue = prefs .getBoolean ("RemoveSearchBar" , false );
87
88
SwitchBtn = (Switch ) mainActivity .findViewById (R .id .RemoveSearchBar );
@@ -169,20 +170,14 @@ private void loadSettings(MainActivity mainActivity) {
169
170
SwitchBtn .setChecked (SetValue );
170
171
}
171
172
initControl (SwitchBtn , "root" );
172
-
173
-
174
-
175
173
}
176
-
177
174
//初始化每个按钮的事件
178
175
private void initControl (Switch SwitchBtn , final String key ) {
179
-
180
176
SwitchBtn .setOnCheckedChangeListener (new CompoundButton .OnCheckedChangeListener () {
181
177
@ Override
182
178
public void onCheckedChanged (CompoundButton buttonView , boolean isChecked ) {
183
179
editor .putBoolean (key , isChecked );
184
180
editor .apply ();
185
-
186
181
switch (key ) {
187
182
case "switchIcon" :
188
183
if (isChecked ) {
@@ -211,20 +206,17 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
211
206
}
212
207
});
213
208
}
214
-
215
209
@ Override
216
210
public boolean onCreateOptionsMenu (Menu menu ) {
217
211
// TODO Auto-generated method stub
218
212
MenuInflater inflater = getMenuInflater ();
219
213
inflater .inflate (R .menu .menu , menu );
220
214
return true ;
221
215
}
222
-
223
216
@ Override
224
217
public boolean onOptionsItemSelected (MenuItem item ) {
225
218
// TODO Auto-generated method stub
226
219
int item_id = item .getItemId ();
227
-
228
220
switch (item_id ) {
229
221
case R .id .hotboot :
230
222
showTips ("busybox killall system_server" , getString (R .string .Tips_HotBoot ), this );
@@ -244,7 +236,6 @@ public boolean onOptionsItemSelected(MenuItem item) {
244
236
}
245
237
return true ;
246
238
}
247
-
248
239
/*实现弹窗确定执行某条命令*/
249
240
public static void showTips (final String commandText , String messageText , final Context mContext ) {
250
241
AlertDialog builder = new AlertDialog .Builder (mContext )
@@ -253,12 +244,10 @@ public static void showTips(final String commandText, String messageText, final
253
244
.setPositiveButton (R .string .Btn_Sure , new DialogInterface .OnClickListener () {
254
245
@ Override
255
246
public void onClick (DialogInterface dialog , int which ) {
256
-
257
247
if ("echo 1" .equals (commandText )) {
258
248
editor .putBoolean ("getRoot" , true );
259
249
editor .apply ();
260
250
}
261
-
262
251
// String cmd = commandText;
263
252
try {
264
253
Runtime .getRuntime ().exec (new String []{"su" , "-c" , commandText });
@@ -277,7 +266,6 @@ public void onClick(DialogInterface dialog, int which) {
277
266
System .exit (0 );
278
267
}
279
268
dialog .cancel ();
280
-
281
269
}
282
270
}).create ();
283
271
builder .show ();
@@ -286,30 +274,26 @@ public void openAbout(View v){
286
274
Intent intent =new Intent (this ,AboutActivity .class );
287
275
startActivity (intent );
288
276
}
289
-
290
277
//隐藏图标
291
278
private void HideIcon () {
292
- ComponentName localComponentName = new ComponentName (this , getClass (). getName () + "-Alias " );
279
+ ComponentName localComponentName = new ComponentName (this ,"com.coderstory.miui_toolkit.SplashActivity " );
293
280
PackageManager localPackageManager = getPackageManager ();
294
281
localPackageManager .getComponentEnabledSetting (localComponentName );
295
282
PackageManager packageManager = getPackageManager ();
296
- ComponentName componentName = new ComponentName (this , getClass (). getName () + "-Alias " );
283
+ ComponentName componentName = new ComponentName (this , "com.coderstory.miui_toolkit.SplashActivity " );
297
284
packageManager .setComponentEnabledSetting (componentName , PackageManager .COMPONENT_ENABLED_STATE_DISABLED ,
298
285
PackageManager .DONT_KILL_APP );
299
286
}
300
-
301
287
//显示图标
302
288
private void showIcon () {
303
- ComponentName localComponentName = new ComponentName (this , getClass (). getName () + "-Alias " );
289
+ ComponentName localComponentName = new ComponentName (this , "com.coderstory.miui_toolkit.SplashActivity " );
304
290
PackageManager localPackageManager = getPackageManager ();
305
291
localPackageManager .getComponentEnabledSetting (localComponentName );
306
292
PackageManager packageManager = getPackageManager ();
307
- ComponentName componentName = new ComponentName (this , getClass (). getName () + "-Alias " );
293
+ ComponentName componentName = new ComponentName (this , "com.coderstory.miui_toolkit.SplashActivity " );
308
294
packageManager .setComponentEnabledSetting (componentName , PackageManager .COMPONENT_ENABLED_STATE_DEFAULT ,
309
295
PackageManager .DONT_KILL_APP );
310
296
}
311
-
312
-
313
297
//修改hosts的方法
314
298
private void changeHosts () {
315
299
boolean NoUpdate = prefs .getBoolean ("NoUpdate" , false ); //1
@@ -333,14 +317,12 @@ private void changeHosts() {
333
317
} else {
334
318
setMap .put ("RemoveAdshosts" , "False" );
335
319
}
336
-
337
320
if (NoStore ) {
338
321
setMap .put ("NoStore" , "True" );
339
322
} else {
340
323
setMap .put ("NoStore" , "False" );
341
324
}
342
-
343
- hosts h = new hosts (MainActivity .this , setMap );
325
+ HostsHelper h = new HostsHelper (MainActivity .this , setMap );
344
326
if (!h .execute ()) {
345
327
Toast .makeText (MainActivity .this , R .string .Tips_No_Root , Toast .LENGTH_SHORT ).show ();
346
328
Switch SwitchBtn = (Switch ) MainActivity .this .findViewById (R .id .RemoveAdshosts );
@@ -349,35 +331,30 @@ private void changeHosts() {
349
331
}
350
332
}
351
333
}
352
-
353
334
//因为hosts修改比较慢 所以改成异步的
354
335
class MyTask extends AsyncTask <String , Integer , String > {
355
336
@ Override
356
337
protected void onPreExecute () {
357
338
setProgressBarIndeterminateVisibility (true );
358
339
showProgress ();
359
340
}
360
-
361
341
@ Override
362
342
protected void onPostExecute (String param ) {
363
343
// showData();
364
344
setProgressBarIndeterminateVisibility (false );
365
345
// adapter.notifyDataSetChanged();
366
346
closeProgress ();
367
347
}
368
-
369
348
@ Override
370
349
protected void onCancelled () {
371
350
// TODO Auto-generated method stub
372
351
super .onCancelled ();
373
352
}
374
-
375
353
@ Override
376
354
protected void onProgressUpdate (Integer ... values ) {
377
355
// TODO Auto-generated method stub
378
356
super .onProgressUpdate (values );
379
357
}
380
-
381
358
@ Override
382
359
protected String doInBackground (String ... params ) {
383
360
Looper .prepare ();
@@ -386,9 +363,7 @@ protected String doInBackground(String... params) {
386
363
return null ;
387
364
}
388
365
}
389
-
390
366
private Dialog dialog ;
391
-
392
367
protected void showProgress () {
393
368
if (dialog == null ) {
394
369
// dialog.setContentView(R.layout.progress_dialog);
@@ -397,12 +372,10 @@ protected void showProgress() {
397
372
dialog .show ();
398
373
}
399
374
}
400
-
401
375
protected void closeProgress () {
402
-
403
376
if (dialog != null ) {
404
377
dialog .cancel ();
405
378
dialog = null ;
406
379
}
407
380
}
408
- }
381
+ }
0 commit comments