Fixing Toast calls outside the UI thread.

This commit is contained in:
Rodrigo Damazio
2011-06-03 01:24:42 -03:00
parent 84835428ba
commit cc4be23802
3 changed files with 41 additions and 27 deletions
@@ -133,7 +133,12 @@ public class ExportAllTracks {
Log.i(Constants.TAG, "ExportAllTracks: Releasing wake lock.");
}
Log.i(Constants.TAG, "ExportAllTracks: Done");
Toast.makeText(activity, R.string.export_done, Toast.LENGTH_SHORT).show();
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(activity, R.string.export_done, Toast.LENGTH_SHORT).show();
}
});
}
private void makeProgressDialog(final int trackCount) {
@@ -193,8 +198,13 @@ public class ExportAllTracks {
if (!writer.wasSuccess()) {
// Abort the whole export on the first error.
int error = writer.getErrorMessage();
Toast.makeText(activity, error, Toast.LENGTH_LONG).show();
final int error = writer.getErrorMessage();
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(activity, error, Toast.LENGTH_LONG).show();
}
});
return;
}
}
@@ -51,6 +51,7 @@ import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import java.util.EnumSet;
@@ -464,21 +465,21 @@ public class MapActivity extends com.google.android.maps.MapActivity
@Override
public void onProviderStateChange(ProviderState state) {
final int messageId;
final boolean bindClick;
final boolean isGpsDisabled;
switch (state) {
case DISABLED:
messageId = R.string.status_enable_gps;
bindClick = true;
isGpsDisabled = true;
break;
case NO_FIX:
case BAD_FIX:
messageId = R.string.wait_for_fix;
bindClick = false;
isGpsDisabled = false;
break;
case GOOD_FIX:
// Nothing to show.
messageId = -1;
bindClick = false;
isGpsDisabled = false;
break;
default:
throw new IllegalArgumentException("Unexpected state: " + state);
@@ -491,7 +492,13 @@ public class MapActivity extends com.google.android.maps.MapActivity
messageText.setText(messageId);
messagePane.setVisibility(View.VISIBLE);
if (bindClick) {
if (isGpsDisabled) {
// Give a warning about this state.
Toast.makeText(MapActivity.this,
R.string.error_no_gps_location_provider,
Toast.LENGTH_LONG).show();
// Make clicking take the user to the location settings.
messagePane.setOnClickListener(MapActivity.this);
} else {
messagePane.setOnClickListener(null);
@@ -654,9 +654,6 @@ public class TrackDataHub {
final TrackDataListener.ProviderState state;
if (!hasProviderEnabled) {
state = ProviderState.DISABLED;
// Give a global warning about this state.
Toast.makeText(context, R.string.error_no_gps_location_provider, Toast.LENGTH_LONG).show();
} else if (!hasFix) {
state = ProviderState.NO_FIX;
} else if (!hasGoodFix) {