- Flash Development for Android Cookbook
- Joseph Labrecque
- 526字
- 2021-04-02 19:15:19
Detecting supported device input types
A variety of input types are available across Android devices and depending upon the project we are working on, we may need to verify that any particular device supports the intended modes of user interaction. Fortunately, there are a number of ActionScript classes to assist us in discovering device capabilities in regard to user input.
How to do it...
We will need to use internal classes to detect whether or not multitouch is supported:
- First, import the following classes into your project in order to check various input types across devices:
import flash.display.Sprite; import flash.display.Stage; import flash.display.StageAlign; import flash.display.StageScaleMode; import flash.system.Capabilities; import flash.system.TouchscreenType; import flash.text.TextField; import flash.text.TextFormat; import flash.ui.Keyboard; import flash.ui.KeyboardType; import flash.ui.Mouse;
- Declare a
TextField
andTextFormat
object to allow visible output upon the device:private var traceField:TextField; private var traceFormat:TextFormat;
- We will now set up our
TextField
, apply aTextFormat
, and add it to theDisplayList
. Here, we create a method to perform all of these actions for us:protected function setupTextField():void { traceFormat = new TextFormat(); traceFormat.bold = true; traceFormat.font = "_sans"; traceFormat.size = 32; traceFormat.align = "center"; traceFormat.color = 0x333333; traceField = new TextField(); traceField.defaultTextFormat = traceFormat; traceField.selectable = false; traceField.mouseEnabled = false; traceField.width = stage.stageWidth; traceField.height = stage.stageHeight; addChild(traceField); }
- Now, we will simply go through and check the data returned from invoking a number of properties off of these classes. In the case of the following example, we are performing this within the following method:
protected function checkInputTypes():void { traceField.appendText("Touch Screen Type: " + flash.system.Capabilities.touchscreenType + "\n"); traceField.appendText("Mouse Cursor: " + flash.ui.Mouse. supportsCursor + "\n"); traceField.appendText("Physical Keyboard Type: " + flash. ui.Keyboard.physicalKeyboardType + "\n"); traceField.appendText("Virtual Keyboard: " + flash.ui.Keyboard. hasVirtualKeyboard + "\n"); }
- The result will appear similar to the following:
How it works...
The Flash platform runtimes are able to report certain device capabilities when invoked. The data reported will allow us to tailor the user experience, based upon what sort of input types are detected by the runtime.
Here follows a basic rundown of the four input types that can be reported upon:
flash.system.Capabilities.touchscreenType
Invoking this method will return a String
constant of FINGER, STYLUS
, or NONE
. It informs us whether some sort of direct screen interaction is available on the device, and if so, what sort. In the case of Android devices, this will always return FINGER
.
flash.ui.Mouse.supportsCursor
Invoking this method will return a Boolean
of true
or false
. It simply informs us whether a persistent mouse cursor is available on the device. In the case of Android devices, this will most likely always return false
.
flash.ui.Keyboard.physicalKeyboardType
Invoking this method will return a String
constant of ALPHANUMERIC, KEYPAD
, or NONE
. It informs us whether some sort of dedicated physical keyboard is available on the device, and if so, what sort. In the case of Android devices, this will most likely always return NONE
, even though certain Android models do have a physical keyboard.
flash.ui.Keyboard.hasVirtualKeyboard
Invoking this method will return a Boolean
of true
or false
. It simply informs us whether a virtual (software) keyboard is available on the device. In the case of Android devices, this will most likely always return true
.
- 中文版3ds Max 2012實(shí)用教程(第2版)
- 工業(yè)產(chǎn)品設(shè)計(jì)(Inventor 2010)
- Photoshop CC中文版基礎(chǔ)與實(shí)例教程(第7版)
- Talend Open Studio Cookbook
- Learning Facebook Application Development
- iPhone JavaScript Cookbook
- Magento 1.4 Themes Design
- Android從入門(mén)到精通
- 零基礎(chǔ)學(xué)AutoCAD 2018(全視頻教學(xué)版)
- Adobe創(chuàng)意大學(xué)Photoshop CS5 產(chǎn)品專(zhuān)家認(rèn)證標(biāo)準(zhǔn)教材
- 中文版After Effects 2022基礎(chǔ)教程
- SolidWorks 2018快速入門(mén)及應(yīng)用技巧
- NetSuite OneWorld Implementation 2011 R2
- PPT設(shè)計(jì)與制作實(shí)戰(zhàn)教程
- 中文版AutoCAD 2022從入門(mén)到精通