How to use this.unlock method in Appium Android Driver

Best JavaScript code snippet using appium-android-driver

SoundManager.js

Source:SoundManager.js Github

copy

Full Screen

1/**2* @author Richard Davey <rich@photonstorm.com>3* @copyright 2016 Photon Storm Ltd.4* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}5*/6/**7* The Sound Manager is responsible for playing back audio via either the Legacy HTML Audio tag or via Web Audio if the browser supports it.8* Note: On Firefox 25+ on Linux if you have media.gstreamer disabled in about:config then it cannot play back mp3 or m4a files.9* The audio file type and the encoding of those files are extremely important. Not all browsers can play all audio formats.10* There is a good guide to what's supported here: http://hpr.dogphilosophy.net/test/11*12* If you are reloading a Phaser Game on a page that never properly refreshes (such as in an AngularJS project) then you will quickly run out13* of AudioContext nodes. If this is the case create a global var called PhaserGlobal on the window object before creating the game. The active14* AudioContext will then be saved to window.PhaserGlobal.audioContext when the Phaser game is destroyed, and re-used when it starts again.15*16* Mobile warning: There are some mobile devices (certain iPad 2 and iPad Mini revisions) that cannot play 48000 Hz audio.17* When they try to play the audio becomes extremely distorted and buzzes, eventually crashing the sound system.18* The solution is to use a lower encoding rate such as 44100 Hz. Sometimes the audio context will19* be created with a sampleRate of 48000. If this happens and audio distorts you should re-create the context.20*21* @class Phaser.SoundManager22* @constructor23* @param {Phaser.Game} game - Reference to the current game instance.24*/25Phaser.SoundManager = function (game) {26 /**27 * @property {Phaser.Game} game - Local reference to game.28 */29 this.game = game;30 /**31 * @property {Phaser.Signal} onSoundDecode - The event dispatched when a sound decodes (typically only for mp3 files)32 */33 this.onSoundDecode = new Phaser.Signal();34 /**35 * This signal is dispatched whenever the global volume changes. The new volume is passed as the only parameter to your callback.36 * @property {Phaser.Signal} onVolumeChange37 */38 this.onVolumeChange = new Phaser.Signal();39 /**40 * This signal is dispatched when the SoundManager is globally muted, either directly via game code or as a result of the game pausing.41 * @property {Phaser.Signal} onMute42 */43 this.onMute = new Phaser.Signal();44 /**45 * This signal is dispatched when the SoundManager is globally un-muted, either directly via game code or as a result of the game resuming from a pause.46 * @property {Phaser.Signal} onUnMute47 */48 this.onUnMute = new Phaser.Signal();49 /**50 * @property {AudioContext} context - The AudioContext being used for playback.51 * @default52 */53 this.context = null;54 /**55 * @property {boolean} usingWebAudio - True the SoundManager and device are both using Web Audio.56 * @readonly57 */58 this.usingWebAudio = false;59 /**60 * @property {boolean} usingAudioTag - True the SoundManager and device are both using the Audio tag instead of Web Audio.61 * @readonly62 */63 this.usingAudioTag = false;64 /**65 * @property {boolean} noAudio - True if audio been disabled via the PhaserGlobal (useful if you need to use a 3rd party audio library) or the device doesn't support any audio.66 * @default67 */68 this.noAudio = false;69 /**70 * @property {boolean} connectToMaster - Used in conjunction with Sound.externalNode this allows you to stop a Sound node being connected to the SoundManager master gain node.71 * @default72 */73 this.connectToMaster = true;74 /**75 * @property {boolean} touchLocked - true if the audio system is currently locked awaiting a touch event.76 * @default77 */78 this.touchLocked = false;79 /**80 * @property {number} channels - The number of audio channels to use in playback.81 * @default82 */83 this.channels = 32;84 /**85 * Set to true to have all sound muted when the Phaser game pauses (such as on loss of focus),86 * or set to false to keep audio playing, regardless of the game pause state. You may need to87 * do this should you wish to control audio muting via external DOM buttons or similar.88 * @property {boolean} muteOnPause 89 * @default90 */91 this.muteOnPause = true;92 /**93 * @property {boolean} _codeMuted - Internal mute tracking var.94 * @private95 * @default96 */97 this._codeMuted = false;98 /**99 * @property {boolean} _muted - Internal mute tracking var.100 * @private101 * @default102 */103 this._muted = false;104 /**105 * @property {AudioContext} _unlockSource - Internal unlock tracking var.106 * @private107 * @default108 */109 this._unlockSource = null;110 /**111 * @property {number} _volume - The global audio volume. A value between 0 (silence) and 1 (full volume).112 * @private113 * @default114 */115 this._volume = 1;116 /**117 * @property {array} _sounds - An array containing all the sounds118 * @private119 */120 this._sounds = [];121 /**122 * @property {Phaser.ArraySet} _watchList - An array set containing all the sounds being monitored for decoding status.123 * @private124 */125 this._watchList = new Phaser.ArraySet();126 /**127 * @property {boolean} _watching - Is the SoundManager monitoring the watchList?128 * @private129 */130 this._watching = false;131 /**132 * @property {function} _watchCallback - The callback to invoke once the watchlist is clear.133 * @private134 */135 this._watchCallback = null;136 /**137 * @property {object} _watchContext - The context in which to call the watchlist callback.138 * @private139 */140 this._watchContext = null;141};142Phaser.SoundManager.prototype = {143 /**144 * Initialises the sound manager.145 * @method Phaser.SoundManager#boot146 * @protected147 */148 boot: function () {149 if (this.game.device.iOS && this.game.device.webAudio === false)150 {151 this.channels = 1;152 }153 // PhaserGlobal overrides154 if (window['PhaserGlobal'])155 {156 // Check to see if all audio playback is disabled (i.e. handled by a 3rd party class)157 if (window['PhaserGlobal'].disableAudio === true)158 {159 this.noAudio = true;160 this.touchLocked = false;161 return;162 }163 // Check if the Web Audio API is disabled (for testing Audio Tag playback during development)164 if (window['PhaserGlobal'].disableWebAudio === true)165 {166 this.usingAudioTag = true;167 this.touchLocked = false;168 return;169 }170 }171 if (window['PhaserGlobal'] && window['PhaserGlobal'].audioContext)172 {173 this.context = window['PhaserGlobal'].audioContext;174 }175 else176 {177 if (!!window['AudioContext'])178 {179 try {180 this.context = new window['AudioContext']();181 } catch (error) {182 this.context = null;183 this.usingWebAudio = false;184 this.touchLocked = false;185 }186 }187 else if (!!window['webkitAudioContext'])188 {189 try {190 this.context = new window['webkitAudioContext']();191 } catch (error) {192 this.context = null;193 this.usingWebAudio = false;194 this.touchLocked = false;195 }196 }197 }198 if (this.context === null)199 {200 // No Web Audio support - how about legacy Audio?201 if (window['Audio'] === undefined)202 {203 this.noAudio = true;204 return;205 }206 else207 {208 this.usingAudioTag = true;209 }210 }211 else212 {213 this.usingWebAudio = true;214 if (this.context.createGain === undefined)215 {216 this.masterGain = this.context.createGainNode();217 }218 else219 {220 this.masterGain = this.context.createGain();221 }222 this.masterGain.gain.value = 1;223 this.masterGain.connect(this.context.destination);224 }225 if (!this.noAudio)226 {227 // On mobile we need a native touch event before we can play anything, so capture it here228 if (!this.game.device.cocoonJS && this.game.device.iOS || (window['PhaserGlobal'] && window['PhaserGlobal'].fakeiOSTouchLock))229 {230 this.setTouchLock();231 }232 }233 },234 /**235 * Sets the Input Manager touch callback to be SoundManager.unlock.236 * Required for iOS audio device unlocking. Mostly just used internally.237 *238 * @method Phaser.SoundManager#setTouchLock239 */240 setTouchLock: function () {241 if (this.noAudio || (window['PhaserGlobal'] && window['PhaserGlobal'].disableAudio === true))242 {243 return;244 }245 if (this.game.device.iOSVersion > 8)246 {247 this.game.input.touch.addTouchLockCallback(this.unlock, this, true);248 }249 else250 {251 this.game.input.touch.addTouchLockCallback(this.unlock, this);252 }253 this.touchLocked = true;254 },255 /**256 * Enables the audio, usually after the first touch.257 *258 * @method Phaser.SoundManager#unlock259 * @return {boolean} True if the callback should be removed, otherwise false.260 */261 unlock: function () {262 if (this.noAudio || !this.touchLocked || this._unlockSource !== null)263 {264 return true;265 }266 // Global override (mostly for Audio Tag testing)267 if (this.usingAudioTag)268 {269 this.touchLocked = false;270 this._unlockSource = null;271 }272 else if (this.usingWebAudio)273 {274 // Create empty buffer and play it275 // The SoundManager.update loop captures the state of it and then resets touchLocked to false276 var buffer = this.context.createBuffer(1, 1, 22050);277 this._unlockSource = this.context.createBufferSource();278 this._unlockSource.buffer = buffer;279 this._unlockSource.connect(this.context.destination);280 if (this._unlockSource.start === undefined)281 {282 this._unlockSource.noteOn(0);283 }284 else285 {286 this._unlockSource.start(0);287 }288 }289 // We can remove the event because we've done what we needed (started the unlock sound playing)290 return true;291 },292 /**293 * Stops all the sounds in the game.294 *295 * @method Phaser.SoundManager#stopAll296 */297 stopAll: function () {298 if (this.noAudio)299 {300 return;301 }302 for (var i = 0; i < this._sounds.length; i++)303 {304 if (this._sounds[i])305 {306 this._sounds[i].stop();307 }308 }309 },310 /**311 * Pauses all the sounds in the game.312 *313 * @method Phaser.SoundManager#pauseAll314 */315 pauseAll: function () {316 if (this.noAudio)317 {318 return;319 }320 for (var i = 0; i < this._sounds.length; i++)321 {322 if (this._sounds[i])323 {324 this._sounds[i].pause();325 }326 }327 },328 /**329 * Resumes every sound in the game.330 *331 * @method Phaser.SoundManager#resumeAll332 */333 resumeAll: function () {334 if (this.noAudio)335 {336 return;337 }338 for (var i = 0; i < this._sounds.length; i++)339 {340 if (this._sounds[i])341 {342 this._sounds[i].resume();343 }344 }345 },346 /**347 * Decode a sound by its asset key.348 *349 * @method Phaser.SoundManager#decode350 * @param {string} key - Assets key of the sound to be decoded.351 * @param {Phaser.Sound} [sound] - Its buffer will be set to decoded data.352 */353 decode: function (key, sound) {354 sound = sound || null;355 var soundData = this.game.cache.getSoundData(key);356 if (soundData)357 {358 if (this.game.cache.isSoundDecoded(key) === false)359 {360 this.game.cache.updateSound(key, 'isDecoding', true);361 var _this = this;362 try {363 this.context.decodeAudioData(soundData, function (buffer) {364 if (buffer)365 {366 _this.game.cache.decodedSound(key, buffer);367 _this.onSoundDecode.dispatch(key, sound);368 }369 });370 }371 catch (e) {}372 }373 }374 },375 /**376 * This method allows you to give the SoundManager a list of Sound files, or keys, and a callback.377 * Once all of the Sound files have finished decoding the callback will be invoked.378 * The amount of time spent decoding depends on the codec used and file size.379 * If all of the files given have already decoded the callback is triggered immediately.380 *381 * @method Phaser.SoundManager#setDecodedCallback382 * @param {string|array} files - An array containing either Phaser.Sound objects or their key strings as found in the Phaser.Cache.383 * @param {Function} callback - The callback which will be invoked once all files have finished decoding.384 * @param {Object} callbackContext - The context in which the callback will run.385 */386 setDecodedCallback: function (files, callback, callbackContext) {387 if (typeof files === 'string')388 {389 files = [ files ];390 }391 this._watchList.reset();392 for (var i = 0; i < files.length; i++)393 {394 if (files[i] instanceof Phaser.Sound)395 {396 if (!this.game.cache.isSoundDecoded(files[i].key))397 {398 this._watchList.add(files[i].key);399 }400 }401 else if (!this.game.cache.isSoundDecoded(files[i]))402 {403 this._watchList.add(files[i]);404 }405 }406 // All decoded already?407 if (this._watchList.total === 0)408 {409 this._watching = false;410 callback.call(callbackContext);411 }412 else413 {414 this._watching = true;415 this._watchCallback = callback;416 this._watchContext = callbackContext;417 }418 },419 /**420 * Updates every sound in the game, checks for audio unlock on mobile and monitors the decoding watch list.421 *422 * @method Phaser.SoundManager#update423 * @protected424 */425 update: function () {426 if (this.noAudio)427 {428 return;429 }430 if (this.touchLocked && this._unlockSource !== null && (this._unlockSource.playbackState === this._unlockSource.PLAYING_STATE || this._unlockSource.playbackState === this._unlockSource.FINISHED_STATE))431 {432 this.touchLocked = false;433 this._unlockSource = null;434 }435 for (var i = 0; i < this._sounds.length; i++)436 {437 this._sounds[i].update();438 }439 if (this._watching)440 {441 var key = this._watchList.first;442 while (key)443 {444 if (this.game.cache.isSoundDecoded(key))445 {446 this._watchList.remove(key);447 }448 key = this._watchList.next;449 }450 if (this._watchList.total === 0)451 {452 this._watching = false;453 this._watchCallback.call(this._watchContext);454 }455 }456 },457 /**458 * Adds a new Sound into the SoundManager.459 *460 * @method Phaser.SoundManager#add461 * @param {string} key - Asset key for the sound.462 * @param {number} [volume=1] - Default value for the volume.463 * @param {boolean} [loop=false] - Whether or not the sound will loop.464 * @param {boolean} [connect=true] - Controls if the created Sound object will connect to the master gainNode of the SoundManager when running under WebAudio.465 * @return {Phaser.Sound} The new sound instance.466 */467 add: function (key, volume, loop, connect) {468 if (volume === undefined) { volume = 1; }469 if (loop === undefined) { loop = false; }470 if (connect === undefined) { connect = this.connectToMaster; }471 var sound = new Phaser.Sound(this.game, key, volume, loop, connect);472 this._sounds.push(sound);473 return sound;474 },475 /**476 * Adds a new AudioSprite into the SoundManager.477 *478 * @method Phaser.SoundManager#addSprite479 * @param {string} key - Asset key for the sound.480 * @return {Phaser.AudioSprite} The new AudioSprite instance.481 */482 addSprite: function(key) {483 var audioSprite = new Phaser.AudioSprite(this.game, key);484 return audioSprite;485 },486 /**487 * Removes a Sound from the SoundManager. The removed Sound is destroyed before removal.488 *489 * @method Phaser.SoundManager#remove490 * @param {Phaser.Sound} sound - The sound object to remove.491 * @return {boolean} True if the sound was removed successfully, otherwise false.492 */493 remove: function (sound) {494 var i = this._sounds.length;495 while (i--)496 {497 if (this._sounds[i] === sound)498 {499 this._sounds[i].destroy(false);500 this._sounds.splice(i, 1);501 return true;502 }503 }504 return false;505 },506 /**507 * Removes all Sounds from the SoundManager that have an asset key matching the given value.508 * The removed Sounds are destroyed before removal.509 *510 * @method Phaser.SoundManager#removeByKey511 * @param {string} key - The key to match when removing sound objects.512 * @return {number} The number of matching sound objects that were removed.513 */514 removeByKey: function (key) {515 var i = this._sounds.length;516 var removed = 0;517 while (i--)518 {519 if (this._sounds[i].key === key)520 {521 this._sounds[i].destroy(false);522 this._sounds.splice(i, 1);523 removed++;524 }525 }526 return removed;527 },528 /**529 * Adds a new Sound into the SoundManager and starts it playing.530 *531 * @method Phaser.SoundManager#play532 * @param {string} key - Asset key for the sound.533 * @param {number} [volume=1] - Default value for the volume.534 * @param {boolean} [loop=false] - Whether or not the sound will loop.535 * @return {Phaser.Sound} The new sound instance.536 */537 play: function (key, volume, loop) {538 if (this.noAudio)539 {540 return;541 }542 var sound = this.add(key, volume, loop);543 sound.play();544 return sound;545 },546 /**547 * Internal mute handler called automatically by the SoundManager.mute setter.548 *549 * @method Phaser.SoundManager#setMute550 * @private551 */552 setMute: function () {553 if (this._muted)554 {555 return;556 }557 this._muted = true;558 if (this.usingWebAudio)559 {560 this._muteVolume = this.masterGain.gain.value;561 this.masterGain.gain.value = 0;562 }563 // Loop through sounds564 for (var i = 0; i < this._sounds.length; i++)565 {566 if (this._sounds[i].usingAudioTag)567 {568 this._sounds[i].mute = true;569 }570 }571 this.onMute.dispatch();572 },573 /**574 * Internal mute handler called automatically by the SoundManager.mute setter.575 *576 * @method Phaser.SoundManager#unsetMute577 * @private578 */579 unsetMute: function () {580 if (!this._muted || this._codeMuted)581 {582 return;583 }584 this._muted = false;585 if (this.usingWebAudio)586 {587 this.masterGain.gain.value = this._muteVolume;588 }589 // Loop through sounds590 for (var i = 0; i < this._sounds.length; i++)591 {592 if (this._sounds[i].usingAudioTag)593 {594 this._sounds[i].mute = false;595 }596 }597 this.onUnMute.dispatch();598 },599 /**600 * Stops all the sounds in the game, then destroys them and finally clears up any callbacks.601 *602 * @method Phaser.SoundManager#destroy603 */604 destroy: function () {605 this.stopAll();606 for (var i = 0; i < this._sounds.length; i++)607 {608 if (this._sounds[i])609 {610 this._sounds[i].destroy();611 }612 }613 this._sounds = [];614 this.onSoundDecode.dispose();615 if (this.context)616 {617 if (window['PhaserGlobal'])618 {619 // Store this in the PhaserGlobal window var, if set, to allow for re-use if the game is created again without the page refreshing620 window['PhaserGlobal'].audioContext = this.context;621 }622 else623 {624 if (this.context.close)625 {626 this.context.close();627 }628 }629 }630 }631};632Phaser.SoundManager.prototype.constructor = Phaser.SoundManager;633/**634* @name Phaser.SoundManager#mute635* @property {boolean} mute - Gets or sets the muted state of the SoundManager. This effects all sounds in the game.636*/637Object.defineProperty(Phaser.SoundManager.prototype, "mute", {638 get: function () {639 return this._muted;640 },641 set: function (value) {642 value = value || false;643 if (value)644 {645 if (this._muted)646 {647 return;648 }649 this._codeMuted = true;650 this.setMute();651 }652 else653 {654 if (!this._muted)655 {656 return;657 }658 this._codeMuted = false;659 this.unsetMute();660 }661 }662});663/**664* @name Phaser.SoundManager#volume665* @property {number} volume - Gets or sets the global volume of the SoundManager, a value between 0 and 1. The value given is clamped to the range 0 to 1.666*/667Object.defineProperty(Phaser.SoundManager.prototype, "volume", {668 get: function () {669 return this._volume;670 },671 set: function (value) {672 if (value < 0)673 {674 value = 0;675 }676 else if (value > 1)677 {678 value = 1;679 }680 if (this._volume !== value)681 {682 this._volume = value;683 if (this.usingWebAudio)684 {685 this.masterGain.gain.value = value;686 }687 else688 {689 // Loop through the sound cache and change the volume of all html audio tags690 for (var i = 0; i < this._sounds.length; i++)691 {692 if (this._sounds[i].usingAudioTag)693 {694 this._sounds[i].updateGlobalVolume(value);695 }696 }697 }698 this.onVolumeChange.dispatch(value);699 }700 }...

Full Screen

Full Screen

ingcart-lock-manager.js

Source:ingcart-lock-manager.js Github

copy

Full Screen

1var Ingcart = require('./ingcart.min')2var config = require('../config/const')3var wxApi = require('./wxApi')4var code = require('../config/unlock-error-code')5var request = require('./request')6var IngcartLockManager = function(setup) {7 const _this = this;8 this.ingcart = null;9 this.subJourneyMsgToken = null;10 this.subUnlockProgressToken = null;11 this.lock_cb = function() {};12 this.forceUseBle = true;13 config.appkey = setup.appkey;14 if (typeof setup.token == undefined) {15 var options = {16 phone: config.identifier_key,17 captcha: ''18 }19 request.checkCaptcha(options)20 .then(function(result){21 if (result.statusCode == 200) {22 wx.setStorageSync('userInfo', result.data);23 } else {24 }25 })26 .catch(err => {27 })28 } else {29 wx.setStorageSync('userInfo', {token: setup.token});30 }31 32 Ingcart.reinit(this);33 this.subscribeJourneyMessage();34 this.ingcart.setSessionFinishCB(function() {35 console.log("IngcartLockManager session finished");36 // session finished, first, we unsubscribe the journey message37 _this.ingcart.pubsub.unsubscribe(_this.subJourneyMsgToken);38 // notify close lock event39 _this.lock_cb();40 });41}42IngcartLockManager.prototype.unlock = function(bike_id, latitude, longitude, unlock_cb, unlock_fail_cb, lock_cb, useBle = true) {43 const _this = this;44 this.forceUseBle = useBle;45 this.unlock_progress = 0;46 this.unlock_fail_cb = unlock_fail_cb || function(code) {};47 this.unlock_cb = unlock_cb || function(progress) {};48 this.lock_cb = lock_cb || function() {};49 this.unlock_latitude = latitude;50 this.unlock_longitude = longitude;51 this.unlock_bikeid = bike_id;52 this.unlock_type=1;53 this.scanBLETimeoutTimer = null;54 this.ingcart.setOnUnlockDataTransmissionListener(function(up) {55 _this.notifyUnlockProgress(_this.unlock_progress + 5)56 });57 // before unlock, we call reinit to reconnect socket.id58 Ingcart.reinit(this);59 console.log("IngcartLockManager init bluetooth success ");60 var options = {61 url: config.BASE_URL.URL_BLE_INFO,62 data: {63 appkey: config.appkey,64 bike_number: _this.unlock_bikeid || wxApi.getStorage('bikeId')65 }66 }67 console.log("IngcartLockManager query ble info options", options);68 _this.ingcart.requestBLEInfo(options)69 .then(function (res) {70 if (res.statusCode == 200) {71 let bleInfo = res.data;72 console.log("IngcartLockManager get ble info success", bleInfo);73 wxApi.setStorage('BLEInfo', bleInfo);74 _this.ingcart.BLE_INFO = bleInfo;75 //-------------------------------------------------使用gprs开锁76 if (_this.forceUseBle == false) {77 new Promise(function (resolve, rejiect) {78 _this.unlock_type=0;79 _this.fireUnlockRequest();80 resolve();81 }).then(res => {82 _this.notifyUnlockProgress(config.UnlockPhases.POLL_SESSION_PHASES);83 _this.ingcart.pubsub.subscribe('unlocking',function(result){84 _this.notifyUnlockProgress(100);85 })86 87 }).catch(err => {88 console.log('gprs', err);89 })90 }91 //-------------------------------------------------使用蓝牙开锁92 else{93 _this.ingcart.initBluetooth()94 .then(function (result) {95 wx.closeBluetoothAdapter({96 success: function (result) {97 wx.openBluetoothAdapter({98 success: function (result) {99 _this.handleBLEInfo(res.data);100 },101 });102 },103 fail: function () {104 wx.openBluetoothAdapter({105 success: function (result) {106 _this.handleBLEInfo(res.data);107 },108 });109 }110 });111 })112 .catch(err => {113 // init bluetooth failed, may need ask user to open bluetooth in settings114 _this.notifyUnlockError(code.UNLOCK_ERROR_CODE.ERROR_OBTAIN_BLUETOOTH_ADAPTER);115 }) 116 }117 }118 })119}120IngcartLockManager.prototype.setUnlockSuccessCallback = function(unlock_success_cb) {121 this.unlock_success_cb = unlock_success_cb;122}123IngcartLockManager.prototype.setUnlockFailCallback = function(unlock_fail_cb) {124 this.unlock_fail_cb = unlock_fail_cb;125}126IngcartLockManager.prototype.setLockEventCallback = function(lock_cb) {127 this.lock_cb = lock_cb;128}129IngcartLockManager.prototype.handleBLEInfo = function(data) {130 const _this = this;131 this.ingcart.handleBLEInfo(data)132 .then(res => {133 wxApi.setStorage('BLE_TARGET_INFO', res);134 _this.scanBLETimeoutTimer = setTimeout(function(){135 _this.ingcart.stopBluetoothDevicesDiscovery()136 .then(res => {137 _this.notifyUnlockError(code.UNLOCK_ERROR_CODE.ERROR_SCAN_TIMEOUT);138 })139 .catch(error => {140 _this.notifyUnlockError(code.UNLOCK_ERROR_CODE.ERROR_SCAN_TIMEOUT);141 })142 }, 30000);143 return _this.ingcart.startBluetoothDevicesDiscovery(function(res) {144 console.log("IngcartLockManager scan result ", res);145 _this.ingcart.handleBLEFound(res)146 .then(result => {147 _this.notifyUnlockProgress(config.UnlockPhases.CONNECT_PHASES);148 clearTimeout(_this.scanBLETimeoutTimer);149 _this.scanBLETimeoutTimer = null;150 _this.ingcart.stopBluetoothDevicesDiscovery();151 _this.createBLEConnection(result);152 })153 });154 })155 .then(res => {156 // start bluetooth devices discovery success157 _this.notifyUnlockProgress(config.UnlockPhases.SCAN_PHASES);158 })159 .catch(error => {160 if (error.errMsg == 'NoBleInfoData') {161 _this.unlock_fail_cb(code.UNLOCK_ERROR_CODE.ERROR_UNKNOWN_LOCK);162 } else {163 _this.unlock_fail_cb(code.UNLOCK_ERROR_CODE.ERROR_SCAN_ERROR);164 }165 })166}167IngcartLockManager.prototype.createBLEConnection = function(peripheral) {168 console.log("IngcartLockManager start create ble connection ", peripheral);169 const _this = this;170 _this.ingcart.createBLEConnection(peripheral)171 .then(res => {172 _this.notifyUnlockProgress(config.UnlockPhases.SERVICE_DISCOVER_PHASES);173 _this.ingcart.getBLEDeviceServices({174 deviceId: wxApi.getStorage('BLE_Target').deviceId || _this.ingcart.BLE_Target.deviceId175 })176 .then(res => {177 console.log("IngcartLockManager get ble services success ", res);178 var options = {179 deviceId: wxApi.getStorage('BLE_Target').deviceId || _this.ingcart.BLE_Target.deviceId,180 serviceId: _this.ingcart.BLE_ServerList.SERVICE_UUID || wxApi.getStorage('BLE_ServerList').SERVICE_UUID181 }182 return _this.ingcart.getBLEDeviceCharacteristics(options)183 })184 .then(res => {185 console.log("IngcartLockManager get ble characteristics success ", res);186 var serviceList = wxApi.getStorage('BLE_ServerList') || _this.ingcart.BLE_ServerList;187 var options = {188 deviceId: wxApi.getStorage('BLE_Target').deviceId || _this.ingcart.BLE_Target.deviceId,189 serviceId: serviceList.SERVICE_UUID,190 characteristicId: serviceList.READ_DATA_UUID,191 state: true192 }193 _this.ingcart.notifyBLECharacteristicValueChange(options)194 .then(res => {195 // set characteristic notification success, now fire unlock request to server196 _this.fireUnlockRequest();197 _this.notifyUnlockProgress(config.UnlockPhases.FIRE_UNLOCK_REQUEST_PHASES);198 })199 .catch(err => {200 _this.notifyUnlockError(code.UNLOCK_ERROR_CODE.ERROR_GET_CHARACTERISTICS);201 })202 })203 .catch(err => {204 console.log("IngcartLockManager err ", err);205 _this.notifyUnlockError(code.UNLOCK_ERROR_CODE.ERROR_SERVICES_DISCOVERED);206 })207 })208 .catch(err => {209 // create ble connection failed210 _this.notifyUnlockError(code.UNLOCK_ERROR_CODE.ERROR_CONNECT_STATUS);211 })212}213IngcartLockManager.prototype.fireUnlockRequest = function() {214 var unlock_options = {215 topic: config.UnlockTopic.TOPIC_UNLOCK_TO_SERVER + this.unlock_bikeid,216 msg: {217 u: wxApi.getStorage('userInfo').token,218 a: 0,219 lat: this.unlock_latitude,220 lng: this.unlock_longitude,221 ble: this.unlock_type // force use ble to unlock222 }223 };224 console.log("IngcartLockManager fire unlock request ", unlock_options);225 this.ingcart.publish(unlock_options);226}227IngcartLockManager.prototype.onSessionFinishedCB = function() {228}229IngcartLockManager.prototype.onBLEConnectionStateChangedCB = function() {230}231IngcartLockManager.prototype.subscribeJourneyMessage = function() {232 const _this = this;233 this.subJourneyMsgToken = this.ingcart.pubsub.subscribe('journey', function(topic, msg) {234 switch (msg.status) {235 case 0:236 // session detail237 break;238 case 13:239 console.log("IngcartLockManager session finished");240 // session finished, first, we unsubscribe the journey message241 _this.ingcart.pubsub.unsubscribe(_this.subJourneyMsgToken);242 // notify close lock event243 _this.lock_cb();244 var BLE_Target = wxApi.getStorage('BLE_Target') || _this.ingcart.BLE_Target;245 // TODO the session state must be update in ingcart self!246 _this.ingcart.sessionState = false;247 _this.ingcart.BLE_RECONNECTION = false;248 _this.ingcart.closeBLEConnection(BLE_Target.deviceId)249 .then(function (res) {250 })251 .catch(err => {252 })253 }254 });255 this.subUnlockProgressToken = this.ingcart.pubsub.subscribe('unlocking', function(topic, msg) {256 if (topic == 'unlocking') {257 if ((typeof msg.status) != 'undefined') {258 switch (msg.status) {259 case 0:260 // unlock success261 console.log("IngcartLockManager unlock success");262 _this.notifyUnlockProgress(100);263 _this.ingcart.setOnUnlockDataTransmissionListener(function(up){});264 break;265 case 1:266 break;267 default:268 _this.ingcart.BLE_CONNECTION = false;269 _this.notifyUnlockError(msg.status);270 }271 }272 }273 });274}275IngcartLockManager.prototype.unsubscribeJourneyMessage= function () {276 this.ingcart.pubsub.unsubscribe(this.subJourneyMsgToken);277 this.ingcart.pubsub.unsubscribe(this.subBleStateToken);278}279IngcartLockManager.prototype.notifyUnlockError = function(errorCode) {280 console.log("IngcartLockManager notifyUnlockError ", errorCode);281 var deviceId = wxApi.getStorage('BLE_Target').deviceId || app.ingcart.BLE_TARGET.deviceId;282 this.ingcart.closeBLEConnection(deviceId);283 this.unsubscribeJourneyMessage();284 this.unlock_fail_cb(errorCode);285}286IngcartLockManager.prototype.notifyUnlockProgress = function(progress) {287 this.unlock_cb(this.unlock_progress = (progress + 40));288 // this.unlock_cb(this.unlock_progress = progress);289}290IngcartLockManager.prototype.reinit = function() {291 Ingcart.reinit(this);292}293module.exports = {294 IngcartLockManager: IngcartLockManager,...

Full Screen

Full Screen

network_siminfo.js

Source:network_siminfo.js Github

copy

Full Screen

1// Copyright 2015 The Chromium Authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file.4/**5 * @fileoverview Polymer element for displaying and modifying a list of cellular6 * access points.7 */8(function() {9/** @enum {string} */10var ErrorType = {11 NONE: 'none',12 INCORRECT_PIN: 'incorrect-pin',13 INCORRECT_PUK: 'incorrect-puk',14 MISMATCHED_PIN: 'mismatched-pin',15 INVALID_PIN: 'invalid-pin',16 INVALID_PUK: 'invalid-puk'17};18var PIN_MIN_LENGTH = 4;19var PUK_MIN_LENGTH = 8;20Polymer({21 is: 'network-siminfo',22 properties: {23 /**24 * The network properties associated with the element.25 * @type {!CrOnc.NetworkProperties|undefined}26 */27 networkProperties: {28 type: Object,29 observer: 'networkPropertiesChanged_'30 },31 /** Set to true when a PUK is required to unlock the SIM. */32 pukRequired: {33 type: Boolean,34 value: false,35 observer: 'pukRequiredChanged_'36 },37 /**38 * Set to an ErrorType value after an incorrect PIN or PUK entry.39 * @type {ErrorType}40 */41 error: {42 type: Object,43 value: ErrorType.NONE44 },45 /**46 * Interface for networkingPrivate calls, passed from internet_page.47 * @type {NetworkingPrivate}48 */49 networkingPrivate: {50 type: Object,51 },52 },53 sendSimLockEnabled_: false,54 /** Polymer networkProperties changed method. */55 networkPropertiesChanged_: function() {56 if (!this.networkProperties || !this.networkProperties.Cellular)57 return;58 var simLockStatus = this.networkProperties.Cellular.SIMLockStatus;59 this.pukRequired =60 !!simLockStatus && simLockStatus.LockType == CrOnc.LockType.PUK;61 },62 /** Polymer networkProperties changed method. */63 pukRequiredChanged_: function() {64 if (this.$.unlockPukDialog.opened) {65 if (this.pukRequired)66 this.$.unlockPuk.focus();67 else68 this.$.unlockPukDialog.close();69 return;70 }71 if (!this.pukRequired)72 return;73 // If the PUK was activated while attempting to enter or change a pin,74 // close the dialog and open the unlock PUK dialog.75 var showUnlockPuk = false;76 if (this.$.enterPinDialog.opened) {77 this.$.enterPinDialog.close();78 showUnlockPuk = true;79 }80 if (this.$.changePinDialog.opened) {81 this.$.changePinDialog.close();82 showUnlockPuk = true;83 }84 if (this.$.unlockPinDialog.opened) {85 this.$.unlockPinDialog.close();86 showUnlockPuk = true;87 }88 if (!showUnlockPuk)89 return;90 this.error = ErrorType.NONE;91 this.$.unlockPukDialog.open();92 this.$.unlockPuk.focus();93 },94 /** Polymer networkProperties changed method. */95 onSimLockEnabledChange_: function(event) {96 if (!this.networkProperties || !this.networkProperties.Cellular)97 return;98 this.sendSimLockEnabled_ = event.target.checked;99 this.error = ErrorType.NONE;100 this.$.enterPinDialog.open();101 },102 /**103 * Focuses the correct element when the dialog is opened.104 * @param {Event} event105 * @private106 */107 onEnterPinDialogOpened_: function(event) {108 this.$.enterPin.value = '';109 this.$.enterPin.focus();110 },111 /**112 * Sends the PIN value from the Enter PIN dialog.113 * @param {Event} event114 * @private115 */116 sendEnterPin_: function(event) {117 var guid = this.networkProperties && this.networkProperties.GUID;118 if (!guid)119 return;120 var pin = this.$.enterPin.value;121 if (!this.validatePin_(pin))122 return;123 var simState = /** @type {!CrOnc.CellularSimState} */({124 currentPin: pin,125 requirePin: this.sendSimLockEnabled_126 });127 this.networkingPrivate.setCellularSimState(guid, simState, function() {128 if (chrome.runtime.lastError) {129 this.error = ErrorType.INCORRECT_PIN;130 } else {131 this.error = ErrorType.NONE;132 this.$.enterPinDialog.close();133 }134 }.bind(this));135 },136 /**137 * Opens the Change PIN dialog.138 * @param {Event} event139 * @private140 */141 onChangePinTap_: function(event) {142 if (!this.networkProperties || !this.networkProperties.Cellular)143 return;144 this.error = ErrorType.NONE;145 this.$.changePinDialog.open();146 },147 /**148 * Focuses the correct element when the dialog is opened.149 * @param {Event} event150 * @private151 */152 onChangePinDialogOpened_: function(event) {153 this.$.changePinOld.value = '';154 this.$.changePinNew1.value = '';155 this.$.changePinNew2.value = '';156 this.$.changePinOld.focus();157 },158 /**159 * Sends the old and new PIN values from the Change PIN dialog.160 * @param {Event} event161 * @private162 */163 sendChangePin_: function(event) {164 var guid = this.networkProperties && this.networkProperties.GUID;165 if (!guid)166 return;167 var newPin = this.$.changePinNew1.value;168 if (!this.validatePin_(newPin, this.$.changePinNew2.value))169 return;170 var simState = /** @type {!CrOnc.CellularSimState} */({171 requirePin: true,172 currentPin: this.$.changePinOld.value,173 newPin: newPin174 });175 this.networkingPrivate.setCellularSimState(guid, simState, function() {176 if (chrome.runtime.lastError) {177 this.error = ErrorType.INCORRECT_PIN;178 } else {179 this.error = ErrorType.NONE;180 this.$.changePinDialog.close();181 }182 }.bind(this));183 },184 /**185 * Opens the Unlock PIN dialog.186 * @param {Event} event187 * @private188 */189 onUnlockPinTap_: function(event) {190 this.error = ErrorType.NONE;191 this.$.unlockPinDialog.open();192 },193 /**194 * Focuses the correct element when the dialog is opened.195 * @param {Event} event196 * @private197 */198 onUnlockPinDialogOpened_: function(event) {199 this.$.unlockPin.value = '';200 this.$.unlockPin.focus();201 },202 /**203 * Sends the PIN value from the Unlock PIN dialog.204 * @param {Event} event205 * @private206 */207 sendUnlockPin_: function(event) {208 var guid = this.networkProperties && this.networkProperties.GUID;209 if (!guid)210 return;211 var pin = this.$.unlockPin.value;212 if (!this.validatePin_(pin))213 return;214 this.networkingPrivate.unlockCellularSim(guid, pin, '', function() {215 if (chrome.runtime.lastError) {216 this.error = ErrorType.INCORRECT_PIN;217 } else {218 this.error = ErrorType.NONE;219 this.$.unlockPinDialog.close();220 }221 }.bind(this));222 },223 /**224 * Opens the Unlock PUK dialog.225 * @param {Event} event226 * @private227 */228 unlockPuk_: function(event) {229 this.error = ErrorType.NONE;230 this.$.unlockPukDialog.open();231 },232 /**233 * Focuses the correct element when the dialog is opened.234 * @param {Event} event235 * @private236 */237 onUnlockPukDialogOpened_: function(event) {238 this.$.unlockPuk.value = '';239 this.$.unlockPin1.value = '';240 this.$.unlockPin2.value = '';241 this.$.unlockPuk.focus();242 },243 /**244 * Sends the PUK value and new PIN value from the Unblock PUK dialog.245 * @param {Event} event246 * @private247 */248 sendUnlockPuk_: function(event) {249 var guid = this.networkProperties && this.networkProperties.GUID;250 if (!guid)251 return;252 var puk = this.$.unlockPuk.value;253 if (!this.validatePuk_(puk))254 return;255 var pin = this.$.unlockPin1.value;256 if (!this.validatePin_(pin, this.$.unlockPin2.value))257 return;258 this.networkingPrivate.unlockCellularSim(guid, pin, puk, function() {259 if (chrome.runtime.lastError) {260 this.error = ErrorType.INCORRECT_PUK;261 } else {262 this.error = ErrorType.NONE;263 this.$.unlockSimDialog.close();264 }265 }.bind(this));266 },267 /**268 * @param {!CrOnc.NetworkProperties|undefined} networkProperties269 * @return {boolean} True if the Cellular SIM is locked.270 * @private271 */272 isSimLocked_: function(networkProperties) {273 return !!networkProperties && CrOnc.isSimLocked(networkProperties);274 },275 /**276 * @param {!CrOnc.NetworkProperties|undefined} networkProperties277 * @return {string} The message for the number of retries left.278 * @private279 */280 getRetriesLeftMsg_: function(networkProperties) {281 var retriesLeft =282 this.get('Cellular.SIMLockStatus.RetriesLeft', networkProperties) || 0;283 // TODO(stevenjb): Localize284 return 'Retries left: ' + retriesLeft.toString();285 },286 /**287 * @param {string} error288 * @return {boolean} True if an error message should be shown for |error|.289 * @private290 */291 showError_: function(error) {292 return !!error && error != ErrorType.NONE;293 },294 /**295 * @param {string} error296 * @return {string} The error message to display for |error|.297 * @private298 */299 getErrorMsg_: function(error) {300 // TODO(stevenjb_: Translate301 if (error == ErrorType.INCORRECT_PIN)302 return 'Incorrect PIN.';303 if (error == ErrorType.INCORRECT_PUK)304 return 'Incorrect PUK.';305 if (error == ErrorType.MISMATCHED_PIN)306 return 'PIN values do not match.';307 if (error == ErrorType.INVALID_PIN)308 return 'Invalid PIN.';309 if (error == ErrorType.INVALID_PUK)310 return 'Invalid PUK.';311 return '';312 },313 /**314 * Checks whether |pin1| is of the proper length and if opt_pin2 is not315 * undefined, whether pin1 and opt_pin2 match. On any failure, sets316 * |this.error| and returns false.317 * @param {string} pin1318 * @param {string=} opt_pin2319 * @return {boolean} True if the pins match and are of minimum length.320 * @private321 */322 validatePin_: function(pin1, opt_pin2) {323 if (pin1.length < PIN_MIN_LENGTH) {324 this.error = ErrorType.INVALID_PIN;325 return false;326 }327 if (opt_pin2 != undefined && pin1 != opt_pin2) {328 this.error = ErrorType.MISMATCHED_PIN;329 return false;330 }331 return true;332 },333 /**334 * Checks whether |puk| is of the proper length. If not, sets |this.error|335 * and returns false.336 * @param {string} puk337 * @return {boolean} True if the puk is of minimum length.338 * @private339 */340 validatePuk_: function(puk) {341 if (puk.length < PUK_MIN_LENGTH) {342 this.error = ErrorType.INVALID_PUK;343 return false;344 }345 return true;346 }347});...

Full Screen

Full Screen

TreeGrid.js

Source:TreeGrid.js Github

copy

Full Screen

1/**2 * @class Aurora.TreeGrid3 * @extends Aurora.Grid4 * <p>树形表格组件.5 * @author njq.niu@hand-china.com6 * @constructor7 * @param {Object} config 配置对象. 8 */9$A.TreeGrid = Ext.extend($A.Grid, {10 initComponent : function(config) {11 $A.TreeGrid.superclass.initComponent.call(this, config);12 if (this.lockColumns.length > 0) {13 var sf = this;14 var ltid = sf.id + "_lb_tree"15 sf.lb.set({id : ltid});16 delete config.marginheight;17 delete config.marginwidth;18 var ltc = sf.createTreeConfig(config, sf.lockColumns, ltid, true,sf);19 sf.lockTree = new $A.Tree(ltc);20 sf.lb.addClass('item-treegrid');21 sf.lockTree.body = sf.lb;22 sf.lockTree.treegrid = sf;23 sf.lockTree.on('render', function() {24 sf.processData();25 Ext.DomHelper.insertHtml("beforeEnd", sf.lb.dom,26 '<div style="height:17px"></div>');27 }, sf)28 this.lockTree.on('expand', function(tree, node) {29 var node = this.unlockTree.getNodeById(node.id);30 node.expand();31 }, this);32 this.lockTree.on('collapse', function(tree, node) {33 var node = this.unlockTree.getNodeById(node.id);34 node.collapse();35 }, this)36 }3738 var utid = this.id + "_ub_tree"39 this.ub.set({40 id : utid41 });42 var tc = this.createTreeConfig(config, this.unlockColumns, utid,this.lockColumns.length == 0, this);43 this.unlockTree = new $A.Tree(tc);44 this.ub.addClass('item-treegrid');45 this.unlockTree.body = this.ub;46 this.unlockTree.treegrid = this;47 this.unlockTree.on('render', this.processData, this)48 },49 initTemplate : function() {50 $A.TreeGrid.superclass.initTemplate.call(this);51 this.cbTpl = new Ext.Template('<center style="width:{width}px"><div class="{cellcls}" style="height:13px;padding:0px;" id="'52 + this.id + '_{name}_{recordid}"></div></center>');53 },54 createTemplateData : function(col, record) {55 return {56 width : col.width - 2,57 // cwidth:col.width-4,58 recordid : record.id,59 visibility : col.hidden === true ? 'hidden' : 'visible',60 name : col.name61 }62 },63 createTreeConfig : function(config, columns, id, showSkeleton, grid) {64 var c = columns[0];65 var width = (c) ? c.width : 150;66 return Ext.apply(config, {67 sw : 20,68 id : id,69 showSkeleton : showSkeleton,70 width : width,71 column : c,72 displayfield : c.name,73 renderer : c.renderer,74 initColumns : function(node) {75 if (!node.isRoot()) {76 for (var i = 0; i < columns.length; i++) {77 var c = columns[i];78 if (c.name == node.ownerTree.displayfield)79 continue;80 var td = document.createElement('td');81 td['_type_'] = 'text';82 td['atype'] = 'grid-cell';83 td['dataindex'] = c.name;84 td['recordid'] = node.record.id;85 if (c.align)86 td.style.textAlign = c.align;87 node.els[c.name + '_td'] = td;8889 // var div = document.createElement('div');90 // node.els[c.name+'_text']= div91 // Ext.fly(div).setWidth(c.width-4);92 // div.innerHTML =93 // grid.renderText(node.record,c,node.record.get(c.name));94 // 9596 var html = grid.createCell(c, node.record,97 false);98 var div = Ext.DomHelper.insertHtml(99 "afterBegin", td, html);100 Ext.fly(td).setWidth(c.width - 2);101 node.els[c.name + '_text'] = div;102103 td.appendChild(node.els[c.name + '_text']);104 td.className = 'node-text';105 node.els['itemNodeTr']106 .appendChild(node.els[c.name + '_td']);107 }108 }109 },110 createTreeNode : function(item) {111 return new $A.Tree.TreeGridNode(item);112 },113 onNodeSelect : function(el) {114 el['itemNodeTable'].style.backgroundColor = '#dfeaf5';115 },116 onNodeUnSelect : function(el) {117 el['itemNodeTable'].style.backgroundColor = '';118 }119 });120 },121 processData : function(tree, root) {122 if (!root)123 return;124 var items = [];125 var datas = this.dataset.data;126 if (tree.showRoot) {127 this.processNode(items, root)128 } else {129 var children = root.children;130 for (var i = 0; i < children.length; i++) {131 this.processNode(items, children[i])132 }133 }134 this.dataset.data = items;135 // this.onLoad();136 },137 onLoad : function(){138 this.drawFootBar();139 $A.Masker.unmask(this.wb);140 },141 processNode : function(items, node) {142 items.add(node.record);143 var children = node.children;144 for (var i = 0; i < children.length; i++) {145 this.processNode(items, children[i])146 }147 },148 bind : function(ds) {149 if (typeof(ds) === 'string') {150 ds = $A.CmpManager.get(ds);151 if (!ds)152 return;153 }154 this.dataset = ds;155 this.processDataSetLiestener('on');156 if (this.lockTree)157 this.lockTree.bind(ds);158 this.unlockTree.bind(ds);159 this.drawFootBar();160 },161 setColumnSize : function(name, size) {162 $A.TreeGrid.superclass.setColumnSize.call(this, name, size);163 var c = this.findColByName(name);164 var tree = (c.lock == true) ? this.lockTree : this.unlockTree;165 c.width = size;166 if (name == tree.displayfield) tree.width = size;167 tree.root.setWidth(name, size);// (name == tree.displayfield) ? size-2168 // :169 },170 renderLockArea : function() {171 var v = 0;172 var columns = this.columns;173 for (var i = 0, l = columns.length; i < l; i++) {174 if (columns[i].lock === true) {175 ;176 if (columns[i].hidden !== true)177 v += columns[i].width;178 }179 }180 this.lockWidth = v;181 },182 focusRow : function(row){183 var n=0,184 tree = this.unlockTree,185 hash = tree.nodeHash,186 datas = this.dataset.data;187 for(var i = 0 ; i<row ;i++){188 if(tree.isAllParentExpand(hash[datas[i].id]))n++;189 }190 $A.TreeGrid.superclass.focusRow.call(this,n);191 },192 onMouseWheel : function(e){193 }194});195$A.Tree.TreeGridNode = Ext.extend($A.Tree.TreeNode, {196 createNode : function(item) {197 return new $A.Tree.TreeGridNode(item);198 },199 createCellEl : function(df) {200 var tree = this.getOwnerTree();201 var html = tree.treegrid.createCell(tree.column, this.record,202 false);203 var td = this.els[df + '_td'];204 var div = Ext.DomHelper.insertHtml("afterBegin", this.els[df205 + '_td'], html);206 td['dataindex'] = df;207 td['atype'] = 'grid-cell';208 td['recordid'] = this.record.id;209 if (tree.column.align)210 td.style.textAlign = tree.column.align;211 this.els[df + '_text'] = div;212 },213 paintText : function() {214 },215 render : function() {216 $A.Tree.TreeGridNode.superclass.render.call(this);217 var tree = this.getOwnerTree();218 this.setWidth(tree.displayfield, tree.width);219 },220 setWidth : function(n, w) {221 $A.Tree.TreeGridNode.superclass.setWidth.call(this, n, w);222 } ...

Full Screen

Full Screen

DynamicTreeGrid.js

Source:DynamicTreeGrid.js Github

copy

Full Screen

1/**2 * @class Aurora.DynamicTreeGrid3 * @extends Aurora.TreeGrid4 * <p>树形表格组件.5 * @author njq.niu@hand-china.com6 * @constructor7 * @param {Object} config 配置对象. 8 */9$A.DynamicTreeGrid = Ext.extend($A.TreeGrid, {10 createTree : function(cfg){11 return cfg.showSkeleton ? new $A.DynamicTree(cfg) : $A.DynamicTreeGrid.superclass.createTree.call(this, cfg); 12 },13 createTreeConfig : function(config, columns, id, showSkeleton, grid) {14 var config = $A.DynamicTreeGrid.superclass.createTreeConfig.call(this, config,columns,id,showSkeleton,grid);15 if(!showSkeleton) return config;16 config['createTreeNode']= function(item) {17 return new $A.DynamicTreeGrid.TreeNode(item);18 }19 return config;20 },21 initTreeLisener : function(lockTree,unlockTree){22 if(lockTree){23 lockTree.on('render', function() {24 this.processData();25 Ext.DomHelper.insertHtml("beforeEnd", this.lb.dom,'<div style="height:17px"></div>');26 }, this)27 lockTree.on('load', function(node) {28 var unode = this.unlockTree.getNodeById(node.id)29 unode.isLoaded = true;30 unode.expand();31 }, this);32 lockTree.on('expand', function(tree, node) {33 this.unlockTree.getNodeById(node.id).expand();34 }, this);35 lockTree.on('collapse', function(tree, node) {36 this.unlockTree.getNodeById(node.id).collapse();37 }, this);38 }39 unlockTree.on('render', this.processData, this);40 if(lockTree){41 unlockTree.on('expand', function(tree, node) {42 this.lockTree.getNodeById(node.id).expand();43 }, this);44 unlockTree.on('collapse', function(tree, node) {45 this.lockTree.getNodeById(node.id).collapse();46 }, this);47 }48 }49});50$A.DynamicTreeGrid.TreeNode = Ext.extend($A.DynamicTree.TreeNode, {51 createNode : function(item) {52 return new $A.DynamicTreeGrid.TreeNode(item);53 },54 createCellEl : function(df) {55 var sf = this,tree = sf.getOwnerTree(),56 tc = tree.column,57 align = tc.align,58 r = sf.record,59 td = sf.els[df + '_td'];60 sf.els[df + '_text'] = Ext.DomHelper.insertHtml("afterBegin", sf.els[df + '_td'], tree.treegrid.createCell(tc, r, false));61 td['dataindex'] = df;62 td['atype'] = 'grid-cell';63 td['recordid'] = r.id;64 if (align)65 td.style.textAlign = align;66 },67 paintText : function() {68 },69 render : function() {70 $A.DynamicTreeGrid.TreeNode.superclass.render.call(this);71 var tree = this.getOwnerTree();72 this.setWidth(tree.displayfield, tree.width);73 }74}); ...

Full Screen

Full Screen

enoughLock.js

Source:enoughLock.js Github

copy

Full Screen

1// Learn cc.Class:2// - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html3// - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html4// Learn Attribute:5// - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html6// - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html7// Learn life-cycle callbacks:8// - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html9// - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html10cc.Class({11 extends: cc.Component,12 properties: {13 unlockInfo : {14 set(value){15 this._unlockInfo = value;16 this.curCoinText.string = '您当前有' + value.curMoney + '片碎片';17 this.costCoinText.string = '是否使用' + value.needCoin + '碎片解锁次关' ;18 this.typeid = value.typeid;19 },20 get(){21 return this._unlockInfo;22 }23 },24 curCoinText :{25 default : null,26 type : cc.Label27 },28 costCoinText :{29 default : null,30 type : cc.Label31 },32 yes_btn : {33 default : null,34 type : cc.Node35 },36 no_btn : {37 default : null,38 type : cc.Node39 },40 indexScript : Object41 },42 // LIFE-CYCLE CALLBACKS:43 onLoad () {44 this.yes_btn.on('click',this.unlock_yes,this);45 },46 unlock_yes(){47 let event = new cc.Event.EventCustom('unlock_yes',true);48 event.detail = {49 curCoinNum : this.unlockInfo.curMoney,50 needCoinNum : this.unlockInfo.needCoin,51 typeid : this.typeid,52 curNode : this.unlockInfo.curClickRankItem53 }54 // 向父节点派送事件55 this.node.dispatchEvent( event ); 56 },57 start () {58 },59 onEnable(){60 this.indexScript.stopButtons();61 },62 onDisable(){63 this.indexScript.activeButtons();64 }65 // update (dt) {},...

Full Screen

Full Screen

boot.js

Source:boot.js Github

copy

Full Screen

1var RocketTux = RocketTux || {};2 3RocketTux.Boot = function(){};4 5// Game configuration6RocketTux.Boot.prototype = {7 preload: function() {8 // Loading screen assets9 this.load.image('logo', 'data/logo.png');10 this.load.image('preloadbar', 'data/loadingbar.png');11 },12 create: function() {13 this.game.stage.backgroundColor = '#000000';14 15 this.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL;16 this.scale.minWidth = 800;17 this.scale.minHeight = 450;18 // Graphics designed for 1280x72019 this.scale.maxWidth = 3840;20 this.scale.maxHeight = 2160;21 this.scale.pageAlignHorizontally = true;22 23 this.game.physics.startSystem(Phaser.Physics.ARCADE);24 25 this.state.start('Preload');26 27 // Hack I copy/pasted from the internet to make sound work again...28 // Author https://github.com/AleBles29 if (this.game.device.android && this.game.device.chrome && this.game.device.chromeVersion >= 55) {30 this.game.sound.touchLocked = true;31 this.game.input.touch.addTouchLockCallback(function () {32 if (this.noAudio || !this.touchLocked || this._unlockSource !== null) {33 return true;34 }35 if (this.usingWebAudio) {36 // Create empty buffer and play it37 // The SoundManager.update loop captures the state of it and then resets touchLocked to false38 var buffer = this.context.createBuffer(1, 1, 22050);39 this._unlockSource = this.context.createBufferSource();40 this._unlockSource.buffer = buffer;41 this._unlockSource.connect(this.context.destination);42 if (this._unlockSource.start === undefined) {43 this._unlockSource.noteOn(0);44 }45 else {46 this._unlockSource.start(0);47 }48 //Hello Chrome 55!49 if (this._unlockSource.context.state === 'suspended') {50 this._unlockSource.context.resume();51 }52 }53 // We can remove the event because we've done what we needed (started the unlock sound playing)54 return true;55 }, this.game.sound, true);56 }57 }...

Full Screen

Full Screen

mutex.js

Source:mutex.js Github

copy

Full Screen

1// @flow2// inspired by https://github.com/plenluno/promise-mutex3export default class Mutex {4 locks: { [string]: true | void };5 constructor() {6 this.locks = {};7 }8 lock<T>(key: string = '~', f: () => Promise<T> | T): Promise<T> {9 const executor = (resolve, reject) => {10 if (!this._lock(key)) {11 setTimeout(() => {12 executor(resolve, reject);13 }, 0);14 return;15 }16 if (!(f instanceof Function)) {17 reject(new Error('argument not function'));18 this._unlock(key);19 return;20 }21 let r;22 try {23 r = f();24 } catch (e) {25 reject(e);26 this._unlock(key);27 return;28 }29 Promise.resolve(r)30 .then(res => {31 resolve(res);32 this._unlock(key);33 })34 .catch(err => {35 reject(err);36 this._unlock(key);37 });38 };39 return new Promise(executor);40 }41 isLocked(key: string = '~'): boolean {42 return !!this.locks[key];43 }44 _lock(key: string): boolean {45 if (!!this.locks[key]) return false;46 return (this.locks[key] = true);47 }48 _unlock(key: string): boolean {49 if (!this.locks[key]) return false;50 delete this.locks[key];51 return true;52 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('Appium Android Driver', function() {2 it('should unlock the device', function() {3 return driver.unlock()4 })5})6describe('Appium Android Driver', function() {7 it('should lock the device', function() {8 return driver.lock()9 })10})11describe('Appium Android Driver', function() {12 it('should return true if the device is locked', function() {13 return driver.isLocked().then(function(isLocked) {14 expect(isLocked).to.be.true15 })16 })17})18describe('Appium Android Driver', function() {19 it('should return true if the device is unlocked', function() {20 return driver.isUnlocked().then(function(isUnlocked) {21 expect(isUnlocked).to.be.true22 })23 })24})25describe('Appium Android Driver', function() {26 it('should press the key code', function() {27 return driver.pressKeyCode(3)28 })29})30describe('Appium Android Driver', function() {31 it('should long press the key code', function() {32 return driver.longPressKeyCode(3)33 })34})35describe('Appium Android Driver', function() {36 it('should hide the keyboard', function() {37 return driver.hideKeyboard()38 })39})40describe('Appium Android Driver', function() {41 it('should toggle data', function() {42 return driver.toggleData()43 })44})45describe('Appium Android Driver', function() {46 it('should toggle airplane mode', function() {47 return driver.toggleAirplaneMode()48 })49})

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('Appium Android Driver', function() {2 it('should unlock the device', function() {3 this.timeout(120000);4 return this.unlock()5 .then(function() {6 console.log('Device unlocked');7 });8 });9});10describe('Appium Android Driver', function() {11 it('should lock the device', function() {12 this.timeout(120000);13 return this.lock()14 .then(function() {15 console.log('Device locked');16 });17 });18});19describe('Appium Android Driver', function() {20 it('should check if device is locked', function() {21 this.timeout(120000);22 return this.isLocked()23 .then(function(isLocked) {24 console.log('Device is locked: ' + isLocked);25 });26 });27});28describe('Appium Android Driver', function() {29 it('should put app in background', function() {30 this.timeout(120000);31 return this.backgroundApp(5)32 .then(function() {33 console.log('App in background for 5 seconds');34 });35 });36});37describe('Appium Android Driver', function() {38 it('should hide keyboard', function() {39 this.timeout(120000);40 return this.hideKeyboard()41 .then(function() {42 console.log('Keyboard hidden');43 });44 });45});46describe('Appium Android Driver', function() {47 it('should press key code', function() {48 this.timeout(120000);49 return this.pressKeyCode(3)50 .then(function() {51 console.log('Key code 3 pressed');52 });53 });54});55describe('Appium Android Driver', function() {56 it('should long press key code', function() {57 this.timeout(120000);58 return this.longPressKeyCode(3)59 .then(function() {60 console.log('Key code 3 long pressed');61 });62 });63});64describe('App

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('test', function() {2 it('test', function(done) {3 driver.unlock().then(function() {4 done();5 });6 });7});8info: [debug] [AndroidBootstrap] Sending command to android: {"cmd":"shutdown"}9info: [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"shutdown"}10info: [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"value":"OK, shutting down","status":0}

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var assert = require('assert');3var serverConfig = {4};5var desired = {6};7var driver = wd.promiseChainRemote(serverConfig);8driver.init(desired).then(function () {9 return driver.unlock();10}).then(function () {11 return driver.quit();12}).done();13info: [debug] [ADB] 1 device(s) connected

Full Screen

Using AI Code Generation

copy

Full Screen

1try {2 await driver.unlock();3} catch (e) {4 console.log(e);5}6async unlock () {7 return await this.adb.unlock();8}9async unlock () {10 return await this.adb.unlock();11}12async unlock () {13 return await this.adb.unlock();14}

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Appium Android Driver automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful