summaryrefslogtreecommitdiffstats
path: root/packages/SystemUI/src/com/android/systemui/quicksettings/RingerModeTile.java
blob: 77d7084aec31923a04b6df7266b219d0effb981d (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
64
65
66
67
68
69
70
package com.android.systemui.quicksettings;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.media.AudioManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnLongClickListener;

import com.android.systemui.R;
import com.android.systemui.statusbar.phone.QuickSettingsController;
import com.android.systemui.statusbar.phone.QuickSettingsContainerView;

public class RingerModeTile extends QuickSettingsTile {

    private AudioManager mAudioManager;

    public RingerModeTile(Context context, LayoutInflater inflater,
            QuickSettingsContainerView container, QuickSettingsController qsc) {
        super(context, inflater, container, qsc);

        mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);

        onClick = new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if(mAudioManager.getRingerMode() == AudioManager.RINGER_MODE_NORMAL){
                    if(mAudioManager.getVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER) == AudioManager.VIBRATE_SETTING_ON){
                        mAudioManager.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
                    }else{
                        mAudioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
                    }
                }else{
                    mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
                }
            }
        };

        onLongClick = new OnLongClickListener() {

            @Override
            public boolean onLongClick(View v) {
                startSettingsActivity(android.provider.Settings.ACTION_SOUND_SETTINGS);
                return true;
            }
        };

        mBroadcastReceiver = new BroadcastReceiver() {

            @Override
            public void onReceive(Context context, Intent intent) {
                if(mAudioManager.isSilentMode()){
                    mDrawable = R.drawable.ic_qs_ring_off;
                    mLabel = mContext.getString(R.string.quick_settings_ringer_off);
                }else{
                    mDrawable = R.drawable.ic_qs_ring_on;
                    mLabel = mContext.getString(R.string.quick_settings_ringer_on);
                }
                updateQuickSettings();
            }
        };

        mIntentFilter = new IntentFilter();
        mIntentFilter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION);
    }

}