summaryrefslogtreecommitdiffstats
path: root/services/java/com/android/server/status/widget/FlashlightButton.java
blob: d4a9b105b888b0842e3765dc9ad4986290449e84 (plain)
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
package com.android.server.status.widget;

import com.android.internal.R;
import com.android.server.status.widget.PowerButton;

import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.provider.Settings;

public class FlashlightButton extends PowerButton {

    Context mContext;
    static FlashlightButton ownButton;
    private static final String TAG = "FlashlightButton";

    public void updateState(Context context) {
        mContext = context;
        boolean useCustomExp = Settings.System.getInt(mContext.getContentResolver(),
        Settings.System.NOTIF_EXPANDED_BAR_CUSTOM, 0) == 1;

        if(getFlashlightEnabled()) {
            if (useCustomExp) {
                currentIcon = com.android.internal.R.drawable.stat_flashlight_on_cust;
            } else {
                currentIcon = com.android.internal.R.drawable.stat_flashlight_on;
            }
            currentState = STATE_ENABLED;
        } else {
            if (useCustomExp) {
                currentIcon = com.android.internal.R.drawable.stat_flashlight_off_cust;
            } else {
                currentIcon = com.android.internal.R.drawable.stat_flashlight_off;
            }
            currentState = STATE_DISABLED;
        }
    }

    public void toggleState(Context context) {
        mContext.sendBroadcast(new Intent("net.cactii.flash2.TOGGLE_FLASHLIGHT"));
    }

    public static FlashlightButton getInstance() {
        if (ownButton==null) ownButton = new FlashlightButton();
        return ownButton;
    }


    public boolean getFlashlightEnabled() {
        return Settings.System.getInt(mContext.getContentResolver(), Settings.System.TORCH_STATE, 0) == 1;
    }

    @Override
    void initButton(int position) {
    }

}