List of usage examples for android.util Log w
public static int w(String tag, Throwable tr)
From source file:it.fdev.utils.DrawableManager.java
public Drawable fetchDrawable(String urlString) { if (drawableMap.containsKey(urlString)) { return drawableMap.get(urlString); }/*from w ww. j ava 2 s.com*/ try { InputStream is = fetch(urlString); Drawable drawable = Drawable.createFromStream(is, "src"); if (drawable != null) { drawableMap.put(urlString, drawable); } else { Log.w(Utils.TAG, "could not get thumbnail"); } return drawable; } catch (MalformedURLException e) { Log.e(Utils.TAG, "fetchDrawable failed", e); return null; } catch (IOException e) { Log.e(Utils.TAG, "fetchDrawable failed", e); return null; } }
From source file:com.kevinquan.android.utils.JSONUtils.java
/** * Construct a JSON Object from the string representation of JSON * @param jsonAsString The string representation of the JSON * @return The JSON object or null if it could not be constructed *///from w ww.j a v a2 s . c om public static JSONObject safeCreateObject(String jsonAsString) { if (TextUtils.isEmpty(jsonAsString)) { Log.w(TAG, "No content was provided."); return new JSONObject(); } JSONObject object = null; try { object = new JSONObject(jsonAsString); } catch (JSONException je) { Log.e(TAG, "Could not construct JSON object from source string: " + jsonAsString, je); return new JSONObject(); } return object; }
From source file:com.arellomobile.android.push.utils.NetworkUtils.java
public static NetworkResult makeRequest(Map<String, Object> data, String methodName) throws Exception { NetworkResult result = new NetworkResult(500, null); OutputStream connectionOutput = null; InputStream inputStream = null; try {//from ww w. j a v a 2 s . c o m String urlString = NetworkUtils.BASE_URL + methodName; if (useSSL) urlString = NetworkUtils.BASE_URL_SECURE + methodName; URL url = new URL(urlString); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("POST"); connection.setRequestProperty("Content-Type", "application/json; charset=utf-8"); connection.setDoOutput(true); JSONObject innerRequestJson = new JSONObject(); for (String key : data.keySet()) { innerRequestJson.put(key, data.get(key)); } JSONObject requestJson = new JSONObject(); requestJson.put("request", innerRequestJson); connection.setRequestProperty("Content-Length", String.valueOf(requestJson.toString().getBytes().length)); connectionOutput = connection.getOutputStream(); connectionOutput.write(requestJson.toString().getBytes()); connectionOutput.flush(); connectionOutput.close(); inputStream = new BufferedInputStream(connection.getInputStream()); ByteArrayOutputStream dataCache = new ByteArrayOutputStream(); // Fully read data byte[] buff = new byte[1024]; int len; while ((len = inputStream.read(buff)) >= 0) { dataCache.write(buff, 0, len); } // Close streams dataCache.close(); String jsonString = new String(dataCache.toByteArray()).trim(); Log.w(TAG, "PushWooshResult: " + jsonString); JSONObject resultJSON = new JSONObject(jsonString); result.setData(resultJSON); result.setCode(resultJSON.getInt("status_code")); } finally { if (null != inputStream) { inputStream.close(); } if (null != connectionOutput) { connectionOutput.close(); } } return result; }
From source file:de.electricdynamite.pasty.GCMIntentService.java
@Override protected void onError(Context context, String errorId) { // TODO Auto-generated method stub Log.w(TAG, "onError(): " + errorId); }
From source file:Main.java
/** * Write a string value to the specified file. * //from w ww . j av a 2s . c om * @param filename The filename * @param value The value */ public static void writeValue(String filename, Boolean value) { FileOutputStream fos = null; String sEnvia; try { fos = new FileOutputStream(new File(filename), false); if (value) sEnvia = "1"; else sEnvia = "0"; fos.write(sEnvia.getBytes()); fos.flush(); // fos.getFD().sync(); } catch (FileNotFoundException ex) { Log.w(TAG, "file " + filename + " not found: " + ex); } catch (SyncFailedException ex) { Log.w(TAG, "file " + filename + " sync failed: " + ex); } catch (IOException ex) { Log.w(TAG, "IOException trying to sync " + filename + ": " + ex); } catch (RuntimeException ex) { Log.w(TAG, "exception while syncing file: ", ex); } finally { if (fos != null) { try { Log.w(TAG_WRITE, "file " + filename + ": " + value); fos.close(); } catch (IOException ex) { Log.w(TAG, "IOException while closing synced file: ", ex); } catch (RuntimeException ex) { Log.w(TAG, "exception while closing file: ", ex); } } } }
From source file:net.cs76.projects.student10792819.DrawableManager.java
/** * Fetch drawable. This fetches a drawable from the url and returns it. Returns null on errors. * * @param urlString the url string// w w w . j a va 2 s . c o m * @return the drawable */ public static Drawable fetchDrawable(String urlString) { if (drawableMap.containsKey(urlString)) { Drawable o = drawableMap.get(urlString).get(); if (o != null) return o; } try { InputStream is = fetch(urlString); Drawable drawable = Drawable.createFromStream(is, "src"); if (drawable != null) { drawableMap.put(urlString, new SoftReference<Drawable>(drawable)); } else { Log.w("DrawableManager", "could not get thumbnail"); } return drawable; } catch (MalformedURLException e) { Log.e("DrawableManager", "fetchDrawable failed", e); return null; } catch (IOException e) { Log.e("DrawableManager", "fetchDrawable failed", e); return null; } }
From source file:com.admob.mobileads.YandexInterstitial.java
@Override public void requestInterstitialAd(final Context context, final CustomEventInterstitialListener customEventInterstitialListener, final String serverParameter, final MediationAdRequest mediationAdRequest, final Bundle adMobExtras) { mInterstitialListener = customEventInterstitialListener; if (mInterstitialListener == null) { Log.w(TAG, "customEventInterstitialListener must not be null"); return;/* w w w.ja va 2 s. c o m*/ } if (isValidServerExtras(serverParameter)) { try { parseServerExtras(serverParameter); final com.yandex.mobile.ads.AdRequest adRequest = configureAdRequest(mediationAdRequest); mInterstitialAd = new InterstitialAd(context); mInterstitialAd.setBlockId(mBlockId); mInterstitialAd.shouldOpenLinksInApp(mOpenLinksInApp); mInterstitialAd.setInterstitialEventListener(mInterstitialEventListener); mInterstitialAd.loadAd(adRequest); } catch (JSONException e) { mInterstitialListener.onAdFailedToLoad(AdRequest.ERROR_CODE_NO_FILL); } } else { mInterstitialListener.onAdFailedToLoad(AdRequest.ERROR_CODE_NO_FILL); } }
From source file:com.intel.iotkitlib.LibModules.AuthorizationManagement.AuthorizationToken.java
private static void storeToken(String token) { //validating shared prefs-editor if (Utilities.editor == null) { Log.w(TAG, "invalid shared preferences-editor object"); }/*w w w . j av a 2s. co m*/ if (token == null) { Log.w(TAG, "Token cannot be empty"); } Utilities.editor.putString("auth_token", token); Utilities.editor.commit(); }
From source file:gmc.hotplate.util.JsonParser.java
public List<Recipe> parseMessage(JSONObject obj) { List<Recipe> recipes = new ArrayList<Recipe>(); try {//from ww w. j a v a 2s. c om JSONArray jsonRecipes = obj.getJSONArray(TAG_RECIPES); for (int i = 0; i < jsonRecipes.length(); i++) { Recipe recipe = parseRecipeObject(jsonRecipes.getJSONObject(i)); if (recipe != null) { recipes.add(recipe); } } } catch (JSONException e) { Log.w(LOG_TAG, "ParseMessage() error: " + e.getMessage()); } return recipes; }
From source file:com.lvlstudios.android.gtmessage.DeviceRegistrar.java
public static void registerWithServer(final Context context, final String deviceRegistrationID) { new Thread(new Runnable() { @Override/* w ww .j a va 2 s . c om*/ public void run() { // Success/failure to be displayed on Setup screens. Intent updateUIIntent = new Intent("com.google.ctp.UPDATE_UI"); try { // Make the request to our server to save the registration id. HttpResponse res = makeRequest(context, deviceRegistrationID, REGISTER_PATH); if (res.getStatusLine().getStatusCode() == 200) { // Save registration id to preferences SharedPreferences settings = Prefs.get(context); SharedPreferences.Editor editor = settings.edit(); editor.putString("deviceRegistrationID", deviceRegistrationID); editor.commit(); updateUIIntent.putExtra(STATUS_EXTRA, REGISTERED_STATUS); } else if (res.getStatusLine().getStatusCode() == 400) { updateUIIntent.putExtra(STATUS_EXTRA, AUTH_ERROR_STATUS); } else { Log.w(TAG, "Registration error " + String.valueOf(res.getStatusLine().getStatusCode())); updateUIIntent.putExtra(STATUS_EXTRA, ERROR_STATUS); } context.sendBroadcast(updateUIIntent); } catch (AppEngineClient.PendingAuthException pae) { // Get setup activity to ask permission from user. Intent intent = new Intent(SetupActivity.AUTH_PERMISSION_ACTION); intent.putExtra("AccountManagerBundle", pae.getAccountManagerBundle()); context.sendBroadcast(intent); } catch (Exception e) { Log.w(TAG, "Registration error " + e.getMessage()); updateUIIntent.putExtra(STATUS_EXTRA, ERROR_STATUS); context.sendBroadcast(updateUIIntent); } } }).start(); }