1 package com.yuji.ec.utility;
\r
3 import java.lang.ref.WeakReference;
\r
5 import android.app.Activity;
\r
6 import android.app.ProgressDialog;
\r
7 import android.content.DialogInterface;
\r
8 import android.content.DialogInterface.OnKeyListener;
\r
9 import android.os.AsyncTask;
\r
10 import android.view.KeyEvent;
\r
12 public class AsyncTaskCommand extends AsyncTask<String, Integer, String> {
\r
13 private WeakReference<Activity> activityRef;
\r
14 private AsyncTaskIF command;
\r
15 private ProgressDialog dialog;
\r
16 private boolean isCancel = false;
\r
17 private boolean isDialog = true;
\r
18 private int status = -1;
\r
20 private String title = "";
\r
21 private String buttonTitle = "";
\r
22 private boolean cancelable = true;
\r
24 @SuppressWarnings({ "rawtypes", "unchecked" })
\r
25 public AsyncTaskCommand(Activity activity, AsyncTaskIF command) {
\r
26 this.activityRef = new WeakReference(activity);
\r
27 this.command = command;
\r
31 protected void onPreExecute() {
\r
32 Debug.d(this, "onPreExecute start");
\r
34 Activity activity = activityRef.get();
\r
35 if (activity == null) {
\r
39 dialog = new ProgressDialog(activity);
\r
40 dialog.setIndeterminate(true);
\r
41 dialog.setCancelable(cancelable);
\r
42 dialog.setTitle(title);
\r
44 dialog.setButton(buttonTitle, new DialogInterface.OnClickListener() {
\r
45 public void onClick(DialogInterface dialog, int which) {
\r
47 AsyncTaskCommand.this.cancel(true);
\r
50 dialog.setOnKeyListener(new OnKeyListener() {
\r
51 public boolean onKey(DialogInterface dialog, int keyCode,
\r
53 switch (event.getKeyCode()) {
\r
54 case KeyEvent.KEYCODE_SEARCH:
\r
63 Debug.d(this, "onPreExecute end");
\r
67 protected String doInBackground(String... arg0) {
\r
69 Debug.d(this, "doInBackground start");
\r
70 command.doExecute();
\r
71 status = command.getStatus();
\r
72 Debug.d(this, "doInBackground end");
\r
73 } catch (RuntimeException e) {
\r
74 Debug.d(this, null, e);
\r
81 protected void onCancelled() {
\r
82 Debug.d(this, "onCancelled start");
\r
86 if (command != null) {
\r
89 onPostExecute(null);
\r
90 Debug.d(this, "onCancelled end");
\r
94 protected void onPostExecute(String result) {
\r
95 Debug.d(this, "onPostExecute start");
\r
98 if (command != null) {
\r
99 command.done(isCancel);
\r
102 if (dialog != null) {
\r
106 catch (IllegalArgumentException e){
\r
111 activityRef = null;
\r
112 } catch (RuntimeException e) {
\r
113 Debug.d(this, null, e);
\r
116 Debug.d(this, "onPostExecute end");
\r
119 public void stop() {
\r
120 Debug.d(this, "stop start");
\r
122 if (command != null) {
\r
126 // onPostExecute()
\82Ìdialog.dismiss();
\82Å
\83G
\83\89\81[
\82Æ
\82È
\82é
\82½
\82ß
\r
127 //
\96{
\8e¿
\93I
\82È
\89ð
\8c\88\8dô
\82Å
\82Í
\82È
\82¢
\r
129 if (dialog != null) {
\r
134 Debug.d(this, "stop end");
\r
137 public void setDialog(boolean b) {
\r
141 public int getResultStatus(){
\r
145 public void setTitle(String title) {
\r
146 this.title = title;
\r
149 public void setButtonTitle(String buttonTitle) {
\r
150 this.buttonTitle = buttonTitle;
\r
153 public void setCancelable(boolean cancelable){
\r
154 this.cancelable = cancelable;
\r