-
Notifications
You must be signed in to change notification settings - Fork 12
Examples: Notification
In this page, we will introduce com.kkbox.toolkit.example.notification, including:
- KKDialog
- KKDialogFactory
- KKDialogPostExecutionListener
- KKServiceActivity
KKDialog is extended from DialogFragment which provides dialog/notification. The different part is that KKDialog binds with KKService, so a notification can be received by all Activities, Fragments, or others; that is, different objects can listen to the same notification.
There are different types of dialogs, defined in KKDialog.Type as follows:
public abstract class Type {
public static final int ALERT_DIALOG = 0;
public static final int YES_OR_NO_DIALOG = 1;
public static final int THREE_CHOICE_DIALOG = 2;
public static final int PROGRESSING_DIALOG = 3;
}
It is recommended that you use KKDialogFactory to create dialogs. There is a getDialogType() function for you to know the dialog type.
In order to use KKDialog, KKService must be present. You may refer to KKService for information about KKService.
See example code for fundamental usage.
KKDialogFactory is derived from KKDialog for you to easily create dialog.
You can create
- one-button dialog by
KKDialogFactory.createAlertDialog() - two-button dialog by
KKDialogFactory.createYesOrNoDialog() - three-button dialog by
KKDialogFactory.createThreeChoiceDialog() - progress dialog by
KKDialogFactory.createProgressingDialog()
The wording of the buttons is customized, either.
Note that according to Android design guildlines:
Action buttons are typically Cancel and/or OK, with OK indicating the preferred or most likely action. However, if the options consist of specific actions such as Close or Wait rather than a confirmation or cancellation of the action described in the content, then all the buttons should be active verbs. Order actions following these rules:
- The dismissive action of a dialog is always on the left. Dismissive actions return to the user to the previous state.
- The affirmative actions are on the right. Affirmative actions continue progress toward the user goal that triggered the dialog.
KKDialogPostExecutionListener is a listener to the dialogs created by KKDialog or its derived class KKDialogFactory. It has the following callback functions for you to implement:
public abstract class KKDialogPostExecutionListener {
public void onPositive() {};
public void onNeutral() {};
public void onNegative() {};
public void onCancel() {};
}
- For all kind of dialog, implement
onCancel()to handle dialog cancelation. - For one-button dialog, implement
onPositive(). - For two-button dialog, implement
onPositive()andonNegative(). - For three-button dialog, implement
onPositive(),onNeutral(), andonNegative().
Since KKService is required for dialog/notification to work, you should use KKServiceActivity whenever you need to use dialog/notification service.
KKServiceActivity is extended from KKActivity, and is for use only with KKService. KKServiceActivity will ensure the presence of KKService; if KKService is not yet fully started, it will show a "Loading..." dialog and block the UI. If your application does not have any running service, you should not use KKServiceActivity.