Example usage for android.util Log w

List of usage examples for android.util Log w

Introduction

In this page you can find the example usage for android.util Log w.

Prototype

public static int w(String tag, Throwable tr) 

Source Link

Usage

From source file:Main.java

private static void logErrorStream(@Nullable InputStream errorStream) throws IOException {
    if (errorStream == null) {
        return;/*from w  w  w.j  a  v  a2  s .c om*/
    }

    StringBuilder builder = new StringBuilder();
    BufferedReader reader = new BufferedReader(new InputStreamReader(errorStream, "UTF-8"));
    try {
        String result;
        while ((result = reader.readLine()) != null) {
            builder.append(result);
        }
    } finally {
        reader.close();
    }

    Log.w(TAG, builder.toString());
}

From source file:com.yandex.sample.metrica.Stuff.java

public static void loadNativePart() {
    try {/* w  ww .  ja  v  a 2 s.  co m*/
        System.loadLibrary(Stuff.NATIVE_LIBRARY_MODULE);
    } catch (Throwable error) {
        Log.w(Stuff.LOG_TAG, Stuff.NATIVE_LIBRARY_PROBLEMS_HINT);
    }
}

From source file:Main.java

public static String byteArray2HexString(byte abyte0[], int i) {
    int j = i;/*from www  . j  a v  a2  s .com*/
    StringBuilder stringbuilder = new StringBuilder(i);
    if (abyte0.length < i) {
        Log.w("Util", "data length is shorter then print command length");
        j = abyte0.length;
    }
    int k = 0;
    do {
        if (k >= j)
            return stringbuilder.toString();
        Object aobj[] = new Object[1];
        aobj[0] = Byte.valueOf(abyte0[k]);
        stringbuilder.append(String.format("%02X ", aobj));
        k++;
    } while (true);
}

From source file:Main.java

public static void waitWithoutInterrupt(Object object) {
    try {/*w ww  .j a v a2  s .  c  o m*/
        object.wait();
    } catch (InterruptedException e) {
        Log.w(TAG, "unexpected interrupt: " + object);
    }
}

From source file:Main.java

public static Point findBestPreviewSizeValue(Camera.Parameters parameters, Point screenResolution) {

    List<Camera.Size> rawSupportedSizes = parameters.getSupportedPreviewSizes();
    if (rawSupportedSizes == null) {
        Log.w(TAG, "Device returned no supported preview sizes; using default");
        Camera.Size defaultSize = parameters.getPreviewSize();
        if (defaultSize == null) {
            throw new IllegalStateException("Parameters contained no preview size!");
        }//from w  w  w  .  j ava2 s.c  o m
        return new Point(defaultSize.width, defaultSize.height);
    }

    // Sort by size, descending
    List<Camera.Size> supportedPreviewSizes = new ArrayList<Camera.Size>(rawSupportedSizes);
    Collections.sort(supportedPreviewSizes, new Comparator<Camera.Size>() {
        @Override
        public int compare(Camera.Size a, Camera.Size b) {
            int aPixels = a.height * a.width;
            int bPixels = b.height * b.width;
            if (bPixels < aPixels) {
                return -1;
            }
            if (bPixels > aPixels) {
                return 1;
            }
            return 0;
        }
    });

    if (Log.isLoggable(TAG, Log.INFO)) {
        StringBuilder previewSizesString = new StringBuilder();
        for (Camera.Size supportedPreviewSize : supportedPreviewSizes) {
            previewSizesString.append(supportedPreviewSize.width).append('x')
                    .append(supportedPreviewSize.height).append(' ');
        }
        Log.i(TAG, "Supported preview sizes: " + previewSizesString);
    }

    double screenAspectRatio = (double) screenResolution.x / (double) screenResolution.y;

    // Remove sizes that are unsuitable
    Iterator<Camera.Size> it = supportedPreviewSizes.iterator();
    while (it.hasNext()) {
        Camera.Size supportedPreviewSize = it.next();
        int realWidth = supportedPreviewSize.width;
        int realHeight = supportedPreviewSize.height;
        if (realWidth * realHeight < MIN_PREVIEW_PIXELS) {
            it.remove();
            continue;
        }

        boolean isCandidatePortrait = realWidth < realHeight;
        int maybeFlippedWidth = isCandidatePortrait ? realHeight : realWidth;
        int maybeFlippedHeight = isCandidatePortrait ? realWidth : realHeight;
        double aspectRatio = (double) maybeFlippedWidth / (double) maybeFlippedHeight;
        double distortion = Math.abs(aspectRatio - screenAspectRatio);
        if (distortion > MAX_ASPECT_DISTORTION) {
            it.remove();
            continue;
        }

        if (maybeFlippedWidth == screenResolution.x && maybeFlippedHeight == screenResolution.y) {
            Point exactPoint = new Point(realWidth, realHeight);
            Log.i(TAG, "Found preview size exactly matching screen size: " + exactPoint);
            return exactPoint;
        }
    }

    // If no exact match, use largest preview size. This was not a great
    // idea on older devices because
    // of the additional computation needed. We're likely to get here on
    // newer Android 4+ devices, where
    // the CPU is much more powerful.
    if (!supportedPreviewSizes.isEmpty()) {
        Camera.Size largestPreview = supportedPreviewSizes.get(0);
        Point largestSize = new Point(largestPreview.width, largestPreview.height);
        Log.i(TAG, "Using largest suitable preview size: " + largestSize);
        return largestSize;
    }

    // If there is nothing at all suitable, return current preview size
    Camera.Size defaultPreview = parameters.getPreviewSize();
    if (defaultPreview == null) {
        throw new IllegalStateException("Parameters contained no preview size!");
    }
    Point defaultSize = new Point(defaultPreview.width, defaultPreview.height);
    Log.i(TAG, "No suitable preview sizes, using default: " + defaultSize);
    return defaultSize;
}

From source file:Main.java

public static void deleteAndReport(File file) {
    if (file != null && file.exists()) {
        // remove garbage
        if (!file.delete()) {
            Log.w(t, file.getAbsolutePath() + " will be deleted upon exit.");
            file.deleteOnExit();//ww w  .j ava2s  .c  om
        } else {
            Log.w(t, file.getAbsolutePath() + " has been deleted.");
        }
    }
}

From source file:Main.java

public static String getCRC32(File file) {
    CRC32 crc32 = new CRC32();
    CheckedInputStream checkedinputstream = null;
    String crc = null;/*  w  ww . j  av a 2s. c o m*/
    try {
        checkedinputstream = new CheckedInputStream(new FileInputStream(file), crc32);
        byte[] buf = new byte[1024];
        while (checkedinputstream.read(buf) >= 0) {
        }
        crc = Long.toHexString(crc32.getValue()).toUpperCase();
    } catch (Exception e) {
        Log.w(TAG, e);
        Log.e("WxException", e.getMessage(), e);
    } finally {
        if (checkedinputstream != null) {
            try {
                checkedinputstream.close();
            } catch (IOException e) {
            }
        }
    }
    return crc;
}

From source file:Main.java

public static String getCurProcessName(Context context) {
    String strRet = null;//www .  ja va 2s. co m
    try {
        Class<?> clazz = Class.forName("android.ddm.DdmHandleAppName");
        Method method = clazz.getDeclaredMethod("getAppName");
        strRet = (String) method.invoke(clazz);
    } catch (Exception e) {
        Log.w(TAG, e);
    }
    if (TextUtils.isEmpty(strRet)) {
        final int pid = android.os.Process.myPid();
        android.app.ActivityManager activityManager = (android.app.ActivityManager) context
                .getSystemService(Context.ACTIVITY_SERVICE);
        final List<ActivityManager.RunningAppProcessInfo> runningAppProcesses = activityManager
                .getRunningAppProcesses();
        for (ActivityManager.RunningAppProcessInfo appProcess : runningAppProcesses) {
            if (appProcess.pid == pid) {
                strRet = appProcess.processName;
                break;
            }
        }
    }
    return strRet;
}

From source file:Main.java

/**
 * Get a list of external SD card paths. (Kitkat or higher.)
 *
 * @return A list of external SD card paths.
 *///from  w  w  w .  j ava 2  s . c o m
@TargetApi(Build.VERSION_CODES.KITKAT)
private static String[] getExtSdCardPaths() {
    List<String> paths = new ArrayList<>();
    for (File file : applicationContext.getExternalFilesDirs("external")) {
        if (file != null && !file.equals(applicationContext.getExternalFilesDir("external"))) {
            int index = file.getAbsolutePath().lastIndexOf("/Android/data");
            if (index < 0) {
                Log.w("Uri", "Unexpected external file dir: " + file.getAbsolutePath());
            } else {
                String path = file.getAbsolutePath().substring(0, index);
                try {
                    path = new File(path).getCanonicalPath();
                } catch (IOException e) {
                    // Keep non-canonical path.
                }
                paths.add(path);
            }
        }
    }
    return paths.toArray(new String[paths.size()]);
}

From source file:Main.java

public static String getNativeLibraryDirectory(Context appContext) {
    ApplicationInfo ai = context.getApplicationInfo();

    Log.w("NDKHelper", "ai.nativeLibraryDir:" + ai.nativeLibraryDir);

    if ((ai.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0
            || (ai.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
        return ai.nativeLibraryDir;
    }//  w w  w .  j  a  v a 2s .co  m
    return "/system/lib/";
}