update app widget layout

This commit is contained in:
Jimmy Shih
2012-10-02 14:30:53 -07:00
parent 7240d02c06
commit 5db20b48ca
9 changed files with 539 additions and 272 deletions
@@ -33,7 +33,7 @@ import java.util.regex.Pattern;
/**
* Various string manipulation methods.
*
*
* @author Sandor Dornbush
* @author Rodrigo Damazio
*/
@@ -64,7 +64,8 @@ public class StringUtils {
}
/**
* Formats the relative date and time based on user's phone date/time preferences.
* Formats the relative date and time based on user's phone date/time
* preferences.
*
* @param context the context
* @param time the time in milliseconds
@@ -74,15 +75,15 @@ public class StringUtils {
if (now - time > DateUtils.WEEK_IN_MILLIS) {
return formatDateTime(context, time);
} else {
return DateUtils.getRelativeTimeSpanString(time, now, DateUtils.MINUTE_IN_MILLIS,
DateUtils.FORMAT_ABBREV_RELATIVE).toString();
return DateUtils.getRelativeTimeSpanString(
time, now, DateUtils.MINUTE_IN_MILLIS, DateUtils.FORMAT_ABBREV_RELATIVE).toString();
}
}
/**
* Formats the time using the ISO 8601 date time format with fractional
* seconds in UTC time zone.
*
*
* @param time the time in milliseconds
*/
public static String formatDateTimeIso8601(long time) {
@@ -91,7 +92,7 @@ public class StringUtils {
/**
* Formats the elapsed timed in the form "MM:SS" or "H:MM:SS".
*
*
* @param time the time in milliseconds
*/
public static String formatElapsedTime(long time) {
@@ -100,7 +101,7 @@ public class StringUtils {
/**
* Formats the elapsed time in the form "H:MM:SS".
*
*
* @param time the time in milliseconds
*/
public static String formatElapsedTimeWithHour(long time) {
@@ -136,7 +137,45 @@ public class StringUtils {
}
}
}
/**
* Gets the distance in an array of two strings. The first string is the
* distance. The second string is the unit.
*
* @param context the context
* @param distance the distance
* @param metricUnits true to use metric unit
*/
public static String[] getDistanceParts(Context context, double distance, boolean metricUnits) {
String[] result = new String[2];
if (Double.isNaN(distance) || Double.isInfinite(distance)) {
result[0] = context.getString(R.string.value_unknown);
result[1] = context.getString(metricUnits ? R.string.unit_meter : R.string.unit_feet);
return result;
}
int unitId;
if (metricUnits) {
if (distance > 500.0) {
distance *= UnitConversions.M_TO_KM;
unitId = R.string.unit_kilometer;
} else {
unitId = R.string.unit_meter;
}
} else {
if (distance * UnitConversions.M_TO_MI > 0.5) {
distance *= UnitConversions.M_TO_MI;
unitId = R.string.unit_mile;
} else {
distance *= UnitConversions.M_TO_FT;
unitId = R.string.unit_feet;
}
}
result[0] = String.format("%.2f", distance);
result[1] = context.getString(unitId);
return result;
}
/**
* Formats the speed.
*
@@ -171,11 +210,51 @@ public class StringUtils {
}
}
/**
* Gets the speed in an array of two strings. The first string is the
* speed. The second string is the unit.
*
* @param context the context
* @param speed the speed
* @param metricUnits true to use metric unit
* @param reportSpeed true to report speed
*/
public static String[] getSpeedParts(
Context context, double speed, boolean metricUnits, boolean reportSpeed) {
String[] result = new String[2];
int unitId;
if (metricUnits) {
unitId = reportSpeed ? R.string.unit_kilometer_per_hour : R.string.unit_minute_per_kilometer;
} else {
unitId = reportSpeed ? R.string.unit_mile_per_hour : R.string.unit_minute_per_mile;
}
result[1] = context.getString(unitId);
if (Double.isNaN(speed) || Double.isInfinite(speed)) {
result[0] = context.getString(R.string.value_unknown);
return result;
}
speed *= UnitConversions.MS_TO_KMH;
if (metricUnits) {
if (!reportSpeed) {
// convert from hours to minutes
speed = speed == 0 ? 0.0 : 60.0 / speed;
}
} else {
speed *= UnitConversions.KM_TO_MI;
if (!reportSpeed) {
// convert from hours to minutes
speed = speed == 0 ? 0.0 : 60.0 / speed;
}
}
result[0] = String.format("%.2f", speed);
return result;
}
/**
* Formats the given text as a XML CDATA element. This includes adding the
* starting and ending CDATA tags. Please notice that this may result in
* multiple consecutive CDATA tags.
*
*
* @param text the given text
*/
public static String formatCData(String text) {
@@ -185,7 +264,7 @@ public class StringUtils {
/**
* Gets the time, in milliseconds, from an XML date time string as defined at
* http://www.w3.org/TR/xmlschema-2/#dateTime
*
*
* @param xmlDateTime the XML date time string
*/
public static long getTime(String xmlDateTime) {
@@ -193,8 +272,9 @@ public class StringUtils {
ParsePosition position = new ParsePosition(0);
Date date = ISO_8601_BASE.parse(xmlDateTime, position);
if (date == null) {
throw new IllegalArgumentException("Invalid XML dateTime value: " + xmlDateTime
+ " (at position " + position.getErrorIndex() + ")"); }
throw new IllegalArgumentException("Invalid XML dateTime value: " + xmlDateTime
+ " (at position " + position.getErrorIndex() + ")");
}
// Parse the date time extras
Matcher matcher = ISO_8601_EXTRAS.matcher(xmlDateTime.substring(position.getIndex()));
@@ -246,7 +326,7 @@ public class StringUtils {
* Gets the time as an array of three integers. Index 0 contains the number of
* seconds, index 1 contains the number of minutes, and index 2 contains the
* number of hours.
*
*
* @param time the time in milliseconds
* @return an array of 3 elements.
*/
@@ -284,7 +364,6 @@ public class StringUtils {
return Html.fromHtml(context.getString(resId, args));
}
/**
* Gets the frequency display options.
*
@@ -299,8 +378,9 @@ public class StringUtils {
if (value == PreferencesUtils.FREQUENCY_OFF) {
options[i] = context.getString(R.string.value_off);
} else if (value < 0) {
options[i] = context.getString(metricUnits ? R.string.value_integer_kilometer
: R.string.value_integer_mile, Math.abs(value));
options[i] = context.getString(
metricUnits ? R.string.value_integer_kilometer : R.string.value_integer_mile,
Math.abs(value));
} else {
options[i] = context.getString(R.string.value_integer_minute, value);
}