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

private static void log(String tag, int level, String msg, Throwable tr) {
    if (isLog) {/*from  www  . ja  v  a 2  s. c  o 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:com.goodway.nominatimparser.Request.java

public static void getPlaces(Action a, ArrayList<Pair>... parameters) {
    try {//www. j  ava2  s .c  o m
        new GetPlaces(a, parameters).execute();
        Log.d("getPlaces", "getPlaces");
    } catch (IllegalStateException e) {
        Log.e(e.getMessage(), "exception");
    }

}

From source file:Main.java

private static File getOutputMediaFile(int type) {

    File mediaStorageDir = new File(
            Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "");

    if (!mediaStorageDir.exists()) {
        if (!mediaStorageDir.mkdirs()) {
            Log.d("failed", "Oops! Failed create " + "Alumni Space Picture" + " directory");
            return null;
        }/*from  w w  w .  j  ava  2 s .c  o m*/
    }

    // Create a media file name
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(new Date());
    File mediaFile;
    if (type == 10) {
        mediaFile = new File(mediaStorageDir.getPath() + File.separator + "IMG_" + timeStamp + ".jpg");
    } else {
        return null;
    }

    return mediaFile;

}

From source file:Main.java

public static void copyFileToDir(File sourceFile, File destFile) {
    InputStream inStream = null;/*from   ww w  . j  a v a  2  s .c  om*/
    OutputStream outStream = null;

    try {

        inStream = new FileInputStream(sourceFile);
        outStream = new FileOutputStream(destFile);

        byte[] buffer = new byte[1024];

        int length;

        // copy the file content in bytes
        while ((length = inStream.read(buffer)) > 0) {

            outStream.write(buffer, 0, length);

        }

        Log.d(TAG, "File copied: " + destFile);

    } catch (IOException e) {
        Log.w(TAG, e.toString());
    } finally {
        if (inStream != null) {
            try {
                inStream.close();
            } catch (IOException e) {
                Log.d(TAG, e.toString());
            }
        }

        if (outStream != null) {
            try {
                outStream.close();
            } catch (IOException e) {
                Log.d(TAG, e.toString());
            }
        }
    }
}

From source file:Main.java

public static void log(String msg) {
    if (!TextUtils.isEmpty(msg)) {
        Log.d(TAG, msg);
    }
}

From source file:Main.java

public static String removeStringSuffix(String s, String suffix) {
    String retval = s;//from   w ww  .  j  a v a  2 s.  c o  m
    if ((null != s) && (null != suffix)) {
        int sLen = s.length();
        int suffixLen = suffix.length();

        if (suffixLen <= sLen) {
            try {
                String t = s.substring(sLen - suffixLen, sLen);
                if (suffixLen == sLen) {
                    retval = "";
                } else if (suffix.equals(t)) {
                    retval = s.substring(0, sLen - suffixLen - 1);
                }
            } catch (Exception e) {
                //^^FE1=removeSuffix()
                Log.e(TAG, "^^FE1", e);
            }
        }
    }
    Log.d(TAG, "AqUtils.removeStringSuffix().  s,suffix,retval: " + s + "," + suffix + "," + retval);
    return retval;
}

From source file:Main.java

/**
 * Read the featureVector_Shape.dat file.
 * Build the double array and return it.
 * k : number of rows/* w w  w  . ja  va 2 s .  co  m*/
 * n : number of columns
 */
public static float[][] readBinFloatDoubleArray(String dir, String fileName, int k, int n) {
    float[][] array2D = new float[k][n];
    float x;
    File sdLien = Environment.getExternalStorageDirectory();
    File inFile = new File(sdLien + File.separator + dir + File.separator + fileName);
    Log.d(TAG, "path of file : " + inFile);
    if (!inFile.exists()) {
        throw new RuntimeException("File doesn't exist");
    }
    DataInputStream in = null;
    try {
        in = new DataInputStream(new FileInputStream(inFile));
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    try {
        for (int i = 0; i < k; i++) {
            for (int j = 0; j < n; j++) {
                x = in.readFloat();
                array2D[i][j] = x;
            }
        }
    } catch (EOFException e) {
        try {
            Log.d(TAG, "close");
            in.close();
        } catch (IOException e1) {
            e1.printStackTrace();
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (in != null) {
            try { //free ressources
                Log.d(TAG, "close");
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    return array2D;
}

From source file:Main.java

public static File getOutputMediaFile() {

    // External sdcard location

    File mediaStorageDir = new File(
            Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
            IMAGE_DIRECTORY_NAME);/*from  www  . j ava  2s  .  c o  m*/
    // Create the storage directory if it does not exist
    if (!mediaStorageDir.exists()) {
        if (!mediaStorageDir.mkdirs()) {
            Log.d(IMAGE_DIRECTORY_NAME, "Oops! Failed create " + IMAGE_DIRECTORY_NAME + " directory");
            return null;
        }
    }

    // Create a media file name
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(new Date());
    File mediaFile;

    mediaFile = new File(mediaStorageDir.getPath() + File.separator + "IMG_" + timeStamp + ".jpg");

    return mediaFile;
}

From source file:Main.java

private static ArrayList<String> getNumbers(Context context) {
    ArrayList<String> list = new ArrayList<String>();
    Cursor cursor = null;//  ww w  .  j a  va2s. c  om
    try {
        cursor = context.getContentResolver().query(Phone.CONTENT_URI, null, null, null, null);
        int phoneNumberIdx = cursor.getColumnIndex(Phone.NUMBER);
        cursor.moveToFirst();
        do {
            String phoneNumber = cursor.getString(phoneNumberIdx);
            list.add(phoneNumber);
        } while (cursor.moveToNext());
    } catch (Exception e) {
        Log.d(context.getPackageName(), e.toString());
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }

    return list;
}

From source file:Main.java

public static Object readObject(File file) {
    Object obj = null;// w  w w.j  a v  a 2  s. c o m
    if (file != null && file.exists()) {
        FileInputStream fileInputStream = null;
        ObjectInputStream objectInputStream = null;

        try {
            fileInputStream = new FileInputStream(file);
            objectInputStream = new ObjectInputStream(fileInputStream);

            obj = objectInputStream.readObject();
        } catch (IOException | ClassNotFoundException e) {
            Log.d("readObject", e.getMessage());
        } finally {
            try {
                if (objectInputStream != null) {
                    objectInputStream.close();
                }
                if (fileInputStream != null) {
                    fileInputStream.close();
                }
            } catch (IOException e) {
                Log.d("readObject", e.getMessage());
            }

        }
    }
    return obj;
}