Example usage for android.util Log e

List of usage examples for android.util Log e

Introduction

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

Prototype

public static int e(String tag, String msg) 

Source Link

Document

Send an #ERROR log message.

Usage

From source file:Main.java

/**
 * This method converts dp unit to equivalent pixels, depending on device
 * density. NEEDS UTILS TO BE INITIALIZED BEFORE USAGE.
 *
 * @param dp A value in dp (density independent pixels) unit. Which we need
 *           to convert into pixels//  w  w w .  j  av a2s.  c o  m
 * @return A float value to represent px equivalent to dp depending on
 * device density
 */
public static float convertDpToPixel(float dp) {

    if (mMetrics == null) {

        Log.e("MPChartLib-Utils", "Utils NOT INITIALIZED. You need to call Utils.init(...) at least once before"
                + " calling Utils.convertDpToPixel(...). Otherwise conversion does not " + "take place.");
        return dp;
        // throw new IllegalStateException(
        // "Utils NOT INITIALIZED. You need to call Utils.init(...) at least once before
        // calling Utils.convertDpToPixel(...).");
    }

    DisplayMetrics metrics = mMetrics;
    float px = dp * (metrics.densityDpi / 160f);
    return px;
}

From source file:Main.java

public static String appNameLookup(Context context, String packageName) {

    try {// www  .  j a v  a  2  s .  co m

        PackageManager pm = context.getPackageManager();
        ApplicationInfo ai = pm.getApplicationInfo(packageName, 0);

        return pm.getApplicationLabel(ai).toString();

    } catch (final PackageManager.NameNotFoundException e) {

        e.printStackTrace();
        Log.e("AppsHelper", "Could not resolve name " + packageName);

        return null;

    }

}

From source file:Main.java

public static Calendar getFinishDate(String startDate, String duration) {
    try {/*from  ww w  . ja va2 s .  c  o m*/
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH);
        Calendar calendarFinish = Calendar.getInstance();
        calendarFinish.setTime(sdf.parse(startDate));
        calendarFinish.add(Calendar.DATE, Integer.parseInt(duration));
        return calendarFinish;
    } catch (ParseException e) {
        Log.e("PARSE_FAIL", Log.getStackTraceString(e));
    }
    return null;
}

From source file:Main.java

/**
 * get the application version//ww  w .  j  a v  a  2  s.co m
 *
 * @return version String
 */

public static String getAppVersion(Context context) {
    String version = "";
    try {
        PackageManager manager = context.getPackageManager();
        PackageInfo info = manager.getPackageInfo(context.getPackageName(), 0);
        version = info.versionName;
    } catch (Exception e) {
        Log.e("YourActivity", "Error getting version");
    }

    return version;
}

From source file:Main.java

private static File getBackupFileName(File f, boolean isGoodBackup) {
    File f2 = null;//from  ww  w .j a va  2  s  . c  o  m
    String prefix = f.getAbsolutePath() + (isGoodBackup ? ".good.bak." : ".corrupted.bak.");
    for (int i = MAX_BACKUP_FILES - 1; i > 2; i--) {
        File to = new File(prefix + i);
        File from = new File(prefix + (i - 1));
        if (to.exists())
            to.delete();
        if (from.exists()) {
            if (!from.renameTo(to))
                Log.e("cr3", "Cannot rename DB file " + from + " to " + to);
        }
    }
    f2 = new File(prefix + 2);
    if (f2.exists())
        if (!f2.delete())
            Log.e("cr3", "Cannot remove DB file " + f2);
    return f2;
}

From source file:Main.java

/**
 * Converts a String to a Date//from ww w .  ja v a  2s.com
 *
 * @param dateString that is in format 30/12/2018 14:18
 * @return Date object
 */
public static Date StringToDate(String dateString) {
    Date result = new Date();
    try {
        result = mDateFormat.parse(dateString);
    } catch (ParseException e) {
        Log.e(TAG, "String " + dateString + " cannot be parsed.");
    }
    return result;
}

From source file:Main.java

public static int getStatusBarHeight(Context context) {
    Class<?> c = null;/*w  w w.  j  av a  2 s . c  om*/
    Object obj = null;
    Field field = null;
    int x = 0, sbar = 0;
    try {
        c = Class.forName("com.android.internal.R$dimen");
        obj = c.newInstance();
        field = c.getField("status_bar_height");
        x = Integer.parseInt(field.get(obj).toString());
        sbar = context.getResources().getDimensionPixelSize(x);
    } catch (Exception e1) {
        Log.e("getStatusBarHight()", "get status bar height fail");
        e1.printStackTrace();
    }
    int statusBarHeight = sbar;
    Log.i("onPreDraw", "statusBarHeight: " + statusBarHeight);
    return statusBarHeight;
}

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
 *//*from   www .  j  ava 2  s . 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

public static Drawable appIconLookup(Context context, String packageName) {

    try {//from   ww w. j a v a  2 s  . c  o  m

        PackageManager pm = context.getPackageManager();
        ApplicationInfo ai = pm.getApplicationInfo(packageName, 0);
        return pm.getApplicationIcon(ai);

    } catch (final PackageManager.NameNotFoundException e) {

        e.printStackTrace();
        Log.e("AppsHelper", "Could not find icon for " + packageName);

        return null;

    }

}

From source file:Main.java

/**
 * Get file content by filename/*from w  w w.  j a v a 2s. co  m*/
 * 
 * @param c
 * @param filename
 * @return content String
 */
public static String getFileContent(Context c, String filename) {
    try {
        InputStream fin = c.getAssets().open(filename);
        byte[] buffer = new byte[fin.available()];
        fin.read(buffer);
        fin.close();
        return new String(buffer);
    } catch (IOException e) {
        Log.e("inspector", e.getLocalizedMessage());
    }
    return "";
}