Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Cleanup and Javadoc

  • Loading branch information...
commit b30000dc29651b25fb04ea9e6546b1178b929c01 1 parent 4212505
@vincentg authored
View
31 src/com/vg/hnc/rules/HNCCompute.java
@@ -2,16 +2,30 @@
import java.util.Calendar;
+
+/**
+ * Compute the restriction given a Calendar
+ * @author vincent
+ *
+ */
public class HNCCompute {
- Calendar cal;
- int dayOfWeek;
+ private final Calendar cal;
+ private final int dayOfWeek;
+ /**
+ * HNCCompute constructor
+ * @param calendar Instance of Calendar
+ */
public HNCCompute(Calendar calendar) {
this.cal = calendar;
this.dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
}
+ /**
+ * Get the restriction for the current Calendar day
+ * @return HNCRestriction
+ */
public HNCRestriction getDay() {
switch (dayOfWeek) {
case Calendar.MONDAY:
@@ -31,10 +45,18 @@ public HNCRestriction getDay() {
return HNCRestriction.NONE;
}
+ /**
+ * Get the restriction for the next Calendar day
+ * @return HNCRestriction
+ */
public HNCRestriction getTomorrow() {
return getRestrictionInXDays(1);
}
+ /**
+ * Get the restriction for the next Saturday
+ * @return HNCRestriction
+ */
public HNCRestriction getNextSaturday() {
int daysToAdd;
if (dayOfWeek == Calendar.SATURDAY) {
@@ -45,6 +67,11 @@ public HNCRestriction getNextSaturday() {
return getRestrictionInXDays(daysToAdd);
}
+ /**
+ * Get the restriction for a day in the future
+ * @param days number of days in the future
+ * @return HNCRestriction
+ */
private HNCRestriction getRestrictionInXDays(int days) {
Calendar newCal = Calendar.getInstance();
newCal.add(Calendar.DAY_OF_YEAR, days);
View
16 src/com/vg/hnc/rules/HNCRestriction.java
@@ -2,8 +2,12 @@
import android.graphics.Color;
+/**
+ * Enum type to holds all the possible restrictions
+ * A restriction is composed by two value, a color and a String
+ * @author vincent
+ */
public enum HNCRestriction {
-
YELLOW (Color.YELLOW, "5-6"),
PINK (Color.argb(255, 255, 192, 203), "7-8"),
RED (Color.RED, "3-4"),
@@ -11,8 +15,14 @@
BLUE (Color.argb(255, 51, 204, 255), "9-0"),
NONE (Color.WHITE, "OK");
- private int color;
- private String lastDigits;
+ /**
+ * Color of the restriction
+ */
+ final private int color;
+ /**
+ * String to hold the last two digits
+ */
+ final private String lastDigits;
private HNCRestriction(int color, String lastDigits) {
this.color = color;
View
42 src/com/vg/hnc/widget/HNCWidget.java
@@ -10,38 +10,56 @@
import com.vg.hnc.rules.HNCCompute;
import com.vg.hnc.rules.HNCRestriction;
+/**
+ * Main Widget Entry point class
+ *
+ * @author vincent
+ *
+ */
public class HNCWidget extends AppWidgetProvider {
+ /**
+ * True if Android >= 2.2
+ */
private static final boolean isAdvanced = Build.VERSION.SDK_INT > 7;
- private HNCCompute c;
+ /**
+ * Update the widget contents periodically
+ * @see android.appwidget.AppWidgetProvider#onUpdate(android.content.Context, android.appwidget.AppWidgetManager, int[])
+ */
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
- c = new HNCCompute(Calendar.getInstance());
- RemoteViews updateView;
- updateView = new RemoteViews(context.getPackageName(), R.layout.main);
-
+ final HNCCompute c = new HNCCompute(Calendar.getInstance());
+ final RemoteViews updateView =
+ new RemoteViews(context.getPackageName(), R.layout.main);
+ // Update for Today, Tomorrow, NextSaturday
updateRestriction(updateView, R.id.hnc_hoy, c.getDay());
updateRestriction(updateView, R.id.hnc_mna, c.getTomorrow());
updateRestriction(updateView, R.id.hnc_prox, c.getNextSaturday());
- /*
- Intent clickservice = new Intent(context, ClickService.class);
- clickservice.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIds);
-
- PendingIntent p = PendingIntent.getService(context, 0, clickservice , 0);
- updateView.setOnClickPendingIntent(R.id.otro, p);
- */
+ // Apply
appWidgetManager.updateAppWidget(appWidgetIds, updateView);
}
+ /**
+ * Sets the text and background of the view with the provided restriction data
+ * @param rv Remote View
+ * @param viewId View to update
+ * @param restriction Restriction to be applied
+ */
private void updateRestriction(RemoteViews rv, int viewId, HNCRestriction restriction) {
rv.setTextViewText(viewId, restriction.getLastDigits());
setTextBGColor(rv, viewId , restriction.getColor());
}
+ /**
+ * Sets the Background color on Android >= 2.2, elsewise, the text color.
+ * @param rv RemoteView
+ * @param viewId TextViewId to update
+ * @param color Color
+ */
private void setTextBGColor(RemoteViews rv, int viewId, int color) {
if (isAdvanced) {
rv.setInt(viewId, "setBackgroundColor", color);
Please sign in to comment.
Something went wrong with that request. Please try again.