Skip to content

Commit

Permalink
Implement a dialog that informs the user that we are synchronizing
Browse files Browse the repository at this point in the history
  • Loading branch information
matburt committed Feb 25, 2010
1 parent 28b2e11 commit 153cd2d
Showing 1 changed file with 35 additions and 5 deletions.
40 changes: 35 additions & 5 deletions src/com/matburt/mobileorg/MobileOrgActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 153cd2d

Please sign in to comment.