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 toast(Context context, final String msg) {
    try {/*from   www  .  j  av a2 s  .  com*/
        Toast.makeText(context, msg, Toast.LENGTH_LONG).show();
        Log.d(TAG, "toast: " + msg);
    } catch (Exception e) {
        Log.d(TAG, "Couldn't display toast: " + msg + " / " + e.toString());
    }
}

From source file:Main.java

private static Field getPropertyField(Class<?> beanClazz, String propertyName) {
    Field property = null;/*from   w ww.jav a 2 s  .  c o  m*/

    try {
        property = beanClazz.getField(propertyName);
    } catch (NoSuchFieldException ex) {
        Log.d(TAG, "No such public property '" + propertyName);
    }

    return property;
}

From source file:Main.java

public static String getServerResponse(String urlRequest) {

    Log.d("urlRequest", urlRequest);
    String response = "";
    HttpURLConnection conn = null;
    try {//from  ww w.j a va  2  s  .  co  m
        conn = (HttpURLConnection) new URL(urlRequest).openConnection();
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    try {
        response = read(conn.getInputStream());
    } catch (IOException e) {
        e.printStackTrace();
    }

    Log.d("response", response);
    return response.trim();
}

From source file:Main.java

public static File savePictureInGallery(String albumName, String prefix, byte[] fileBytes) {
    Log.d(TAG, "[AirImagePickerUtils] Entering didSavePictureInGallery");

    long current = System.currentTimeMillis();

    // Save image to album
    File folder = getAlbumFolder(albumName);
    File picture = new File(folder, prefix + "_" + current);

    // Write Image to File
    try {//from  www .  j av  a2 s.c  om
        FileOutputStream stream = new FileOutputStream(picture);
        stream.write(fileBytes);
        stream.close();
    } catch (Exception exception) {
        Log.d(TAG, "[AirImagePickerUtils] exception = " + exception.getMessage());
        Log.d(TAG, "[AirImagePickerUtils] Exiting didSavePictureInGallery (failed)");
        return null;
    }

    Log.d(TAG, "[AirImagePickerUtils] Exiting didSavePictureInGallery (succeeded)");
    return picture;
}

From source file:Main.java

public static boolean isWAVFile(String fileName) {

    byte header[] = new byte[16];
    try {/*from   w  w w  .  ja v  a2  s  .  co m*/
        File f = new File(fileName);
        if (!f.exists()) {
            Log.d("OpusTool", fileName + ":" + "File does not exist.");
            return false;
        }
        long actualLength = f.length();
        FileInputStream io = new FileInputStream(f);
        io.read(header, 0, 16);
        io.close();

        String tag = new String(header, 0, 4) + new String(header, 8, 8);
        if (!tag.equals("RIFFWAVEfmt ")) {
            Log.d("OpusTool", fileName + ":" + "It's not a WAV file!");
            return false;
        }

        long paraLength = (header[4] & 0x000000ff) | ((header[5] << 8) & 0x0000ff00)
                | ((header[6] << 16) & 0x00ff0000) | ((header[7] << 24) & 0xff000000);
        if (paraLength != actualLength - 8) {
            Log.d("OpusTool", fileName + ":" + "It might be a WAV file, but it's corrupted!");
            return false;
        }
        return true;

    } catch (Exception e) {
        Log.d("OpusTool", fileName + ":" + "File Error");
        return false;
    }
}

From source file:Main.java

public static String getHostName(String ip) {
    String hostName = "Unknown";

    try {/*w  w w .  j av a 2 s  . c om*/
        InetAddress add = InetAddress.getByName(ip);
        hostName = add.getHostName();

        Log.d(Tag, "host name is " + hostName);
    } catch (UnknownHostException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return hostName;
}

From source file:Main.java

public static void DownloadFromUrl(String thisUrl, String path, String filename) {
    Log.d("DownloadFromUrl", "url: " + thisUrl);
    Log.d("DownloadFromUrl", "path: " + path);
    Log.d("DownloadFromUrl", "filename: " + filename);
    try {/* w  ww  .j  av a2 s  . co m*/
        URL url = new URL(thisUrl);
        new File(path).mkdirs();
        File file = new File(path, filename);

        /* Open a connection to that URL. */
        URLConnection ucon = url.openConnection();

        Log.d("DownloadFromUrl", "about to write file");
        /*
         * Define InputStreams to read from the URLConnection.
         */
        InputStream is = ucon.getInputStream();
        try {
            OutputStream os = new FileOutputStream(file);
            try {
                byte[] buffer = new byte[4096];
                for (int n; (n = is.read(buffer)) != -1;)
                    os.write(buffer, 0, n);
            } finally {
                os.close();
            }
        } finally {
            is.close();
        }
        Log.d("DownloadFromUrl", "finished");

    } catch (IOException e) {
        Log.d("DownloadFromUrl", "Error: " + e);
    }
}

From source file:Main.java

public static void downloadImage(String imageUrl) {
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        Log.d("TAG", "monted sdcard");
    } else {/* w w w  .j  a  v a2s. c o m*/
        Log.d("TAG", "has no sdcard");
    }
    HttpURLConnection con = null;
    FileOutputStream fos = null;
    BufferedOutputStream bos = null;
    BufferedInputStream bis = null;
    File imageFile = null;
    try {
        URL url = new URL(imageUrl);
        con = (HttpURLConnection) url.openConnection();
        con.setConnectTimeout(5 * 1000);
        con.setReadTimeout(15 * 1000);
        con.setDoInput(true);
        con.setDoOutput(true);
        bis = new BufferedInputStream(con.getInputStream());
        imageFile = new File(getImagePath(imageUrl));
        fos = new FileOutputStream(imageFile);
        bos = new BufferedOutputStream(fos);
        byte[] b = new byte[1024];
        int length;
        while ((length = bis.read(b)) != -1) {
            bos.write(b, 0, length);
            bos.flush();
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            if (bis != null) {
                bis.close();
            }
            if (bos != null) {
                bos.close();
            }
            if (con != null) {
                con.disconnect();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    if (imageFile != null) {
    }
}

From source file:Main.java

public static File loadFromFile(String filename) {
    try {//w w w.  j  a va  2 s  .  c om
        File f = new File(filename);
        if (!f.exists()) {
            return null;
        }
        //           Bitmap tmp = BitmapFactory.decodeFile(filename);
        return f;
    } catch (Exception e) {
        Log.d("Exception", e.getMessage());
        return null;
    }
}

From source file:Main.java

static public Bitmap getOrientedBitmapFromBitmapAndPath(Bitmap bitmap, String filePath) {
    Log.d(TAG, "[AirImagePickerUtils] Entering getOrientedBitmapFromBitmapAndPath");
    try {// w w w.j a  v a  2  s  . com
        // Get orientation from EXIF
        ExifInterface exif = new ExifInterface(filePath);
        int exifOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION,
                ExifInterface.ORIENTATION_NORMAL);

        // Compute rotation matrix
        Matrix rotation = new Matrix();
        switch (exifOrientation) {
        case ExifInterface.ORIENTATION_ROTATE_90:
            rotation.preRotate(90);
            break;

        case ExifInterface.ORIENTATION_ROTATE_180:
            rotation.preRotate(180);
            break;

        case ExifInterface.ORIENTATION_ROTATE_270:
            rotation.preRotate(270);
            break;
        }

        // Return new bitmap
        Log.d(TAG, "[AirImagePickerUtils] Exiting getOrientedBitmapFromBitmapAndPath");
        return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), rotation, true);
    } catch (Exception exception) {
        Log.d(TAG, "Couldn't fix bitmap orientation: " + exception.getMessage());
        Log.d(TAG, "[AirImagePickerUtils] Exiting getOrientedBitmapFromBitmapAndPath");
        return bitmap;
    }
}