android-ActionQueueAndroid 開(kāi)發(fā)包
ActionQueue 允許你一個(gè)一個(gè)的執(zhí)行任務(wù)。
導(dǎo)入:
allprojects {
repositories {
mavenCentral()
maven {
url "https://oss.sonatype.org/content/repositories/snapshots"
}
jcenter()
}
}
加依賴:
compile 'in.srain.cube:action-queue:1.0.1'
使用
創(chuàng)建 action:
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);
}
處理 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);
}
}
action 執(zhí)行完之后通知提醒:
DialogInterface.OnDismissListener mOnDismissListener = new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
mActionQueue.notifyActionDoneThenTryToPopNext();
}
};評(píng)論
圖片
表情
