From b45acf9411e9fadbf6789850dffcea2ac4b1bd11 Mon Sep 17 00:00:00 2001 From: gliechtenstein Date: Thu, 13 Jul 2017 20:19:53 -0400 Subject: [PATCH] New Release (#140) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Allow html container video autoplay + gradle upgrade + api min version upgrade to 17 * Support html video inline play for background html container * Correct data-uri handling for images * Fix $geo.get -> Should be only triggered once * readme update * Replace useless “Error” messages with more informative warning messages * Fix Map component event handling for render * Fixes OAuth action doubling up on some query params * Add “title” attribute to $util.picker * Support JSONArray when reading JSON * Local Mixin + Local $require * Local Image Support + Menu Image fix + Gif fix 1. Local image support - Image/Button component - background - layer - menu - tabs 2. fixed the bug where an image menu item was not being displayed when there's a badge. 3. Gif fix Glide doesn't handle Gifs properly when not using disk cache strategy. With this fix, Gif images load properly * $audio.play should trigger pause if already playing * Add $back action * $global.set + $global.reset * $env * Added $env.device.language * Template engine fix. See iOS counterpart: https://github.com/Jasonette/JASONETTE-iOS/pull/224 * support data-url scheme for images (only normal cases) * Support loading.json * Support loading.json (continued) * Support $env.view.url * background color fix * offline.json support * Bug fix * Updated policy for $show and $load * Only trigger if an action is not empty * Fix #104: Crop background When you put a background image to your view, it is streched to fit screen dimensions. With this patch, image is cropped to keep the aspect ratio. Moreover, this patch fix GIF background and it is now played. * Fix #127 Background image is no more displayed Background of sectionLayout should always be transparent. * Add .idea/codeStyleSettings.xml in .gitignore * Handle behavior when layers is null * Check that backgroundImageView is not created This patch avoids multiple ImageView creation (like fof webview) --- .gitignore | 1 + README.md | 20 +- app/build.gradle | 2 +- app/src/main/assets/file/error.json | 32 ++ app/src/main/assets/file/infinit.gif | Bin 0 -> 32654 bytes app/src/main/assets/file/jasonpedia.json | 115 ---- app/src/main/assets/file/loading.json | 28 + app/src/main/assets/parser | 511 ++++++++---------- .../seed/Action/JasonAudioAction.java | 43 +- .../seed/Action/JasonCacheAction.java | 4 +- .../seed/Action/JasonConvertAction.java | 4 +- .../jasonette/seed/Action/JasonGeoAction.java | 9 +- .../seed/Action/JasonGlobalAction.java | 103 ++++ .../jasonette/seed/Action/JasonLogAction.java | 2 +- .../seed/Action/JasonMediaAction.java | 23 +- .../seed/Action/JasonNetworkAction.java | 18 +- .../seed/Action/JasonOauthAction.java | 20 +- .../seed/Action/JasonReturnAction.java | 4 +- .../seed/Action/JasonSessionAction.java | 4 +- .../seed/Action/JasonTimerAction.java | 4 +- .../seed/Action/JasonUtilAction.java | 30 +- .../seed/Component/JasonButtonComponent.java | 2 +- .../seed/Component/JasonComponent.java | 4 +- .../seed/Component/JasonComponentFactory.java | 2 +- .../seed/Component/JasonHtmlComponent.java | 7 +- .../seed/Component/JasonImageComponent.java | 309 +++++++---- .../seed/Component/JasonLabelComponent.java | 2 +- .../seed/Component/JasonMapComponent.java | 62 ++- .../seed/Component/JasonSliderComponent.java | 4 +- .../seed/Component/JasonSpaceComponent.java | 2 +- .../Component/JasonTextareaComponent.java | 2 +- .../Component/JasonTextfieldComponent.java | 2 +- .../com/jasonette/seed/Core/JasonModel.java | 75 +-- .../com/jasonette/seed/Core/JasonParser.java | 6 +- .../com/jasonette/seed/Core/JasonRequire.java | 25 +- .../seed/Core/JasonViewActivity.java | 403 ++++++++------ .../jasonette/seed/Helper/JasonHelper.java | 36 +- .../seed/Helper/JasonImageHelper.java | 6 +- .../com/jasonette/seed/Launcher/Launcher.java | 89 ++- .../jasonette/seed/Section/ItemAdapter.java | 3 +- build.gradle | 2 +- 41 files changed, 1149 insertions(+), 871 deletions(-) create mode 100644 app/src/main/assets/file/error.json create mode 100644 app/src/main/assets/file/infinit.gif delete mode 100644 app/src/main/assets/file/jasonpedia.json create mode 100644 app/src/main/assets/file/loading.json create mode 100644 app/src/main/java/com/jasonette/seed/Action/JasonGlobalAction.java diff --git a/.gitignore b/.gitignore index e6587e33..2c7e135c 100644 --- a/.gitignore +++ b/.gitignore @@ -23,6 +23,7 @@ local.properties .idea/modules.xml .idea/scopes/scope_settings.xml .idea/vcs.xml +.idea/codeStyleSettings.xml *.iml # OS-specific files diff --git a/README.md b/README.md index 88a84501..84659761 100644 --- a/README.md +++ b/README.md @@ -13,23 +13,23 @@ Looking for an iOS version? [See here](https://www.github.com/Jasonette/JASONETT
-##★ Jasonette fetches this JSON markup from a server: +## ★ Jasonette fetches this JSON markup from a server: ![json](https://raw.githubusercontent.com/gliechtenstein/images/master/json.png) -##★ And self-constructs into the following native app, in realtime: +## ★ And self-constructs into the following native app, in realtime: ![instagram](https://github.com/Jasonette/Instagram-UI-example/blob/master/images/instagram-android.gif)
-#How it works +# How it works ![diagram](https://raw.githubusercontent.com/gliechtenstein/images/master/diagram.gif)
-#Cool things about Jasonette +# Cool things about Jasonette - **100% NATIVE**: Jasonette maps JSON into native components and native function calls. There is no gimmick. There is no magic. - **App loads over HTTP**: Your app exists 100% as JSON, and loads from the cloud. No more hard-coding. @@ -57,7 +57,7 @@ Try playing these on Jasonette and watch them turn into native apps in front of # Technical Highlights -##1. One JSON to rule them all +## 1. One JSON to rule them all Jasonette simplifies the entire app building process down to nothing more than: @@ -75,24 +75,24 @@ This is possible because Jasonette came up with a way to **fit an entire app wor
-##2. App-over-HTTP +## 2. App-over-HTTP Until now, the only thing JSON could send over the Internet was raw data. Normally apps would fetch remote data from the server for a connected experience, but the actual app logic would be hard-coded on the client side. This makes it hard to update and extend apps. But what happens when you can express an entire app logic as JSON? -**Then apps can be stored, processed, shared, and sent over the Internet just like any other JSON.** Watch below where we update the JSON on a [JSON pastebin server](https://www.jasonbase.com), and the app changes immediately to reflect the new markup: +** Then apps can be stored, processed, shared, and sent over the Internet just like any other JSON.** Watch below where we update the JSON on a [JSON pastebin server](https://www.jasonbase.com), and the app changes immediately to reflect the new markup: ![remote control](http://i.giphy.com/3o7TKrdmlX5uD7RszK.gif)
-##3. Designed to be extended or integrated +## 3. Designed to be extended or integrated Currently Jasonette covers all the essential native APIs and components, which means you can build pretty much any app you can imagine. But Jasonette is very flexible. -###A. Extensible +### A. Extensible If you don't see a feature you want, you can simply extend Jasonette. Just follow the convention. Want to learn more? [Ask here](https://github.com/gliechtenstein/jasonette-android#questions-and-support) -###B. Integrate existing code +### B. Integrate existing code Since Jasonette is simply a Java project, You can even integrate Jasonette with your existing Android project if you want. This way you can use Jasonette for just a small part of your app without having to completely switch to a new way of programming. Want to learn more? [Ask here](https://github.com/gliechtenstein/jasonette-android#questions-and-support)
diff --git a/app/build.gradle b/app/build.gradle index 5710876a..bc398f03 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -5,7 +5,7 @@ android { buildToolsVersion '25.0.0' defaultConfig { applicationId "com.jasonette" - minSdkVersion 16 + minSdkVersion 17 targetSdkVersion 22 versionCode 3 versionName "0.1.0" diff --git a/app/src/main/assets/file/error.json b/app/src/main/assets/file/error.json new file mode 100644 index 00000000..06597456 --- /dev/null +++ b/app/src/main/assets/file/error.json @@ -0,0 +1,32 @@ +{ + "$jason": { + "head": { + "title": "Error Loading Screen" + }, + "body": { + "layers": [ + { + "type": "label", + "text": "Offline", + "style": { + "top": "50%-80", + "align": "center", + "font": "AvenirNext-Regular", + "size": "20", + "left": "50%-50", + "width": "100" + } + }, + { + "type": "image", + "url": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAAGDUlEQVR4Xu2d7ZUNQRCGayNABIgAESACRIAIEIHdCBABGwEiQASIgI3AioDzrjtOnz41019V1dU7PX/23DvTX/VMdVdX1e09onm5ksCRq97MztAE4uwlmEAmEGcScNadqSETiIoErh5qPVep3bDSy6AhT4jo7UFmT4nonaH8xJsaHcgNIvoRSeUmEf0Ul5RRhaMDeU9EDyNZfSCiR0byE29mZCD3iOjTikTuE9FncWkZVDgyEExVmLK46xsR3TGQn3gTowJ5TkSvEtJ4QUSvxSWmXOGIQGDiQjsWUxciOj3I6XEgL5jAWOCHMoVHBIK3/lkg+N9EdPvwGVPVleDeGyKCNg1zjQaEM3NPiOj4IHH8fTmyGTwaEFhVsK6W6yxa2DG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AoJIrA5P+8Et/Iw6/I17C/DcsmIZNbVANMOyuULAc3g748OUoaGWWrqYwSJnPdYA6Z7dV0LM8FkRuZQCsQjLGspQvKnmrMdSIGJzpbgofFTYvLaWANHKPvQhSrlecGZw9iE3JUC0sg/lROGjpqasx1wgmtmHtWLEwPEbQ+7Cbwy1f1a91e9qD0YuEC9mbu5O3dJ9swamKusxB4iKV7NWLaJya85FD0CqvOApIJy/quXsQyEO/6vxDASdjM3g5CE3KSAW2YctkLwDKY6kbgFRjR23UAjKegeCrhblGmwBsco+bGGz/COXuI6171vaqi1blPW4BqRqQart8Q7KZRtGa0Assw93wONiiFlnPXJATHJY90IhGGfW5joG0iP7cE9sklmPMZAii2BPkhQaa9JyDYEU28xCndxbNZt7uxBIr+zDvQHZPORmAcKFH93+j41LQHDVDF6A9Mw+vATyrRoCG+4FEG5Oq2phFmqWwAmAcAdJNtc8K6iSwDmArDnoqmqchZokcAYgWGCw/4gzAJtqnoWLJYDzho9T8ZDiWmeBNglMIG3yEy89gYiLtK3CCaRNfuKlJxBxkbZVOIG0yU+89F/0oJEjHJ/peAAAAABJRU5ErkJggg==", + "style": { + "width": "100", + "top": "50%-50", + "left": "50%-50" + } + } + ] + } + } +} diff --git a/app/src/main/assets/file/infinit.gif b/app/src/main/assets/file/infinit.gif new file mode 100644 index 0000000000000000000000000000000000000000..25b230c19e3a6709e1e88cce0c90bd576d482d50 GIT binary patch literal 32654 zcmeIbcUaT;p8lOq5{jW0fmG=wAW9KENoWDl3CIY83IPE@Q2|kcfTU1D56B2AB_Jwd z14O|(p$E$hIL?R-0v15g2^LgT^7|&}oN>=QyL;`*p|42!NdB- zo1444yOWc5rlqCl!kP;gE)EXfx_kF- zWo6ZmKmK^+NCTVAUB5oU-#=jI&eXWLgfnMaZ{NPNZCm2?>pzEtFi)H~Sz7x2z`%f~ zC!N9YU%8S|T)aCdD0uDK5Fa1kq9VbTEpb<`Ud_)h2o7F5G&J1P(-RdH&EsWcWMopQ zZb?bWB9UnI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O0!Z2Lkj|HPf0(b( z;L>YOb7yr0Vn!e)pAN0?=->Z;=Fkek#|anw>v5-F;<(fQ)$ke3`j|BKXAK~`x4r6f ze$;^8L$Zdx3^mo%mYB#m+ZqydzvXaKQ+>g!3mr26=LJ}PjG!NIj35;_Mlipym94KhMoGt3HU42oAGPhRWcB(neTh$_AbS#rtYef;20#_5jfRU zsYAYU2vF%zznn@1lh$mc_TCvK9>T9^tffDl-&ULEK!QL9w*u|xi?QGMQSXiV2Il In this case instead of rendering "null", should just skip it completely + // Todo : Distinguish between #if arrays and ordinary arrays, and return null for ordinary arrays result.push(item); } } @@ -22571,14 +22572,18 @@ var run = function(template, data){ } } // end of #each } else { // end of if(fun) - // This shouldn't happen since the only supported functions are #each and #include currently. - // But need to return the original template for debugging - result = template; + // If the key is a template expression but aren't either #include or #each, + // it needs to be parsed + var k = getData(data, key); + var v = getData(data, template[key]); + if(k !== undefined && v !== undefined){ + result[k] = v; + } } } else { // isTemplate(key) was false, which means the key was not a template (hardcoded string) var item = run(template[key], data); - if(item){ + if(item !== undefined){ result[key] = item; } } @@ -22694,7 +22699,7 @@ function isObject(obj) { } var include = function(template, data){ - return manipulator(template).select(function(key, value){ + return jason(template).select(function(key, value){ return /#include/.test(key) || /#include/.test(value); }).parse(data).root(); }; @@ -22703,23 +22708,23 @@ var include = function(template, data){ /****************************************************************************************************************** * # USAGE * -* manipulator(template).select(function(key, value){ +* jason(template).select(function(key, value){ * return key=='type' && value=='label'; // return all the objects with "type": "label" * }).object(); * -* manipulator(template).select(function(key, value){ +* jason(template).select(function(key, value){ * return /class/.test(key); // return all objects that contains the key 'class' * }).object(); * -* manipulator(template).select(function(key, value){ +* jason(template).select(function(key, value){ * return /\{\{#include\}\}/.test(key); // return all objects that contains the key '{{#include}}' * }).objects(); * -* manipulator(template).select(function(key, value){ +* jason(template).select(function(key, value){ * return /\{\{#include\}\}/.test(key); // selects the object, and then returns the value of the selected object * }).values(); * -* manipulator(template).select(function(key, value){ +* jason(template).select(function(key, value){ * return /\{\{#include\}\}/.test(key); // return all objects that contains the key '{{#include}}' * }).keys(); * @@ -22739,7 +22744,7 @@ var resolve = function(o, path, new_val){ } } -var manipulator = function(template){ +var jason = function(template){ var tpl = template; // current: currently accessed object @@ -22798,7 +22803,7 @@ var manipulator = function(template){ }, parse: function(data){ - // manipulator(template).select("{{#include}}").parse(data).values(); + // jason(template).select("{{#include}}").parse(data).values(); o.$parsed = []; @@ -22892,7 +22897,7 @@ module.exports = { run: json, resolve: resolve, include: include, - manipulator: manipulator + jason: jason }; },{"cheerio":1}],68:[function(require,module,exports){ @@ -23126,7 +23131,6 @@ exports.allocUnsafeSlow = function allocUnsafeSlow(size) { }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) },{"buffer":71}],71:[function(require,module,exports){ -(function (global){ /*! * The buffer module from node.js, for the browser. * @@ -23139,80 +23143,57 @@ exports.allocUnsafeSlow = function allocUnsafeSlow(size) { var base64 = require('base64-js') var ieee754 = require('ieee754') -var isArray = require('isarray') exports.Buffer = Buffer exports.SlowBuffer = SlowBuffer exports.INSPECT_MAX_BYTES = 50 +var K_MAX_LENGTH = 0x7fffffff +exports.kMaxLength = K_MAX_LENGTH + /** * If `Buffer.TYPED_ARRAY_SUPPORT`: * === true Use Uint8Array implementation (fastest) - * === false Use Object implementation (most compatible, even IE6) + * === false Print warning and recommend using `buffer` v4.x which has an Object + * implementation (most compatible, even IE6) * * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+, * Opera 11.6+, iOS 4.2+. * - * Due to various browser bugs, sometimes the Object implementation will be used even - * when the browser supports typed arrays. - * - * Note: - * - * - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances, - * See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438. - * - * - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function. - * - * - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of - * incorrect length in some situations. - - * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they - * get the Object implementation, which is slower but behaves correctly. + * We report that the browser does not support typed arrays if the are not subclassable + * using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array` + * (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support + * for __proto__ and has a buggy typed array implementation. */ -Buffer.TYPED_ARRAY_SUPPORT = global.TYPED_ARRAY_SUPPORT !== undefined - ? global.TYPED_ARRAY_SUPPORT - : typedArraySupport() +Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport() -/* - * Export kMaxLength after typed array support is determined. - */ -exports.kMaxLength = kMaxLength() +if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' && + typeof console.error === 'function') { + console.error( + 'This browser lacks typed array (Uint8Array) support which is required by ' + + '`buffer` v5.x. Use `buffer` v4.x if you require old browser support.' + ) +} function typedArraySupport () { + // Can typed array instances can be augmented? try { var arr = new Uint8Array(1) arr.__proto__ = {__proto__: Uint8Array.prototype, foo: function () { return 42 }} - return arr.foo() === 42 && // typed array instances can be augmented - typeof arr.subarray === 'function' && // chrome 9-10 lack `subarray` - arr.subarray(1, 1).byteLength === 0 // ie10 has broken `subarray` + return arr.foo() === 42 } catch (e) { return false } } -function kMaxLength () { - return Buffer.TYPED_ARRAY_SUPPORT - ? 0x7fffffff - : 0x3fffffff -} - -function createBuffer (that, length) { - if (kMaxLength() < length) { +function createBuffer (length) { + if (length > K_MAX_LENGTH) { throw new RangeError('Invalid typed array length') } - if (Buffer.TYPED_ARRAY_SUPPORT) { - // Return an augmented `Uint8Array` instance, for best performance - that = new Uint8Array(length) - that.__proto__ = Buffer.prototype - } else { - // Fallback: Return an object instance of the Buffer class - if (that === null) { - that = new Buffer(length) - } - that.length = length - } - - return that + // Return an augmented `Uint8Array` instance + var buf = new Uint8Array(length) + buf.__proto__ = Buffer.prototype + return buf } /** @@ -23226,10 +23207,6 @@ function createBuffer (that, length) { */ function Buffer (arg, encodingOrOffset, length) { - if (!Buffer.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer)) { - return new Buffer(arg, encodingOrOffset, length) - } - // Common case. if (typeof arg === 'number') { if (typeof encodingOrOffset === 'string') { @@ -23237,33 +23214,38 @@ function Buffer (arg, encodingOrOffset, length) { 'If encoding is specified then the first argument must be a string' ) } - return allocUnsafe(this, arg) + return allocUnsafe(arg) } - return from(this, arg, encodingOrOffset, length) + return from(arg, encodingOrOffset, length) } -Buffer.poolSize = 8192 // not used by this implementation - -// TODO: Legacy, not needed anymore. Remove in next major version. -Buffer._augment = function (arr) { - arr.__proto__ = Buffer.prototype - return arr +// Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97 +if (typeof Symbol !== 'undefined' && Symbol.species && + Buffer[Symbol.species] === Buffer) { + Object.defineProperty(Buffer, Symbol.species, { + value: null, + configurable: true, + enumerable: false, + writable: false + }) } -function from (that, value, encodingOrOffset, length) { +Buffer.poolSize = 8192 // not used by this implementation + +function from (value, encodingOrOffset, length) { if (typeof value === 'number') { throw new TypeError('"value" argument must not be a number') } - if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) { - return fromArrayBuffer(that, value, encodingOrOffset, length) + if (value instanceof ArrayBuffer) { + return fromArrayBuffer(value, encodingOrOffset, length) } if (typeof value === 'string') { - return fromString(that, value, encodingOrOffset) + return fromString(value, encodingOrOffset) } - return fromObject(that, value) + return fromObject(value) } /** @@ -23275,21 +23257,13 @@ function from (that, value, encodingOrOffset, length) { * Buffer.from(arrayBuffer[, byteOffset[, length]]) **/ Buffer.from = function (value, encodingOrOffset, length) { - return from(null, value, encodingOrOffset, length) + return from(value, encodingOrOffset, length) } -if (Buffer.TYPED_ARRAY_SUPPORT) { - Buffer.prototype.__proto__ = Uint8Array.prototype - Buffer.__proto__ = Uint8Array - if (typeof Symbol !== 'undefined' && Symbol.species && - Buffer[Symbol.species] === Buffer) { - // Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97 - Object.defineProperty(Buffer, Symbol.species, { - value: null, - configurable: true - }) - } -} +// Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug: +// https://github.com/feross/buffer/pull/148 +Buffer.prototype.__proto__ = Uint8Array.prototype +Buffer.__proto__ = Uint8Array function assertSize (size) { if (typeof size !== 'number') { @@ -23299,20 +23273,20 @@ function assertSize (size) { } } -function alloc (that, size, fill, encoding) { +function alloc (size, fill, encoding) { assertSize(size) if (size <= 0) { - return createBuffer(that, size) + return createBuffer(size) } if (fill !== undefined) { // Only pay attention to encoding if it's a string. This // prevents accidentally sending in a number that would // be interpretted as a start offset. return typeof encoding === 'string' - ? createBuffer(that, size).fill(fill, encoding) - : createBuffer(that, size).fill(fill) + ? createBuffer(size).fill(fill, encoding) + : createBuffer(size).fill(fill) } - return createBuffer(that, size) + return createBuffer(size) } /** @@ -23320,34 +23294,28 @@ function alloc (that, size, fill, encoding) { * alloc(size[, fill[, encoding]]) **/ Buffer.alloc = function (size, fill, encoding) { - return alloc(null, size, fill, encoding) + return alloc(size, fill, encoding) } -function allocUnsafe (that, size) { +function allocUnsafe (size) { assertSize(size) - that = createBuffer(that, size < 0 ? 0 : checked(size) | 0) - if (!Buffer.TYPED_ARRAY_SUPPORT) { - for (var i = 0; i < size; ++i) { - that[i] = 0 - } - } - return that + return createBuffer(size < 0 ? 0 : checked(size) | 0) } /** * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance. * */ Buffer.allocUnsafe = function (size) { - return allocUnsafe(null, size) + return allocUnsafe(size) } /** * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. */ Buffer.allocUnsafeSlow = function (size) { - return allocUnsafe(null, size) + return allocUnsafe(size) } -function fromString (that, string, encoding) { +function fromString (string, encoding) { if (typeof encoding !== 'string' || encoding === '') { encoding = 'utf8' } @@ -23357,32 +23325,30 @@ function fromString (that, string, encoding) { } var length = byteLength(string, encoding) | 0 - that = createBuffer(that, length) + var buf = createBuffer(length) - var actual = that.write(string, encoding) + var actual = buf.write(string, encoding) if (actual !== length) { // Writing a hex string, for example, that contains invalid characters will // cause everything after the first invalid character to be ignored. (e.g. // 'abxxcd' will be treated as 'ab') - that = that.slice(0, actual) + buf = buf.slice(0, actual) } - return that + return buf } -function fromArrayLike (that, array) { +function fromArrayLike (array) { var length = array.length < 0 ? 0 : checked(array.length) | 0 - that = createBuffer(that, length) + var buf = createBuffer(length) for (var i = 0; i < length; i += 1) { - that[i] = array[i] & 255 + buf[i] = array[i] & 255 } - return that + return buf } -function fromArrayBuffer (that, array, byteOffset, length) { - array.byteLength // this throws if `array` is not a valid ArrayBuffer - +function fromArrayBuffer (array, byteOffset, length) { if (byteOffset < 0 || array.byteLength < byteOffset) { throw new RangeError('\'offset\' is out of bounds') } @@ -23391,49 +23357,43 @@ function fromArrayBuffer (that, array, byteOffset, length) { throw new RangeError('\'length\' is out of bounds') } + var buf if (byteOffset === undefined && length === undefined) { - array = new Uint8Array(array) + buf = new Uint8Array(array) } else if (length === undefined) { - array = new Uint8Array(array, byteOffset) + buf = new Uint8Array(array, byteOffset) } else { - array = new Uint8Array(array, byteOffset, length) + buf = new Uint8Array(array, byteOffset, length) } - if (Buffer.TYPED_ARRAY_SUPPORT) { - // Return an augmented `Uint8Array` instance, for best performance - that = array - that.__proto__ = Buffer.prototype - } else { - // Fallback: Return an object instance of the Buffer class - that = fromArrayLike(that, array) - } - return that + // Return an augmented `Uint8Array` instance + buf.__proto__ = Buffer.prototype + return buf } -function fromObject (that, obj) { +function fromObject (obj) { if (Buffer.isBuffer(obj)) { var len = checked(obj.length) | 0 - that = createBuffer(that, len) + var buf = createBuffer(len) - if (that.length === 0) { - return that + if (buf.length === 0) { + return buf } - obj.copy(that, 0, 0, len) - return that + obj.copy(buf, 0, 0, len) + return buf } if (obj) { - if ((typeof ArrayBuffer !== 'undefined' && - obj.buffer instanceof ArrayBuffer) || 'length' in obj) { + if (ArrayBuffer.isView(obj) || 'length' in obj) { if (typeof obj.length !== 'number' || isnan(obj.length)) { - return createBuffer(that, 0) + return createBuffer(0) } - return fromArrayLike(that, obj) + return fromArrayLike(obj) } - if (obj.type === 'Buffer' && isArray(obj.data)) { - return fromArrayLike(that, obj.data) + if (obj.type === 'Buffer' && Array.isArray(obj.data)) { + return fromArrayLike(obj.data) } } @@ -23441,11 +23401,11 @@ function fromObject (that, obj) { } function checked (length) { - // Note: cannot use `length < kMaxLength()` here because that fails when + // Note: cannot use `length < K_MAX_LENGTH` here because that fails when // length is NaN (which is otherwise coerced to zero.) - if (length >= kMaxLength()) { + if (length >= K_MAX_LENGTH) { throw new RangeError('Attempt to allocate Buffer larger than maximum ' + - 'size: 0x' + kMaxLength().toString(16) + ' bytes') + 'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes') } return length | 0 } @@ -23458,7 +23418,7 @@ function SlowBuffer (length) { } Buffer.isBuffer = function isBuffer (b) { - return !!(b != null && b._isBuffer) + return b != null && b._isBuffer === true } Buffer.compare = function compare (a, b) { @@ -23504,7 +23464,7 @@ Buffer.isEncoding = function isEncoding (encoding) { } Buffer.concat = function concat (list, length) { - if (!isArray(list)) { + if (!Array.isArray(list)) { throw new TypeError('"list" argument must be an Array of Buffers') } @@ -23537,8 +23497,7 @@ function byteLength (string, encoding) { if (Buffer.isBuffer(string)) { return string.length } - if (typeof ArrayBuffer !== 'undefined' && typeof ArrayBuffer.isView === 'function' && - (ArrayBuffer.isView(string) || string instanceof ArrayBuffer)) { + if (ArrayBuffer.isView(string) || string instanceof ArrayBuffer) { return string.byteLength } if (typeof string !== 'string') { @@ -23648,8 +23607,12 @@ function slowToString (encoding, start, end) { } } -// The property is used by `Buffer.isBuffer` and `is-buffer` (in Safari 5-7) to detect -// Buffer instances. +// This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package) +// to detect a Buffer instance. It's not possible to use `instanceof Buffer` +// reliably in a browserify context because there could be multiple different +// copies of the 'buffer' package in use. This method works even for Buffer +// instances that were created from another copy of the `buffer` package. +// See: https://github.com/feross/buffer/issues/154 Buffer.prototype._isBuffer = true function swap (b, n, m) { @@ -23696,7 +23659,7 @@ Buffer.prototype.swap64 = function swap64 () { } Buffer.prototype.toString = function toString () { - var length = this.length | 0 + var length = this.length if (length === 0) return '' if (arguments.length === 0) return utf8Slice(this, 0, length) return slowToString.apply(this, arguments) @@ -23829,8 +23792,7 @@ function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) { return arrayIndexOf(buffer, val, byteOffset, encoding, dir) } else if (typeof val === 'number') { val = val & 0xFF // Search for a byte value [0-255] - if (Buffer.TYPED_ARRAY_SUPPORT && - typeof Uint8Array.prototype.indexOf === 'function') { + if (typeof Uint8Array.prototype.indexOf === 'function') { if (dir) { return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset) } else { @@ -23971,15 +23933,14 @@ Buffer.prototype.write = function write (string, offset, length, encoding) { offset = 0 // Buffer#write(string, offset[, length][, encoding]) } else if (isFinite(offset)) { - offset = offset | 0 + offset = offset >>> 0 if (isFinite(length)) { - length = length | 0 + length = length >>> 0 if (encoding === undefined) encoding = 'utf8' } else { encoding = length length = undefined } - // legacy write(string, encoding, offset, length) - remove in v0.13 } else { throw new Error( 'Buffer.write(string, encoding, offset[, length]) is no longer supported' @@ -24178,7 +24139,7 @@ function utf16leSlice (buf, start, end) { var bytes = buf.slice(start, end) var res = '' for (var i = 0; i < bytes.length; i += 2) { - res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256) + res += String.fromCharCode(bytes[i] + (bytes[i + 1] * 256)) } return res } @@ -24204,18 +24165,9 @@ Buffer.prototype.slice = function slice (start, end) { if (end < start) end = start - var newBuf - if (Buffer.TYPED_ARRAY_SUPPORT) { - newBuf = this.subarray(start, end) - newBuf.__proto__ = Buffer.prototype - } else { - var sliceLen = end - start - newBuf = new Buffer(sliceLen, undefined) - for (var i = 0; i < sliceLen; ++i) { - newBuf[i] = this[i + start] - } - } - + var newBuf = this.subarray(start, end) + // Return an augmented `Uint8Array` instance + newBuf.__proto__ = Buffer.prototype return newBuf } @@ -24228,8 +24180,8 @@ function checkOffset (offset, ext, length) { } Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) { - offset = offset | 0 - byteLength = byteLength | 0 + offset = offset >>> 0 + byteLength = byteLength >>> 0 if (!noAssert) checkOffset(offset, byteLength, this.length) var val = this[offset] @@ -24243,8 +24195,8 @@ Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) } Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) { - offset = offset | 0 - byteLength = byteLength | 0 + offset = offset >>> 0 + byteLength = byteLength >>> 0 if (!noAssert) { checkOffset(offset, byteLength, this.length) } @@ -24259,21 +24211,25 @@ Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) } Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) { + offset = offset >>> 0 if (!noAssert) checkOffset(offset, 1, this.length) return this[offset] } Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) { + offset = offset >>> 0 if (!noAssert) checkOffset(offset, 2, this.length) return this[offset] | (this[offset + 1] << 8) } Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) { + offset = offset >>> 0 if (!noAssert) checkOffset(offset, 2, this.length) return (this[offset] << 8) | this[offset + 1] } Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) { + offset = offset >>> 0 if (!noAssert) checkOffset(offset, 4, this.length) return ((this[offset]) | @@ -24283,6 +24239,7 @@ Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) { } Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) { + offset = offset >>> 0 if (!noAssert) checkOffset(offset, 4, this.length) return (this[offset] * 0x1000000) + @@ -24292,8 +24249,8 @@ Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) { } Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) { - offset = offset | 0 - byteLength = byteLength | 0 + offset = offset >>> 0 + byteLength = byteLength >>> 0 if (!noAssert) checkOffset(offset, byteLength, this.length) var val = this[offset] @@ -24310,8 +24267,8 @@ Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) { } Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) { - offset = offset | 0 - byteLength = byteLength | 0 + offset = offset >>> 0 + byteLength = byteLength >>> 0 if (!noAssert) checkOffset(offset, byteLength, this.length) var i = byteLength @@ -24328,24 +24285,28 @@ Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) { } Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) { + offset = offset >>> 0 if (!noAssert) checkOffset(offset, 1, this.length) if (!(this[offset] & 0x80)) return (this[offset]) return ((0xff - this[offset] + 1) * -1) } Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) { + offset = offset >>> 0 if (!noAssert) checkOffset(offset, 2, this.length) var val = this[offset] | (this[offset + 1] << 8) return (val & 0x8000) ? val | 0xFFFF0000 : val } Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) { + offset = offset >>> 0 if (!noAssert) checkOffset(offset, 2, this.length) var val = this[offset + 1] | (this[offset] << 8) return (val & 0x8000) ? val | 0xFFFF0000 : val } Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) { + offset = offset >>> 0 if (!noAssert) checkOffset(offset, 4, this.length) return (this[offset]) | @@ -24355,6 +24316,7 @@ Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) { } Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) { + offset = offset >>> 0 if (!noAssert) checkOffset(offset, 4, this.length) return (this[offset] << 24) | @@ -24364,21 +24326,25 @@ Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) { } Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) { + offset = offset >>> 0 if (!noAssert) checkOffset(offset, 4, this.length) return ieee754.read(this, offset, true, 23, 4) } Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) { + offset = offset >>> 0 if (!noAssert) checkOffset(offset, 4, this.length) return ieee754.read(this, offset, false, 23, 4) } Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) { + offset = offset >>> 0 if (!noAssert) checkOffset(offset, 8, this.length) return ieee754.read(this, offset, true, 52, 8) } Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) { + offset = offset >>> 0 if (!noAssert) checkOffset(offset, 8, this.length) return ieee754.read(this, offset, false, 52, 8) } @@ -24391,8 +24357,8 @@ function checkInt (buf, value, offset, ext, max, min) { Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) { value = +value - offset = offset | 0 - byteLength = byteLength | 0 + offset = offset >>> 0 + byteLength = byteLength >>> 0 if (!noAssert) { var maxBytes = Math.pow(2, 8 * byteLength) - 1 checkInt(this, value, offset, byteLength, maxBytes, 0) @@ -24410,8 +24376,8 @@ Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) { value = +value - offset = offset | 0 - byteLength = byteLength | 0 + offset = offset >>> 0 + byteLength = byteLength >>> 0 if (!noAssert) { var maxBytes = Math.pow(2, 8 * byteLength) - 1 checkInt(this, value, offset, byteLength, maxBytes, 0) @@ -24429,89 +24395,57 @@ Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) { value = +value - offset = offset | 0 + offset = offset >>> 0 if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0) - if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value) this[offset] = (value & 0xff) return offset + 1 } -function objectWriteUInt16 (buf, value, offset, littleEndian) { - if (value < 0) value = 0xffff + value + 1 - for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; ++i) { - buf[offset + i] = (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>> - (littleEndian ? i : 1 - i) * 8 - } -} - Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) { value = +value - offset = offset | 0 + offset = offset >>> 0 if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0) - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = (value & 0xff) - this[offset + 1] = (value >>> 8) - } else { - objectWriteUInt16(this, value, offset, true) - } + this[offset] = (value & 0xff) + this[offset + 1] = (value >>> 8) return offset + 2 } Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) { value = +value - offset = offset | 0 + offset = offset >>> 0 if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0) - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = (value >>> 8) - this[offset + 1] = (value & 0xff) - } else { - objectWriteUInt16(this, value, offset, false) - } + this[offset] = (value >>> 8) + this[offset + 1] = (value & 0xff) return offset + 2 } -function objectWriteUInt32 (buf, value, offset, littleEndian) { - if (value < 0) value = 0xffffffff + value + 1 - for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; ++i) { - buf[offset + i] = (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff - } -} - Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) { value = +value - offset = offset | 0 + offset = offset >>> 0 if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0) - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset + 3] = (value >>> 24) - this[offset + 2] = (value >>> 16) - this[offset + 1] = (value >>> 8) - this[offset] = (value & 0xff) - } else { - objectWriteUInt32(this, value, offset, true) - } + this[offset + 3] = (value >>> 24) + this[offset + 2] = (value >>> 16) + this[offset + 1] = (value >>> 8) + this[offset] = (value & 0xff) return offset + 4 } Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) { value = +value - offset = offset | 0 + offset = offset >>> 0 if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0) - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = (value >>> 24) - this[offset + 1] = (value >>> 16) - this[offset + 2] = (value >>> 8) - this[offset + 3] = (value & 0xff) - } else { - objectWriteUInt32(this, value, offset, false) - } + this[offset] = (value >>> 24) + this[offset + 1] = (value >>> 16) + this[offset + 2] = (value >>> 8) + this[offset + 3] = (value & 0xff) return offset + 4 } Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) { value = +value - offset = offset | 0 + offset = offset >>> 0 if (!noAssert) { - var limit = Math.pow(2, 8 * byteLength - 1) + var limit = Math.pow(2, (8 * byteLength) - 1) checkInt(this, value, offset, byteLength, limit - 1, -limit) } @@ -24532,9 +24466,9 @@ Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, no Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) { value = +value - offset = offset | 0 + offset = offset >>> 0 if (!noAssert) { - var limit = Math.pow(2, 8 * byteLength - 1) + var limit = Math.pow(2, (8 * byteLength) - 1) checkInt(this, value, offset, byteLength, limit - 1, -limit) } @@ -24555,9 +24489,8 @@ Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, no Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) { value = +value - offset = offset | 0 + offset = offset >>> 0 if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80) - if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value) if (value < 0) value = 0xff + value + 1 this[offset] = (value & 0xff) return offset + 1 @@ -24565,58 +24498,42 @@ Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) { Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) { value = +value - offset = offset | 0 + offset = offset >>> 0 if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000) - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = (value & 0xff) - this[offset + 1] = (value >>> 8) - } else { - objectWriteUInt16(this, value, offset, true) - } + this[offset] = (value & 0xff) + this[offset + 1] = (value >>> 8) return offset + 2 } Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) { value = +value - offset = offset | 0 + offset = offset >>> 0 if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000) - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = (value >>> 8) - this[offset + 1] = (value & 0xff) - } else { - objectWriteUInt16(this, value, offset, false) - } + this[offset] = (value >>> 8) + this[offset + 1] = (value & 0xff) return offset + 2 } Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) { value = +value - offset = offset | 0 + offset = offset >>> 0 if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000) - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = (value & 0xff) - this[offset + 1] = (value >>> 8) - this[offset + 2] = (value >>> 16) - this[offset + 3] = (value >>> 24) - } else { - objectWriteUInt32(this, value, offset, true) - } + this[offset] = (value & 0xff) + this[offset + 1] = (value >>> 8) + this[offset + 2] = (value >>> 16) + this[offset + 3] = (value >>> 24) return offset + 4 } Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) { value = +value - offset = offset | 0 + offset = offset >>> 0 if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000) if (value < 0) value = 0xffffffff + value + 1 - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = (value >>> 24) - this[offset + 1] = (value >>> 16) - this[offset + 2] = (value >>> 8) - this[offset + 3] = (value & 0xff) - } else { - objectWriteUInt32(this, value, offset, false) - } + this[offset] = (value >>> 24) + this[offset + 1] = (value >>> 16) + this[offset + 2] = (value >>> 8) + this[offset + 3] = (value & 0xff) return offset + 4 } @@ -24626,6 +24543,8 @@ function checkIEEE754 (buf, value, offset, ext, max, min) { } function writeFloat (buf, value, offset, littleEndian, noAssert) { + value = +value + offset = offset >>> 0 if (!noAssert) { checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38) } @@ -24642,6 +24561,8 @@ Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) } function writeDouble (buf, value, offset, littleEndian, noAssert) { + value = +value + offset = offset >>> 0 if (!noAssert) { checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308) } @@ -24690,7 +24611,7 @@ Buffer.prototype.copy = function copy (target, targetStart, start, end) { for (i = len - 1; i >= 0; --i) { target[i + targetStart] = this[i + start] } - } else if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) { + } else if (len < 1000) { // ascending copy from start for (i = 0; i < len; ++i) { target[i + targetStart] = this[i + start] @@ -24759,7 +24680,7 @@ Buffer.prototype.fill = function fill (val, start, end, encoding) { } else { var bytes = Buffer.isBuffer(val) ? val - : utf8ToBytes(new Buffer(val, encoding).toString()) + : new Buffer(val, encoding) var len = bytes.length for (i = 0; i < end - start; ++i) { this[i + start] = bytes[i % len] @@ -24772,7 +24693,7 @@ Buffer.prototype.fill = function fill (val, start, end, encoding) { // HELPER FUNCTIONS // ================ -var INVALID_BASE64_RE = /[^+\/0-9A-Za-z-_]/g +var INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g function base64clean (str) { // Node strips out invalid characters like \n and \t from the string, base64-js does not @@ -24917,8 +24838,7 @@ function isnan (val) { return val !== val // eslint-disable-line no-self-compare } -}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"base64-js":68,"ieee754":74,"isarray":77}],72:[function(require,module,exports){ +},{"base64-js":68,"ieee754":74}],72:[function(require,module,exports){ (function (Buffer){ // Copyright Joyent, Inc. and other Node contributors. // @@ -25905,7 +25825,7 @@ function ReadableState(options, stream) { this.highWaterMark = hwm || hwm === 0 ? hwm : defaultHwm; // cast to ints. - this.highWaterMark = ~ ~this.highWaterMark; + this.highWaterMark = ~~this.highWaterMark; // A linked list is used to store data chunks instead of an array because the // linked list can remove elements from the beginning faster than @@ -27017,7 +26937,7 @@ function WritableState(options, stream) { this.highWaterMark = hwm || hwm === 0 ? hwm : defaultHwm; // cast to ints. - this.highWaterMark = ~ ~this.highWaterMark; + this.highWaterMark = ~~this.highWaterMark; // drain event flag. this.needDrain = false; @@ -27172,20 +27092,16 @@ function writeAfterEnd(stream, cb) { processNextTick(cb, er); } -// If we get something that is not a buffer, string, null, or undefined, -// and we're not in objectMode, then that's an error. -// Otherwise stream chunks are all considered to be of length=1, and the -// watermarks determine how many objects to keep in the buffer, rather than -// how many bytes or characters. +// Checks that a user-supplied chunk is valid, especially for the particular +// mode the stream is in. Currently this means that `null` is never accepted +// and undefined/non-string values are only allowed in object mode. function validChunk(stream, state, chunk, cb) { var valid = true; var er = false; - // Always throw error if a null is written - // if we are not in object mode then throw - // if it is not a buffer, string, or undefined. + if (chunk === null) { er = new TypeError('May not write null values to stream'); - } else if (!Buffer.isBuffer(chunk) && typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) { + } else if (typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) { er = new TypeError('Invalid non-string/buffer chunk'); } if (er) { @@ -27199,19 +27115,20 @@ function validChunk(stream, state, chunk, cb) { Writable.prototype.write = function (chunk, encoding, cb) { var state = this._writableState; var ret = false; + var isBuf = Buffer.isBuffer(chunk); if (typeof encoding === 'function') { cb = encoding; encoding = null; } - if (Buffer.isBuffer(chunk)) encoding = 'buffer';else if (!encoding) encoding = state.defaultEncoding; + if (isBuf) encoding = 'buffer';else if (!encoding) encoding = state.defaultEncoding; if (typeof cb !== 'function') cb = nop; - if (state.ended) writeAfterEnd(this, cb);else if (validChunk(this, state, chunk, cb)) { + if (state.ended) writeAfterEnd(this, cb);else if (isBuf || validChunk(this, state, chunk, cb)) { state.pendingcb++; - ret = writeOrBuffer(this, state, chunk, encoding, cb); + ret = writeOrBuffer(this, state, isBuf, chunk, encoding, cb); } return ret; @@ -27251,10 +27168,11 @@ function decodeChunk(state, chunk, encoding) { // if we're already writing something, then just put this // in the queue, and wait our turn. Otherwise, call _write // If we return false, then we need a drain event, so set that flag. -function writeOrBuffer(stream, state, chunk, encoding, cb) { - chunk = decodeChunk(state, chunk, encoding); - - if (Buffer.isBuffer(chunk)) encoding = 'buffer'; +function writeOrBuffer(stream, state, isBuf, chunk, encoding, cb) { + if (!isBuf) { + chunk = decodeChunk(state, chunk, encoding); + if (Buffer.isBuffer(chunk)) encoding = 'buffer'; + } var len = state.objectMode ? 1 : chunk.length; state.length += len; @@ -27323,8 +27241,8 @@ function onwrite(stream, er) { asyncWrite(afterWrite, stream, state, finished, cb); /**/ } else { - afterWrite(stream, state, finished, cb); - } + afterWrite(stream, state, finished, cb); + } } } @@ -27475,7 +27393,6 @@ function CorkedRequest(state) { this.next = null; this.entry = null; - this.finish = function (err) { var entry = _this.entry; _this.entry = null; diff --git a/app/src/main/java/com/jasonette/seed/Action/JasonAudioAction.java b/app/src/main/java/com/jasonette/seed/Action/JasonAudioAction.java index b78e1273..905a5f00 100644 --- a/app/src/main/java/com/jasonette/seed/Action/JasonAudioAction.java +++ b/app/src/main/java/com/jasonette/seed/Action/JasonAudioAction.java @@ -33,25 +33,28 @@ public void play(final JSONObject action, JSONObject data, final JSONObject even if(player == null) { player = new MediaPlayer(); player.setAudioStreamType(AudioManager.STREAM_MUSIC); + + String url = options.getString("url"); + player.reset(); + player.setDataSource(url); + player.prepare(); } AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); ((JasonViewActivity)context).setVolumeControlStream(AudioManager.STREAM_MUSIC); - String url = options.getString("url"); - player.reset(); - player.setDataSource(url); - player.prepare(); - player.start(); - - + if(player.isPlaying()){ + player.pause(); + } else { + player.start(); + } } } JasonHelper.next("success", action, new JSONObject(), event, context); } catch (SecurityException e){ JasonHelper.permission_exception("$audio.play", context); } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } public void pause(final JSONObject action, JSONObject data, final JSONObject event, final Context context) { @@ -76,13 +79,13 @@ public void duration(final JSONObject action, JSONObject data, final JSONObject ret.put("value", String.valueOf(duration)); JasonHelper.next("success", action, ret, event, context); } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); try { JSONObject err = new JSONObject(); err.put("message", "invalid position"); JasonHelper.next("error", action, err, event, context); } catch (Exception e2){ - Log.d("Error", e2.toString()); + Log.d("Warning", e2.getStackTrace()[0].getMethodName() + " : " + e2.toString()); } } } else { @@ -91,7 +94,7 @@ public void duration(final JSONObject action, JSONObject data, final JSONObject err.put("message", "player doesn't exist"); JasonHelper.next("error", action, err, event, context); } catch (Exception e){ - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } } @@ -110,7 +113,7 @@ public void position(final JSONObject action, JSONObject data, final JSONObject err.put("message", "invalid position or duration"); JasonHelper.next("error", action, err, event, context); } catch (Exception e2){ - Log.d("Error", e2.toString()); + Log.d("Warning", e2.getStackTrace()[0].getMethodName() + " : " + e2.toString()); } } } else { @@ -119,7 +122,7 @@ public void position(final JSONObject action, JSONObject data, final JSONObject err.put("message", "player doesn't exist"); JasonHelper.next("error", action, err, event, context); } catch (Exception e){ - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } } @@ -135,7 +138,7 @@ public void seek(final JSONObject action, JSONObject data, final JSONObject even } } } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } JasonHelper.next("success", action, new JSONObject(), event, context); @@ -155,8 +158,8 @@ public void record(final JSONObject action, JSONObject data, final JSONObject ev public void onSuccess() { } @Override - public void onFailure(Exception error) { - Log.d("Error", error.toString()); + public void onFailure(Exception e) { + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } }); @@ -183,7 +186,7 @@ public void onFailure(Exception error) { } catch (SecurityException e){ JasonHelper.permission_exception("$audio.record", context); } catch (Exception e){ - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } @@ -212,7 +215,7 @@ public void onSuccess(File convertedFile) { ret.put("content_type", "audio/m4a"); JasonHelper.next("success", action, ret, event, context); } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } @Override @@ -222,7 +225,7 @@ public void onFailure(Exception error) { err.put("message", error.toString()); JasonHelper.next("error", action, err, event, context); } catch (Exception e){ - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } }; @@ -232,7 +235,7 @@ public void onFailure(Exception error) { .setCallback(callback) .convert(); } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } } diff --git a/app/src/main/java/com/jasonette/seed/Action/JasonCacheAction.java b/app/src/main/java/com/jasonette/seed/Action/JasonCacheAction.java index 83039b88..bb05ede6 100644 --- a/app/src/main/java/com/jasonette/seed/Action/JasonCacheAction.java +++ b/app/src/main/java/com/jasonette/seed/Action/JasonCacheAction.java @@ -32,7 +32,7 @@ public void set(final JSONObject action, final JSONObject data, final JSONObject JasonHelper.next("success", action, new_cache, event, context); } catch (Exception e){ - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } @@ -53,7 +53,7 @@ public void reset(final JSONObject action, final JSONObject data, final JSONObje JasonHelper.next("success", action, new JSONObject(), event, context); } catch (Exception e){ - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } } diff --git a/app/src/main/java/com/jasonette/seed/Action/JasonConvertAction.java b/app/src/main/java/com/jasonette/seed/Action/JasonConvertAction.java index e674dd83..91a18010 100644 --- a/app/src/main/java/com/jasonette/seed/Action/JasonConvertAction.java +++ b/app/src/main/java/com/jasonette/seed/Action/JasonConvertAction.java @@ -108,8 +108,8 @@ private void handle_exception(Exception exc){ JSONObject error = new JSONObject(); error.put("data", exc.toString()); JasonHelper.next("error", action, error, event_cache, context); - } catch (Exception err){ - Log.d("Error", err.toString()); + } catch (Exception e){ + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } diff --git a/app/src/main/java/com/jasonette/seed/Action/JasonGeoAction.java b/app/src/main/java/com/jasonette/seed/Action/JasonGeoAction.java index f4b206ad..de1989a3 100644 --- a/app/src/main/java/com/jasonette/seed/Action/JasonGeoAction.java +++ b/app/src/main/java/com/jasonette/seed/Action/JasonGeoAction.java @@ -15,17 +15,20 @@ public class JasonGeoAction { public void get(final JSONObject action, JSONObject data, final JSONObject event, final Context context) { try { - LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); + final LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); LocationListener locationListener = new LocationListener() { public void onLocationChanged(Location location) { try { + + locationManager.removeUpdates(this); + JSONObject ret = new JSONObject(); String val = String.format("%f,%f", location.getLatitude(), location.getLongitude()); ret.put("coord", val); ret.put("value", val); JasonHelper.next("success", action, ret, event, context); } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } @@ -42,7 +45,7 @@ public void onProviderDisabled(String provider) { } catch (SecurityException e){ JasonHelper.permission_exception("$geo.get", context); } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } } diff --git a/app/src/main/java/com/jasonette/seed/Action/JasonGlobalAction.java b/app/src/main/java/com/jasonette/seed/Action/JasonGlobalAction.java new file mode 100644 index 00000000..90f385de --- /dev/null +++ b/app/src/main/java/com/jasonette/seed/Action/JasonGlobalAction.java @@ -0,0 +1,103 @@ +package com.jasonette.seed.Action; +import android.content.Context; +import android.content.SharedPreferences; +import android.util.Log; + +import com.jasonette.seed.Core.JasonViewActivity; +import com.jasonette.seed.Helper.JasonHelper; +import com.jasonette.seed.Launcher.Launcher; + +import org.json.JSONArray; +import org.json.JSONObject; + +import java.util.Iterator; + +public class JasonGlobalAction { + public void reset(final JSONObject action, final JSONObject data, final JSONObject event, final Context context) { + + /******************** + + The following resets a global variable named "db". + When a variable is reset, the key itself gets destroyed, so when you check ('db' in $global), it will return false + + { + "type": "$global.reset", + "options": { + "items": ["db"] + } + } + + ********************/ + + try { + SharedPreferences pref = context.getSharedPreferences("global", 0); + SharedPreferences.Editor editor = pref.edit(); + + JSONObject options = action.getJSONObject("options"); + if(options.has("items")){ + JSONArray items = options.getJSONArray("items"); + for (int i=0; i keysIterator = options.keys(); + while (keysIterator.hasNext()) { + String key = (String) keysIterator.next(); + Object val = options.get(key); + editor.putString(key, val.toString()); + ((Launcher)context.getApplicationContext()).setGlobal(key, val); + } + editor.commit(); + + // Execute next + JasonHelper.next("success", action, ((Launcher)context.getApplicationContext()).getGlobal(), event, context); + + } catch (Exception e) { + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); + } + } +} diff --git a/app/src/main/java/com/jasonette/seed/Action/JasonLogAction.java b/app/src/main/java/com/jasonette/seed/Action/JasonLogAction.java index b391b3f4..be9e9777 100644 --- a/app/src/main/java/com/jasonette/seed/Action/JasonLogAction.java +++ b/app/src/main/java/com/jasonette/seed/Action/JasonLogAction.java @@ -32,7 +32,7 @@ private void log(final JSONObject action, JSONObject data, JSONObject event, Con } JasonHelper.next("success", action, data, event, context); } catch (Exception e){ - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } diff --git a/app/src/main/java/com/jasonette/seed/Action/JasonMediaAction.java b/app/src/main/java/com/jasonette/seed/Action/JasonMediaAction.java index 27346baf..5635656a 100644 --- a/app/src/main/java/com/jasonette/seed/Action/JasonMediaAction.java +++ b/app/src/main/java/com/jasonette/seed/Action/JasonMediaAction.java @@ -53,7 +53,7 @@ public void play(final JSONObject action, JSONObject data, final JSONObject even JasonHelper.dispatchIntent(action, data, event, context, intent, callback); } } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } // Util for play @@ -75,7 +75,7 @@ public void finishplay(Intent intent, final JSONObject options) { JasonHelper.next("success", action, new JSONObject(), event, context); } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } @@ -120,7 +120,7 @@ public void picker(final JSONObject action, JSONObject data, final JSONObject ev } catch (SecurityException e){ JasonHelper.permission_exception("$media.picker", context); } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } @@ -206,7 +206,7 @@ public void camera(final JSONObject action, JSONObject data, final JSONObject ev } catch (SecurityException e){ JasonHelper.permission_exception("$media.camera", context); } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } @@ -235,14 +235,19 @@ public void process(Intent intent, final JSONObject options) { ret.put("content_type", "video/mp4"); JasonHelper.next("success", action, ret, event, context); } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } else { // image InputStream stream = context.getContentResolver().openInputStream(uri); byte[] byteArray = JasonHelper.readBytes(stream); - String encoded = Base64.encodeToString(byteArray, Base64.DEFAULT); - String data_uri = "data:image/jpeg;base64," + encoded; + String encoded = Base64.encodeToString(byteArray, Base64.NO_WRAP); + + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append("data:image/jpeg;base64,"); + stringBuilder.append(encoded); + String data_uri = stringBuilder.toString(); + try { JSONObject ret = new JSONObject(); ret.put("data", encoded); @@ -250,12 +255,12 @@ public void process(Intent intent, final JSONObject options) { ret.put("content_type", "image/jpeg"); JasonHelper.next("success", action, ret, event, context); } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } private File createFile(String type, Context context) throws IOException { diff --git a/app/src/main/java/com/jasonette/seed/Action/JasonNetworkAction.java b/app/src/main/java/com/jasonette/seed/Action/JasonNetworkAction.java index 6105d1c1..28f9b4a5 100644 --- a/app/src/main/java/com/jasonette/seed/Action/JasonNetworkAction.java +++ b/app/src/main/java/com/jasonette/seed/Action/JasonNetworkAction.java @@ -178,8 +178,8 @@ public void onFailure(Call call, IOException e) { JasonHelper.next("error", action, error, event, context); } } - } catch (Exception err){ - Log.d("Error", err.toString()); + } catch (Exception e2){ + Log.d("Warning", e2.getStackTrace()[0].getMethodName() + " : " + e2.toString()); } } @@ -196,8 +196,8 @@ public void onResponse(Call call, final Response response) throws IOException { JasonHelper.next("error", action, error, event, context); } } - } catch (Exception err){ - Log.d("Error", err.toString()); + } catch (Exception e){ + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } else { try { @@ -209,7 +209,7 @@ public void onResponse(Call call, final Response response) throws IOException { } } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } } @@ -217,7 +217,7 @@ public void onResponse(Call call, final Response response) throws IOException { } } catch (Exception e){ - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } public void request(final JSONObject action, final JSONObject data, final JSONObject event, final Context context){ @@ -255,7 +255,7 @@ public void upload(JSONObject action, final JSONObject data, final JSONObject ev _request(stack, upload_action, data, event, context); } } catch (Exception e){ - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } @@ -291,7 +291,7 @@ public void process(JSONObject stack, String result) { } } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } public void uploadfinished(JSONObject stack, String result) { @@ -306,7 +306,7 @@ public void uploadfinished(JSONObject stack, String result) { final Context context = (Context) o.get("context"); JasonHelper.next("success", action, ret, event, context); } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } } diff --git a/app/src/main/java/com/jasonette/seed/Action/JasonOauthAction.java b/app/src/main/java/com/jasonette/seed/Action/JasonOauthAction.java index 3b6adcd9..77475ab4 100644 --- a/app/src/main/java/com/jasonette/seed/Action/JasonOauthAction.java +++ b/app/src/main/java/com/jasonette/seed/Action/JasonOauthAction.java @@ -197,7 +197,7 @@ protected String getAuthorizationBaseUrl() { Iterator paramKeys = authorize_options_data.keys(); while(paramKeys.hasNext()) { String key = (String)paramKeys.next(); - if(key != "redirect_uri" || key != "response_type" || key != "scope" || key != "state") { + if(key != "redirect_uri" && key != "response_type" && key != "scope" && key != "state") { String value = authorize_options_data.getString(key); additionalParams.put(key, value); } @@ -314,7 +314,7 @@ protected String getAuthorizationBaseUrl() { Iterator paramKeys = authorize_options_data.keys(); while(paramKeys.hasNext()) { String key = (String)paramKeys.next(); - if(key != "redirect_uri" || key != "response_type" || key != "scope" || key != "state") { + if(key != "redirect_uri" && key != "response_type" && key != "scope" && key != "state") { String value = authorize_options_data.getString(key); additionalParams.put(key, value); } @@ -476,14 +476,14 @@ protected Void doInBackground(String... params) { } } } - catch(JSONException e) { + catch(JSONException err) { try { JSONObject error = new JSONObject(); - error.put("data", e.toString()); + error.put("data", err.toString()); JasonHelper.next("error", intent_options.getJSONObject("action"), error, intent_options.getJSONObject("event"), (Context)intent_options.get("context")); - } catch(JSONException error) { - Log.d("Error", error.toString()); + } catch(JSONException e) { + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } } @@ -800,13 +800,13 @@ protected Void doInBackground(Void... voids) { } } - private void handleError(Exception e, JSONObject action, JSONObject event, Context context) { + private void handleError(Exception err, JSONObject action, JSONObject event, Context context) { try { JSONObject error = new JSONObject(); - error.put("data", e.toString()); + error.put("data", err.toString()); JasonHelper.next("error", action, error, event, context); - } catch(JSONException error) { - Log.d("Error", error.toString()); + } catch(JSONException e) { + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } } \ No newline at end of file diff --git a/app/src/main/java/com/jasonette/seed/Action/JasonReturnAction.java b/app/src/main/java/com/jasonette/seed/Action/JasonReturnAction.java index 9e713d84..b84f69c3 100644 --- a/app/src/main/java/com/jasonette/seed/Action/JasonReturnAction.java +++ b/app/src/main/java/com/jasonette/seed/Action/JasonReturnAction.java @@ -90,7 +90,7 @@ public void success(final JSONObject action, JSONObject data, final JSONObject e intent.putExtra("data", data.toString()); LocalBroadcastManager.getInstance(context).sendBroadcast(intent); } catch (Exception e){ - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } else { JasonHelper.next("success", new JSONObject(), data, event, context); @@ -104,7 +104,7 @@ public void error(final JSONObject action, JSONObject data, final JSONObject eve intent.putExtra("data", data.toString()); LocalBroadcastManager.getInstance(context).sendBroadcast(intent); } catch (Exception e){ - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } else { JasonHelper.next("error", new JSONObject(), data, event, context); diff --git a/app/src/main/java/com/jasonette/seed/Action/JasonSessionAction.java b/app/src/main/java/com/jasonette/seed/Action/JasonSessionAction.java index c2552090..2734f95d 100644 --- a/app/src/main/java/com/jasonette/seed/Action/JasonSessionAction.java +++ b/app/src/main/java/com/jasonette/seed/Action/JasonSessionAction.java @@ -42,7 +42,7 @@ public void set(final JSONObject action, final JSONObject data, final JSONObject JasonHelper.next("success", action, new JSONObject(), event, context); } catch (Exception e){ - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } @@ -77,7 +77,7 @@ public void reset(final JSONObject action, final JSONObject data, final JSONObje JasonHelper.next("success", action, new JSONObject(), event, context); } catch (Exception e){ - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } } diff --git a/app/src/main/java/com/jasonette/seed/Action/JasonTimerAction.java b/app/src/main/java/com/jasonette/seed/Action/JasonTimerAction.java index 786a4fe4..bcb1d40f 100644 --- a/app/src/main/java/com/jasonette/seed/Action/JasonTimerAction.java +++ b/app/src/main/java/com/jasonette/seed/Action/JasonTimerAction.java @@ -82,7 +82,7 @@ public void run() { JasonHelper.next("success", action, data, event, context); } catch (Exception e){ - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } @@ -102,7 +102,7 @@ public void stop(final JSONObject action, final JSONObject data, final JSONObjec // Go on to the next success action JasonHelper.next("success", action, data, event, context); } catch (Exception e){ - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } diff --git a/app/src/main/java/com/jasonette/seed/Action/JasonUtilAction.java b/app/src/main/java/com/jasonette/seed/Action/JasonUtilAction.java index f4d9d527..afce0844 100644 --- a/app/src/main/java/com/jasonette/seed/Action/JasonUtilAction.java +++ b/app/src/main/java/com/jasonette/seed/Action/JasonUtilAction.java @@ -52,14 +52,14 @@ public void run() { Snackbar snackbar = Snackbar.make(((JasonViewActivity)context).rootLayout, options.getString("title") + "\n" + options.getString("description"), Snackbar.LENGTH_LONG); snackbar.show(); } catch (Exception e){ - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } }); try { JasonHelper.next("success", action, new JSONObject(), event, context); } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } public void toast(final JSONObject action, final JSONObject data, final JSONObject event, final Context context) { @@ -72,14 +72,14 @@ public void run() { Toast toast = Toast.makeText(context, (CharSequence)options.getString("text"), duration); toast.show(); } catch (Exception e){ - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } }); try { JasonHelper.next("success", action, new JSONObject(), event, context); - } catch (Exception err) { - Log.d("Error", err.toString()); + } catch (Exception e) { + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } public void alert(final JSONObject action, final JSONObject data, final JSONObject event, final Context context){ @@ -166,7 +166,7 @@ public void onClick(DialogInterface dialog, }); builder.show(); } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } }); @@ -180,6 +180,10 @@ public void run() { if(options.has("items")){ final JSONArray items = options.getJSONArray("items"); AlertDialog.Builder builder = new AlertDialog.Builder(context); + if(options.has("title")){ + String title = options.getString("title"); + builder.setTitle(title); + } ArrayList listItems = new ArrayList(); for (int i = 0; i < items.length() ; i++) { @@ -209,7 +213,7 @@ public void onClick(DialogInterface dialog, int val) { LocalBroadcastManager.getInstance(context).sendBroadcast(intent); } } catch (Exception e){ - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } }); @@ -222,14 +226,14 @@ public void onClick(DialogInterface dialog, int val) { builder.create().show(); } } catch (Exception e){ - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } }); try { JasonHelper.next("success", action, new JSONObject(), event, context); } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } @@ -269,7 +273,7 @@ public void onDateSelected(Date date) { value.put("value", val); JasonHelper.next("success", action, value, event, context); } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } @@ -332,13 +336,13 @@ private void getContacts(final JSONObject action, final JSONObject data, final J // Add to array contactList.put(contact); } catch (Exception e){ - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } try { JasonHelper.next("success", action, contactList, event, context); } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } } catch (SecurityException e){ @@ -447,7 +451,7 @@ public void onLoaded(byte[] data, Uri uri) { } } } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } }).start(); diff --git a/app/src/main/java/com/jasonette/seed/Component/JasonButtonComponent.java b/app/src/main/java/com/jasonette/seed/Component/JasonButtonComponent.java index b664e2fa..49277e54 100644 --- a/app/src/main/java/com/jasonette/seed/Component/JasonButtonComponent.java +++ b/app/src/main/java/com/jasonette/seed/Component/JasonButtonComponent.java @@ -99,7 +99,7 @@ public static View build(View view, final JSONObject component, final JSONObject view.setPadding(padding_left, padding_top, padding_right, padding_bottom); } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } else { diff --git a/app/src/main/java/com/jasonette/seed/Component/JasonComponent.java b/app/src/main/java/com/jasonette/seed/Component/JasonComponent.java index 4cae32e8..e0c3bbf6 100644 --- a/app/src/main/java/com/jasonette/seed/Component/JasonComponent.java +++ b/app/src/main/java/com/jasonette/seed/Component/JasonComponent.java @@ -142,7 +142,7 @@ public static View build(View view, final JSONObject component, final JSONObject return view; } catch (Exception e){ - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); return new View(root_context); } } @@ -173,7 +173,7 @@ public void onClick(View v) { } } } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } }; diff --git a/app/src/main/java/com/jasonette/seed/Component/JasonComponentFactory.java b/app/src/main/java/com/jasonette/seed/Component/JasonComponentFactory.java index b1d6f83a..73546298 100644 --- a/app/src/main/java/com/jasonette/seed/Component/JasonComponentFactory.java +++ b/app/src/main/java/com/jasonette/seed/Component/JasonComponentFactory.java @@ -47,7 +47,7 @@ public static View build(View prototype, final JSONObject component, final JSONO } catch (Exception e){ - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } return new View(context); diff --git a/app/src/main/java/com/jasonette/seed/Component/JasonHtmlComponent.java b/app/src/main/java/com/jasonette/seed/Component/JasonHtmlComponent.java index 17fd0625..eb713eac 100644 --- a/app/src/main/java/com/jasonette/seed/Component/JasonHtmlComponent.java +++ b/app/src/main/java/com/jasonette/seed/Component/JasonHtmlComponent.java @@ -24,7 +24,7 @@ public static View build(View view, final JSONObject component, final JSONObject return webview; } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } else { JasonComponent.build(view, component, parent, context); @@ -42,6 +42,7 @@ public static View build(View view, final JSONObject component, final JSONObject settings.setJavaScriptEnabled(true); settings.setDomStorageEnabled(true); settings.setJavaScriptCanOpenWindowsAutomatically(true); + settings.setMediaPlaybackRequiresUserGesture(false); settings.setAppCachePath( context.getCacheDir().getAbsolutePath() ); settings.setAllowFileAccess( true ); @@ -104,7 +105,7 @@ public boolean onTouch(View v, MotionEvent event) { } return true; } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } return true; } @@ -114,7 +115,7 @@ public boolean onTouch(View v, MotionEvent event) { view.requestLayout(); return view; } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } return new View(context); diff --git a/app/src/main/java/com/jasonette/seed/Component/JasonImageComponent.java b/app/src/main/java/com/jasonette/seed/Component/JasonImageComponent.java index bb1bb3dd..46d6d476 100644 --- a/app/src/main/java/com/jasonette/seed/Component/JasonImageComponent.java +++ b/app/src/main/java/com/jasonette/seed/Component/JasonImageComponent.java @@ -8,14 +8,20 @@ import android.support.v4.graphics.drawable.DrawableCompat; import android.support.v4.graphics.drawable.RoundedBitmapDrawable; import android.support.v4.graphics.drawable.RoundedBitmapDrawableFactory; +import android.util.Base64; import android.util.Log; import android.view.View; import android.widget.ImageView; import com.bumptech.glide.Glide; +import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.bumptech.glide.load.model.GlideUrl; import com.bumptech.glide.load.model.LazyHeaders; +import com.bumptech.glide.load.resource.drawable.GlideDrawable; +import com.bumptech.glide.load.resource.gif.GifDrawable; +import com.bumptech.glide.request.animation.GlideAnimation; import com.bumptech.glide.request.target.BitmapImageViewTarget; +import com.bumptech.glide.request.target.SimpleTarget; import com.jasonette.seed.Helper.JasonHelper; import org.json.JSONObject; @@ -23,6 +29,152 @@ import java.util.Iterator; public class JasonImageComponent { + private static LazyHeaders.Builder prepare(JSONObject component, Context context){ + try { + // Constructing URL + GlideUrl url; + LazyHeaders.Builder builder = new LazyHeaders.Builder(); + + // Add session if included + SharedPreferences pref = context.getSharedPreferences("session", 0); + JSONObject session = null; + URI uri_for_session = new URI(component.getString("url").toLowerCase()); + String session_domain = uri_for_session.getHost(); + if(pref.contains(session_domain)){ + String str = pref.getString(session_domain, null); + session = new JSONObject(str); + } + // Attach Header from Session + if(session != null && session.has("header")) { + Iterator keys = session.getJSONObject("header").keys(); + while (keys.hasNext()) { + String key = (String) keys.next(); + String val = session.getJSONObject("header").getString(key); + builder.addHeader(key, val); + } + } + + if(component.has("header")){ + Iterator keys = component.getJSONObject("header").keys(); + while (keys.hasNext()) { + String key = (String) keys.next(); + String val = component.getJSONObject("header").getString(key); + builder.addHeader(key, val); + } + } + return builder; + + } catch (Exception e) { + + return null; + } + } + + public static Object resolve_url(JSONObject component, Context context){ + try { + String url = component.getString("url"); + if(url.contains("file://")) { + return "file:///android_asset/file/" + url.substring(7); + } else if(url.startsWith("data:image")) { + return url; + } else { + LazyHeaders.Builder builder = JasonImageComponent.prepare(component, context); + return new GlideUrl(url, builder.build()); + } + } catch (Exception e){ + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); + return ""; + } + } + + private static void gif(JSONObject component, View view, Context context){ + Object new_url = JasonImageComponent.resolve_url(component, context); + Glide + .with(context) + .load(new_url) + .asGif() + .diskCacheStrategy(DiskCacheStrategy.SOURCE) + .into((ImageView)view); + } + private static void rounded(JSONObject component, View view, final float corner_radius_float, final Context context){ + Object new_url = JasonImageComponent.resolve_url(component, context); + try { + Glide + .with(context) + .load(new_url) + .asBitmap() + .fitCenter() + .into(new BitmapImageViewTarget((ImageView)view) { + @Override + protected void setResource(Bitmap res) { + RoundedBitmapDrawable bitmapDrawable = + RoundedBitmapDrawableFactory.create(context.getResources(), res); + bitmapDrawable.setCornerRadius(corner_radius_float); + view.setImageDrawable(bitmapDrawable); + } + }); + } catch (Exception e) { + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); + } + } + private static void normal(JSONObject component, final View view, Context context) { + Object new_url = JasonImageComponent.resolve_url(component, context); + if(new_url.getClass().toString().equalsIgnoreCase("string") && ((String)new_url).startsWith("data:image")){ + String n = (String)new_url; + String base64; + if(n.startsWith("data:image/jpeg")){ + base64 = n.substring("data:image/jpeg;base64,".length()); + } else if(n.startsWith("data:image/png")){ + base64 = n.substring("data:image/png;base64,".length()); + } else if(n.startsWith("data:image/gif")){ + base64 = n.substring("data:image/gif;base64,".length()); + } else { + base64 = ""; // exception + } + byte[] bs = Base64.decode(base64, Base64.NO_WRAP); + + Glide.with(context).load(bs) + .into(new SimpleTarget() { + @Override + public void onResourceReady(GlideDrawable resource, GlideAnimation glideAnimation) { + ((ImageView)view).setImageDrawable(resource); + } + }); + } else { + Glide + .with(context) + .load(new_url) + .into((ImageView) view); + } + + } + private static void tinted(JSONObject component, View view, final Context context){ + try { + Object new_url = JasonImageComponent.resolve_url(component, context); + final JSONObject style = component.getJSONObject("style"); + Glide + .with(context) + .load(new_url) + .asBitmap() + .fitCenter() + .into(new BitmapImageViewTarget((ImageView)view) { + @Override + protected void setResource(Bitmap res) { + BitmapDrawable d = new BitmapDrawable(context.getResources(), res); + try { + Drawable wrapper = DrawableCompat.wrap(d); + DrawableCompat.setTint(wrapper, JasonHelper.parse_color(style.getString("color"))); + view.setImageDrawable(wrapper); + } catch (Exception e) { + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); + view.setImageDrawable(d); + } + } + }); + } catch (Exception e) { + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); + } + } public static View build(View view, final JSONObject component, final JSONObject parent, final Context context) { if(view == null){ @@ -32,7 +184,7 @@ public static View build(View view, final JSONObject component, final JSONObject imageview.setAdjustViewBounds(true); return imageview; } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); return new View(context); } } else { @@ -44,116 +196,75 @@ public static View build(View view, final JSONObject component, final JSONObject try { String type; final JSONObject style = JasonHelper.style(component, context); - type = component.getString("type"); - - // Constructing URL - GlideUrl url; - LazyHeaders.Builder builder = new LazyHeaders.Builder(); - - // Add session if included - SharedPreferences pref = context.getSharedPreferences("session", 0); - JSONObject session = null; - URI uri_for_session = new URI(component.getString("url").toLowerCase()); - String session_domain = uri_for_session.getHost(); - if(pref.contains(session_domain)){ - String str = pref.getString(session_domain, null); - session = new JSONObject(str); - } - // Attach Header from Session - if(session != null && session.has("header")) { - Iterator keys = session.getJSONObject("header").keys(); - while (keys.hasNext()) { - String key = (String) keys.next(); - String val = session.getJSONObject("header").getString(key); - builder.addHeader(key, val); - } - } - - if(component.has("header")){ - Iterator keys = component.getJSONObject("header").keys(); - while (keys.hasNext()) { - String key = (String) keys.next(); - String val = component.getJSONObject("header").getString(key); - builder.addHeader(key, val); - } - } - - url = new GlideUrl(component.getString("url"), builder.build()); - if (style.has("corner_radius")) { corner_radius = JasonHelper.pixels(context, style.getString("corner_radius"), "horizontal"); } + type = component.getString("type"); - if (corner_radius == 0) { - try { - if (component.getString("url").matches("\\.gif")) { - Glide - .with(context) - .load(url) - .asGif() - .into((ImageView)view); + if (component.has("url")) { + if(component.getString("url").contains("file://")){ + if (corner_radius == 0) { + try { + if (component.getString("url").matches(".*\\.gif")) { + JasonImageComponent.gif(component, view, context); + } else { + if(style.has("color")){ + JasonImageComponent.tinted(component, view, context); + } else { + JasonImageComponent.normal(component, view, context); + } + } + } catch (Exception e) { + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); + } } else { - if(style.has("color")){ - Glide - .with(context) - .load(url) - .asBitmap() - .fitCenter() - .into(new BitmapImageViewTarget((ImageView)view) { - @Override - protected void setResource(Bitmap res) { - BitmapDrawable d = new BitmapDrawable(context.getResources(), res); - try { - Drawable wrapper = DrawableCompat.wrap(d); - DrawableCompat.setTint(wrapper, JasonHelper.parse_color(style.getString("color"))); - view.setImageDrawable(wrapper); - } catch (Exception e) { - Log.d("Error", e.toString()); - view.setImageDrawable(d); - } - } - }); - } else { - - Glide - .with(context) - .load(url) - .into((ImageView)view); + final float corner_radius_float = (float)corner_radius; + try { + JasonImageComponent.rounded(component, view, corner_radius_float, context); + } catch (Exception e) { + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } + } + JasonComponent.addListener(view, context); + view.requestLayout(); + return view; + + } else { + if (corner_radius == 0) { + try { + if (component.getString("url").matches(".*\\.gif")) { + JasonImageComponent.gif(component, view, context); + } else { + if(style.has("color")){ + JasonImageComponent.tinted(component, view, context); + } else { + JasonImageComponent.normal(component, view, context); + } + } + } catch (Exception e) { + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); + } + } else { + final float corner_radius_float = (float)corner_radius; + try { + JasonImageComponent.rounded(component, view, corner_radius_float, context); + } catch (Exception e) { + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); + } } - } catch (Exception e) { - Log.d("Error", e.toString()); + + JasonComponent.addListener(view, context); + view.requestLayout(); + return view; + } + } else { - final float corner_radius_float = (float)corner_radius; - if (component.getString("url").length() > 0) { - try { - Glide - .with(context) - .load(url) - .asBitmap() - .fitCenter() - .into(new BitmapImageViewTarget((ImageView)view) { - @Override - protected void setResource(Bitmap res) { - RoundedBitmapDrawable bitmapDrawable = - RoundedBitmapDrawableFactory.create(context.getResources(), res); - bitmapDrawable.setCornerRadius(corner_radius_float); - view.setImageDrawable(bitmapDrawable); - } - }); - } catch (Exception e) { - Log.d("Error", e.toString()); - } - } + return new View(context); } - - JasonComponent.addListener(view, context); - view.requestLayout(); - return view; } catch (Exception e){ - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } return new View(context); } diff --git a/app/src/main/java/com/jasonette/seed/Component/JasonLabelComponent.java b/app/src/main/java/com/jasonette/seed/Component/JasonLabelComponent.java index 326e0ea1..5b268ad6 100644 --- a/app/src/main/java/com/jasonette/seed/Component/JasonLabelComponent.java +++ b/app/src/main/java/com/jasonette/seed/Component/JasonLabelComponent.java @@ -101,7 +101,7 @@ public static View build(View view, final JSONObject component, final JSONObject return view; } catch (Exception e){ - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); return new View(context); } } diff --git a/app/src/main/java/com/jasonette/seed/Component/JasonMapComponent.java b/app/src/main/java/com/jasonette/seed/Component/JasonMapComponent.java index f2ef9630..c57885a6 100644 --- a/app/src/main/java/com/jasonette/seed/Component/JasonMapComponent.java +++ b/app/src/main/java/com/jasonette/seed/Component/JasonMapComponent.java @@ -63,8 +63,8 @@ public static View build(View view, final JSONObject component, final JSONObject // Add pins when the map is ready mapview.getMapAsync(new MapReadyHandler(component, mapview, context)); return mapview; - } catch (Exception err) { - Log.d("Error", err.toString()); + } catch (Exception e) { + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } else { try { @@ -77,8 +77,8 @@ public static View build(View view, final JSONObject component, final JSONObject ((MapView)view).onResume(); // Trigger onResume return view; - } catch (Exception err){ - Log.d("Error", err.toString()); + } catch (Exception e){ + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } return new View(context); @@ -94,8 +94,8 @@ private static LatLng getCoordinates(JSONObject position) { latitude = Double.parseDouble(r[0]); longitude = Double.parseDouble(r[1]); } - } catch (Exception err) { - Log.d("Error", err.toString()); + } catch (Exception e) { + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } return new LatLng(latitude, longitude); } @@ -167,8 +167,8 @@ public void onMapReady(GoogleMap map) { map.moveCamera(CameraUpdateFactory.zoomTo(zoom)); } } - } catch (Exception err) { - Log.d("Error", err.toString()); + } catch (Exception e) { + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } } @@ -179,28 +179,30 @@ public void onMapReady(GoogleMap map) { // to let the mapview handle them @Override public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) { - LinearLayout layout = (LinearLayout)rv.findChildViewUnder(e.getX(),e.getY()); - if(layout != null) { - for(int i=0; i left && e.getX() < right && e.getY() > top && e.getY() < bottom) { - switch (e.getActionMasked()) { - // Pressed on map: stop listview from scrolling - case MotionEvent.ACTION_DOWN: - rv.requestDisallowInterceptTouchEvent(true); - break; - - // Released on map or cancelled: listview can be normal again - case MotionEvent.ACTION_UP: - case MotionEvent.ACTION_CANCEL: - rv.requestDisallowInterceptTouchEvent(false); - break; + if((rv.findChildViewUnder(e.getX(), e.getY())) instanceof LinearLayout) { + LinearLayout layout = (LinearLayout)rv.findChildViewUnder(e.getX(),e.getY()); + if (layout != null) { + for (int i = 0; i < layout.getChildCount(); i++) { + View child = layout.getChildAt(i); + // Weed out non-map views ASAP + if (child.getClass().equals(MapView.class)) { + int left = layout.getLeft() + child.getLeft(); + int right = layout.getLeft() + child.getRight(); + int top = layout.getTop() + child.getTop(); + int bottom = layout.getTop() + child.getBottom(); + if (e.getX() > left && e.getX() < right && e.getY() > top && e.getY() < bottom) { + switch (e.getActionMasked()) { + // Pressed on map: stop listview from scrolling + case MotionEvent.ACTION_DOWN: + rv.requestDisallowInterceptTouchEvent(true); + break; + + // Released on map or cancelled: listview can be normal again + case MotionEvent.ACTION_UP: + case MotionEvent.ACTION_CANCEL: + rv.requestDisallowInterceptTouchEvent(false); + break; + } } } } diff --git a/app/src/main/java/com/jasonette/seed/Component/JasonSliderComponent.java b/app/src/main/java/com/jasonette/seed/Component/JasonSliderComponent.java index 0fbaf6ec..df39913a 100644 --- a/app/src/main/java/com/jasonette/seed/Component/JasonSliderComponent.java +++ b/app/src/main/java/com/jasonette/seed/Component/JasonSliderComponent.java @@ -44,7 +44,7 @@ public static View build(View view, final JSONObject component, final JSONObject view.requestLayout(); return view; } catch (Exception e){ - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); return new View(context); } } @@ -69,7 +69,7 @@ public void onStopTrackingTouch(SeekBar seekBar) { ((JasonViewActivity) root_context).call(action.toString(), new JSONObject().toString(), "{}", view.getContext()); } } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } }; diff --git a/app/src/main/java/com/jasonette/seed/Component/JasonSpaceComponent.java b/app/src/main/java/com/jasonette/seed/Component/JasonSpaceComponent.java index 8f2ad838..1898d993 100644 --- a/app/src/main/java/com/jasonette/seed/Component/JasonSpaceComponent.java +++ b/app/src/main/java/com/jasonette/seed/Component/JasonSpaceComponent.java @@ -16,7 +16,7 @@ public static View build(View view, final JSONObject component, final JSONObject view.requestLayout(); return view; } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); return new View(context); } } diff --git a/app/src/main/java/com/jasonette/seed/Component/JasonTextareaComponent.java b/app/src/main/java/com/jasonette/seed/Component/JasonTextareaComponent.java index 66783e57..e957d27c 100644 --- a/app/src/main/java/com/jasonette/seed/Component/JasonTextareaComponent.java +++ b/app/src/main/java/com/jasonette/seed/Component/JasonTextareaComponent.java @@ -166,7 +166,7 @@ public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { view.requestLayout(); return view; } catch (Exception e){ - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); return new View(context); } } diff --git a/app/src/main/java/com/jasonette/seed/Component/JasonTextfieldComponent.java b/app/src/main/java/com/jasonette/seed/Component/JasonTextfieldComponent.java index 6e1b3be1..098253c6 100644 --- a/app/src/main/java/com/jasonette/seed/Component/JasonTextfieldComponent.java +++ b/app/src/main/java/com/jasonette/seed/Component/JasonTextfieldComponent.java @@ -195,7 +195,7 @@ public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { view.requestLayout(); return view; } catch (Exception e){ - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); return new View(context); } } diff --git a/app/src/main/java/com/jasonette/seed/Core/JasonModel.java b/app/src/main/java/com/jasonette/seed/Core/JasonModel.java index 7532012d..e1478b18 100644 --- a/app/src/main/java/com/jasonette/seed/Core/JasonModel.java +++ b/app/src/main/java/com/jasonette/seed/Core/JasonModel.java @@ -1,30 +1,22 @@ package com.jasonette.seed.Core; -import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.net.Uri; -import android.os.AsyncTask; import android.util.Log; import com.jasonette.seed.Helper.JasonHelper; +import com.jasonette.seed.Launcher.Launcher; -import org.apache.commons.lang.StringEscapeUtils; -import org.apache.commons.lang.StringUtils; -import org.json.JSONArray; -import org.json.JSONException; import org.json.JSONObject; + import java.io.IOException; import java.net.URI; import java.util.ArrayList; -import java.util.HashMap; import java.util.Iterator; -import java.util.List; -import java.util.concurrent.Callable; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -63,7 +55,7 @@ public JasonModel(String url, Intent intent, JasonViewActivity view){ try { this.params = new JSONObject(intent.getStringExtra("params")); } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } @@ -78,7 +70,7 @@ public JasonModel(String url, Intent intent, JasonViewActivity view){ try { this.cache = new JSONObject(str); } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } @@ -93,7 +85,15 @@ public JasonModel(String url, Intent intent, JasonViewActivity view){ this.session = new JSONObject(str); } } catch (Exception e){ - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); + }; + + try { + JSONObject v = new JSONObject(); + v.put("url", this.url); + ((Launcher)(this.view.getApplicationContext())).setEnv("view", v); + } catch (Exception e){ + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); }; } @@ -101,26 +101,23 @@ public JasonModel(String url, Intent intent, JasonViewActivity view){ public void fetch() { if(url.startsWith("file://")) { - fetch_local(); + fetch_local(url); } else { - fetch_http(); + fetch_http(url); } } - private void fetch_local(){ + public void fetch_local(String url){ try { - jason = JasonHelper.read_json(url, this.view); - if(jason.has("$jason")){ - view.build(); - } else { - Log.d("Error", "Invalid jason"); - } + jason = (JSONObject)JasonHelper.read_json(url, this.view); + refs = new JSONObject(); + resolve_and_build(jason.toString()); } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } - private void fetch_http(){ + private void fetch_http(String url){ try{ Request request; Request.Builder builder = new Request.Builder(); @@ -159,21 +156,23 @@ private void fetch_http(){ client.newCall(request).enqueue(new Callback() { @Override public void onFailure(Call call, IOException e) { + fetch_local("file://error.json"); e.printStackTrace(); } @Override public void onResponse(Call call, final Response response) throws IOException { if (!response.isSuccessful()) { - throw new IOException("Unexpected code " + response); + fetch_local("file://error.json"); + } else { + String res = response.body().string(); + refs = new JSONObject(); + resolve_and_build(res); } - String res = response.body().string(); - refs = new JSONObject(); - resolve_and_build(res); } }); } catch (Exception e){ - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } @@ -204,7 +203,7 @@ private void include(String res){ try { latch.await(); } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } @@ -237,14 +236,14 @@ private void resolve_and_build(String res){ resolve_local_reference(); } else { if (jason.has("$jason")) { - view.build(); + view.build(jason); } else { } } } } catch (Exception e){ - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } @@ -278,13 +277,13 @@ public void onFinished(JSONObject resolved_jason) { try { resolve_and_build(resolved_jason.toString()); } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } }); JasonParser.getInstance(this.view).parse("json", refs, to_resolve, this.view); } catch (Exception e){ - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } @@ -312,13 +311,13 @@ public void onFinished(JSONObject resolved_jason) { try { resolve_and_build(resolved_jason.toString()); } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } }); JasonParser.getInstance(this.view).parse("json", refs, to_resolve, this.view); } catch (Exception e){ - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } @@ -348,9 +347,11 @@ public void set(String name, JSONObject data){ // merge with passed in data state.put("$get", var); state.put("$cache", cache); + state.put("$global", ((Launcher)(this.view.getApplicationContext())).getGlobal()); + state.put("$env", ((Launcher)(this.view.getApplicationContext())).getEnv()); state.put("$params", params); } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } else { diff --git a/app/src/main/java/com/jasonette/seed/Core/JasonParser.java b/app/src/main/java/com/jasonette/seed/Core/JasonParser.java index f8ebd23e..8c67081b 100644 --- a/app/src/main/java/com/jasonette/seed/Core/JasonParser.java +++ b/app/src/main/java/com/jasonette/seed/Core/JasonParser.java @@ -41,7 +41,7 @@ public static JasonParser getInstance(Context context){ instance.juice.executeVoidScript(js); instance.juice.getLocker().release(); } catch (Exception e){ - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } return instance; @@ -92,7 +92,7 @@ public void parse(final String data_type, final JSONObject data, final Object te listener.onFinished(res); } catch (Exception e){ - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } // thread handling - release handle @@ -100,7 +100,7 @@ public void parse(final String data_type, final JSONObject data, final Object te } }).start(); } catch (Exception e){ - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } } diff --git a/app/src/main/java/com/jasonette/seed/Core/JasonRequire.java b/app/src/main/java/com/jasonette/seed/Core/JasonRequire.java index cf050541..c0e72383 100644 --- a/app/src/main/java/com/jasonette/seed/Core/JasonRequire.java +++ b/app/src/main/java/com/jasonette/seed/Core/JasonRequire.java @@ -5,6 +5,8 @@ import android.net.Uri; import android.util.Log; +import com.jasonette.seed.Helper.JasonHelper; + import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -35,7 +37,24 @@ public JasonRequire(String url, CountDownLatch latch, JSONObject refs, OkHttpCli this.context = context; this.client = client; } - public void run(){ + public void run() { + if(this.URL.contains("file://")) { + local(); + } else { + remote(); + } + } + private void local(){ + try { + Object json = JasonHelper.read_json(this.URL, this.context); + private_refs.put(URL, json); + latch.countDown(); + } catch (Exception e){ + latch.countDown(); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); + } + } + private void remote(){ Request request; Request.Builder builder = new Request.Builder(); @@ -108,13 +127,13 @@ public void onResponse(Call call, final Response response) throws IOException { } latch.countDown(); } catch (JSONException e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } }); } catch (Exception e){ - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } } diff --git a/app/src/main/java/com/jasonette/seed/Core/JasonViewActivity.java b/app/src/main/java/com/jasonette/seed/Core/JasonViewActivity.java index 899f8e35..eee702b2 100644 --- a/app/src/main/java/com/jasonette/seed/Core/JasonViewActivity.java +++ b/app/src/main/java/com/jasonette/seed/Core/JasonViewActivity.java @@ -31,6 +31,7 @@ import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; +import android.view.ViewGroup; import android.webkit.CookieManager; import android.webkit.WebChromeClient; import android.webkit.WebSettings; @@ -44,11 +45,15 @@ import com.aurelhubert.ahbottomnavigation.AHBottomNavigation; import com.aurelhubert.ahbottomnavigation.AHBottomNavigationItem; import com.bumptech.glide.Glide; +import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.bumptech.glide.load.resource.drawable.GlideDrawable; import com.bumptech.glide.load.resource.gif.GifDrawable; import com.bumptech.glide.request.animation.GlideAnimation; +import com.bumptech.glide.request.target.GlideDrawableImageViewTarget; import com.bumptech.glide.request.target.SimpleTarget; +import com.eclipsesource.v8.debug.mirror.Frame; import com.jasonette.seed.Component.JasonComponentFactory; +import com.jasonette.seed.Component.JasonImageComponent; import com.jasonette.seed.Helper.JasonHelper; import com.jasonette.seed.Helper.JasonSettings; import com.jasonette.seed.Launcher.Launcher; @@ -61,6 +66,7 @@ import org.json.JSONException; import org.json.JSONObject; +import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.InputStream; import java.lang.reflect.Constructor; @@ -96,6 +102,7 @@ public class JasonViewActivity extends AppCompatActivity { public LinearLayout sectionLayout; public RelativeLayout rootLayout; public WebView webview; + public ImageView backgroundImageView; private AHBottomNavigation bottomNavigation; private LinearLayout footerInput; private View footer_input_textfield; @@ -194,6 +201,7 @@ protected void onCreate(Bundle savedInstanceState) { loadingLayoutParams.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE); loading = new ProgressBar(this); loading.setLayoutParams(loadingLayoutParams); + loading.setVisibility(View.INVISIBLE); rootLayout.addView(loading); // 6. set root layout as content @@ -238,7 +246,7 @@ protected void onCreate(Bundle savedInstanceState) { setup_body(model.rendered); } catch (Exception e){ - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } else { @@ -257,8 +265,10 @@ protected void onCreate(Bundle savedInstanceState) { model.rendered = offline_cache.getJSONObject("rendered"); setup_body(model.rendered); } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } + } else { + model.fetch_local("file://loading.json"); } // Fetch @@ -296,7 +306,7 @@ protected void onPause() { editor.commit(); } } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } super.onPause(); @@ -332,7 +342,7 @@ protected void onResume() { editor.commit(); } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } @@ -349,7 +359,7 @@ protected void onResume() { intent_to_resolve.put("name", "oauth"); intent_to_resolve.put("intent", getIntent()); } catch (JSONException e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } @@ -366,7 +376,7 @@ protected void onResume() { } } } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } super.onResume(); @@ -399,7 +409,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent intent) intent_to_resolve.put("name", requestCode); } } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } @@ -427,17 +437,27 @@ protected void onSaveInstanceState(Bundle savedInstanceState) { /************************************************************* - ## Event Handlers Rule + ## Event Handlers Rule ver2. + + 1. When there's only $show handler + - $show: Handles both initial load and subsequent show events + + 2. When there's only $load handler + - $load: Handles Only the initial load event + + 3. When there are both $show and $load handlers + - $load : handle initial load only + - $show : handle subsequent show events only + + + ## Summary + + $load: + - triggered when view loads for the first time. + $show: + - triggered at load time + subsequent show events (IF $load handler doesn't exist) + - NOT triggered at load time BUT ONLY at subsequent show events (IF $load handler exists) - 1. Pick only ONE Between $load and $show. - - It's because currently action call chains are single threaded on Jason. - - If you include both, only $load will be triggered. - 2. Use $show if you want to keep content constantly in sync without manually refreshing ($show gets triggered whenever the view shows up while you're in the app, either from a parent view or coming back from a child view). - 3. Use $load if you want to trigger ONLY when the view loads (for populating content once) - - You still may want to implement a way to refresh the view manually. You can: - - add some component that calls "$network.request" or "$reload" when touched - - add "$pull" event handler that calls "$network.request" or "$reload" when user makes a pull to refresh action - 4. Use $foreground to handle coming background ($show only gets triggered WHILE you're on the app) *************************************************************/ void onShow(){ @@ -445,17 +465,25 @@ void onShow(){ try { JSONObject head = model.jason.getJSONObject("$jason").getJSONObject("head"); JSONObject events = head.getJSONObject("actions"); - if(events!=null && !events.has("$load")){ - simple_trigger("$show", new JSONObject(), this); - } + simple_trigger("$show", new JSONObject(), this); } catch (Exception e){ - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } void onLoad(){ loaded = true; simple_trigger("$load", new JSONObject(), this); - onShow(); + try { + JSONObject head = model.jason.getJSONObject("$jason").getJSONObject("head"); + JSONObject events = head.getJSONObject("actions"); + if(events!=null && events.has("$load")){ + // nothing + } else { + onShow(); + } + } catch (Exception e){ + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); + } } void onForeground(){ // Not implemented yet @@ -509,7 +537,7 @@ public void onFinished(JSONObject reduced_action) { final_call((JSONObject)action, data, event, context); } } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } }; private void final_call(final JSONObject action, final JSONObject data, final JSONObject event, final Context context) { @@ -519,6 +547,9 @@ private void final_call(final JSONObject action, final JSONObject data, final JS if (action.has("trigger")) { trigger(action, data, event, context); } else { + if(action.length() == 0){ + return; + } // If not trigger, regular call if(action.has("options")){ // if action has options, we need to parse out the options first @@ -531,7 +562,7 @@ public void onFinished(JSONObject parsed_options) { action_with_parsed_options.put("options", parsed_options); exec(action_with_parsed_options, model.state, event, context); } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } }); @@ -542,7 +573,7 @@ public void onFinished(JSONObject parsed_options) { } } } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } @@ -618,7 +649,7 @@ public void onFinished(JSONObject parsed_options) { try { invoke_lambda(action, data, parsed_options, context); } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } }); @@ -630,7 +661,7 @@ public void onFinished(JSONObject parsed_options) { } catch (Exception e){ - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } @@ -659,7 +690,7 @@ private void invoke_lambda(final JSONObject action, final JSONObject data, final call(lambda.toString(), data.toString(), "{}", context); } catch (Exception e){ - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } @@ -672,7 +703,7 @@ public void simple_trigger(final String event_name, JSONObject data, Context con Object action = events.get(event_name); call(action.toString(), data.toString(), "{}", context); } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } @@ -711,7 +742,7 @@ private void exec(final JSONObject action, final JSONObject data, final JSONObje resolved_classname = jrjson.getString("classname"); } } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } @@ -723,20 +754,6 @@ private void exec(final JSONObject action, final JSONObject data, final JSONObje methodName = type.substring(type.lastIndexOf('.') + 1); - // Turn on Loading indicator if it's an async action - if(JasonSettings.isAsync(className, this)){ - JasonViewActivity.this.runOnUiThread(new Runnable() { - @Override - public void run() { - try { - loading.setVisibility(View.VISIBLE); - } catch (Exception e) { - Log.d("Error", e.toString()); - } - } - }); - } - // Look up the module registry to see if there's an instance already // 1. If there is, use that // 2. If there isn't: @@ -761,7 +778,7 @@ public void run() { } } catch (Exception e){ // Action doesn't exist yet - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); try { JSONObject alert_action = new JSONObject(); @@ -777,8 +794,8 @@ public void run() { call(alert_action.toString(), new JSONObject().toString(), "{}", JasonViewActivity.this); - } catch (Exception err){ - Log.d("Error", err.toString()); + } catch (Exception e2){ + Log.d("Warning", e2.getStackTrace()[0].getMethodName() + " : " + e2.toString()); } } } @@ -815,7 +832,7 @@ public void onReceive(Context context, Intent intent) { // call next call(action_string, data.toString(), event_string, JasonViewActivity.this); } catch (Exception e){ - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } }; @@ -840,7 +857,7 @@ public void onReceive(Context context, Intent intent) { // call next call(action_string, data.toString(), event_string, JasonViewActivity.this); } catch (Exception e){ - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } }; @@ -858,7 +875,7 @@ public void onReceive(Context context, Intent intent) { // call next call(action_string, data_string, event_string, JasonViewActivity.this); } catch (Exception e){ - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } }; @@ -1071,7 +1088,7 @@ public void onFinished(JSONObject parsed_options) { } } } catch (Exception e){ - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); JasonHelper.next("error", action, new JSONObject(), new JSONObject(), JasonViewActivity.this); } @@ -1126,7 +1143,7 @@ public void require(final JSONObject action, JSONObject data, final JSONObject e try { latch.await(); } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } JSONObject res = new JSONObject(); @@ -1152,7 +1169,7 @@ public void require(final JSONObject action, JSONObject data, final JSONObject e JasonHelper.next("error", action, new JSONObject(), event, context); } } catch (Exception e){ - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); JasonHelper.next("error", action, new JSONObject(), event, context); } @@ -1198,7 +1215,7 @@ public void onFinished(JSONObject body) { JasonParser.getInstance(this).parse(type, data, template, context); } catch (Exception e){ - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); JasonHelper.next("error", action, new JSONObject(), event, context); } } @@ -1211,7 +1228,7 @@ public void set(final JSONObject action, JSONObject data, JSONObject event, Cont JasonHelper.next("success", action, new JSONObject(), event, context); } catch (Exception e){ - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } @@ -1272,10 +1289,13 @@ public void href(final JSONObject action, JSONObject data, JSONObject event, Con } } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } + public void back ( final JSONObject action, JSONObject data, JSONObject event, Context context){ + finish(); + } public void close ( final JSONObject action, JSONObject data, JSONObject event, Context context){ finish(); } @@ -1289,7 +1309,7 @@ public void run() { swipeLayout.setRefreshing(false); } } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } }); @@ -1302,7 +1322,7 @@ public void reload ( final JSONObject action, JSONObject data, JSONObject event, try { JasonHelper.next("success", action, new JSONObject(), event, context); } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } } @@ -1312,7 +1332,7 @@ public void flush ( final JSONObject action, JSONObject data, JSONObject event, try { JasonHelper.next("success", action, new JSONObject(), event, context); } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } @@ -1325,10 +1345,15 @@ public void snapshot ( final JSONObject action, JSONObject data, final JSONObjec @Override public void run() { ByteArrayOutputStream stream = new ByteArrayOutputStream(); - bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream); + bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream); byte[] byteArray = stream.toByteArray(); - String encoded = Base64.encodeToString(byteArray, Base64.DEFAULT); - String data_uri = "data:image/png;base64," + encoded; + String encoded = Base64.encodeToString(byteArray, Base64.NO_WRAP); + + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append("data:image/jpeg;base64,"); + stringBuilder.append(encoded); + String data_uri = stringBuilder.toString(); + try { JSONObject ret = new JSONObject(); ret.put("data", encoded); @@ -1336,7 +1361,7 @@ public void run() { ret.put("content_type", "image/png"); JasonHelper.next("success", action, ret, event, context); } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } @@ -1349,22 +1374,22 @@ public void run() { * ************************************************************/ - public void build(){ + public void build(JSONObject jason){ // set fetched to true since build() is only called after network.request succeeds fetched = true; - if(model.jason!=null) { + if(jason!=null) { try { // Set up background - if (model.jason.getJSONObject("$jason").has("body")) { + if (jason.getJSONObject("$jason").has("body")) { final JSONObject body; - body = (JSONObject) model.jason.getJSONObject("$jason").getJSONObject("body"); + body = (JSONObject) jason.getJSONObject("$jason").getJSONObject("body"); setup_body(body); } - if (model.jason.getJSONObject("$jason").has("head")) { - final JSONObject head = model.jason.getJSONObject("$jason").getJSONObject("head"); + if (jason.getJSONObject("$jason").has("head")) { + final JSONObject head = jason.getJSONObject("$jason").getJSONObject("head"); if (head.has("data")) { if (head.has("templates")) { if (head.getJSONObject("templates").has("body")) { @@ -1382,18 +1407,18 @@ public void build(){ onLoad(); } catch (JSONException e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } } private void setup_body(final JSONObject body) { - model.rendered = body; - invalidateOptionsMenu(); // Store to offline cache in case head.offline == true try { + model.rendered = body; + invalidateOptionsMenu(); if(model.jason != null && model.jason.has("$jason") && model.jason.getJSONObject("$jason").has("head") && model.jason.getJSONObject("$jason").getJSONObject("head").has("offline")){ SharedPreferences pref = getSharedPreferences("offline", 0); SharedPreferences.Editor editor = pref.edit(); @@ -1408,42 +1433,78 @@ private void setup_body(final JSONObject body) { } } catch (Exception e){ - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } JasonViewActivity.this.runOnUiThread(new Runnable() { @Override public void run() { try { - loading.setVisibility(View.GONE); + // First need to remove all handlers because they will be reattached after render + removeListViewOnItemTouchListeners(); + if(swipeLayout !=null) { swipeLayout.setRefreshing(false); } + sectionLayout.setBackgroundColor(JasonHelper.parse_color("rgb(255,255,255)")); + getWindow().getDecorView().setBackgroundColor(JasonHelper.parse_color("rgb(255,255,255)")); if (body.has("style")) { JSONObject style = body.getJSONObject("style"); if (style.has("background")) { - sectionLayout.setBackgroundColor(JasonHelper.parse_color("rgba(0,0,0,0)")); if(style.get("background") instanceof String){ String background = style.getString("background"); - if(background.matches("http[s]?:\\/\\/.*")) { + JSONObject c = new JSONObject(); + c.put("url", background); + if(background.matches("(file|http[s]?):\\/\\/.*")) { + if(backgroundImageView == null) { + RelativeLayout.LayoutParams rlp = new RelativeLayout.LayoutParams( + RelativeLayout.LayoutParams.MATCH_PARENT, + RelativeLayout.LayoutParams.MATCH_PARENT); + backgroundImageView = new ImageView(JasonViewActivity.this); + rootLayout.addView(backgroundImageView, 0, rlp); + } + + DiskCacheStrategy cacheStrategy = DiskCacheStrategy.RESULT; + // gif doesn't work with RESULT cache strategy + // TODO: Check with Glide V4 if (background.matches(".*\\.gif")) { - with(JasonViewActivity.this).load(background).asGif().into(new SimpleTarget() { - @Override - public void onResourceReady(GifDrawable resource, GlideAnimation glideAnimation) { - sectionLayout.setBackground(resource); + cacheStrategy = DiskCacheStrategy.SOURCE; + } - } - }); + with(JasonViewActivity.this) + .load(JasonImageComponent.resolve_url(c, JasonViewActivity.this)) + .diskCacheStrategy(cacheStrategy) + .centerCrop() + .into(new GlideDrawableImageViewTarget(backgroundImageView) { + + @Override + public void onResourceReady(GlideDrawable resource, GlideAnimation animation) { + super.onResourceReady(resource, animation); + sectionLayout.setBackgroundColor(JasonHelper.parse_color("rgba(0,0,0,0)")); + } + }); + } else if(background == "camera") { + } else if(background.matches("data:image.*")){ + String base64; + if(background.startsWith("data:image/jpeg")){ + base64 = background.substring("data:image/jpeg;base64,".length()); + } else if(background.startsWith("data:image/png")){ + base64 = background.substring("data:image/png;base64,".length()); + } else if(background.startsWith("data:image/gif")){ + base64 = background.substring("data:image/gif;base64,".length()); } else { - with(JasonViewActivity.this).load(background).into(new SimpleTarget() { - @Override - public void onResourceReady(GlideDrawable resource, GlideAnimation glideAnimation) { - sectionLayout.setBackground(resource); - } - }); + base64 = ""; // exception } - } else if(background == "camera") { + byte[] bs = Base64.decode(base64, Base64.NO_WRAP); + + with(JasonViewActivity.this).load(bs).into(new SimpleTarget() { + @Override + public void onResourceReady(GlideDrawable resource, GlideAnimation glideAnimation) { + sectionLayout.setBackground(resource); + } + }); } else { + sectionLayout.setBackgroundColor(JasonHelper.parse_color(background)); getWindow().getDecorView().setBackgroundColor(JasonHelper.parse_color(background)); } } else { @@ -1464,6 +1525,7 @@ public void onResourceReady(GlideDrawable resource, GlideAnimation(100, 100) { @Override @@ -1866,7 +1932,7 @@ public void onResourceReady(Bitmap resource, GlideAnimation glideAnimation) { bottomNavigation.setTitleState(AHBottomNavigation.TitleState.ALWAYS_SHOW); } } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } AHBottomNavigationItem tab_item = bottomNavigation.getItem(index); bottomNavigationItems.put(Integer.valueOf(index), tab_item); @@ -1882,7 +1948,7 @@ public void onResourceReady(Bitmap resource, GlideAnimation glideAnimation) { text = item.getString("text"); bottomNavigation.setTitleState(AHBottomNavigation.TitleState.ALWAYS_SHOW); } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } AHBottomNavigationItem tab_item = bottomNavigation.getItem(i); bottomNavigationItems.put(Integer.valueOf(i), tab_item); @@ -1898,31 +1964,33 @@ public void onResourceReady(Bitmap resource, GlideAnimation glideAnimation) { final JSONObject item = items.getJSONObject(i); final int index = i; if(item.has("image")) { + JSONObject c = new JSONObject(); + c.put("url", item.getString("image")); with(this) - .load(item.getString("image")) - .asBitmap() - .into(new SimpleTarget(100, 100) { - @Override - public void onResourceReady(Bitmap resource, GlideAnimation glideAnimation) { - String text = ""; - try { - if (item.has("text")) { - text = item.getString("text"); - bottomNavigation.setTitleState(AHBottomNavigation.TitleState.ALWAYS_SHOW); - } - } catch (Exception e) { - Log.d("Error", e.toString()); + .load(JasonImageComponent.resolve_url(c, JasonViewActivity.this)) + .asBitmap() + .into(new SimpleTarget(100, 100) { + @Override + public void onResourceReady(Bitmap resource, GlideAnimation glideAnimation) { + String text = ""; + try { + if (item.has("text")) { + text = item.getString("text"); + bottomNavigation.setTitleState(AHBottomNavigation.TitleState.ALWAYS_SHOW); } - Drawable drawable = new BitmapDrawable(getResources(), resource); - AHBottomNavigationItem item = new AHBottomNavigationItem(text, drawable); - bottomNavigationItems.put(Integer.valueOf(index), item); - if(bottomNavigationItems.size() >= items.length()){ - for(int j = 0; j < bottomNavigationItems.size(); j++){ - bottomNavigation.addItem(bottomNavigationItems.get(Integer.valueOf(j))); - } + } catch (Exception e) { + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); + } + Drawable drawable = new BitmapDrawable(getResources(), resource); + AHBottomNavigationItem item = new AHBottomNavigationItem(text, drawable); + bottomNavigationItems.put(Integer.valueOf(index), item); + if(bottomNavigationItems.size() >= items.length()){ + for(int j = 0; j < bottomNavigationItems.size(); j++){ + bottomNavigation.addItem(bottomNavigationItems.get(Integer.valueOf(j))); } } - }); + } + }); } else if(item.has("text")){ String text = ""; @@ -1932,7 +2000,7 @@ public void onResourceReady(Bitmap resource, GlideAnimation glideAnimation) { bottomNavigation.setTitleState(AHBottomNavigation.TitleState.ALWAYS_SHOW); } } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } ColorDrawable d = new ColorDrawable(Color.TRANSPARENT); @@ -1976,7 +2044,7 @@ public boolean onTabSelected(int position, boolean wasSelected) { href(action, new JSONObject(), new JSONObject(), JasonViewActivity.this); } } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } return true; } @@ -1985,7 +2053,7 @@ public boolean onTabSelected(int position, boolean wasSelected) { listView.setClipToPadding(false); listView.setPadding(0,0,0,160); } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } @@ -1997,19 +2065,22 @@ private void setup_layers(JSONArray layers){ View layerView = layer_items.get(j); rootLayout.removeView(layerView); } + layer_items = new ArrayList(); } - for(int i = 0; i toArrayList(JSONArray jsonArray) { list.add(jsonArray.getJSONObject(i)); } } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } return list; } @@ -239,12 +239,13 @@ public static String read_file(String filename, Context context) throws IOExcept return stringBuilder.toString(); } - public static JSONObject read_json(String fn, Context context) throws IOException { + public static Object read_json(String fn, Context context) {// throws IOException { // we're expecting a filename that looks like "file://..." String filename = fn.replace("file://", "file/"); String jr = null; + Object ret; try { InputStream is = context.getAssets().open(filename); int size = is.available(); @@ -252,11 +253,23 @@ public static JSONObject read_json(String fn, Context context) throws IOExceptio is.read(buffer); is.close(); jr = new String(buffer, "UTF-8"); - return new JSONObject(jr); + + + if(jr.trim().startsWith("[")) { + // array + ret = new JSONArray(jr); + } else if(jr.trim().startsWith("{")){ + // object + ret = new JSONObject(jr); + } else { + // string + ret = jr; + } } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); return new JSONObject(); } + return ret; } @@ -272,7 +285,7 @@ public static void permission_exception(String actionName, Context context) { intent.putExtra("action", alert_action.toString()); LocalBroadcastManager.getInstance(context).sendBroadcast(intent); } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } @@ -330,7 +343,7 @@ public static void dispatchIntent(String name, JSONObject action, JSONObject dat ((Launcher) ((JasonViewActivity) context).getApplicationContext()).once(name, handler); } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } if (intent != null) { @@ -362,6 +375,7 @@ public static JSONObject preserve(JSONObject callback, JSONObject action, JSONOb return callback; } catch (Exception e) { Log.d("Error", "wasn't able to preserve stack"); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); return callback; } } diff --git a/app/src/main/java/com/jasonette/seed/Helper/JasonImageHelper.java b/app/src/main/java/com/jasonette/seed/Helper/JasonImageHelper.java index 840f907f..7ae43100 100644 --- a/app/src/main/java/com/jasonette/seed/Helper/JasonImageHelper.java +++ b/app/src/main/java/com/jasonette/seed/Helper/JasonImageHelper.java @@ -56,7 +56,7 @@ public void load(){ Uri bitmapUri = Uri.fromFile(file); this.listener.onLoaded(this.data, bitmapUri); } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } @@ -121,7 +121,7 @@ public void onResourceReady(Bitmap bitmap, GlideAnimation anim) { listener.onLoaded(byteArray, bitmapUri); } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } @@ -129,7 +129,7 @@ public void onResourceReady(Bitmap bitmap, GlideAnimation anim) { } } catch (Exception e){ - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } } diff --git a/app/src/main/java/com/jasonette/seed/Launcher/Launcher.java b/app/src/main/java/com/jasonette/seed/Launcher/Launcher.java index 2abab049..3e78d696 100644 --- a/app/src/main/java/com/jasonette/seed/Launcher/Launcher.java +++ b/app/src/main/java/com/jasonette/seed/Launcher/Launcher.java @@ -3,23 +3,63 @@ import android.app.Application; import android.content.Context; import android.content.Intent; +import android.content.SharedPreferences; +import android.content.res.Resources; +import android.os.Build; +import android.util.DisplayMetrics; import android.util.Log; +import android.view.Display; +import android.view.WindowManager; import com.bumptech.glide.request.target.ViewTarget; import com.jasonette.seed.Core.JasonViewActivity; import com.jasonette.seed.Helper.JasonHelper; import com.jasonette.seed.R; +import org.json.JSONArray; import org.json.JSONObject; +import org.json.JSONTokener; import java.io.InputStream; import java.lang.reflect.Constructor; import java.lang.reflect.Method; +import java.util.Locale; +import java.util.Map; import static android.R.attr.action; public class Launcher extends Application { private JSONObject handlers; + private JSONObject global; + private JSONObject env; + + public JSONObject getEnv(){ + return this.env; + } + public void setEnv(String key, Object json) { + try { + this.env.put(key, json); + } catch (Exception e) { + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); + } + } + public JSONObject getGlobal(){ + return this.global; + } + public void setGlobal(String key, Object json){ + try { + this.global.put(key, json); + } catch (Exception e) { + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); + } + } + public void resetGlobal(String key){ + try { + this.global.remove(key); + } catch (Exception e) { + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); + } + } public Launcher() { } @@ -58,8 +98,49 @@ public void onCreate() { // handler init handlers = new JSONObject(); + // $global + SharedPreferences global_pref = getSharedPreferences("global", 0); + this.global = new JSONObject(); + if(global_pref != null){ + Map map = global_pref.getAll(); + for (Map.Entry entry : map.entrySet()) { + try { + String val = (String) entry.getValue(); + Object json = new JSONTokener(val).nextValue(); + if (json instanceof JSONObject) { + this.global.put(entry.getKey(), new JSONObject(val)); + } else if (json instanceof JSONArray) { + this.global.put(entry.getKey(), new JSONArray(val)); + } + } catch (Exception e){ + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); + } + } + } + + this.env = new JSONObject(); + + // device info + JSONObject device = new JSONObject(); + DisplayMetrics displayMetrics = Resources.getSystem().getDisplayMetrics(); + + float width = displayMetrics.widthPixels / displayMetrics.density; + float height = displayMetrics.heightPixels / displayMetrics.density; + device.put("width", width); + device.put("height", height); + device.put("language", Locale.getDefault().toString()); + + JSONObject os = new JSONObject(); + os.put("name", "android"); + os.put("version", Build.VERSION.RELEASE); + os.put("sdk", Build.VERSION.SDK_INT); + + device.put("os", os); + + this.env.put("device", device); + } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } @@ -78,7 +159,7 @@ public void on(String key, JSONObject val){ store.put("content", val); handlers.put(key, store); } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } public void once(String key, JSONObject val){ @@ -88,7 +169,7 @@ public void once(String key, JSONObject val){ store.put("content", val); handlers.put(key, store); } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } public void trigger(JSONObject intent_to_resolve, JasonViewActivity context) { @@ -184,7 +265,7 @@ private JSONObject getHandler(String key){ return handler.getJSONObject("content"); } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); return new JSONObject(); } } diff --git a/app/src/main/java/com/jasonette/seed/Section/ItemAdapter.java b/app/src/main/java/com/jasonette/seed/Section/ItemAdapter.java index 897ae42b..1237141b 100644 --- a/app/src/main/java/com/jasonette/seed/Section/ItemAdapter.java +++ b/app/src/main/java/com/jasonette/seed/Section/ItemAdapter.java @@ -409,6 +409,7 @@ public LinearLayout buildLayout(LinearLayout layout, JSONObject item, JSONObject // Layout styling String type = item.getString("type"); JSONObject style = JasonHelper.style(item, root_context); + layout.setBackgroundColor(JasonHelper.parse_color("rgba(0,0,0,0)")); JSONArray components; if (type.equalsIgnoreCase("vertical") || type.equalsIgnoreCase("horizontal")) { @@ -569,7 +570,7 @@ private void add_spacing(View view, JSONObject item, String type) { } view.requestLayout(); } catch (Exception e) { - Log.d("Error", e.toString()); + Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString()); } } diff --git a/build.gradle b/build.gradle index 84b34ab2..61297c85 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.3.0' + classpath 'com.android.tools.build:gradle:2.3.3' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files