List of usage examples for android.util Log w
public static int w(String tag, Throwable tr)
From source file:Main.java
public static String getSha1(FileDescriptor fd) { MessageDigest md;/*from w ww . ja va2s.c om*/ try { md = MessageDigest.getInstance("SHA-1"); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } byte[] b = new byte[4096]; FileInputStream fis = new FileInputStream(fd); InputStream is = new BufferedInputStream(fis, 4096); try { for (int n; (n = is.read(b)) != -1;) { md.update(b, 0, n); } } catch (IOException e) { Log.w(TAG, "IOException while computing SHA-1"); return null; } byte[] sha1hash = new byte[40]; sha1hash = md.digest(); return getHex(sha1hash); }
From source file:Main.java
/** * Check whether a ratio is valid./*from ww w .ja va2s .co m*/ * @param ratio The string containing the proposed ratio. * @param split The amount of shares the ratio should be split in. * Pass less than 2 to avoid checking shares. * @return Whether ratio is valid for required shares. */ public static boolean validRatio(String ratio, int split) { boolean result = false; if (ratio.matches("^[0-9][0-9]*:[[0-9]:]*[0-9]*[0-9]$")) { Log.v(TAG, "Checking ratio " + ratio + " results follow..."); Log.i(TAG, "RATIO PATTERN MATCHED"); if (split > 1) { String[] ratios = ratio.split(":"); if (ratios.length == split) { Log.i(TAG, "RATIO IS VALID, hoorah!"); result = true; } else { Log.w(TAG, "INVALID AMOUNT OF SHARES, RATIO INVALID"); } } else { result = true; } } else { Log.w(TAG, "INVALID RATIO"); } return result; }
From source file:Main.java
/** * Gets the original mime type of DRM protected content. * * @param context The context/*from ww w . j a va 2 s . com*/ * @param path Path to the file * @param containingMime The current mime type of of the file i.e. the * containing mime type * @return The original mime type of the file if DRM protected else the * currentMime */ public static String getOriginalMimeType(Context context, String path, String containingMime) { String result = containingMime; DrmManagerClient drmClient = new DrmManagerClient(context); try { if (drmClient.canHandle(path, null)) { result = drmClient.getOriginalMimeType(path); } } catch (IllegalArgumentException ex) { Log.w(TAG, "Can't get original mime type since path is null or empty string."); } catch (IllegalStateException ex) { Log.w(TAG, "DrmManagerClient didn't initialize properly."); } return result; }
From source file:Main.java
public static boolean isDefaultDialer(Context context) { final boolean result = TextUtils.equals(context.getPackageName(), getTelecomManager(context).getDefaultDialerPackage()); if (result) { sWarningLogged = false;/*from ww w .j a v a 2 s. c om*/ } else { if (!sWarningLogged) { // Log only once to prevent spam. Log.w(TAG, "Dialer is not currently set to be default dialer"); sWarningLogged = true; } } return result; }
From source file:Main.java
public static File getCacheDirectory(Context context) { File appCacheDir = null;//from w w w .j a v a2 s.c om if (MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) && hasExternalStoragePermission(context)) { appCacheDir = getExternalCacheDir(context); } if (appCacheDir == null) { appCacheDir = context.getCacheDir(); } if (appCacheDir == null) { Log.w(TAG, "Can't define system cache directory! The app should be re-installed."); } return appCacheDir; }
From source file:Main.java
/** * @return the version code of the application *///from ww w . j a v a 2 s . c o m public static int getVersionCode(Context context) { int versionCode = -1; try { PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); versionCode = packageInfo.versionCode; } catch (PackageManager.NameNotFoundException e) { Log.w(TAG, e); } return versionCode; }
From source file:Main.java
public static boolean isPathStringValid(String path) { if (null == path || path.length() == 0) { return false; }// w ww.j a v a 2s. com if (path.contains(":") || path.contains("*") || path.contains("?") || path.contains("\"") || path.contains("<") || path.contains(">") || path.contains("|")) { Log.w(TAG, "filename can not contains:*:?\"<>|"); return false; } return true; }
From source file:Main.java
/** * * Send an ADB command using existing socket connection * * the streams provided must be from a socket connected to adbd already * * @param is input stream of the socket connection * @param os output stream of the socket * @param cmd the adb command to send/*from w w w . j ava 2 s . co m*/ * @return if adb gave a success response * @throws IOException */ public static boolean sendAdbCmd(InputStream is, OutputStream os, String cmd) throws IOException { byte[] buf = new byte[ADB_RESPONSE_SIZE]; cmd = String.format("%04X", cmd.length()) + cmd; os.write(cmd.getBytes()); int read = is.read(buf); if (read != ADB_RESPONSE_SIZE || !ADB_OK.equals(new String(buf))) { Log.w(LOGTAG, "adb cmd faild."); return false; } return true; }
From source file:Main.java
public static Size getOptimalVideoSnapshotPictureSize(List<Size> sizes, double targetRatio) { // Use a very small tolerance because we want an exact match. final double ASPECT_TOLERANCE = 0.001; if (sizes == null) return null; Size optimalSize = null;/*from w ww . j a va2 s.c om*/ // Try to find a size matches aspect ratio and has the largest width for (Size size : sizes) { double ratio = (double) size.width / size.height; if (Math.abs(ratio - targetRatio) > ASPECT_TOLERANCE) continue; if (optimalSize == null || size.width > optimalSize.width) { optimalSize = size; } } // Cannot find one that matches the aspect ratio. This should not happen. // Ignore the requirement. if (optimalSize == null) { Log.w(TAG, "No picture size match the aspect ratio"); for (Size size : sizes) { if (optimalSize == null || size.width > optimalSize.width) { optimalSize = size; } } } return optimalSize; }
From source file:Main.java
static Pair<String, Resources> findSystemApk(String action, PackageManager pm) { final Intent intent = new Intent(action); for (ResolveInfo info : pm.queryBroadcastReceivers(intent, 0)) { if (info.activityInfo != null && (info.activityInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) { final String packageName = info.activityInfo.packageName; try { final Resources res = pm.getResourcesForApplication(packageName); return Pair.create(packageName, res); } catch (NameNotFoundException e) { Log.w(TAG, "Failed to find resources for " + packageName); }//from w w w .j a v a 2 s . c o m } } return null; }