]> iEval git - unical.git/blob - src/ro/ieval/unical/AlarmReceiverActivity.java
Edit event. work in progress[3]
[unical.git] / src / ro / ieval / unical / AlarmReceiverActivity.java
1 package ro.ieval.unical;
2
3 import java.io.IOException;
4
5 import android.app.Activity;
6 import android.content.Context;
7 import android.media.AudioManager;
8 import android.media.MediaPlayer;
9 import android.media.RingtoneManager;
10 import android.net.Uri;
11 import android.os.Bundle;
12 import android.view.MotionEvent;
13 import android.view.View;
14 import android.view.View.OnTouchListener;
15 import android.view.Window;
16 import android.view.WindowManager;
17 import android.widget.Button;
18
19 public class AlarmReceiverActivity extends Activity {
20 public static final String EXTRA_EVENT = "event";
21 private MediaPlayer mMediaPlayer;
22
23 @Override
24 public void onCreate(final Bundle savedInstanceState) {
25 super.onCreate(savedInstanceState);
26 this.requestWindowFeature(Window.FEATURE_NO_TITLE);
27 this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
28 setContentView(R.layout.alarm);
29
30 final Button stopAlarm = (Button) findViewById(R.id.stopAlarm);
31 stopAlarm.setOnTouchListener(new OnTouchListener() {
32 @Override
33 public boolean onTouch(final View arg0, final MotionEvent arg1) {
34 mMediaPlayer.stop();
35 finish();
36 return false;
37 }
38 });
39
40 playSound(this, getAlarmUri());
41 }
42
43 private void playSound(final Context context, final Uri alert) {
44 mMediaPlayer = new MediaPlayer();
45 try {
46 mMediaPlayer.setDataSource(context, alert);
47 final AudioManager audioManager = (AudioManager) context
48 .getSystemService(Context.AUDIO_SERVICE);
49 if (audioManager.getStreamVolume(AudioManager.STREAM_ALARM) != 0) {
50 mMediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
51 mMediaPlayer.prepare();
52 mMediaPlayer.start();
53 }
54 } catch (IOException e) {
55 e.printStackTrace();
56 }
57 }
58
59 private static Uri getAlarmUri() {
60 Uri alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
61 if (alert == null)
62 alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
63 if (alert == null)
64 alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
65
66 return alert;
67 }
68 }
This page took 0.046961 seconds and 4 git commands to generate.