List of usage examples for org.json JSONException printStackTrace
public void printStackTrace()
From source file:com.wabbit.libraries.remoting.HttpHelper.java
static public JSONArray loadJSON(String url) { HttpURLConnection connection = null; JSONArray json = null;// w w w . java 2 s . c o m InputStream is = null; try { connection = (HttpURLConnection) new URL(url).openConnection(); connection.setConnectTimeout(5000); is = new BufferedInputStream(connection.getInputStream()); json = new JSONArray(convertStreamToString(is)); } catch (IOException ioe) { ioe.printStackTrace(); } catch (JSONException je) { je.printStackTrace(); } finally { try { if (is != null) { is.close(); } } catch (IOException ioe) { ioe.printStackTrace(); } if (connection != null) { connection.disconnect(); } } return json; }
From source file:com.ct.speech.TTS.java
@Override public PluginResult execute(String action, JSONArray args, String callbackId) { PluginResult.Status status = PluginResult.Status.OK; String result = ""; try {// www.j a v a 2 s . co m if (action.equals("speak")) { String text = args.getString(0); if (isReady()) { mTts.speak(text, TextToSpeech.QUEUE_ADD, null); return new PluginResult(status, result); } else { JSONObject error = new JSONObject(); error.put("message", "TTS service is still initialzing."); error.put("code", TTS.INITIALIZING); return new PluginResult(PluginResult.Status.ERROR, error); } } else if (action.equals("silence")) { if (isReady()) { mTts.playSilence(args.getLong(0), TextToSpeech.QUEUE_ADD, null); return new PluginResult(status, result); } else { JSONObject error = new JSONObject(); error.put("message", "TTS service is still initialzing."); error.put("code", TTS.INITIALIZING); return new PluginResult(PluginResult.Status.ERROR, error); } } else if (action.equals("startup")) { if (mTts == null) { this.startupCallbackId = callbackId; state = TTS.INITIALIZING; mTts = new TextToSpeech((Context) ctx, this); //mTts.setLanguage(Locale.US); } PluginResult pluginResult = new PluginResult(status, TTS.INITIALIZING); pluginResult.setKeepCallback(true); return pluginResult; } else if (action.equals("shutdown")) { if (mTts != null) { mTts.shutdown(); } return new PluginResult(status, result); } else if (action.equals("stop")) { if (mTts != null) { mTts.stop(); } return new PluginResult(status, result); } else if (action.equals("getLanguage")) { if (mTts != null) { result = mTts.getLanguage().toString(); return new PluginResult(status, result); } } else if (action.equals("isLanguageAvailable")) { if (mTts != null) { Locale loc = new Locale(args.getString(0)); int available = mTts.isLanguageAvailable(loc); result = (available < 0) ? "false" : "true"; return new PluginResult(status, result); } } else if (action.equals("setLanguage")) { if (mTts != null) { Locale loc = new Locale(args.getString(0)); int available = mTts.setLanguage(loc); result = (available < 0) ? "false" : "true"; return new PluginResult(status, result); } } return new PluginResult(status, result); } catch (JSONException e) { e.printStackTrace(); return new PluginResult(PluginResult.Status.JSON_EXCEPTION); } }
From source file:com.jjoseba.podemosquotes.model.JSONReader.java
public ArrayList<Quote> parse() { String contentsJson = readJSONFile(); HashMap<String, QuoteAuthor> authors = new HashMap<>(); ArrayList<Quote> quotes = new ArrayList<>(); try {//from ww w . j ava 2 s .c o m JSONObject json = new JSONObject(contentsJson); JSONArray authorsArray = json.getJSONArray("authors"); for (int i = 0; i < authorsArray.length(); ++i) { JSONObject auth = (JSONObject) authorsArray.get(i); QuoteAuthor author = new QuoteAuthor(); author.setName(auth.getString("name")); author.setImagePath(auth.getString("image")); author.setPosition(auth.getString("position")); authors.put(auth.getString("id"), author); } JSONArray quotesArray = json.getJSONArray("quotes"); for (int i = 0; i < quotesArray.length(); ++i) { JSONObject q = (JSONObject) quotesArray.get(i); Quote quote = new Quote(); quote.setQuote(q.getString("quote")); quote.setSoundPath(q.getString("sound")); quote.setAuthor(authors.get(q.getString("author"))); quotes.add(quote); } } catch (JSONException e) { e.printStackTrace(); } return quotes; }
From source file:com.bradzzz.dotdashdot.mytv_stream.activity.TvShowsActivity.java
/** * Initialize the Activity with some injected data. *//*from w w w .j a v a 2 s . c om*/ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_tv_shows_sample); ButterKnife.inject(this); //handler.postDelayed(runnable, 10000); self = this; ClassMyTVClient client = new ClassMyTVClient("https://mytv-stream.herokuapp.com", requestCallback); try { client.getMediaMeta(); } catch (JSONException e) { e.printStackTrace(); } }
From source file:com.doylestowncoder.plugin.mobileaccessibility.MobileAccessibility.java
@Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { try {/*from w w w. java2 s. c o m*/ if (action.equals("isScreenReaderRunning")) { isScreenReaderRunning(callbackContext); return true; } else if (action.equals("isClosedCaptioningEnabled")) { isClosedCaptioningEnabled(callbackContext); return true; } else if (action.equals("isTouchExplorationEnabled")) { isTouchExplorationEnabled(callbackContext); return true; } else if (action.equals("postNotification")) { if (args.length() > 1) { String string = args.getString(1); if (!string.isEmpty()) { announceForAccessibility(string, callbackContext); } } return true; } else if (action.equals("getTextZoom")) { getTextZoom(callbackContext); return true; } else if (action.equals("setTextZoom")) { if (args.length() > 0) { double textZoom = args.getDouble(0); if (textZoom > 0) { setTextZoom(textZoom, callbackContext); } } return true; } else if (action.equals("updateTextZoom")) { updateTextZoom(callbackContext); return true; } else if (action.equals("start")) { start(callbackContext); return true; } else if (action.equals("stop")) { stop(); return true; } } catch (JSONException e) { e.printStackTrace(); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION)); } return false; }
From source file:com.doylestowncoder.plugin.mobileaccessibility.MobileAccessibility.java
protected void announceForAccessibility(CharSequence text, final CallbackContext callbackContext) { mMobileAccessibilityHelper.announceForAccessibility(text); if (callbackContext != null) { JSONObject info = new JSONObject(); try {//from ww w.j a va2 s. co m info.put("stringValue", text); info.put("wasSuccessful", mIsScreenReaderRunning); } catch (JSONException e) { e.printStackTrace(); } callbackContext.success(info); } }
From source file:com.doylestowncoder.plugin.mobileaccessibility.MobileAccessibility.java
protected JSONObject getMobileAccessibilityStatus() { JSONObject status = new JSONObject(); try {//from w w w .jav a 2 s. co m status.put("isScreenReaderRunning", mIsScreenReaderRunning); status.put("isClosedCaptioningEnabled", mClosedCaptioningEnabled); status.put("isTouchExplorationEnabled", mTouchExplorationEnabled); //Log.i("MobileAccessibility", "MobileAccessibility.isScreenReaderRunning == " + status.getString("isScreenReaderRunning") + // "\nMobileAccessibility.isClosedCaptioningEnabled == " + status.getString("isClosedCaptioningEnabled") + // "\nMobileAccessibility.isTouchExplorationEnabled == " + status.getString("isTouchExplorationEnabled") ); } catch (JSONException e) { e.printStackTrace(); } return status; }
From source file:com.example.quadros_10084564.sunshine_v2.FetchWeatherTask.java
/** * Take the String representing the complete forecast in JSON Format and * pull out the data we need to construct the Strings needed for the wireframes. * * Fortunately parsing is easy: constructor takes the JSON string and converts it * into an Object hierarchy for us./*from w w w. ja v a 2 s . c om*/ */ private void getWeatherDataFromJson(String forecastJsonStr, String locationSetting) throws JSONException { // Now we have a String representing the complete forecast in JSON Format. // Fortunately parsing is easy: constructor takes the JSON string and converts it // into an Object hierarchy for us. // These are the names of the JSON objects that need to be extracted. // Location information final String OWM_CITY = "city"; final String OWM_CITY_NAME = "name"; final String OWM_COORD = "coord"; // Location coordinate final String OWM_LATITUDE = "lat"; final String OWM_LONGITUDE = "lon"; // Weather information. Each day's forecast info is an element of the "list" array. final String OWM_LIST = "list"; final String OWM_PRESSURE = "pressure"; final String OWM_HUMIDITY = "humidity"; final String OWM_WINDSPEED = "speed"; final String OWM_WIND_DIRECTION = "deg"; // All temperatures are children of the "temp" object. final String OWM_TEMPERATURE = "temp"; final String OWM_MAX = "max"; final String OWM_MIN = "min"; final String OWM_WEATHER = "weather"; final String OWM_DESCRIPTION = "main"; final String OWM_WEATHER_ID = "id"; try { JSONObject forecastJson = new JSONObject(forecastJsonStr); JSONArray weatherArray = forecastJson.getJSONArray(OWM_LIST); JSONObject cityJson = forecastJson.getJSONObject(OWM_CITY); String cityName = cityJson.getString(OWM_CITY_NAME); JSONObject cityCoord = cityJson.getJSONObject(OWM_COORD); double cityLatitude = cityCoord.getDouble(OWM_LATITUDE); double cityLongitude = cityCoord.getDouble(OWM_LONGITUDE); long locationId = addLocation(locationSetting, cityName, cityLatitude, cityLongitude); // Insert the new weather information into the database Vector<ContentValues> cVVector = new Vector<ContentValues>(weatherArray.length()); // OWM returns daily forecasts based upon the local time of the city that is being // asked for, which means that we need to know the GMT offset to translate this data // properly. // Since this data is also sent in-order and the first day is always the // current day, we're going to take advantage of that to get a nice // normalized UTC date for all of our weather. Time dayTime = new Time(); dayTime.setToNow(); // we start at the day returned by local time. Otherwise this is a mess. int julianStartDay = Time.getJulianDay(System.currentTimeMillis(), dayTime.gmtoff); // now we work exclusively in UTC dayTime = new Time(); for (int i = 0; i < weatherArray.length(); i++) { // These are the values that will be collected. long dateTime; double pressure; int humidity; double windSpeed; double windDirection; double high; double low; String description; int weatherId; // Get the JSON object representing the day JSONObject dayForecast = weatherArray.getJSONObject(i); // Cheating to convert this to UTC time, which is what we want anyhow dateTime = dayTime.setJulianDay(julianStartDay + i); pressure = dayForecast.getDouble(OWM_PRESSURE); humidity = dayForecast.getInt(OWM_HUMIDITY); windSpeed = dayForecast.getDouble(OWM_WINDSPEED); windDirection = dayForecast.getDouble(OWM_WIND_DIRECTION); // Description is in a child array called "weather", which is 1 element long. // That element also contains a weather code. JSONObject weatherObject = dayForecast.getJSONArray(OWM_WEATHER).getJSONObject(0); description = weatherObject.getString(OWM_DESCRIPTION); weatherId = weatherObject.getInt(OWM_WEATHER_ID); // Temperatures are in a child object called "temp". Try not to name variables // "temp" when working with temperature. It confuses everybody. JSONObject temperatureObject = dayForecast.getJSONObject(OWM_TEMPERATURE); high = temperatureObject.getDouble(OWM_MAX); low = temperatureObject.getDouble(OWM_MIN); ContentValues weatherValues = new ContentValues(); weatherValues.put(WeatherEntry.COLUMN_LOC_KEY, locationId); weatherValues.put(WeatherEntry.COLUMN_DATE, dateTime); weatherValues.put(WeatherEntry.COLUMN_HUMIDITY, humidity); weatherValues.put(WeatherEntry.COLUMN_PRESSURE, pressure); weatherValues.put(WeatherEntry.COLUMN_WIND_SPEED, windSpeed); weatherValues.put(WeatherEntry.COLUMN_DEGREES, windDirection); weatherValues.put(WeatherEntry.COLUMN_MAX_TEMP, high); weatherValues.put(WeatherEntry.COLUMN_MIN_TEMP, low); weatherValues.put(WeatherEntry.COLUMN_SHORT_DESC, description); weatherValues.put(WeatherEntry.COLUMN_WEATHER_ID, weatherId); cVVector.add(weatherValues); } int inserted = 0; // add to database if (cVVector.size() > 0) { ContentValues[] cvArray = new ContentValues[cVVector.size()]; cVVector.toArray(cvArray); inserted = mContext.getContentResolver().bulkInsert(WeatherEntry.CONTENT_URI, cvArray); } Log.d(LOG_TAG, "FetchWeatherTask Complete. " + inserted + " Inserted"); } catch (JSONException e) { Log.e(LOG_TAG, e.getMessage(), e); e.printStackTrace(); } }
From source file:com.devsh.androidlogin.library.FacebookLoginUtil.java
private FacebookLoginUtil() { callbackManager = CallbackManager.Factory.create(); accessTokenTracker = new AccessTokenTracker() { @Override/* www .ja v a2s .c o m*/ protected void onCurrentAccessTokenChanged(AccessToken oldAccessToken, AccessToken currentAccessToken) { if (oldAccessToken == null && currentAccessToken != null) { loginCallback.onCallback(currentAccessToken); } if (oldAccessToken != null && currentAccessToken == null) { SharedData.clearSharedPreference(sContext); logoutCallback.onCallback(currentAccessToken); } if (oldAccessToken != null && currentAccessToken != null) { updateTokenCallback.onCallback(currentAccessToken); } } }; // profileTracker = new ProfileTracker() { // @Override // protected void onCurrentProfileChanged( // Profile oldProfile, // Profile currentProfile) { // Log.i(TAG, "oldProfile" + oldProfile + "currentProfile" + currentProfile); // } // }; loginCallback = nullCallback; logoutCallback = nullCallback; updateTokenCallback = nullCallback; // LoginResultCallback LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() { @Override public void onSuccess(LoginResult loginResult) { Profile profile = Profile.getCurrentProfile(); final AccessToken accessToken = loginResult.getAccessToken(); if (profile != null) { SharedData.putAccountProvider(sContext, SharedData.PROVIDER_FACEBOOK); SharedData.putAccountIdToken(sContext, accessToken.getToken()); SharedData.putAccountId(sContext, profile.getId()); SharedData.putAccountUserName(sContext, profile.getName()); SharedData.putAccountUserPhoto(sContext, profile.getProfilePictureUri(200, 200).toString()); // No email loginResultCallback.onSuccess(loginResult); } else { final LoginResult loginResult2 = loginResult; GraphRequest request = GraphRequest.newMeRequest(accessToken, new GraphRequest.GraphJSONObjectCallback() { @Override public void onCompleted(JSONObject object, GraphResponse response) { SharedData.putAccountProvider(sContext, SharedData.PROVIDER_FACEBOOK); SharedData.putAccountIdToken(sContext, accessToken.getToken()); SharedData.putAccountId(sContext, accessToken.getUserId()); try { String userName = response.getJSONObject().getString("name"); String userPhoto = object.getJSONObject("picture").getJSONObject("data") .getString("url"); String userEmail = object.getString("email"); SharedData.putAccountUserName(sContext, userName); SharedData.putAccountUserPhoto(sContext, userPhoto); SharedData.putAccountUserEmail(sContext, userEmail); } catch (JSONException e) { e.printStackTrace(); } loginResultCallback.onSuccess(loginResult2); } }); Bundle parameters = new Bundle(); parameters.putString("fields", "id,name,email,picture"); request.setParameters(parameters); request.executeAsync(); } } @Override public void onCancel() { SharedData.clearSharedPreference(sContext); loginResultCallback.onCancel(); } @Override public void onError(FacebookException error) { SharedData.clearSharedPreference(sContext); loginResultCallback.onError(error); } }); }
From source file:com.tuarua.AVANEContext.java
public AVANEContext() { libAVANE.eventDispatcher.addEventListener(Event.TRACE, new IEventHandler() { @Override//from w ww . java 2 s.c o m public void callback(Event event) { trace((String) event.getParams()); } }); libAVANE.eventDispatcher.addEventListener(Event.INFO, new IEventHandler() { @Override public void callback(Event event) { dispatchStatusEventAsync(String.valueOf(event.getParams()), Event.INFO); } }); libAVANE.eventDispatcher.addEventListener(Event.INFO_HTML, new IEventHandler() { @Override public void callback(Event event) { dispatchStatusEventAsync(String.valueOf(event.getParams()), Event.INFO_HTML); } }); libAVANE.eventDispatcher.addEventListener(Event.ON_PROBE_INFO_AVAILABLE, new IEventHandler() { @Override public void callback(Event event) { dispatchStatusEventAsync("", Event.ON_PROBE_INFO); } }); libAVANE.eventDispatcher.addEventListener(Event.NO_PROBE_INFO, new IEventHandler() { @Override public void callback(Event event) { dispatchStatusEventAsync("", Event.NO_PROBE_INFO); } }); libAVANE.eventDispatcher.addEventListener(Event.ON_ENCODE_START, new IEventHandler() { @Override public void callback(Event event) { dispatchStatusEventAsync("", Event.ON_ENCODE_START); } }); libAVANE.eventDispatcher.addEventListener(Event.ON_ENCODE_ERROR, new IEventHandler() { @Override public void callback(Event event) { dispatchStatusEventAsync(String.valueOf(event.getParams()), Event.ON_ENCODE_ERROR); } }); libAVANE.eventDispatcher.addEventListener(Event.ON_ERROR_MESSAGE, new IEventHandler() { @Override public void callback(Event event) { dispatchStatusEventAsync(String.valueOf(event.getParams()), Event.ON_ERROR_MESSAGE); } }); libAVANE.eventDispatcher.addEventListener(Event.ON_ENCODE_FATAL, new IEventHandler() { @Override public void callback(Event event) { dispatchStatusEventAsync(String.valueOf(event.getParams()), Event.ON_ENCODE_FATAL); } }); libAVANE.eventDispatcher.addEventListener(Event.ON_ENCODE_FINISH, new IEventHandler() { @Override public void callback(Event event) { dispatchStatusEventAsync("", Event.ON_ENCODE_FINISH); } }); libAVANE.eventDispatcher.addEventListener(Event.ON_ENCODE_PROGRESS, new IEventHandler() { @Override public void callback(Event event) { final Progress progress = (Progress) event.getParams(); JSONObject obj = new JSONObject(); try { obj.put("bitrate", progress.bitrate); obj.put("frame", progress.frame); obj.put("fps", progress.fps); obj.put("secs", progress.secs); obj.put("size", progress.size); obj.put("speed", progress.speed); obj.put("us", progress.us); dispatchStatusEventAsync(obj.toString(), Event.ON_ENCODE_PROGRESS); } catch (JSONException e) { e.printStackTrace(); } } }); }