Example usage for android.util Log d

List of usage examples for android.util Log d

Introduction

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

Prototype

public static int d(String tag, String msg, Throwable tr) 

Source Link

Document

Send a #DEBUG log message and log the exception.

Usage

From source file:Main.java

/**
 * Set the field represented by the supplied {@link Field field object} on the
 * specified {@link Object target object} to the specified <code>value</code>.
 * In accordance with {@link Field#set(Object, Object)} semantics, the new value
 * is automatically unwrapped if the underlying field has a primitive type.
 *
 * @param field  the field to set//from   w w w .j av a  2 s  .c  om
 * @param target the target object on which to set the field
 * @param value  the value to set; may be <code>null</code>
 */
public static void setField(Field field, Object target, Object value) {
    try {
        field.set(target, value);
    } catch (IllegalAccessException ex) {
        Log.d(TAG, "setField failed value= " + value, ex);
    }
}

From source file:Main.java

public static void invokeObjMethod(Object ob, String methodName, CharSequence value) {

    if (ob == null) {
        return;//from w  w  w  .  ja v  a 2 s  .  c  o m
    }
    try {
        Method method = ob.getClass().getMethod(methodName, CharSequence.class);
        method.invoke(ob, value);
    } catch (Exception e) {
        Log.d(TAG, "invokeObjMethod error", e);
    }
}

From source file:Main.java

public static Uri createImageFile() {
    // Create an image file name
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
    String imageFileName = "JPEG_" + timeStamp + "_";
    File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
    File image;/*from w  w w .  j a  v a2 s  .c o  m*/
    try {
        image = File.createTempFile(imageFileName, /* prefix */
                ".jpg", /* suffix */
                storageDir /* directory */
        );
    } catch (IOException e) {
        Log.d(TAG, "create tmp file error!", e);
        return null;
    }
    return Uri.fromFile(image);
}

From source file:Main.java

public static void close(Closeable... closeables) {
    if (closeables == null)
        return;/*from  ww  w.  ja  v  a  2  s .  c o m*/
    for (Closeable c : closeables) {
        if (c == null)
            continue;

        try {
            c.close();
        } catch (Exception e) {
            Log.d("Closing", e.getMessage(), e);
        }
    }
}

From source file:Main.java

private static CharSequence decryptText(String ciphertextString, Cipher cipher) {
    byte[] ciphertext = hexStringToBytes(ciphertextString);
    byte[] plaintext = {};

    //can't decrypt an empty string...exceptions gallore
    if (ciphertextString.length() == 0)
        return (CharSequence) ciphertextString;

    try {//from w w w.  j a v  a2s .c  om
        plaintext = cipher.doFinal(ciphertext);
    } catch (Exception e) {
        Log.d(LOG_TAG, "decryptText", e);
    }

    //TODO: dont' convert to string as interim...insecure
    return (CharSequence) (new String(plaintext));
}

From source file:Main.java

public static boolean checkPassword(char[] plaintextPassword, String passwordHash, String passwordSalt) {
    byte[] calculatedHash = null;
    byte[] savedSalt = hexStringToBytes(passwordSalt);
    byte[] savedHash = hexStringToBytes(passwordHash);

    if (savedHash.length == 0)
        return true; //if they are both empty this will fall through (first time, no set pass)

    try {/*w  w  w.  j av a  2s.  c  om*/
        calculatedHash = generateHash(plaintextPassword, savedSalt);
    } catch (Exception e) {
        Log.d(LOG_TAG, "checkPassword", e);
        return false;
    }

    if (calculatedHash != null) {
        if (Arrays.equals(calculatedHash, savedHash))
            return true;
        else
            return false;
    }
    return false;
}

From source file:Main.java

static Field getField(Class<?> clz, final String fldName) {
    if (clz == null || TextUtils.isEmpty(fldName)) {
        return null;
    }//  ww w.  jav a 2 s. c  o m
    Field fld = null;
    try {
        fld = clz.getDeclaredField(fldName);
        fld.setAccessible(true);
    } catch (NoSuchFieldException e) {
        Log.d(TAG, e.getMessage(), e);
    }
    return fld;
}

From source file:Main.java

public static void LOGD(final String tag, String message, Throwable cause) {
    //noinspection PointlessBooleanExpression,ConstantConditions
    if (debug || Log.isLoggable(tag, Log.DEBUG)) {
        Log.d(tag, message, cause);
    }//from w ww .java  2 s . co m
}

From source file:Main.java

public static BitmapFactory.Options getBitmapOptions(DisplayMetrics mDisplayMetrics) {
    try {/*from  w  w  w  .j  a v a 2  s.  c  om*/
        // TODO I think this can all be done without reflection now because all these properties are SDK 4
        final Field density = DisplayMetrics.class.getDeclaredField("DENSITY_DEFAULT");
        final Field inDensity = BitmapFactory.Options.class.getDeclaredField("inDensity");
        final Field inTargetDensity = BitmapFactory.Options.class.getDeclaredField("inTargetDensity");
        final Field targetDensity = DisplayMetrics.class.getDeclaredField("densityDpi");
        final BitmapFactory.Options options = new BitmapFactory.Options();
        inDensity.setInt(options, density.getInt(null));
        inTargetDensity.setInt(options, targetDensity.getInt(mDisplayMetrics));
        return options;
    } catch (final IllegalAccessException ex) {
        Log.d(TAG, "Couldn't access fields.", ex);
    } catch (final NoSuchFieldException ex) {
        Log.d(TAG, "Couldn't find fields.", ex);
    }
    return null;
}

From source file:Main.java

static Method getMethod(Class<?> clz, final String mtdName, Class<?>[] mtdArgs) {
    if (clz == null || TextUtils.isEmpty(mtdName) || mtdArgs == null) {
        return null;
    }// w  w  w . j a  va 2 s  .c  o  m
    Method mtd = null;
    try {
        mtd = clz.getDeclaredMethod(mtdName, mtdArgs);
        mtd.setAccessible(true);
    } catch (NoSuchMethodException e) {
        Log.d(TAG, e.getMessage(), e);
    }
    return mtd;
}