Advertisement
Guest User

AndroidSoftKeyboardHelper.as

a guest
Mar 26th, 2020
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.sf.util {
  2. import com.distriqt.extension.application.Application;
  3.  
  4. import flash.events.TimerEvent;
  5. import flash.system.Capabilities;
  6. import flash.utils.Timer;
  7.  
  8. public class AndroidSoftKeyboardHelper {
  9.  
  10.     public static var SoftKeyboardHeight:int;
  11.  
  12.     private static var _callBack:Function;
  13.  
  14.     public static function get isNeeded():Boolean {
  15.         var os:String = Capabilities.manufacturer.toLowerCase();
  16.         if (os.search("android") > -1) {
  17.             return true;
  18.         }
  19.         return false;
  20.     }
  21.  
  22.     public static function get hasValidRecordedKeyboardHeight():Boolean {
  23.         if (SoftKeyboardHeight > 0) {
  24.             return true;
  25.         }
  26.         return false;
  27.     }
  28.  
  29.     // here we check if we have already the softkeyboard height.
  30.     // if not we start the timer to get the correct height when the
  31.     // SoftKeyboard is fully appeared
  32.     public static function onSoftKeyboardInitialized(callback:Function):void {
  33.         _callBack = callback;
  34.  
  35.         if (hasValidRecordedKeyboardHeight) {
  36.             callCallBack();
  37.         } else {
  38.             startInitializeSoftKeyboard();
  39.         }
  40.  
  41.     }
  42.  
  43.     private static function startInitializeSoftKeyboard():void {
  44.         var timer:Timer = new Timer(100, 1);
  45.         timer.addEventListener(TimerEvent.TIMER_COMPLETE, onRefreshTimerComplete);
  46.         timer.start();
  47.     }
  48.  
  49.     // Here we check if the sofkeyboard height is already bigger than 0
  50.     // if not we start the timer again till we get the correct height
  51.     private static function onRefreshTimerComplete(e:TimerEvent):void {
  52.         if (e.target != null) {
  53.             var timer:Timer = e.target as Timer;
  54.             timer.removeEventListener(TimerEvent.TIMER, onRefreshTimerComplete);
  55.             timer = null;
  56.         }
  57.  
  58.         if (Application.isSupported) {
  59.             SoftKeyboardHeight = Application.service.keyboard.height;
  60.         }
  61.  
  62.         if (hasValidRecordedKeyboardHeight) {
  63.             callCallBack();
  64.         } else {
  65.             startInitializeSoftKeyboard();
  66.         }
  67.     }
  68.  
  69.     private static function callCallBack():void {
  70.         if (_callBack != null) {
  71.             _callBack();
  72.         }
  73.         _callBack = null;
  74.     }
  75. }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement