コード例 #1
0
ファイル: AlertPlayer.java プロジェクト: bklinker/NightWatch
 private static int getAlertProfile(Context ctx) {
   SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
   String profile = prefs.getString("bg_alert_profile", "ascending");
   if (profile.equals("High")) {
     Log.i(TAG, "getAlertProfile returning ALERT_PROFILE_HIGH");
     return ALERT_PROFILE_HIGH;
   }
   if (profile.equals("ascending")) {
     Log.i(TAG, "getAlertProfile returning ALERT_PROFILE_ASCENDING");
     return ALERT_PROFILE_ASCENDING;
   }
   if (profile.equals("medium")) {
     Log.i(TAG, "getAlertProfile returning ALERT_PROFILE_MEDIUM");
     return ALERT_PROFILE_MEDIUM;
   }
   if (profile.equals("vibrate only")) {
     Log.i(TAG, "getAlertProfile returning ALERT_PROFILE_VIBRATE_ONLY");
     return ALERT_PROFILE_VIBRATE_ONLY;
   }
   if (profile.equals("Silent")) {
     Log.i(TAG, "getAlertProfile returning ALERT_PROFILE_SILENT");
     return ALERT_PROFILE_SILENT;
   }
   Log.wtf(TAG, "getAlertProfile unknown value " + profile + " ALERT_PROFILE_ASCENDING");
   return ALERT_PROFILE_ASCENDING;
 }
コード例 #2
0
ファイル: AlertPlayer.java プロジェクト: bklinker/NightWatch
 public synchronized void PreSnooze(Context ctx, String uuid, int repeatTime) {
   Log.i(TAG, "PreSnooze called repeatTime = " + repeatTime);
   stopAlert(ctx, true, false);
   ActiveBgAlert.Create(uuid, true, new Date().getTime() + repeatTime * 60000);
   ActiveBgAlert activeBgAlert = ActiveBgAlert.getOnly();
   if (activeBgAlert == null) {
     Log.wtf(TAG, "Just created the alert, where did it go...");
     return;
   }
   activeBgAlert.snooze(repeatTime);
 }
コード例 #3
0
ファイル: AlertPlayer.java プロジェクト: bklinker/NightWatch
  private void PlayFile(Context ctx, String FileName, float VolumeFrac) {
    Log.i(TAG, "PlayFile: called FileName = " + FileName);
    if (mediaPlayer != null) {
      Log.i(TAG, "ERROR, PlayFile:going to leak a mediaplayer !!!");
    }
    if (FileName != null && FileName.length() > 0) {
      mediaPlayer = MediaPlayer.create(ctx, Uri.parse(FileName), null);
    }
    if (mediaPlayer == null) {
      Log.i(
          TAG,
          "PlayFile: Creating mediaplayer with file " + FileName + " failed. using default alarm");
      mediaPlayer = MediaPlayer.create(ctx, R.raw.default_alert);
    }
    if (mediaPlayer != null) {
      AudioManager manager = (AudioManager) ctx.getSystemService(Context.AUDIO_SERVICE);
      int maxVolume = manager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
      volumeBeforeAlert = manager.getStreamVolume(AudioManager.STREAM_MUSIC);
      volumeForThisAlert = (int) (maxVolume * VolumeFrac);
      manager.setStreamVolume(AudioManager.STREAM_MUSIC, volumeForThisAlert, 0);
      context = ctx;

      mediaPlayer.setOnCompletionListener(
          new MediaPlayer.OnCompletionListener() {
            @Override
            public void onCompletion(MediaPlayer mp) {
              Log.i(TAG, "PlayFile: onCompletion called (finished playing) ");
              AudioManager manager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
              int currentVolume = manager.getStreamVolume(AudioManager.STREAM_MUSIC);
              if (volumeForThisAlert == currentVolume) {
                // If the user has changed the volume, don't change it again.
                manager.setStreamVolume(AudioManager.STREAM_MUSIC, volumeBeforeAlert, 0);
              }
            }
          });
      Log.i(TAG, "PlayFile: calling mediaPlayer.start() ");
      mediaPlayer.start();
    } else {
      // TODO, what should we do here???
      Log.wtf(TAG, "PlayFile: Starting an alert failed, what should we do !!!");
    }
  }