Removed mytracks prefix from files and variables.

Moved colors to colors.xml.
Code clean-up and more documentation.
This commit is contained in:
saxman
2011-04-25 09:00:39 -07:00
parent f1746b41a2
commit 7020b78faa
9 changed files with 70 additions and 65 deletions
+2 -2
View File
@@ -107,7 +107,7 @@ limitations under the License.
</intent-filter>
</receiver>
<receiver android:name="com.google.android.apps.mytracks.widgets.MyTracksAppWidgetProvider">
<receiver android:name="com.google.android.apps.mytracks.widgets.AppWidgetProvider">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
<action android:name="com.google.android.apps.mytracks.TRACK_STARTED" />
@@ -115,7 +115,7 @@ limitations under the License.
<action android:name="com.google.android.apps.mytracks.TRACK_UPDATED" />
</intent-filter>
<meta-data android:name="android.appwidget.provider"
android:resource="@xml/mytracks_appwidget_info" />
android:resource="@xml/appwidget_info" />
</receiver>
</application>

Before

Width:  |  Height:  |  Size: 2.9 KiB

After

Width:  |  Height:  |  Size: 2.9 KiB

Before

Width:  |  Height:  |  Size: 3.8 KiB

After

Width:  |  Height:  |  Size: 3.8 KiB

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 4.2 KiB

@@ -26,17 +26,17 @@ limitations under the License.
<LinearLayout
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:background="@drawable/widget_background">
android:background="@drawable/appwidget_background">
<ImageButton
android:id="@+id/mytracks_appwidget_button"
android:id="@+id/appwidget_button"
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:background="@android:color/transparent"
android:paddingLeft="10px"
android:paddingRight="10px"
android:src="@drawable/widget_button_disabled" />
android:src="@drawable/appwidget_button_disabled" />
<LinearLayout
android:id="@+id/statistics"
android:id="@+id/appwidget_track_statistics"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_weight="1"
@@ -48,62 +48,62 @@ limitations under the License.
android:layout_width="fill_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/mytracks_appwidget_distance_text"
android:id="@+id/appwidget_distance_text"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textColor="#EDEDED"
android:textColor="@color/appwidget_text"
android:textSize="14sp"
android:width="110px" />
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/total_distance_label"
android:textColor="#EDEDED"
android:textColor="@color/appwidget_text"
android:textSize="14sp" />
</LinearLayout>
<ImageView
android:layout_width="fill_parent"
android:layout_height="1px"
android:background="#99999999" />
android:background="@color/appwidget_hr" />
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:orientation="horizontal"
android:paddingBottom="2px">
<TextView
android:id="@+id/mytracks_appwidget_time_text"
android:id="@+id/appwidget_time_text"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textColor="#EDEDED"
android:textColor="@color/appwidget_text"
android:textSize="14sp"
android:width="110px" />
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/moving_time_label"
android:textColor="#EDEDED"
android:textColor="@color/appwidget_text"
android:textSize="14sp" />
</LinearLayout>
<ImageView
android:layout_width="fill_parent"
android:layout_height="1px"
android:background="#99999999" />
android:background="@color/appwidget_hr" />
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/mytracks_appwidget_speed_text"
android:id="@+id/appwidget_speed_text"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textColor="#EDEDED"
android:textColor="@color/appwidget_text"
android:textSize="14sp"
android:width="110px" />
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/average_moving_speed_label"
android:textColor="#EDEDED"
android:textColor="@color/appwidget_text"
android:textSize="14sp" />
</LinearLayout>
</LinearLayout>
+4
View File
@@ -47,4 +47,8 @@ limitations under the License.
<!-- Purple and a transparent purple -->
<color name="power_border">#FF401465</color>
<color name="power_fill">#40401465</color>
<!-- AppWidget colors -->
<color name="appwidget_text">#EDEDED</color>
<color name="appwidget_hr">#99999999</color>
</resources>
@@ -16,7 +16,7 @@ limitations under the License.
-->
<appwidget-provider
xmlns:android="http://schemas.android.com/apk/res/android"
android:initialLayout="@layout/mytracks_appwidget"
android:initialLayout="@layout/appwidget"
android:minHeight="72dp"
android:minWidth="294dp"
android:updatePeriodMillis="0" />
@@ -66,7 +66,7 @@ public class StringUtils implements DescriptionGenerator {
return formatTimeInternal(time, true);
}
private static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("#.#");
private static final DecimalFormat SINGLE_DECIMAL_PLACE_FORMAT = new DecimalFormat("#.#");
/**
* Formats a double precision number as decimal number with a single decimal
@@ -76,8 +76,8 @@ public class StringUtils implements DescriptionGenerator {
* @return A string representation of a decimal number, derived from the input
* double, with a single decimal place
*/
public static final String formatDecimal(double number) {
return DECIMAL_FORMAT.format(number);
public static final String formatSingleDecimalPlace(double number) {
return SINGLE_DECIMAL_PLACE_FORMAT.format(number);
}
/**
@@ -18,7 +18,6 @@ package com.google.android.apps.mytracks.widgets;
import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
@@ -39,7 +38,7 @@ import com.google.android.maps.mytracks.R;
*
* @author Paul R. Saxman
*/
public class MyTracksAppWidgetProvider extends AppWidgetProvider {
public class AppWidgetProvider extends android.appwidget.AppWidgetProvider {
@Override
public void onReceive(Context context, Intent intent) {
super.onReceive(context, intent);
@@ -64,10 +63,10 @@ public class MyTracksAppWidgetProvider extends AppWidgetProvider {
}
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
ComponentName widget = new ComponentName(context,
MyTracksAppWidgetProvider.class);
ComponentName widget =
new ComponentName(context, AppWidgetProvider.class);
RemoteViews views = new RemoteViews(context.getPackageName(),
R.layout.mytracks_appwidget);
R.layout.appwidget);
int[] appWidgetIds = appWidgetManager.getAppWidgetIds(widget);
for (int appWidgetId : appWidgetIds) {
@@ -85,25 +84,26 @@ public class MyTracksAppWidgetProvider extends AppWidgetProvider {
* @param action The action broadcast from the track service
*/
protected void updateViewButton(RemoteViews views, Context context, String action) {
if (context.getString(R.string.track_started_broadcast_action).equals(action)
|| context.getString(R.string.track_updated_broadcast_action).equals(action)) {
if (context.getString(R.string.track_started_broadcast_action).equals(action)) {
// If a new track is started by this appwidget or elsewhere,
// toggle the button to active and have it disable the track if pressed.
Intent intent = new Intent(context, TrackRecordingService.class);
intent.setAction(context.getString(R.string.end_current_track_action));
PendingIntent pendingIntent = PendingIntent.getService(context, 0,
intent, PendingIntent.FLAG_UPDATE_CURRENT);
views.setImageViewResource(R.id.mytracks_appwidget_button,
R.drawable.widget_button_enabled);
views.setOnClickPendingIntent(R.id.mytracks_appwidget_button,
pendingIntent);
views.setImageViewResource(R.id.appwidget_button,
R.drawable.appwidget_button_enabled);
views.setOnClickPendingIntent(R.id.appwidget_button, pendingIntent);
} else {
// If a track is stopped by this appwidget or elsewhere,
// toggle the button to inactive and have it start a new track if pressed.
Intent intent = new Intent(context, TrackRecordingService.class);
intent.setAction(context.getString(R.string.start_new_track_action));
PendingIntent pendingIntent = PendingIntent.getService(context, 0,
intent, PendingIntent.FLAG_UPDATE_CURRENT);
views.setImageViewResource(R.id.mytracks_appwidget_button,
R.drawable.widget_button_disabled);
views.setOnClickPendingIntent(R.id.mytracks_appwidget_button,
pendingIntent);
views.setImageViewResource(R.id.appwidget_button,
R.drawable.appwidget_button_disabled);
views.setOnClickPendingIntent(R.id.appwidget_button, pendingIntent);
}
}
@@ -117,36 +117,37 @@ public class MyTracksAppWidgetProvider extends AppWidgetProvider {
*/
protected void updateViewTrackStatistics(RemoteViews views, Track track,
Context context) {
String distance = "NA";
String time = "NA";
String speed = "NA";
if (track != null) {
// TODO(saxman) Re-enable once good strategy for displaying details is found.
// Since we have a track, display stats details if stats pressed
// Intent i = new Intent(context, StatsActivity.class);
// PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, i, 0);
// views.setOnClickPendingIntent(R.id.statistics, pendingIntent);
TripStatistics stats = track.getStatistics();
// convert meters to kilometers
distance = StringUtils.formatDecimal(stats.getTotalDistance() / 1000)
+ " " + context.getString(R.string.kilometer);
// convert ms to minutes
time = StringUtils.formatDecimal(stats.getMovingTime() / 60000d)
+ " mins";
if (!Double.isNaN(stats.getAverageMovingSpeed())) {
// convert m/s to km/h
speed = StringUtils.formatDecimal(stats.getAverageMovingSpeed() * 3.6)
+ " " + context.getString(R.string.kilometer_per_hour);
}
if (track == null) {
views.setTextViewText(R.id.appwidget_distance_text, "NA");
views.setTextViewText(R.id.appwidget_time_text, "NA");
views.setTextViewText(R.id.appwidget_speed_text, "NA");
return;
}
views.setTextViewText(R.id.mytracks_appwidget_distance_text, distance);
views.setTextViewText(R.id.mytracks_appwidget_time_text, time);
views.setTextViewText(R.id.mytracks_appwidget_speed_text, speed);
// TODO(saxman) Display stats details when track stats view is pressed.
// Intent i = new Intent(context, StatsActivity.class);
// PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, i, 0);
// views.setOnClickPendingIntent(R.id.appwidget_track_statistics, pendingIntent);
TripStatistics stats = track.getStatistics();
// convert meters to kilometers
String distance = StringUtils.formatSingleDecimalPlace(stats.getTotalDistance() / 1000)
+ " " + context.getString(R.string.kilometer);
// convert ms to minutes
String time = StringUtils.formatSingleDecimalPlace(stats.getMovingTime() / 60000d)
+ " mins";
String speed = "NA";
if (!Double.isNaN(stats.getAverageMovingSpeed())) {
// convert m/s to km/h
speed = StringUtils.formatSingleDecimalPlace(stats.getAverageMovingSpeed() * 3.6)
+ " " + context.getString(R.string.kilometer_per_hour);
}
views.setTextViewText(R.id.appwidget_distance_text, distance);
views.setTextViewText(R.id.appwidget_time_text, time);
views.setTextViewText(R.id.appwidget_speed_text, speed);
}
}