<name>AvoidMultipleUnaryOperators</name>
<ruleset>Basic Rules</ruleset>
</rule>
- <rule>
- <name>AvoidPrintStackTrace</name>
- <ruleset>Java Logging Rules</ruleset>
- </rule>
<rule>
<name>AvoidProtectedFieldInFinalClass</name>
<ruleset>Design Rules</ruleset>
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;
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);
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;
}
}
import java.util.GregorianCalendar;
import java.util.Locale;
-import android.app.Activity;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
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);
}
}