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:Main.java

@SuppressWarnings("unchecked")
public static <T> T getMetaData(Context context, String name) {
    try {/*from  w w w  .j a v  a2 s  .  com*/
        final ApplicationInfo ai = context.getPackageManager().getApplicationInfo(context.getPackageName(),
                PackageManager.GET_META_DATA);

        if (ai.metaData != null) {
            return (T) ai.metaData.get(name);
        }
    } catch (Exception e) {
        Log.w("Couldn't find:" + name, name);
    }

    return null;
}

From source file:Main.java

public static Integer stringToInteger(String str) {
    if (str == null) {
        return null;
    } else {/*from   ww  w.  j a v  a  2s.  co  m*/
        try {
            return Integer.parseInt(str);
        } catch (NumberFormatException e) {
            try {
                Double d = Double.valueOf(str);
                if (d.doubleValue() > mMaxInt.doubleValue() + 1.0) {
                    Log.w(TAG, "Value " + d + " too large for integer");
                    return null;
                }
                return Integer.valueOf(d.intValue());
            } catch (NumberFormatException nfe2) {
                Log.w(TAG,
                        "Unable to interpret value " + str + " in field being "
                                + "converted to int, caught NumberFormatException <" + e.getMessage()
                                + "> field discarded");
                return null;
            }
        }
    }
}

From source file:Main.java

public static HashMap<String, String> jsonObject2HashMap(JSONObject jsonObject) {
    HashMap<String, String> hashMap = new HashMap<String, String>();
    Iterator<String> iterator = jsonObject.keys();

    try {/*from  www  . ja  v  a2 s .c om*/
        while (iterator.hasNext()) {
            String key = iterator.next();
            String value = jsonObject.getString(key);
            hashMap.put(key, value);

        }
    } catch (Exception e) {
        Log.w("apputil", "jsonobject2hasmap");
    }
    return hashMap;
}

From source file:Main.java

public static RSAPublicKeySpec getRecipientsPublicKey(String contactNum, Context context) {
    Log.w(TAG, "retrieving public key for contact " + contactNum);
    SharedPreferences prefs = context.getSharedPreferences(contactNum, Context.MODE_PRIVATE);

    String pubMod = prefs.getString(PREF_PUBLIC_MOD, DEFAULT_PREF);
    String pubExp = prefs.getString(PREF_PUBLIC_EXP, DEFAULT_PREF);
    Log.w(TAG, "the public modulus is " + pubMod + " and exponent is " + pubExp + " for " + contactNum);
    // String recipient = prefs.getString(PREF_RECIPIENT_NUM, DEFAULT_PREF);
    if (!pubMod.isEmpty() && !pubExp.isEmpty()) {
        Log.i(TAG, "great! public key found for " + contactNum + " with modulus " + pubMod + " and exponent "
                + pubExp);// ww w. j a  v  a2 s .  c  o  m
        byte[] pubModBA = Base64.decode(pubMod, Base64.DEFAULT);
        byte[] pubExpBA = Base64.decode(pubExp, Base64.DEFAULT);
        BigInteger pubModBI = new BigInteger(1, pubModBA); // 1 is added as
        // an attempt to
        // deal with
        // com.android.org.bouncycastle.crypto.DataLengthException:
        // input too
        // large for RSA
        // cipher
        BigInteger pubExpBI = new BigInteger(1, pubExpBA);
        Log.i(TAG, "public modulus is " + pubModBI + " and public exponent is " + pubExpBI + " in base 256 "
                + pubModBA + " " + pubExpBA);

        // do I need to catch any exception for the following?
        RSAPublicKeySpec pubKeySpec = new RSAPublicKeySpec(pubModBI, pubExpBI);
        // X509EncodedKeySpec publicKeySpec = new
        // X509EncodedKeySpec(encodedKey);

        return pubKeySpec;
    }
    Log.w(TAG, "recipient's public key not found");
    return null;

}

From source file:Main.java

public static String uploadFile(String path) {
    String sourceFileUri = path;/*from   w w  w .jav  a 2s .co m*/
    File file = new File(sourceFileUri);
    ByteArrayOutputStream objByteArrayOS = null;
    FileInputStream objFileIS = null;
    boolean isSuccess = false;
    String strAttachmentCoded = null;

    if (!file.isFile()) {
        Log.w(TAG, "Source File not exist :" + sourceFileUri);
    } else {
        try {
            objFileIS = new FileInputStream(file);
            objByteArrayOS = new ByteArrayOutputStream();
            byte[] byteBufferString = new byte[(int) file.length()];
            objFileIS.read(byteBufferString);

            byte[] byteBinaryData = Base64.encode(byteBufferString, Base64.DEFAULT);
            strAttachmentCoded = new String(byteBinaryData);

            isSuccess = true;
        } catch (Exception e) {
            e.printStackTrace();
            Log.e("Upload file to server", "error: " + e.getMessage(), e);
        } finally {
            try {
                objByteArrayOS.close();
                objFileIS.close();
            } catch (IOException e) {
                Log.e(TAG, "Error : " + e.getMessage());
            }
        }
    }

    if (isSuccess) {
        return strAttachmentCoded;
    } else {
        return "No Picture";
    }
}

From source file:Main.java

/**
 * Retrieves FreeFlight media directory.
 * May return null.//w  w w  .  j a  v  a  2 s.  c o  m
 * @param context
 * @return Media directory to store the media files or null if sd card is not mounted.
 */
public static File getMediaFolder(Context context) {
    File dcimFolder = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);

    if (dcimFolder == null) {
        Log.w(TAG, "Looks like sd card is not available.");
        return null;
    }

    File mediaFolder = new File(dcimFolder, MEDIA_PUBLIC_FOLDER_NAME);

    if (!mediaFolder.exists()) {
        mediaFolder.mkdirs();
        Log.d(TAG, "Root media folder created " + mediaFolder);
    }

    return mediaFolder;
}

From source file:Main.java

private static void deleteDirectorySync(File dir) {
    try {//from  w w  w  . j a va 2  s .  co m
        File[] files = dir.listFiles();
        if (files != null) {
            for (File file : files) {
                String fileName = file.getName();
                if (!file.delete()) {
                    Log.e(TAG, "Failed to remove " + file.getAbsolutePath());
                }
            }
        }
        if (!dir.delete()) {
            Log.w(TAG, "Failed to remove " + dir.getAbsolutePath());
        }
        return;
    } catch (Exception e) {
        Log.e(TAG, "Failed to remove old libs, ", e);
    }
}

From source file:Main.java

static public void copyDataBase() throws IOException {

    OutputStream databaseOutputStream = new FileOutputStream("/mnt/sdcard/jwdroid.db");
    InputStream databaseInputStream = new FileInputStream("/data/data/com.jwdroid/databases/jwdroid");

    byte[] buffer = new byte[1];
    int length;/* w ww.  java2  s.com*/
    while ((length = databaseInputStream.read(buffer)) > 0) {
        databaseOutputStream.write(buffer);
        Log.w("Bytes: ", ((Integer) length).toString());
        Log.w("value", buffer.toString());
    }

    databaseOutputStream.flush();
    databaseOutputStream.close();
    databaseInputStream.close();
}

From source file:Main.java

public static boolean isExists(String urlString) {
    try {/*from w  w  w.j  av  a2 s  . c om*/
        URL u = new URL(urlString);
        HttpURLConnection huc = (HttpURLConnection) u.openConnection();
        huc.setRequestMethod("GET");
        huc.connect();
        int rc = huc.getResponseCode();
        return (rc == HttpURLConnection.HTTP_OK);
        // Handle response code here...
    } catch (UnknownHostException uhe) {
        // Handle exceptions as necessary
        Log.w("EPub", uhe.getMessage());
    } catch (FileNotFoundException fnfe) {
        // Handle exceptions as necessary
        Log.w("EPub", fnfe.getMessage());
    } catch (Exception e) {
        // Handle exceptions as necessary
        Log.w("EPub", e.getMessage());
    }
    return false;
}

From source file:Main.java

public static void LOGW(final String tag, String message) {
    Log.w(tag, message);
}