ActionQueue

Additional

Language
Java
Version
N/A
Created
Aug 20, 2015
Updated
Aug 22, 2015 (Retired)
Owner
Huqiu Liao (liaohuqiu)
Contributor
Huqiu Liao (liaohuqiu)
1
Activity
Badge
Generate
Download
Source code

Advertising

ActionQueue allows you run action one by one.

Import

Repositories:

allprojects {
    repositories {
        mavenCentral()
        maven {
            url "https://oss.sonatype.org/content/repositories/snapshots"
        }
        jcenter()
    }
}

Add to dependencies:

compile 'in.srain.cube:action-queue:1.0.1'

Usage

  • create actions

    String[] messageList = new String[]{
            "message 1",
            "message 2",
            "message 3",
    };
    for (int i = 0; i < messageList.length; i++) {
        String message = messageList[i];
        PopDialogAction action = new PopDialogAction(message);
        mActionQueue.add(action);
    }
  • process action

    class PopDialogAction extends ActionQueue.Action<String> {
    
        public PopDialogAction(String badge) {
            super(badge);
        }
    
        @Override
        public void onAction() {
            AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
            Dialog dialog = builder.setMessage(getBadge()).show();
            // notify action is done, and next aciton will be executed
            dialog.setOnDismissListener(mOnDismissListener);
        }
    }
  • notify when action is done

    DialogInterface.OnDismissListener mOnDismissListener = new DialogInterface.OnDismissListener() {
        @Override
        public void onDismiss(DialogInterface dialog) {
            mActionQueue.notifyActionDoneThenTryToPopNext();
        }
    };
  • LICENSE: MIT