forked from upstream-mirrors/OpenTracks
Update app widget to support pause/resume.
This commit is contained in:
@@ -236,10 +236,7 @@ limitations under the License.
|
|||||||
<receiver android:name="com.google.android.apps.mytracks.widgets.TrackWidgetProvider" >
|
<receiver android:name="com.google.android.apps.mytracks.widgets.TrackWidgetProvider" >
|
||||||
<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_STOPPED" />
|
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
|
||||||
<meta-data
|
<meta-data
|
||||||
android:name="android.appwidget.provider"
|
android:name="android.appwidget.provider"
|
||||||
android:resource="@xml/track_widget_info" />
|
android:resource="@xml/track_widget_info" />
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 42 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 38 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 40 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 36 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 42 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 36 KiB |
@@ -1,29 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!--
|
|
||||||
Copyright 2012 Google Inc.
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
-->
|
|
||||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:shape="rectangle" >
|
|
||||||
<solid android:color="@android:color/transparent" />
|
|
||||||
<padding
|
|
||||||
android:bottom="8dp"
|
|
||||||
android:left="8dp"
|
|
||||||
android:right="8dp"
|
|
||||||
android:top="8dp" />
|
|
||||||
<corners android:radius="8dp" />
|
|
||||||
<stroke
|
|
||||||
android:color="@android:color/white"
|
|
||||||
android:width="2dp" />
|
|
||||||
</shape>
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!--
|
|
||||||
Copyright 2012 Google Inc.
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
-->
|
|
||||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:shape="rectangle" >
|
|
||||||
<solid android:color="@color/track_widget_red" />
|
|
||||||
<padding
|
|
||||||
android:bottom="8dp"
|
|
||||||
android:left="8dp"
|
|
||||||
android:right="8dp"
|
|
||||||
android:top="8dp" />
|
|
||||||
<corners android:radius="8dp" />
|
|
||||||
</shape>
|
|
||||||
@@ -15,94 +15,100 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
-->
|
-->
|
||||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:background="@drawable/track_widget_background"
|
||||||
android:layout_height="fill_parent"
|
android:layout_height="fill_parent"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:padding="@dimen/widget_margin" >
|
android:padding="@dimen/widget_margin" >
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:background="@drawable/track_widget_background"
|
|
||||||
android:layout_height="fill_parent"
|
android:layout_height="fill_parent"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:orientation="horizontal" >
|
android:orientation="vertical"
|
||||||
<ImageButton
|
android:paddingBottom="8dp"
|
||||||
android:background="@android:color/transparent"
|
android:paddingLeft="16dp"
|
||||||
android:contentDescription="@string/my_tracks_app_name"
|
android:paddingRight="16dp"
|
||||||
android:id="@+id/track_widget_icon"
|
android:paddingTop="8dp" >
|
||||||
android:layout_height="fill_parent"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:padding="8dp"
|
|
||||||
android:src="@drawable/my_tracks_icon" />
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:clickable="true"
|
android:clickable="true"
|
||||||
android:id="@+id/track_widget_statistics"
|
android:id="@+id/track_widget_statistics"
|
||||||
android:layout_height="fill_parent"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_width="fill_parent"
|
||||||
android:layout_width="0dp"
|
android:orientation="vertical" >
|
||||||
android:orientation="vertical"
|
|
||||||
android:paddingLeft="8dp" >
|
|
||||||
<LinearLayout style="@style/TrackWidgetStat" >
|
<LinearLayout style="@style/TrackWidgetStat" >
|
||||||
<TextView
|
|
||||||
android:id="@+id/track_widget_distance_value"
|
|
||||||
style="@style/TrackWidgetValue" />
|
|
||||||
<TextView
|
<TextView
|
||||||
android:text="@string/stats_total_distance"
|
android:text="@string/stats_total_distance"
|
||||||
style="@style/TrackWidgetLabel" />
|
style="@style/TrackWidgetLabel" />
|
||||||
|
<TextView style="@style/TrackWidgetSpacer" />
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/track_widget_total_distance_value"
|
||||||
|
style="@style/TrackWidgetLabel" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
<LinearLayout style="@style/TrackWidgetSeparator" />
|
<LinearLayout style="@style/TrackWidgetSeparator" />
|
||||||
<LinearLayout style="@style/TrackWidgetStat" >
|
<LinearLayout style="@style/TrackWidgetStat" >
|
||||||
<TextView
|
|
||||||
android:id="@+id/track_widget_total_time_value"
|
|
||||||
style="@style/TrackWidgetValue" />
|
|
||||||
<TextView
|
<TextView
|
||||||
android:text="@string/stats_total_time"
|
android:text="@string/stats_total_time"
|
||||||
style="@style/TrackWidgetLabel" />
|
style="@style/TrackWidgetLabel" />
|
||||||
|
<TextView style="@style/TrackWidgetSpacer" />
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/track_widget_total_time_value"
|
||||||
|
style="@style/TrackWidgetLabel" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
<LinearLayout style="@style/TrackWidgetSeparator" />
|
<LinearLayout style="@style/TrackWidgetSeparator" />
|
||||||
<LinearLayout style="@style/TrackWidgetStat" >
|
<LinearLayout style="@style/TrackWidgetStat" >
|
||||||
<TextView
|
|
||||||
android:id="@+id/track_widget_average_speed_value"
|
|
||||||
style="@style/TrackWidgetValue" />
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/track_widget_average_speed_label"
|
android:id="@+id/track_widget_average_speed_label"
|
||||||
style="@style/TrackWidgetLabel" />
|
style="@style/TrackWidgetLabel" />
|
||||||
</LinearLayout>
|
<TextView style="@style/TrackWidgetSpacer" />
|
||||||
<LinearLayout
|
|
||||||
android:id="@+id/track_widget_moving_time_separator"
|
|
||||||
style="@style/TrackWidgetSeparator" />
|
|
||||||
<LinearLayout
|
|
||||||
android:id="@+id/track_widget_moving_time_stat"
|
|
||||||
style="@style/TrackWidgetStat" >
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/track_widget_moving_time_value"
|
android:id="@+id/track_widget_average_speed_value"
|
||||||
style="@style/TrackWidgetValue" />
|
|
||||||
<TextView
|
|
||||||
android:text="@string/stats_moving_time"
|
|
||||||
style="@style/TrackWidgetLabel" />
|
style="@style/TrackWidgetLabel" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/track_widget_average_moving_speed_separator"
|
android:id="@+id/track_widget_moving_time_container"
|
||||||
style="@style/TrackWidgetSeparator" />
|
android:layout_height="wrap_content"
|
||||||
<LinearLayout
|
android:layout_width="fill_parent"
|
||||||
android:id="@+id/track_widget_average_moving_speed_stat"
|
android:orientation="vertical" >
|
||||||
style="@style/TrackWidgetStat" >
|
<LinearLayout style="@style/TrackWidgetSeparator" />
|
||||||
<TextView
|
<LinearLayout style="@style/TrackWidgetStat" >
|
||||||
android:id="@+id/track_widget_average_moving_speed_value"
|
<TextView
|
||||||
style="@style/TrackWidgetValue" />
|
android:text="@string/stats_moving_time"
|
||||||
<TextView
|
style="@style/TrackWidgetLabel" />
|
||||||
android:id="@+id/track_widget_average_moving_speed_label"
|
<TextView style="@style/TrackWidgetSpacer" />
|
||||||
style="@style/TrackWidgetLabel" />
|
<TextView
|
||||||
|
android:id="@+id/track_widget_moving_time_value"
|
||||||
|
style="@style/TrackWidgetLabel" />
|
||||||
|
</LinearLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
</LinearLayout>
|
||||||
|
<LinearLayout
|
||||||
|
android:clipChildren="false"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:paddingLeft="4dp"
|
||||||
|
android:paddingRight="4dp"
|
||||||
|
android:paddingTop="4dp" >
|
||||||
<ImageButton
|
<ImageButton
|
||||||
android:background="@drawable/track_widget_record_button_background"
|
android:background="@android:color/transparent"
|
||||||
android:contentDescription="@string/icon_record_track"
|
android:contentDescription="@string/icon_record_track"
|
||||||
android:id="@+id/track_widget_record_button"
|
android:id="@+id/track_widget_record_button"
|
||||||
android:src="@drawable/track_widget_record_button"
|
android:layout_height="wrap_content"
|
||||||
style="@style/TrackWidgetButton" />
|
android:layout_width="wrap_content"
|
||||||
|
android:src="@drawable/btn_record" />
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/track_widget_record_status"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:singleLine="true"
|
||||||
|
style="@style/TextSmall" />
|
||||||
<ImageButton
|
<ImageButton
|
||||||
android:background="@drawable/track_widget_stop_button_background"
|
android:background="@android:color/transparent"
|
||||||
android:contentDescription="@string/icon_stop_recording"
|
android:contentDescription="@string/icon_stop_recording"
|
||||||
android:id="@+id/track_widget_stop_button"
|
android:id="@+id/track_widget_stop_button"
|
||||||
android:src="@drawable/track_widget_stop_button"
|
android:layout_height="wrap_content"
|
||||||
style="@style/TrackWidgetButton" />
|
android:layout_width="wrap_content"
|
||||||
|
android:src="@drawable/btn_stop_0" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
@@ -94,7 +94,8 @@ Google은 이용자에 대한 위치정보의 이용∙제공사실을 위치정
|
|||||||
<string name="settings_recording_track_name_location_value">LOCATION</string>
|
<string name="settings_recording_track_name_location_value">LOCATION</string>
|
||||||
<string name="settings_recording_track_name_number_value">NUMBER</string>
|
<string name="settings_recording_track_name_number_value">NUMBER</string>
|
||||||
<string name="track_action_end">com.google.android.apps.mytracks.END_CURRENT_TRACK</string>
|
<string name="track_action_end">com.google.android.apps.mytracks.END_CURRENT_TRACK</string>
|
||||||
<string name="track_action_save">android.intent.action.SAVE</string>
|
<string name="track_action_pause">com.google.android.apps.mytracks.PAUSE_CURRENT_TRACK</string>
|
||||||
|
<string name="track_action_resume">com.google.android.apps.mytracks.RESUME_CURRENT_TRACK</string>
|
||||||
<string name="track_action_start">com.google.android.apps.mytracks.START_NEW_TRACK</string>
|
<string name="track_action_start">com.google.android.apps.mytracks.START_NEW_TRACK</string>
|
||||||
<string name="value_unknown">-</string>
|
<string name="value_unknown">-</string>
|
||||||
</resources>
|
</resources>
|
||||||
@@ -192,17 +192,11 @@ limitations under the License.
|
|||||||
<item name="android:layout_width">fill_parent</item>
|
<item name="android:layout_width">fill_parent</item>
|
||||||
<item name="android:orientation">vertical</item>
|
<item name="android:orientation">vertical</item>
|
||||||
</style>
|
</style>
|
||||||
<!-- The style for the track widget button -->
|
|
||||||
<style name="TrackWidgetButton">
|
|
||||||
<item name="android:layout_gravity">center_horizontal</item>
|
|
||||||
<item name="android:layout_height">wrap_content</item>
|
|
||||||
<item name="android:layout_marginTop">8dp</item>
|
|
||||||
<item name="android:layout_width">fill_parent</item>
|
|
||||||
<item name="android:padding">8dp</item>
|
|
||||||
</style>
|
|
||||||
<!-- The style for the track widget label -->
|
<!-- The style for the track widget label -->
|
||||||
<style name="TrackWidgetLabel" parent="@style/TextSmall">
|
<style name="TrackWidgetLabel" parent="@style/TextSmall">
|
||||||
<item name="android:width">100dp</item>
|
<item name="android:layout_height">wrap_content</item>
|
||||||
|
<item name="android:layout_weight">1</item>
|
||||||
|
<item name="android:layout_width">0dp</item>
|
||||||
</style>
|
</style>
|
||||||
<!-- The style for the track widget separator -->
|
<!-- The style for the track widget separator -->
|
||||||
<style name="TrackWidgetSeparator">
|
<style name="TrackWidgetSeparator">
|
||||||
@@ -210,15 +204,15 @@ limitations under the License.
|
|||||||
<item name="android:layout_height">1dp</item>
|
<item name="android:layout_height">1dp</item>
|
||||||
<item name="android:layout_width">fill_parent</item>
|
<item name="android:layout_width">fill_parent</item>
|
||||||
</style>
|
</style>
|
||||||
|
<!-- The style for the track widget spacer -->
|
||||||
|
<style name="TrackWidgetSpacer">
|
||||||
|
<item name="android:layout_height">fill_parent</item>
|
||||||
|
<item name="android:layout_width">4dp</item>
|
||||||
|
</style>
|
||||||
<!-- The style for the track widget stat -->
|
<!-- The style for the track widget stat -->
|
||||||
<style name="TrackWidgetStat">
|
<style name="TrackWidgetStat">
|
||||||
<item name="android:layout_height">wrap_content</item>
|
<item name="android:layout_height">wrap_content</item>
|
||||||
<item name="android:layout_width">fill_parent</item>
|
<item name="android:layout_width">fill_parent</item>
|
||||||
<item name="android:orientation">horizontal</item>
|
<item name="android:orientation">horizontal</item>
|
||||||
</style>
|
</style>
|
||||||
<!-- The style for the track widget value -->
|
|
||||||
<style name="TrackWidgetValue" parent="@style/TextSmall">
|
|
||||||
<item name="android:layout_weight">1</item>
|
|
||||||
<item name="android:layout_width">0dp</item>
|
|
||||||
</style>
|
|
||||||
</resources>
|
</resources>
|
||||||
@@ -114,6 +114,10 @@ public class ControlRecordingService extends IntentService implements ServiceCon
|
|||||||
trackRecordingService.startNewTrack();
|
trackRecordingService.startNewTrack();
|
||||||
} else if (action.equals(getString(R.string.track_action_end))) {
|
} else if (action.equals(getString(R.string.track_action_end))) {
|
||||||
trackRecordingService.endCurrentTrack();
|
trackRecordingService.endCurrentTrack();
|
||||||
|
} else if (action.equals(getString(R.string.track_action_pause))) {
|
||||||
|
trackRecordingService.pauseCurrentTrack();
|
||||||
|
} else if (action.equals(getString(R.string.track_action_resume))) {
|
||||||
|
trackRecordingService.resumeCurrentTrack();
|
||||||
}
|
}
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
Log.d(TAG, "ControlRecordingService onHandleIntent RemoteException", e);
|
Log.d(TAG, "ControlRecordingService onHandleIntent RemoteException", e);
|
||||||
|
|||||||
@@ -45,8 +45,9 @@ import android.view.View;
|
|||||||
import android.widget.RemoteViews;
|
import android.widget.RemoteViews;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A track widget to start/stop recording, launch My Tracks, and display track
|
* A track widget to start/stop/pause/resume recording, launch My Tracks, and
|
||||||
* statistics (distance, time, speed) for the selected track or the last track.
|
* display track statistics (total distance, total time, average speed, and
|
||||||
|
* moving time) for the recording track, the selected track or the last track.
|
||||||
*
|
*
|
||||||
* @author Sandor Dornbush
|
* @author Sandor Dornbush
|
||||||
* @author Paul R. Saxman
|
* @author Paul R. Saxman
|
||||||
@@ -67,21 +68,28 @@ public class TrackWidgetProvider extends AppWidgetProvider
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onChange(boolean selfChange) {
|
public void onChange(boolean selfChange) {
|
||||||
updateTrack(null);
|
update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set in constructor
|
||||||
private final Handler handler;
|
private final Handler handler;
|
||||||
|
|
||||||
|
// Set when initializing
|
||||||
private Context context;
|
private Context context;
|
||||||
private TrackObserver trackObserver;
|
private TrackObserver trackObserver;
|
||||||
private MyTracksProviderUtils myTracksProviderUtils;
|
private MyTracksProviderUtils myTracksProviderUtils;
|
||||||
|
private RemoteViews remoteViews;
|
||||||
private String unknown;
|
private String unknown;
|
||||||
private String trackStartedBroadcastAction;
|
|
||||||
private String trackStoppedBroadcastAction;
|
|
||||||
|
|
||||||
private SharedPreferences sharedPreferences;
|
private SharedPreferences sharedPreferences;
|
||||||
|
|
||||||
|
// Set if there is a track
|
||||||
|
private TripStatistics tripStatistics;
|
||||||
|
|
||||||
|
// Preferences
|
||||||
private long selectedTrackId;
|
private long selectedTrackId;
|
||||||
|
private long recordingTrackId;
|
||||||
|
private boolean recordingtrackPaused;
|
||||||
private boolean metricUnits;
|
private boolean metricUnits;
|
||||||
private boolean reportSpeed;
|
private boolean reportSpeed;
|
||||||
private boolean showMovingTime;
|
private boolean showMovingTime;
|
||||||
@@ -93,6 +101,24 @@ public class TrackWidgetProvider extends AppWidgetProvider
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
|
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
|
||||||
|
if (key == null
|
||||||
|
|| key.equals(PreferencesUtils.getKey(context, R.string.selected_track_id_key))) {
|
||||||
|
selectedTrackId = PreferencesUtils.getLong(context, R.string.selected_track_id_key);
|
||||||
|
}
|
||||||
|
if (key == null
|
||||||
|
|| key.equals(PreferencesUtils.getKey(context, R.string.recording_track_id_key))) {
|
||||||
|
long oldValue = recordingTrackId;
|
||||||
|
recordingTrackId = PreferencesUtils.getLong(context, R.string.recording_track_id_key);
|
||||||
|
if (oldValue == PreferencesUtils.RECORDING_TRACK_ID_DEFAULT
|
||||||
|
&& recordingTrackId != PreferencesUtils.RECORDING_TRACK_ID_DEFAULT) {
|
||||||
|
recordingtrackPaused = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (key == null
|
||||||
|
|| key.equals(PreferencesUtils.getKey(context, R.string.recording_track_paused_key))) {
|
||||||
|
recordingtrackPaused = PreferencesUtils.getBoolean(context,
|
||||||
|
R.string.recording_track_paused_key, PreferencesUtils.RECORDING_TRACK_PAUSED_DEFAULT);
|
||||||
|
}
|
||||||
if (key == null || key.equals(PreferencesUtils.getKey(context, R.string.metric_units_key))) {
|
if (key == null || key.equals(PreferencesUtils.getKey(context, R.string.metric_units_key))) {
|
||||||
metricUnits = PreferencesUtils.getBoolean(
|
metricUnits = PreferencesUtils.getBoolean(
|
||||||
context, R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT);
|
context, R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT);
|
||||||
@@ -106,29 +132,33 @@ public class TrackWidgetProvider extends AppWidgetProvider
|
|||||||
showMovingTime = PreferencesUtils.getBoolean(context, R.string.stats_show_moving_time_key,
|
showMovingTime = PreferencesUtils.getBoolean(context, R.string.stats_show_moving_time_key,
|
||||||
PreferencesUtils.STATS_SHOW_MOVING_TIME_DEFAULT);
|
PreferencesUtils.STATS_SHOW_MOVING_TIME_DEFAULT);
|
||||||
}
|
}
|
||||||
if (key == null
|
|
||||||
|| key.equals(PreferencesUtils.getKey(context, R.string.selected_track_id_key))) {
|
|
||||||
selectedTrackId = PreferencesUtils.getLong(context, R.string.selected_track_id_key);
|
|
||||||
}
|
|
||||||
if (key != null) {
|
if (key != null) {
|
||||||
updateTrack(null);
|
update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context aContext, Intent intent) {
|
public void onReceive(Context aContext, Intent intent) {
|
||||||
super.onReceive(aContext, intent);
|
super.onReceive(aContext, intent);
|
||||||
initialize(aContext);
|
if (context == null) {
|
||||||
|
// Not initialized
|
||||||
|
context = aContext;
|
||||||
|
trackObserver = new TrackObserver();
|
||||||
|
myTracksProviderUtils = MyTracksProviderUtils.Factory.get(context);
|
||||||
|
remoteViews = new RemoteViews(context.getPackageName(), R.layout.track_widget);
|
||||||
|
|
||||||
selectedTrackId = intent.getLongExtra(
|
unknown = context.getString(R.string.value_unknown);
|
||||||
context.getString(R.string.track_id_broadcast_extra), selectedTrackId);
|
|
||||||
|
sharedPreferences = context.getSharedPreferences(SETTINGS_NAME, Context.MODE_PRIVATE);
|
||||||
|
sharedPreferences.registerOnSharedPreferenceChangeListener(this);
|
||||||
|
onSharedPreferenceChanged(sharedPreferences, null);
|
||||||
|
context.getContentResolver()
|
||||||
|
.registerContentObserver(TracksColumns.CONTENT_URI, true, trackObserver);
|
||||||
|
}
|
||||||
String action = intent.getAction();
|
String action = intent.getAction();
|
||||||
|
|
||||||
if (AppWidgetManager.ACTION_APPWIDGET_ENABLED.equals(action)
|
if (AppWidgetManager.ACTION_APPWIDGET_ENABLED.equals(action)
|
||||||
|| AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(action)
|
|| AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(action)) {
|
||||||
|| trackStartedBroadcastAction.equals(action)
|
update();
|
||||||
|| trackStoppedBroadcastAction.equals(action)) {
|
|
||||||
updateTrack(action);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,44 +172,24 @@ public class TrackWidgetProvider extends AppWidgetProvider
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Initializes the widget.
|
|
||||||
*
|
|
||||||
* @param aContext a context
|
|
||||||
*/
|
|
||||||
private void initialize(Context aContext) {
|
|
||||||
if (context != null) {
|
|
||||||
// Already initialized
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
context = aContext;
|
|
||||||
trackObserver = new TrackObserver();
|
|
||||||
myTracksProviderUtils = MyTracksProviderUtils.Factory.get(context);
|
|
||||||
|
|
||||||
unknown = context.getString(R.string.value_unknown);
|
|
||||||
trackStartedBroadcastAction = context.getString(R.string.track_started_broadcast_action);
|
|
||||||
trackStoppedBroadcastAction = context.getString(R.string.track_stopped_broadcast_action);
|
|
||||||
|
|
||||||
sharedPreferences = context.getSharedPreferences(SETTINGS_NAME, Context.MODE_PRIVATE);
|
|
||||||
sharedPreferences.registerOnSharedPreferenceChangeListener(this);
|
|
||||||
onSharedPreferenceChanged(sharedPreferences, null);
|
|
||||||
|
|
||||||
context.getContentResolver()
|
|
||||||
.registerContentObserver(TracksColumns.CONTENT_URI, true, trackObserver);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the widget.
|
* Updates the widget.
|
||||||
*
|
|
||||||
* @param action the action
|
|
||||||
*/
|
*/
|
||||||
private void updateTrack(String action) {
|
private void update() {
|
||||||
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.track_widget);
|
boolean isRecording = recordingTrackId != PreferencesUtils.RECORDING_TRACK_ID_DEFAULT;
|
||||||
|
long trackId = isRecording ? recordingTrackId : selectedTrackId;
|
||||||
|
Track track = trackId != -1L ? myTracksProviderUtils.getTrack(trackId)
|
||||||
|
: myTracksProviderUtils.getLastTrack();
|
||||||
|
tripStatistics = track == null ? null : track.getTripStatistics();
|
||||||
|
|
||||||
if (action != null) {
|
updateStatisticsContainer(track);
|
||||||
updateButton(remoteViews, action);
|
updateTotalDistance();
|
||||||
}
|
updateTotalTime(isRecording);
|
||||||
updateView(remoteViews);
|
updateAverageSpeed();
|
||||||
|
updateMovingTime();
|
||||||
|
updateRecordButton(isRecording);
|
||||||
|
updateRecordStatus(isRecording);
|
||||||
|
updateStopButton(isRecording);
|
||||||
|
|
||||||
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
|
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
|
||||||
int[] appWidgetIds = appWidgetManager.getAppWidgetIds(
|
int[] appWidgetIds = appWidgetManager.getAppWidgetIds(
|
||||||
@@ -190,75 +200,11 @@ public class TrackWidgetProvider extends AppWidgetProvider
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates button to start/stop recording.
|
* Updates the statistics container.
|
||||||
*
|
*
|
||||||
* @param remoteViews the remote views
|
* @param track the track.
|
||||||
* @param action the action
|
|
||||||
*/
|
*/
|
||||||
private void updateButton(RemoteViews remoteViews, String action) {
|
private void updateStatisticsContainer(Track track) {
|
||||||
boolean isRecording = trackStartedBroadcastAction.equals(action);
|
|
||||||
remoteViews.setViewVisibility(
|
|
||||||
R.id.track_widget_record_button, isRecording ? View.GONE : View.VISIBLE);
|
|
||||||
remoteViews.setViewVisibility(
|
|
||||||
R.id.track_widget_stop_button, isRecording ? View.VISIBLE : View.INVISIBLE);
|
|
||||||
Intent intent = new Intent(context, ControlRecordingService.class).setAction(
|
|
||||||
context.getString(isRecording ? R.string.track_action_end : R.string.track_action_start));
|
|
||||||
PendingIntent pendingIntent = PendingIntent.getService(
|
|
||||||
context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
||||||
remoteViews.setOnClickPendingIntent(
|
|
||||||
isRecording ? R.id.track_widget_stop_button : R.id.track_widget_record_button,
|
|
||||||
pendingIntent);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates view.
|
|
||||||
*
|
|
||||||
* @param remoteViews the remote views
|
|
||||||
*/
|
|
||||||
private void updateView(RemoteViews remoteViews) {
|
|
||||||
Track track = selectedTrackId != PreferencesUtils.SELECTED_TRACK_ID_DEFAULT ? myTracksProviderUtils
|
|
||||||
.getTrack(selectedTrackId)
|
|
||||||
: myTracksProviderUtils.getLastTrack();
|
|
||||||
TripStatistics tripStatistics = track == null ? null : track.getTripStatistics();
|
|
||||||
|
|
||||||
String distanceValue = tripStatistics == null ? unknown
|
|
||||||
: StringUtils.formatDistance(context, tripStatistics.getTotalDistance(), metricUnits);
|
|
||||||
remoteViews.setTextViewText(R.id.track_widget_distance_value, distanceValue);
|
|
||||||
|
|
||||||
String totalTimeValue = tripStatistics == null ? unknown
|
|
||||||
: StringUtils.formatElapsedTime(tripStatistics.getTotalTime());
|
|
||||||
remoteViews.setTextViewText(R.id.track_widget_total_time_value, totalTimeValue);
|
|
||||||
|
|
||||||
String averageSpeedLabel = context.getString(
|
|
||||||
reportSpeed ? R.string.stats_average_speed : R.string.stats_average_pace);
|
|
||||||
remoteViews.setTextViewText(R.id.track_widget_average_speed_label, averageSpeedLabel);
|
|
||||||
String averageSpeedValue = tripStatistics == null ? unknown
|
|
||||||
: StringUtils.formatSpeed(
|
|
||||||
context, tripStatistics.getAverageSpeed(), metricUnits, reportSpeed);
|
|
||||||
remoteViews.setTextViewText(R.id.track_widget_average_speed_value, averageSpeedValue);
|
|
||||||
|
|
||||||
setStatVisibility(remoteViews, R.id.track_widget_moving_time_stat,
|
|
||||||
R.id.track_widget_moving_time_separator, showMovingTime);
|
|
||||||
if (showMovingTime) {
|
|
||||||
String movingTimeValue = tripStatistics == null ? unknown
|
|
||||||
: StringUtils.formatElapsedTime(tripStatistics.getMovingTime());
|
|
||||||
remoteViews.setTextViewText(R.id.track_widget_moving_time_value, movingTimeValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
setStatVisibility(remoteViews, R.id.track_widget_average_moving_speed_stat,
|
|
||||||
R.id.track_widget_average_moving_speed_separator, showMovingTime);
|
|
||||||
if (showMovingTime) {
|
|
||||||
String averageMovingSpeedLabel = context.getString(
|
|
||||||
reportSpeed ? R.string.stats_average_moving_speed : R.string.stats_average_moving_pace);
|
|
||||||
remoteViews.setTextViewText(
|
|
||||||
R.id.track_widget_average_moving_speed_label, averageMovingSpeedLabel);
|
|
||||||
String averageMovingSpeedValue = tripStatistics == null ? unknown
|
|
||||||
: StringUtils.formatSpeed(
|
|
||||||
context, tripStatistics.getAverageMovingSpeed(), metricUnits, reportSpeed);
|
|
||||||
remoteViews.setTextViewText(
|
|
||||||
R.id.track_widget_average_moving_speed_value, averageMovingSpeedValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
Intent intent;
|
Intent intent;
|
||||||
if (track != null) {
|
if (track != null) {
|
||||||
intent = IntentUtils.newIntent(context, TrackDetailActivity.class)
|
intent = IntentUtils.newIntent(context, TrackDetailActivity.class)
|
||||||
@@ -270,12 +216,120 @@ public class TrackWidgetProvider extends AppWidgetProvider
|
|||||||
taskStackBuilder.addNextIntent(intent);
|
taskStackBuilder.addNextIntent(intent);
|
||||||
PendingIntent pendingIntent = taskStackBuilder.getPendingIntent(0, 0);
|
PendingIntent pendingIntent = taskStackBuilder.getPendingIntent(0, 0);
|
||||||
remoteViews.setOnClickPendingIntent(R.id.track_widget_statistics, pendingIntent);
|
remoteViews.setOnClickPendingIntent(R.id.track_widget_statistics, pendingIntent);
|
||||||
remoteViews.setOnClickPendingIntent(R.id.track_widget_icon, pendingIntent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setStatVisibility(
|
/**
|
||||||
RemoteViews remoteViews, int statId, int separatorId, boolean show) {
|
* Updates total distance.
|
||||||
remoteViews.setViewVisibility(statId, show ? View.VISIBLE : View.GONE);
|
*/
|
||||||
remoteViews.setViewVisibility(separatorId, show ? View.VISIBLE : View.GONE);
|
private void updateTotalDistance() {
|
||||||
|
String totalDistanceValue = tripStatistics == null ? unknown
|
||||||
|
: StringUtils.formatDistance(context, tripStatistics.getTotalDistance(), metricUnits);
|
||||||
|
remoteViews.setTextViewText(R.id.track_widget_total_distance_value, totalDistanceValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates total time.
|
||||||
|
*
|
||||||
|
* @param isRecording true if recording
|
||||||
|
*/
|
||||||
|
private void updateTotalTime(boolean isRecording) {
|
||||||
|
String totalTimeValue;
|
||||||
|
if (tripStatistics == null) {
|
||||||
|
totalTimeValue = unknown;
|
||||||
|
} else {
|
||||||
|
long totalTime = tripStatistics.getTotalTime();
|
||||||
|
if (isRecording && !recordingtrackPaused) {
|
||||||
|
totalTime += System.currentTimeMillis() - tripStatistics.getStopTime();
|
||||||
|
}
|
||||||
|
totalTimeValue = StringUtils.formatElapsedTime(totalTime);
|
||||||
|
}
|
||||||
|
remoteViews.setTextViewText(R.id.track_widget_total_time_value, totalTimeValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates average speed.
|
||||||
|
*/
|
||||||
|
private void updateAverageSpeed() {
|
||||||
|
String averageSpeedLabel = context.getString(
|
||||||
|
reportSpeed ? R.string.stats_average_speed : R.string.stats_average_pace);
|
||||||
|
remoteViews.setTextViewText(R.id.track_widget_average_speed_label, averageSpeedLabel);
|
||||||
|
String averageSpeedValue = tripStatistics == null ? unknown
|
||||||
|
: StringUtils.formatSpeed(
|
||||||
|
context, tripStatistics.getAverageSpeed(), metricUnits, reportSpeed);
|
||||||
|
remoteViews.setTextViewText(R.id.track_widget_average_speed_value, averageSpeedValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates moving time.
|
||||||
|
*/
|
||||||
|
private void updateMovingTime() {
|
||||||
|
remoteViews.setViewVisibility(
|
||||||
|
R.id.track_widget_moving_time_container, showMovingTime ? View.VISIBLE : View.GONE);
|
||||||
|
if (showMovingTime) {
|
||||||
|
String movingTimeValue = tripStatistics == null ? unknown
|
||||||
|
: StringUtils.formatElapsedTime(tripStatistics.getMovingTime());
|
||||||
|
remoteViews.setTextViewText(R.id.track_widget_moving_time_value, movingTimeValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the record button.
|
||||||
|
*
|
||||||
|
* @param isRecording true if recording
|
||||||
|
*/
|
||||||
|
private void updateRecordButton(boolean isRecording) {
|
||||||
|
remoteViews.setImageViewResource(R.id.track_widget_record_button,
|
||||||
|
isRecording && !recordingtrackPaused ? R.drawable.btn_pause : R.drawable.btn_record);
|
||||||
|
int recordActionId;
|
||||||
|
if (isRecording) {
|
||||||
|
recordActionId = recordingtrackPaused ? R.string.track_action_resume
|
||||||
|
: R.string.track_action_pause;
|
||||||
|
} else {
|
||||||
|
recordActionId = R.string.track_action_start;
|
||||||
|
}
|
||||||
|
Intent intent = new Intent(context, ControlRecordingService.class).setAction(
|
||||||
|
context.getString(recordActionId));
|
||||||
|
PendingIntent pendingIntent = PendingIntent.getService(
|
||||||
|
context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
|
remoteViews.setOnClickPendingIntent(R.id.track_widget_record_button, pendingIntent);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates recording status.
|
||||||
|
*
|
||||||
|
* @param isRecording true if recording
|
||||||
|
*/
|
||||||
|
private void updateRecordStatus(boolean isRecording) {
|
||||||
|
String status;
|
||||||
|
int colorId;
|
||||||
|
if (isRecording) {
|
||||||
|
status = context.getString(
|
||||||
|
recordingtrackPaused ? R.string.generic_paused : R.string.generic_recording);
|
||||||
|
colorId = recordingtrackPaused ? android.R.color.white : R.color.red;
|
||||||
|
} else {
|
||||||
|
status = "";
|
||||||
|
colorId = android.R.color.white;
|
||||||
|
}
|
||||||
|
remoteViews.setTextColor(
|
||||||
|
R.id.track_widget_record_status, context.getResources().getColor(colorId));
|
||||||
|
remoteViews.setTextViewText(R.id.track_widget_record_status, status);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the stop button.
|
||||||
|
*
|
||||||
|
* @param isRecording true if recording
|
||||||
|
*/
|
||||||
|
private void updateStopButton(boolean isRecording) {
|
||||||
|
remoteViews.setImageViewResource(
|
||||||
|
R.id.track_widget_stop_button, isRecording ? R.drawable.btn_stop_1 : R.drawable.btn_stop_0);
|
||||||
|
remoteViews.setBoolean(R.id.track_widget_stop_button, "setEnabled", isRecording);
|
||||||
|
if (isRecording) {
|
||||||
|
Intent intent = new Intent(context, ControlRecordingService.class).setAction(
|
||||||
|
context.getString(R.string.track_action_end));
|
||||||
|
PendingIntent pendingIntent = PendingIntent.getService(
|
||||||
|
context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
|
remoteViews.setOnClickPendingIntent(R.id.track_widget_stop_button, pendingIntent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user