Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.sf.util {
- import com.distriqt.extension.application.Application;
- import flash.events.TimerEvent;
- import flash.system.Capabilities;
- import flash.utils.Timer;
- public class AndroidSoftKeyboardHelper {
- public static var SoftKeyboardHeight:int;
- private static var _callBack:Function;
- public static function get isNeeded():Boolean {
- var os:String = Capabilities.manufacturer.toLowerCase();
- if (os.search("android") > -1) {
- return true;
- }
- return false;
- }
- public static function get hasValidRecordedKeyboardHeight():Boolean {
- if (SoftKeyboardHeight > 0) {
- return true;
- }
- return false;
- }
- // here we check if we have already the softkeyboard height.
- // if not we start the timer to get the correct height when the
- // SoftKeyboard is fully appeared
- public static function onSoftKeyboardInitialized(callback:Function):void {
- _callBack = callback;
- if (hasValidRecordedKeyboardHeight) {
- callCallBack();
- } else {
- startInitializeSoftKeyboard();
- }
- }
- private static function startInitializeSoftKeyboard():void {
- var timer:Timer = new Timer(100, 1);
- timer.addEventListener(TimerEvent.TIMER_COMPLETE, onRefreshTimerComplete);
- timer.start();
- }
- // Here we check if the sofkeyboard height is already bigger than 0
- // if not we start the timer again till we get the correct height
- private static function onRefreshTimerComplete(e:TimerEvent):void {
- if (e.target != null) {
- var timer:Timer = e.target as Timer;
- timer.removeEventListener(TimerEvent.TIMER, onRefreshTimerComplete);
- timer = null;
- }
- if (Application.isSupported) {
- SoftKeyboardHeight = Application.service.keyboard.height;
- }
- if (hasValidRecordedKeyboardHeight) {
- callCallBack();
- } else {
- startInitializeSoftKeyboard();
- }
- }
- private static function callCallBack():void {
- if (_callBack != null) {
- _callBack();
- }
- _callBack = null;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement