2 * Copyright (C) 2008 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.android.fixvibratesetting;
19 import android.app.Activity;
20 import android.app.Notification;
21 import android.app.NotificationManager;
22 import android.app.PendingIntent;
23 import android.content.Intent;
24 import android.media.AudioManager;
25 import android.util.Log;
26 import android.view.View;
27 import android.widget.TextView;
28 import android.os.Bundle;
30 public class FixVibrateSetting extends Activity implements View.OnClickListener
32 AudioManager mAudioManager;
33 NotificationManager mNotificationManager;
34 TextView mCurrentSetting;
40 public void onCreate(Bundle icicle) {
41 super.onCreate(icicle);
43 setContentView(R.layout.fix_vibrate);
45 mAudioManager = (AudioManager)getSystemService(AUDIO_SERVICE);
46 mNotificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
48 mCurrentSetting = (TextView)findViewById(R.id.current_setting);
50 mFix = findViewById(R.id.fix);
51 mFix.setOnClickListener(this);
53 mUnfix = findViewById(R.id.unfix);
54 mUnfix.setOnClickListener(this);
56 mTest = findViewById(R.id.test);
57 mTest.setOnClickListener(this);
61 public void onResume() {
67 private String getSettingValue(int vibrateType) {
68 int setting = mAudioManager.getVibrateSetting(vibrateType);
70 case AudioManager.VIBRATE_SETTING_OFF:
72 case AudioManager.VIBRATE_SETTING_ON:
74 case AudioManager.VIBRATE_SETTING_ONLY_SILENT:
81 public void onClick(View v) {
85 } else if (v == mUnfix) {
88 } else if (v == mTest) {
94 private void update() {
95 String ringer = getSettingValue(AudioManager.VIBRATE_TYPE_RINGER);
96 String notification = getSettingValue(AudioManager.VIBRATE_TYPE_NOTIFICATION);
97 String text = getString(R.string.current_setting, ringer, notification);
98 mCurrentSetting.setText(text);
102 mAudioManager.setVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION,
103 AudioManager.VIBRATE_SETTING_ON);
106 private void unfix() {
107 mAudioManager.setVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION,
108 AudioManager.VIBRATE_SETTING_OFF);
111 private void test() {
112 Notification n = new Notification(R.drawable.stat_sys_warning, "Test notification",
113 System.currentTimeMillis());
114 Intent intent = new Intent(this, FixVibrateSetting.class);
115 PendingIntent pending = PendingIntent.getActivity(this, 0, intent, 0);
116 n.setLatestEventInfo(this, "Test notification", "Test notification", pending);
118 n.vibrate = new long[] { 0, 700, 500, 1000 };
119 n.flags |= Notification.FLAG_AUTO_CANCEL;
120 mNotificationManager.notify(1, n);