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) 

Source Link

Document

Send a #DEBUG log message.

Usage

From source file:Main.java

public static void saveThumb(Context context, String thumbName, Bitmap image) {
    if (thumbName == null || thumbName.length() <= 0)
        return;/*ww w .j  a  va2s .c o m*/

    File pictureFile = getOutputMediaFile(context, thumbName);
    File dir = new File(context.getCacheDir() + "/thumbnails");
    if (dir.exists())//too many caches
    {
        File files[] = dir.listFiles();
        if (files.length > CACHE_LIMIT)
            files[0].deleteOnExit();
    }
    if (pictureFile == null) {
        Log.d(TAG, "Error creating media file, check storage permissions: ");// e.getMessage());
        return;
    }
    try {
        FileOutputStream fos = new FileOutputStream(pictureFile);
        image.compress(Bitmap.CompressFormat.PNG, 90, fos);
        fos.close();
    } catch (FileNotFoundException e) {
        Log.d(TAG, "File not found: " + e.getMessage());
    } catch (IOException e) {
        Log.d(TAG, "Error accessing file: " + e.getMessage());
    }
}

From source file:Main.java

public static String execRootCmd(String[] cmds) {
    String result = "";
    DataOutputStream dos = null;//from   ww  w  .  j a v  a2 s.com
    DataInputStream dis = null;

    try {
        Process p = Runtime.getRuntime().exec("su");
        dos = new DataOutputStream(p.getOutputStream());
        dis = new DataInputStream(p.getInputStream());

        for (String cmd : cmds) {
            Log.i("CmdUtils", cmd);
            dos.writeBytes(cmd + "\n");
            dos.flush();
        }
        dos.writeBytes("exit\n");
        dos.flush();
        String line;
        while ((line = dis.readLine()) != null) {
            Log.d("result", line);
            result += line;
        }
        p.waitFor();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (dos != null) {
            try {
                dos.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        if (dis != null) {
            try {
                dis.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    return result;
}

From source file:Main.java

public static String getDeviceUUID(Context context) {

    @SuppressWarnings("static-access")
    final TelephonyManager tm = (TelephonyManager) context.getSystemService(context.TELEPHONY_SERVICE);

    final String tmDevice, tmSerial, tmPhone, androidId;

    tmDevice = "" + tm.getDeviceId();

    tmSerial = "" + tm.getSimSerialNumber();

    androidId = "" + android.provider.Settings.Secure.getString(context.getContentResolver(),
            android.provider.Settings.Secure.ANDROID_ID);

    UUID deviceUuid = new UUID(androidId.hashCode(), ((long) tmDevice.hashCode() << 32) | tmSerial.hashCode());

    String uniqueId = deviceUuid.toString();

    Log.d("debug", "uuid=" + uniqueId);

    return uniqueId;
}

From source file:Main.java

public static int execRootCmdForExitCode(String[] cmds) {
    int result = -1;
    DataOutputStream dos = null;/*from w  ww  .ja va2s .  co m*/
    DataInputStream dis = null;

    try {
        Process p = Runtime.getRuntime().exec("su");
        dos = new DataOutputStream(p.getOutputStream());
        dis = new DataInputStream(p.getInputStream());

        for (String cmd : cmds) {
            Log.i("CmdUtils", cmd);
            dos.writeBytes(cmd + "\n");
            dos.flush();
        }
        dos.writeBytes("exit\n");
        dos.flush();
        String line;
        while ((line = dis.readLine()) != null) {
            Log.d("result", line);
        }
        p.waitFor();
        result = p.exitValue();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (dos != null) {
            try {
                dos.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        if (dis != null) {
            try {
                dis.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    return result;
}

From source file:Main.java

/**
 * Retrieves FreeFlight media directory.
 * May return null./* w  ww .j  av  a 2s . c om*/
 * @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

public static Bitmap getUploadBitmap(String imagePath) {
    BitmapFactory.Options bmOptions = new BitmapFactory.Options();
    bmOptions.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(imagePath, bmOptions);
    int photoW = bmOptions.outWidth;
    int photoH = bmOptions.outHeight;

    /* Figure out which way needs to be reduced less */
    int scaleFactor;
    if (photoW < MAX_WIDTH && photoH < MAX_HEIGHT) {
        scaleFactor = 1;/*from   w  w w  . j a  va  2 s.c  o  m*/
    } else {
        scaleFactor = Math.max(photoW / MAX_WIDTH, photoH / MAX_HEIGHT);
    }
    Log.d(TAG, "scaleFactor:" + scaleFactor);
    /* Set bitmap options to scale the image decode target */
    bmOptions.inJustDecodeBounds = false;
    bmOptions.inSampleSize = scaleFactor;
    /* Decode the JPEG file into a Bitmap */
    return BitmapFactory.decodeFile(imagePath, bmOptions);

}

From source file:Main.java

public static String kidFromJwk(String jwkp) {
    String kid = "";
    try {//  w  w  w  .j  a  va  2s .  c o  m
        JSONObject jk = new JSONObject(jwkp).getJSONArray("keys").getJSONObject(0);
        kid = jk.getString("kid");
        Log.d("kidFromJwk", "kid " + kid);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return kid;
}

From source file:Main.java

public static void logd(String msg) {
    if (!debug) {
        return;//  w  w w .j a va2s.  c  om
    }
    Log.d("ldx", "" + msg);
}

From source file:Main.java

public static String getDateForHistory(String dateString) {
    String[] shortMonths = new DateFormatSymbols().getShortMonths();

    SimpleDateFormat parserSDF = new SimpleDateFormat("yyyy-MM-dd");
    SimpleDateFormat formater = new SimpleDateFormat("dd");
    String month = "";

    parserSDF.setTimeZone(TimeZone.getTimeZone("UTC"));
    formater.setTimeZone(TimeZone.getTimeZone("UTC"));
    Date date = null;/*from w w w  .  j av a 2s  . c o m*/
    try {
        parserSDF.setTimeZone(TimeZone.getTimeZone("UTC"));
        date = parserSDF.parse(dateString);
        month = shortMonths[date.getMonth()];
    } catch (ParseException e) {
        Log.d(TAG, e.getMessage());
    }

    return month + " " + formater.format(date);
}

From source file:Main.java

public static StringBuilder listFilesByName(File f, String lineSep) {
    Log.d("listFileByName f", "" + f);
    StringBuilder sb = new StringBuilder();
    if (f != null) {
        final Stack<File> stk = new Stack<>();
        if (f.isDirectory()) {
            stk.push(f);/*w  ww.j  a  v  a 2  s.  co  m*/
        } else {
            sb.append(f.getAbsolutePath()).append(": ").append(f.length()).append(" bytes.").append(lineSep);
        }
        File fi = null;
        File[] fs;
        while (stk.size() > 0) {
            fi = stk.pop();
            fs = fi.listFiles();
            for (File f2 : fs) {
                if (f2.isDirectory()) {
                    stk.push(f2);
                } else {
                    sb.append(f2.getAbsolutePath()).append(": ").append(f2.length()).append(" bytes.")
                            .append(lineSep);
                }
            }
        }

    }
    return sb;
}