forked from upstream-mirrors/OpenTracks
Address Bart's comments and more dialog clean up.
This commit is contained in:
@@ -24,6 +24,7 @@ import android.content.DialogInterface;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.WindowManager.BadTokenException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A class to handle a dialog related events for My Tracks.
|
* A class to handle a dialog related events for My Tracks.
|
||||||
@@ -164,4 +165,67 @@ public class DialogManager {
|
|||||||
public SendToGoogleDialog getSendToGoogleDialog() {
|
public SendToGoogleDialog getSendToGoogleDialog() {
|
||||||
return sendToGoogleDialog;
|
return sendToGoogleDialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shows a dialog with the given message.
|
||||||
|
* Does it on the UI thread.
|
||||||
|
*
|
||||||
|
* @param success if true, displays an info icon/title, otherwise an error
|
||||||
|
* icon/title
|
||||||
|
* @param message resource string id
|
||||||
|
*/
|
||||||
|
public void showMessageDialog(final int message, final boolean success) {
|
||||||
|
activity.runOnUiThread(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
AlertDialog dialog = null;
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
|
||||||
|
builder.setMessage(activity.getString(message));
|
||||||
|
builder.setNegativeButton(activity.getString(R.string.ok), null);
|
||||||
|
builder.setIcon(success ? android.R.drawable.ic_dialog_info :
|
||||||
|
android.R.drawable.ic_dialog_alert);
|
||||||
|
builder.setTitle(success ? R.string.success : R.string.error);
|
||||||
|
dialog = builder.create();
|
||||||
|
dialog.show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Just like showDialog, but will catch a BadTokenException that sometimes
|
||||||
|
* (very rarely) gets thrown. This might happen if the user hits the "back"
|
||||||
|
* button immediately after sending tracks to google.
|
||||||
|
*
|
||||||
|
* @param id the dialog id
|
||||||
|
*/
|
||||||
|
public void showDialogSafely(final int id) {
|
||||||
|
activity.runOnUiThread(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
activity.showDialog(id);
|
||||||
|
} catch (BadTokenException e) {
|
||||||
|
Log.w(MyTracksConstants.TAG,
|
||||||
|
"Could not display dialog with id " + id, e);
|
||||||
|
} catch (IllegalStateException e) {
|
||||||
|
Log.w(MyTracksConstants.TAG,
|
||||||
|
"Could not display dialog with id " + id, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dismisses the progress dialog if it is showing. Executed on the UI thread.
|
||||||
|
*/
|
||||||
|
public void dismissDialogSafely(final int id) {
|
||||||
|
activity.runOnUiThread(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
activity.dismissDialog(id);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
// This will be thrown if this dialog was not shown before.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ import com.google.android.apps.mytracks.io.SendToMyMaps.OnSendCompletedListener;
|
|||||||
import com.google.android.apps.mytracks.io.TempFileCleaner;
|
import com.google.android.apps.mytracks.io.TempFileCleaner;
|
||||||
import com.google.android.apps.mytracks.io.TrackWriter;
|
import com.google.android.apps.mytracks.io.TrackWriter;
|
||||||
import com.google.android.apps.mytracks.io.TrackWriterFactory;
|
import com.google.android.apps.mytracks.io.TrackWriterFactory;
|
||||||
import com.google.android.apps.mytracks.io.SendToMyMaps.OnSendCompletedListener;
|
|
||||||
import com.google.android.apps.mytracks.io.TrackWriterFactory.TrackFileFormat;
|
import com.google.android.apps.mytracks.io.TrackWriterFactory.TrackFileFormat;
|
||||||
import com.google.android.apps.mytracks.services.ITrackRecordingService;
|
import com.google.android.apps.mytracks.services.ITrackRecordingService;
|
||||||
import com.google.android.apps.mytracks.services.StatusAnnouncerFactory;
|
import com.google.android.apps.mytracks.services.StatusAnnouncerFactory;
|
||||||
@@ -71,7 +70,6 @@ import android.view.View;
|
|||||||
import android.view.Window;
|
import android.view.Window;
|
||||||
import android.view.View.OnTouchListener;
|
import android.view.View.OnTouchListener;
|
||||||
import android.view.ViewGroup.LayoutParams;
|
import android.view.ViewGroup.LayoutParams;
|
||||||
import android.view.WindowManager.BadTokenException;
|
|
||||||
import android.widget.RelativeLayout;
|
import android.widget.RelativeLayout;
|
||||||
import android.widget.TabHost;
|
import android.widget.TabHost;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
@@ -104,14 +102,6 @@ public class MyTracks extends TabActivity implements OnTouchListener,
|
|||||||
|
|
||||||
private ChartActivity chartActivity;
|
private ChartActivity chartActivity;
|
||||||
|
|
||||||
public ChartActivity getChartActivity() {
|
|
||||||
return chartActivity;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setChartActivity(ChartActivity chartActivity) {
|
|
||||||
this.chartActivity = chartActivity;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Authentication
|
* Authentication
|
||||||
*/
|
*/
|
||||||
@@ -373,7 +363,7 @@ public class MyTracks extends TabActivity implements OnTouchListener,
|
|||||||
protected void onStop() {
|
protected void onStop() {
|
||||||
Log.d(MyTracksConstants.TAG, "MyTracks.onStop");
|
Log.d(MyTracksConstants.TAG, "MyTracks.onStop");
|
||||||
// Clean up any temporary track files.
|
// Clean up any temporary track files.
|
||||||
(new TempFileCleaner()).clean();
|
TempFileCleaner.clean();
|
||||||
super.onStop();
|
super.onStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -450,17 +440,17 @@ public class MyTracks extends TabActivity implements OnTouchListener,
|
|||||||
authenticate(results, MyTracksConstants.SEND_TO_GOOGLE,
|
authenticate(results, MyTracksConstants.SEND_TO_GOOGLE,
|
||||||
MyMapsConstants.MAPSHOP_SERVICE);
|
MyMapsConstants.MAPSHOP_SERVICE);
|
||||||
} else {
|
} else {
|
||||||
dismissDialogSafely(DIALOG_PROGRESS);
|
dialogManager.dismissDialogSafely(DIALOG_PROGRESS);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MyTracksConstants.GET_LOGIN: {
|
case MyTracksConstants.GET_LOGIN: {
|
||||||
if (resultCode == RESULT_OK && auth != null) {
|
if (resultCode == RESULT_OK && auth != null) {
|
||||||
if (!auth.authResult(resultCode, results)) {
|
if (!auth.authResult(resultCode, results)) {
|
||||||
dismissDialogSafely(DIALOG_PROGRESS);
|
dialogManager.dismissDialogSafely(DIALOG_PROGRESS);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
dismissDialogSafely(DIALOG_PROGRESS);
|
dialogManager.dismissDialogSafely(DIALOG_PROGRESS);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -516,7 +506,7 @@ public class MyTracks extends TabActivity implements OnTouchListener,
|
|||||||
authenticate(results,
|
authenticate(results,
|
||||||
MyTracksConstants.AUTHENTICATE_TO_TRIX, "writely");
|
MyTracksConstants.AUTHENTICATE_TO_TRIX, "writely");
|
||||||
} else {
|
} else {
|
||||||
dismissDialogSafely(DIALOG_PROGRESS);
|
dialogManager.dismissDialogSafely(DIALOG_PROGRESS);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -527,7 +517,7 @@ public class MyTracks extends TabActivity implements OnTouchListener,
|
|||||||
R.string.progress_message_authenticating_docs);
|
R.string.progress_message_authenticating_docs);
|
||||||
authenticate(results, MyTracksConstants.SEND_TO_DOCS, "wise");
|
authenticate(results, MyTracksConstants.SEND_TO_DOCS, "wise");
|
||||||
} else {
|
} else {
|
||||||
dismissDialogSafely(DIALOG_PROGRESS);
|
dialogManager.dismissDialogSafely(DIALOG_PROGRESS);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -542,7 +532,7 @@ public class MyTracks extends TabActivity implements OnTouchListener,
|
|||||||
Runnable onCompletion = new Runnable() {
|
Runnable onCompletion = new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
setProgressValue(100);
|
setProgressValue(100);
|
||||||
dismissDialogSafely(DIALOG_PROGRESS);
|
dialogManager.dismissDialogSafely(DIALOG_PROGRESS);
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
sendToDocsMessage = sender.getStatusMessage();
|
sendToDocsMessage = sender.getStatusMessage();
|
||||||
@@ -555,13 +545,13 @@ public class MyTracks extends TabActivity implements OnTouchListener,
|
|||||||
sender.setOnCompletion(onCompletion);
|
sender.setOnCompletion(onCompletion);
|
||||||
sender.run();
|
sender.run();
|
||||||
} else {
|
} else {
|
||||||
dismissDialogSafely(DIALOG_PROGRESS);
|
dialogManager.dismissDialogSafely(DIALOG_PROGRESS);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MyTracksConstants.SEND_TO_GOOGLE_DIALOG: {
|
case MyTracksConstants.SEND_TO_GOOGLE_DIALOG: {
|
||||||
shareRequested = false;
|
shareRequested = false;
|
||||||
showDialogSafely(DIALOG_SEND_TO_GOOGLE);
|
dialogManager.showDialogSafely(DIALOG_SEND_TO_GOOGLE);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MyTracksConstants.SEND_TO_GOOGLE: {
|
case MyTracksConstants.SEND_TO_GOOGLE: {
|
||||||
@@ -602,7 +592,7 @@ public class MyTracks extends TabActivity implements OnTouchListener,
|
|||||||
onActivityResult(MyTracksConstants.AUTHENTICATE_TO_DOCS,
|
onActivityResult(MyTracksConstants.AUTHENTICATE_TO_DOCS,
|
||||||
RESULT_OK, new Intent());
|
RESULT_OK, new Intent());
|
||||||
} else {
|
} else {
|
||||||
dismissDialogSafely(DIALOG_PROGRESS);
|
dialogManager.dismissDialogSafely(DIALOG_PROGRESS);
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
handleMapsFinish();
|
handleMapsFinish();
|
||||||
@@ -619,7 +609,7 @@ public class MyTracks extends TabActivity implements OnTouchListener,
|
|||||||
Handler handler = new Handler(handlerThread.getLooper());
|
Handler handler = new Handler(handlerThread.getLooper());
|
||||||
handler.post(sender);
|
handler.post(sender);
|
||||||
} else {
|
} else {
|
||||||
dismissDialogSafely(DIALOG_PROGRESS);
|
dialogManager.dismissDialogSafely(DIALOG_PROGRESS);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -649,7 +639,7 @@ public class MyTracks extends TabActivity implements OnTouchListener,
|
|||||||
shareLinkToMyMap(selectedTrack.getMapId());
|
shareLinkToMyMap(selectedTrack.getMapId());
|
||||||
} else {
|
} else {
|
||||||
shareRequested = true;
|
shareRequested = true;
|
||||||
showDialogSafely(DIALOG_SEND_TO_GOOGLE);
|
dialogManager.showDialogSafely(DIALOG_SEND_TO_GOOGLE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -763,7 +753,7 @@ public class MyTracks extends TabActivity implements OnTouchListener,
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void importGpxFile(final String fileName) {
|
private void importGpxFile(final String fileName) {
|
||||||
showDialogSafely(DIALOG_IMPORT_PROGRESS);
|
dialogManager.showDialogSafely(DIALOG_IMPORT_PROGRESS);
|
||||||
Thread t = new Thread() {
|
Thread t = new Thread() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
@@ -795,7 +785,7 @@ public class MyTracks extends TabActivity implements OnTouchListener,
|
|||||||
// select last track from import file
|
// select last track from import file
|
||||||
setSelectedTrack(trackIdsImported[trackIdsImported.length - 1]);
|
setSelectedTrack(trackIdsImported[trackIdsImported.length - 1]);
|
||||||
} else {
|
} else {
|
||||||
MyTracks.this.showMessageDialog(message, false/* success */);
|
dialogManager.showMessageDialog(message, false/* success */);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
@@ -809,44 +799,6 @@ public class MyTracks extends TabActivity implements OnTouchListener,
|
|||||||
t.start();
|
t.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Just like showDialog, but will catch a BadTokenException that sometimes
|
|
||||||
* (very rarely) gets thrown. This might happen if the user hits the "back"
|
|
||||||
* button immediately after sending tracks to google.
|
|
||||||
*
|
|
||||||
* @param id the dialog id
|
|
||||||
*/
|
|
||||||
public void showDialogSafely(final int id) {
|
|
||||||
runOnUiThread(new Runnable() {
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
showDialog(id);
|
|
||||||
} catch (BadTokenException e) {
|
|
||||||
Log.w(MyTracksConstants.TAG,
|
|
||||||
"Could not display dialog with id " + id, e);
|
|
||||||
} catch (IllegalStateException e) {
|
|
||||||
Log.w(MyTracksConstants.TAG,
|
|
||||||
"Could not display dialog with id " + id, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Dismisses the progress dialog if it is showing. Executed on the UI thread.
|
|
||||||
*/
|
|
||||||
public void dismissDialogSafely(final int id) {
|
|
||||||
runOnUiThread(new Runnable() {
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
dismissDialog(id);
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
// This will be thrown if this dialog was not shown before.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// ProgressIndicator implementation
|
// ProgressIndicator implementation
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -1070,7 +1022,7 @@ public class MyTracks extends TabActivity implements OnTouchListener,
|
|||||||
@Override
|
@Override
|
||||||
public void handleAccountSelected(Account account) {
|
public void handleAccountSelected(Account account) {
|
||||||
if (account == null) {
|
if (account == null) {
|
||||||
dismissDialogSafely(DIALOG_PROGRESS);
|
dialogManager.dismissDialogSafely(DIALOG_PROGRESS);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
doLogin(results, requestCode, service, account);
|
doLogin(results, requestCode, service, account);
|
||||||
@@ -1163,7 +1115,7 @@ public class MyTracks extends TabActivity implements OnTouchListener,
|
|||||||
}
|
}
|
||||||
setProgressValue(0);
|
setProgressValue(0);
|
||||||
clearProgressMessage();
|
clearProgressMessage();
|
||||||
showDialogSafely(DIALOG_PROGRESS);
|
dialogManager.showDialogSafely(DIALOG_PROGRESS);
|
||||||
if (sendToGoogleDialog.getSendToMyMaps()) {
|
if (sendToGoogleDialog.getSendToMyMaps()) {
|
||||||
if (!sendToGoogleDialog.getCreateNewMap()) {
|
if (!sendToGoogleDialog.getCreateNewMap()) {
|
||||||
Intent listIntent = new Intent(this, MyMapsList.class);
|
Intent listIntent = new Intent(this, MyMapsList.class);
|
||||||
@@ -1232,43 +1184,20 @@ public class MyTracks extends TabActivity implements OnTouchListener,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Shows a dialog with the given message.
|
|
||||||
* Does it on the UI thread.
|
|
||||||
*
|
|
||||||
* @param success if true, displays an info icon/title, otherwise an error
|
|
||||||
* icon/title
|
|
||||||
* @param message resource string id
|
|
||||||
*/
|
|
||||||
public void showMessageDialog(final int message, final boolean success) {
|
|
||||||
runOnUiThread(new Runnable() {
|
|
||||||
public void run() {
|
|
||||||
AlertDialog dialog = null;
|
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(MyTracks.this);
|
|
||||||
builder.setMessage(MyTracks.this.getString(message));
|
|
||||||
builder.setNegativeButton(MyTracks.this.getString(R.string.ok), null);
|
|
||||||
builder.setIcon(success ? android.R.drawable.ic_dialog_info :
|
|
||||||
android.R.drawable.ic_dialog_alert);
|
|
||||||
builder.setTitle(success ? R.string.success : R.string.error);
|
|
||||||
dialog = builder.create();
|
|
||||||
dialog.show();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves the track with the given id to the SD card.
|
* Saves the track with the given id to the SD card.
|
||||||
*
|
*
|
||||||
* @param trackId The id of the track to be sent
|
* @param trackId The id of the track to be sent
|
||||||
*/
|
*/
|
||||||
public void saveTrack(long trackId, TrackFileFormat format) {
|
public void saveTrack(long trackId, TrackFileFormat format) {
|
||||||
showDialogSafely(DIALOG_WRITE_PROGRESS);
|
dialogManager.showDialogSafely(DIALOG_WRITE_PROGRESS);
|
||||||
final TrackWriter writer =
|
final TrackWriter writer =
|
||||||
TrackWriterFactory.newWriter(this, providerUtils, trackId, format);
|
TrackWriterFactory.newWriter(this, providerUtils, trackId, format);
|
||||||
writer.setOnCompletion(new Runnable() {
|
writer.setOnCompletion(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
dismissDialogSafely(DIALOG_WRITE_PROGRESS);
|
dialogManager.dismissDialogSafely(DIALOG_WRITE_PROGRESS);
|
||||||
showMessageDialog(writer.getErrorMessage(), writer.wasSuccess());
|
dialogManager.showMessageDialog(writer.getErrorMessage(),
|
||||||
|
writer.wasSuccess());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
writer.writeTrackAsync();
|
writer.writeTrackAsync();
|
||||||
@@ -1282,7 +1211,7 @@ public class MyTracks extends TabActivity implements OnTouchListener,
|
|||||||
* @param trackId The id of the track to be sent
|
* @param trackId The id of the track to be sent
|
||||||
*/
|
*/
|
||||||
public void sendTrack(long trackId, final TrackFileFormat format) {
|
public void sendTrack(long trackId, final TrackFileFormat format) {
|
||||||
showDialogSafely(DIALOG_WRITE_PROGRESS);
|
dialogManager.showDialogSafely(DIALOG_WRITE_PROGRESS);
|
||||||
final TrackWriter writer =
|
final TrackWriter writer =
|
||||||
TrackWriterFactory.newWriter(this, providerUtils, trackId, format);
|
TrackWriterFactory.newWriter(this, providerUtils, trackId, format);
|
||||||
|
|
||||||
@@ -1294,9 +1223,10 @@ public class MyTracks extends TabActivity implements OnTouchListener,
|
|||||||
writer.setDirectory(dir);
|
writer.setDirectory(dir);
|
||||||
writer.setOnCompletion(new Runnable() {
|
writer.setOnCompletion(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
dismissDialogSafely(DIALOG_WRITE_PROGRESS);
|
dialogManager.dismissDialogSafely(DIALOG_WRITE_PROGRESS);
|
||||||
if (!writer.wasSuccess()) {
|
if (!writer.wasSuccess()) {
|
||||||
showMessageDialog(writer.getErrorMessage(), writer.wasSuccess());
|
dialogManager.showMessageDialog(writer.getErrorMessage(),
|
||||||
|
writer.wasSuccess());
|
||||||
} else {
|
} else {
|
||||||
Intent shareIntent = new Intent(Intent.ACTION_SEND);
|
Intent shareIntent = new Intent(Intent.ACTION_SEND);
|
||||||
shareIntent.putExtra(Intent.EXTRA_SUBJECT,
|
shareIntent.putExtra(Intent.EXTRA_SUBJECT,
|
||||||
@@ -1324,7 +1254,8 @@ public class MyTracks extends TabActivity implements OnTouchListener,
|
|||||||
Toast.makeText(this, getMapsResultMessage(), Toast.LENGTH_LONG).show();
|
Toast.makeText(this, getMapsResultMessage(), Toast.LENGTH_LONG).show();
|
||||||
shareLinkToMyMap(sendToMyMapsMapId);
|
shareLinkToMyMap(sendToMyMapsMapId);
|
||||||
} else {
|
} else {
|
||||||
showDialogSafely(DialogManager.DIALOG_SEND_TO_GOOGLE_RESULT);
|
dialogManager.showDialogSafely(
|
||||||
|
DialogManager.DIALOG_SEND_TO_GOOGLE_RESULT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1352,6 +1283,14 @@ public class MyTracks extends TabActivity implements OnTouchListener,
|
|||||||
return accountChooser;
|
return accountChooser;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ChartActivity getChartActivity() {
|
||||||
|
return chartActivity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setChartActivity(ChartActivity chartActivity) {
|
||||||
|
this.chartActivity = chartActivity;
|
||||||
|
}
|
||||||
|
|
||||||
public String getSendToMyMapsMapId() {
|
public String getSendToMyMapsMapId() {
|
||||||
return sendToMyMapsMapId;
|
return sendToMyMapsMapId;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,15 +27,16 @@ public class TempFileCleaner {
|
|||||||
|
|
||||||
private long currentTimeMillis;
|
private long currentTimeMillis;
|
||||||
|
|
||||||
public TempFileCleaner() {
|
public static void clean() {
|
||||||
currentTimeMillis = System.currentTimeMillis();
|
(new TempFileCleaner(System.currentTimeMillis())).cleanImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
public TempFileCleaner(long time) {
|
// @VisibleForTesting
|
||||||
|
TempFileCleaner(long time) {
|
||||||
currentTimeMillis = time;
|
currentTimeMillis = time;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clean() {
|
private void cleanImpl() {
|
||||||
if (!Environment.getExternalStorageState().equals(
|
if (!Environment.getExternalStorageState().equals(
|
||||||
Environment.MEDIA_MOUNTED)) {
|
Environment.MEDIA_MOUNTED)) {
|
||||||
return; // Can't do anything now.
|
return; // Can't do anything now.
|
||||||
@@ -54,15 +55,14 @@ public class TempFileCleaner {
|
|||||||
+ "tmp"));
|
+ "tmp"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// VisibleForTesting
|
// @VisibleForTesting
|
||||||
protected int cleanTmpDirectory(File dir) {
|
int cleanTmpDirectory(File dir) {
|
||||||
if (!dir.exists()) {
|
if (!dir.exists()) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
File[] list = dir.listFiles();
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
long oldest = currentTimeMillis - 1000 * 3600;
|
long oldest = currentTimeMillis - 1000 * 3600;
|
||||||
for (File f : list) {
|
for (File f : dir.listFiles()) {
|
||||||
if (f.lastModified() < oldest) {
|
if (f.lastModified() < oldest) {
|
||||||
f.delete();
|
f.delete();
|
||||||
count++;
|
count++;
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ public class TempFileCleanerTest extends AndroidTestCase {
|
|||||||
|
|
||||||
public void test_noDir() {
|
public void test_noDir() {
|
||||||
File dir = AndroidMock.createMock(File.class, "/no_file");
|
File dir = AndroidMock.createMock(File.class, "/no_file");
|
||||||
TempFileCleaner cleaner = new TempFileCleaner();
|
TempFileCleaner cleaner = new TempFileCleaner(0);
|
||||||
expect(dir.exists()).andStubReturn(false);
|
expect(dir.exists()).andStubReturn(false);
|
||||||
AndroidMock.replay(dir);
|
AndroidMock.replay(dir);
|
||||||
assertEquals(0, cleaner.cleanTmpDirectory(dir));
|
assertEquals(0, cleaner.cleanTmpDirectory(dir));
|
||||||
@@ -43,7 +43,7 @@ public class TempFileCleanerTest extends AndroidTestCase {
|
|||||||
|
|
||||||
public void test_emptyDir() {
|
public void test_emptyDir() {
|
||||||
File dir = AndroidMock.createMock(File.class, "/no_file");
|
File dir = AndroidMock.createMock(File.class, "/no_file");
|
||||||
TempFileCleaner cleaner = new TempFileCleaner();
|
TempFileCleaner cleaner = new TempFileCleaner(0);
|
||||||
expect(dir.exists()).andStubReturn(true);
|
expect(dir.exists()).andStubReturn(true);
|
||||||
expect(dir.listFiles()).andStubReturn(new File[0]);
|
expect(dir.listFiles()).andStubReturn(new File[0]);
|
||||||
AndroidMock.replay(dir);
|
AndroidMock.replay(dir);
|
||||||
|
|||||||
Reference in New Issue
Block a user