mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-11 13:33:07 +02:00
Removed mytracks prefix from files and variables.
Moved colors to colors.xml. Code clean-up and more documentation.
This commit is contained in:
@@ -107,7 +107,7 @@ limitations under the License.
|
|||||||
</intent-filter>
|
</intent-filter>
|
||||||
</receiver>
|
</receiver>
|
||||||
|
|
||||||
<receiver android:name="com.google.android.apps.mytracks.widgets.MyTracksAppWidgetProvider">
|
<receiver android:name="com.google.android.apps.mytracks.widgets.AppWidgetProvider">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
|
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
|
||||||
<action android:name="com.google.android.apps.mytracks.TRACK_STARTED" />
|
<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" />
|
<action android:name="com.google.android.apps.mytracks.TRACK_UPDATED" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
<meta-data android:name="android.appwidget.provider"
|
<meta-data android:name="android.appwidget.provider"
|
||||||
android:resource="@xml/mytracks_appwidget_info" />
|
android:resource="@xml/appwidget_info" />
|
||||||
</receiver>
|
</receiver>
|
||||||
</application>
|
</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
|
<LinearLayout
|
||||||
android:layout_height="fill_parent"
|
android:layout_height="fill_parent"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:background="@drawable/widget_background">
|
android:background="@drawable/appwidget_background">
|
||||||
<ImageButton
|
<ImageButton
|
||||||
android:id="@+id/mytracks_appwidget_button"
|
android:id="@+id/appwidget_button"
|
||||||
android:layout_height="fill_parent"
|
android:layout_height="fill_parent"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:background="@android:color/transparent"
|
android:background="@android:color/transparent"
|
||||||
android:paddingLeft="10px"
|
android:paddingLeft="10px"
|
||||||
android:paddingRight="10px"
|
android:paddingRight="10px"
|
||||||
android:src="@drawable/widget_button_disabled" />
|
android:src="@drawable/appwidget_button_disabled" />
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/statistics"
|
android:id="@+id/appwidget_track_statistics"
|
||||||
android:layout_height="fill_parent"
|
android:layout_height="fill_parent"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
@@ -48,62 +48,62 @@ limitations under the License.
|
|||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:orientation="horizontal">
|
android:orientation="horizontal">
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/mytracks_appwidget_distance_text"
|
android:id="@+id/appwidget_distance_text"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:textColor="#EDEDED"
|
android:textColor="@color/appwidget_text"
|
||||||
android:textSize="14sp"
|
android:textSize="14sp"
|
||||||
android:width="110px" />
|
android:width="110px" />
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:text="@string/total_distance_label"
|
android:text="@string/total_distance_label"
|
||||||
android:textColor="#EDEDED"
|
android:textColor="@color/appwidget_text"
|
||||||
android:textSize="14sp" />
|
android:textSize="14sp" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
<ImageView
|
<ImageView
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="1px"
|
android:layout_height="1px"
|
||||||
android:background="#99999999" />
|
android:background="@color/appwidget_hr" />
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
android:paddingBottom="2px">
|
android:paddingBottom="2px">
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/mytracks_appwidget_time_text"
|
android:id="@+id/appwidget_time_text"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:textColor="#EDEDED"
|
android:textColor="@color/appwidget_text"
|
||||||
android:textSize="14sp"
|
android:textSize="14sp"
|
||||||
android:width="110px" />
|
android:width="110px" />
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:text="@string/moving_time_label"
|
android:text="@string/moving_time_label"
|
||||||
android:textColor="#EDEDED"
|
android:textColor="@color/appwidget_text"
|
||||||
android:textSize="14sp" />
|
android:textSize="14sp" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
<ImageView
|
<ImageView
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="1px"
|
android:layout_height="1px"
|
||||||
android:background="#99999999" />
|
android:background="@color/appwidget_hr" />
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:orientation="horizontal">
|
android:orientation="horizontal">
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/mytracks_appwidget_speed_text"
|
android:id="@+id/appwidget_speed_text"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:textColor="#EDEDED"
|
android:textColor="@color/appwidget_text"
|
||||||
android:textSize="14sp"
|
android:textSize="14sp"
|
||||||
android:width="110px" />
|
android:width="110px" />
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:text="@string/average_moving_speed_label"
|
android:text="@string/average_moving_speed_label"
|
||||||
android:textColor="#EDEDED"
|
android:textColor="@color/appwidget_text"
|
||||||
android:textSize="14sp" />
|
android:textSize="14sp" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
@@ -47,4 +47,8 @@ limitations under the License.
|
|||||||
<!-- Purple and a transparent purple -->
|
<!-- Purple and a transparent purple -->
|
||||||
<color name="power_border">#FF401465</color>
|
<color name="power_border">#FF401465</color>
|
||||||
<color name="power_fill">#40401465</color>
|
<color name="power_fill">#40401465</color>
|
||||||
|
|
||||||
|
<!-- AppWidget colors -->
|
||||||
|
<color name="appwidget_text">#EDEDED</color>
|
||||||
|
<color name="appwidget_hr">#99999999</color>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ limitations under the License.
|
|||||||
-->
|
-->
|
||||||
<appwidget-provider
|
<appwidget-provider
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:initialLayout="@layout/mytracks_appwidget"
|
android:initialLayout="@layout/appwidget"
|
||||||
android:minHeight="72dp"
|
android:minHeight="72dp"
|
||||||
android:minWidth="294dp"
|
android:minWidth="294dp"
|
||||||
android:updatePeriodMillis="0" />
|
android:updatePeriodMillis="0" />
|
||||||
@@ -66,7 +66,7 @@ public class StringUtils implements DescriptionGenerator {
|
|||||||
return formatTimeInternal(time, true);
|
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
|
* 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
|
* @return A string representation of a decimal number, derived from the input
|
||||||
* double, with a single decimal place
|
* double, with a single decimal place
|
||||||
*/
|
*/
|
||||||
public static final String formatDecimal(double number) {
|
public static final String formatSingleDecimalPlace(double number) {
|
||||||
return DECIMAL_FORMAT.format(number);
|
return SINGLE_DECIMAL_PLACE_FORMAT.format(number);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+45
-44
@@ -18,7 +18,6 @@ package com.google.android.apps.mytracks.widgets;
|
|||||||
|
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.appwidget.AppWidgetManager;
|
import android.appwidget.AppWidgetManager;
|
||||||
import android.appwidget.AppWidgetProvider;
|
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@@ -39,7 +38,7 @@ import com.google.android.maps.mytracks.R;
|
|||||||
*
|
*
|
||||||
* @author Paul R. Saxman
|
* @author Paul R. Saxman
|
||||||
*/
|
*/
|
||||||
public class MyTracksAppWidgetProvider extends AppWidgetProvider {
|
public class AppWidgetProvider extends android.appwidget.AppWidgetProvider {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
super.onReceive(context, intent);
|
super.onReceive(context, intent);
|
||||||
@@ -64,10 +63,10 @@ public class MyTracksAppWidgetProvider extends AppWidgetProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
|
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
|
||||||
ComponentName widget = new ComponentName(context,
|
ComponentName widget =
|
||||||
MyTracksAppWidgetProvider.class);
|
new ComponentName(context, AppWidgetProvider.class);
|
||||||
RemoteViews views = new RemoteViews(context.getPackageName(),
|
RemoteViews views = new RemoteViews(context.getPackageName(),
|
||||||
R.layout.mytracks_appwidget);
|
R.layout.appwidget);
|
||||||
|
|
||||||
int[] appWidgetIds = appWidgetManager.getAppWidgetIds(widget);
|
int[] appWidgetIds = appWidgetManager.getAppWidgetIds(widget);
|
||||||
for (int appWidgetId : appWidgetIds) {
|
for (int appWidgetId : appWidgetIds) {
|
||||||
@@ -85,25 +84,26 @@ public class MyTracksAppWidgetProvider extends AppWidgetProvider {
|
|||||||
* @param action The action broadcast from the track service
|
* @param action The action broadcast from the track service
|
||||||
*/
|
*/
|
||||||
protected void updateViewButton(RemoteViews views, Context context, String action) {
|
protected void updateViewButton(RemoteViews views, Context context, String action) {
|
||||||
if (context.getString(R.string.track_started_broadcast_action).equals(action)
|
if (context.getString(R.string.track_started_broadcast_action).equals(action)) {
|
||||||
|| context.getString(R.string.track_updated_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 intent = new Intent(context, TrackRecordingService.class);
|
||||||
intent.setAction(context.getString(R.string.end_current_track_action));
|
intent.setAction(context.getString(R.string.end_current_track_action));
|
||||||
PendingIntent pendingIntent = PendingIntent.getService(context, 0,
|
PendingIntent pendingIntent = PendingIntent.getService(context, 0,
|
||||||
intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
views.setImageViewResource(R.id.mytracks_appwidget_button,
|
views.setImageViewResource(R.id.appwidget_button,
|
||||||
R.drawable.widget_button_enabled);
|
R.drawable.appwidget_button_enabled);
|
||||||
views.setOnClickPendingIntent(R.id.mytracks_appwidget_button,
|
views.setOnClickPendingIntent(R.id.appwidget_button, pendingIntent);
|
||||||
pendingIntent);
|
|
||||||
} else {
|
} 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 intent = new Intent(context, TrackRecordingService.class);
|
||||||
intent.setAction(context.getString(R.string.start_new_track_action));
|
intent.setAction(context.getString(R.string.start_new_track_action));
|
||||||
PendingIntent pendingIntent = PendingIntent.getService(context, 0,
|
PendingIntent pendingIntent = PendingIntent.getService(context, 0,
|
||||||
intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
views.setImageViewResource(R.id.mytracks_appwidget_button,
|
views.setImageViewResource(R.id.appwidget_button,
|
||||||
R.drawable.widget_button_disabled);
|
R.drawable.appwidget_button_disabled);
|
||||||
views.setOnClickPendingIntent(R.id.mytracks_appwidget_button,
|
views.setOnClickPendingIntent(R.id.appwidget_button, pendingIntent);
|
||||||
pendingIntent);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,36 +117,37 @@ public class MyTracksAppWidgetProvider extends AppWidgetProvider {
|
|||||||
*/
|
*/
|
||||||
protected void updateViewTrackStatistics(RemoteViews views, Track track,
|
protected void updateViewTrackStatistics(RemoteViews views, Track track,
|
||||||
Context context) {
|
Context context) {
|
||||||
String distance = "NA";
|
if (track == null) {
|
||||||
String time = "NA";
|
views.setTextViewText(R.id.appwidget_distance_text, "NA");
|
||||||
String speed = "NA";
|
views.setTextViewText(R.id.appwidget_time_text, "NA");
|
||||||
|
views.setTextViewText(R.id.appwidget_speed_text, "NA");
|
||||||
if (track != null) {
|
return;
|
||||||
// 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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
views.setTextViewText(R.id.mytracks_appwidget_distance_text, distance);
|
// TODO(saxman) Display stats details when track stats view is pressed.
|
||||||
views.setTextViewText(R.id.mytracks_appwidget_time_text, time);
|
// Intent i = new Intent(context, StatsActivity.class);
|
||||||
views.setTextViewText(R.id.mytracks_appwidget_speed_text, speed);
|
// 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user