Android Open Source - CloudyPhone Commands Async Task






From Project

Back to project page CloudyPhone.

License

The source code is released under:

MIT License

If you think the Android project CloudyPhone listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.cloudyphone.android.controller.commands;
/*  w ww .j a  v a 2s  .c o m*/
import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;
import android.text.TextUtils;

/**
 * An async task that will run commands
 * 
 * @author nguyenthanhhuy
 * 
 */
public class CommandsAsyncTask extends AsyncTask<Command, Void, Void> {
  private Command preExecuteCommand, callbackCommand;
  private Context context;
  private boolean showDialog;
  private String dialogMessage;
  private ProgressDialog dialog;

  /**
   * 
   * @param preExecuteComand
   * @param executeCommand
   * @param callbackCommand
   * @param showDialog
   *            true if you want to show a dialog onPreExecute
   * @param context
   *            must be provided if showDialog is true
   * @param dialogMessage
   *            must be provided if showDialog is true
   */
  public CommandsAsyncTask(Command preExecuteComand, Command callbackCommand,
      boolean showDialog, Context context, String dialogMessage) {
    this.preExecuteCommand = preExecuteComand;
    this.callbackCommand = callbackCommand;
    this.showDialog = showDialog;
    this.dialogMessage = dialogMessage;
    this.context = context;
  }

  @Override
  protected void onPreExecute() {
    super.onPreExecute();

    if (showDialog && context != null && !TextUtils.isEmpty(dialogMessage)) {
      // Show a progress dialog
      dialog = ProgressDialog.show(context, "", dialogMessage);
    }

    if (preExecuteCommand != null) {
      preExecuteCommand.execute();
    }
  }

  @Override
  protected Void doInBackground(Command... commands) {
    if (commands == null) {
      return null;
    }

    for (Command c : commands) {
      c.execute();
    }

    return null;
  }

  @Override
  protected void onPostExecute(Void result) {
    super.onPostExecute(result);

    if (callbackCommand != null) {
      callbackCommand.execute();
    }

    if (showDialog && dialog != null) {
      dialog.dismiss();
    }
  }
}




Java Source Code List

com.cloudyphone.android.Constants.java
com.cloudyphone.android.controller.activities.CloudyPhoneActivity.java
com.cloudyphone.android.controller.activities.LoginActivity.java
com.cloudyphone.android.controller.activities.ResetPasswordActivity.java
com.cloudyphone.android.controller.activities.SignupActivity.java
com.cloudyphone.android.controller.activities.WelcomeActivity.java
com.cloudyphone.android.controller.callbacks.MyLoginCallback.java
com.cloudyphone.android.controller.callbacks.MyResetPasswordCallback.java
com.cloudyphone.android.controller.callbacks.MySignUpCallback.java
com.cloudyphone.android.controller.commands.Command.java
com.cloudyphone.android.controller.commands.CommandsAsyncTask.java
com.cloudyphone.android.controller.commands.SyncContactsCommand.java
com.cloudyphone.android.controller.commands.SyncContactsImagesCommand.java
com.cloudyphone.android.controller.commands.SyncPhoneInforCommand.java
com.cloudyphone.android.controller.commands.SyncSmsThreadsCommand.java
com.cloudyphone.android.controller.listeners.LoginClickListener.java
com.cloudyphone.android.controller.listeners.ResetPasswordClickListener.java
com.cloudyphone.android.controller.listeners.SignupClickListener.java
com.cloudyphone.android.controller.network.ServerConnector.java
com.cloudyphone.android.controller.push.PushManager.java
com.cloudyphone.android.controller.receivers.CopyClipboardReceiver.java
com.cloudyphone.android.controller.receivers.DenyCallReceiver.java
com.cloudyphone.android.controller.receivers.MakeCallReceiver.java
com.cloudyphone.android.controller.receivers.OpenWebReceiver.java
com.cloudyphone.android.controller.receivers.PushReceiver.java
com.cloudyphone.android.controller.receivers.SendSmsReceiver.java
com.cloudyphone.android.controller.receivers.SyncReceiver.java
com.cloudyphone.android.controller.sync.SyncThread.java
com.cloudyphone.android.controller.sync.UpdateThread.java
com.cloudyphone.android.model.InputValidator.java
com.cloudyphone.android.model.MyParseObject.java
com.cloudyphone.android.model.contact.ContactsManager.java
com.cloudyphone.android.model.contact.JSONContact.java
com.cloudyphone.android.model.contact.ParseContactImg.java
com.cloudyphone.android.model.contact.ParseContacts.java
com.cloudyphone.android.model.infor.ParsePhoneInfor.java
com.cloudyphone.android.model.sms.JSONSmsMessage.java
com.cloudyphone.android.model.sms.JSONSmsThread.java
com.cloudyphone.android.model.sms.ParseSmsThreads.java
com.cloudyphone.android.model.sms.SmsManager.java
com.cloudyphone.android.utils.Logger.java