Java Code Examples for org.json.JSONObject#names()

The following examples show how to use org.json.JSONObject#names() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SolrActionCheckResult.java    From alfresco-repository with GNU Lesser General Public License v3.0 8 votes vote down vote up
@Override
protected void processCoresInfoJson(JSONObject json) throws JSONException
{

    cores = new ArrayList<>();
    
    if (json.has("status")) 
    {
    
        JSONObject coreList = json.getJSONObject("status");
        JSONArray coreNameList = coreList.names();
        for(int i = 0; i < coreNameList.length(); i++)
        {
            JSONObject core = coreList.getJSONObject(String.valueOf(coreNameList.get(i)));
            cores.add(core.getString("name"));
        }

    }
    
}
 
Example 2
Source File: Utility.java    From aws-mobile-self-paced-labs-samples with Apache License 2.0 7 votes vote down vote up
static Map<String, Object> convertJSONObjectToHashMap(JSONObject jsonObject) {
    HashMap<String, Object> map = new HashMap<String, Object>();
    JSONArray keys = jsonObject.names();
    for (int i = 0; i < keys.length(); ++i) {
        String key;
        try {
            key = keys.getString(i);
            Object value = jsonObject.get(key);
            if (value instanceof JSONObject) {
                value = convertJSONObjectToHashMap((JSONObject) value);
            }
            map.put(key, value);
        } catch (JSONException e) {
        }
    }
    return map;
}
 
Example 3
Source File: Utility.java    From HypFacebook with BSD 2-Clause "Simplified" License 6 votes vote down vote up
static Map<String, Object> convertJSONObjectToHashMap(JSONObject jsonObject) {
    HashMap<String, Object> map = new HashMap<String, Object>();
    JSONArray keys = jsonObject.names();
    for (int i = 0; i < keys.length(); ++i) {
        String key;
        try {
            key = keys.getString(i);
            Object value = jsonObject.get(key);
            if (value instanceof JSONObject) {
                value = convertJSONObjectToHashMap((JSONObject) value);
            }
            map.put(key, value);
        } catch (JSONException e) {
        }
    }
    return map;
}
 
Example 4
Source File: JMXQueryHelper.java    From eagle with Apache License 2.0 6 votes vote down vote up
private static Map<String, JMXBean> parseStream(InputStream is) {
    final Map<String, JMXBean> resultMap = new HashMap<String, JMXBean>();
    final JSONTokener tokener = new JSONTokener(is);
    final JSONObject jsonBeansObject = new JSONObject(tokener);
    final JSONArray jsonArray = jsonBeansObject.getJSONArray("beans");
    int size = jsonArray.length();
    for (int i = 0; i < size; ++i) {
        final JSONObject obj = (JSONObject) jsonArray.get(i);
        final JMXBean bean = new JMXBean();
        final Map<String, Object> map = new HashMap<String, Object>();
        bean.setPropertyMap(map);
        final JSONArray names = obj.names();
        int jsonSize = names.length();
        for (int j = 0; j < jsonSize; ++j) {
            final String key = names.getString(j);
            Object value = obj.get(key);
            map.put(key, value);
        }
        final String nameString = (String) map.get("name");
        resultMap.put(nameString, bean);
    }
    return resultMap;
}
 
Example 5
Source File: CastMessageHandler.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * Remove 'null' fields from a JSONObject. This method calls itself recursively until all the
 * fields have been looked at.
 * TODO(mlamouri): move to some util class?
 */
private static void removeNullFields(Object object) throws JSONException {
    if (object instanceof JSONArray) {
        JSONArray array = (JSONArray) object;
        for (int i = 0; i < array.length(); ++i) removeNullFields(array.get(i));
    } else if (object instanceof JSONObject) {
        JSONObject json = (JSONObject) object;
        JSONArray names = json.names();
        if (names == null) return;
        for (int i = 0; i < names.length(); ++i) {
            String key = names.getString(i);
            if (json.isNull(key)) {
                json.remove(key);
            } else {
                removeNullFields(json.get(key));
            }
        }
    }
}
 
Example 6
Source File: Utility.java    From kognitivo with Apache License 2.0 6 votes vote down vote up
static Map<String, Object> convertJSONObjectToHashMap(JSONObject jsonObject) {
    HashMap<String, Object> map = new HashMap<String, Object>();
    JSONArray keys = jsonObject.names();
    for (int i = 0; i < keys.length(); ++i) {
        String key;
        try {
            key = keys.getString(i);
            Object value = jsonObject.get(key);
            if (value instanceof JSONObject) {
                value = convertJSONObjectToHashMap((JSONObject) value);
            }
            map.put(key, value);
        } catch (JSONException e) {
        }
    }
    return map;
}
 
Example 7
Source File: JSONObjectTest.java    From JSON-Java-unit-test with Apache License 2.0 5 votes vote down vote up
/**
 * Populate a JSONArray from an empty JSONObject names() method.
 * It should be empty.
 */
@Test
public void emptyJsonObjectNamesToJsonAray() {
    JSONObject jsonObject = new JSONObject();
    JSONArray jsonArray = jsonObject.names();
    assertTrue("jsonArray should be null", jsonArray == null);
}
 
Example 8
Source File: DeviceInformationListAdapter.java    From androiddevice.info with GNU General Public License v2.0 5 votes vote down vote up
public DeviceInformationListAdapter(Context context, JSONObject deviceInformation){
    mInflater = LayoutInflater.from(context);
    mItems = new ArrayList<KeyValuePair>();
    mWhiteColor = context.getResources().getColor(android.R.color.white);
    mGreyColor = context.getResources().getColor(R.color.subtext_grey);
    JSONArray keys = deviceInformation.names();
    for(int ii = 0 ; ii < keys.length(); ++ii) {
        try {
            final String key = keys.getString(ii);
            final Object value = deviceInformation.get(key);
            final String valueString = String.valueOf(value);
            mItems.add(new KeyValuePair(key, value, valueString, key.equals("name")));
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    Collections.sort(mItems, new Comparator<KeyValuePair>() {
        @Override
        public int compare(KeyValuePair lhs, KeyValuePair rhs) {
            if(lhs.isEditable){
                return -1;
            }
            return lhs.key.compareTo(rhs.key);
        }
    });
}
 
Example 9
Source File: WikipediaReader.java    From swcv with MIT License 5 votes vote down vote up
private boolean downloadContent(String query)
{
    try
    {
        InputStream is = new URL(query).openStream();
        try
        {
            StringWriter writer = new StringWriter();
            IOUtils.copy(is, writer);
            JSONObject json = new JSONObject(writer.toString());
            json = json.getJSONObject("query");
            json = json.getJSONObject("pages");
            
            //System.out.println(json.names());

            JSONArray arr = json.names();
            StringBuffer sb = new StringBuffer();
            for (int i = 0; i < arr.length(); i++)
            {
                JSONObject tmp = json.getJSONObject(arr.getString(i)); 
                String en = tmp.getString("extract");
                if (en.length() > 0)
                    sb.append(en + ".\n");
            }

            text = sb.toString();
            return true;
        }
        finally
        {
            is.close();
        }
    }
    catch (Exception e)
    {
        e.printStackTrace();
        return false;
    }
}
 
Example 10
Source File: App.java    From phonegap-plugin-loading-spinner with Apache License 2.0 4 votes vote down vote up
/**
 * Load the url into the webview.
 *
 * @param url
 * @param props			Properties that can be passed in to the Cordova activity (i.e. loadingDialog, wait, ...)
 * @throws JSONException
 */
public void loadUrl(String url, JSONObject props) throws JSONException {
    LOG.d("App", "App.loadUrl("+url+","+props+")");
    int wait = 0;
    boolean openExternal = false;
    boolean clearHistory = false;

    // If there are properties, then set them on the Activity
    HashMap<String, Object> params = new HashMap<String, Object>();
    if (props != null) {
        JSONArray keys = props.names();
        for (int i = 0; i < keys.length(); i++) {
            String key = keys.getString(i);
            if (key.equals("wait")) {
                wait = props.getInt(key);
            }
            else if (key.equalsIgnoreCase("openexternal")) {
                openExternal = props.getBoolean(key);
            }
            else if (key.equalsIgnoreCase("clearhistory")) {
                clearHistory = props.getBoolean(key);
            }
            else {
                Object value = props.get(key);
                if (value == null) {

                }
                else if (value.getClass().equals(String.class)) {
                    params.put(key, (String)value);
                }
                else if (value.getClass().equals(Boolean.class)) {
                    params.put(key, (Boolean)value);
                }
                else if (value.getClass().equals(Integer.class)) {
                    params.put(key, (Integer)value);
                }
            }
        }
    }

    // If wait property, then delay loading

    if (wait > 0) {
        try {
            synchronized(this) {
                this.wait(wait);
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    this.webView.showWebPage(url, openExternal, clearHistory, params);
}
 
Example 11
Source File: mcstocksapicomms.java    From openstock with GNU General Public License v3.0 4 votes vote down vote up
public java.util.List<mccandle> av_receberforexcandlesdaily(String fromsimbolo, String tosimbolo, String outputsize)
{
    String urlquery = "https://www.alphavantage.co/query?function=FX_DAILY&from_symbol="+fromsimbolo+"&to_symbol="+tosimbolo+"&outputsize="+outputsize+"&apikey=" + av_chave;
    //mierclasses.mcfuncoeshelper.setarclipboard(urlquery);
    //mierclasses.mcfuncoeshelper.mostrarmensagem(urlquery);
    String jsonconteudo = mwcomms.receberconteudopagina(urlquery);
    
    JSONObject obj = new JSONObject(jsonconteudo);
    
    String md_information = obj.getJSONObject("Meta Data").getString("1. Information");
    String md_fromsymbol = obj.getJSONObject("Meta Data").getString("2. From Symbol");
    String md_tosymbol = obj.getJSONObject("Meta Data").getString("3. To Symbol");
    String md_outputsize = obj.getJSONObject("Meta Data").getString("4. Output Size");
    String md_lastrefreshed = obj.getJSONObject("Meta Data").getString("5. Last Refreshed");
    String md_timezone = obj.getJSONObject("Meta Data").getString("6. Time Zone");

    JSONObject candlesjson = obj.getJSONObject("Time Series FX (Daily)");
    JSONArray candlesjsontimestamparray = candlesjson.names();
    
    
    java.util.List<mccandle> listacandlesretornar = new java.util.ArrayList<>();
    
    for (int i = 0; i < candlesjsontimestamparray.length(); i++)
    {
        String timestampcandle = candlesjsontimestamparray.getString(i);
        
        String opencandle = candlesjson.getJSONObject(timestampcandle).getString("1. open");
        String highcandle = candlesjson.getJSONObject(timestampcandle).getString("2. high");
        String lowcandle = candlesjson.getJSONObject(timestampcandle).getString("3. low");
        String closecandle = candlesjson.getJSONObject(timestampcandle).getString("4. close");
        
        mccandle candleatual = new mccandle(timestampcandle,opencandle,highcandle,closecandle,lowcandle,"0");
        listacandlesretornar.add(candleatual);
    }
   
    //reordernar lista de candles antes de retornar
    java.util.Collections.sort(listacandlesretornar, new java.util.Comparator<mierclasses.mccandle>() 
    {
        public int compare(mierclasses.mccandle candleone, mierclasses.mccandle candletwo) 
        {
            return candleone.timestampdate.compareTo(candletwo.timestampdate);
        }
    });
    if (math_tirarzeros == true)
        listacandlesretornar = math_retirarzeroscandles(listacandlesretornar);
    
    return listacandlesretornar;
}
 
Example 12
Source File: CoreAndroid.java    From BigDataPlatform with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Load the url into the webview.
 *
 * @param url
 * @param props			Properties that can be passed in to the Cordova activity (i.e. loadingDialog, wait, ...)
 * @throws JSONException
 */
public void loadUrl(String url, JSONObject props) throws JSONException {
    LOG.d("App", "App.loadUrl("+url+","+props+")");
    int wait = 0;
    boolean openExternal = false;
    boolean clearHistory = false;

    // If there are properties, then set them on the Activity
    HashMap<String, Object> params = new HashMap<String, Object>();
    if (props != null) {
        JSONArray keys = props.names();
        for (int i = 0; i < keys.length(); i++) {
            String key = keys.getString(i);
            if (key.equals("wait")) {
                wait = props.getInt(key);
            }
            else if (key.equalsIgnoreCase("openexternal")) {
                openExternal = props.getBoolean(key);
            }
            else if (key.equalsIgnoreCase("clearhistory")) {
                clearHistory = props.getBoolean(key);
            }
            else {
                Object value = props.get(key);
                if (value == null) {

                }
                else if (value.getClass().equals(String.class)) {
                    params.put(key, (String)value);
                }
                else if (value.getClass().equals(Boolean.class)) {
                    params.put(key, (Boolean)value);
                }
                else if (value.getClass().equals(Integer.class)) {
                    params.put(key, (Integer)value);
                }
            }
        }
    }

    // If wait property, then delay loading

    if (wait > 0) {
        try {
            synchronized(this) {
                this.wait(wait);
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    this.webView.showWebPage(url, openExternal, clearHistory, params);
}
 
Example 13
Source File: CoreAndroid.java    From xmall with MIT License 4 votes vote down vote up
/**
 * Load the url into the webview.
 *
 * @param url
 * @param props			Properties that can be passed in to the Cordova activity (i.e. loadingDialog, wait, ...)
 * @throws JSONException
 */
public void loadUrl(String url, JSONObject props) throws JSONException {
    LOG.d("App", "App.loadUrl("+url+","+props+")");
    int wait = 0;
    boolean openExternal = false;
    boolean clearHistory = false;

    // If there are properties, then set them on the Activity
    HashMap<String, Object> params = new HashMap<String, Object>();
    if (props != null) {
        JSONArray keys = props.names();
        for (int i = 0; i < keys.length(); i++) {
            String key = keys.getString(i);
            if (key.equals("wait")) {
                wait = props.getInt(key);
            }
            else if (key.equalsIgnoreCase("openexternal")) {
                openExternal = props.getBoolean(key);
            }
            else if (key.equalsIgnoreCase("clearhistory")) {
                clearHistory = props.getBoolean(key);
            }
            else {
                Object value = props.get(key);
                if (value == null) {

                }
                else if (value.getClass().equals(String.class)) {
                    params.put(key, (String)value);
                }
                else if (value.getClass().equals(Boolean.class)) {
                    params.put(key, (Boolean)value);
                }
                else if (value.getClass().equals(Integer.class)) {
                    params.put(key, (Integer)value);
                }
            }
        }
    }

    // If wait property, then delay loading

    if (wait > 0) {
        try {
            synchronized(this) {
                this.wait(wait);
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    this.webView.showWebPage(url, openExternal, clearHistory, params);
}
 
Example 14
Source File: CoreAndroid.java    From pychat with MIT License 4 votes vote down vote up
/**
 * Load the url into the webview.
 *
 * @param url
 * @param props			Properties that can be passed in to the Cordova activity (i.e. loadingDialog, wait, ...)
 * @throws JSONException
 */
public void loadUrl(String url, JSONObject props) throws JSONException {
    LOG.d("App", "App.loadUrl("+url+","+props+")");
    int wait = 0;
    boolean openExternal = false;
    boolean clearHistory = false;

    // If there are properties, then set them on the Activity
    HashMap<String, Object> params = new HashMap<String, Object>();
    if (props != null) {
        JSONArray keys = props.names();
        for (int i = 0; i < keys.length(); i++) {
            String key = keys.getString(i);
            if (key.equals("wait")) {
                wait = props.getInt(key);
            }
            else if (key.equalsIgnoreCase("openexternal")) {
                openExternal = props.getBoolean(key);
            }
            else if (key.equalsIgnoreCase("clearhistory")) {
                clearHistory = props.getBoolean(key);
            }
            else {
                Object value = props.get(key);
                if (value == null) {

                }
                else if (value.getClass().equals(String.class)) {
                    params.put(key, (String)value);
                }
                else if (value.getClass().equals(Boolean.class)) {
                    params.put(key, (Boolean)value);
                }
                else if (value.getClass().equals(Integer.class)) {
                    params.put(key, (Integer)value);
                }
            }
        }
    }

    // If wait property, then delay loading

    if (wait > 0) {
        try {
            synchronized(this) {
                this.wait(wait);
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    this.webView.showWebPage(url, openExternal, clearHistory, params);
}
 
Example 15
Source File: CoreAndroid.java    From cordova-plugin-intent with MIT License 4 votes vote down vote up
/**
 * Load the url into the webview.
 *
 * @param url
 * @param props			Properties that can be passed in to the Cordova activity (i.e. loadingDialog, wait, ...)
 * @throws JSONException
 */
public void loadUrl(String url, JSONObject props) throws JSONException {
    LOG.d("App", "App.loadUrl("+url+","+props+")");
    int wait = 0;
    boolean openExternal = false;
    boolean clearHistory = false;

    // If there are properties, then set them on the Activity
    HashMap<String, Object> params = new HashMap<String, Object>();
    if (props != null) {
        JSONArray keys = props.names();
        for (int i = 0; i < keys.length(); i++) {
            String key = keys.getString(i);
            if (key.equals("wait")) {
                wait = props.getInt(key);
            }
            else if (key.equalsIgnoreCase("openexternal")) {
                openExternal = props.getBoolean(key);
            }
            else if (key.equalsIgnoreCase("clearhistory")) {
                clearHistory = props.getBoolean(key);
            }
            else {
                Object value = props.get(key);
                if (value == null) {

                }
                else if (value.getClass().equals(String.class)) {
                    params.put(key, (String)value);
                }
                else if (value.getClass().equals(Boolean.class)) {
                    params.put(key, (Boolean)value);
                }
                else if (value.getClass().equals(Integer.class)) {
                    params.put(key, (Integer)value);
                }
            }
        }
    }

    // If wait property, then delay loading

    if (wait > 0) {
        try {
            synchronized(this) {
                this.wait(wait);
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    this.webView.showWebPage(url, openExternal, clearHistory, params);
}
 
Example 16
Source File: CoreAndroid.java    From ultimate-cordova-webview-app with MIT License 4 votes vote down vote up
/**
 * Load the url into the webview.
 *
 * @param url
 * @param props			Properties that can be passed in to the Cordova activity (i.e. loadingDialog, wait, ...)
 * @throws JSONException
 */
public void loadUrl(String url, JSONObject props) throws JSONException {
    LOG.d("App", "App.loadUrl("+url+","+props+")");
    int wait = 0;
    boolean openExternal = false;
    boolean clearHistory = false;

    // If there are properties, then set them on the Activity
    HashMap<String, Object> params = new HashMap<String, Object>();
    if (props != null) {
        JSONArray keys = props.names();
        for (int i = 0; i < keys.length(); i++) {
            String key = keys.getString(i);
            if (key.equals("wait")) {
                wait = props.getInt(key);
            }
            else if (key.equalsIgnoreCase("openexternal")) {
                openExternal = props.getBoolean(key);
            }
            else if (key.equalsIgnoreCase("clearhistory")) {
                clearHistory = props.getBoolean(key);
            }
            else {
                Object value = props.get(key);
                if (value == null) {

                }
                else if (value.getClass().equals(String.class)) {
                    params.put(key, (String)value);
                }
                else if (value.getClass().equals(Boolean.class)) {
                    params.put(key, (Boolean)value);
                }
                else if (value.getClass().equals(Integer.class)) {
                    params.put(key, (Integer)value);
                }
            }
        }
    }

    // If wait property, then delay loading

    if (wait > 0) {
        try {
            synchronized(this) {
                this.wait(wait);
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    this.webView.showWebPage(url, openExternal, clearHistory, params);
}
 
Example 17
Source File: SolrActionStatusResult.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
protected void processCoresInfoJson(JSONObject json) throws JSONException
{

    List<String> cores = new ArrayList<>();
    Map<String, Map<String, Object>> coresInfo = new HashMap<>();
    
    if (json.has("status"))
    {
        
        JSONObject coreList = json.getJSONObject("status");
        JSONArray coreNameList = coreList.names();
        for(int i = 0; i < coreNameList.length(); i++)
        {
            JSONObject core = coreList.getJSONObject(String.valueOf(coreNameList.get(i)));
            
            String coreName = core.getString("name");
            
            cores.add(coreName);
            
            Map<String, Object> coreInfo = new HashMap<>();
            coreInfo.put("instanceDir", core.getString("instanceDir"));
            coreInfo.put("dataDirectory", core.get("dataDir"));
            coreInfo.put("startTime", Date.from(ZonedDateTime.parse(core.getString("startTime")).toInstant()));
            coreInfo.put("uptime", core.getLong("uptime"));
            
            if (core.has("index"))
            {
                JSONObject index = core.getJSONObject("index");
                coreInfo.put("numDocs", index.getInt("numDocs"));
                coreInfo.put("maxDocument", index.getInt("maxDoc"));
                coreInfo.put("version", index.getLong("version"));
                coreInfo.put("current", index.getBoolean("current"));
                coreInfo.put("hasDeletions", index.getBoolean("hasDeletions"));
                coreInfo.put("directory", index.getString("directory"));
                coreInfo.put("lastModified", Date.from(ZonedDateTime.parse(index.getString("lastModified")).toInstant()));
            }
        
            coresInfo.put(coreName, coreInfo);
            
        }

    }
    
    this.cores = cores;
    this.coresInfo = coresInfo;
    
}
 
Example 18
Source File: App.java    From wildfly-samples with MIT License 4 votes vote down vote up
/**
 * Load the url into the webview.
 *
 * @param url
 * @param props			Properties that can be passed in to the Cordova activity (i.e. loadingDialog, wait, ...)
 * @throws JSONException
 */
public void loadUrl(String url, JSONObject props) throws JSONException {
    LOG.d("App", "App.loadUrl("+url+","+props+")");
    int wait = 0;
    boolean openExternal = false;
    boolean clearHistory = false;

    // If there are properties, then set them on the Activity
    HashMap<String, Object> params = new HashMap<String, Object>();
    if (props != null) {
        JSONArray keys = props.names();
        for (int i = 0; i < keys.length(); i++) {
            String key = keys.getString(i);
            if (key.equals("wait")) {
                wait = props.getInt(key);
            }
            else if (key.equalsIgnoreCase("openexternal")) {
                openExternal = props.getBoolean(key);
            }
            else if (key.equalsIgnoreCase("clearhistory")) {
                clearHistory = props.getBoolean(key);
            }
            else {
                Object value = props.get(key);
                if (value == null) {

                }
                else if (value.getClass().equals(String.class)) {
                    params.put(key, (String)value);
                }
                else if (value.getClass().equals(Boolean.class)) {
                    params.put(key, (Boolean)value);
                }
                else if (value.getClass().equals(Integer.class)) {
                    params.put(key, (Integer)value);
                }
            }
        }
    }

    // If wait property, then delay loading

    if (wait > 0) {
        try {
            synchronized(this) {
                this.wait(wait);
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    this.webView.showWebPage(url, openExternal, clearHistory, params);
}
 
Example 19
Source File: App.java    From IoTgo_Android_App with MIT License 4 votes vote down vote up
/**
 * Load the url into the webview.
 *
 * @param url
 * @param props			Properties that can be passed in to the Cordova activity (i.e. loadingDialog, wait, ...)
 * @throws JSONException
 */
public void loadUrl(String url, JSONObject props) throws JSONException {
    LOG.d("App", "App.loadUrl("+url+","+props+")");
    int wait = 0;
    boolean openExternal = false;
    boolean clearHistory = false;

    // If there are properties, then set them on the Activity
    HashMap<String, Object> params = new HashMap<String, Object>();
    if (props != null) {
        JSONArray keys = props.names();
        for (int i = 0; i < keys.length(); i++) {
            String key = keys.getString(i);
            if (key.equals("wait")) {
                wait = props.getInt(key);
            }
            else if (key.equalsIgnoreCase("openexternal")) {
                openExternal = props.getBoolean(key);
            }
            else if (key.equalsIgnoreCase("clearhistory")) {
                clearHistory = props.getBoolean(key);
            }
            else {
                Object value = props.get(key);
                if (value == null) {

                }
                else if (value.getClass().equals(String.class)) {
                    params.put(key, (String)value);
                }
                else if (value.getClass().equals(Boolean.class)) {
                    params.put(key, (Boolean)value);
                }
                else if (value.getClass().equals(Integer.class)) {
                    params.put(key, (Integer)value);
                }
            }
        }
    }

    // If wait property, then delay loading

    if (wait > 0) {
        try {
            synchronized(this) {
                this.wait(wait);
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    this.webView.showWebPage(url, openExternal, clearHistory, params);
}
 
Example 20
Source File: CoreAndroid.java    From lona with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Load the url into the webview.
 *
 * @param url
 * @param props			Properties that can be passed in to the Cordova activity (i.e. loadingDialog, wait, ...)
 * @throws JSONException
 */
public void loadUrl(String url, JSONObject props) throws JSONException {
    LOG.d("App", "App.loadUrl("+url+","+props+")");
    int wait = 0;
    boolean openExternal = false;
    boolean clearHistory = false;

    // If there are properties, then set them on the Activity
    HashMap<String, Object> params = new HashMap<String, Object>();
    if (props != null) {
        JSONArray keys = props.names();
        for (int i = 0; i < keys.length(); i++) {
            String key = keys.getString(i);
            if (key.equals("wait")) {
                wait = props.getInt(key);
            }
            else if (key.equalsIgnoreCase("openexternal")) {
                openExternal = props.getBoolean(key);
            }
            else if (key.equalsIgnoreCase("clearhistory")) {
                clearHistory = props.getBoolean(key);
            }
            else {
                Object value = props.get(key);
                if (value == null) {

                }
                else if (value.getClass().equals(String.class)) {
                    params.put(key, (String)value);
                }
                else if (value.getClass().equals(Boolean.class)) {
                    params.put(key, (Boolean)value);
                }
                else if (value.getClass().equals(Integer.class)) {
                    params.put(key, (Integer)value);
                }
            }
        }
    }

    // If wait property, then delay loading

    if (wait > 0) {
        try {
            synchronized(this) {
                this.wait(wait);
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    this.webView.showWebPage(url, openExternal, clearHistory, params);
}