List of usage examples for android.util Log w
public static int w(String tag, Throwable tr)
From source file:Main.java
public static Uri getAdnUriForPhoneAccount(Context context, PhoneAccountHandle handle) { if (hasModifyPhoneStatePermission(context)) { try {// www .j a v a 2 s. c om return getTelecomManager(context).getAdnUriForPhoneAccount(handle); } catch (SecurityException e) { Log.w(TAG, "TelecomManager.getAdnUriForPhoneAccount called without permission."); } } return null; }
From source file:Main.java
/** * @param intendedColour the intended colour (as String) * @param alternativeColour an alternative colour (as int) to use if parsing of the intended one failed * @return/*from w ww . java2 s . co m*/ */ static public int ParseColour(String intendedColour, int alternativeColour) { int colour = alternativeColour; try { colour = Color.parseColor(intendedColour); } catch (NullPointerException npe) { Log.w(TAG, "Unable to parse null colour."); } catch (IllegalArgumentException iae) { Log.w(TAG, "Unable to parse colour: " + intendedColour); } return colour; }
From source file:Main.java
private static void print(int mode, final String tag, String msg) { if (!isPrint) { return;// w w w.jav a 2 s . c o m } if (msg == null) { Log.e(tag, MSG); return; } switch (mode) { case Log.VERBOSE: Log.v(tag, msg); break; case Log.DEBUG: Log.d(tag, msg); break; case Log.INFO: Log.i(tag, msg); break; case Log.WARN: Log.w(tag, msg); break; case Log.ERROR: Log.e(tag, msg); break; default: Log.d(tag, msg); break; } }
From source file:Main.java
/** * Checks whether the filename looks legitimate *//*from w w w. j a va2 s. c om*/ static boolean isFilenameValid(String filename, File downloadsDataDir) { final String[] whitelist; try { filename = new File(filename).getCanonicalPath(); whitelist = new String[] { downloadsDataDir.getCanonicalPath(), Environment.getDownloadCacheDirectory().getCanonicalPath(), Environment.getExternalStorageDirectory().getCanonicalPath(), }; } catch (IOException e) { Log.w(TAG, "Failed to resolve canonical path: " + e); return false; } for (String test : whitelist) { if (filename.startsWith(test)) { return true; } } return false; }
From source file:com.granita.icloudcalsync.DateUtils.java
public static String findAndroidTimezoneID(String tzID) { String localTZ = null;/*from w w w .j a va2 s . c o m*/ String availableTZs[] = SimpleTimeZone.getAvailableIDs(); // first, try to find an exact match (case insensitive) for (String availableTZ : availableTZs) if (availableTZ.equalsIgnoreCase(tzID)) { localTZ = availableTZ; break; } // if that doesn't work, try to find something else that matches if (localTZ == null) { Log.w(TAG, "Coulnd't find time zone with matching identifiers, trying to guess"); for (String availableTZ : availableTZs) if (StringUtils.indexOfIgnoreCase(tzID, availableTZ) != -1) { localTZ = availableTZ; break; } } // if that doesn't work, use UTC as fallback if (localTZ == null) { Log.e(TAG, "Couldn't identify time zone, using UTC as fallback"); localTZ = Time.TIMEZONE_UTC; } Log.d(TAG, "Assuming time zone " + localTZ + " for " + tzID); return localTZ; }
From source file:Main.java
private static int compileShader(int type, String shaderCode) { //create shader final int shaderObjectId = glCreateShader(type); if (shaderObjectId != 0) { //fill shader with the src code glShaderSource(shaderObjectId, shaderCode); //compile glCompileShader(shaderObjectId); //check for success final int[] status = new int[1]; glGetShaderiv(shaderObjectId, GL_COMPILE_STATUS, status, 0); if (status[0] != 0) { //compilation succesfull return shaderObjectId; } else {// w ww .j a va 2 s .c o m //compilation failed glDeleteShader(shaderObjectId); Log.w(TAG, "compilation failed" + type); return 0; } } else { //creation failed Log.w(TAG, "Couldn't create shader."); return 0; } }
From source file:Main.java
public static boolean writeToFileAppend(@NonNull File file, @NonNull CharSequence text) { try {//from w w w . ja va2 s . com //noinspection ResultOfMethodCallIgnored file.createNewFile(); } catch (IOException e) { Log.w(TAG, "Failed to create the file: file=" + file.getName()); return false; } OutputStream os = null; InputStream is = null; try { os = new FileOutputStream(file, true); is = new ByteArrayInputStream(text.toString().getBytes("UTF-8")); int read; final byte[] buffer = new byte[1024]; do { read = is.read(buffer, 0, buffer.length); if (read > 0) os.write(buffer, 0, read); } while (read > 0); return true; } catch (Exception e) { Log.w(TAG, "Failed to append to a file: file=" + file.getName()); e.printStackTrace(); } finally { // Try to close the stream. if (os != null) try { os.close(); } catch (IOException e) { Log.e(TAG, "Failed to close the stream!"); e.printStackTrace(); } // Try to close the stream. if (is != null) try { is.close(); } catch (IOException e) { Log.e(TAG, "Failed to close the stream!"); e.printStackTrace(); } } return false; }
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(); return new Point(defaultSize.width, defaultSize.height); }/*from ww w .jav a 2s .c o m*/ // 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(); 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 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 ww .j a v a 2 s. c o m*/ return new Point(defaultSize.width, defaultSize.height); } // Sort by size, descending List<Camera.Size> supportedPreviewSizes = new ArrayList<>(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 = 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 = 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 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 www.j ava 2 s. c o m*/ return new Point(defaultSize.width, defaultSize.height); } // Sort by size, descending List<Camera.Size> supportedPreviewSizes = new ArrayList<>(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; }