Example usage for android.util Log w

List of usage examples for android.util Log w

Introduction

In this page you can find the example usage for android.util Log w.

Prototype

public static int w(String tag, Throwable tr) 

Source Link

Usage

From source file:net.kayateia.lifestream.Network.java

static public synchronized String DoLogin(Context context, String userText, String passText) {
    Settings settings = new Settings(context);

    // See if we have a GCM ID first.
    String gcmId = settings.getGcmId();
    if (gcmId.equals(""))
        gcmId = GCMRegistrar.getRegistrationId(context);
    if (gcmId.equals("")) {
        // Request one. We'll pick up its contents and re-register later.
        GCMRegistrar.register(context, GCMIntentService.GCM_SENDER_ID);
    } else {/* w  w  w  .j  av  a2  s  . com*/
        String oldId = settings.getGcmId();
        if (!oldId.equals("") && !gcmId.equals(oldId)) {
            Log.w(LOG_TAG, "GCMRegistrar returned a different ID (" + gcmId + ") than we thought we had ("
                    + oldId + ")");
        }
    }
    Log.i(LOG_TAG, "Our GCM ID for user login is: " + gcmId);

    // Do we have an auth ID?
    String authId = settings.getAuthToken();
    if (authId.equals("")) {
        authId = userText + "+" + Settings.GetAndroidID(context);
    }

    // Now contact the LifeStream server.
    HashMap<String, String> parameters = new HashMap<String, String>();
    parameters.put("login", userText);
    parameters.put("pass", passText);
    parameters.put("gcm", gcmId);
    parameters.put("auth", authId);
    String resultText = "";
    try {
        String baseUrl = Settings.GetBaseUrl();
        resultText = HttpMultipartUpload.DownloadString(new URL(baseUrl + "login.php"), parameters, context);

        // Crack the JSON. If we can't parse it, we fail below. If we
        // parse it but get a 'message', we failed too. Otherwise we
        // should have some login info.
        JSONObject result = new JSONObject(resultText);
        String message = result.optString("message");
        if (message != null && message.length() > 0) {
            Log.e(LOG_TAG, "Couldn't log in: " + message);
            return null;
        }

        settings.setUserName(userText);
        settings.setPassword(passText);
        settings.setGcmId(gcmId);
        settings.setAuthToken(authId);
        settings.commit();

        return result.optString("name");
    } catch (IOException e) {
        Log.e(LOG_TAG, "Couldn't log in: " + e);
        return null;
    } catch (JSONException e) {
        Log.e(LOG_TAG, "Couldn't parse login response: " + resultText);
        return null;
    }
}

From source file:com.kevinquan.android.utils.JSONUtils.java

/**
 * Returns a "pretty print" string version of the JSONArray
 * @param array The array to pretty print
 * @param indentation The amount of indentation for each level
 * @return A pretty string //  w  w  w . ja  va  2 s. co m
 */
public static String prettyPrint(JSONArray array, int indentation) {
    if (array == null) {
        return new String();
    }
    try {
        return array.toString(indentation);
    } catch (JSONException je) {
        Log.w(TAG, "Could not pretty print JSON: " + array.toString());
        return new String();
    }
}

From source file:com.github.piasy.biv.example.App.java

static void fixLeakCanary696(Context context) {
    if (!isEmui()) {
        Log.w(TAG, "not emui");
        return;/*  www  . j av  a 2s  . c  o m*/
    }
    try {
        Class clazz = Class.forName("android.gestureboost.GestureBoostManager");
        Log.w(TAG, "clazz " + clazz);

        Field _sGestureBoostManager = clazz.getDeclaredField("sGestureBoostManager");
        _sGestureBoostManager.setAccessible(true);
        Field _mContext = clazz.getDeclaredField("mContext");
        _mContext.setAccessible(true);

        Object sGestureBoostManager = _sGestureBoostManager.get(null);
        if (sGestureBoostManager != null) {
            _mContext.set(sGestureBoostManager, context);
        }
    } catch (Exception ignored) {
        ignored.printStackTrace();
    }
}

From source file:Main.java

private static void createNoMediaFile(File file) {
    try {//from  ww  w .  j a  v a2  s.com
        File noMediaFile = new File(file, NO_MEDIA_FILE);

        if (!noMediaFile.exists()) {
            noMediaFile.createNewFile();
        }
    } catch (IOException e) {
        Log.w(TAG, e.toString());
    }
}

From source file:com.kevinquan.google.activityrecoginition.model.MotionHelper.java

public static List<MotionSnapshot> parseMotionSnapshots(Cursor result, final boolean sortDescending) {
    if (!CursorUtils.hasResults(result)) {
        Log.d(TAG, "No results were provided to parse motion snapshots from");
        return new ArrayList<MotionSnapshot>();
    }//  w  ww .j  a va2 s. c o m
    Hashtable<Long, MotionSnapshot> snapshots = new Hashtable<Long, MotionSnapshot>();

    do {
        Motion thisMotion = new Motion(result);
        if (thisMotion.getTimestamp() == 0) {
            Log.w(TAG, "Current motion seems corrupt: " + thisMotion);
            continue;
        }
        if (!snapshots.containsKey(thisMotion.getTimestamp())) {
            MotionSnapshot snapshot = new MotionSnapshot(thisMotion);
            snapshots.put(snapshot.getTimestamp(), snapshot);
        } else {
            if (!snapshots.get(thisMotion.getTimestamp()).addMotion(thisMotion)) {
                Log.w(TAG, "Could not add motion to snapshot: " + thisMotion.toString());
            }
        }
    } while (result.moveToNext());

    List<MotionSnapshot> results = new ArrayList<MotionSnapshot>();
    results.addAll(snapshots.values());
    Collections.sort(results, new Comparator<MotionSnapshot>() {
        @Override
        public int compare(MotionSnapshot lhs, MotionSnapshot rhs) {
            int result = ((Long) lhs.getTimestamp()).compareTo((Long) rhs.getTimestamp());
            return sortDescending ? -1 * result : result;
        }
    });
    return results;
}

From source file:Main.java

private static File getExternalCacheDir(Context context, String dirName) {
    File dataDir = new File(new File(Environment.getExternalStorageDirectory(), "Android"), "data");
    File appCacheDir2 = new File(new File(dataDir, context.getPackageName()), "cache");
    File appCacheDir = new File(appCacheDir2, dirName);
    if (!appCacheDir.exists()) {
        if (!appCacheDir.mkdirs()) {
            Log.w(TAG, "Unable to create external cache directory");
            return null;
        }//ww  w .  j a  v a2 s  . co m
        try {
            new File(appCacheDir, ".nomedia").createNewFile();
        } catch (IOException e) {
            Log.i(TAG, "Can't create \".nomedia\" file in application external cache directory");
        }
    }
    return appCacheDir;
}

From source file:Main.java

/**
 * From original Android Camera App/* w  w w  .j a  v a2 s.  c  om*/
 * See: http://android.git.kernel.org/?p=platform/packages/apps/Camera.git;a=blob;f=src/com/android/camera/ImageManager.java;h=76a6d1dffdcfb91f2c55032ce14f7cd9ecf7962c;hb=HEAD
 * @param imageData
 * @param quality
 * @param filename
 * @return
 */
public static boolean StoreByteImage(byte[] imageData, int quality, String filename) {
    String directory = storageTarget + "/FreqCap";
    Bitmap source = BitmapFactory.decodeByteArray(imageData, 0, imageData.length);

    OutputStream outputStream = null;
    String filePath = directory + "/" + filename;
    try {
        File dir = new File(directory);
        if (!dir.exists())
            dir.mkdirs();
        File file = new File(directory, filename);
        outputStream = new FileOutputStream(file);
        if (source != null) {
            source.compress(CompressFormat.JPEG, picCompression, outputStream);
        } else {
            outputStream.write(imageData);
            // degree[0] = getExifOrientation(filePath);
        }
        //         outputStream.flush();
        //         outputStream.close();
        Log.e(TAG, file.getAbsolutePath());
    } catch (FileNotFoundException ex) {
        Log.w(TAG, ex);
        return false;
    } catch (IOException ex) {
        Log.w(TAG, ex);
        return false;
    } finally {
        closeSilently(outputStream);
    }
    return true;
}

From source file:Main.java

/**
 * Returns application cache directory. Cache directory will be created on SD card
 * <i>("/Android/data/[app_package_name]/cache")</i> if card is mounted and app has appropriate permission. Else -
 * Android defines cache directory on device's file system.
 *
 * @param context Application context//from w ww .j a v  a 2s  . c o m
 * @return Cache {@link File directory}
 */
public static File getCacheDirectory(Context context) {
    File appCacheDir = null;
    if (MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) && hasExternalStoragePermission(context)) {
        appCacheDir = getExternalCacheDir(context);
    }
    if (appCacheDir == null) {
        appCacheDir = context.getCacheDir();
    }
    if (appCacheDir == null) {
        Log.w(TAG, "Can't define system cache directory! The app should be re-installed.");
    }
    return appCacheDir;
}

From source file:at.bitfire.davdroid.DateUtils.java

public static String findAndroidTimezoneID(String tz) {
    String deviceTZ = null;/*from   ww w . j  av a 2 s .  c  o  m*/
    String availableTZs[] = SimpleTimeZone.getAvailableIDs();

    // first, try to find an exact match (case insensitive)
    for (String availableTZ : availableTZs)
        if (availableTZ.equalsIgnoreCase(tz)) {
            deviceTZ = availableTZ;
            break;
        }

    // if that doesn't work, try to find something else that matches
    if (deviceTZ == null) {
        Log.w(TAG, "Coulnd't find time zone with matching identifiers, trying to guess");
        for (String availableTZ : availableTZs)
            if (StringUtils.indexOfIgnoreCase(tz, availableTZ) != -1) {
                deviceTZ = availableTZ;
                break;
            }
    }

    // if that doesn't work, use UTC as fallback
    if (deviceTZ == null) {
        final String defaultTZ = TimeZone.getDefault().getID();
        Log.e(TAG, "Couldn't identify time zone, using system default (" + defaultTZ + ") as fallback");
        deviceTZ = defaultTZ;
    }

    return deviceTZ;
}

From source file:com.norman0406.slimgress.API.Plext.PlextBase.java

public static PlextBase createByJSON(JSONArray json) throws JSONException {
    if (json.length() != 3) {
        Log.e("PlextBase", "invalid array size");
        return null;
    }/* ww w .  java  2  s  .  co m*/

    JSONObject item = json.getJSONObject(2);
    JSONObject plext = item.getJSONObject("plext");

    PlextBase newPlext = null;

    String plextType = plext.getString("plextType");
    if (plextType.equals("PLAYER_GENERATED"))
        newPlext = new PlextPlayer(json);
    else if (plextType.equals("SYSTEM_BROADCAST"))
        newPlext = new PlextSystem(json);
    else
        Log.w("PlextBase", "unknown plext type: " + plextType);

    return newPlext;
}