Skip to content

Instantly share code, notes, and snippets.

@tistaharahap
Created October 20, 2011 18:10
Show Gist options
  • Save tistaharahap/1301843 to your computer and use it in GitHub Desktop.
Save tistaharahap/1301843 to your computer and use it in GitHub Desktop.
An abstract of running a Startup in plain Android AsyncTask subclass.
private class RunStartupTask extends AsyncTask<Problem, Idea, Execution> {
public static final List<Founder> founders = new ArrayList<Founder>();
private ProgressDialog dialog;
@Override
protected void onPreExecute() {
founders.add("Clark");
founders.add("Kent");
new GetFunding().execute(founders);
dialog = new ProgressDialog(getActivity());
dialog.setIcon(R.drawable.logo);
dialog.setIndeterminate(Startup.WAKU);
dialog.setTitle(Startup.NAME);
dialog.setMessage("Cooking..");
dialog.show();
}
@Override
protected Execution doInBackground(Problem... problems) {
Execution exec = new Execution();
for(int i=0, max=problems.length(); i<max; i++) {
try {
// 2 Founders are enough!
Founder.get( i % 2 == 0 ? 0 : 1 ).delegate();
StoryBoard story = new StoryBoard(problems[i]);
Wireframe wireframe = story.getWireframe();
UIX uix = wireframe.generateUix();
Development dev = new Development(uix,
Development.BACKEND | Development.WEB | Development.MWEB |
Development.ANDROID | Development.IOS | Development.BB);
publishProgress(new Idea((int) ((i / (float) max) * 100)));
exec.add(dev);
} catch(Exception e) {
Log.e(Startup.NAME, "Nice Try!");
e.printStackTrace();
}
}
return exec;
}
@Override
protected void onProgressUpdate(Idea... idea) {
setProgressPercent(idea[0].getProgress());
}
@Override
protected void onPostExecute(Execution exec) {
dialog.dismiss();
new RunStartupTask().execute(new Problem(exec.getAnalytics(), exec.getNextVersionImprovements()));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment