forked from upstream-mirrors/OpenTracks
Use a async task to delete tracks and show a progress dialog.
This commit is contained in:
@@ -153,6 +153,7 @@ limitations under the License.
|
|||||||
<activity
|
<activity
|
||||||
android:label="@string/menu_aggregated_statistics"
|
android:label="@string/menu_aggregated_statistics"
|
||||||
android:name="com.google.android.apps.mytracks.AggregatedStatsActivity" />
|
android:name="com.google.android.apps.mytracks.AggregatedStatsActivity" />
|
||||||
|
<activity android:name="com.google.android.apps.mytracks.DeleteActivity" />
|
||||||
<activity
|
<activity
|
||||||
android:label="@string/menu_help"
|
android:label="@string/menu_help"
|
||||||
android:name="com.google.android.apps.mytracks.HelpActivity" />
|
android:name="com.google.android.apps.mytracks.HelpActivity" />
|
||||||
|
|||||||
@@ -2202,6 +2202,10 @@ limitations under the License.
|
|||||||
The selected tracks and their markers will be permanently deleted from the device. If Google
|
The selected tracks and their markers will be permanently deleted from the device. If Google
|
||||||
Drive sync is enabled, this will also delete the tracks on Google Drive.
|
Drive sync is enabled, this will also delete the tracks on Google Drive.
|
||||||
</string>
|
</string>
|
||||||
|
<string name="track_delete_progress_message"
|
||||||
|
translation_description="The progress message when deleting tracks.">
|
||||||
|
Deleting…
|
||||||
|
</string>
|
||||||
|
|
||||||
<!-- Track Detail -->
|
<!-- Track Detail -->
|
||||||
<string name="track_detail_chart_tab"
|
<string name="track_detail_chart_tab"
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ import com.google.android.apps.mytracks.fragments.CheckPermissionFragment;
|
|||||||
import com.google.android.apps.mytracks.fragments.CheckPermissionFragment.CheckPermissionCaller;
|
import com.google.android.apps.mytracks.fragments.CheckPermissionFragment.CheckPermissionCaller;
|
||||||
import com.google.android.apps.mytracks.fragments.ChooseAccountDialogFragment;
|
import com.google.android.apps.mytracks.fragments.ChooseAccountDialogFragment;
|
||||||
import com.google.android.apps.mytracks.fragments.ChooseAccountDialogFragment.ChooseAccountCaller;
|
import com.google.android.apps.mytracks.fragments.ChooseAccountDialogFragment.ChooseAccountCaller;
|
||||||
|
import com.google.android.apps.mytracks.fragments.ConfirmDeleteDialogFragment;
|
||||||
|
import com.google.android.apps.mytracks.fragments.ConfirmDeleteDialogFragment.ConfirmDeleteCaller;
|
||||||
import com.google.android.apps.mytracks.fragments.ConfirmPlayDialogFragment;
|
import com.google.android.apps.mytracks.fragments.ConfirmPlayDialogFragment;
|
||||||
import com.google.android.apps.mytracks.fragments.ConfirmPlayDialogFragment.ConfirmPlayCaller;
|
import com.google.android.apps.mytracks.fragments.ConfirmPlayDialogFragment.ConfirmPlayCaller;
|
||||||
import com.google.android.apps.mytracks.fragments.ConfirmSyncDialogFragment;
|
import com.google.android.apps.mytracks.fragments.ConfirmSyncDialogFragment;
|
||||||
@@ -38,10 +40,12 @@ import com.google.android.apps.mytracks.io.sendtogoogle.SendToGoogleUtils;
|
|||||||
import com.google.android.apps.mytracks.io.sendtogoogle.UploadResultActivity;
|
import com.google.android.apps.mytracks.io.sendtogoogle.UploadResultActivity;
|
||||||
import com.google.android.apps.mytracks.io.spreadsheets.SendSpreadsheetsActivity;
|
import com.google.android.apps.mytracks.io.spreadsheets.SendSpreadsheetsActivity;
|
||||||
import com.google.android.apps.mytracks.io.sync.SyncUtils;
|
import com.google.android.apps.mytracks.io.sync.SyncUtils;
|
||||||
|
import com.google.android.apps.mytracks.services.TrackRecordingServiceConnection;
|
||||||
import com.google.android.apps.mytracks.util.AnalyticsUtils;
|
import com.google.android.apps.mytracks.util.AnalyticsUtils;
|
||||||
import com.google.android.apps.mytracks.util.GoogleEarthUtils;
|
import com.google.android.apps.mytracks.util.GoogleEarthUtils;
|
||||||
import com.google.android.apps.mytracks.util.IntentUtils;
|
import com.google.android.apps.mytracks.util.IntentUtils;
|
||||||
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
||||||
|
import com.google.android.apps.mytracks.util.TrackRecordingServiceConnectionUtils;
|
||||||
import com.google.android.maps.mytracks.R;
|
import com.google.android.maps.mytracks.R;
|
||||||
|
|
||||||
import android.accounts.Account;
|
import android.accounts.Account;
|
||||||
@@ -67,13 +71,15 @@ import java.io.IOException;
|
|||||||
* @author Jimmy Shih
|
* @author Jimmy Shih
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractSendToGoogleActivity extends AbstractMyTracksActivity implements
|
public abstract class AbstractSendToGoogleActivity extends AbstractMyTracksActivity implements
|
||||||
ChooseAccountCaller, ConfirmSyncCaller, CheckPermissionCaller, ShareTrackCaller, ConfirmPlayCaller {
|
ChooseAccountCaller, ConfirmSyncCaller, CheckPermissionCaller, ShareTrackCaller, ConfirmPlayCaller,
|
||||||
|
ConfirmDeleteCaller {
|
||||||
|
|
||||||
private static final String TAG = AbstractMyTracksActivity.class.getSimpleName();
|
private static final String TAG = AbstractMyTracksActivity.class.getSimpleName();
|
||||||
private static final String SEND_REQUEST_KEY = "send_request_key";
|
private static final String SEND_REQUEST_KEY = "send_request_key";
|
||||||
private static final int DRIVE_REQUEST_CODE = 0;
|
private static final int DRIVE_REQUEST_CODE = 0;
|
||||||
private static final int FUSION_TABLES_REQUEST_CODE = 1;
|
private static final int FUSION_TABLES_REQUEST_CODE = 1;
|
||||||
private static final int SPREADSHEETS_REQUEST_CODE = 2;
|
private static final int SPREADSHEETS_REQUEST_CODE = 2;
|
||||||
|
private static final int DELETE_REQUEST_CODE = 3;
|
||||||
|
|
||||||
private SendRequest sendRequest;
|
private SendRequest sendRequest;
|
||||||
|
|
||||||
@@ -212,6 +218,9 @@ public abstract class AbstractSendToGoogleActivity extends AbstractMyTracksActiv
|
|||||||
onPermissionFailure();
|
onPermissionFailure();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case DELETE_REQUEST_CODE:
|
||||||
|
onDeleted();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
super.onActivityResult(requestCode, resultCode, data);
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
}
|
}
|
||||||
@@ -379,4 +388,36 @@ public abstract class AbstractSendToGoogleActivity extends AbstractMyTracksActiv
|
|||||||
.putExtra(SaveActivity.EXTRA_PLAY_TRACK, true);
|
.putExtra(SaveActivity.EXTRA_PLAY_TRACK, true);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void deleteTrack(long[] trackIds) {
|
||||||
|
ConfirmDeleteDialogFragment.newInstance(trackIds)
|
||||||
|
.show(getSupportFragmentManager(), ConfirmDeleteDialogFragment.CONFIRM_DELETE_DIALOG_TAG);
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract protected TrackRecordingServiceConnection getTrackRecordingServiceConnection();
|
||||||
|
|
||||||
|
abstract protected void onDeleted();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onConfirmDeleteDone(long[] trackIds) {
|
||||||
|
boolean stopRecording = false;
|
||||||
|
if (trackIds.length == 1 && trackIds[0] == -1L) {
|
||||||
|
stopRecording = true;
|
||||||
|
} else {
|
||||||
|
long recordingTrackId = PreferencesUtils.getLong(this, R.string.recording_track_id_key);
|
||||||
|
for (long trackId : trackIds) {
|
||||||
|
if (trackId == recordingTrackId) {
|
||||||
|
stopRecording = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (stopRecording) {
|
||||||
|
TrackRecordingServiceConnectionUtils.stopRecording(
|
||||||
|
this, getTrackRecordingServiceConnection(), false);
|
||||||
|
}
|
||||||
|
Intent intent = IntentUtils.newIntent(this, DeleteActivity.class);
|
||||||
|
intent.putExtra(DeleteActivity.EXTRA_TRACK_IDS, trackIds);
|
||||||
|
startActivityForResult(intent, DELETE_REQUEST_CODE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,97 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.google.android.apps.mytracks;
|
||||||
|
|
||||||
|
import com.google.android.apps.mytracks.util.DialogUtils;
|
||||||
|
import com.google.android.maps.mytracks.R;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.app.Dialog;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An activity for delete tracks.
|
||||||
|
*
|
||||||
|
* @author Jimmy Shih
|
||||||
|
*/
|
||||||
|
public class DeleteActivity extends Activity {
|
||||||
|
|
||||||
|
public static final String EXTRA_TRACK_IDS = "track_ids";
|
||||||
|
|
||||||
|
private static final int DIALOG_PROGRESS_ID = 0;
|
||||||
|
|
||||||
|
private DeleteAsyncTask deleteAsyncTask;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
setResult(RESULT_CANCELED);
|
||||||
|
|
||||||
|
Intent intent = getIntent();
|
||||||
|
long[] trackIds = intent.getLongArrayExtra(EXTRA_TRACK_IDS);
|
||||||
|
|
||||||
|
Object retained = getLastNonConfigurationInstance();
|
||||||
|
if (retained instanceof DeleteAsyncTask) {
|
||||||
|
deleteAsyncTask = (DeleteAsyncTask) retained;
|
||||||
|
deleteAsyncTask.setActivity(this);
|
||||||
|
} else {
|
||||||
|
deleteAsyncTask = new DeleteAsyncTask(this, trackIds);
|
||||||
|
deleteAsyncTask.execute();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object onRetainNonConfigurationInstance() {
|
||||||
|
deleteAsyncTask.setActivity(null);
|
||||||
|
return deleteAsyncTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Dialog onCreateDialog(int id) {
|
||||||
|
if (id != DIALOG_PROGRESS_ID) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return DialogUtils.createSpinnerProgressDialog(
|
||||||
|
this, R.string.track_delete_progress_message, new DialogInterface.OnCancelListener() {
|
||||||
|
@Override
|
||||||
|
public void onCancel(DialogInterface dialog) {
|
||||||
|
deleteAsyncTask.cancel(true);
|
||||||
|
dialog.dismiss();
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invokes when the associated AsyncTask completes.
|
||||||
|
*/
|
||||||
|
public void onAsyncTaskCompleted() {
|
||||||
|
removeDialog(DIALOG_PROGRESS_ID);
|
||||||
|
setResult(RESULT_OK);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shows the progress dialog.
|
||||||
|
*/
|
||||||
|
public void showProgressDialog() {
|
||||||
|
showDialog(DIALOG_PROGRESS_ID);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,102 @@
|
|||||||
|
package com.google.android.apps.mytracks;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright 2013 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
|
||||||
|
import com.google.android.apps.mytracks.io.sync.SyncUtils;
|
||||||
|
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
||||||
|
import com.google.android.maps.mytracks.R;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.AsyncTask;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Async Task to delete tracks.
|
||||||
|
*
|
||||||
|
* @author Jimmy Shih
|
||||||
|
*/
|
||||||
|
public class DeleteAsyncTask extends AsyncTask<Void, Integer, Boolean> {
|
||||||
|
|
||||||
|
private DeleteActivity deleteActivity;
|
||||||
|
private final long[] trackIds;
|
||||||
|
private final Context context;
|
||||||
|
|
||||||
|
// true if the AsyncTask has completed
|
||||||
|
private boolean completed;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an AsyncTask.
|
||||||
|
*
|
||||||
|
* @param deleteActivity the activity currently associated with this task
|
||||||
|
* @param trackIds the track ids to delete. To delete all, set to size 1 with
|
||||||
|
* trackIds[0] == -1L
|
||||||
|
*/
|
||||||
|
public DeleteAsyncTask(DeleteActivity deleteActivity, long[] trackIds) {
|
||||||
|
this.deleteActivity = deleteActivity;
|
||||||
|
this.trackIds = trackIds;
|
||||||
|
context = deleteActivity.getApplicationContext();
|
||||||
|
completed = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the current activity associated with this AyncTask.
|
||||||
|
*
|
||||||
|
* @param deleteActivity the current activity, can be null
|
||||||
|
*/
|
||||||
|
public void setActivity(DeleteActivity deleteActivity) {
|
||||||
|
this.deleteActivity = deleteActivity;
|
||||||
|
if (completed && deleteActivity != null) {
|
||||||
|
deleteActivity.onAsyncTaskCompleted();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPreExecute() {
|
||||||
|
if (deleteActivity != null) {
|
||||||
|
deleteActivity.showProgressDialog();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Boolean doInBackground(Void... params) {
|
||||||
|
MyTracksProviderUtils myTracksProviderUtils = MyTracksProviderUtils.Factory.get(context);
|
||||||
|
|
||||||
|
if (trackIds.length == 1 && trackIds[0] == -1L) {
|
||||||
|
PreferencesUtils.setBoolean(
|
||||||
|
context, R.string.drive_sync_key, PreferencesUtils.DRIVE_SYNC_DEFAULT);
|
||||||
|
SyncUtils.disableSync(context);
|
||||||
|
SyncUtils.clearSyncState(context);
|
||||||
|
myTracksProviderUtils.deleteAllTracks();
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
for (long id : trackIds) {
|
||||||
|
if (!isCancelled()) {
|
||||||
|
myTracksProviderUtils.deleteTrack(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(Boolean result) {
|
||||||
|
completed = true;
|
||||||
|
if (deleteActivity != null) {
|
||||||
|
deleteActivity.onAsyncTaskCompleted();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -24,10 +24,9 @@ import com.google.android.apps.mytracks.content.SearchEngineProvider;
|
|||||||
import com.google.android.apps.mytracks.content.Track;
|
import com.google.android.apps.mytracks.content.Track;
|
||||||
import com.google.android.apps.mytracks.content.Waypoint;
|
import com.google.android.apps.mytracks.content.Waypoint;
|
||||||
import com.google.android.apps.mytracks.content.Waypoint.WaypointType;
|
import com.google.android.apps.mytracks.content.Waypoint.WaypointType;
|
||||||
|
import com.google.android.apps.mytracks.fragments.ConfirmDeleteDialogFragment;
|
||||||
import com.google.android.apps.mytracks.fragments.DeleteMarkerDialogFragment;
|
import com.google.android.apps.mytracks.fragments.DeleteMarkerDialogFragment;
|
||||||
import com.google.android.apps.mytracks.fragments.DeleteMarkerDialogFragment.DeleteMarkerCaller;
|
import com.google.android.apps.mytracks.fragments.DeleteMarkerDialogFragment.DeleteMarkerCaller;
|
||||||
import com.google.android.apps.mytracks.fragments.DeleteTrackDialogFragment;
|
|
||||||
import com.google.android.apps.mytracks.fragments.DeleteTrackDialogFragment.DeleteTrackCaller;
|
|
||||||
import com.google.android.apps.mytracks.services.MyTracksLocationManager;
|
import com.google.android.apps.mytracks.services.MyTracksLocationManager;
|
||||||
import com.google.android.apps.mytracks.services.TrackRecordingServiceConnection;
|
import com.google.android.apps.mytracks.services.TrackRecordingServiceConnection;
|
||||||
import com.google.android.apps.mytracks.stats.TripStatistics;
|
import com.google.android.apps.mytracks.stats.TripStatistics;
|
||||||
@@ -75,8 +74,7 @@ import java.util.SortedSet;
|
|||||||
*
|
*
|
||||||
* @author Rodrigo Damazio
|
* @author Rodrigo Damazio
|
||||||
*/
|
*/
|
||||||
public class SearchListActivity extends AbstractSendToGoogleActivity
|
public class SearchListActivity extends AbstractSendToGoogleActivity implements DeleteMarkerCaller {
|
||||||
implements DeleteTrackCaller, DeleteMarkerCaller {
|
|
||||||
|
|
||||||
private static final String TAG = SearchListActivity.class.getSimpleName();
|
private static final String TAG = SearchListActivity.class.getSimpleName();
|
||||||
|
|
||||||
@@ -372,8 +370,8 @@ public class SearchListActivity extends AbstractSendToGoogleActivity
|
|||||||
DeleteMarkerDialogFragment.newInstance(new long[] { markerId }).show(
|
DeleteMarkerDialogFragment.newInstance(new long[] { markerId }).show(
|
||||||
getSupportFragmentManager(), DeleteMarkerDialogFragment.DELETE_MARKER_DIALOG_TAG);
|
getSupportFragmentManager(), DeleteMarkerDialogFragment.DELETE_MARKER_DIALOG_TAG);
|
||||||
} else {
|
} else {
|
||||||
DeleteTrackDialogFragment.newInstance(false, new long[] { trackId })
|
ConfirmDeleteDialogFragment.newInstance(new long[] { trackId })
|
||||||
.show(getSupportFragmentManager(), DeleteTrackDialogFragment.DELETE_TRACK_DIALOG_TAG);
|
.show(getSupportFragmentManager(), ConfirmDeleteDialogFragment.CONFIRM_DELETE_DIALOG_TAG);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
@@ -527,21 +525,6 @@ public class SearchListActivity extends AbstractSendToGoogleActivity
|
|||||||
resultMap.put(MARKER_ID_FIELD, null);
|
resultMap.put(MARKER_ID_FIELD, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public TrackRecordingServiceConnection getTrackRecordingServiceConnection() {
|
|
||||||
return trackRecordingServiceConnection;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDeleteTrackDone() {
|
|
||||||
runOnUiThread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
handleIntent(getIntent());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDeleteMarkerDone() {
|
public void onDeleteMarkerDone() {
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
@@ -551,4 +534,19 @@ public class SearchListActivity extends AbstractSendToGoogleActivity
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected TrackRecordingServiceConnection getTrackRecordingServiceConnection() {
|
||||||
|
return trackRecordingServiceConnection;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onDeleted() {
|
||||||
|
runOnUiThread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
handleIntent(getIntent());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,8 +22,7 @@ import com.google.android.apps.mytracks.content.TrackDataHub;
|
|||||||
import com.google.android.apps.mytracks.content.Waypoint;
|
import com.google.android.apps.mytracks.content.Waypoint;
|
||||||
import com.google.android.apps.mytracks.content.WaypointCreationRequest;
|
import com.google.android.apps.mytracks.content.WaypointCreationRequest;
|
||||||
import com.google.android.apps.mytracks.fragments.ChartFragment;
|
import com.google.android.apps.mytracks.fragments.ChartFragment;
|
||||||
import com.google.android.apps.mytracks.fragments.DeleteTrackDialogFragment;
|
import com.google.android.apps.mytracks.fragments.ConfirmDeleteDialogFragment;
|
||||||
import com.google.android.apps.mytracks.fragments.DeleteTrackDialogFragment.DeleteTrackCaller;
|
|
||||||
import com.google.android.apps.mytracks.fragments.ExportDialogFragment;
|
import com.google.android.apps.mytracks.fragments.ExportDialogFragment;
|
||||||
import com.google.android.apps.mytracks.fragments.ExportDialogFragment.ExportCaller;
|
import com.google.android.apps.mytracks.fragments.ExportDialogFragment.ExportCaller;
|
||||||
import com.google.android.apps.mytracks.fragments.ExportDialogFragment.ExportType;
|
import com.google.android.apps.mytracks.fragments.ExportDialogFragment.ExportType;
|
||||||
@@ -67,8 +66,7 @@ import java.util.Locale;
|
|||||||
* @author Leif Hendrik Wilden
|
* @author Leif Hendrik Wilden
|
||||||
* @author Rodrigo Damazio
|
* @author Rodrigo Damazio
|
||||||
*/
|
*/
|
||||||
public class TrackDetailActivity extends AbstractSendToGoogleActivity
|
public class TrackDetailActivity extends AbstractSendToGoogleActivity implements ExportCaller {
|
||||||
implements ExportCaller, DeleteTrackCaller {
|
|
||||||
|
|
||||||
public static final String EXTRA_TRACK_ID = "track_id";
|
public static final String EXTRA_TRACK_ID = "track_id";
|
||||||
public static final String EXTRA_MARKER_ID = "marker_id";
|
public static final String EXTRA_MARKER_ID = "marker_id";
|
||||||
@@ -368,8 +366,8 @@ public class TrackDetailActivity extends AbstractSendToGoogleActivity
|
|||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
return true;
|
return true;
|
||||||
case R.id.track_detail_delete:
|
case R.id.track_detail_delete:
|
||||||
DeleteTrackDialogFragment.newInstance(false, new long[] { trackId })
|
ConfirmDeleteDialogFragment.newInstance(new long[] { trackId })
|
||||||
.show(getSupportFragmentManager(), DeleteTrackDialogFragment.DELETE_TRACK_DIALOG_TAG);
|
.show(getSupportFragmentManager(), ConfirmDeleteDialogFragment.CONFIRM_DELETE_DIALOG_TAG);
|
||||||
return true;
|
return true;
|
||||||
case R.id.track_detail_sensor_state:
|
case R.id.track_detail_sensor_state:
|
||||||
intent = IntentUtils.newIntent(this, SensorStateActivity.class);
|
intent = IntentUtils.newIntent(this, SensorStateActivity.class);
|
||||||
@@ -434,12 +432,12 @@ public class TrackDetailActivity extends AbstractSendToGoogleActivity
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TrackRecordingServiceConnection getTrackRecordingServiceConnection() {
|
protected TrackRecordingServiceConnection getTrackRecordingServiceConnection() {
|
||||||
return trackRecordingServiceConnection;
|
return trackRecordingServiceConnection;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDeleteTrackDone() {
|
protected void onDeleted() {
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|||||||
@@ -19,8 +19,7 @@ package com.google.android.apps.mytracks;
|
|||||||
import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
|
import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
|
||||||
import com.google.android.apps.mytracks.content.Track;
|
import com.google.android.apps.mytracks.content.Track;
|
||||||
import com.google.android.apps.mytracks.content.TracksColumns;
|
import com.google.android.apps.mytracks.content.TracksColumns;
|
||||||
import com.google.android.apps.mytracks.fragments.DeleteTrackDialogFragment;
|
import com.google.android.apps.mytracks.fragments.ConfirmDeleteDialogFragment;
|
||||||
import com.google.android.apps.mytracks.fragments.DeleteTrackDialogFragment.DeleteTrackCaller;
|
|
||||||
import com.google.android.apps.mytracks.fragments.EnableSyncDialogFragment;
|
import com.google.android.apps.mytracks.fragments.EnableSyncDialogFragment;
|
||||||
import com.google.android.apps.mytracks.fragments.EnableSyncDialogFragment.EnableSyncCaller;
|
import com.google.android.apps.mytracks.fragments.EnableSyncDialogFragment.EnableSyncCaller;
|
||||||
import com.google.android.apps.mytracks.fragments.EulaDialogFragment;
|
import com.google.android.apps.mytracks.fragments.EulaDialogFragment;
|
||||||
@@ -93,7 +92,7 @@ import java.util.Locale;
|
|||||||
* @author Leif Hendrik Wilden
|
* @author Leif Hendrik Wilden
|
||||||
*/
|
*/
|
||||||
public class TrackListActivity extends AbstractSendToGoogleActivity
|
public class TrackListActivity extends AbstractSendToGoogleActivity
|
||||||
implements EulaCaller, EnableSyncCaller, DeleteTrackCaller, FileTypeCaller {
|
implements EulaCaller, EnableSyncCaller, FileTypeCaller {
|
||||||
|
|
||||||
private static final String TAG = TrackListActivity.class.getSimpleName();
|
private static final String TAG = TrackListActivity.class.getSimpleName();
|
||||||
private static final int GOOGLE_PLAY_SERVICES_REQUEST_CODE = 0;
|
private static final int GOOGLE_PLAY_SERVICES_REQUEST_CODE = 0;
|
||||||
@@ -561,8 +560,8 @@ public class TrackListActivity extends AbstractSendToGoogleActivity
|
|||||||
.show(getSupportFragmentManager(), FileTypeDialogFragment.FILE_TYPE_DIALOG_TAG);
|
.show(getSupportFragmentManager(), FileTypeDialogFragment.FILE_TYPE_DIALOG_TAG);
|
||||||
return true;
|
return true;
|
||||||
case R.id.track_list_delete_all:
|
case R.id.track_list_delete_all:
|
||||||
DeleteTrackDialogFragment.newInstance(true, new long[] {})
|
ConfirmDeleteDialogFragment.newInstance(new long[] {-1L})
|
||||||
.show(getSupportFragmentManager(), DeleteTrackDialogFragment.DELETE_TRACK_DIALOG_TAG);
|
.show(getSupportFragmentManager(), ConfirmDeleteDialogFragment.CONFIRM_DELETE_DIALOG_TAG);
|
||||||
return true;
|
return true;
|
||||||
case R.id.track_list_settings:
|
case R.id.track_list_settings:
|
||||||
intent = IntentUtils.newIntent(this, SettingsActivity.class);
|
intent = IntentUtils.newIntent(this, SettingsActivity.class);
|
||||||
@@ -617,12 +616,12 @@ public class TrackListActivity extends AbstractSendToGoogleActivity
|
|||||||
};
|
};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TrackRecordingServiceConnection getTrackRecordingServiceConnection() {
|
protected TrackRecordingServiceConnection getTrackRecordingServiceConnection() {
|
||||||
return trackRecordingServiceConnection;
|
return trackRecordingServiceConnection;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDeleteTrackDone() {
|
protected void onDeleted() {
|
||||||
// Do nothing
|
// Do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -634,7 +633,7 @@ public class TrackListActivity extends AbstractSendToGoogleActivity
|
|||||||
AnalyticsUtils.sendPageViews(
|
AnalyticsUtils.sendPageViews(
|
||||||
this, "/action/save_all_" + trackFileFormat.name().toLowerCase(Locale.US));
|
this, "/action/save_all_" + trackFileFormat.name().toLowerCase(Locale.US));
|
||||||
intent = IntentUtils.newIntent(this, SaveActivity.class)
|
intent = IntentUtils.newIntent(this, SaveActivity.class)
|
||||||
.putExtra(SaveActivity.EXTRA_SAVE_ALL, true)
|
.putExtra(SaveActivity.EXTRA_TRACK_IDS, new long[] {-1L})
|
||||||
.putExtra(SaveActivity.EXTRA_TRACK_FILE_FORMAT, (Parcelable) trackFileFormat);
|
.putExtra(SaveActivity.EXTRA_TRACK_FILE_FORMAT, (Parcelable) trackFileFormat);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
break;
|
break;
|
||||||
@@ -788,9 +787,11 @@ public class TrackListActivity extends AbstractSendToGoogleActivity
|
|||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
return true;
|
return true;
|
||||||
case R.id.list_context_menu_delete:
|
case R.id.list_context_menu_delete:
|
||||||
boolean deleteAll = trackIds.length > 1 && trackIds.length == listView.getCount();
|
if (trackIds.length > 1 && trackIds.length == listView.getCount()) {
|
||||||
DeleteTrackDialogFragment.newInstance(deleteAll, trackIds)
|
trackIds = new long[] {-1L};
|
||||||
.show(getSupportFragmentManager(), DeleteTrackDialogFragment.DELETE_TRACK_DIALOG_TAG);
|
}
|
||||||
|
ConfirmDeleteDialogFragment.newInstance(trackIds)
|
||||||
|
.show(getSupportFragmentManager(), ConfirmDeleteDialogFragment.CONFIRM_DELETE_DIALOG_TAG);
|
||||||
return true;
|
return true;
|
||||||
case R.id.list_context_menu_select_all:
|
case R.id.list_context_menu_select_all:
|
||||||
int size = listView.getCount();
|
int size = listView.getCount();
|
||||||
|
|||||||
+100
@@ -0,0 +1,100 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.google.android.apps.mytracks.fragments;
|
||||||
|
|
||||||
|
import com.google.android.apps.mytracks.util.DialogUtils;
|
||||||
|
import com.google.android.maps.mytracks.R;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.app.Dialog;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.v4.app.DialogFragment;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A DialogFragment to confirm delete.
|
||||||
|
*
|
||||||
|
* @author Jimmy Shih
|
||||||
|
*/
|
||||||
|
public class ConfirmDeleteDialogFragment extends DialogFragment {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface for caller of this dialog fragment.
|
||||||
|
*
|
||||||
|
* @author Jimmy Shih
|
||||||
|
*/
|
||||||
|
public interface ConfirmDeleteCaller {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when confirm delete is done.
|
||||||
|
*
|
||||||
|
* @param trackIds list of track ids to delete. To delete all, set to size 1
|
||||||
|
* with trackIds[0] == -1L
|
||||||
|
*/
|
||||||
|
public void onConfirmDeleteDone(long[] trackIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final String CONFIRM_DELETE_DIALOG_TAG = "confirmDeleteDialog";
|
||||||
|
private static final String KEY_TRACK_IDS = "trackIds";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new instance.
|
||||||
|
*
|
||||||
|
* @param trackIds list of track ids to delete. To delete all, set to size 1
|
||||||
|
* with trackIds[0] == -1L
|
||||||
|
*/
|
||||||
|
public static ConfirmDeleteDialogFragment newInstance(long[] trackIds) {
|
||||||
|
Bundle bundle = new Bundle();
|
||||||
|
bundle.putLongArray(KEY_TRACK_IDS, trackIds);
|
||||||
|
|
||||||
|
ConfirmDeleteDialogFragment deleteTrackDialogFragment = new ConfirmDeleteDialogFragment();
|
||||||
|
deleteTrackDialogFragment.setArguments(bundle);
|
||||||
|
return deleteTrackDialogFragment;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ConfirmDeleteCaller caller;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAttach(Activity activity) {
|
||||||
|
super.onAttach(activity);
|
||||||
|
try {
|
||||||
|
caller = (ConfirmDeleteCaller) activity;
|
||||||
|
} catch (ClassCastException e) {
|
||||||
|
throw new ClassCastException(
|
||||||
|
activity.toString() + " must implement " + ConfirmDeleteCaller.class.getSimpleName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
|
final long[] trackIds = getArguments().getLongArray(KEY_TRACK_IDS);
|
||||||
|
int messageId;
|
||||||
|
if (trackIds.length == 1 && trackIds[0] == -1L) {
|
||||||
|
messageId = R.string.track_delete_all_confirm_message;
|
||||||
|
} else {
|
||||||
|
messageId = trackIds.length > 1 ? R.string.track_delete_multiple_confirm_message
|
||||||
|
: R.string.track_delete_one_confirm_message;
|
||||||
|
}
|
||||||
|
return DialogUtils.createConfirmationDialog(
|
||||||
|
getActivity(), messageId, new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
caller.onConfirmDeleteDone(trackIds);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
-142
@@ -1,142 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.google.android.apps.mytracks.fragments;
|
|
||||||
|
|
||||||
import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
|
|
||||||
import com.google.android.apps.mytracks.io.sync.SyncUtils;
|
|
||||||
import com.google.android.apps.mytracks.services.TrackRecordingServiceConnection;
|
|
||||||
import com.google.android.apps.mytracks.util.DialogUtils;
|
|
||||||
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
|
||||||
import com.google.android.apps.mytracks.util.TrackRecordingServiceConnectionUtils;
|
|
||||||
import com.google.android.maps.mytracks.R;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.app.Dialog;
|
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.support.v4.app.DialogFragment;
|
|
||||||
import android.support.v4.app.FragmentActivity;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A DialogFragment to track.
|
|
||||||
*
|
|
||||||
* @author Jimmy Shih
|
|
||||||
*/
|
|
||||||
public class DeleteTrackDialogFragment extends DialogFragment {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Interface for caller of this dialog fragment.
|
|
||||||
*
|
|
||||||
* @author Jimmy Shih
|
|
||||||
*/
|
|
||||||
public interface DeleteTrackCaller {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the track recording service connection.
|
|
||||||
*/
|
|
||||||
public TrackRecordingServiceConnection getTrackRecordingServiceConnection();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when delete track is done.
|
|
||||||
*/
|
|
||||||
public void onDeleteTrackDone();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final String DELETE_TRACK_DIALOG_TAG = "deleteTrackDialog";
|
|
||||||
private static final String KEY_DELETE_ALL = "deleteAll";
|
|
||||||
private static final String KEY_TRACK_IDS = "trackIds";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new instance.
|
|
||||||
*
|
|
||||||
* @param deleteAll true to delete all tracks
|
|
||||||
* @param trackIds list of track ids to delete when deleteAll if false
|
|
||||||
*/
|
|
||||||
public static DeleteTrackDialogFragment newInstance(boolean deleteAll, long[] trackIds) {
|
|
||||||
Bundle bundle = new Bundle();
|
|
||||||
bundle.putBoolean(KEY_DELETE_ALL, deleteAll);
|
|
||||||
bundle.putLongArray(KEY_TRACK_IDS, trackIds);
|
|
||||||
|
|
||||||
DeleteTrackDialogFragment deleteTrackDialogFragment = new DeleteTrackDialogFragment();
|
|
||||||
deleteTrackDialogFragment.setArguments(bundle);
|
|
||||||
return deleteTrackDialogFragment;
|
|
||||||
}
|
|
||||||
|
|
||||||
private DeleteTrackCaller caller;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onAttach(Activity activity) {
|
|
||||||
super.onAttach(activity);
|
|
||||||
try {
|
|
||||||
caller = (DeleteTrackCaller) activity;
|
|
||||||
} catch (ClassCastException e) {
|
|
||||||
throw new ClassCastException(
|
|
||||||
activity.toString() + " must implement " + DeleteTrackCaller.class.getSimpleName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
|
||||||
boolean deleteAll = getArguments().getBoolean(KEY_DELETE_ALL);
|
|
||||||
final FragmentActivity fragmentActivity = getActivity();
|
|
||||||
if (deleteAll) {
|
|
||||||
return DialogUtils.createConfirmationDialog(fragmentActivity,
|
|
||||||
R.string.track_delete_all_confirm_message, new DialogInterface.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
new Thread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
PreferencesUtils.setBoolean(fragmentActivity, R.string.drive_sync_key,
|
|
||||||
PreferencesUtils.DRIVE_SYNC_DEFAULT);
|
|
||||||
SyncUtils.disableSync(fragmentActivity);
|
|
||||||
SyncUtils.clearSyncState(fragmentActivity);
|
|
||||||
MyTracksProviderUtils.Factory.get(fragmentActivity).deleteAllTracks();
|
|
||||||
caller.onDeleteTrackDone();
|
|
||||||
}
|
|
||||||
}).start();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
final long[] trackIds = getArguments().getLongArray(KEY_TRACK_IDS);
|
|
||||||
int messageId = trackIds.length > 1 ? R.string.track_delete_multiple_confirm_message
|
|
||||||
: R.string.track_delete_one_confirm_message;
|
|
||||||
return DialogUtils.createConfirmationDialog(
|
|
||||||
fragmentActivity, messageId, new DialogInterface.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
for (long trackId : trackIds) {
|
|
||||||
if (trackId == PreferencesUtils.getLong(
|
|
||||||
fragmentActivity, R.string.recording_track_id_key)) {
|
|
||||||
TrackRecordingServiceConnectionUtils.stopRecording(
|
|
||||||
fragmentActivity, caller.getTrackRecordingServiceConnection(), false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
new Thread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
for (long id : trackIds) {
|
|
||||||
MyTracksProviderUtils.Factory.get(fragmentActivity).deleteTrack(id);
|
|
||||||
}
|
|
||||||
caller.onDeleteTrackDone();
|
|
||||||
}
|
|
||||||
}).start();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -42,7 +42,6 @@ import java.io.File;
|
|||||||
public class SaveActivity extends Activity {
|
public class SaveActivity extends Activity {
|
||||||
|
|
||||||
public static final String EXTRA_TRACK_FILE_FORMAT = "track_file_format";
|
public static final String EXTRA_TRACK_FILE_FORMAT = "track_file_format";
|
||||||
public static final String EXTRA_SAVE_ALL = "save_all";
|
|
||||||
public static final String EXTRA_TRACK_IDS = "track_ids";
|
public static final String EXTRA_TRACK_IDS = "track_ids";
|
||||||
public static final String EXTRA_PLAY_TRACK = "play_track";
|
public static final String EXTRA_PLAY_TRACK = "play_track";
|
||||||
|
|
||||||
@@ -72,7 +71,6 @@ public class SaveActivity extends Activity {
|
|||||||
|
|
||||||
Intent intent = getIntent();
|
Intent intent = getIntent();
|
||||||
trackFileFormat = intent.getParcelableExtra(EXTRA_TRACK_FILE_FORMAT);
|
trackFileFormat = intent.getParcelableExtra(EXTRA_TRACK_FILE_FORMAT);
|
||||||
boolean saveAll = intent.getBooleanExtra(EXTRA_SAVE_ALL, false);
|
|
||||||
trackIds = intent.getLongArrayExtra(EXTRA_TRACK_IDS);
|
trackIds = intent.getLongArrayExtra(EXTRA_TRACK_IDS);
|
||||||
playTrack = intent.getBooleanExtra(EXTRA_PLAY_TRACK, false);
|
playTrack = intent.getBooleanExtra(EXTRA_PLAY_TRACK, false);
|
||||||
|
|
||||||
@@ -101,7 +99,7 @@ public class SaveActivity extends Activity {
|
|||||||
saveAsyncTask = (SaveAsyncTask) retained;
|
saveAsyncTask = (SaveAsyncTask) retained;
|
||||||
saveAsyncTask.setActivity(this);
|
saveAsyncTask.setActivity(this);
|
||||||
} else {
|
} else {
|
||||||
saveAsyncTask = new SaveAsyncTask(this, trackFileFormat, saveAll, trackIds, directory);
|
saveAsyncTask = new SaveAsyncTask(this, trackFileFormat, trackIds, directory);
|
||||||
saveAsyncTask.execute();
|
saveAsyncTask.execute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -164,7 +162,7 @@ public class SaveActivity extends Activity {
|
|||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
}).setTitle(titleId);
|
}).setTitle(titleId);
|
||||||
if (!playTrack && trackIds != null && trackIds.length == 1 && successCount == totalCount
|
if (!playTrack && trackIds.length == 1 && trackIds[0] != -1L && successCount == totalCount
|
||||||
&& savedPath != null) {
|
&& savedPath != null) {
|
||||||
builder.setNegativeButton(
|
builder.setNegativeButton(
|
||||||
R.string.share_track_share_file, new DialogInterface.OnClickListener() {
|
R.string.share_track_share_file, new DialogInterface.OnClickListener() {
|
||||||
|
|||||||
@@ -46,7 +46,6 @@ public class SaveAsyncTask extends AsyncTask<Void, Integer, Boolean> {
|
|||||||
|
|
||||||
private SaveActivity saveActivity;
|
private SaveActivity saveActivity;
|
||||||
private final TrackFileFormat trackFileFormat;
|
private final TrackFileFormat trackFileFormat;
|
||||||
private final boolean saveAll;
|
|
||||||
private final long[] trackIds;
|
private final long[] trackIds;
|
||||||
private final File directory;
|
private final File directory;
|
||||||
private final Context context;
|
private final Context context;
|
||||||
@@ -72,15 +71,14 @@ public class SaveAsyncTask extends AsyncTask<Void, Integer, Boolean> {
|
|||||||
*
|
*
|
||||||
* @param saveActivity the activity currently associated with this task
|
* @param saveActivity the activity currently associated with this task
|
||||||
* @param trackFileFormat the track file format
|
* @param trackFileFormat the track file format
|
||||||
* @param saveAll true to save all the tracks
|
* @param trackIds the track ids to save. To save all, set to size 1 with
|
||||||
* @param trackIds the track ids to save. null if saveAll if true
|
* trackIds[0] == -1L
|
||||||
* @param directory the directory to save to
|
* @param directory the directory to save to
|
||||||
*/
|
*/
|
||||||
public SaveAsyncTask(SaveActivity saveActivity, TrackFileFormat trackFileFormat, boolean saveAll,
|
public SaveAsyncTask(
|
||||||
long[] trackIds, File directory) {
|
SaveActivity saveActivity, TrackFileFormat trackFileFormat, long[] trackIds, File directory) {
|
||||||
this.saveActivity = saveActivity;
|
this.saveActivity = saveActivity;
|
||||||
this.trackFileFormat = trackFileFormat;
|
this.trackFileFormat = trackFileFormat;
|
||||||
this.saveAll = saveAll;
|
|
||||||
this.trackIds = trackIds;
|
this.trackIds = trackIds;
|
||||||
this.directory = directory;
|
this.directory = directory;
|
||||||
context = saveActivity.getApplicationContext();
|
context = saveActivity.getApplicationContext();
|
||||||
@@ -122,13 +120,10 @@ public class SaveAsyncTask extends AsyncTask<Void, Integer, Boolean> {
|
|||||||
if (!isRecording || isPaused) {
|
if (!isRecording || isPaused) {
|
||||||
wakeLock = SystemUtils.acquireWakeLock(saveActivity, wakeLock);
|
wakeLock = SystemUtils.acquireWakeLock(saveActivity, wakeLock);
|
||||||
}
|
}
|
||||||
if (saveAll) {
|
if (trackIds.length == 1 && trackIds[0] == -1L) {
|
||||||
return saveAllTracks();
|
return saveAllTracks();
|
||||||
} else {
|
} else {
|
||||||
totalCount = 1;
|
totalCount = 1;
|
||||||
if (trackIds == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
Track[] tracks = new Track[trackIds.length];
|
Track[] tracks = new Track[trackIds.length];
|
||||||
for (int i = 0; i < trackIds.length; i++) {
|
for (int i = 0; i < trackIds.length; i++) {
|
||||||
tracks[i] = myTracksProviderUtils.getTrack(trackIds[i]);
|
tracks[i] = myTracksProviderUtils.getTrack(trackIds[i]);
|
||||||
@@ -199,7 +194,7 @@ public class SaveAsyncTask extends AsyncTask<Void, Integer, Boolean> {
|
|||||||
* If only saving one track, update the progress dialog once every
|
* If only saving one track, update the progress dialog once every
|
||||||
* 500 points
|
* 500 points
|
||||||
*/
|
*/
|
||||||
if (trackIds != null && trackIds.length == 1 && number % 500 == 0) {
|
if (trackIds.length == 1 && trackIds[0] != -1L && number % 500 == 0) {
|
||||||
publishProgress(number, max);
|
publishProgress(number, max);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user