Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Implement a dialog that informs the user that we are synchronizing

  • Loading branch information...
commit 153cd2da9b8dfa462d3408b8b4f46a311ba89f79 1 parent 28b2e11
@matburt authored
Showing with 35 additions and 5 deletions.
  1. +35 −5 src/com/matburt/mobileorg/MobileOrgActivity.java
View
40 src/com/matburt/mobileorg/MobileOrgActivity.java
@@ -2,7 +2,9 @@
import android.app.ListActivity;
import android.app.Application;
+import android.app.ProgressDialog;
import android.os.Bundle;
+import android.os.Handler;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
@@ -16,6 +18,7 @@
import android.content.Context;
import android.util.Log;
import java.util.ArrayList;
+import java.lang.Runnable;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
@@ -83,7 +86,14 @@ public View getView(int position, View convertView, ViewGroup parent) {
private static final int OP_MENU_OUTLINE = 3;
private static final int OP_MENU_CAPTURE = 4;
private static final String LT = "MobileOrg";
- private Synchronizer appSync;
+ private ProgressDialog syncDialog;
+ final Handler syncHandler = new Handler();
+ final Runnable syncUpdateResults = new Runnable() {
+ public void run() {
+ postSynchronize();
+ }
+ };
+ public boolean syncResults;
/** Called when the activity is first created. */
@Override
@@ -178,14 +188,34 @@ public boolean onShowSettings() {
return true;
}
+ public void runSynchronizer() {
+ final Synchronizer appSync = new Synchronizer(this);
+ Thread syncThread = new Thread() {
+ public void run() {
+ syncResults = appSync.pull();
+ syncHandler.post(syncUpdateResults);
+ }
+ };
+ syncThread.start();
+ syncDialog = ProgressDialog.show(this, "",
+ "Synchronizing. Please wait...", true);
+ }
+
+ public void postSynchronize() {
+ syncDialog.dismiss();
+ if (!this.syncResults) {
+ Log.d(LT, "Sync Failed");
+ }
+
+ this.runParser();
+ this.onResume();
+ }
+
/* Handles item selections */
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case MobileOrgActivity.OP_MENU_SYNC:
- appSync = new Synchronizer(this);
- appSync.pull();
- this.runParser();
- this.onResume();
+ this.runSynchronizer();
return true;
case MobileOrgActivity.OP_MENU_SETTINGS:
return this.onShowSettings();
Please sign in to comment.
Something went wrong with that request. Please try again.