use of org.json.JSONObject in project jpHolo by teusink.
the class Globalization method getCurrencyPattern.
/*
* @Description: Returns a pattern string for formatting and parsing currency values according to the client's
* user preferences and ISO 4217 currency code.
* @Return: JSONObject
* Object.pattern {String}: The currency pattern for formatting and parsing currency values.
* The patterns follow Unicode Technical Standard #35
* http://unicode.org/reports/tr35/tr35-4.html
* Object.code {String}: The ISO 4217 currency code for the pattern.
* Object.fraction {Number}: The number of fractional digits to use when parsing and
* formatting currency.
* Object.rounding {Number}: The rounding increment to use when parsing and formatting.
* Object.decimal: {String}: The decimal symbol to use for parsing and formatting.
* Object.grouping: {String}: The grouping symbol to use for parsing and formatting.
*
* @throws: GlobalizationError.FORMATTING_ERROR
*/
private JSONObject getCurrencyPattern(JSONArray options) throws GlobalizationError {
JSONObject obj = new JSONObject();
try {
//get ISO 4217 currency code
String code = options.getJSONObject(0).getString(CURRENCYCODE);
//uses java.text.DecimalFormat to format value
DecimalFormat fmt = (DecimalFormat) DecimalFormat.getCurrencyInstance(Locale.getDefault());
//set currency format
Currency currency = Currency.getInstance(code);
fmt.setCurrency(currency);
//return properties
obj.put("pattern", fmt.toPattern());
obj.put("code", currency.getCurrencyCode());
obj.put("fraction", fmt.getMinimumFractionDigits());
obj.put("rounding", Integer.valueOf(0));
obj.put("decimal", String.valueOf(fmt.getDecimalFormatSymbols().getDecimalSeparator()));
obj.put("grouping", String.valueOf(fmt.getDecimalFormatSymbols().getGroupingSeparator()));
return obj;
} catch (Exception ge) {
throw new GlobalizationError(GlobalizationError.FORMATTING_ERROR);
}
}
use of org.json.JSONObject in project jpHolo by teusink.
the class Globalization method getNumberPattern.
/*
* @Description: Returns a pattern string for formatting and parsing numbers according to the client's user
* preferences.
* @Return: JSONObject
* Object.pattern {String}: The number pattern for formatting and parsing numbers.
* The patterns follow Unicode Technical Standard #35.
* http://unicode.org/reports/tr35/tr35-4.html
* Object.symbol {String}: The symbol to be used when formatting and parsing
* e.g., percent or currency symbol.
* Object.fraction {Number}: The number of fractional digits to use when parsing and
* formatting numbers.
* Object.rounding {Number}: The rounding increment to use when parsing and formatting.
* Object.positive {String}: The symbol to use for positive numbers when parsing and formatting.
* Object.negative: {String}: The symbol to use for negative numbers when parsing and formatting.
* Object.decimal: {String}: The decimal symbol to use for parsing and formatting.
* Object.grouping: {String}: The grouping symbol to use for parsing and formatting.
*
* @throws: GlobalizationError.PATTERN_ERROR
*/
private JSONObject getNumberPattern(JSONArray options) throws GlobalizationError {
JSONObject obj = new JSONObject();
try {
//uses java.text.DecimalFormat to format value
//default format
DecimalFormat fmt = (DecimalFormat) DecimalFormat.getInstance(Locale.getDefault());
String symbol = String.valueOf(fmt.getDecimalFormatSymbols().getDecimalSeparator());
//get Date value + options (if available)
if (options.getJSONObject(0).length() > 0) {
//options were included
if (!((JSONObject) options.getJSONObject(0).get(OPTIONS)).isNull(TYPE)) {
String fmtOpt = (String) ((JSONObject) options.getJSONObject(0).get(OPTIONS)).get(TYPE);
if (fmtOpt.equalsIgnoreCase(CURRENCY)) {
fmt = (DecimalFormat) DecimalFormat.getCurrencyInstance(Locale.getDefault());
symbol = fmt.getDecimalFormatSymbols().getCurrencySymbol();
} else if (fmtOpt.equalsIgnoreCase(PERCENT)) {
fmt = (DecimalFormat) DecimalFormat.getPercentInstance(Locale.getDefault());
symbol = String.valueOf(fmt.getDecimalFormatSymbols().getPercent());
}
}
}
//return properties
obj.put("pattern", fmt.toPattern());
obj.put("symbol", symbol);
obj.put("fraction", fmt.getMinimumFractionDigits());
obj.put("rounding", Integer.valueOf(0));
obj.put("positive", fmt.getPositivePrefix());
obj.put("negative", fmt.getNegativePrefix());
obj.put("decimal", String.valueOf(fmt.getDecimalFormatSymbols().getDecimalSeparator()));
obj.put("grouping", String.valueOf(fmt.getDecimalFormatSymbols().getGroupingSeparator()));
return obj;
} catch (Exception ge) {
throw new GlobalizationError(GlobalizationError.PATTERN_ERROR);
}
}
use of org.json.JSONObject in project jpHolo by teusink.
the class InAppBrowser method closeDialog.
/**
* Closes the dialog
*/
public void closeDialog() {
final WebView childView = this.inAppWebView;
// closeDialog() is called by other native code.
if (childView == null) {
return;
}
this.cordova.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
childView.setWebViewClient(new WebViewClient() {
// NB: wait for about:blank before dismissing
public void onPageFinished(WebView view, String url) {
if (dialog != null) {
dialog.dismiss();
}
}
});
// NB: From SDK 19: "If you call methods on WebView from any thread
// other than your app's UI thread, it can cause unexpected results."
// http://developer.android.com/guide/webapps/migrating.html#Threads
childView.loadUrl("about:blank");
}
});
try {
JSONObject obj = new JSONObject();
obj.put("type", EXIT_EVENT);
sendUpdate(obj, false);
} catch (JSONException ex) {
Log.d(LOG_TAG, "Should never happen");
}
}
use of org.json.JSONObject in project jpHolo by teusink.
the class AndroidPreferences method execute.
@Override
public boolean execute(final String action, final JSONArray args, final CallbackContext callbackContext) {
cordova.getThreadPool().execute(new Runnable() {
@Override
public void run() {
try {
final JSONObject params = args.getJSONObject(0);
final String preferenceLib = params.getString("preferenceLib");
final String preferenceName = params.getString("preferenceName");
final String preferenceValue = params.getString("preferenceValue");
if (preferenceLib != null && preferenceName != null && preferenceValue != null && !preferenceLib.equals("") && !preferenceName.equals("")) {
final SharedPreferences settings = cordova.getActivity().getSharedPreferences(preferenceLib, Context.MODE_PRIVATE);
final SharedPreferences.Editor editor = settings.edit();
if (action.equals("set") && settings != null && editor != null) {
editor.putString(preferenceName, preferenceValue);
editor.commit();
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK));
} else if (action.equals("get") && settings != null && editor != null) {
final String returnValue = settings.getString(preferenceName, "");
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, returnValue));
} else {
Log.e(LOG_PROV, LOG_NAME + "Error: " + PluginResult.Status.INVALID_ACTION);
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.INVALID_ACTION));
}
} else {
Log.e(LOG_PROV, LOG_NAME + "Error: " + PluginResult.Status.ERROR);
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR));
}
} catch (final JSONException e) {
e.printStackTrace();
Log.e(LOG_PROV, LOG_NAME + "Error: " + PluginResult.Status.JSON_EXCEPTION);
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
}
}
});
return true;
}
use of org.json.JSONObject in project jpHolo by teusink.
the class Capture method execute.
//private CordovaInterface cordova;
// public void setContext(Context mCtx)
// {
// if (CordovaInterface.class.isInstance(mCtx))
// cordova = (CordovaInterface) mCtx;
// else
// LOG.d(LOG_TAG, "ERROR: You must use the CordovaInterface for this to work correctly. Please implement it in your activity");
// }
@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
this.callbackContext = callbackContext;
this.limit = 1;
this.duration = 0;
this.results = new JSONArray();
JSONObject options = args.optJSONObject(0);
if (options != null) {
limit = options.optLong("limit", 1);
duration = options.optInt("duration", 0);
}
if (action.equals("getFormatData")) {
JSONObject obj = getFormatData(args.getString(0), args.getString(1));
callbackContext.success(obj);
return true;
} else if (action.equals("captureAudio")) {
this.captureAudio();
} else if (action.equals("captureImage")) {
this.captureImage();
} else if (action.equals("captureVideo")) {
this.captureVideo(duration);
} else {
return false;
}
return true;
}
Aggregations