]> iEval git - unical.git/blame - src/ro/ieval/unical/AlarmReceiverActivity.java
Edit event. work in progress[3]
[unical.git] / src / ro / ieval / unical / AlarmReceiverActivity.java
CommitLineData
e2332327
PT
1package ro.ieval.unical;
2
3import java.io.IOException;
4
5import android.app.Activity;
6import android.content.Context;
7import android.media.AudioManager;
8import android.media.MediaPlayer;
9import android.media.RingtoneManager;
10import android.net.Uri;
11import android.os.Bundle;
12import android.view.MotionEvent;
13import android.view.View;
14import android.view.View.OnTouchListener;
15import android.view.Window;
16import android.view.WindowManager;
17import android.widget.Button;
18
19public class AlarmReceiverActivity extends Activity {
57ca4051 20 public static final String EXTRA_EVENT = "event";
e2332327 21 private MediaPlayer mMediaPlayer;
57ca4051 22
e2332327 23 @Override
ea370609 24 public void onCreate(final Bundle savedInstanceState) {
e2332327
PT
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
ea370609 30 final Button stopAlarm = (Button) findViewById(R.id.stopAlarm);
e2332327 31 stopAlarm.setOnTouchListener(new OnTouchListener() {
ea370609
MG
32 @Override
33 public boolean onTouch(final View arg0, final MotionEvent arg1) {
e2332327
PT
34 mMediaPlayer.stop();
35 finish();
36 return false;
37 }
38 });
39
40 playSound(this, getAlarmUri());
41 }
42
ea370609 43 private void playSound(final Context context, final Uri alert) {
e2332327
PT
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) {
ea370609 55 e.printStackTrace();
e2332327
PT
56 }
57 }
ea370609
MG
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
e2332327
PT
66 return alert;
67 }
68}
This page took 0.025052 seconds and 4 git commands to generate.