dialogs


CloudControl Pro 9 Docs / dialogs

dialogs

dialogs module is used to show dialogs, which is usually used to show user key information, input information, and complete simple interaction.

This module provides multiple configuration modes, which can be displayed in the application dialog or floating window, confirm dialog, input box, radio button, and so on.

You can use const dialogs = require('dialogs'); to import dialogs module. Then you can use dialogs.showInputDialog("Title", "Text"); to call the module's method.

You can also directly import the function you want to use, such as const { showInputDialog } = require('dialogs'); showInputDialog("Title", "Text");

Table of contents

Interfaces

Type Aliases

Variables

Functions

Type Aliases

Dialog

Ƭ Dialog: android.app.Dialog & DialogExt

Dialog type, extends from Dialogopen in new window to add some methods and properties. See DialogExt.


DialogType

Ƭ DialogType: "overlay" | "app"

The type of the dialog.

  • overlay: can be shown on other applications, need floating window permission.
  • app: application-level dialog, can only be shown in the current activity, no extra permission required.

Variables

defaultDialogType

defaultDialogType: DialogType = 'app'

Default dialog type, the default value is 'app'. Can be modified by the setDefaultDialogType function.

See

Functions

buildDialog

buildDialog(properties): Promise<Dialog>

Create a dialog. You can customize dialog's title, content, progress, input, button, etc.

Parameters

NameTypeDescription
propertiesDialogPropertiesDialog's configuration properties. See DialogProperties

Returns

Promise<Dialog>

Dialog object's Promise

"nodejs";
const { buildDialog} = require("dialogs");
async function main() {
  const dialog = await buildDialog({
     title: "",
     content: "",
  }).on("positive", () => {
      console.log("positive");
  });
  dialog.show();
}
main();

setDefaultDialogType

setDefaultDialogType(type): void

See

defaultDialogType

Parameters

NameType
typeDialogType

Returns

void


showAlertDialog

showAlertDialog(title, properties?): Promise<void>

Show a alert dialog. Alert dialog includes title, content and a confirm button.

Example

"nodejs";
const { showAlertDialog } = require('dialogs');
async function alert() {
  await showAlertDialog("This is an alert dialog.");
  await showAlertDialog("Summary", { content: "Some description" });
}
alert();

Parameters

NameTypeDescription
titlestringThe title of the dialog.
properties?DialogPropertiesThe configuration properties of the dialog. See DialogProperties

Returns

Promise<void>

The result of the dialog. You can use await to wait for the dialog to dismiss.


showConfirmDialog

showConfirmDialog(title, properties?): Promise<boolean>

Show a confirm dialog, including a confirm button and a cancel button.

Example

"nodejs";
const dialogs = require('dialogs');
async function confirm() {
  const sure = await dialogs.showConfirmDialog("Are you sure?");
  console.log(sure); // true or false
  console.log(await dialogs.showConfirmDialog("Are you sure?", { positive: "Yes", negative: "No" }));
}
confirm();

Parameters

NameTypeDescription
titlestringThe title of the confirm dialog.
properties?DialogPropertiesThe extra configuration properties of the dialog. See DialogProperties

Returns

Promise<boolean>

The result of the dialog. You can use await to get the result.


showDialog

showDialog(properties): Promise<Dialog>

Create and show a dialog. Similar to buildDialog, but show directly without calling show.

Parameters

NameTypeDescription
propertiesDialogPropertiesDialog's configuration properties. See DialogProperties

Returns

Promise<Dialog>

Dialog object's Promise


showInputDialog

showInputDialog(title, prefill?, properties?): Promise<string | null>

show a input dialog.

Example

"nodejs";
const dialogs = require('dialogs');
async function inputDialog() {
  const name = await dialogs.showInputDialog("Input your name", "Tony");
  if (name != "") {
      console.log(`hello, ${mName}`);
  }
}
inputDialog();

Parameters

NameTypeDescription
titlestringThe title of the input dialog.
prefill?stringThe default text of the input dialog.
properties?DialogPropertiesThe configuration properties of the dialog. See DialogProperties

Returns

Promise<string | null>

The promise of the input result. If the user cancels the input, the result will be null.


showMultiChoiceDialog

showMultiChoiceDialog(title, items, initialSelectedIndices?, properties?): Promise<number[] | null>

Show a multi-choice dialog. Multi-choice dialog includes a title and a multi-choice list, and the user clicks on the list items to confirm.

Parameters

NameTypeDescription
titlestringThe title of the multi-choice dialog.
itemsstring[]The options of the multi-choice dialog.
initialSelectedIndices?number[]The default selected options. The form is an array of the index of items array.
properties?DialogPropertiesThe configuration properties of the dialog. See DialogProperties

Returns

Promise<number[] | null>

The promise of the selected indices. If the user cancels the multi-choice, the result will be an empty array.

"nodejs";
const { showMultiChoiceDialog } = require('dialogs');
async function multiChoice() {
    const indices = await showMultiChoiceDialog("Choose items", ["item1", "item2", "item3"]);
    console.log(`selected items: ${indices}`);
}

showSelectDialog

showSelectDialog(title, items, properties?): Promise<number>

Show a select dialog.

Example

"nodejs";
const { showSelectDialog } = require('dialogs');
async function select() {
  const i = await showSelectDialog("Select an item", ["item1", "item2", "item3"]);
  console.log(`selected item: ${i}`);
}
select();

Parameters

NameTypeDescription
titlestringThe title of the select dialog.
itemsstring[]The options of the select dialog.
properties?DialogPropertiesThe configuration properties of the dialog. See DialogProperties

Returns

Promise<number>

The promise of the selected index. If the user cancels the select, the result will be -1.


showSingleChoiceDialog

showSingleChoiceDialog(title, items, initialSelectedIndex?, properties?): Promise<number>

Show a radio dialog.

Example

"nodejs";
const { showSingleChoiceDialog } = require('dialogs');
async function singleChoice() {
  const i = await showSingleChoiceDialog("Choose an item", ["item1", "item2", "item3"]);
  console.log(`selected item: ${i}`);
}
singleChoice();

Parameters

NameTypeDescription
titlestringThe title of the radio dialog.
itemsstring[]The options of the radio dialog.
initialSelectedIndex?numberThe default selected index of the items array.
properties?DialogPropertiesThe configuration properties of the dialog. See DialogProperties

Returns

Promise<number>

The promise of the selected index. If the user cancels the radio, the result will be -1.