-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSceneMode.java
More file actions
84 lines (70 loc) · 1.99 KB
/
Copy pathSceneMode.java
File metadata and controls
84 lines (70 loc) · 1.99 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package design.wang.com.designpatterns;
import android.util.Log;
/**
* 知其然,而后知其所以然
* 倔强小指,成名在望
* 作者: Tomato
* on 2018/3/11 0011.
* design.wang.com.designpatterns
* 功能、作用:
*/
public abstract class SceneMode {
private static final String TAG = "SceneMode";
private static final String DEFAULT_RING = "little Star";
private String mRing = DEFAULT_RING;
private boolean isRing;
private boolean isVibrating;
public void goModel() {
Log.d(TAG, "开启模式:");
}
public abstract String getSceneModelName();
public abstract boolean isRing();
public abstract boolean isVibration();
public void setRingMusic(String ringName) {
this.mRing = ringName;
};
private void playRing() {
this.isRing = true;
Log.d(TAG, "play: " + mRing);
}
private void vibrating() {
this.isVibrating = true;
Log.d(TAG, "vibrating");
}
private void startRing() {
if (isRing()) playRing();
}
private void startVibrating() {
if (isVibration()) vibrating();
}
private void stopRing() {
if (isRing) {
Log.d(TAG, "停止响铃");
this.isRing = false;
}
}
private void stopVibration() {
if (isVibrating) {
Log.d(TAG, "停止震动");
this.isVibrating = false;
}
}
public final void called() {
//为了防止恶意的操作,一般模板方法都加上final关键字,不允许被重写
Log.d(TAG, "called: 被呼叫");
new Thread() {
@Override
public void run() {
startRing();
startVibrating();
try {
Thread.sleep(60 * 1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
stopRing();
stopVibration();
}
}.start();
}
}