summaryrefslogtreecommitdiffstats
path: root/services/java/com/android/server/status/widget/AirplaneButton.java
blob: c7a4df75ed7e09db97a2e69626e0c9af828169ca (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
58
59
60
61
62
63
package com.android.server.status.widget;

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

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

public class AirplaneButton extends PowerButton {

    static AirplaneButton ownButton=null;

    public void updateState(Context context) {
        if (getState(context)) {
            currentIcon = R.drawable.stat_airplane_on;
            currentState = PowerButton.STATE_ENABLED;
        } else {
            currentIcon = R.drawable.stat_airplane_off;
            currentState = PowerButton.STATE_DISABLED;
        }

    }

    /**
     * Toggles the state of Airplane
     *
     * @param context
     */
    public void toggleState(Context context) {
        boolean state = getState(context);
        Settings.System.putInt(context.getContentResolver(),
            Settings.System.AIRPLANE_MODE_ON, state ? 0 : 1);
        // notify change
        Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
        intent.putExtra("state", state);
        context.sendBroadcast(intent);
    }

    /**
     * Gets the state of Airplane.
     *
     * @param context
     * @return true if enabled.
     */
    private static boolean getState(Context context) {
        return Settings.System.getInt(context.getContentResolver(),
                 Settings.System.AIRPLANE_MODE_ON,0) == 1;
    }


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

    @Override
    void initButton(int poisition) {
    }

}