mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-22 00:32:55 +08:00
Port Globalization to CordovaPlugin.
This commit is contained in:
parent
c55fd06b99
commit
7379d2135d
@ -33,7 +33,8 @@ import java.util.Locale;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
|
||||||
import org.apache.cordova.api.Plugin;
|
import org.apache.cordova.api.CallbackContext;
|
||||||
|
import org.apache.cordova.api.CordovaPlugin;
|
||||||
import org.apache.cordova.api.PluginResult;
|
import org.apache.cordova.api.PluginResult;
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
@ -44,7 +45,7 @@ import android.text.format.Time;
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class Globalization extends Plugin {
|
public class Globalization extends CordovaPlugin {
|
||||||
//GlobalizationCommand Plugin Actions
|
//GlobalizationCommand Plugin Actions
|
||||||
public static final String GETLOCALENAME = "getLocaleName";
|
public static final String GETLOCALENAME = "getLocaleName";
|
||||||
public static final String DATETOSTRING = "dateToString";
|
public static final String DATETOSTRING = "dateToString";
|
||||||
@ -85,54 +86,45 @@ public class Globalization extends Plugin {
|
|||||||
public static final String CURRENCYCODE = "currencyCode";
|
public static final String CURRENCYCODE = "currencyCode";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PluginResult execute(String action, JSONArray data, String callbackId) {
|
public boolean execute(String action, JSONArray data, CallbackContext callbackContext) {
|
||||||
PluginResult.Status status = PluginResult.Status.OK;
|
|
||||||
JSONObject obj = new JSONObject();
|
JSONObject obj = new JSONObject();
|
||||||
|
|
||||||
try{
|
try{
|
||||||
if (action.equals(GETLOCALENAME)){
|
if (action.equals(GETLOCALENAME)){
|
||||||
obj = getLocaleName();
|
obj = getLocaleName();
|
||||||
return new PluginResult(status, obj);
|
|
||||||
}else if (action.equals(GETPREFERREDLANGUAGE)){
|
}else if (action.equals(GETPREFERREDLANGUAGE)){
|
||||||
obj = getPreferredLanguage();
|
obj = getPreferredLanguage();
|
||||||
return new PluginResult(status, obj);
|
|
||||||
} else if (action.equalsIgnoreCase(DATETOSTRING)) {
|
} else if (action.equalsIgnoreCase(DATETOSTRING)) {
|
||||||
obj = getDateToString(data);
|
obj = getDateToString(data);
|
||||||
return new PluginResult(PluginResult.Status.OK, obj);
|
|
||||||
}else if(action.equalsIgnoreCase(STRINGTODATE)){
|
}else if(action.equalsIgnoreCase(STRINGTODATE)){
|
||||||
obj = getStringtoDate(data);
|
obj = getStringtoDate(data);
|
||||||
return new PluginResult(PluginResult.Status.OK, obj);
|
|
||||||
}else if(action.equalsIgnoreCase(GETDATEPATTERN)){
|
}else if(action.equalsIgnoreCase(GETDATEPATTERN)){
|
||||||
obj = getDatePattern(data);
|
obj = getDatePattern(data);
|
||||||
return new PluginResult(PluginResult.Status.OK, obj);
|
|
||||||
}else if(action.equalsIgnoreCase(GETDATENAMES)){
|
}else if(action.equalsIgnoreCase(GETDATENAMES)){
|
||||||
obj = getDateNames(data);
|
obj = getDateNames(data);
|
||||||
return new PluginResult(PluginResult.Status.OK, obj);
|
|
||||||
}else if(action.equalsIgnoreCase(ISDAYLIGHTSAVINGSTIME)){
|
}else if(action.equalsIgnoreCase(ISDAYLIGHTSAVINGSTIME)){
|
||||||
obj = getIsDayLightSavingsTime(data);
|
obj = getIsDayLightSavingsTime(data);
|
||||||
return new PluginResult(PluginResult.Status.OK, obj);
|
|
||||||
}else if(action.equalsIgnoreCase(GETFIRSTDAYOFWEEK)){
|
}else if(action.equalsIgnoreCase(GETFIRSTDAYOFWEEK)){
|
||||||
obj = getFirstDayOfWeek(data);
|
obj = getFirstDayOfWeek(data);
|
||||||
return new PluginResult(PluginResult.Status.OK, obj);
|
|
||||||
}else if(action.equalsIgnoreCase(NUMBERTOSTRING)){
|
}else if(action.equalsIgnoreCase(NUMBERTOSTRING)){
|
||||||
obj = getNumberToString(data);
|
obj = getNumberToString(data);
|
||||||
return new PluginResult(PluginResult.Status.OK, obj);
|
|
||||||
}else if(action.equalsIgnoreCase(STRINGTONUMBER)){
|
}else if(action.equalsIgnoreCase(STRINGTONUMBER)){
|
||||||
obj = getStringToNumber(data);
|
obj = getStringToNumber(data);
|
||||||
return new PluginResult(PluginResult.Status.OK, obj);
|
|
||||||
}else if(action.equalsIgnoreCase(GETNUMBERPATTERN)){
|
}else if(action.equalsIgnoreCase(GETNUMBERPATTERN)){
|
||||||
obj = getNumberPattern(data);
|
obj = getNumberPattern(data);
|
||||||
return new PluginResult(PluginResult.Status.OK, obj);
|
|
||||||
}else if(action.equalsIgnoreCase(GETCURRENCYPATTERN)){
|
}else if(action.equalsIgnoreCase(GETCURRENCYPATTERN)){
|
||||||
obj = getCurrencyPattern(data);
|
obj = getCurrencyPattern(data);
|
||||||
return new PluginResult(PluginResult.Status.OK, obj);
|
}else {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
callbackContext.success(obj);
|
||||||
}catch (GlobalizationError ge){
|
}catch (GlobalizationError ge){
|
||||||
return new PluginResult(PluginResult.Status.ERROR, ge.toJson());
|
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, ge.toJson()));
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
|
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
|
||||||
}
|
}
|
||||||
return new PluginResult(PluginResult.Status.INVALID_ACTION);
|
return true;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* @Description: Returns the string identifier for the client's current locale setting
|
* @Description: Returns the string identifier for the client's current locale setting
|
||||||
|
Loading…
Reference in New Issue
Block a user