-
Notifications
You must be signed in to change notification settings - Fork 19
/
FreezeActivity.java
66 lines (54 loc) · 2.25 KB
/
FreezeActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package com.catchingnow.iceboxsdk;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;
import android.widget.Toast;
import com.catchingnow.icebox.sdk_client.IceBox;
import com.catchingnow.iceboxsdktestapp.R;
public class FreezeActivity extends AppCompatActivity {
// 测试包名随便写
private static final String TEST_PACKAGE = "com.supercell.clashroyale";
private Handler mBackgroundHandler;
private TextView mWorkModeTextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
HandlerThread backgroundThread = new HandlerThread("BACKGROUND_THREAD");
backgroundThread.start();
mBackgroundHandler = new Handler(backgroundThread.getLooper());
setContentView(R.layout.activity_main);
mWorkModeTextView = findViewById(R.id.work_mode);
findViewById(R.id.freeze).setOnClickListener(v -> freeze());
findViewById(R.id.defrost).setOnClickListener(v -> defrost());
}
@Override
protected void onResume() {
super.onResume();
// 如果没有权限,则先请求权限
// 走的标准系统流程
if (ContextCompat.checkSelfPermission(this, IceBox.SDK_PERMISSION) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{IceBox.SDK_PERMISSION}, 0x233);
}
IceBox.WorkMode workMode = IceBox.queryWorkMode(this);
mWorkModeTextView.setText(workMode.toString());
}
private void freeze() {
// 冻结,记得异步哦
mBackgroundHandler.post(() -> {
IceBox.setAppEnabledSettings(this, false, TEST_PACKAGE);
Toast.makeText(this, "Frozen", Toast.LENGTH_SHORT).show();
});
}
private void defrost() {
// 解冻,同样记得异步哦
mBackgroundHandler.post(() -> {
IceBox.setAppEnabledSettings(this, true, TEST_PACKAGE);
Toast.makeText(this, "Defrosted", Toast.LENGTH_SHORT).show();
});
}
}