List of usage examples for org.json JSONObject optBoolean
public boolean optBoolean(String key, boolean defaultValue)
From source file:com.google.blockly.model.FieldCheckbox.java
public static FieldCheckbox fromJson(JSONObject json) throws BlockLoadingException { String name = json.optString("name"); if (TextUtils.isEmpty(name)) { throw new BlockLoadingException("field_checkbox \"name\" attribute must not be empty."); }/*w ww . j ava 2s .com*/ return new FieldCheckbox(name, json.optBoolean("checked", true)); }
From source file:fr.cobaltians.cobalt.fragments.CobaltFragment.java
/****************************************************************************************************************** * ALERT DIALOG/* ww w . java 2s . c om*/ *****************************************************************************************************************/ private void showAlertDialog(JSONObject data, final String callback) { try { String title = data.optString(Cobalt.kJSAlertTitle); String message = data.optString(Cobalt.kJSMessage); boolean cancelable = data.optBoolean(Cobalt.kJSAlertCancelable, false); JSONArray buttons = data.has(Cobalt.kJSAlertButtons) ? data.getJSONArray(Cobalt.kJSAlertButtons) : new JSONArray(); AlertDialog alertDialog = new AlertDialog.Builder(mContext).setTitle(title).setMessage(message) .create(); alertDialog.setCancelable(cancelable); if (buttons.length() == 0) { alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (callback != null) { try { JSONObject data = new JSONObject(); data.put(Cobalt.kJSAlertButtonIndex, 0); sendCallback(callback, data); } catch (JSONException exception) { if (Cobalt.DEBUG) Log.e(Cobalt.TAG, TAG + ".AlertDialog - onClick: JSONException"); exception.printStackTrace(); } } } }); } else { int buttonsLength = Math.min(buttons.length(), 3); for (int i = 0; i < buttonsLength; i++) { int buttonId; switch (i) { case 0: default: buttonId = DialogInterface.BUTTON_NEGATIVE; break; case 1: buttonId = DialogInterface.BUTTON_NEUTRAL; break; case 2: buttonId = DialogInterface.BUTTON_POSITIVE; break; } alertDialog.setButton(buttonId, buttons.getString(i), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (callback != null) { int buttonIndex; switch (which) { case DialogInterface.BUTTON_NEGATIVE: default: buttonIndex = 0; break; case DialogInterface.BUTTON_NEUTRAL: buttonIndex = 1; break; case DialogInterface.BUTTON_POSITIVE: buttonIndex = 2; break; } try { JSONObject data = new JSONObject(); data.put(Cobalt.kJSAlertButtonIndex, buttonIndex); sendCallback(callback, data); } catch (JSONException exception) { if (Cobalt.DEBUG) Log.e(Cobalt.TAG, TAG + ".AlertDialog - onClick: JSONException"); exception.printStackTrace(); } } } }); } } alertDialog.show(); } catch (JSONException exception) { if (Cobalt.DEBUG) Log.e(Cobalt.TAG, TAG + " - showAlertDialog: JSONException"); exception.printStackTrace(); } }
From source file:net.zorgblub.typhon.dto.PageOffsets.java
public static PageOffsets fromJSON(String json) throws JSONException { JSONObject offsetsObject = new JSONObject(json); PageOffsets result = new PageOffsets(); result.fontFamily = offsetsObject.getString(Fields.fontFamily.name()); result.fontSize = offsetsObject.getInt(Fields.fontSize.name()); result.vMargin = offsetsObject.getInt(Fields.vMargin.name()); result.hMargin = offsetsObject.getInt(Fields.hMargin.name()); result.lineSpacing = offsetsObject.getInt(Fields.lineSpacing.name()); result.fullScreen = offsetsObject.getBoolean(Fields.fullScreen.name()); result.algorithmVersion = offsetsObject.optInt(Fields.algorithmVersion.name(), -1); result.allowStyling = offsetsObject.optBoolean(Fields.allowStyling.name(), true); result.offsets = readOffsets(offsetsObject.getJSONArray(Fields.offsets.name())); return result; }
From source file:com.phonegap.plugin.ChildBrowser.java
/** * Display a new browser with the specified URL. * * @param url The url to load. * @param jsonObject /*from w w w. ja v a 2s .c o m*/ */ public String showWebPage(final String url, JSONObject options) { // Determine if we should hide the location bar. if (options != null) { showLocationBar = options.optBoolean("showLocationBar", true); } // Create dialog in new thread Runnable runnable = new Runnable() { public void run() { dialog = new Dialog(ctx.getContext(), android.R.style.Theme_Translucent_NoTitleBar); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setCancelable(true); dialog.setOnDismissListener(new DialogInterface.OnDismissListener() { public void onDismiss(DialogInterface dialog) { try { JSONObject obj = new JSONObject(); obj.put("type", CLOSE_EVENT); sendUpdate(obj, false); } catch (JSONException e) { Log.d(LOG_TAG, "Should never happen"); } } }); LinearLayout.LayoutParams backParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LinearLayout.LayoutParams forwardParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LinearLayout.LayoutParams editParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1.0f); LinearLayout.LayoutParams closeParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LinearLayout.LayoutParams wvParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); LinearLayout main = new LinearLayout(ctx.getContext()); main.setOrientation(LinearLayout.VERTICAL); LinearLayout toolbar = new LinearLayout(ctx.getContext()); toolbar.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); toolbar.setOrientation(LinearLayout.HORIZONTAL); ImageButton back = new ImageButton(ctx.getContext()); back.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { goBack(); } }); back.setId(1); try { back.setImageBitmap(loadDrawable("www/childbrowser/icon_arrow_left.png")); } catch (IOException e) { Log.e(LOG_TAG, e.getMessage(), e); } back.setLayoutParams(backParams); ImageButton forward = new ImageButton(ctx.getContext()); forward.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { goForward(); } }); forward.setId(2); try { forward.setImageBitmap(loadDrawable("www/childbrowser/icon_arrow_right.png")); } catch (IOException e) { Log.e(LOG_TAG, e.getMessage(), e); } forward.setLayoutParams(forwardParams); edittext = new EditText(ctx.getContext()); edittext.setOnKeyListener(new View.OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { // If the event is a key-down event on the "enter" button if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { navigate(edittext.getText().toString()); return true; } return false; } }); edittext.setId(3); edittext.setSingleLine(true); edittext.setText(url); edittext.setLayoutParams(editParams); ImageButton close = new ImageButton(ctx.getContext()); close.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { closeDialog(); } }); close.setId(4); try { close.setImageBitmap(loadDrawable("www/childbrowser/icon_close.png")); } catch (IOException e) { Log.e(LOG_TAG, e.getMessage(), e); } close.setLayoutParams(closeParams); webview = new WebView(ctx.getContext()); webview.setWebChromeClient(new WebChromeClient()); WebViewClient client = new ChildBrowserClient(edittext); webview.setWebViewClient(client); WebSettings settings = webview.getSettings(); settings.setJavaScriptEnabled(true); settings.setJavaScriptCanOpenWindowsAutomatically(true); settings.setBuiltInZoomControls(true); settings.setPluginsEnabled(true); settings.setDomStorageEnabled(true); webview.loadUrl(url); webview.setId(5); webview.setInitialScale(0); webview.setLayoutParams(wvParams); webview.requestFocus(); webview.requestFocusFromTouch(); toolbar.addView(back); toolbar.addView(forward); toolbar.addView(edittext); toolbar.addView(close); if (getShowLocationBar()) { main.addView(toolbar); } main.addView(webview); WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); lp.copyFrom(dialog.getWindow().getAttributes()); lp.width = WindowManager.LayoutParams.FILL_PARENT; lp.height = WindowManager.LayoutParams.FILL_PARENT; dialog.setContentView(main); dialog.show(); dialog.getWindow().setAttributes(lp); } private Bitmap loadDrawable(String filename) throws java.io.IOException { InputStream input = ctx.getAssets().open(filename); return BitmapFactory.decodeStream(input); } }; this.ctx.runOnUiThread(runnable); return ""; }
From source file:uk.ac.imperial.presage2.core.cli.run.ExecutorModule.java
/** * <p>/*from w w w . j a v a 2 s. c o m*/ * Load an {@link AbstractModule} which can inject an * {@link ExecutorManager} with the appropriate {@link SimulationExecutor}s * as per provided configuration. * </p> * * <p> * The executor config can be provided in two ways (in order of precedence): * </p> * <ul> * <li><code>executors.properties</code> file on the classpath. This file * should contain a <code>module</code> key who's value is the fully * qualified name of a class which extends {@link AbstractModule} and has a * public constructor which takes a single {@link Properties} object as an * argument or public no-args constructor. An instance of this class will be * returned.</li> * <li><code>executors.json</code> file on the classpath. This file contains * a specification of the executors to load in JSON format. If this file is * valid we will instantiate each executor defined in the spec and add it to * an {@link ExecutorModule} which will provide the bindings for them.</li> * </ul> * * <h3>executors.json format</h3> * * <p> * The <code>executors.json</code> file should contain a JSON object with * the following: * <ul> * <li><code>executors</code> key whose value is an array. Each element of * the array is a JSON object with the following keys: * <ul> * <li><code>class</code>: the fully qualified name of the executor class.</li> * <li><code>args</code>: an array of arguments to pass to a public * constructor of the class.</li> * <li><code>enableLogs</code> (optional): boolean value whether this * executor should save logs to file. Defaults to global value.</li> * <li><code>logDir</code> (optional): string path to save logs to. Defaults * to global value</li> * </ul> * </li> * <li><code>enableLogs</code> (optional): Global value for enableLogs for * each executor. Defaults to false.</li> * <li><code>logDir</code> (optional): Global value for logDir for each * executor. Default values depend on the executor.</li> * </ul> * </p> * <p> * e.g.: * </p> * * <pre class="prettyprint"> * { * "executors": [{ * "class": "my.fully.qualified.Executor", * "args": [1, "some string", true] * },{ * ... * }], * "enableLogs": true * } * </pre> * * @return */ public static AbstractModule load() { Logger logger = Logger.getLogger(ExecutorModule.class); // look for executors.properties // This defines an AbstractModule to use instead of this one. // We try and load the module class given and return it. try { Properties execProps = new Properties(); execProps.load(ExecutorModule.class.getClassLoader().getResourceAsStream("executors.properties")); String moduleName = execProps.getProperty("module", ""); Class<? extends AbstractModule> module = Class.forName(moduleName).asSubclass(AbstractModule.class); // look for suitable ctor, either Properties parameter or default Constructor<? extends AbstractModule> ctor; try { ctor = module.getConstructor(Properties.class); return ctor.newInstance(execProps); } catch (NoSuchMethodException e) { ctor = module.getConstructor(); return ctor.newInstance(); } } catch (Exception e) { logger.debug("Could not create module from executors.properties"); } // executors.properties fail, look for executors.json // This file defines a set of classes to load with parameters for the // constructor. // We try to create each defined executor and add it to this // ExecutorModule. try { // get executors.json file and parse to JSON. // throws NullPointerException if file doesn't exist, or // JSONException if we can't parse the JSON. InputStream is = ExecutorModule.class.getClassLoader().getResourceAsStream("executors.json"); logger.debug("Processing executors from executors.json"); JSONObject execConf = new JSONObject(new JSONTokener(new InputStreamReader(is))); // Create our module and look for executor specs under the executors // array in the JSON. ExecutorModule module = new ExecutorModule(); JSONArray executors = execConf.getJSONArray("executors"); // optional global settings boolean enableLogs = execConf.optBoolean("enableLogs", false); String logDir = execConf.optString("logDir"); logger.info("Building Executors from executors.json"); // Try and instantiate an instance of each executor in the spec. for (int i = 0; i < executors.length(); i++) { try { JSONObject executorSpec = executors.getJSONObject(i); String executorClass = executorSpec.getString("class"); JSONArray args = executorSpec.getJSONArray("args"); Class<? extends SimulationExecutor> clazz = Class.forName(executorClass) .asSubclass(SimulationExecutor.class); // build constructor args. // We assume all types are in primitive form where // applicable. // The only available types are boolean, int, double and // String. Class<?>[] argTypes = new Class<?>[args.length()]; Object[] argValues = new Object[args.length()]; for (int j = 0; j < args.length(); j++) { argValues[j] = args.get(j); Class<?> type = argValues[j].getClass(); if (type == Boolean.class) type = Boolean.TYPE; else if (type == Integer.class) type = Integer.TYPE; else if (type == Double.class) type = Double.TYPE; argTypes[j] = type; } SimulationExecutor exe = clazz.getConstructor(argTypes).newInstance(argValues); logger.debug("Adding executor to pool: " + exe.toString()); module.addExecutorInstance(exe); // logging config boolean exeEnableLog = executorSpec.optBoolean("enableLogs", enableLogs); String exeLogDir = executorSpec.optString("logDir", logDir); exe.enableLogs(exeEnableLog); if (exeLogDir.length() > 0) { exe.setLogsDirectory(exeLogDir); } } catch (JSONException e) { logger.warn("Error parsing executor config", e); } catch (ClassNotFoundException e) { logger.warn("Unknown executor class in config", e); } catch (IllegalArgumentException e) { logger.warn("Illegal arguments for executor ctor", e); } catch (NoSuchMethodException e) { logger.warn("No matching public ctor for args in executor config", e); } catch (Exception e) { logger.warn("Could not create executor from specification", e); } } return module; } catch (JSONException e) { logger.debug("Could not create module from executors.json"); } catch (NullPointerException e) { logger.debug("Could not open executors.json"); } // no executor config, use a default config: 1 local sub process // executor. logger.info("Using default ExecutorModule."); return new ExecutorModule(1); }
From source file:com.funzio.pure2D.particles.nova.vo.TweenAnimatorVO.java
public TweenAnimatorVO(final JSONObject json) throws JSONException { super(json);//from w w w . j ava 2s .c o m interpolation = json.optString("interpolation"); reversed = json.optBoolean("reversed", false); duration = NovaVO.getListInt(json, "duration"); }
From source file:com.phelps.liteweibo.model.weibo.User.java
public static User parse(JSONObject jsonObject) { if (null == jsonObject) { return null; }/*from w w w. j a v a2s .c o m*/ User user = new User(); user.id = jsonObject.optString("id", ""); user.idstr = jsonObject.optString("idstr", ""); user.screen_name = jsonObject.optString("screen_name", ""); user.name = jsonObject.optString("name", ""); user.province = jsonObject.optInt("province", -1); user.city = jsonObject.optInt("city", -1); user.location = jsonObject.optString("location", ""); user.description = jsonObject.optString("description", ""); user.url = jsonObject.optString("url", ""); user.profile_image_url = jsonObject.optString("profile_image_url", ""); user.profile_url = jsonObject.optString("profile_url", ""); user.domain = jsonObject.optString("domain", ""); user.weihao = jsonObject.optString("weihao", ""); user.gender = jsonObject.optString("gender", ""); user.followers_count = jsonObject.optInt("followers_count", 0); user.friends_count = jsonObject.optInt("friends_count", 0); user.statuses_count = jsonObject.optInt("statuses_count", 0); user.favourites_count = jsonObject.optInt("favourites_count", 0); user.created_at = jsonObject.optString("created_at", ""); user.following = jsonObject.optBoolean("following", false); user.allow_all_act_msg = jsonObject.optBoolean("allow_all_act_msg", false); user.geo_enabled = jsonObject.optBoolean("geo_enabled", false); user.verified = jsonObject.optBoolean("verified", false); user.verified_type = jsonObject.optInt("verified_type", -1); user.remark = jsonObject.optString("remark", ""); //user.status = jsonObject.optString("status", ""); // XXX: NO Need ? user.allow_all_comment = jsonObject.optBoolean("allow_all_comment", true); user.avatar_large = jsonObject.optString("avatar_large", ""); user.avatar_hd = jsonObject.optString("avatar_hd", ""); user.verified_reason = jsonObject.optString("verified_reason", ""); user.follow_me = jsonObject.optBoolean("follow_me", false); user.online_status = jsonObject.optInt("online_status", 0); user.bi_followers_count = jsonObject.optInt("bi_followers_count", 0); user.lang = jsonObject.optString("lang", ""); // ???OpenAPI ?? user.star = jsonObject.optString("star", ""); user.mbtype = jsonObject.optString("mbtype", ""); user.mbrank = jsonObject.optString("mbrank", ""); user.block_word = jsonObject.optString("block_word", ""); return user; }
From source file:ezy.boost.update.UpdateInfo.java
private static UpdateInfo parse(JSONObject o) { UpdateInfo info = new UpdateInfo(); if (o == null) { return info; }//from ww w. j a v a2 s.c o m info.hasUpdate = o.optBoolean("hasUpdate", false); if (!info.hasUpdate) { return info; } info.isSilent = o.optBoolean("isSilent", false); info.isForce = o.optBoolean("isForce", false); info.isAutoInstall = o.optBoolean("isAutoInstall", !info.isSilent); info.isIgnorable = o.optBoolean("isIgnorable", true); info.isPatch = o.optBoolean("isPatch", false); info.versionCode = o.optInt("versionCode", 0); info.versionName = o.optString("versionName"); info.updateContent = o.optString("updateContent"); info.url = o.optString("url"); info.md5 = o.optString("md5"); info.size = o.optLong("size", 0); if (!info.isPatch) { return info; } info.patchUrl = o.optString("patchUrl"); info.patchMd5 = o.optString("patchMd5"); info.patchSize = o.optLong("patchSize", 0); return info; }
From source file:com.jumpbyte.mobile.plugin.ChildBrowser.java
/** * Display a new browser with the specified URL. * * @param url The url to load. * @param jsonObject // w w w . j av a2s . c om */ public String showWebPage(final String url, JSONObject options) { // Determine if we should hide the location bar. if (options != null) { showLocationBar = options.optBoolean("showLocationBar", true); showAddressBar = options.optBoolean("showAddressBar", true); } // Create dialog in new thread Runnable runnable = new Runnable() { /** * Convert our DIP units to Pixels * * @return int */ private int dpToPixels(int dipValue) { int value = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, (float) dipValue, ctx.getContext().getResources().getDisplayMetrics()); return value; } public void run() { // Let's create the main dialog dialog = new Dialog(ctx.getContext(), android.R.style.Theme_NoTitleBar); dialog.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog; dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setCancelable(true); dialog.setOnDismissListener(new DialogInterface.OnDismissListener() { public void onDismiss(DialogInterface dialog) { try { JSONObject obj = new JSONObject(); obj.put("type", CLOSE_EVENT); sendUpdate(obj, false); } catch (JSONException e) { Log.d(LOG_TAG, "Should never happen"); } } }); // Main container layout LinearLayout main = new LinearLayout(ctx.getContext()); main.setOrientation(LinearLayout.VERTICAL); // Toolbar layout RelativeLayout toolbar = new RelativeLayout(ctx.getContext()); toolbar.setLayoutParams( new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, this.dpToPixels(44))); toolbar.setPadding(this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2)); toolbar.setHorizontalGravity(Gravity.LEFT); toolbar.setVerticalGravity(Gravity.TOP); // Action Button Container layout RelativeLayout actionButtonContainer = new RelativeLayout(ctx.getContext()); actionButtonContainer.setLayoutParams( new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); actionButtonContainer.setHorizontalGravity(Gravity.LEFT); actionButtonContainer.setVerticalGravity(Gravity.CENTER_VERTICAL); actionButtonContainer.setId(1); // Back button ImageButton back = new ImageButton(ctx.getContext()); RelativeLayout.LayoutParams backLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT); backLayoutParams.addRule(RelativeLayout.ALIGN_LEFT); back.setLayoutParams(backLayoutParams); back.setContentDescription("Back Button"); back.setId(2); try { back.setImageBitmap(loadDrawable("www/childbrowser/icon_arrow_left.png")); } catch (IOException e) { Log.e(LOG_TAG, e.getMessage(), e); } back.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { goBack(); } }); // Forward button ImageButton forward = new ImageButton(ctx.getContext()); RelativeLayout.LayoutParams forwardLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT); forwardLayoutParams.addRule(RelativeLayout.RIGHT_OF, 2); forward.setLayoutParams(forwardLayoutParams); forward.setContentDescription("Forward Button"); forward.setId(3); try { forward.setImageBitmap(loadDrawable("www/childbrowser/icon_arrow_right.png")); } catch (IOException e) { Log.e(LOG_TAG, e.getMessage(), e); } forward.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { goForward(); } }); // Edit Text Box edittext = new EditText(ctx.getContext()); RelativeLayout.LayoutParams textLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); textLayoutParams.addRule(RelativeLayout.RIGHT_OF, 1); textLayoutParams.addRule(RelativeLayout.LEFT_OF, 5); edittext.setLayoutParams(textLayoutParams); edittext.setId(4); edittext.setSingleLine(true); edittext.setText(url); edittext.setInputType(InputType.TYPE_TEXT_VARIATION_URI); edittext.setImeOptions(EditorInfo.IME_ACTION_GO); edittext.setInputType(InputType.TYPE_NULL); // Will not except input... Makes the text NON-EDITABLE edittext.setOnKeyListener(new View.OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { // If the event is a key-down event on the "enter" button if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { navigate(edittext.getText().toString()); return true; } return false; } }); if (!showAddressBar) { edittext.setVisibility(EditText.INVISIBLE); } // Close button ImageButton close = new ImageButton(ctx.getContext()); RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT); closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); close.setLayoutParams(closeLayoutParams); forward.setContentDescription("Close Button"); close.setId(5); try { close.setImageBitmap(loadDrawable("www/childbrowser/icon_close.png")); } catch (IOException e) { Log.e(LOG_TAG, e.getMessage(), e); } close.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { closeDialog(); } }); // WebView webview = new WebView(ctx.getContext()); webview.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); webview.setWebChromeClient(new WebChromeClient()); WebViewClient client = new ChildBrowserClient(edittext); webview.setWebViewClient(client); WebSettings settings = webview.getSettings(); settings.setJavaScriptEnabled(true); settings.setJavaScriptCanOpenWindowsAutomatically(true); settings.setBuiltInZoomControls(true); settings.setPluginsEnabled(true); settings.setDomStorageEnabled(true); webview.loadUrl(url); webview.setId(6); webview.getSettings().setLoadWithOverviewMode(true); webview.getSettings().setUseWideViewPort(true); webview.requestFocus(); webview.requestFocusFromTouch(); // Add the back and forward buttons to our action button container layout actionButtonContainer.addView(back); actionButtonContainer.addView(forward); // Add the views to our toolbar toolbar.addView(actionButtonContainer); toolbar.addView(edittext); toolbar.addView(close); // Don't add the toolbar if its been disabled if (getShowLocationBar()) { // Add our toolbar to our main view/layout main.addView(toolbar); } // Add our webview to our main view/layout main.addView(webview); WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); lp.copyFrom(dialog.getWindow().getAttributes()); lp.width = WindowManager.LayoutParams.FILL_PARENT; lp.height = WindowManager.LayoutParams.FILL_PARENT; dialog.setContentView(main); dialog.show(); dialog.getWindow().setAttributes(lp); } private Bitmap loadDrawable(String filename) throws java.io.IOException { InputStream input = ctx.getAssets().open(filename); return BitmapFactory.decodeStream(input); } }; this.ctx.runOnUiThread(runnable); return ""; }
From source file:com.example.wcl.test_weiboshare.StatusList.java
public static StatusList parse(String jsonString) { if (TextUtils.isEmpty(jsonString)) { return null; }/*w w w . j a v a 2s . c o m*/ StatusList statuses = new StatusList(); try { JSONObject jsonObject = new JSONObject(jsonString); statuses.hasvisible = jsonObject.optBoolean("hasvisible", false); statuses.previous_cursor = jsonObject.optString("previous_cursor", "0"); statuses.next_cursor = jsonObject.optString("next_cursor", "0"); statuses.total_number = jsonObject.optInt("total_number", 0); JSONArray jsonArray = jsonObject.optJSONArray("statuses"); if (jsonArray != null && jsonArray.length() > 0) { int length = jsonArray.length(); statuses.statusList = new ArrayList<Status>(length); for (int ix = 0; ix < length; ix++) { statuses.statusList.add(Status.parse(jsonArray.getJSONObject(ix))); } } } catch (JSONException e) { e.printStackTrace(); } return statuses; }