List of usage examples for android.util Log w
public static int w(String tag, Throwable tr)
From source file:Main.java
/** * Get the total hrs logged this pay period. * * @param page the raw html of the user's timecard page * @return A double representing the total hours logged this pay period by the user. *//* ww w . j a va 2 s. c o m*/ protected static double getTotalsHrs(String page) { double total = 0; try { Pattern pattern = Pattern.compile("(?i)(<div.*?>)(" + TOTAL_STR + ")(.*?)(</div>)"); Matcher matcher = pattern.matcher(page); if (matcher.find()) { String totalStr = matcher.group(3); if (!(totalStr == null || totalStr.trim().length() == 0)) { total = Double.parseDouble(totalStr); } } } catch (Exception e) { Log.w(TAG, e.toString()); } return total; }
From source file:com.rincliu.library.util.RLNetUtil.java
/** * @param context/*from w ww .java 2 s . c om*/ * @return */ public static boolean isNetworkAvailable(Context context) { ConnectivityManager connectivity = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivity == null) { Log.w(LOG_TAG, "couldn't get connectivity manager"); } else { NetworkInfo[] info = connectivity.getAllNetworkInfo(); if (info != null) { for (int i = 0; i < info.length; i++) { if (info[i].isAvailable()) { Log.d(LOG_TAG, "network is available"); return true; } } } } Log.d(LOG_TAG, "network is not available"); return false; }
From source file:Main.java
/** * Finds the most optimal size. The optimal size is when possible the same as * the camera resolution, if not is is it the best size between the camera solution and * MIN_SIZE_PIXELS//from w ww . j a v a 2 s . co m * @param screenResolution * @param rawSupportedSizes *@param defaultCameraSize @return optimal preview size */ private static Point findBestSizeValue(Point screenResolution, List<Camera.Size> rawSupportedSizes, Camera.Size defaultCameraSize) { if (rawSupportedSizes == null) { Log.w(TAG, "Device returned no supported sizes; using default"); if (defaultCameraSize == null) { throw new IllegalStateException("Parameters contained no size!"); } return new Point(defaultCameraSize.width, defaultCameraSize.height); } // Sort by size, descending List<Camera.Size> supportedSizes = new ArrayList<>(rawSupportedSizes); Collections.sort(supportedSizes, 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 sizesString = new StringBuilder(); for (Camera.Size supportedSize : supportedSizes) { sizesString.append(supportedSize.width).append('x').append(supportedSize.height).append(' '); } Log.i(TAG, "Supported sizes: " + sizesString); } double screenAspectRatio = (double) screenResolution.x / (double) screenResolution.y; // Remove sizes that are unsuitable Iterator<Camera.Size> it = supportedSizes.iterator(); while (it.hasNext()) { Camera.Size supportedSize = it.next(); int realWidth = supportedSize.width; int realHeight = supportedSize.height; if (realWidth * realHeight < MIN_SIZE_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 size exactly matching screen size: " + exactPoint); return exactPoint; } } // If no exact match, use largest 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 (!supportedSizes.isEmpty()) { Camera.Size largestCameraSizes = supportedSizes.get(0); Point largestSize = new Point(largestCameraSizes.width, largestCameraSizes.height); Log.i(TAG, "Using largest suitable size: " + largestSize); return largestSize; } // If there is nothing at all suitable, return current size if (defaultCameraSize == null) { throw new IllegalStateException("Parameters contained no size!"); } Point defaultSize = new Point(defaultCameraSize.width, defaultCameraSize.height); Log.i(TAG, "No suitable sizes, using default: " + defaultSize); return defaultSize; }
From source file:Main.java
private static Integer indexOfClosestZoom(Camera.Parameters parameters, double targetZoomRatio) { List<Integer> ratios = parameters.getZoomRatios(); Log.i(TAG, "Zoom ratios: " + ratios); int maxZoom = parameters.getMaxZoom(); if (ratios == null || ratios.isEmpty() || ratios.size() != maxZoom + 1) { Log.w(TAG, "Invalid zoom ratios!"); return null; }//from ww w . j a v a 2s . c o m double target100 = 100.0 * targetZoomRatio; double smallestDiff = Double.POSITIVE_INFINITY; int closestIndex = 0; for (int i = 0; i < ratios.size(); i++) { double diff = Math.abs(ratios.get(i) - target100); if (diff < smallestDiff) { smallestDiff = diff; closestIndex = i; } } Log.i(TAG, "Chose zoom ratio of " + (ratios.get(closestIndex) / 100.0)); return closestIndex; }
From source file:org.fdroid.enigtext.mms.MmsSendHelper.java
private static byte[] makePost(Context context, MmsConnectionParameters parameters, byte[] mms) throws ClientProtocolException, IOException { AndroidHttpClient client = null;/*from w w w.jav a 2 s.c om*/ try { Log.w("MmsSender", "Sending MMS1 of length: " + (mms != null ? mms.length : "null")); client = constructHttpClient(context, parameters); URI targetUrl = new URI(parameters.getMmsc()); if (Util.isEmpty(targetUrl.getHost())) throw new IOException("Invalid target host: " + targetUrl.getHost() + " , " + targetUrl); HttpHost target = new HttpHost(targetUrl.getHost(), targetUrl.getPort(), HttpHost.DEFAULT_SCHEME_NAME); HttpPost request = new HttpPost(parameters.getMmsc()); ByteArrayEntity entity = new ByteArrayEntity(mms); entity.setContentType("application/vnd.wap.mms-message"); request.setEntity(entity); request.setParams(client.getParams()); request.addHeader("Accept", "*/*, application/vnd.wap.mms-message, application/vnd.wap.sic"); request.addHeader("x-wap-profile", "http://www.google.com/oha/rdf/ua-profile-kila.xml"); HttpResponse response = client.execute(target, request); StatusLine status = response.getStatusLine(); if (status.getStatusCode() != 200) throw new IOException("Non-successful HTTP response: " + status.getReasonPhrase()); return parseResponse(response.getEntity()); } catch (URISyntaxException use) { Log.w("MmsSendHelper", use); throw new IOException("Couldn't parse URI."); } finally { if (client != null) client.close(); } }
From source file:Main.java
public static File getExternalCacheDir(Context context, String dirName) { File dataDir = new File(new File(Environment.getExternalStorageDirectory(), "Charismatic_yichang"), "data"); File appCacheDir2 = new File(new File(dataDir, context.getPackageName()), "cache"); File appCacheDir = new File(appCacheDir2, dirName); if (!appCacheDir.exists()) { if (!appCacheDir.mkdirs()) { Log.w(TAG, "Unable to create external cache directory"); return null; }//w w w.ja va 2s . com try { new File(appCacheDir, ".nomedia").createNewFile(); } catch (IOException e) { Log.i(TAG, "Can't create \".nomedia\" file in application external cache directory"); } } return appCacheDir; }
From source file:Main.java
public static Size getOptimalPreviewSize(Activity currentActivity, 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 av a2s . co m*/ double minDiff = Double.MAX_VALUE; // Because of bugs of overlay and layout, we sometimes will try to // layout the viewfinder in the portrait orientation and thus get the // wrong size of preview surface. When we change the preview size, the // new overlay will be created before the old one closed, which causes // an exception. For now, just get the screen size. Point point = getDefaultDisplaySize(currentActivity, new Point()); int targetHeight = Math.min(point.x, point.y); // Try to find an size match aspect ratio and size for (Size size : sizes) { double ratio = (double) size.width / size.height; if (Math.abs(ratio - targetRatio) > ASPECT_TOLERANCE) continue; if (Math.abs(size.height - targetHeight) < minDiff) { optimalSize = size; minDiff = Math.abs(size.height - targetHeight); } } // Cannot find the one match the aspect ratio. This should not happen. // Ignore the requirement. if (optimalSize == null) { Log.w(TAG, "No preview size match the aspect ratio"); minDiff = Double.MAX_VALUE; for (Size size : sizes) { if (Math.abs(size.height - targetHeight) < minDiff) { optimalSize = size; minDiff = Math.abs(size.height - targetHeight); } } } return optimalSize; }
From source file:Main.java
@SuppressLint("NewApi") public static Bitmap createVideoThumbnail(String filePath, int kind) { Bitmap bitmap = null;// w ww .j a v a2 s. c o m if (Build.VERSION.SDK_INT < 10) { // This peace of code is for compatibility with android 8 and 9. return android.media.ThumbnailUtils.createVideoThumbnail(filePath, kind); } // MediaMetadataRetriever is not available for Android version less than 10 // but we need to use it in order to get first frame of the video for thumbnail. MediaMetadataRetriever retriever = new MediaMetadataRetriever(); try { retriever.setDataSource(filePath); bitmap = retriever.getFrameAtTime(0); } catch (IllegalArgumentException ex) { // Assume this is a corrupt video file } catch (RuntimeException ex) { // Assume this is a corrupt video file. } finally { try { retriever.release(); } catch (RuntimeException ex) { // Ignore failures while cleaning up. Log.w("ThumbnailUtils", "MediaMetadataRetriever failed with exception: " + ex); } } if (bitmap == null) return null; if (kind == Images.Thumbnails.MINI_KIND) { // Scale down the bitmap if it's too large. int width = bitmap.getWidth(); int height = bitmap.getHeight(); int max = Math.max(width, height); if (max > 512) { float scale = 512f / max; int w = Math.round(scale * width); int h = Math.round(scale * height); bitmap = Bitmap.createScaledBitmap(bitmap, w, h, true); } } else if (kind == Images.Thumbnails.MICRO_KIND) { bitmap = android.media.ThumbnailUtils.extractThumbnail(bitmap, TARGET_SIZE_MICRO_THUMBNAIL, TARGET_SIZE_MICRO_THUMBNAIL, OPTIONS_RECYCLE_INPUT); } return bitmap; }
From source file:Main.java
/** * Returns the version string of the installed APK. * * @param context The activity context to access the Package Manager * @param packageNamespace The APK's namespace * @return Version string/*from w ww . j av a2 s . c o m*/ * @throws PackageManager.NameNotFoundException */ public static String getInstalledApkVersion(Context context, String packageNamespace) throws PackageManager.NameNotFoundException { String installedVersion = ""; try { PackageInfo pInfo = context.getPackageManager().getPackageInfo(packageNamespace, 0); if (pInfo != null) installedVersion = pInfo.versionName; } catch (PackageManager.NameNotFoundException e) { Log.w("ApkUpdater", "[WARNING #900] Package name '" + packageNamespace + "'was not found."); } catch (Exception e) { Log.e("ApkUpdater", "[ERROR #900] getInstalledApkVersion() failed."); } return installedVersion; }
From source file:Main.java
static List<Pair<String, Resources>> findSystemApks(String action, PackageManager pm) { final Intent intent = new Intent(action); List<Pair<String, Resources>> systemApks = new ArrayList<Pair<String, Resources>>(); 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); systemApks.add(Pair.create(packageName, res)); } catch (NameNotFoundException e) { Log.w(TAG, "Failed to find resources for " + packageName); }/*from w ww. ja va 2 s . c o m*/ } } return systemApks; }