PageRenderTime 18ms CodeModel.GetById 14ms app.highlight 3ms RepoModel.GetById 0ms app.codeStats 1ms

/remindme/src/com/google/marvin/remindme/ReminderSpeakerActivity.java

http://eyes-free.googlecode.com/
Java | 71 lines | 53 code | 12 blank | 6 comment | 1 complexity | 344200b3e21f9e5866be212f3d253f5f MD5 | raw file
 1package com.google.marvin.remindme;
 2
 3import android.app.Activity;
 4import android.app.AlertDialog.Builder;
 5import android.content.DialogInterface;
 6import android.content.DialogInterface.OnClickListener;
 7import android.media.MediaPlayer;
 8import android.net.Uri;
 9import android.os.Bundle;
10
11public class ReminderSpeakerActivity extends Activity {
12
13  private ReminderSpeakerActivity self;
14  private boolean stopNow;
15
16
17
18  /** Called when the activity is first created. */
19  @Override
20  public void onCreate(Bundle savedInstanceState) {
21    super.onCreate(savedInstanceState);
22    self = this;
23    stopNow = false;
24    //if (reminderUriStr != null) {
25      class AlarmPlayer implements Runnable {
26        public void run() {
27          new MediaPlayer();
28		MediaPlayer mPlayer =
29              MediaPlayer.create(self, Uri.parse("/sdcard/remindme/note00.amr"));
30          mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
31            public void onCompletion(MediaPlayer mp) {
32              try {
33                Thread.sleep(3000);
34              } catch (InterruptedException e) {
35                // TODO Auto-generated catch block
36                e.printStackTrace();
37              }
38              if (!stopNow) {
39                new Thread(new AlarmPlayer()).start();
40              }
41            }
42          });
43          mPlayer.start();
44        }
45      }
46      displayDismissDialog();
47      new Thread(new AlarmPlayer()).start();
48  //  } else {
49//      finish();
50//    }
51  }
52
53  private void displayDismissDialog() {
54    Builder dismissDialog = new Builder(this);
55
56    String titleText = "Alarm";
57    dismissDialog.setTitle(titleText);
58    dismissDialog.setMessage("Press the DISMISS button to stop the alarm.");
59
60    dismissDialog.setNeutralButton("Dismiss", new OnClickListener() {
61      public void onClick(DialogInterface dialog, int which) {
62        stopNow = true;
63        finish();
64      }
65    });
66    dismissDialog.show();
67  }
68
69
70
71}