]> iEval git - unical.git/commitdiff
Add alarm to events. work in progress
authorPetru Trimbitas <l3asketballplayer@yahoo.com>
Mon, 17 Jun 2013 17:13:02 +0000 (20:13 +0300)
committerPetru Trimbitas <l3asketballplayer@yahoo.com>
Mon, 17 Jun 2013 17:13:02 +0000 (20:13 +0300)
AndroidManifest.xml
res/layout/alarm.xml [new file with mode: 0644]
res/values/strings.xml
src/ro/ieval/unical/AlarmActivity.java [new file with mode: 0644]
src/ro/ieval/unical/AlarmReceiverActivity.java [new file with mode: 0644]

index f87c534d44149f284b66db323447589aac7667e5..b9e4f6a342737e5468108029c7b7ff11a908d635 100644 (file)
@@ -25,6 +25,7 @@
         </activity>
         <activity android:name=".AddEventActivity"></activity>
         <activity android:name=".DisplayEventActivity"></activity>
+        <activity android:name=".AlarmReceiverActivity"></activity>
     </application>
 
 </manifest>
\ No newline at end of file
diff --git a/res/layout/alarm.xml b/res/layout/alarm.xml
new file mode 100644 (file)
index 0000000..ce2e6f8
--- /dev/null
@@ -0,0 +1,13 @@
+<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
index 6c0ba0740e88356129d87379856ec24a57f741fd..9568417392359cd2423fcac2d91b5ed3218fcbcc 100644 (file)
@@ -46,6 +46,7 @@
     <string name="year">year</string>
     <string name="years">years</string>
     <string name="refresh">Refresh</string>
+    <string name="stop_alarm">Stop Alarm</string>
 
     <string-array name="repeat_array_s">
         <item>Day</item>
diff --git a/src/ro/ieval/unical/AlarmActivity.java b/src/ro/ieval/unical/AlarmActivity.java
new file mode 100644 (file)
index 0000000..2868764
--- /dev/null
@@ -0,0 +1,19 @@
+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);
+       }
+}
diff --git a/src/ro/ieval/unical/AlarmReceiverActivity.java b/src/ro/ieval/unical/AlarmReceiverActivity.java
new file mode 100644 (file)
index 0000000..8f5fca0
--- /dev/null
@@ -0,0 +1,72 @@
+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;
+    }
+}
This page took 0.023722 seconds and 4 git commands to generate.