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

/**
 * @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 w w w .  jav  a2 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

/**
 * Creates a thumbnail file starting from an image/video file
 *
 * @param original_file original file path
 * @param video         true if the file is a video. false if the file is a picture
 * @return a file//w  w w .  j  a va  2  s.c  o m
 */
private static File generateThumbnailFileForFile(File original_file, boolean video) {
    // Create an image file name
    try {
        String imageFileName = "thumb" + original_file.getName();
        Log.d(TAG, original_file.getName());
        File storageDir = Environment.getExternalStoragePublicDirectory(
                video ? Environment.DIRECTORY_MOVIES : Environment.DIRECTORY_PICTURES);
        return File.createTempFile(imageFileName, /* prefix */
                THUMB_FORMAT_EXTENSION, /* suffix */
                storageDir /* directory */
        );
    } catch (IOException e) {
        Log.d(TAG, "Error", e);
    }
    return null;

}

From source file:Main.java

public static String getDateDiff(Date date1, Date date2) {
    long diff = date2.getTime() - date1.getTime();
    long diffInSeconds = diff / 1000 % 60;
    long diffInMinutes = diff / (60 * 1000) % 60;
    long diffInHours = diff / (60 * 60 * 1000) % 24;
    long diffInDays = diff / (24 * 60 * 60 * 1000);
    StringBuilder returnString = new StringBuilder();
    if (diffInDays >= 1) {
        returnString.append(diffInDays + " days ");
    }/*from  ww w. java 2 s. c  o m*/
    if (diffInHours >= 1) {
        returnString.append(diffInHours + " hours ");
    }
    if (diffInMinutes >= 1) {
        returnString.append(diffInMinutes + " minutes ");
    }
    Log.d("praveen panduru", "timediff is " + returnString.toString());
    return returnString.toString();
}

From source file:Main.java

private static String[] convertCursorAsStringArrayWithCloseCursor(Cursor cursor, int colIdx) {
    String[] result = null;/*from  w ww. j  a v  a  2 s  . co m*/
    try {
        int resultCount = cursor.getCount();
        if (resultCount > 0) {
            HashSet<String> phones = new HashSet<String>(resultCount);
            while (cursor.moveToNext()) {
                String phone = cursor.getString(0);
                phones.add(phone);
            }
            result = phones.toArray(new String[phones.size()]);
        }
        Log.d(TAG,
                "ConvertCursor As StringArray : found " + resultCount + " String converted from idx " + colIdx);
    } finally {
        cursor.close();
    }
    return result;
}

From source file:Main.java

public static void printOutMyHashKey(Context context, String packageName) {
    try {//from   ww w.  j  a  va  2 s . co  m
        PackageInfo info = context.getPackageManager().getPackageInfo(packageName,
                PackageManager.GET_SIGNATURES);
        for (Signature signature : info.signatures) {
            MessageDigest md = MessageDigest.getInstance("SHA");
            md.update(signature.toByteArray());
            Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
        }
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static BigInteger getZ(ArrayList<byte[]> c1, ArrayList<byte[]> c2, BigInteger p) {
    BigInteger z = BigInteger.ZERO;

    //TODO: make sure c1 and c2 are of the same size
    int size = c1.size();
    if (size > c2.size()) {
        size = c2.size();/*from w w  w . jav  a  2 s.  c o m*/
    }

    for (int i = 0; i < size; i++) {
        BigInteger c1BI = new BigInteger(1, c1.get(i));
        BigInteger c2BI = new BigInteger(1, c2.get(i));
        BigInteger exp = new BigInteger(1, ByteBuffer.allocate(8).putLong((long) Math.pow(2, i)).array());

        z = z.add((c1BI.multiply(c2BI)).modPow(exp, p));
        Log.d("CeCk", "z calculation " + i + "/" + size + " round");
    }
    return z.mod(p);
}

From source file:Main.java

public static Bitmap loadBitmapFromView(View v, int width, int height) {
    v.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
            View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
    long time = System.currentTimeMillis();
    Bitmap b = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas c = new Canvas(b);

    v.measure(View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY),
            View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.EXACTLY));
    v.layout(0, 0, width, height);/* w  w  w  .  j  a  v  a2 s .  com*/
    v.draw(c);

    Log.d("artbook", "load bitmap time: " + (System.currentTimeMillis() - time));
    return b;
}

From source file:Main.java

public static File getOutputMediaFile(int type, Context c) {
    File mediaStorageDir = new File(c.getApplicationContext().getExternalFilesDir(null).getAbsolutePath());
    // Create the storage directory if it does not exist
    if (!mediaStorageDir.exists()) {
        if (!mediaStorageDir.mkdirs()) {
            Log.d("MyCameraApp", "failed to create directory");
            return null;
        }/*from  w  ww  . j  av  a 2 s.  c om*/
    }

    // Create a media file name
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
    File mediaFile;
    if (type == MEDIA_TYPE_IMAGE) {
        mediaFile = new File(mediaStorageDir.getPath() + File.separator + "IMG_" + timeStamp + ".jpg");
    } else if (type == MEDIA_TYPE_AUDIO) {
        mediaFile = new File(mediaStorageDir.getPath() + File.separator + "VID_" + timeStamp + ".3gp");
    } else {
        return null;
    }

    return mediaFile;
}

From source file:Main.java

public static String initializeService(String data, String serviceName, String serviceUrl) {
    Log.d("EliademyUtils", "initializeService");
    try {/* www  .ja  v  a 2s  .  com*/
        JSONObject jsObj = new JSONObject(data.toString());
        DefaultHttpClient httpclient = new DefaultHttpClient();

        HttpPost httppost = new HttpPost(serviceUrl + "/login/token.php");

        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
        nameValuePairs.add(new BasicNameValuePair("username", jsObj.get("username").toString()));
        nameValuePairs.add(new BasicNameValuePair("password", jsObj.get("password").toString()));
        nameValuePairs.add(new BasicNameValuePair("service", serviceName));
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

        HttpResponse response = httpclient.execute(httppost);

        HttpEntity entity = response.getEntity();
        if (entity != null) {
            StringBuilder jsonStr = new StringBuilder();
            InputStream iStream = entity.getContent();
            BufferedReader bufferReader = new BufferedReader(new InputStreamReader(iStream));
            String jpart;
            while ((jpart = bufferReader.readLine()) != null) {
                jsonStr.append(jpart);
            }
            iStream.close();
            Log.d("Moodle", jsonStr.toString());
            JSONObject jsonObj = new JSONObject(jsonStr.toString());
            return (String) jsonObj.get("token");
        }
    } catch (Exception e) {
        Log.e("EliademyUtils", "exception", e);
        return null;
    }
    return null;
}

From source file:Main.java

/**
 * Return date in specified format.//from   w  ww. ja  v  a  2  s .  co  m
 * @param milliSeconds Date in milliseconds
 * @param dateFormat Date format 
 * @return String representing date in specified format
 */
public static String getDate(long milliSeconds) {
    String dateFormat = "dd/MM/yyyy hh:mm:ss"; //.SSS";
    // Create a DateFormatter object for displaying date in specified format.
    SimpleDateFormat formatter = new SimpleDateFormat(dateFormat);

    // Create a calendar object that will convert the date and time value in milliseconds to date. 
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(milliSeconds);

    Log.d("EarthquakeMonitor",
            "Helpers.getDate result => " + milliSeconds + " to " + formatter.format(calendar.getTime()));

    return formatter.format(calendar.getTime());
}