From e61a115a29626b3957cd8279e19f8a05249eea2a Mon Sep 17 00:00:00 2001 From: Michael Herzberg Date: Tue, 18 Aug 2015 14:37:47 +0200 Subject: [PATCH 1/2] Updated Featherweight for thesis. --- DVHMA-Featherweight/www/js/index.js | 50 ++++++++---------- plugins/DVHMA-Storage/plugin.xml | 2 +- .../src/android/DVHMAStorage.java | 17 ++++-- plugins/DVHMA-Storage/www/DVHMA-Storage.js | 52 +++++-------------- plugins/DVHMA-WebIntent/plugin.xml | 2 +- .../src/android/WebIntent.java | 43 +-------------- plugins/DVHMA-WebIntent/www/webintent.js | 46 ++++------------ 7 files changed, 60 insertions(+), 152 deletions(-) diff --git a/DVHMA-Featherweight/www/js/index.js b/DVHMA-Featherweight/www/js/index.js index b3a5e81..b2f57dc 100644 --- a/DVHMA-Featherweight/www/js/index.js +++ b/DVHMA-Featherweight/www/js/index.js @@ -17,34 +17,28 @@ function onDeviceReady() { checkForExtraText(); } +function logError(error) { + console.log(error); +} + function checkForExtraText() { - window.plugins.webintent.hasExtra(window.plugins.webintent.EXTRA_TEXT, function(hasExtra) { - if (hasExtra) { - window.plugins.webintent.getExtra(window.plugins.webintent.EXTRA_TEXT, function(content) { - window.plugins.webintent.hasExtra(window.plugins.webintent.EXTRA_SUBJECT, function(hasSubjectExtra) { - if (hasSubjectExtra) { - window.plugins.webintent.getExtra(window.plugins.webintent.EXTRA_SUBJECT, function(title) { - var param = {}; - param.title = title; - param.content = content; - window.todo.create([param], reloadItems, console.log); - }, console.log); - } else { - var param = {}; - param.title = "NewTitle"; - param.content = content; - window.todo.create([param], reloadItems, console.log); - } - }, console.log); - }, console.log); - } else { - window.todo.get(reloadItems, console.log); - } - }, console.log); + window.webintent(window.webintent.EXTRA_TEXT, function(content) { + window.webintent(window.webintent.EXTRA_SUBJECT, function(title) { + var param = {}; + param.title = title; + param.content = content; + window.todo.create([param], reloadItems, logError); + }, function(error) { + var param = {}; + param.title = "NewTitle"; + param.content = content; + window.todo.create([param], reloadItems, logError); + }); + }); } function onRemoveItem(e) { - window.todo.delete([e.target.parentNode.parentNode.dataset.id], reloadItems, console.log); + window.todo.delete([e.target.parentNode.parentNode.dataset.id], reloadItems, logError); } function onEditItem(e) { @@ -60,8 +54,8 @@ function onEditItem(e) { if (newContent == null) { newContent = oldContent; } - window.todo.edit([id, {"title" : newTitle, "content" : newContent}], reloadItems, console.log); - }, alert); + window.todo.edit([id, {"title" : newTitle, "content" : newContent}], reloadItems, logError); + }, logError); } function onLoadContent(e) { @@ -76,7 +70,7 @@ function onLoadContent(e) { contentDiv.parentNode.getElementsByTagName("img")[0].src = "img/ic_action_collapse.png"; contentDiv.innerHTML = items[id]["content"]; contentDiv.dataset.loaded = true; - }, console.log); + }, logError); } } @@ -132,7 +126,7 @@ function reloadItems(items) { } function onNewItemClick() { - window.todo.create([{"title" : "NewTitle", "content" : "New Content"}], reloadItems, console.log); + window.todo.create([{"title" : "NewTitle", "content" : "New Content"}], reloadItems, logError); } document.addEventListener("deviceready", onDeviceReady); diff --git a/plugins/DVHMA-Storage/plugin.xml b/plugins/DVHMA-Storage/plugin.xml index f9c7723..1dd48a4 100644 --- a/plugins/DVHMA-Storage/plugin.xml +++ b/plugins/DVHMA-Storage/plugin.xml @@ -4,7 +4,7 @@ version="1.0.0"> DVHMA-Storage DVHMA Storage Backend - + diff --git a/plugins/DVHMA-Storage/src/android/DVHMAStorage.java b/plugins/DVHMA-Storage/src/android/DVHMAStorage.java index 4b488cd..0817c71 100644 --- a/plugins/DVHMA-Storage/src/android/DVHMAStorage.java +++ b/plugins/DVHMA-Storage/src/android/DVHMAStorage.java @@ -57,6 +57,10 @@ public class DVHMAStorage extends CordovaPlugin { return false; } } + private void get(CordovaArgs args, CallbackContext callbackContext) { + JSONArray result = queryDatabase(); + callbackContext.success(result); + } private void edit(CordovaArgs args, CallbackContext callbackContext) { int index; @@ -77,10 +81,11 @@ public class DVHMAStorage extends CordovaPlugin { db.execSQL("UPDATE " + DVHMAStorageDbHelper.TABLE_NAME + " SET title='" + newTitle + "',content='" + newContent + "' WHERE id=" + c.getInt(c.getColumnIndex("id")) + ";"); db.close(); - get(null, callbackContext); + JSONArray result = queryDatabase(); + callbackContext.success(result); } - private void get(CordovaArgs args, CallbackContext callbackContext) { + private JSONArray queryDatabase() { SQLiteDatabase db = mDbHelper.getWritableDatabase(); JSONArray array = new JSONArray(); Cursor c = db.rawQuery("SELECT * FROM " + DVHMAStorageDbHelper.TABLE_NAME + ";", null); @@ -98,7 +103,7 @@ public class DVHMAStorage extends CordovaPlugin { } c.close(); db.close(); - callbackContext.success(array); + return array; } private void delete(CordovaArgs args, CallbackContext callbackContext) { @@ -117,7 +122,8 @@ public class DVHMAStorage extends CordovaPlugin { c.close(); db.close(); - get(null, callbackContext); + JSONArray result = queryDatabase(); + callbackContext.success(result); } private void create(CordovaArgs args, CallbackContext callbackContext) { @@ -135,6 +141,7 @@ public class DVHMAStorage extends CordovaPlugin { db.execSQL("INSERT INTO " + DVHMAStorageDbHelper.TABLE_NAME + " (title,content) VALUES('" + newTitle + "','" + newContent + "');"); db.close(); - get(null, callbackContext); + JSONArray result = queryDatabase(); + callbackContext.success(result); } } diff --git a/plugins/DVHMA-Storage/www/DVHMA-Storage.js b/plugins/DVHMA-Storage/www/DVHMA-Storage.js index dbd5c39..1549fee 100644 --- a/plugins/DVHMA-Storage/www/DVHMA-Storage.js +++ b/plugins/DVHMA-Storage/www/DVHMA-Storage.js @@ -12,46 +12,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +module.exports.create = function(params, success, fail) { + return cordova.exec(success, fail, 'DVHMAStorage', 'create', params); +} -(function(cordova){ - var DVHMAStorage = function() { +module.exports.get = function(success, fail) { + return cordova.exec(success, fail, 'DVHMAStorage', 'get', []); +} - }; - - DVHMAStorage.prototype.create = function(params, success, fail) { - return cordova.exec(function(args) { - success(args); - }, function(args) { - fail(args); - }, 'DVHMAStorage', 'create', params); - } - - DVHMAStorage.prototype.get = function(success, fail) { - return cordova.exec(function(args) { - success(args); - }, function(args) { - fail(args); - }, 'DVHMAStorage', 'get', []); - } - DVHMAStorage.prototype.delete = function(params, success, fail) { - return cordova.exec(function(args) { - success(args); - }, function(args) { - fail(args); - }, 'DVHMAStorage', 'delete', params); - } - - DVHMAStorage.prototype.edit = function(params, success, fail) { - return cordova.exec(function(args) { - success(args); - }, function(args) { - fail(args); - }, 'DVHMAStorage', 'edit', params); - } +module.exports.delete = function(params, success, fail) { + return cordova.exec(success, fail, 'DVHMAStorage', 'delete', params); +} - window.todo = new DVHMAStorage(); - - // backwards compatibility - window.plugins = window.plugins || {}; - window.plugins.webintent = window.webintent; -})(window.PhoneGap || window.Cordova || window.cordova); +module.exports.edit = function(params, success, fail) { + return cordova.exec(success, fail, 'DVHMAStorage', 'edit', params); +} diff --git a/plugins/DVHMA-WebIntent/plugin.xml b/plugins/DVHMA-WebIntent/plugin.xml index 93ed060..0eb6a64 100644 --- a/plugins/DVHMA-WebIntent/plugin.xml +++ b/plugins/DVHMA-WebIntent/plugin.xml @@ -9,7 +9,7 @@ cordova,webintent - + diff --git a/plugins/DVHMA-WebIntent/src/android/WebIntent.java b/plugins/DVHMA-WebIntent/src/android/WebIntent.java index aaaadb8..016f624 100644 --- a/plugins/DVHMA-WebIntent/src/android/WebIntent.java +++ b/plugins/DVHMA-WebIntent/src/android/WebIntent.java @@ -1,20 +1,13 @@ package com.borismus.webintent; -import java.util.HashMap; -import java.util.Map; - import org.apache.cordova.CordovaActivity; import org.json.JSONArray; import org.json.JSONException; -import org.json.JSONObject; import android.content.Intent; -import android.net.Uri; -import android.text.Html; import org.apache.cordova.CallbackContext; import org.apache.cordova.CordovaPlugin; -import org.apache.cordova.CordovaResourceApi; import org.apache.cordova.PluginResult; /** @@ -29,69 +22,35 @@ import org.apache.cordova.PluginResult; */ public class WebIntent extends CordovaPlugin { - private CallbackContext onNewIntentCallbackContext = null; - - // public boolean execute(String action, JSONArray args, String callbackId) { @Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) { try { - - if (action.equals("hasExtra")) { - return hasExtra(args, callbackContext); - } else if (action.equals("getExtra")) { + if (action.equals("getExtra")) { return getExtra(args, callbackContext); } - // return new PluginResult(PluginResult.Status.INVALID_ACTION); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.INVALID_ACTION)); return false; } catch (JSONException e) { e.printStackTrace(); String errorMessage = e.getMessage(); - // return new PluginResult(PluginResult.Status.JSON_EXCEPTION); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION, errorMessage)); return false; } } - boolean hasExtra(JSONArray args, CallbackContext callbackContext) throws JSONException { - if (args.length() != 1) { - // return new PluginResult(PluginResult.Status.INVALID_ACTION); - callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.INVALID_ACTION)); - return false; - } - Intent i = ((CordovaActivity) this.cordova.getActivity()).getIntent(); - String extraName = args.getString(0); - // return new PluginResult(PluginResult.Status.OK, i.hasExtra(extraName)); - callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, i.hasExtra(extraName))); - return true; - } - boolean getExtra(JSONArray args, CallbackContext callbackContext) throws JSONException { if (args.length() != 1) { - // return new PluginResult(PluginResult.Status.INVALID_ACTION); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.INVALID_ACTION)); return false; } Intent i = ((CordovaActivity) this.cordova.getActivity()).getIntent(); String extraName = args.getString(0); if (i.hasExtra(extraName)) { - // return new PluginResult(PluginResult.Status.OK, i.getStringExtra(extraName)); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, i.getStringExtra(extraName))); return true; } else { - // return new PluginResult(PluginResult.Status.ERROR); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR)); return false; } } - - @Override - public void onNewIntent(Intent intent) { - - if (this.onNewIntentCallbackContext != null) { - PluginResult result = new PluginResult(PluginResult.Status.OK, intent.getDataString()); - result.setKeepCallback(true); - this.onNewIntentCallbackContext.sendPluginResult(result); - } - } } diff --git a/plugins/DVHMA-WebIntent/www/webintent.js b/plugins/DVHMA-WebIntent/www/webintent.js index 6f54991..8ab228e 100644 --- a/plugins/DVHMA-WebIntent/www/webintent.js +++ b/plugins/DVHMA-WebIntent/www/webintent.js @@ -3,39 +3,15 @@ * Copyright (c) Boris Smus 2010 * */ -(function(cordova) { - var WebIntent = function() { +module.exports = function(params, success, fail) { + return cordova.exec(success, fail, 'WebIntent', 'getExtra', [params]); +}; - }; - - WebIntent.prototype.ACTION_SEND = "android.intent.action.SEND"; - WebIntent.prototype.ACTION_VIEW= "android.intent.action.VIEW"; - WebIntent.prototype.EXTRA_TEXT = "android.intent.extra.TEXT"; - WebIntent.prototype.EXTRA_SUBJECT = "android.intent.extra.SUBJECT"; - WebIntent.prototype.EXTRA_STREAM = "android.intent.extra.STREAM"; - WebIntent.prototype.EXTRA_EMAIL = "android.intent.extra.EMAIL"; - WebIntent.prototype.ACTION_CALL = "android.intent.action.CALL"; - WebIntent.prototype.ACTION_SENDTO = "android.intent.action.SENDTO"; - - WebIntent.prototype.hasExtra = function(params, success, fail) { - return cordova.exec(function(args) { - success(args); - }, function(args) { - fail(args); - }, 'WebIntent', 'hasExtra', [params]); - }; - - WebIntent.prototype.getExtra = function(params, success, fail) { - return cordova.exec(function(args) { - success(args); - }, function(args) { - fail(args); - }, 'WebIntent', 'getExtra', [params]); - }; - - window.webintent = new WebIntent(); - - // backwards compatibility - window.plugins = window.plugins || {}; - window.plugins.webintent = window.webintent; -})(window.PhoneGap || window.Cordova || window.cordova); +module.exports.ACTION_SEND = "android.intent.action.SEND"; +module.exports.ACTION_VIEW= "android.intent.action.VIEW"; +module.exports.EXTRA_TEXT = "android.intent.extra.TEXT"; +module.exports.EXTRA_SUBJECT = "android.intent.extra.SUBJECT"; +module.exports.EXTRA_STREAM = "android.intent.extra.STREAM"; +module.exports.EXTRA_EMAIL = "android.intent.extra.EMAIL"; +module.exports.ACTION_CALL = "android.intent.action.CALL"; +module.exports.ACTION_SENDTO = "android.intent.action.SENDTO"; \ No newline at end of file From bc9ee60385a1b364d5cf6f79aef5c3a2c6babd64 Mon Sep 17 00:00:00 2001 From: Michael Herzberg Date: Thu, 20 Aug 2015 11:32:44 +0200 Subject: [PATCH 2/2] Added missing window.todo.get call at startup. --- DVHMA-Featherweight/www/js/index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/DVHMA-Featherweight/www/js/index.js b/DVHMA-Featherweight/www/js/index.js index b2f57dc..b5cccb7 100644 --- a/DVHMA-Featherweight/www/js/index.js +++ b/DVHMA-Featherweight/www/js/index.js @@ -34,6 +34,8 @@ function checkForExtraText() { param.content = content; window.todo.create([param], reloadItems, logError); }); + }, function(error) { + window.todo.get(reloadItems, logError); }); }