forked from upstream-mirrors/OpenTracks
merge heads
This commit is contained in:
@@ -30,6 +30,7 @@ import android.content.DialogInterface;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.v4.app.TaskStackBuilder;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
@@ -142,10 +143,12 @@ public class ImportActivity extends Activity {
|
|||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
if (!importAll && trackId != -1L) {
|
if (!importAll && trackId != -1L) {
|
||||||
Intent intent = IntentUtils.newIntent(
|
Intent intent = IntentUtils
|
||||||
ImportActivity.this, TrackDetailActivity.class)
|
.newIntent(ImportActivity.this, TrackDetailActivity.class)
|
||||||
.putExtra(TrackDetailActivity.EXTRA_TRACK_ID, trackId);
|
.putExtra(TrackDetailActivity.EXTRA_TRACK_ID, trackId);
|
||||||
startActivity(intent);
|
TaskStackBuilder taskStackBuilder = TaskStackBuilder.from(ImportActivity.this);
|
||||||
|
taskStackBuilder.addNextIntent(intent);
|
||||||
|
taskStackBuilder.startActivities();
|
||||||
}
|
}
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,6 +64,8 @@ import android.os.IBinder;
|
|||||||
import android.os.PowerManager;
|
import android.os.PowerManager;
|
||||||
import android.os.PowerManager.WakeLock;
|
import android.os.PowerManager.WakeLock;
|
||||||
import android.os.Process;
|
import android.os.Process;
|
||||||
|
import android.support.v4.app.NotificationCompat;
|
||||||
|
import android.support.v4.app.TaskStackBuilder;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
@@ -479,16 +481,19 @@ public class TrackRecordingService extends Service {
|
|||||||
*/
|
*/
|
||||||
private void showNotification() {
|
private void showNotification() {
|
||||||
if (isRecording) {
|
if (isRecording) {
|
||||||
Notification notification = new Notification(
|
|
||||||
R.drawable.my_tracks_notification_icon, null, System.currentTimeMillis());
|
|
||||||
Intent intent = IntentUtils.newIntent(this, TrackDetailActivity.class)
|
Intent intent = IntentUtils.newIntent(this, TrackDetailActivity.class)
|
||||||
.putExtra(TrackDetailActivity.EXTRA_TRACK_ID, recordingTrackId);
|
.putExtra(TrackDetailActivity.EXTRA_TRACK_ID, recordingTrackId);
|
||||||
PendingIntent contentIntent = PendingIntent.getActivity(
|
TaskStackBuilder taskStackBuilder = TaskStackBuilder.from(this);
|
||||||
this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
taskStackBuilder.addNextIntent(intent);
|
||||||
notification.setLatestEventInfo(this, getString(R.string.my_tracks_app_name),
|
|
||||||
getString(R.string.track_record_notification), contentIntent);
|
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
|
||||||
notification.flags += Notification.FLAG_NO_CLEAR;
|
.setContentIntent(taskStackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT))
|
||||||
startForegroundService(notification);
|
.setContentText(getString(R.string.track_record_notification))
|
||||||
|
.setContentTitle(getString(R.string.my_tracks_app_name))
|
||||||
|
.setOngoing(true)
|
||||||
|
.setSmallIcon(R.drawable.my_tracks_notification_icon)
|
||||||
|
.setWhen(System.currentTimeMillis());
|
||||||
|
startForegroundService(builder.getNotification());
|
||||||
} else {
|
} else {
|
||||||
stopForegroundService();
|
stopForegroundService();
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-6
@@ -74,8 +74,6 @@ public class AntSensorManager extends SensorManager {
|
|||||||
private static final short SDM_PERIOD = 8134;
|
private static final short SDM_PERIOD = 8134;
|
||||||
|
|
||||||
private static final byte DEFAULT_PROXIMITY_SEARCH_BIN = 7;
|
private static final byte DEFAULT_PROXIMITY_SEARCH_BIN = 7;
|
||||||
private static final short SCREEN_ON_BUFFER_THRESHOLD = AntDefine.MIN_BUFFER_THRESHOLD;
|
|
||||||
private static final short SCREEN_OFF_BUFFER_THRESHOLD = AntDefine.MAX_BUFFER_THRESHOLD;
|
|
||||||
|
|
||||||
private static final String RADIO_ANT = "ant";
|
private static final String RADIO_ANT = "ant";
|
||||||
private static final byte ANT_NETWORK = (byte) 0x01;
|
private static final byte ANT_NETWORK = (byte) 0x01;
|
||||||
@@ -222,13 +220,12 @@ public class AntSensorManager extends SensorManager {
|
|||||||
try {
|
try {
|
||||||
if (serviceConnected && hasClaimedInterface && antInterface.isEnabled()) {
|
if (serviceConnected && hasClaimedInterface && antInterface.isEnabled()) {
|
||||||
try {
|
try {
|
||||||
antInterface.ANTConfigEventBuffering((short) 0xFFFF, SCREEN_ON_BUFFER_THRESHOLD,
|
antInterface.ANTDisableEventBuffering();
|
||||||
(short) 0xFFFF, SCREEN_OFF_BUFFER_THRESHOLD);
|
|
||||||
} catch (AntInterfaceException e) {
|
} catch (AntInterfaceException e) {
|
||||||
Log.e(TAG, "Cannot configure event buffering.", e);
|
Log.e(TAG, "Cannot disable event buffering.", e);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Log.i(TAG, "Cannot set event buffering now.");
|
Log.i(TAG, "Cannot disable event buffering now.");
|
||||||
}
|
}
|
||||||
} catch (AntInterfaceException e) {
|
} catch (AntInterfaceException e) {
|
||||||
Log.e(TAG, "Unable to check enabled state.", e);
|
Log.e(TAG, "Unable to check enabled state.", e);
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ import android.content.SharedPreferences;
|
|||||||
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
||||||
import android.database.ContentObserver;
|
import android.database.ContentObserver;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
|
import android.support.v4.app.TaskStackBuilder;
|
||||||
import android.widget.RemoteViews;
|
import android.widget.RemoteViews;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -172,26 +173,13 @@ public class TrackWidgetProvider extends AppWidgetProvider
|
|||||||
* @param action the action
|
* @param action the action
|
||||||
*/
|
*/
|
||||||
private void updateTrack(String action) {
|
private void updateTrack(String action) {
|
||||||
Track track = selectedTrackId != PreferencesUtils.SELECTED_TRACK_ID_DEFAULT ? myTracksProviderUtils
|
|
||||||
.getTrack(selectedTrackId)
|
|
||||||
: myTracksProviderUtils.getLastTrack();
|
|
||||||
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.track_widget);
|
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.track_widget);
|
||||||
|
|
||||||
Intent intent;
|
|
||||||
if (track != null) {
|
|
||||||
intent = IntentUtils.newIntent(context, TrackDetailActivity.class)
|
|
||||||
.putExtra(TrackDetailActivity.EXTRA_TRACK_ID, track.getId());
|
|
||||||
} else {
|
|
||||||
intent = IntentUtils.newIntent(context, TrackListActivity.class);
|
|
||||||
}
|
|
||||||
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
|
|
||||||
remoteViews.setOnClickPendingIntent(R.id.track_widget_statistics, pendingIntent);
|
|
||||||
|
|
||||||
if (action != null) {
|
if (action != null) {
|
||||||
updateButton(remoteViews, action);
|
updateButton(remoteViews, action);
|
||||||
}
|
}
|
||||||
updateStatistics(remoteViews, track);
|
updateStatistics(remoteViews);
|
||||||
|
|
||||||
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
|
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
|
||||||
int[] appWidgetIds = appWidgetManager.getAppWidgetIds(
|
int[] appWidgetIds = appWidgetManager.getAppWidgetIds(
|
||||||
new ComponentName(context, TrackWidgetProvider.class));
|
new ComponentName(context, TrackWidgetProvider.class));
|
||||||
@@ -209,13 +197,14 @@ public class TrackWidgetProvider extends AppWidgetProvider
|
|||||||
private void updateButton(RemoteViews remoteViews, String action) {
|
private void updateButton(RemoteViews remoteViews, String action) {
|
||||||
int trackAction = trackStartedBroadcastAction.equals(action) ? R.string.track_action_end
|
int trackAction = trackStartedBroadcastAction.equals(action) ? R.string.track_action_end
|
||||||
: R.string.track_action_start;
|
: R.string.track_action_start;
|
||||||
int icon = trackStartedBroadcastAction.equals(action) ? R.drawable.app_widget_button_enabled
|
|
||||||
: R.drawable.app_widget_button_disabled;
|
|
||||||
Intent intent = new Intent(context, ControlRecordingService.class).setAction(
|
Intent intent = new Intent(context, ControlRecordingService.class).setAction(
|
||||||
context.getString(trackAction));
|
context.getString(trackAction));
|
||||||
PendingIntent pendingIntent = PendingIntent.getService(
|
PendingIntent pendingIntent = PendingIntent.getService(
|
||||||
context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
remoteViews.setOnClickPendingIntent(R.id.track_widget_button, pendingIntent);
|
remoteViews.setOnClickPendingIntent(R.id.track_widget_button, pendingIntent);
|
||||||
|
|
||||||
|
int icon = trackStartedBroadcastAction.equals(action) ? R.drawable.app_widget_button_enabled
|
||||||
|
: R.drawable.app_widget_button_disabled;
|
||||||
remoteViews.setImageViewResource(R.id.track_widget_button, icon);
|
remoteViews.setImageViewResource(R.id.track_widget_button, icon);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -223,9 +212,10 @@ public class TrackWidgetProvider extends AppWidgetProvider
|
|||||||
* Updates statistics.
|
* Updates statistics.
|
||||||
*
|
*
|
||||||
* @param remoteViews the remote views
|
* @param remoteViews the remote views
|
||||||
* @param track the track
|
|
||||||
*/
|
*/
|
||||||
private void updateStatistics(RemoteViews remoteViews, Track track) {
|
private void updateStatistics(RemoteViews remoteViews) {
|
||||||
|
Track track = selectedTrackId != PreferencesUtils.SELECTED_TRACK_ID_DEFAULT
|
||||||
|
? myTracksProviderUtils.getTrack(selectedTrackId) : myTracksProviderUtils.getLastTrack();
|
||||||
TripStatistics tripStatistics = track == null ? null : track.getStatistics();
|
TripStatistics tripStatistics = track == null ? null : track.getStatistics();
|
||||||
String distance = tripStatistics == null ? unknown
|
String distance = tripStatistics == null ? unknown
|
||||||
: StringUtils.formatDistance(context, tripStatistics.getTotalDistance(), metricUnits);
|
: StringUtils.formatDistance(context, tripStatistics.getTotalDistance(), metricUnits);
|
||||||
@@ -240,6 +230,7 @@ public class TrackWidgetProvider extends AppWidgetProvider
|
|||||||
speedLabelId = reportSpeed ? R.string.stats_average_moving_speed
|
speedLabelId = reportSpeed ? R.string.stats_average_moving_speed
|
||||||
: R.string.stats_average_moving_pace;
|
: R.string.stats_average_moving_pace;
|
||||||
}
|
}
|
||||||
|
|
||||||
String speed = tripStatistics == null ? unknown : StringUtils.formatSpeed(
|
String speed = tripStatistics == null ? unknown : StringUtils.formatSpeed(
|
||||||
context, useTotalTime ? tripStatistics.getAverageSpeed()
|
context, useTotalTime ? tripStatistics.getAverageSpeed()
|
||||||
: tripStatistics.getAverageMovingSpeed(), metricUnits, reportSpeed);
|
: tripStatistics.getAverageMovingSpeed(), metricUnits, reportSpeed);
|
||||||
@@ -248,5 +239,17 @@ public class TrackWidgetProvider extends AppWidgetProvider
|
|||||||
remoteViews.setTextViewText(R.id.track_widget_time_value, time);
|
remoteViews.setTextViewText(R.id.track_widget_time_value, time);
|
||||||
remoteViews.setTextViewText(R.id.track_widget_speed_label, context.getString(speedLabelId));
|
remoteViews.setTextViewText(R.id.track_widget_speed_label, context.getString(speedLabelId));
|
||||||
remoteViews.setTextViewText(R.id.track_widget_speed_value, speed);
|
remoteViews.setTextViewText(R.id.track_widget_speed_value, speed);
|
||||||
|
|
||||||
|
Intent intent;
|
||||||
|
if (track != null) {
|
||||||
|
intent = IntentUtils.newIntent(context, TrackDetailActivity.class)
|
||||||
|
.putExtra(TrackDetailActivity.EXTRA_TRACK_ID, track.getId());
|
||||||
|
} else {
|
||||||
|
intent = IntentUtils.newIntent(context, TrackListActivity.class);
|
||||||
|
}
|
||||||
|
TaskStackBuilder taskStackBuilder = TaskStackBuilder.from(context);
|
||||||
|
taskStackBuilder.addNextIntent(intent);
|
||||||
|
remoteViews.setOnClickPendingIntent(
|
||||||
|
R.id.track_widget_statistics, taskStackBuilder.getPendingIntent(0, 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user