예제 #1
0
  protected void authenticate() {
    Log.i(TAG, "Inside the authenticate method..");
    mLoginProgressDialog.setMessage("Login in progress..");
    mLoginProgressDialog.show();
    AsyncTask<Void, Void, String> tTask =
        new AsyncTask<Void, Void, String>() {
          @Override
          protected String doInBackground(Void... params) {
            twitter = getTwitterInstance(OAUTH_TOKEN, OAUTH_SECRET);

            try {
              getTwitterProfileInfo(twitter.getOAuthAccessToken());
            } catch (TwitterException e) {
              Toast.makeText(mContext, "Twitter login error", Toast.LENGTH_LONG).show();
            }

            return "";
          }

          @Override
          protected void onPostExecute(String result) {

            super.onPostExecute(result);
          }
        };
    tTask.execute();
  }
예제 #2
0
 private void cleanUp() {
   synchronized (tasks) {
     for (AsyncTask task : tasks) {
       if (task.isReadyToClose()) {
         task.close();
       }
     }
   }
 }
예제 #3
0
  private void setExit() {
    synchronized (tasks) {
      for (AsyncTask task : tasks) {
        task.requestExit();
      }
    }

    this.exit = true;
  }
예제 #4
0
파일: AsyncExecutor.java 프로젝트: QiXi/vtm
  /**
   * Submits a {@link Runnable} to be executed asynchronously. If maxConcurrent runnables are
   * already running, the runnable will be queued.
   *
   * @param task the task to execute asynchronously
   */
  @SuppressWarnings("rawtypes")
  public <T> AsyncResult<T> submit(final AsyncTask<T> task) {

    T result = null;
    boolean error = false;
    try {
      task.run();
      result = task.getResult();
    } catch (Throwable t) {
      error = true;
    }
    return new AsyncResult(result);
  }
예제 #5
0
  public Thread start(AsyncTask asyncTask) {
    asyncTask.setManager(this);

    if (asyncTask.isTrustClose()) {
      addTask(asyncTask);
    }

    Runnable jvmShutdownHook = asyncTask.getJvmShutdownHook();
    if (jvmShutdownHook != null) {
      Runtime.getRuntime().addShutdownHook(Utils.createThread(jvmShutdownHook));
    }

    return Utils.startThread(asyncTask);
  }
예제 #6
0
 @Override
 protected void onCancelled(BitmapDrawable value) {
   super.onCancelled(value);
   synchronized (mPauseWorkLock) {
     mPauseWorkLock.notifyAll();
   }
 }
예제 #7
0
 @Override
 protected void onPostExecute(Void result) {
   super.onPostExecute(result);
   if (pd != null) {
     pd.dismiss();
   }
 }
예제 #8
0
 @Override
 protected void onCancelled() {
   super.onCancelled();
   if (pd != null) {
     pd.dismiss();
   }
 }
예제 #9
0
 public void destroyAlertWaiter() {
   mAlertsActive = false;
   if (mAlertDialog != null) {
     mAlertDialog.cancel();
     mAlertDialog = null;
   }
   if (mAlertTask != null) {
     mAlertTask.cancel(true);
     mAlertTask = null;
   }
 }
예제 #10
0
 @Override
 protected void onPreExecute() {
   super.onPreExecute();
   pd = new ProgressDialog(that);
   pd.setProgressStyle(pd.STYLE_SPINNER);
   pd.setTitle("Getting File...");
   pd.setMessage("Please wait.");
   pd.setCancelable(true);
   pd.setCanceledOnTouchOutside(true);
   pd.setIndeterminate(true);
   pd.show();
 }
예제 #11
0
		@Override
		protected void onPostExecute(Void result) {
			iView.setImageDrawable(draw);
			iTv.setText(name);
			iTv2.setText(size);
			if(date == 0){
				iTv3.setText("No Backup");
				iTv.setTextColor(Color.WHITE);
			}else{
				iTv3.setText("Backup On :" + new Date(date));
				iTv.setTextColor(Color.GREEN);
			}
			super.onPostExecute(result);
		}
예제 #12
0
 public void onDestroy() {
   if (null != mDocView) {
     mDocView.applyToChildren(
         new AKReaderView.ViewMapper() {
           void applyToView(View view) {
             ((MuPDFView) view).releaseBitmaps();
           }
         });
   }
   if (core != null) core.onDestroy();
   if (mAlertTask != null) {
     mAlertTask.cancel(true);
     mAlertTask = null;
   }
   core = null;
   super.onDestroy();
 }
    protected void onProgressUpdate(Integer... progress) {
      super.onProgressUpdate(progress);
      int total_files = progress[1];
      int current_file = progress[0];
      progress_download.incrementProgressBy(1);
      progress_download.setMax(total_files);

      if (current_file < total_files) {
        progress_text.setText(
            "Downloading "
                + Integer.toString(current_file)
                + " of "
                + Integer.toString(total_files)
                + ".");
      } else {
        progress_text.setText("Completed.");
        resume_pause.setVisibility(View.GONE);
        // writeProgress(
        // viewimages.setEnabled(true);
      }
      //	mProgressDialog.setProgress(progress[0]);
      progress_download.setProgress(current_file);
    }
    protected void onPreExecute() {
      super.onPreExecute();
      //	mProgressDialog.show();

    }
예제 #15
0
		@Override
		protected void onPreExecute() {
			super.onPreExecute();
		}
예제 #16
0
  public void go(final String text, int direction, int displayPage, int searchPage) {
    if (mCore == null) return;
    stop();

    final int increment = direction;
    final int startIndex = searchPage == -1 ? displayPage : searchPage + increment;

    final ProgressDialogX progressDialog = new ProgressDialogX(mContext);
    progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    progressDialog.setTitle(mContext.getString(R.string.searching_));
    progressDialog.setOnCancelListener(
        new DialogInterface.OnCancelListener() {
          public void onCancel(DialogInterface dialog) {
            stop();
          }
        });
    progressDialog.setMax(mCore.countPages());

    mSearchTask =
        new AsyncTask<Void, Integer, SearchTaskResult>() {
          @Override
          protected SearchTaskResult doInBackground(Void... params) {
            int index = startIndex;

            while (0 <= index && index < mCore.countPages() && !isCancelled()) {
              publishProgress(index);
              RectF searchHits[] = mCore.searchPage(index, text);

              if (searchHits != null && searchHits.length > 0)
                return new SearchTaskResult(text, index, searchHits);

              index += increment;
            }
            return null;
          }

          @Override
          protected void onPostExecute(SearchTaskResult result) {
            progressDialog.cancel();
            if (result != null) {
              onTextFound(result);
            } else {
              mAlertBuilder.setTitle(
                  SearchTaskResult.get() == null
                      ? R.string.text_not_found
                      : R.string.no_further_occurrences_found);
              AlertDialog alert = mAlertBuilder.create();
              alert.setButton(
                  AlertDialog.BUTTON_POSITIVE,
                  mContext.getString(R.string.dismiss),
                  (DialogInterface.OnClickListener) null);
              alert.show();
            }
          }

          @Override
          protected void onCancelled() {
            progressDialog.cancel();
          }

          @Override
          protected void onProgressUpdate(Integer... values) {
            progressDialog.setProgress(values[0].intValue());
          }

          @Override
          protected void onPreExecute() {
            super.onPreExecute();
            mHandler.postDelayed(
                new Runnable() {
                  public void run() {
                    if (!progressDialog.isCancelled()) {
                      progressDialog.show();
                      progressDialog.setProgress(startIndex);
                    }
                  }
                },
                SEARCH_PROGRESS_DELAY);
          }
        };

    mSearchTask.execute();
  }
예제 #17
0
 public void stop() {
   if (mSearchTask != null) {
     mSearchTask.cancel(true);
     mSearchTask = null;
   }
 }
예제 #18
0
 @Override
 protected void onProgressUpdate(Integer... progress) {
   super.onProgressUpdate(progress);
 }
예제 #19
0
  public void createAlertWaiter() {
    mAlertsActive = true;
    // All mupdf library calls are performed on asynchronous tasks to avoid stalling
    // the UI. Some calls can lead to javascript-invoked requests to display an
    // alert dialog and collect a reply from the user. The task has to be blocked
    // until the user's reply is received. This method creates an asynchronous task,
    // the purpose of which is to wait of these requests and produce the dialog
    // in response, while leaving the core blocked. When the dialog receives the
    // user's response, it is sent to the core via replyToAlert, unblocking it.
    // Another alert-waiting task is then created to pick up the next alert.
    if (mAlertTask != null) {
      mAlertTask.cancel(true);
      mAlertTask = null;
    }
    if (mAlertDialog != null) {
      mAlertDialog.cancel();
      mAlertDialog = null;
    }
    mAlertTask =
        new AsyncTask<Void, Void, MuPDFAlert>() {

          @Override
          protected MuPDFAlert doInBackground(Void... arg0) {
            if (!mAlertsActive) return null;

            return core.waitForAlert();
          }

          @Override
          protected void onPostExecute(final MuPDFAlert result) {
            // core.waitForAlert may return null when shutting down
            if (result == null) return;
            final MuPDFAlert.ButtonPressed pressed[] = new MuPDFAlert.ButtonPressed[3];
            for (int i = 0; i < 3; i++) pressed[i] = MuPDFAlert.ButtonPressed.None;
            DialogInterface.OnClickListener listener =
                new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int which) {
                    mAlertDialog = null;
                    if (mAlertsActive) {
                      int index = 0;
                      switch (which) {
                        case AlertDialog.BUTTON1:
                          index = 0;
                          break;
                        case AlertDialog.BUTTON2:
                          index = 1;
                          break;
                        case AlertDialog.BUTTON3:
                          index = 2;
                          break;
                      }
                      result.buttonPressed = pressed[index];
                      // Send the user's response to the core, so that it can
                      // continue processing.
                      core.replyToAlert(result);
                      // Create another alert-waiter to pick up the next alert.
                      createAlertWaiter();
                    }
                  }
                };
            mAlertDialog = mAlertBuilder.create();
            mAlertDialog.setTitle(result.title);
            mAlertDialog.setMessage(result.message);
            switch (result.iconType) {
              case Error:
                break;
              case Warning:
                break;
              case Question:
                break;
              case Status:
                break;
            }
            switch (result.buttonGroupType) {
              case OkCancel:
                mAlertDialog.setButton(AlertDialog.BUTTON2, getString(R.string.cancel), listener);
                pressed[1] = MuPDFAlert.ButtonPressed.Cancel;
              case Ok:
                mAlertDialog.setButton(AlertDialog.BUTTON1, getString(R.string.okay), listener);
                pressed[0] = MuPDFAlert.ButtonPressed.Ok;
                break;
              case YesNoCancel:
                mAlertDialog.setButton(AlertDialog.BUTTON3, getString(R.string.cancel), listener);
                pressed[2] = MuPDFAlert.ButtonPressed.Cancel;
              case YesNo:
                mAlertDialog.setButton(AlertDialog.BUTTON1, getString(R.string.yes), listener);
                pressed[0] = MuPDFAlert.ButtonPressed.Yes;
                mAlertDialog.setButton(AlertDialog.BUTTON2, getString(R.string.no), listener);
                pressed[1] = MuPDFAlert.ButtonPressed.No;
                break;
            }
            mAlertDialog.setOnCancelListener(
                new DialogInterface.OnCancelListener() {
                  public void onCancel(DialogInterface dialog) {
                    mAlertDialog = null;
                    if (mAlertsActive) {
                      result.buttonPressed = MuPDFAlert.ButtonPressed.None;
                      core.replyToAlert(result);
                      createAlertWaiter();
                    }
                  }
                });

            mAlertDialog.show();
          }
        };

    mAlertTask.executeOnExecutor(new ThreadPerTaskExecutor());
  }
예제 #20
0
 public static boolean stop(AsyncTask task) {
   if (task == null) return false;
   task.stop();
   return true;
 }
예제 #21
0
 @Override
 protected void onProgressUpdate(Void... values) {
   super.onProgressUpdate(values);
 }
예제 #22
0
 public void execute(Params... params) {
   asyncTask.execute(params);
 }