編輯:中級開發
vIEw plaincopy to clipboardprint?
01.package com.examples.android;
02.
03.import android.content.BroadcastReceiver;
04.import android.content.Context;
05.import android.content.Intent;
06.import android.media.AudioManager;
07.import android.util.Log;
08.
09.public class RingBroadcastReceiver extends BroadcastReceiver {
10.
11. private static final String TAG = "RingBroadcastReceiver";
12. public static final String VIBRATE_CHANGED = "com.examples.android.VIBRATE_CHANGED";
13. public static final String SILENT_CHANGED = "com.examples.android.SILENT_CHANGED";
14. public static final String RV_CHANGED = "com.examples.android.RV_CHANGED";
15. public static final String RING_CHANGED = "com.examples.android.RING_CHANGED";
16. public static final int REQUEST_CODE = 0;
17.
18.
19. @Override
20. public void onReceive(Context context, Intent intent) {
21. // TODO Auto-generated method stub
22.
23. AudioManager audio = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
24.
25. int checkedId = intent.getIntExtra("checkedId", 0);
26.
27. Log.e(TAG, checkedId + intent.getAction());
28.
29. // 切換情景模式
30. switch (checkedId)
31. {
32. case R.id.ring_and_vibrate01:
33. case R.id.ring_and_vibrate02:
34. ringAndVibrate(audio);
35. break;
36. case R.id.vibrate01:
37. case R.id.vibrate02:
38. vibrate(audio);
39. break;
40. case R.id.silent01:
41. case R.id.silent02:
42. silent(audio);
43. break;
44. default:
45. ring(audio);
46. break;
47. }
48.
49. }
50.
51. // 鈴聲和震動
52. protected void ringAndVibrate(AudioManager audio)
53. {
54. audio.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
55. audio.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_ON);
56. audio.setVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION, AudioManager.VIBRATE_SETTING_ON);
57. }
58.
59. // 鈴聲
60. protected void ring(AudioManager audio)
61. {
62. audio.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
63. audio.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_OFF);
64. audio.setVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION, AudioManager.VIBRATE_SETTING_ON);
65. }
66.
67. // 震動
68. protected void vibrate(AudioManager audio)
69. {
70. audio.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
71. audio.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_ON);
72. audio.setVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION, AudioManager.VIBRATE_SETTING_ON);
73. }
74.
75. // 靜音
76. protected void silent(AudioManager audio)
77. {
78. audio.setRingerMode(AudioManager.RINGER_MODE_SILENT);
79. audio.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_OFF);
80. audio.setVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION, AudioManager.VIBRATE_SETTING_OFF);
81. }
82.
83.}
package com.examples.android;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.media.AudioManager;
import android.util.Log;
public class RingBroadcastReceiver extends BroadcastReceiver {
private static final String TAG = "RingBroadcastReceiver";
public static final String VIBRATE_CHANGED = "com.examples.android.VIBRATE_CHANGED";
public static final String SILENT_CHANGED = "com.examples.android.SILENT_CHANGED";
public static final String RV_CHANGED = "com.examples.android.RV_CHANGED";
public static final String RING_CHANGED = "com.examples.android.RING_CHANGED";
public static final int REQUEST_CODE = 0;
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
AudioManager audio = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
int checkedId = intent.getIntExtra("checkedId", 0);
Log.e(TAG, checkedId + intent.getAction());
// 切換情景模式
switch (checkedId)
{
case R.id.ring_and_vibrate01:
case R.id.ring_and_vibrate02:
ringAndVibrate(audio);
break;
case R.id.vibrate01:
case R.id.vibrate02:
vibrate(audio);
break;
case R.id.silent01:
case R.id.silent02:
silent(audio);
break;
default:
ring(audio);
break;
}
}
// 鈴聲和震動
protected void ringAndVibrate(AudioManager audio)
{
audio.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
audio.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_ON);
audio.setVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION, AudioManager.VIBRATE_SETTING_ON);
}
// 鈴聲
protected void ring(AudioManager audio)
{
audio.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
audio.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_OFF);
audio.setVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION, AudioManager.VIBRATE_SETTING_ON);
}
// 震動
protected void vibrate(AudioManager audio)
{
audio.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
audio.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_ON);
audio.setVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION, AudioManager.VIBRATE_SETTING_ON);
}
// 靜音
protected void silent(AudioManager audio)
{
audio.setRingerMode(AudioManager.RINGER_MODE_SILENT);
audio.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_OFF);
audio.setVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION, AudioManager.VIBRATE_SETTING_OFF);
}
}
main.XML文件:
vIEw plaincopy to clipboardprint?
01.<?XML version="1.0" encoding="utf-8"?>
02.<TabHost XMLns:android="http://schemas.android.com/apk/res/android"
03. android:id="@android:id/tabhost"
04. android:layout_width="fill_parent"
05. android:layout_height="fill_parent">
06.
07. <LinearLayout
08. android:orIEntation="vertical"
09. android:layout_width="fill_parent"
10. android:layout_height="fill_parent">
11.
12. <TabWidget
13. android:id="@android:id/tabs"
14. android:layout_width="fill_parent"
15. android:layout_height="wrap_content"/>
16. <FrameLayout
17. android:id="@android:id/tabcontent"
18. android:layout_width="fill_parent"
19. android:layout_height="fill_parent">
20. <RadioGroup
21. android:id="@+id/RadioGroup01"
22. android:orIEntation="vertical"
23. android:layout_width="wrap_content"
24. android:layout_height="wrap_content"
25. android:layout_centerInParent="true">
26.
27. <RadioButton
28. android:text="@string/ring_and_vibrate"
29. android:id="@+id/ring_and_vibrate01"
30. android:layout_width="fill_parent"
31. android:textSize="24sp"
32. android:paddingLeft="50sp"/>
33. <RadioButton
34. android:text="@string/ring"
35. android:id="@+id/ring01"
36. android:layout_width="fill_parent"
37. android:textSize="24sp"
38. android:paddingLeft="50sp"
39. android:paddingRight="50sp"/>
40. <RadioButton
41. android:text="@string/vibrate"
42. android:id="@+id/vibrate01"
43. android:layout_width="fill_parent"
44. android:textSize="24sp"
45. android:paddingLeft="50sp"
46. android:paddingRight="50sp"/>
47. <RadioButton
48. android:text="@string/silent"
49. android:id="@+id/silent01"
50. android:layout_width="fill_parent"
51. android:textSize="24sp"
52. android:paddingLeft="50sp"
53. android:paddingRight="50sp"/>
54. </RadioGroup>
55.
56. <RelativeLayout XMLns:android="http://schemas.android.com/apk/res/android"
57. android:id="@+id/RelativeLayout01"
58. android:orIEntation="vertical"
59. android:layout_width="fill_parent"
60. android:layout_height="fill_parent"
61. android:padding="12sp">
62. <TextVIEw
63. android:layout_width="wrap_content"
64. android:layout_height="wrap_content"
65. android:text="@string/help"
66. android:textSize="20px"
67. android:textStyle="bold"
68. android:id="@+id/help"/>
69. <TimePicker
70. android:id="@+id/timePkr"
71. android:layout_below="@id/help"
72. android:layout_width="wrap_content"
73. android:layout_height="wrap_content"/>
74. <RadioGroup
75. android:orIEntation="vertical"
76. android:id="@+id/RadioGroup02"
77. android:layout_below="@id/timePkr"
78. android:layout_height="wrap_content"
79. android:layout_width="wrap_content"
80. android:layout_centerInParent="true">
81. <RadioButton
82. android:text="@string/ring_and_vibrate"
83. android:id="@+id/ring_and_vibrate02"
84. android:layout_width="fill_parent"
85. android:textSize="24sp"
86. android:paddingLeft="50sp"/>
87. <RadioButton
88. android:text="@string/ring"
89. android:id="@+id/ring02"
90. android:layout_width="fill_parent"
91. android:textSize="24sp"
92. android:paddingLeft="50sp"
93. android:paddingRight="50sp"/>
94. <RadioButton
95. android:text="@string/vibrate"
96. android:id="@+id/vibrate02"
97. android:layout_width="fill_parent"
98. android:textSize="24sp"
99. android:paddingLeft="50sp"
100. android:paddingRight="50sp"/>
101. <RadioButton
102. android:text="@string/silent"
103. android:id="@+id/silent02"
104. android:layout_width="fill_parent"
105. android:textSize="24sp"
106. android:paddingLeft="50sp"
107. android:paddingRight="50sp"/>
108. </RadioGroup>
109.
110. </RelativeLayout>
111. <AbsoluteLayout XMLns:android="http://schemas.android.com/apk/res/android"
112. android:id="@+id/AbsoluteLayout03"
113. android:layout_width="fill_parent"
114. android:layout_height="fill_parent">
115. <TextVIEw
116. android:id="@+id/myText1"
117. android:layout_width="wrap_content"
118. android:layout_height="wrap_content"
119. android:text="情景模式:"
120. android:textSize="16sp"
121. android:layout_x="20px"
122. android:layout_y="42px"/>
123. <ImageVIEw
124. android:id="@+id/myImage"
125. android:layout_width="48px"
126. android:layout_height="48px"
127. android:layout_x="110px"
128. android:layout_y="32px"/>
129. <TextVIEw
130. android:id="@+id/myText2"
131. android:layout_width="wrap_content"
132. android:layout_height="wrap_content"
133. android:text="聲音音量:"
134. android:textSize="16sp"
135. android:layout_x="20px"
136. android:layout_y="102px"/>
137. <ProgressBar
138. android:id="@+id/myProgress"
139.
145. android:layout_y="102px"/>
146. <ImageButton
147. android:id="@+id/downButton"
148. android:layout_width="100px"
149. android:layout_height="100px"
150. android:layout_x="50px"
151. android:layout_y="162px"
152. android:src="@drawable/down"/>
153. <ImageButton
154. android:id="@+id/upButton"
155. android:layout_width="100px"
156. android:layout_height="100px"
157. android:layout_x="150px"
158. android:layout_y="162px"
159. android:src="@drawable/up"/>
160. <ImageButton
161. android:id="@+id/normalButton"
162. android:layout_width="60px"
163. android:layout_height="60px"
164. android:layout_x="50px"
165. android:layout_y="272px"
166. android:src="@drawable/icon"/>
167. <ImageButton
168. android:id="@+id/muteButton"
169. android:layout_width="60px"
170. android:layout_height="60px"
171. android:layout_x="120px"
172. android:layout_y="272px"
173. android:src="@drawable/mute"/>
174. <ImageButton
175. android:id="@+id/vibrateButton"
176. android:layout_width="60px"
177. android:layout_height="60px"
178. android:layout_x="190px"
179. android:layout_y="272px"
180. android:src="@drawable/vibrate"/>
181. </AbsoluteLayout>
182. </FrameLayout>
183. </LinearLayout>
184.
185.</TabHost>
<?XML version="1.0" encoding="utf-8"?>
<TabHost XMLns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orIEntation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RadioGroup
android:id="@+id/RadioGroup01"
android:orIEntation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true">
<RadioButton
android:text="@string/ring_and_vibrate"
android:id="@+id/ring_and_vibrate01"
android:layout_width="fill_parent"
android:textSize="24sp"
android:paddingLeft="50sp"/>
<RadioButton
android:text="@string/ring"
android:id="@+id/ring01"
android:layout_width="fill_parent"
android:textSize="24sp"
android:paddingLeft="50sp"
android:paddingRight="50sp"/>
<RadioButton
android:text="@string/vibrate"
android:id="@+id/vibrate01"
android:layout_width="fill_parent"
android:textSize="24sp"
android:paddingLeft="50sp"
android:paddingRight="50sp"/>
<RadioButton
android:text="@string/silent"
android:id="@+id/silent01"
android:layout_width="fill_parent"
android:textSize="24sp"
android:paddingLeft="50sp"
android:paddingRight="50sp"/>
</RadioGroup>
<RelativeLayout XMLns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout01"
android:orIEntation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="12sp">
<TextVIEw
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/help"
android:textSize="20px"
android:textStyle="bold"
android:id="@+id/help"/>
<TimePicker
android:id="@+id/timePkr"
android:layout_below="@id/help"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<RadioGroup
android:orIEntation="vertical"
android:id="@+id/RadioGroup02"
android:layout_below="@id/timePkr"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_centerInParent="true">
<RadioButton
android:text="@string/ring_and_vibrate"
android:id="@+id/ring_and_vibrate02"
android:layout_width="fill_parent"
android:textSize="24sp"
android:paddingLeft="50sp"/>
<RadioButton
android:text="@string/ring"
android:id="@+id/ring02"
android:layout_width="fill_parent"
android:textSize="24sp"
android:paddingLeft="50sp"
android:paddingRight="50sp"/>
<RadioButton
android:text="@string/vibrate"
android:id="@+id/vibrate02"
android:layout_width="fill_parent"
android:textSize="24sp"
android:paddingLeft="50sp"
android:paddingRight="50sp"/>
<RadioButton
android:text="@string/silent"
android:id="@+id/silent02"
android:layout_width="fill_parent"
android:textSize="24sp"
android:paddingLeft="50sp"
android:paddingRight="50sp"/>
</RadioGroup>
</RelativeLayout>
<AbsoluteLayout XMLns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/AbsoluteLayout03"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextVIEw
android:id="@+id/myText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="情景模式:"
android:textSize="16sp"
android:layout_x="20px"
android:layout_y="42px"/>
<ImageVIEw
android:id="@+id/myImage"
android:layout_width="48px"
android:layout_height="48px"
android:layout_x="110px"
android:layout_y="32px"/>
<TextVIEw
android:id="@+id/myText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="聲音音量:"
android:textSize="16sp"
android:layout_x="20px"
android:layout_y="102px"/>
<ProgressBar
android:id="@+id/myProgress"
android:layout_y="102px"/>
<ImageButton
android:id="@+id/downButton"
android:layout_width="100px"
android:layout_height="100px"
android:layout_x="50px"
android:layout_y="162px"
android:src="@drawable/down"/>
<ImageButton
android:id="@+id/upButton"
android:layout_width="100px"
android:layout_height="100px"
android:layout_x="150px"
android:layout_y="162px"
android:src="@drawable/up"/>
<ImageButton
android:id="@+id/normalButton"
android:layout_width="60px"
android:layout_height="60px"
android:layout_x="50px"
android:layout_y="272px"
android:src="@drawable/icon"/>
<ImageButton
android:id="@+id/muteButton"
android:layout_width="60px"
android:layout_height="60px"
android:layout_x="120px"
android:layout_y="272px"
android:src="@drawable/mute"/>
<ImageButton
android:id="@+id/vibrateButton"
android:layout_width="60px"
android:layout_height="60px"
android:layout_x="190px"
android:layout_y="272px"
android:src="@drawable/vibrate"/>
</AbsoluteLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
strings.XML文件:
vIEw plaincopy to clipboardprint?
01.<?XML version="1.0" encoding="utf-8"?>
02.<resources>
03. <string name="hello">Hello World, RingProfile!</string>
04. <string name="app_name">《情景模式》</string>
05. <string name="ring_and_vibrate">鈴聲和振動</string>
06. <string name="ring">鈴聲</string>
07. <string name="vibrate">振動</string>
08. <string name="silent">靜音</string>
09. <string name="help">設置時間:</string>
10.</resources>
<?XML version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, RingProfile!</string>
<string name="app_name">《情景模式》</string>
<string name="ring_and_vibrate">鈴聲和振動</string>
<string name="ring">鈴聲</string>
<string name="vibrate">振動</string>
<string name="silent">靜音</string>
<string name="help">設置時間:</string>
</resources>
androidManifest.XML文件:
vIEw plaincopy to clipboardprint?
01.<?XML version="1.0" encoding="utf-8"?>
02.<manifest XMLns:android="http://schemas.android.com/apk/res/android"
03. package="com.examples.android"
04. android:versionCode="1"
05. android:versionName="1.0">
06. <application android:icon="@drawable/icon" android:label="@string/app_name">
07. <activity android:name=".RingProfile"
08. android:label="@string/app_name">
09. <intent-filter>
10. <action android:name="android.intent.action.MAIN" />
11. <category android:name="android.intent.category.LAUNCHER" />
12. </intent-filter>
13. </activity>
14. <receiver android:name="RingBroadcastReceiver">
15. <intent-filter>
16. <action android:name="com.examples.android.RV_CHANGED" />
17. <action android:name="com.examples.android.RING_CHANGED" />
18. <action android:name="com.examples.android.VIBRATE_CHANGED" />
19. <action android:name="com.examples.android.SILENT_CHANGED" />
20. </intent-filter>
21. </receiver>
22. </application>
23. <uses-sdk android:minSdkVersion="5" />
24.
25.</manifest>
簡介: BFS 是一款專門為 Linux 桌面環境所設計的內核調度器,它基於 Staircase Deadline 和 EEVDF 算法,支持 Linux 2
開發出高效穩定的Android應用我們不得不需要了解下Java虛擬機的原理和內存分配機制,android使用的是Google經過優化的Dalvik Java VM。通常
簡介: 本文詳細介紹了 Android 應用編程中 Activity 的生命周期、通信方式和 Intent Filter 等內容,並提供了一些日常開發中經常用
簡介: 有幾個網站從事一些非盈利服務,提供一些可輕松設置和使用的表單來進行民意測驗和數據收集。本教程介紹一個簡單的架構來為 android 設計類似的應用程