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

public static File getCacheDirectory(Context context, boolean preferExternal, String dirName) {
    File appCacheDir = null;// w ww  . j  a v  a  2s.  co  m
    if (preferExternal && MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
            && hasExternalStoragePermission(context)) {
        appCacheDir = getExternalCacheDir(context, dirName);
    }
    if (appCacheDir == null) {
        appCacheDir = context.getCacheDir();
    }
    if (appCacheDir == null) {
        String cacheDirPath = "/data/data/" + context.getPackageName() + "/cache/";
        Log.w("Can't define system cache directory! '%s' will be used.", cacheDirPath);
        appCacheDir = new File(cacheDirPath);
    }
    return appCacheDir;
}

From source file:Main.java

public static String getDaysBetween(String date1, String date2) {
    // input is expected to be exactly like; 2011-01-05
    // date2 must be before date1
    String result = "";

    try {/*from  w w  w.jav  a  2  s  .c  o  m*/

        Date dateOne = DateUtils.parseDate(date1, new String[] { "yyyy-MM-dd" });
        Calendar cal1 = Calendar.getInstance();
        cal1.setTime(dateOne);

        Date dateTwo = DateUtils.parseDate(date2, new String[] { "yyyy-MM-dd" });
        Calendar cal2 = Calendar.getInstance();
        cal2.setTime(dateTwo);

        long diff = dateOne.getTime() - dateTwo.getTime();
        Log.d(TAG, "days in between:" + (TimeUnit.MILLISECONDS.toSeconds(diff) / 60 / 60 / 24));
    } catch (Exception ex) {
        Log.w(TAG, ex.toString());
    }

    return result;
}

From source file:Main.java

/**
 * Links a vertex shader and a fragment shader together into an OpenGL
 * program. Returns the OpenGL program object ID, or 0 if linking failed.
 *///w  w w  .j  a  v  a2  s  . c  om
public static int linkProgram(int vertexShaderId, int fragmentShaderId) {

    // Create a new program object.
    final int programObjectId = glCreateProgram();

    if (programObjectId == 0) {
        if (IS_LOGGING_ON) {
            Log.w(TAG, "Could not create new program");
        }

        return 0;
    }

    // Attach the vertex shader to the program.
    glAttachShader(programObjectId, vertexShaderId);

    // Attach the fragment shader to the program.
    glAttachShader(programObjectId, fragmentShaderId);

    // Link the two shaders together into a program.
    glLinkProgram(programObjectId);

    // Get the link status.
    final int[] linkStatus = new int[1];
    glGetProgramiv(programObjectId, GL_LINK_STATUS, linkStatus, 0);

    if (IS_LOGGING_ON) {
        // Print the program info log to the Android log output.
        Log.v(TAG, "Results of linking program:\n" + glGetProgramInfoLog(programObjectId));
    }

    // Verify the link status.
    if (linkStatus[0] == 0) {
        // If it failed, delete the program object.
        glDeleteProgram(programObjectId);

        if (IS_LOGGING_ON) {
            Log.w(TAG, "Linking of program failed.");
        }

        return 0;
    }

    // Return the program object ID.
    return programObjectId;
}

From source file:Main.java

/**
 * @param message     Message to display
 * @param type        [Log.Error, Log.Warn, ...]
 * @param shouldPrint value that comes from Preferences which allows the user to decide if debug info should be printed to logcat. Error info will ALWAYS be displayed despite this value
 *///w  w  w .  j a va 2s . c o m
public static void debugFunc(String message, int type, boolean shouldPrint) {
    // errors must always be displayed
    if (type == Log.ERROR) {
        Log.e(LOG_TAG, message);
    } else if (shouldPrint) {
        switch (type) {
        case Log.DEBUG:
            Log.d(LOG_TAG, message);
            break;
        case Log.INFO:
            Log.i(LOG_TAG, message);
            break;
        case Log.VERBOSE:
            Log.v(LOG_TAG, message);
            break;
        case Log.WARN:
            Log.w(LOG_TAG, message);
            break;
        default:
            Log.v(LOG_TAG, message);
            break;
        }
    }
}

From source file:Main.java

private static void log(String tag, int level, String msg, Throwable tr) {
    if (isLog) {//from   w  ww  . ja v a2 s . co  m
        switch (level) {
        case Log.VERBOSE:
            if (tr == null) {
                Log.v(tag, msg);
            } else {
                Log.v(tag, msg, tr);
            }
            break;
        case Log.INFO:
            if (tr == null) {
                Log.i(tag, msg);
            } else {
                Log.i(tag, msg, tr);
            }
            break;
        case Log.DEBUG:
            if (tr == null) {
                Log.d(tag, msg);
            } else {
                Log.d(tag, msg, tr);
            }
            break;
        case Log.WARN:
            if (tr == null) {
                Log.w(tag, msg);
            } else {
                Log.w(tag, msg, tr);
            }
            break;
        case Log.ERROR:
            if (tr == null) {
                Log.e(tag, msg, tr);
            } else {
                Log.e(tag, msg, tr);
            }
            break;
        }
    }
}

From source file:Main.java

private static String getPhoneNumber(Context context) {
    String result = null;/*  w w w  .  ja v  a 2  s .  co m*/
    try {
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        result = tm.getLine1Number();
    } catch (Exception e) {
        Log.w(LOG_TAG, e);
    }
    return result == null ? "" : result;
}

From source file:Main.java

private static String getPhoneIMSI(Context context) {
    String result = null;/*from   w  w w.jav  a 2s. co  m*/
    try {
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        result = tm.getSubscriberId();
    } catch (Exception e) {
        Log.w(LOG_TAG, e);
    }

    return result == null ? "" : result;
}

From source file:Main.java

private static byte[] generateMacSecret() {
    try {// w  w  w  .  j a v a 2 s . c  o m
        KeyGenerator generator = KeyGenerator.getInstance("HmacSHA1");
        return generator.generateKey().getEncoded();
    } catch (NoSuchAlgorithmException e) {
        Log.w("keyutil", e);
        return null;
    }
}

From source file:Main.java

/**
 * Compiles a shader, returning the OpenGL object ID.
 *//*  w w w. j  a  va  2 s.  c o m*/
private static int compileShader(int type, String shaderCode) {
    // Create a new shader object.
    final int shaderObjectId = glCreateShader(type);

    if (shaderObjectId == 0) {
        Log.w(TAG, "Could not create new shader.");
        return 0;
    }

    // Pass in the shader source.
    glShaderSource(shaderObjectId, shaderCode);

    // Compile the shader.
    glCompileShader(shaderObjectId);

    // Get the compilation status.
    final int[] compileStatus = new int[1];
    glGetShaderiv(shaderObjectId, GL_COMPILE_STATUS, compileStatus, 0);

    // Print the shader info log to the Android log output.
    Log.v(TAG, "Results of compiling source:" + "\n" + shaderCode + "\n:" + glGetShaderInfoLog(shaderObjectId));

    // Verify the compile status.
    if (compileStatus[0] == 0) {
        // If it failed, delete the shader object.
        glDeleteShader(shaderObjectId);
        Log.w(TAG, "Compilation of shader failed.");
        return 0;
    }

    // Return the shader object ID.
    return shaderObjectId;
}

From source file:Main.java

public static String readOneLine(String sFile) {
    BufferedReader brBuffer;//  w  ww.j a  v a  2s. c o m
    String sLine = null;

    try {
        brBuffer = new BufferedReader(new FileReader(sFile), 512);
        try {
            sLine = brBuffer.readLine();
        } finally {
            Log.w(TAG_READ, "file " + sFile + ": " + sLine);
            brBuffer.close();
        }
    } catch (Exception e) {
        Log.e(TAG_READ, "IO Exception when reading /sys/ file", e);
    }
    return sLine;
}