]>
Commit | Line | Data |
---|---|---|
e2332327 PT |
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 { | |
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 | } |