Add basic tests to the DialogManager.

This commit is contained in:
Sandor Dornbush
2010-11-08 11:28:39 -08:00
parent a21663da61
commit a0d42c8b59
2 changed files with 42 additions and 42 deletions
@@ -27,18 +27,18 @@ import android.view.View;
import android.view.WindowManager.BadTokenException; import android.view.WindowManager.BadTokenException;
/** /**
* A class to handle a dialog related events for My Tracks. * A class to handle all dialog related events for My Tracks.
* *
* @author Sandor Dornbush * @author Sandor Dornbush
*/ */
public class DialogManager { public class DialogManager {
public static final int DIALOG_PROGRESS = 1; public static final int DIALOG_CHART_SETTINGS = 1;
public static final int DIALOG_IMPORT_PROGRESS = 2; public static final int DIALOG_IMPORT_PROGRESS = 2;
public static final int DIALOG_WRITE_PROGRESS = 3; public static final int DIALOG_PROGRESS = 3;
public static final int DIALOG_SEND_TO_GOOGLE = 4; public static final int DIALOG_SEND_TO_GOOGLE = 4;
public static final int DIALOG_SEND_TO_GOOGLE_RESULT = 5; public static final int DIALOG_SEND_TO_GOOGLE_RESULT = 5;
public static final int DIALOG_CHART_SETTINGS = 6; public static final int DIALOG_WRITE_PROGRESS = 6;
private ProgressDialog progressDialog; private ProgressDialog progressDialog;
private ProgressDialog importProgressDialog; private ProgressDialog importProgressDialog;
@@ -55,15 +55,9 @@ public class DialogManager {
protected Dialog onCreateDialog(int id, Bundle args) { protected Dialog onCreateDialog(int id, Bundle args) {
switch (id) { switch (id) {
case DIALOG_PROGRESS: case DIALOG_CHART_SETTINGS:
progressDialog = new ProgressDialog(activity); chartSettingsDialog = new ChartSettingsDialog(activity);
progressDialog.setIcon(android.R.drawable.ic_dialog_info); return chartSettingsDialog;
progressDialog.setTitle(activity.getString(R.string.progress_title));
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressDialog.setMessage("");
progressDialog.setMax(100);
progressDialog.setProgress(10);
return progressDialog;
case DIALOG_IMPORT_PROGRESS: case DIALOG_IMPORT_PROGRESS:
importProgressDialog = new ProgressDialog(activity); importProgressDialog = new ProgressDialog(activity);
importProgressDialog.setIcon(android.R.drawable.ic_dialog_info); importProgressDialog.setIcon(android.R.drawable.ic_dialog_info);
@@ -73,15 +67,15 @@ public class DialogManager {
importProgressDialog.setMessage( importProgressDialog.setMessage(
activity.getString(R.string.import_progress_message)); activity.getString(R.string.import_progress_message));
return importProgressDialog; return importProgressDialog;
case DIALOG_WRITE_PROGRESS: case DIALOG_PROGRESS:
writeProgressDialog = new ProgressDialog(activity); progressDialog = new ProgressDialog(activity);
writeProgressDialog.setIcon(android.R.drawable.ic_dialog_info); progressDialog.setIcon(android.R.drawable.ic_dialog_info);
writeProgressDialog.setTitle( progressDialog.setTitle(activity.getString(R.string.progress_title));
activity.getString(R.string.progress_title)); progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
writeProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); progressDialog.setMessage("");
writeProgressDialog.setMessage( progressDialog.setMax(100);
activity.getString(R.string.write_progress_message)); progressDialog.setProgress(10);
return writeProgressDialog; return progressDialog;
case DIALOG_SEND_TO_GOOGLE: case DIALOG_SEND_TO_GOOGLE:
sendToGoogleDialog = new SendToGoogleDialog(activity); sendToGoogleDialog = new SendToGoogleDialog(activity);
return sendToGoogleDialog; return sendToGoogleDialog;
@@ -100,9 +94,15 @@ public class DialogManager {
}); });
sendToGoogleResultDialog = builder.create(); sendToGoogleResultDialog = builder.create();
return sendToGoogleResultDialog; return sendToGoogleResultDialog;
case DIALOG_CHART_SETTINGS: case DIALOG_WRITE_PROGRESS:
chartSettingsDialog = new ChartSettingsDialog(activity); writeProgressDialog = new ProgressDialog(activity);
return chartSettingsDialog; 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; return null;
} }
@@ -1,12 +1,12 @@
/* /*
* Copyright 2008 Google Inc. * Copyright 2008 Google Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not * 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 * use this file except in compliance with the License. You may obtain a copy of
* the License at * the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@@ -102,9 +102,9 @@ public class MyTracks extends TabActivity implements OnTouchListener,
private static MyTracks instance; private static MyTracks instance;
private ChartActivity chartActivity; private ChartActivity chartActivity;
/* /*
* Authentication. * Authentication
*/ */
private AuthManager auth; private AuthManager auth;
private final HashMap<String, AuthManager> authMap = private final HashMap<String, AuthManager> authMap =
@@ -159,7 +159,7 @@ public class MyTracks extends TabActivity implements OnTouchListener,
* Utilities to deal with the database. * Utilities to deal with the database.
*/ */
private MyTracksProviderUtils providerUtils; private MyTracksProviderUtils providerUtils;
private SharedPreferences sharedPreferences; private SharedPreferences sharedPreferences;
/** /**
@@ -190,7 +190,7 @@ public class MyTracks extends TabActivity implements OnTouchListener,
trackRecordingService = null; trackRecordingService = null;
} }
}; };
/** /**
* Whether {@link #serviceConnection} is bound or not. * Whether {@link #serviceConnection} is bound or not.
*/ */
@@ -226,11 +226,11 @@ public class MyTracks extends TabActivity implements OnTouchListener,
/** /**
* Checks whether we have a track recording session in progress. * Checks whether we have a track recording session in progress.
* In some cases, when the service has crashed or has been restarted * In some cases, when the service has crashed or has been restarted
* by the system, we fall back to the shared preferences. * by the system, we fall back to the shared preferences.
* *
* @return true if the activity is bound to the track recording service and * @return true if the activity is bound to the track recording service and
* the service is recording a track or in case the service is down, * the service is recording a track or in case the service is down,
* based on settings from the shared preferences. * based on settings from the shared preferences.
*/ */
public boolean isRecording() { public boolean isRecording() {
if (trackRecordingService == null) { if (trackRecordingService == null) {
@@ -241,12 +241,12 @@ public class MyTracks extends TabActivity implements OnTouchListener,
return trackRecordingService.isRecording(); return trackRecordingService.isRecording();
} catch (RemoteException e) { } catch (RemoteException e) {
Log.e(MyTracksConstants.TAG, "MyTracks: Remote exception.", e); Log.e(MyTracksConstants.TAG, "MyTracks: Remote exception.", e);
// Fall back to alternative check method. // Fall back to alternative check method.
return isRecordingBasedOnSharedPreferences(); return isRecordingBasedOnSharedPreferences();
} }
} }
private boolean isRecordingBasedOnSharedPreferences() { private boolean isRecordingBasedOnSharedPreferences() {
// TrackRecordingServices guarantees that recordingTrackId is set to // TrackRecordingServices guarantees that recordingTrackId is set to
// -1 if the track has been stopped. // -1 if the track has been stopped.
@@ -345,7 +345,7 @@ public class MyTracks extends TabActivity implements OnTouchListener,
Log.d(MyTracksConstants.TAG, "Received an intent with no action."); Log.d(MyTracksConstants.TAG, "Received an intent with no action.");
} }
} }
@Override @Override
protected void onDestroy() { protected void onDestroy() {
Log.d(MyTracksConstants.TAG, "MyTracks.onDestroy"); Log.d(MyTracksConstants.TAG, "MyTracks.onDestroy");
@@ -1046,7 +1046,7 @@ public class MyTracks extends TabActivity implements OnTouchListener,
doLogin(results, requestCode, service, null); doLogin(results, requestCode, service, null);
} }
} }
private void doLogin(final Intent results, final int requestCode, private void doLogin(final Intent results, final int requestCode,
final String service, final Account account) { final String service, final Account account) {
auth.doLogin(new Runnable() { auth.doLogin(new Runnable() {
@@ -1056,7 +1056,7 @@ public class MyTracks extends TabActivity implements OnTouchListener,
} }
}, account); }, account);
} }
private void startRecordingNewTrack( private void startRecordingNewTrack(
ITrackRecordingService trackRecordingService) { ITrackRecordingService trackRecordingService) {
try { try {
@@ -1324,11 +1324,11 @@ public class MyTracks extends TabActivity implements OnTouchListener,
public String getSendToMyMapsMapId() { public String getSendToMyMapsMapId() {
return sendToMyMapsMapId; return sendToMyMapsMapId;
} }
public boolean getSendToGoogleSuccess() { public boolean getSendToGoogleSuccess() {
return sendToMyMapsSuccess && sendToDocsSuccess; return sendToMyMapsSuccess && sendToDocsSuccess;
} }
// @VisibleForTesting // @VisibleForTesting
long getRecordingTrackId() { long getRecordingTrackId() {
return recordingTrackId; return recordingTrackId;