wangzhibo
4 天以前 ae6f40460dcd56af6c5f60ba52c883854c3bac55
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*  Copyright (C) 2015-2024 Carsten Pfeiffer, José Rebelo, Uwe Hermann
 
    This file is part of Gadgetbridge.
 
    Gadgetbridge is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as published
    by the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
 
    Gadgetbridge is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.
 
    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.devices.miband;
 
import android.content.Context;
 
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.alertnotification.AlertLevel;
 
public class VibrationProfile {
    public static final String ID_STACCATO;
    public static final String ID_SHORT;
    public static final String ID_MEDIUM;
    public static final String ID_LONG;
    public static final String ID_WATERDROP;
    public static final String ID_RING;
    public static final String ID_ALARM_CLOCK;
 
    static {
        Context CONTEXT = GBApplication.getContext();
        ID_STACCATO = CONTEXT.getString(R.string.p_staccato);
        ID_SHORT = CONTEXT.getString(R.string.p_short);
        ID_MEDIUM = CONTEXT.getString(R.string.p_medium);
        ID_LONG = CONTEXT.getString(R.string.p_long);
        ID_WATERDROP = CONTEXT.getString(R.string.p_waterdrop);
        ID_RING = CONTEXT.getString(R.string.p_ring);
        ID_ALARM_CLOCK = CONTEXT.getString(R.string.p_alarm_clock);
    }
 
    public static VibrationProfile getProfile(String id, short repeat) {
        if (ID_STACCATO.equals(id)) {
            return new VibrationProfile(id, new int[]{100, 0}, repeat);
        }
        if (ID_SHORT.equals(id)) {
            return new VibrationProfile(id, new int[]{200, 200}, repeat);
        }
        if (ID_LONG.equals(id)) {
            return new VibrationProfile(id, new int[]{500, 1000}, repeat);
        }
        if (ID_WATERDROP.equals(id)) {
            return new VibrationProfile(id, new int[]{100, 1500}, repeat);
        }
        if (ID_RING.equals(id)) {
            return new VibrationProfile(id, new int[]{300, 200, 600, 2000}, repeat);
        }
        if (ID_ALARM_CLOCK.equals(id)) {
            return new VibrationProfile(id, new int[]{30, 35, 30, 35, 30, 35, 30, 800}, repeat);
        }
        // medium
        return new VibrationProfile(id, new int[]{300, 600}, repeat);
    }
 
    private final String id;
 
    private final int[] onOffSequence;
    private final short repeat;
    private int alertLevel = AlertLevel.MildAlert.getId();
 
    /**
     * Creates a new profile instance.
     *
     * @param id            the ID, used as preference key.
     * @param onOffSequence a sequence of alternating on and off durations, in milliseconds
     * @param repeat        how often the sequence shall be repeated
     */
    public VibrationProfile(String id, int[] onOffSequence, short repeat) {
        if (onOffSequence.length % 2 != 0) {
            throw new IllegalArgumentException("Each on duration must have a subsequent off duration");
        }
 
        this.id = id;
        this.repeat = repeat;
        this.onOffSequence = onOffSequence;
    }
 
    public String getId() {
        return id;
    }
 
    public int[] getOnOffSequence() {
        return onOffSequence;
    }
 
    public short getRepeat() {
        return repeat;
    }
 
    public void setAlertLevel(int alertLevel) {
        this.alertLevel = alertLevel;
    }
 
    public int getAlertLevel() {
        return alertLevel;
    }
}