Merge heads

This commit is contained in:
youtaol
2012-09-07 10:45:01 +08:00
14 changed files with 252 additions and 251 deletions
-3
View File
@@ -236,10 +236,7 @@ limitations under the License.
<receiver android:name="com.google.android.apps.mytracks.widgets.TrackWidgetProvider" >
<intent-filter>
<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>
<meta-data
android:name="android.appwidget.provider"
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>
+58 -52
View File
@@ -15,94 +15,100 @@ See the License for the specific language governing permissions and
limitations under the License.
-->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@drawable/track_widget_background"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:padding="@dimen/widget_margin" >
<LinearLayout
android:background="@drawable/track_widget_background"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:orientation="horizontal" >
<ImageButton
android:background="@android:color/transparent"
android:contentDescription="@string/my_tracks_app_name"
android:id="@+id/track_widget_icon"
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:padding="8dp"
android:src="@drawable/my_tracks_icon" />
android:orientation="vertical"
android:paddingBottom="8dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="8dp" >
<LinearLayout
android:clickable="true"
android:id="@+id/track_widget_statistics"
android:layout_height="fill_parent"
android:layout_weight="1"
android:layout_width="0dp"
android:orientation="vertical"
android:paddingLeft="8dp" >
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:orientation="vertical" >
<LinearLayout style="@style/TrackWidgetStat" >
<TextView
android:id="@+id/track_widget_distance_value"
style="@style/TrackWidgetValue" />
<TextView
android:text="@string/stats_total_distance"
style="@style/TrackWidgetLabel" />
<TextView style="@style/TrackWidgetSpacer" />
<TextView
android:id="@+id/track_widget_total_distance_value"
style="@style/TrackWidgetLabel" />
</LinearLayout>
<LinearLayout style="@style/TrackWidgetSeparator" />
<LinearLayout style="@style/TrackWidgetStat" >
<TextView
android:id="@+id/track_widget_total_time_value"
style="@style/TrackWidgetValue" />
<TextView
android:text="@string/stats_total_time"
style="@style/TrackWidgetLabel" />
<TextView style="@style/TrackWidgetSpacer" />
<TextView
android:id="@+id/track_widget_total_time_value"
style="@style/TrackWidgetLabel" />
</LinearLayout>
<LinearLayout style="@style/TrackWidgetSeparator" />
<LinearLayout style="@style/TrackWidgetStat" >
<TextView
android:id="@+id/track_widget_average_speed_value"
style="@style/TrackWidgetValue" />
<TextView
android:id="@+id/track_widget_average_speed_label"
style="@style/TrackWidgetLabel" />
</LinearLayout>
<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 style="@style/TrackWidgetSpacer" />
<TextView
android:id="@+id/track_widget_moving_time_value"
style="@style/TrackWidgetValue" />
<TextView
android:text="@string/stats_moving_time"
android:id="@+id/track_widget_average_speed_value"
style="@style/TrackWidgetLabel" />
</LinearLayout>
<LinearLayout
android:id="@+id/track_widget_average_moving_speed_separator"
style="@style/TrackWidgetSeparator" />
<LinearLayout
android:id="@+id/track_widget_average_moving_speed_stat"
style="@style/TrackWidgetStat" >
<TextView
android:id="@+id/track_widget_average_moving_speed_value"
style="@style/TrackWidgetValue" />
<TextView
android:id="@+id/track_widget_average_moving_speed_label"
style="@style/TrackWidgetLabel" />
android:id="@+id/track_widget_moving_time_container"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:orientation="vertical" >
<LinearLayout style="@style/TrackWidgetSeparator" />
<LinearLayout style="@style/TrackWidgetStat" >
<TextView
android:text="@string/stats_moving_time"
style="@style/TrackWidgetLabel" />
<TextView style="@style/TrackWidgetSpacer" />
<TextView
android:id="@+id/track_widget_moving_time_value"
style="@style/TrackWidgetLabel" />
</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
android:background="@drawable/track_widget_record_button_background"
android:background="@android:color/transparent"
android:contentDescription="@string/icon_record_track"
android:id="@+id/track_widget_record_button"
android:src="@drawable/track_widget_record_button"
style="@style/TrackWidgetButton" />
android:layout_height="wrap_content"
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
android:background="@drawable/track_widget_stop_button_background"
android:background="@android:color/transparent"
android:contentDescription="@string/icon_stop_recording"
android:id="@+id/track_widget_stop_button"
android:src="@drawable/track_widget_stop_button"
style="@style/TrackWidgetButton" />
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="@drawable/btn_stop_0" />
</LinearLayout>
</LinearLayout>
</FrameLayout>
+2 -1
View File
@@ -94,7 +94,8 @@ Google은 이용자에 대한 위치정보의 이용∙제공사실을 위치정
<string name="settings_recording_track_name_location_value">LOCATION</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_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="value_unknown">-</string>
</resources>
+8 -14
View File
@@ -192,17 +192,11 @@ limitations under the License.
<item name="android:layout_width">fill_parent</item>
<item name="android:orientation">vertical</item>
</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 -->
<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>
<!-- The style for the track widget separator -->
<style name="TrackWidgetSeparator">
@@ -210,15 +204,15 @@ limitations under the License.
<item name="android:layout_height">1dp</item>
<item name="android:layout_width">fill_parent</item>
</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 -->
<style name="TrackWidgetStat">
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_width">fill_parent</item>
<item name="android:orientation">horizontal</item>
</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>
@@ -114,6 +114,10 @@ public class ControlRecordingService extends IntentService implements ServiceCon
trackRecordingService.startNewTrack();
} else if (action.equals(getString(R.string.track_action_end))) {
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) {
Log.d(TAG, "ControlRecordingService onHandleIntent RemoteException", e);
@@ -45,8 +45,9 @@ import android.view.View;
import android.widget.RemoteViews;
/**
* A track widget to start/stop recording, launch My Tracks, and display track
* statistics (distance, time, speed) for the selected track or the last track.
* A track widget to start/stop/pause/resume recording, launch My Tracks, and
* 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 Paul R. Saxman
@@ -67,21 +68,28 @@ public class TrackWidgetProvider extends AppWidgetProvider
@Override
public void onChange(boolean selfChange) {
updateTrack(null);
update();
}
}
// Set in constructor
private final Handler handler;
// Set when initializing
private Context context;
private TrackObserver trackObserver;
private MyTracksProviderUtils myTracksProviderUtils;
private RemoteViews remoteViews;
private String unknown;
private String trackStartedBroadcastAction;
private String trackStoppedBroadcastAction;
private SharedPreferences sharedPreferences;
// Set if there is a track
private TripStatistics tripStatistics;
// Preferences
private long selectedTrackId;
private long recordingTrackId;
private boolean recordingtrackPaused;
private boolean metricUnits;
private boolean reportSpeed;
private boolean showMovingTime;
@@ -93,6 +101,24 @@ public class TrackWidgetProvider extends AppWidgetProvider
@Override
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))) {
metricUnits = PreferencesUtils.getBoolean(
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,
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) {
updateTrack(null);
update();
}
}
@Override
public void onReceive(Context aContext, Intent 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(
context.getString(R.string.track_id_broadcast_extra), selectedTrackId);
unknown = context.getString(R.string.value_unknown);
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();
if (AppWidgetManager.ACTION_APPWIDGET_ENABLED.equals(action)
|| AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(action)
|| trackStartedBroadcastAction.equals(action)
|| trackStoppedBroadcastAction.equals(action)) {
updateTrack(action);
|| AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(action)) {
update();
}
}
@@ -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.
*
* @param action the action
*/
private void updateTrack(String action) {
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.track_widget);
private void update() {
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) {
updateButton(remoteViews, action);
}
updateView(remoteViews);
updateStatisticsContainer(track);
updateTotalDistance();
updateTotalTime(isRecording);
updateAverageSpeed();
updateMovingTime();
updateRecordButton(isRecording);
updateRecordStatus(isRecording);
updateStopButton(isRecording);
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
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 action the action
* @param track the track.
*/
private void updateButton(RemoteViews remoteViews, String action) {
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);
}
private void updateStatisticsContainer(Track track) {
Intent intent;
if (track != null) {
intent = IntentUtils.newIntent(context, TrackDetailActivity.class)
@@ -270,12 +216,120 @@ public class TrackWidgetProvider extends AppWidgetProvider
taskStackBuilder.addNextIntent(intent);
PendingIntent pendingIntent = taskStackBuilder.getPendingIntent(0, 0);
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) {
remoteViews.setViewVisibility(statId, show ? View.VISIBLE : View.GONE);
remoteViews.setViewVisibility(separatorId, show ? View.VISIBLE : View.GONE);
/**
* Updates total distance.
*/
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);
}
}
}