← 所有扩展

原生扩展

KlugDialog

com.klug.dialog.Dialog

无需 APM。下载即用,再简单不过。

适用于 Android、iOS 和 macOS 上 AIR 应用的原生对话框:提示框、文本框始终位于键盘上方的对话框,以及可由您的代码更新和关闭的进度对话框。

AndroidiOSmacOS 已投入生产 €19 / 年起 · 购买

概览

AIR 内置的 Mac 提示框看起来像是上个年代的产物。KlugDialog 展示的是真正的原生效果:附着在应用窗口上的原生 macOS 提示面板,带有应用图标、系统字体和熟悉的按钮样式。

除了简单的提示框,它还涵盖桌面应用每天所需的功能:带文本框的对话框(例如用户名和密码,也可作为安全输入框)、带各自样式的多个按钮,以及进度面板(“正在连接…”),由您的代码更新,并在工作完成后关闭。

一切都是异步的:show() 立即返回,您的回调会收到所选的按钮。KlugDialog 运行在我们的应用的 Mac 版本中,这就是我们的概念验证。

Android 新增:同样的对话框以原生 Android 对话框呈现。文本框在每种屏幕上都始终位于键盘上方,包括平板上的横屏,此前按钮会在那里消失在键盘后面;密码、用户名和电子邮件地址绝不会被自动大写,电子邮件输入框会使用电子邮件键盘。Android 版本还可堆叠较长的按钮列表,并提供简单的旋转指示器,已在我们应用的 Android 版本中运行。

iOS 同样适用:自 1.2 版起,同一套 API 可显示原生 iOS 提示框、带文本框的对话框和进度对话框,因此一条代码路径即可同时覆盖 Android、iOS 和 macOS。

特性

  • 自成一体:一个 ANE,无需添加核心库或依赖 ANE
  • 原生 macOS 提示面板,最多三个按钮
  • 信息、警告和严重三种样式
  • 可包含任意数量按钮和文本框的对话框,包括安全输入框
  • 可通过代码更新和关闭的进度面板
  • 对话框可通过代码关闭
  • 回调携带所选按钮和输入的值
  • Android:输入框位于键盘上方,密码不自动大写,电子邮件 / 数字键盘,浅色和深色主题

支持的平台

Android 提示框 · 文本框 · 进度 · 长按钮列表
iOS arm64 · 提示框 · 文本框 · 进度
macOS arm64 · x86_64

在其他平台上,isSupported 返回 false,因此您的应用可在那里回退到常规对话框。

入门

将扩展添加到您的应用描述文件中:

app.xml
<extensions>
    <extensionID>com.klug.dialog.Dialog</extensionID>
</extensions>

代码示例

五个完整流程。每次调用都会立即返回;结果稍后在您的回调中到达,因此对话框打开期间应用绝不会被阻塞。完整文档 →

1 · 检查支持情况并显示简单提示框
Setup.as
import com.klug.dialog.Dialog;

var dialog:Dialog = Dialog.getInstance();

if ( dialog.isSupported )
{
    dialog.show( "Saved", "The recording is in your library." );   // one "OK" button
}
else
{
    showAppAlert( "Saved" );   // your app's own fallback dialog, e.g. on Windows
}
2 · 用最多三个按钮提出问题
Confirm.as
dialog.show( "Delete recording?", "This cannot be undone.",
    [ "Delete", "Keep" ],
    function( index:int ):void
    {
        // index = position in the buttons array;
        // -1 = closed without a button, e.g. the Android back key
        if ( index == 0 ) deleteRecording();   // your app
    },
    Dialog.STYLE_WARNING );   // alert style of the macOS sheet
3 · 带文本框的登录对话框
SignIn.as
var buttons:Array = [
    { label:"Cancel",  style:4, tag:0 },   // style 4 = cancel, 3 = destructive
    { label:"Sign in", style:0, tag:1 }
];
var fields:Array = [
    { placeholder:"E-mail", text:lastEmail, keyboardType:7 },   // 7 = e-mail keyboard
    { placeholder:"Password", secure:true }                 // never auto-capitalised
];

dialog.present( "Sign in", "Please enter your account.", true, buttons, fields,
    function( tag:int, values:Array, cancelled:Boolean = false ):void
    {
        if ( cancelled ) return;   // closed without a button (tag -1)
        if ( tag == 1 ) signIn( values[0], values[1] );   // values in field order
    },
    null, "dark" );   // theme on Android and iOS; macOS follows the system
4 · 代码工作期间显示进度对话框
Connect.as
// your own id: the same dialog is updated and closed with it
dialog.progressShow( "connect", "Connecting", "Contacting the server…", false,
    function():void { trace( "progress dialog closed" ); } );   // fires once

dialog.progressUpdate( "connect", "Signing in…" );

// when the work is done, or has failed
dialog.progressDismiss( "connect" );
5 · 通过代码关闭对话框
Waiting.as
// pass your own id as the 7th parameter to close the dialog later
dialog.present( "Waiting for the camera", "Tap Cancel to stop waiting.", false,
    [ { label:"Cancel", style:4, tag:0 } ], null,
    function( tag:int, values:Array ):void { stopWaiting(); },   // your app
    "waitCamera" );

// the camera has answered: close the dialog, no callback fires
dialog.presentDismiss( "waitCamera" );

API 概览

Dialog.getInstance()返回唯一实例。
isSupported在 Android、iOS 和 macOS 上为 True;其他平台(例如 Windows)为 false。
show(title, message, buttons, callback, style)最多三个按钮的提示框(默认为“OK”);callback(index),若未点击按钮而关闭则为 -1。若不受支持则返回 false。
present(title, message, cancelable, buttons, fields, callback, id, theme)可包含任意数量按钮和文本框的对话框;callback(tag, values, cancelled)。传入您自己的 id 以便稍后关闭它;在 Android 和 iOS 上,theme 可为 "light" 或 "dark"。
presentDismiss(id)通过代码关闭 present() 对话框;不会触发回调。
progressShow(id, title, message, cancelable, closeCallback, theme)带旋转指示器的进度对话框;对话框消失后 closeCallback 触发一次。
progressUpdate(id, message) / progressDismiss(id)更改进度对话框的文字 / 关闭它。
STYLE_INFO, STYLE_WARNING, STYLE_CRITICALshow() 的提示框样式,供 macOS 提示面板使用。
Button {label, style, tag}style:0 默认,1 肯定,2 否定,3 破坏性,4 取消,5 中性。Android 使用全部样式,iOS 使用 3 和 4,macOS 对所有按钮一视同仁。
Field {placeholder, secure, text, keyboardType, autocorrect, autocap}keyboardType:0 默认,3 URL,4 数字,5 电话,7 电子邮件,8 小数。autocap:0 无(默认),1 句子,2 单词,3 全部。后三项适用于 Android 和 iOS。

购买 KlugDialog

一个 AIR 应用的年度许可,含 12 个月内的所有更新。付款后,您将通过电子邮件收到扩展、ActionScript 库和文档,通常在一个工作日内。许可与条款

基础版
€19 / 年
  • 一个 AIR 应用的许可
  • 12 个月内的所有更新
  • 不含支持
购买基础版
标准版
€149 / 年
  • 一个 AIR 应用的许可
  • 12 个月内的所有更新
  • 7 天内通过电子邮件答复
购买标准版
优先版
€299 / 年
  • 一个 AIR 应用的许可
  • 12 个月内的所有更新
  • 48 小时内通过电子邮件答复
购买优先版
税费在结账时由 Link (Stripe) 计算。您需要在结账时输入 AIR 应用的应用 ID。

要求

AIR SDK51.x (HARMAN)
AndroidAndroid 6 或更高版本
iOSiOS 13 或更高版本
macOSmacOS 11 或更高版本