--- /dev/null
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:orientation="vertical"
+ android:gravity="center" >
+
+ <Button
+ android:id="@+id/stopAlarm"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/stop_alarm" />
+
+</RelativeLayout>
\ No newline at end of file
--- /dev/null
+package ro.ieval.unical;
+
+import java.util.GregorianCalendar;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.view.Window;
+
+public class AlarmActivity extends Activity {
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ this.requestWindowFeature(Window.FEATURE_NO_TITLE);
+ setContentView(layoutResID);
+
+ GregorianCalendar cal = (GregorianCalendar) GregorianCalendar.getInstance();
+ cal.add(GregorianCalendar.SECOND, 5);
+ }
+}
--- /dev/null
+package ro.ieval.unical;
+
+import java.io.IOException;
+
+import android.app.Activity;
+import android.content.Context;
+import android.media.AudioManager;
+import android.media.MediaPlayer;
+import android.media.RingtoneManager;
+import android.net.Uri;
+import android.os.Bundle;
+import android.view.MotionEvent;
+import android.view.View;
+import android.view.View.OnTouchListener;
+import android.view.Window;
+import android.view.WindowManager;
+import android.widget.Button;
+
+public class AlarmReceiverActivity extends Activity {
+ private MediaPlayer mMediaPlayer;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ this.requestWindowFeature(Window.FEATURE_NO_TITLE);
+ this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
+ setContentView(R.layout.alarm);
+
+ Button stopAlarm = (Button) findViewById(R.id.stopAlarm);
+ stopAlarm.setOnTouchListener(new OnTouchListener() {
+ public boolean onTouch(View arg0, MotionEvent arg1) {
+ mMediaPlayer.stop();
+ finish();
+ return false;
+ }
+ });
+
+ playSound(this, getAlarmUri());
+ }
+
+ private void playSound(Context context, Uri alert) {
+ mMediaPlayer = new MediaPlayer();
+ try {
+ mMediaPlayer.setDataSource(context, alert);
+ final AudioManager audioManager = (AudioManager) context
+ .getSystemService(Context.AUDIO_SERVICE);
+ if (audioManager.getStreamVolume(AudioManager.STREAM_ALARM) != 0) {
+ mMediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
+ mMediaPlayer.prepare();
+ mMediaPlayer.start();
+ }
+ } catch (IOException e) {
+ System.out.println("OOPS");
+ }
+ }
+
+ //Get an alarm sound. Try for an alarm. If none set, try notification,
+ //Otherwise, ringtone.
+ private Uri getAlarmUri() {
+ Uri alert = RingtoneManager
+ .getDefaultUri(RingtoneManager.TYPE_ALARM);
+ if (alert == null) {
+ alert = RingtoneManager
+ .getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
+ if (alert == null) {
+ alert = RingtoneManager
+ .getDefaultUri(RingtoneManager.TYPE_RINGTONE);
+ }
+ }
+ return alert;
+ }
+}