Merge with head and address comments.

This commit is contained in:
Sandor Dornbush
2010-11-03 12:53:12 -07:00
parent 224c0d759f
commit 7df8025f6a
8 changed files with 96 additions and 44 deletions
+1
View File
@@ -3,3 +3,4 @@ syntax:glob
*/bin */bin
*/gen/** */gen/**
.metadata .metadata
MyTracksTest/annotations.log
+4 -1
View File
@@ -12,7 +12,7 @@
android:value="AEdPqrEAAAAIi-_QiwoRSc9_bAC9cmuNXTQyU8ajJmGtKdhskQ" /> android:value="AEdPqrEAAAAIi-_QiwoRSc9_bAC9cmuNXTQyU8ajJmGtKdhskQ" />
<provider android:name="com.google.android.apps.mytracks.content.MyTracksProvider" <provider android:name="com.google.android.apps.mytracks.content.MyTracksProvider"
android:multiprocess="true" android:process=":trackrecord"
android:authorities="com.google.android.maps.mytracks" /> android:authorities="com.google.android.maps.mytracks" />
<activity android:name="com.google.android.apps.mytracks.MyTracks" <activity android:name="com.google.android.apps.mytracks.MyTracks"
@@ -101,6 +101,9 @@
<uses-permission android:name="com.google.android.googleapps.permission.GOOGLE_AUTH.writely" /> <uses-permission android:name="com.google.android.googleapps.permission.GOOGLE_AUTH.writely" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" /> <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<!-- Permissions for misc services -->
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-sdk android:minSdkVersion="3"/> <uses-sdk android:minSdkVersion="3"/>
<supports-screens <supports-screens
android:largeScreens="true" android:largeScreens="true"
@@ -21,6 +21,7 @@ import android.app.AlertDialog;
import android.app.Dialog; import android.app.Dialog;
import android.app.ProgressDialog; import android.app.ProgressDialog;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.os.Bundle;
import android.util.Log; import android.util.Log;
import android.view.View; import android.view.View;
@@ -51,7 +52,7 @@ public class DialogManager {
this.activity = activity; this.activity = activity;
} }
protected Dialog onCreateDialog(int id) { protected Dialog onCreateDialog(int id, Bundle args) {
switch (id) { switch (id) {
case DIALOG_PROGRESS: case DIALOG_PROGRESS:
progressDialog = new ProgressDialog(activity); progressDialog = new ProgressDialog(activity);
@@ -18,6 +18,10 @@ package com.google.android.apps.mytracks;
import com.google.android.accounts.Account; import com.google.android.accounts.Account;
import com.google.android.apps.mymaps.MyMapsConstants; import com.google.android.apps.mymaps.MyMapsConstants;
import com.google.android.apps.mymaps.MyMapsList; import com.google.android.apps.mymaps.MyMapsList;
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_IMPORT_PROGRESS;
import static com.google.android.apps.mytracks.DialogManager.DIALOG_WRITE_PROGRESS;
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.Waypoint; import com.google.android.apps.mytracks.content.Waypoint;
@@ -107,9 +111,8 @@ public class MyTracks extends TabActivity implements OnTouchListener,
} }
/* /*
* Authentication: * Authentication
*/ */
private AuthManager auth; private AuthManager auth;
private final HashMap<String, AuthManager> authMap = private final HashMap<String, AuthManager> authMap =
new HashMap<String, AuthManager>(); new HashMap<String, AuthManager>();
@@ -277,7 +280,7 @@ public class MyTracks extends TabActivity implements OnTouchListener,
new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
layout.setLayoutParams(params); layout.setLayoutParams(params);
navControls = navControls =
new NavControls(this, layout, leftIcons, rightIcons, changeTab); new NavControls(this, layout, leftIcons, rightIcons, changeTab);
navControls.show(); navControls.show();
tabHost.addView(layout); tabHost.addView(layout);
layout.setOnTouchListener(this); layout.setOnTouchListener(this);
@@ -345,7 +348,7 @@ public class MyTracks extends TabActivity implements OnTouchListener,
@Override @Override
protected void onStop() { protected void onStop() {
Log.d(MyTracksConstants.TAG, "MyTracks.onStop"); Log.d(MyTracksConstants.TAG, "MyTracks.onStop");
// Clean up any temporary GPX and KML files. // Clean up any temporary track files.
(new TempFileCleaner()).clean(); (new TempFileCleaner()).clean();
super.onStop(); super.onStop();
} }
@@ -381,8 +384,8 @@ public class MyTracks extends TabActivity implements OnTouchListener,
*/ */
@Override @Override
protected Dialog onCreateDialog(int id) { protected Dialog onCreateDialog(int id, Bundle args) {
return dialogManager.onCreateDialog(id); return dialogManager.onCreateDialog(id, args);
} }
@Override @Override
@@ -423,17 +426,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(DialogManager.DIALOG_PROGRESS); 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(DialogManager.DIALOG_PROGRESS); dismissDialogSafely(DIALOG_PROGRESS);
} }
} else { } else {
dismissDialogSafely(DialogManager.DIALOG_PROGRESS); dismissDialogSafely(DIALOG_PROGRESS);
} }
break; break;
} }
@@ -489,7 +492,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(DialogManager.DIALOG_PROGRESS); dismissDialogSafely(DIALOG_PROGRESS);
} }
break; break;
} }
@@ -500,7 +503,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(DialogManager.DIALOG_PROGRESS); dismissDialogSafely(DIALOG_PROGRESS);
} }
break; break;
} }
@@ -515,7 +518,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(DialogManager.DIALOG_PROGRESS); dismissDialogSafely(DIALOG_PROGRESS);
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
public void run() { public void run() {
sendToDocsMessage = sender.getStatusMessage(); sendToDocsMessage = sender.getStatusMessage();
@@ -528,13 +531,13 @@ public class MyTracks extends TabActivity implements OnTouchListener,
sender.setOnCompletion(onCompletion); sender.setOnCompletion(onCompletion);
sender.run(); sender.run();
} else { } else {
dismissDialogSafely(DialogManager.DIALOG_PROGRESS); dismissDialogSafely(DIALOG_PROGRESS);
} }
break; break;
} }
case MyTracksConstants.SEND_TO_GOOGLE_DIALOG: { case MyTracksConstants.SEND_TO_GOOGLE_DIALOG: {
shareRequested = false; shareRequested = false;
showDialogSafely(DialogManager.DIALOG_SEND_TO_GOOGLE); showDialogSafely(DIALOG_SEND_TO_GOOGLE);
break; break;
} }
case MyTracksConstants.SEND_TO_GOOGLE: { case MyTracksConstants.SEND_TO_GOOGLE: {
@@ -575,7 +578,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(DialogManager.DIALOG_PROGRESS); dismissDialogSafely(DIALOG_PROGRESS);
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
public void run() { public void run() {
handleMapsFinish(); handleMapsFinish();
@@ -592,7 +595,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(DialogManager.DIALOG_PROGRESS); dismissDialogSafely(DIALOG_PROGRESS);
} }
break; break;
} }
@@ -622,7 +625,7 @@ public class MyTracks extends TabActivity implements OnTouchListener,
shareLinkToMyMap(selectedTrack.getMapId()); shareLinkToMyMap(selectedTrack.getMapId());
} else { } else {
shareRequested = true; shareRequested = true;
showDialogSafely(DialogManager.DIALOG_SEND_TO_GOOGLE); showDialogSafely(DIALOG_SEND_TO_GOOGLE);
} }
} }
break; break;
@@ -736,7 +739,7 @@ public class MyTracks extends TabActivity implements OnTouchListener,
} }
private void importGpxFile(final String fileName) { private void importGpxFile(final String fileName) {
showDialogSafely(DialogManager.DIALOG_IMPORT_PROGRESS); showDialogSafely(DIALOG_IMPORT_PROGRESS);
Thread t = new Thread() { Thread t = new Thread() {
@Override @Override
public void run() { public void run() {
@@ -773,7 +776,7 @@ public class MyTracks extends TabActivity implements OnTouchListener,
} finally { } finally {
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
public void run() { public void run() {
dismissDialog(DialogManager.DIALOG_IMPORT_PROGRESS); dismissDialog(DIALOG_IMPORT_PROGRESS);
} }
}); });
} }
@@ -1048,7 +1051,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(DialogManager.DIALOG_PROGRESS); dismissDialogSafely(DIALOG_PROGRESS);
return; return;
} }
doLogin(results, requestCode, service, account); doLogin(results, requestCode, service, account);
@@ -1141,7 +1144,7 @@ public class MyTracks extends TabActivity implements OnTouchListener,
} }
setProgressValue(0); setProgressValue(0);
clearProgressMessage(); clearProgressMessage();
showDialogSafely(DialogManager.DIALOG_PROGRESS); 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);
@@ -1282,12 +1285,12 @@ 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 saveTrack(long trackId, TrackFileFormat format) { public void saveTrack(long trackId, TrackFileFormat format) {
showDialogSafely(DialogManager.DIALOG_WRITE_PROGRESS); 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(DialogManager.DIALOG_WRITE_PROGRESS); dismissDialogSafely(DIALOG_WRITE_PROGRESS);
showMessageDialog(writer.getErrorMessage(), writer.wasSuccess()); showMessageDialog(writer.getErrorMessage(), writer.wasSuccess());
} }
}); });
@@ -1302,7 +1305,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(DialogManager.DIALOG_WRITE_PROGRESS); showDialogSafely(DIALOG_WRITE_PROGRESS);
final TrackWriter writer = final TrackWriter writer =
TrackWriterFactory.newWriter(this, providerUtils, trackId, format); TrackWriterFactory.newWriter(this, providerUtils, trackId, format);
@@ -1314,7 +1317,7 @@ 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(DialogManager.DIALOG_WRITE_PROGRESS); dismissDialogSafely(DIALOG_WRITE_PROGRESS);
if (!writer.wasSuccess()) { if (!writer.wasSuccess()) {
showMessageDialog(writer.getErrorMessage(), writer.wasSuccess()); showMessageDialog(writer.getErrorMessage(), writer.wasSuccess());
} else { } else {
@@ -1372,9 +1375,6 @@ public class MyTracks extends TabActivity implements OnTouchListener,
return accountChooser; return accountChooser;
} }
/**
* @return the sendToMyMapsMapId
*/
public String getSendToMyMapsMapId() { public String getSendToMyMapsMapId() {
return sendToMyMapsMapId; return sendToMyMapsMapId;
} }
@@ -29,6 +29,10 @@ public class TempFileCleaner {
} }
public void clean() { public void clean() {
if (!Environment.getExternalStorageState().equals(
Environment.MEDIA_MOUNTED)) {
return; // Can't do anything now.
}
cleanTmpDirectory("csv"); cleanTmpDirectory("csv");
cleanTmpDirectory("gpx"); cleanTmpDirectory("gpx");
cleanTmpDirectory("kml"); cleanTmpDirectory("kml");
@@ -36,13 +40,14 @@ public class TempFileCleaner {
} }
private void cleanTmpDirectory(String name) { private void cleanTmpDirectory(String name) {
if (!Environment.getExternalStorageState().equals(
Environment.MEDIA_MOUNTED)) {
return; // Can't do anything now.
}
String sep = System.getProperty("file.separator"); String sep = System.getProperty("file.separator");
File dir = new File( cleanTmpDirectory(
Environment.getExternalStorageDirectory() + sep + name + sep + "tmp"); new File(
Environment.getExternalStorageDirectory() + sep + name + sep
+ "tmp"));
}
private void cleanTmpDirectory(File dir) {
if (!dir.exists()) { if (!dir.exists()) {
return; return;
} }
@@ -27,6 +27,8 @@ import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.speech.tts.TextToSpeech; import android.speech.tts.TextToSpeech;
import android.speech.tts.TextToSpeech.OnInitListener; import android.speech.tts.TextToSpeech.OnInitListener;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.util.Log; import android.util.Log;
import java.util.Locale; import java.util.Locale;
@@ -63,6 +65,26 @@ public class StatusAnnouncerTask implements PeriodicTask {
*/ */
private boolean ready = false; private boolean ready = false;
/**
* Whether we're allowed to speak right now.
*/
private boolean speechAllowed;
/**
* Listener which updates {@link #speechAllowed} when the phone state changes.
*/
private final PhoneStateListener phoneListener = new PhoneStateListener() {
@Override
public void onCallStateChanged(int state, String incomingNumber) {
speechAllowed = state == TelephonyManager.CALL_STATE_IDLE;
if (!speechAllowed && tts.isSpeaking()) {
// If we're already speaking, stop it.
tts.stop();
}
}
};
/** /**
* Constructs the announcer and start the TTS engine. * Constructs the announcer and start the TTS engine.
*/ */
@@ -94,8 +116,8 @@ public class StatusAnnouncerTask implements PeriodicTask {
int languageAvailability = tts.isLanguageAvailable(speechLanguage); int languageAvailability = tts.isLanguageAvailable(speechLanguage);
if (languageAvailability == TextToSpeech.LANG_MISSING_DATA || if (languageAvailability == TextToSpeech.LANG_MISSING_DATA ||
languageAvailability == TextToSpeech.LANG_NOT_SUPPORTED) { languageAvailability == TextToSpeech.LANG_NOT_SUPPORTED) {
// English is probably supported // English is probably supported.
// TODO: Somehow use announcement strings from English too // TODO: Somehow use announcement strings from English too.
Log.w(MyTracksConstants.TAG, "Default language not available, using English."); Log.w(MyTracksConstants.TAG, "Default language not available, using English.");
speechLanguage = Locale.ENGLISH; speechLanguage = Locale.ENGLISH;
} }
@@ -116,6 +138,12 @@ public class StatusAnnouncerTask implements PeriodicTask {
return; return;
} }
if (!speechAllowed) {
Log.i(MyTracksConstants.TAG,
"Not making announcement - not allowed at this time");
return;
}
if (service == null || service.getTripStatistics() == null) { if (service == null || service.getTripStatistics() == null) {
Log.e(MyTracksConstants.TAG, "StatusAnnouncer stats not initialized."); Log.e(MyTracksConstants.TAG, "StatusAnnouncer stats not initialized.");
return; return;
@@ -193,12 +221,23 @@ public class StatusAnnouncerTask implements PeriodicTask {
context.getString(speedLabel)); context.getString(speedLabel));
} }
public void shutdown() { @Override
tts.shutdown(); public void start() {
// Register ourselves as a listener so we won't speak during a call.
speechAllowed = true;
TelephonyManager telephony =
(TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
telephony.listen(phoneListener, PhoneStateListener.LISTEN_CALL_STATE);
} }
@Override @Override
public void start() { public void shutdown() {
// Stop listening to phone state.
TelephonyManager telephony =
(TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
telephony.listen(phoneListener, PhoneStateListener.LISTEN_NONE);
tts.shutdown();
} }
public static int getVolumeStream() { public static int getVolumeStream() {
+3
View File
@@ -1,4 +1,7 @@
<factorypath> <factorypath>
<factorypathentry kind="PLUGIN" id="org.eclipse.jst.ws.annotations.core" enabled="true" runInBatchMode="false"/> <factorypathentry kind="PLUGIN" id="org.eclipse.jst.ws.annotations.core" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="WKSPJAR" id="/MyTracksTest/libs/AndroidMockGenerator.jar" enabled="true" runInBatchMode="false"/> <factorypathentry kind="WKSPJAR" id="/MyTracksTest/libs/AndroidMockGenerator.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="ANDROID_SDK/platforms/android-8/android.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="ANDROID_SDK/add-ons/addon_google_apis_google_inc_8/libs/maps.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="MYTRACKS_BIN" enabled="true" runInBatchMode="false"/>
</factorypath> </factorypath>
@@ -1,7 +1,7 @@
#Thu Aug 12 19:30:48 BRT 2010 #Mon Nov 01 02:42:03 BRST 2010
eclipse.preferences.version=1 eclipse.preferences.version=1
org.eclipse.jdt.apt.aptEnabled=true org.eclipse.jdt.apt.aptEnabled=true
org.eclipse.jdt.apt.genSrcDir=.apt_generated org.eclipse.jdt.apt.genSrcDir=.apt_generated
org.eclipse.jdt.apt.processorOptions/bin_dir=MyTracksTest/bin org.eclipse.jdt.apt.processorOptions/bin_dir=%PROJECT.DIR%/bin
org.eclipse.jdt.apt.processorOptions/logfile=MyTracksTest/annotations.log org.eclipse.jdt.apt.processorOptions/logfile=%PROJECT.DIR%/annotations.log
org.eclipse.jdt.apt.reconcileEnabled=false org.eclipse.jdt.apt.reconcileEnabled=false