mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-02 09:33:06 +02:00
Clean up code + add pace.
This commit is contained in:
@@ -180,7 +180,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/appwidget_info" />
|
||||
android:resource="@xml/track_widget_info" />
|
||||
</receiver>
|
||||
</application>
|
||||
|
||||
|
||||
@@ -48,18 +48,11 @@ limitations under the License.
|
||||
android:layout_width="fill_parent"
|
||||
android:orientation="horizontal">
|
||||
<TextView
|
||||
android:id="@+id/appwidget_distance_text"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="wrap_content"
|
||||
android:textColor="@color/appwidget_text"
|
||||
android:textSize="14sp"
|
||||
android:width="110px" />
|
||||
style="@style/WidgetText.Register"
|
||||
android:id="@+id/appwidget_distance_text" />
|
||||
<TextView
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="wrap_content"
|
||||
android:text="@string/total_distance_label"
|
||||
android:textColor="@color/appwidget_text"
|
||||
android:textSize="14sp" />
|
||||
style="@style/WidgetText"
|
||||
android:text="@string/total_distance_label" />
|
||||
</LinearLayout>
|
||||
<ImageView
|
||||
android:layout_width="fill_parent"
|
||||
@@ -71,18 +64,11 @@ limitations under the License.
|
||||
android:orientation="horizontal"
|
||||
android:paddingBottom="2px">
|
||||
<TextView
|
||||
android:id="@+id/appwidget_time_text"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="wrap_content"
|
||||
android:textColor="@color/appwidget_text"
|
||||
android:textSize="14sp"
|
||||
android:width="110px" />
|
||||
style="@style/WidgetText.Register"
|
||||
android:id="@+id/appwidget_time_text" />
|
||||
<TextView
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="wrap_content"
|
||||
android:text="@string/moving_time_label"
|
||||
android:textColor="@color/appwidget_text"
|
||||
android:textSize="14sp" />
|
||||
style="@style/WidgetText"
|
||||
android:text="@string/moving_time_label" />
|
||||
</LinearLayout>
|
||||
<ImageView
|
||||
android:layout_width="fill_parent"
|
||||
@@ -93,18 +79,11 @@ limitations under the License.
|
||||
android:layout_width="fill_parent"
|
||||
android:orientation="horizontal">
|
||||
<TextView
|
||||
android:id="@+id/appwidget_speed_text"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="wrap_content"
|
||||
android:textColor="@color/appwidget_text"
|
||||
android:textSize="14sp"
|
||||
android:width="110px" />
|
||||
style="@style/WidgetText.Register"
|
||||
android:id="@+id/appwidget_speed_text" />
|
||||
<TextView
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="wrap_content"
|
||||
android:text="@string/average_moving_speed_label"
|
||||
android:textColor="@color/appwidget_text"
|
||||
android:textSize="14sp" />
|
||||
style="@style/WidgetText"
|
||||
android:text="@string/speed" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
@@ -74,4 +74,15 @@ limitations under the License.
|
||||
<item name="android:layout_height">3dip</item>
|
||||
<item name="android:layout_width">fill_parent</item>
|
||||
</style>
|
||||
|
||||
<!-- The style for the track widget. -->
|
||||
<style name="WidgetText" parent="@android:Widget.TextView">
|
||||
<item name="android:layout_height">wrap_content</item>
|
||||
<item name="android:layout_width">wrap_content</item>
|
||||
<item name="android:textColor">@color/appwidget_text</item>
|
||||
<item name="android:textSize">14sp</item>
|
||||
</style>
|
||||
<style name="WidgetText.Register">
|
||||
<item name="android:width">160px</item>
|
||||
</style>
|
||||
</resources>
|
||||
@@ -16,7 +16,7 @@ limitations under the License.
|
||||
-->
|
||||
<appwidget-provider
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:initialLayout="@layout/appwidget"
|
||||
android:initialLayout="@layout/track_widget"
|
||||
android:minHeight="72dp"
|
||||
android:minWidth="294dp"
|
||||
android:updatePeriodMillis="0" />
|
||||
@@ -70,8 +70,10 @@ public class TrackWidgetProvider
|
||||
private String unknown;
|
||||
private String distance;
|
||||
private String speed;
|
||||
private String pace;
|
||||
private TrackObserver trackObserver;
|
||||
private boolean isMetric;
|
||||
private boolean reportSpeed;
|
||||
private long selectedTrackId;
|
||||
private SharedPreferences sharedPreferences;
|
||||
private String TRACK_STARTED_ACTION;
|
||||
@@ -141,7 +143,7 @@ public class TrackWidgetProvider
|
||||
|
||||
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
|
||||
ComponentName widget = new ComponentName(context, TrackWidgetProvider.class);
|
||||
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.appwidget);
|
||||
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.track_widget);
|
||||
|
||||
// Make all of the stats open the mytracks activity.
|
||||
Intent intent = new Intent(context, MyTracks.class);
|
||||
@@ -237,7 +239,12 @@ public class TrackWidgetProvider
|
||||
if (!isMetric) {
|
||||
displaySpeed *= UnitConversions.KMH_TO_MPH;
|
||||
}
|
||||
speed = StringUtils.formatSingleDecimalPlace(displaySpeed) + " " + this.speed;
|
||||
if (reportSpeed) {
|
||||
speed = StringUtils.formatSingleDecimalPlace(displaySpeed) + " " + this.speed;
|
||||
} else {
|
||||
long displayPace = (long) (3600000.0 / displaySpeed);
|
||||
speed = StringUtils.formatTime(displayPace) + " " + pace;
|
||||
}
|
||||
}
|
||||
|
||||
views.setTextViewText(R.id.appwidget_distance_text, distance);
|
||||
@@ -252,7 +259,14 @@ public class TrackWidgetProvider
|
||||
isMetric = prefs.getBoolean(metricUnitsKey, true);
|
||||
distance = context.getString(isMetric ? R.string.kilometer : R.string.mile);
|
||||
speed = context.getString(isMetric ? R.string.kilometer_per_hour : R.string.mile_per_hour);
|
||||
pace = context.getString(isMetric ? R.string.min_per_kilometer : R.string.min_per_mile);
|
||||
}
|
||||
|
||||
String reportSpeedKey = context.getString(R.string.report_speed_key);
|
||||
if (key == null || key.equals(reportSpeedKey)) {
|
||||
reportSpeed = prefs.getBoolean(reportSpeedKey, true);
|
||||
}
|
||||
|
||||
String selectedTrackKey = context.getString(R.string.selected_track_key);
|
||||
if (key == null || key.equals(selectedTrackKey)) {
|
||||
selectedTrackId = prefs.getLong(selectedTrackKey, -1);
|
||||
|
||||
Reference in New Issue
Block a user