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 String getLocalIpAddress(Context context) {
    try {/*from w ww.  jav  a 2 s .c  om*/
        String ipv4;

        List<NetworkInterface> nilist = Collections.list(NetworkInterface.getNetworkInterfaces());
        for (NetworkInterface ni : nilist) {
            if (ni.getName().toLowerCase().contains("usbnet"))
                continue;
            List<InetAddress> ialist = Collections.list(ni.getInetAddresses());
            for (InetAddress address : ialist) {
                if (!address.isLoopbackAddress()
                        && InetAddressUtils.isIPv4Address(ipv4 = address.getHostAddress())) {
                    return ipv4;
                }
            }

        }

    } catch (SocketException ex) {
        Log.d("socket_err", ex.toString());
    }
    return null;
}

From source file:Main.java

/**
 * //from  w  w  w  .  j a v a 2 s  .c  o  m
 * @return Bitmap's RGBA byte array
 */
public static byte[] getImageRGBA(Bitmap inputBitmap) {
    Config config = inputBitmap.getConfig();
    ByteBuffer buffer;

    Bitmap bitmap;
    /**
     * if bitmap size is not 32*32 create scaled bitmap
     */

    if (inputBitmap.getWidth() != 32 || inputBitmap.getHeight() != 32) {
        Log.d(TAG, "bitmap resized to 32x32");
        bitmap = Bitmap.createScaledBitmap(inputBitmap, 32, 32, false);
    } else {
        bitmap = inputBitmap;
    }
    /**
     * if bitmap is not ARGB_8888 format, copy bitmap with ARGB_8888 format
     */
    if (!config.equals(Bitmap.Config.ARGB_8888)) {
        Bitmap bitmapARBG = bitmap.copy(Bitmap.Config.ARGB_8888, false);
        buffer = ByteBuffer.allocate(bitmapARBG.getByteCount());
        bitmapARBG.copyPixelsToBuffer(buffer);
        bitmapARBG.recycle();
    } else {
        buffer = ByteBuffer.allocate(bitmap.getByteCount());
        bitmap.copyPixelsToBuffer(buffer);
    }
    return buffer.array();
}

From source file:Main.java

public static boolean saveFile(String filePath, InputStream inputStream) throws IOException {
    boolean result = false;
    if (filePath != null && inputStream != null) {
        Log.d(TAG, "filePath:" + filePath);
        File file = new File(filePath);
        if (file.exists()) {
            file.delete();/*  w  w  w.  ja  va 2 s .c  om*/
        }
        if (file.createNewFile()) {
            FileOutputStream fos = new FileOutputStream(file.getAbsolutePath());
            byte[] buf = new byte[1024];
            int size = 0;
            while ((size = inputStream.read(buf, 0, 1024)) != -1) {
                fos.write(buf, 0, size);
            }

            fos.flush();
            fos.close();
            inputStream.close();
            result = true;
        }
    }
    return result;
}

From source file:Main.java

public static void insertUrl(Context context, Uri contentUri, URL sourceUrl) {
    if (DEBUG) {/*from  w  w w. jav a  2  s .  co  m*/
        Log.d(TAG, "Inserting " + sourceUrl + " to " + contentUri);
    }
    InputStream is = null;
    OutputStream os = null;
    try {
        is = sourceUrl.openStream();
        os = context.getContentResolver().openOutputStream(contentUri);
        copy(is, os);
    } catch (IOException ioe) {
        Log.e(TAG, "Failed to write " + sourceUrl + "  to " + contentUri, ioe);
    } finally {
        if (is != null) {
            try {
                is.close();
            } catch (IOException e) {
                // Ignore exception.
            }
        }
        if (os != null) {
            try {
                os.close();
            } catch (IOException e) {
                // Ignore exception.
            }
        }
    }
}

From source file:Main.java

/**
 * Create a new dummy account for the sync adapter
 *
 * @param context The application context
 *///from  w  w w. jav  a 2s  .c  o m
public static Account CreateSyncAccount(Context context) {

    // Create the account type and default account
    Account newAccount = new Account(ACCOUNT_NAME, ACCOUNT_TYPE);
    // Get an instance of the Android account manager
    AccountManager accountManager = (AccountManager) context.getSystemService(context.ACCOUNT_SERVICE);

    /*
     * Add the account and account type, no password or user data
     * If successful, return the Account object, otherwise report an error.
     */
    if (accountManager.addAccountExplicitly(newAccount, null, null)) {
        Log.d(TAG, "Account created: " + newAccount.name);

        return newAccount;
    } else {
        /*
         * The account exists or some other error occurred.
         * Try and get account first. Then log or report the error and return null.
         */
        Account[] accounts = accountManager.getAccounts();
        for (Account account : accounts) {
            if (account.name.equals(ACCOUNT_NAME)) {
                Log.d(TAG, "Account exists: " + account.name);
                return account;
            }
        }
        Log.d(TAG, "Error occured. The account is null");
        return null;
    }

}

From source file:Main.java

private static Method getBooleanColumnGetMethod(Class<?> entityType, final String fieldName) {
    String methodName = "is" + fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1);
    if (isStartWithIs(fieldName)) {
        methodName = fieldName;/*from  w  ww.  j a v a2s.co  m*/
    }
    try {
        return entityType.getDeclaredMethod(methodName);
    } catch (NoSuchMethodException e) {
        Log.d("getBooleanColumnGetMethod", methodName + " not exist");
    }
    return null;
}

From source file:Main.java

public static float[] maxMinXYZ(float[] array) {
    float maxX = 0.0f, minX = 0.0f, maxY = 0.0f, minY = 0.0f, maxZ = 0.0f, minZ = 0.0f;
    float[] res = new float[6];

    for (int i = 0; i < array.length; i = i + 3) {

        // Max/*w  w w. j ava  2s.  c o m*/
        if (array[i] > maxX) {
            maxX = array[i];
        }
        if (array[i + 1] > maxY) {
            maxY = array[i + 1];
        }
        if (array[i + 2] > maxZ) {
            maxZ = array[i + 2];
        }

        // Min
        if (array[i] < minX) {
            minX = array[i];
        }
        if (array[i + 1] < minY) {
            minY = array[i + 1];
        }
        if (array[i + 2] < minZ) {
            minZ = array[i + 2];
        }
    }
    res[0] = maxX;
    res[1] = minX;

    res[2] = maxY;
    res[3] = minY;

    res[4] = maxZ;
    res[5] = minZ;

    Log.d(TAG, "maxX = " + res[0]);
    Log.d(TAG, "minX = " + res[1]);

    Log.d(TAG, "maxY = " + res[2]);
    Log.d(TAG, "minY = " + res[3]);

    Log.d(TAG, "maxZ = " + res[4]);
    Log.d(TAG, "minZ = " + res[5]);
    return res;
}

From source file:Main.java

public static void setCookie(Context context, String url) {
    FileInputStream in = null;/*from  w  ww . j  a  v a  2s .co m*/
    try {
        in = context.openFileInput(TAXICOOKIE_FILE);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    if (in == null) {
        Log.w(TAG, "saveCookie: Cannot open file: " + TAXICOOKIE_FILE);
    }

    BufferedReader reader = new BufferedReader(new InputStreamReader(in));
    String cookieStr = null;
    try {
        cookieStr = reader.readLine();
        reader.close();
    } catch (IOException e) {
        e.printStackTrace();
    }

    Log.d(TAG, "cookieStr: " + cookieStr);
    if (cookieStr == null) {
        return;
    }

    CookieSyncManager.createInstance(context);
    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.removeSessionCookie();
    cookieManager.setCookie(url, cookieStr);
    CookieSyncManager.getInstance().sync();
}

From source file:Main.java

/** Create a File for saving an image or video */
private static File getOutputMediaFile() {
    // To be safe, you should check that the SDCard is mounted
    // using Environment.getExternalStorageState() before doing this.

    File mediaStorageDir = new File(
            Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "FoodBook");
    // This location works best if you want the created images to be shared
    // between applications and persist after your app has been uninstalled.

    // Create the storage directory if it does not exist
    if (!mediaStorageDir.exists()) {
        if (!mediaStorageDir.mkdirs()) {
            Log.d("FoodBook", "failed to create directory");
            return null;
        }/* w  w w  .j  av  a 2 s .  co m*/
    }

    // Create a media file name
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
    File mediaFile = new File(mediaStorageDir.getPath() + File.separator + "IMG_" + timeStamp + ".jpg");

    return mediaFile;
}

From source file:Main.java

private static void setStartOfWeekToCalendar(Calendar c) {
    c.set(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek());
    setStartOfDayToCalendar(c);/*from  w ww  . ja  v  a2s  . c  o m*/
    Log.d("La Cuenta: ", "Min of Current Week: " + DateFormat.getInstance().format(c.getTime()));
}