forked from upstream-mirrors/OpenTracks
Fixing stats screen registration.
This commit is contained in:
@@ -160,7 +160,7 @@ limitations under the License.
|
||||
<string name="settings_sharing">Partage</string>
|
||||
|
||||
<string name="settings_announcement_frequency">Fréquence des annonces</string>
|
||||
<string name="settings_announcement_frequency_summary">Temps minimum entre eux annonces vocales</string>
|
||||
<string name="settings_announcement_frequency_summary">Temps minimum entre deux annonces vocales</string>
|
||||
|
||||
<string name="settings_min_recording_distance">Distance min. entre 2 points</string>
|
||||
<string name="settings_min_recording_distance_summary">Plus petite distance entre deux enregistrements de votre position</string>
|
||||
|
||||
@@ -39,11 +39,9 @@ public class DialogManager {
|
||||
public static final int DIALOG_IMPORT_PROGRESS = 2;
|
||||
public static final int DIALOG_PROGRESS = 3;
|
||||
public static final int DIALOG_SEND_TO_GOOGLE = 4;
|
||||
public static final int DIALOG_WRITE_PROGRESS = 5;
|
||||
|
||||
private ProgressDialog progressDialog;
|
||||
private ProgressDialog importProgressDialog;
|
||||
private ProgressDialog writeProgressDialog;
|
||||
private SendDialog sendToGoogleDialog;
|
||||
private ChartSettingsDialog chartSettingsDialog;
|
||||
|
||||
@@ -79,15 +77,6 @@ public class DialogManager {
|
||||
case DIALOG_SEND_TO_GOOGLE:
|
||||
sendToGoogleDialog = new SendDialog(activity);
|
||||
return sendToGoogleDialog;
|
||||
case DIALOG_WRITE_PROGRESS:
|
||||
writeProgressDialog = new ProgressDialog(activity);
|
||||
writeProgressDialog.setIcon(android.R.drawable.ic_dialog_info);
|
||||
writeProgressDialog.setTitle(
|
||||
activity.getString(R.string.progress_title));
|
||||
writeProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
|
||||
writeProgressDialog.setMessage(
|
||||
activity.getString(R.string.write_progress_message));
|
||||
return writeProgressDialog;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -213,4 +202,19 @@ public class DialogManager {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* The equivalent of {@link #dismissDialogSafely(int)}, but for a specific
|
||||
* dialog instance.
|
||||
*/
|
||||
public static void dismissDialogSafely(Activity activity, final Dialog dialog) {
|
||||
activity.runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
dialog.dismiss();
|
||||
} catch (IllegalArgumentException e) {
|
||||
// This will be thrown if this dialog was not shown before.
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ import static com.google.android.apps.mytracks.Constants.TAG;
|
||||
import static com.google.android.apps.mytracks.DialogManager.DIALOG_IMPORT_PROGRESS;
|
||||
import static com.google.android.apps.mytracks.DialogManager.DIALOG_PROGRESS;
|
||||
import static com.google.android.apps.mytracks.DialogManager.DIALOG_SEND_TO_GOOGLE;
|
||||
import static com.google.android.apps.mytracks.DialogManager.DIALOG_WRITE_PROGRESS;
|
||||
|
||||
import com.google.android.accounts.Account;
|
||||
import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
|
||||
@@ -1227,17 +1226,15 @@ public class MyTracks extends TabActivity implements OnTouchListener,
|
||||
* @param trackId The id of the track to be sent
|
||||
*/
|
||||
public void saveTrack(long trackId, TrackFileFormat format) {
|
||||
dialogManager.showDialogSafely(DIALOG_WRITE_PROGRESS);
|
||||
final TrackWriter writer =
|
||||
TrackWriterFactory.newWriter(this, providerUtils, trackId, format);
|
||||
writer.setOnCompletion(new Runnable() {
|
||||
public void run() {
|
||||
dialogManager.dismissDialogSafely(DIALOG_WRITE_PROGRESS);
|
||||
dialogManager.showMessageDialog(writer.getErrorMessage(),
|
||||
writer.wasSuccess());
|
||||
TrackWriter writer = TrackWriterFactory.newWriter(this, providerUtils, trackId, format);
|
||||
WriteProgressController controller = new WriteProgressController(this, writer);
|
||||
controller.setOnCompletionListener(new WriteProgressController.OnCompletionListener() {
|
||||
@Override
|
||||
public void onComplete(TrackWriter writer) {
|
||||
dialogManager.showMessageDialog(writer.getErrorMessage(), writer.wasSuccess());
|
||||
}
|
||||
});
|
||||
writer.writeTrackAsync();
|
||||
controller.startWrite();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1248,9 +1245,7 @@ public class MyTracks extends TabActivity implements OnTouchListener,
|
||||
* @param trackId The id of the track to be sent
|
||||
*/
|
||||
public void sendTrack(long trackId, final TrackFileFormat format) {
|
||||
dialogManager.showDialogSafely(DIALOG_WRITE_PROGRESS);
|
||||
final TrackWriter writer =
|
||||
TrackWriterFactory.newWriter(this, providerUtils, trackId, format);
|
||||
TrackWriter writer = TrackWriterFactory.newWriter(this, providerUtils, trackId, format);
|
||||
|
||||
FileUtils fileUtils = new FileUtils();
|
||||
String extension = format.getExtension();
|
||||
@@ -1258,28 +1253,31 @@ public class MyTracks extends TabActivity implements OnTouchListener,
|
||||
|
||||
File dir = new File(dirName);
|
||||
writer.setDirectory(dir);
|
||||
writer.setOnCompletion(new Runnable() {
|
||||
public void run() {
|
||||
dialogManager.dismissDialogSafely(DIALOG_WRITE_PROGRESS);
|
||||
|
||||
WriteProgressController controller = new WriteProgressController(this, writer);
|
||||
controller.setOnCompletionListener(new WriteProgressController.OnCompletionListener() {
|
||||
@Override
|
||||
public void onComplete(TrackWriter writer) {
|
||||
if (!writer.wasSuccess()) {
|
||||
dialogManager.showMessageDialog(writer.getErrorMessage(),
|
||||
writer.wasSuccess());
|
||||
} else {
|
||||
Intent shareIntent = new Intent(Intent.ACTION_SEND);
|
||||
shareIntent.putExtra(Intent.EXTRA_SUBJECT,
|
||||
getResources().getText(R.string.send_track_subject).toString());
|
||||
shareIntent.putExtra(Intent.EXTRA_TEXT,
|
||||
getResources().getText(R.string.send_track_body_format)
|
||||
.toString());
|
||||
shareIntent.setType(format.getMimeType());
|
||||
Uri u = Uri.fromFile(new File(writer.getAbsolutePath()));
|
||||
shareIntent.putExtra(Intent.EXTRA_STREAM, u);
|
||||
startActivity(Intent.createChooser(shareIntent,
|
||||
getResources().getText(R.string.share_track).toString()));
|
||||
dialogManager.showMessageDialog(writer.getErrorMessage(), writer.wasSuccess());
|
||||
return;
|
||||
}
|
||||
|
||||
Intent shareIntent = new Intent(Intent.ACTION_SEND);
|
||||
shareIntent.putExtra(Intent.EXTRA_SUBJECT,
|
||||
getResources().getText(R.string.send_track_subject).toString());
|
||||
shareIntent.putExtra(Intent.EXTRA_TEXT,
|
||||
getResources().getText(R.string.send_track_body_format)
|
||||
.toString());
|
||||
shareIntent.setType(format.getMimeType());
|
||||
Uri u = Uri.fromFile(new File(writer.getAbsolutePath()));
|
||||
shareIntent.putExtra(Intent.EXTRA_STREAM, u);
|
||||
startActivity(Intent.createChooser(shareIntent,
|
||||
getResources().getText(R.string.share_track).toString()));
|
||||
}
|
||||
});
|
||||
writer.writeTrackAsync();
|
||||
|
||||
controller.startWrite();
|
||||
}
|
||||
|
||||
public AccountChooser getAccountChooser() {
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* Copyright 2011 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.io.file.TrackWriter;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.ProgressDialog;
|
||||
|
||||
/**
|
||||
* Given a {@link TrackWriter}, this class manages the process of writing the
|
||||
* data in the track represented by the writer. This includes the display of
|
||||
* a progress dialog, updating the progress bar in said dialog, and notifying
|
||||
* interested parties when the write completes.
|
||||
*
|
||||
* @author Matthew Simmons
|
||||
*/
|
||||
class WriteProgressController {
|
||||
/**
|
||||
* This listener is used to notify interested parties when the write has
|
||||
* completed.
|
||||
*/
|
||||
public interface OnCompletionListener {
|
||||
/**
|
||||
* When this method is invoked, the write has completed, and the progress
|
||||
* dialog has been dismissed. Whether the write succeeded can be
|
||||
* determined by examining the {@link TrackWriter}.
|
||||
*/
|
||||
public void onComplete(TrackWriter writer);
|
||||
}
|
||||
|
||||
private final Activity activity;
|
||||
private final TrackWriter writer;
|
||||
private final ProgressDialog dialog;
|
||||
|
||||
private OnCompletionListener onCompletionListener;
|
||||
|
||||
/**
|
||||
* @param activity the activity associated with this write
|
||||
* @param writer the writer which writes the track to disk. Note that this
|
||||
* class will use the writer's completion listener. If callers are
|
||||
* interested in notification upon completion of the write, they should
|
||||
* use {@link #setOnCompletionListener}.
|
||||
*/
|
||||
public WriteProgressController(Activity activity, TrackWriter writer) {
|
||||
this.activity = activity;
|
||||
this.writer = writer;
|
||||
|
||||
dialog = new ProgressDialog(activity);
|
||||
dialog.setIcon(android.R.drawable.ic_dialog_info);
|
||||
dialog.setTitle(activity.getString(R.string.progress_title));
|
||||
dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
|
||||
dialog.setMessage(activity.getString(R.string.write_progress_message));
|
||||
dialog.setIndeterminate(true);
|
||||
|
||||
writer.setOnCompletionListener(writerCompleteListener);
|
||||
writer.setOnWriteListener(writerWriteListener);
|
||||
}
|
||||
|
||||
/** Set a listener to be invoked when the write completes. */
|
||||
public void setOnCompletionListener(OnCompletionListener onCompletionListener) {
|
||||
this.onCompletionListener = onCompletionListener;
|
||||
}
|
||||
|
||||
/** Initiate an asynchronous write. */
|
||||
public void startWrite() {
|
||||
DialogManager.showDialogSafely(activity, dialog);
|
||||
writer.writeTrackAsync();
|
||||
}
|
||||
|
||||
/** VisibleForTesting */
|
||||
ProgressDialog getDialog() {
|
||||
return dialog;
|
||||
}
|
||||
|
||||
private final TrackWriter.OnCompletionListener writerCompleteListener =
|
||||
new TrackWriter.OnCompletionListener() {
|
||||
@Override
|
||||
public void onComplete() {
|
||||
DialogManager.dismissDialogSafely(activity, dialog);
|
||||
|
||||
if (onCompletionListener != null) {
|
||||
onCompletionListener.onComplete(writer);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private final TrackWriter.OnWriteListener writerWriteListener =
|
||||
new TrackWriter.OnWriteListener() {
|
||||
@Override
|
||||
public void onWrite(int number, int max) {
|
||||
if (number % 500 == 0) {
|
||||
dialog.setIndeterminate(false);
|
||||
dialog.setMax(max);
|
||||
dialog.setProgress(Math.min(number, max));
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -27,12 +27,31 @@ import java.io.File;
|
||||
* @author Rodrigo Damazio
|
||||
*/
|
||||
public interface TrackWriter {
|
||||
/** This listener is used to signal completion of track write */
|
||||
public interface OnCompletionListener {
|
||||
public void onComplete();
|
||||
}
|
||||
|
||||
/** This listener is used to signal track writes. */
|
||||
public interface OnWriteListener {
|
||||
/**
|
||||
* This method is invoked whenever a location within a track is written.
|
||||
* @param number the location number
|
||||
* @param max the maximum number of locations, for calculation of
|
||||
* completion percentage
|
||||
*/
|
||||
public void onWrite(int number, int max);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a completion callback.
|
||||
*
|
||||
* @param onCompletion Runnable that will be executed when finished
|
||||
* Sets listener to be invoked when the writer has finished.
|
||||
*/
|
||||
void setOnCompletion(Runnable onCompletion);
|
||||
void setOnCompletionListener(OnCompletionListener onCompletionListener);
|
||||
|
||||
/**
|
||||
* Sets a listener to be invoked for each location writer.
|
||||
*/
|
||||
void setOnWriteListener(OnWriteListener onWriteListener);
|
||||
|
||||
/**
|
||||
* Sets a custom directory where the file will be written.
|
||||
|
||||
@@ -45,17 +45,18 @@ import java.io.OutputStream;
|
||||
* @author Sandor Dornbush
|
||||
* @author Rodrigo Damazio
|
||||
*/
|
||||
public class TrackWriterImpl implements TrackWriter {
|
||||
class TrackWriterImpl implements TrackWriter {
|
||||
private final Context context;
|
||||
private final MyTracksProviderUtils providerUtils;
|
||||
private final Track track;
|
||||
private final TrackFormatWriter writer;
|
||||
private final FileUtils fileUtils;
|
||||
private Runnable onCompletion = null;
|
||||
private boolean success = false;
|
||||
private int errorMessage = -1;
|
||||
private File directory = null;
|
||||
private File file = null;
|
||||
private OnCompletionListener onCompletionListener;
|
||||
private OnWriteListener onWriteListener;
|
||||
|
||||
TrackWriterImpl(Context context, MyTracksProviderUtils providerUtils,
|
||||
Track track, TrackFormatWriter writer) {
|
||||
@@ -67,8 +68,13 @@ public class TrackWriterImpl implements TrackWriter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOnCompletion(Runnable onCompletion) {
|
||||
this.onCompletion = onCompletion;
|
||||
public void setOnCompletionListener(OnCompletionListener onCompletionListener) {
|
||||
this.onCompletionListener = onCompletionListener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOnWriteListener(OnWriteListener onWriteListener) {
|
||||
this.onWriteListener = onWriteListener;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -121,8 +127,13 @@ public class TrackWriterImpl implements TrackWriter {
|
||||
*/
|
||||
|
||||
private void finished() {
|
||||
if (onCompletion != null) {
|
||||
runOnUiThread(onCompletion);
|
||||
if (onCompletionListener != null) {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
onCompletionListener.onComplete();
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -289,9 +300,12 @@ public class TrackWriterImpl implements TrackWriter {
|
||||
Log.w(Constants.TAG, "Unable to get any points to write");
|
||||
return;
|
||||
}
|
||||
int pointNumber = 0;
|
||||
while (it.hasNext()) {
|
||||
Location loc = it.next();
|
||||
|
||||
pointNumber++;
|
||||
|
||||
boolean isValid = LocationUtils.isValidLocation(loc);
|
||||
boolean validSegment = isValid && isLastValid;
|
||||
if (!wroteFirst && validSegment) {
|
||||
@@ -312,6 +326,9 @@ public class TrackWriterImpl implements TrackWriter {
|
||||
|
||||
// Write the current point
|
||||
writer.writeLocation(loc);
|
||||
if (onWriteListener != null) {
|
||||
onWriteListener.onWrite(pointNumber, track.getNumberOfPoints());
|
||||
}
|
||||
} else {
|
||||
if (segmentOpen) {
|
||||
writer.writeCloseSegment();
|
||||
|
||||
Reference in New Issue
Block a user