The more I work on extensions the more I see how chaotic they are.
But never mind..
New classes in my as3NativeAlert.
Now a class NativeMultiChoiceDialog has the ability to show a native android popup multi-choice(or single) dialog inside Adobe Air project.
Usage:
private var NativeListDialog;
private var choces:Vector.<String>;
private var buttons:Vector.<String>;
private var checkedItems:Vector.<Boolean>;
private var selectedIndex:int = -1;
protected function view1_viewActivateHandler(event:ViewNavigatorEvent):void
{
choces = new Vector.<String>();
//the text of the items to be displayed in the list.
choces.push("one",'two","three","four");
checkedItems = new Vector.<Boolean>();
// specifies which items are checked. It should be null in which case no items are checked. If non null it must be exactly the same length as the array of items.
checkedItems.push(true,false,false,true);
buttons = new Vector.<String>();
//the labels for the buttons. It should be null in which case there will be only one button "OK". If non null max length 3 buttons
buttons.push("OK","Settings","Cancle");
}
protected function openMultiChoiceDialog(event:MouseEvent):void
{
multChDialog = new NativeListDialog();
multChDialog.theme = NativeListDialog.THEME_HOLO_DARK;
multChDialog.addEventListener(NativeDialogEvent.CANCLED,closeNativeDialogHandler);
multChDialog.addEventListener(NativeDialogEvent.OPENED,traceEvent);
multChDialog.addEventListener(NativeDialogEvent.CLOSED,closeNativeDialogHandler);
multChDialog.addEventListener(NativeExtensionErrorEvent.ERROR,onError);
multChDialog.addEventListener(NativeDialogListEvent.LIST_CHANGE,onListChange);
multChDialog.title ="Some Title";
multChDialog.cancleble = true;
multChDialog.showMultiChoice(choces,checkedItems,buttons);
}
public function openSingleChoiceDialog(event:MouseEvent):void
{
singleChDialog = new NativeListDialog();
singleChDialog.theme = ThemeSelector.selectedItem.data;
singleChDialog.addEventListener(NativeDialogEvent.CANCLED,closeNativeDialogHandler);
singleChDialog.addEventListener(NativeDialogEvent.OPENED,traceEvent);
singleChDialog.addEventListener(NativeDialogEvent.CLOSED,closeNativeDialogHandler);
singleChDialog.addEventListener(LogEvent.LOG_EVENT,traceEvent);
singleChDialog.addEventListener(NativeExtensionErrorEvent.ERROR,onError);
singleChDialog.addEventListener(NativeDialogListEvent.LIST_CHANGE,onListChange);
singleChDialog.cancleble = true;
singleChDialog.showSingleChoice(choces,selectedIndex,buttons,titleInput.text);
}
public function closeNativeDialogHandler(event:NativeDialogEvent):void
{
var dialog:NativeListDialog = (event.target as NativeListDialog);
dialog.removeEventListener(NativeDialogEvent.CANCLED,closeNativeDialogHandler);
dialog.removeEventListener(NativeDialogEvent.CLOSED,closeNativeDialogHandler);
dialog.removeEventListener(NativeDialogEvent.OPENED,traceEvent);
dialog.removeEventListener(NativeExtensionErrorEvent.ERROR,onError);
dialog.kill();
}
private function onListChange(event:NativeDialogListEvent):void
{
var dialog:NativeListDialog = (event.target as NativeListDialog)
if(dialog.selectedIndex>-1){
selectedIndex = dialog.selectedIndex;
}else{
const a:Vector.<String> = dialog.selectedLabels;
if(a.length>0){
for (var i:int = 0; i < a.length; i++)
{
trace(a[i]);
}
}
}
}
like always available themes for android :
THEME_DEVICE_DEFAULT_DARK
THEME_DEVICE_DEFAULT_LIGHT
THEME_HOLO_DARK
THEME_HOLO_LIGHT
THEME_TRADITIONAL
All my extensions are compiled by Android SDK revision 12 (Android 3.1).