From ea370609f2d174a59f8dafd5ddd229c5c41da940 Mon Sep 17 00:00:00 2001 From: Marius Gavrilescu Date: Tue, 18 Jun 2013 17:04:18 +0300 Subject: [PATCH] Clean up previous commit --- .pmd | 4 --- .../ieval/unical/AlarmReceiverActivity.java | 33 ++++++++----------- src/ro/ieval/unical/Utils.java | 8 ++--- 3 files changed, 17 insertions(+), 28 deletions(-) diff --git a/.pmd b/.pmd index 6a82507..7edda50 100644 --- a/.pmd +++ b/.pmd @@ -111,10 +111,6 @@ AvoidMultipleUnaryOperators Basic Rules - - AvoidPrintStackTrace - Java Logging Rules - AvoidProtectedFieldInFinalClass Design Rules diff --git a/src/ro/ieval/unical/AlarmReceiverActivity.java b/src/ro/ieval/unical/AlarmReceiverActivity.java index 8f5fca0..d96a5af 100644 --- a/src/ro/ieval/unical/AlarmReceiverActivity.java +++ b/src/ro/ieval/unical/AlarmReceiverActivity.java @@ -20,15 +20,16 @@ public class AlarmReceiverActivity extends Activity { private MediaPlayer mMediaPlayer; @Override - public void onCreate(Bundle savedInstanceState) { + public void onCreate(final 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); + final Button stopAlarm = (Button) findViewById(R.id.stopAlarm); stopAlarm.setOnTouchListener(new OnTouchListener() { - public boolean onTouch(View arg0, MotionEvent arg1) { + @Override + public boolean onTouch(final View arg0, final MotionEvent arg1) { mMediaPlayer.stop(); finish(); return false; @@ -38,7 +39,7 @@ public class AlarmReceiverActivity extends Activity { playSound(this, getAlarmUri()); } - private void playSound(Context context, Uri alert) { + private void playSound(final Context context, final Uri alert) { mMediaPlayer = new MediaPlayer(); try { mMediaPlayer.setDataSource(context, alert); @@ -50,23 +51,17 @@ public class AlarmReceiverActivity extends Activity { mMediaPlayer.start(); } } catch (IOException e) { - System.out.println("OOPS"); + e.printStackTrace(); } } - - //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); - } - } + + private static 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; } } diff --git a/src/ro/ieval/unical/Utils.java b/src/ro/ieval/unical/Utils.java index 73e2737..df57cda 100644 --- a/src/ro/ieval/unical/Utils.java +++ b/src/ro/ieval/unical/Utils.java @@ -3,7 +3,6 @@ package ro.ieval.unical; import java.util.GregorianCalendar; import java.util.Locale; -import android.app.Activity; import android.app.AlarmManager; import android.app.PendingIntent; import android.content.Context; @@ -27,10 +26,9 @@ final class Utils { return String.format(Locale.ENGLISH, "%4d-%02d-%02d", year, month, day); } - public static void setAlarm(GregorianCalendar cal,Context context) { - Intent in = new Intent(context,AlarmReceiverActivity.class); - PendingIntent pi = PendingIntent.getActivity(context, 1234, in, PendingIntent.FLAG_CANCEL_CURRENT); - AlarmManager am = (AlarmManager)context.getSystemService(Activity.ALARM_SERVICE); + public static void setAlarm(final GregorianCalendar cal, final Context context) { + final PendingIntent pi = PendingIntent.getActivity(context, 1234, new Intent(context, AlarmReceiverActivity.class), PendingIntent.FLAG_CANCEL_CURRENT); + final AlarmManager am = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE); am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), pi); } } -- 2.39.2