List of usage examples for android.util Log d
public static int d(String tag, String msg)
From source file:Main.java
public static Bitmap decodeSampledBitmapFromResource(int resId, int reqWidth, int reqHeight) { // First decode with inJustDecodeBounds=true to check dimensions final BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true;//from w w w . j a va2 s .com BitmapFactory.decodeResource(context.getResources(), resId, options); // Calculate inSampleSize float sampleSize = calculateInSampleSize(options, reqWidth, reqHeight); Log.d("----> Sample Size:", sampleSize + ""); if (sampleSize < 1) { // return a scaled UP version of image Bitmap bg = BitmapFactory.decodeResource(context.getResources(), resId); Bitmap scaledBitmap = Bitmap.createScaledBitmap(bg, (int) (bg.getWidth() / sampleSize), (int) (bg.getHeight() / sampleSize), true); bg.recycle(); return scaledBitmap; } else { // return a scaled DOWN version of image options.inSampleSize = Math.round(sampleSize); // Decode bitmap with inSampleSize set options.inJustDecodeBounds = false; return BitmapFactory.decodeResource(context.getResources(), resId, options); } }
From source file:Main.java
/** * get the FileOutputStream//from w ww. j a va 2 s . co m * @param filePath the filePath must contain head "/" * @return */ public static FileOutputStream getFileOutputStream(String filePath) { FileOutputStream fouts = null; File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + filePath.trim()); if (file.exists() && file.isFile()) { try { fouts = new FileOutputStream(file); Log.d("Ragnarok", "get the fouts path = " + file.getAbsolutePath()); return fouts; } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { try { File fileDirs = new File(file.getParent()); fileDirs.mkdirs(); //Log.d(LOG_TAG, "make the fileDirs " + fileDirs.getPath()); //file.createNewFile(); //Log.d("Ragnarok", "create a new file name " + file.getName()); Log.d("Ragnarok", "file path " + file.getAbsolutePath()); synchronized (file) { file.createNewFile(); fouts = new FileOutputStream(file); return fouts; } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return null; }
From source file:Main.java
public static boolean mobileNumberValidation(EditText editText) { if (nonEmpty(editText)) { String mobileNumber = removeBlankSpace(editText.getText().toString().trim()); return Patterns.PHONE.matcher(mobileNumber).matches(); } else {//from w w w . jav a2 s. c om Log.d("SERI_PAR->Error", "edit text object is null"); return NO; } }
From source file:Main.java
public static int getRotationAngle(String photoPath) { ExifInterface ei = null;// w ww . ja v a2 s .c o m try { ei = new ExifInterface(photoPath); } catch (IOException e) { Log.e(TAG, "Unexpected error occurred when getting rotation angle."); } int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED); switch (orientation) { case ExifInterface.ORIENTATION_ROTATE_90: Log.d(TAG, "90 Degrees rotation needed"); return 90; case ExifInterface.ORIENTATION_ROTATE_180: Log.d(TAG, "180 Degrees rotation needed"); return 180; case ExifInterface.ORIENTATION_ROTATE_270: Log.d(TAG, "270 Degrees rotation needed"); return 270; case ExifInterface.ORIENTATION_NORMAL: default: Log.d(TAG, "0 Degrees rotation needed"); return 0; } }
From source file:Main.java
public static float calculatorRatioScreen(Activity activity, boolean portrait) { DisplayMetrics disp = new DisplayMetrics(); activity.getWindowManager().getDefaultDisplay().getMetrics(disp); int screenWidth, screenHeight; screenWidth = disp.widthPixels;/*w ww . ja v a 2 s . c om*/ screenHeight = disp.heightPixels; Log.d("", "ratio screenWidth " + screenWidth + " screenHeight " + screenHeight); int defaultWidth = 480; int defaultHeight = 320; if (portrait) { defaultWidth = DEFAULT_SCREEN_WIDTH_PORTRAIT; defaultHeight = DEFAULT_SCREEN_HEIGHT_PORTRAIT; } else { defaultWidth = DEFAULT_SCREEN_WIDTH_LANSCAPE; defaultHeight = DEFAULT_SCREEN_HEIGHT_LANSCAPE; } float ratioByWidth = (float) screenWidth / defaultWidth; float ratioByHeight = (float) screenHeight / defaultHeight; float ratioReturn = Math.min(ratioByWidth, ratioByHeight); // isAlReady = true; return ratioReturn; }
From source file:Main.java
public static String getHours(String dateString) { SimpleDateFormat parserSDF = new SimpleDateFormat("HH:mm:ss"); SimpleDateFormat formater = new SimpleDateFormat("HH:mm"); parserSDF.setTimeZone(TimeZone.getTimeZone("UTC")); formater.setTimeZone(TimeZone.getTimeZone("UTC")); Date date = null;//from www . jav a 2s .c o m try { parserSDF.setTimeZone(TimeZone.getTimeZone("UTC")); date = parserSDF.parse(dateString); } catch (ParseException e) { Log.d(TAG, e.getMessage()); } return formater.format(date); }
From source file:Main.java
public static void debugWhere(String tag, String msg) { Log.d(tag, msg + " --- stack trace begins: "); StackTraceElement elements[] = Thread.currentThread().getStackTrace(); // skip first 3 element, they are not related to the caller for (int i = 3, n = elements.length; i < n; ++i) { StackTraceElement st = elements[i]; String message = String.format(" at %s.%s(%s:%s)", st.getClassName(), st.getMethodName(), st.getFileName(), st.getLineNumber()); Log.d(tag, message);//from w w w.ja va 2 s.c o m } Log.d(tag, msg + " --- stack trace ends."); }
From source file:Main.java
public static File getMediaThumbFolder(Context context) { File mediaThumbFolder = new File(getMediaFolder(context), THUMBNAILS_FOLDER); if (mediaThumbFolder != null) { if (!mediaThumbFolder.exists()) { mediaThumbFolder.mkdirs();/*from w w w .ja va 2 s .co m*/ Log.d(TAG, "Thumbnails folder created " + mediaThumbFolder); } createNoMediaFile(mediaThumbFolder); } return mediaThumbFolder; }
From source file:Main.java
public static Boolean isCameraAvailable(Activity activity) { Log.d(TAG, "[AirImagePickerUtils] Entering isCameraAvailable"); Boolean hasCameraFeature = activity.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA); Boolean hasFrontCameraFeature = activity.getPackageManager() .hasSystemFeature("android.hardware.camera.front"); Boolean isAvailable = (hasFrontCameraFeature || hasCameraFeature) && (isActionAvailable(activity, CAMERA_IMAGE_ACTION) || isActionAvailable(activity, CAMERA_VIDEO_ACTION)); Log.d(TAG, "[AirImagePickerUtils] Exiting isCameraAvailable"); return isAvailable; }
From source file:Main.java
public static int doShellCommand(String[] cmds, StringBuilder log, boolean runAsRoot, boolean waitFor) throws Exception { Process proc = null;// ww w .j a va2 s.c om int exitCode = -1; if (runAsRoot) proc = Runtime.getRuntime().exec("su"); else proc = Runtime.getRuntime().exec("sh"); OutputStreamWriter out = new OutputStreamWriter(proc.getOutputStream()); for (int i = 0; i < cmds.length; i++) { Log.d("the-onion-phone", "executing shell cmd: " + cmds[i] + "; runAsRoot=" + runAsRoot + ";waitFor=" + waitFor); out.write(cmds[i]); out.write("\n"); } out.flush(); out.write("exit\n"); out.flush(); if (waitFor) { final char buf[] = new char[10]; // Consume the "stdout" InputStreamReader reader = new InputStreamReader(proc.getInputStream()); int read = 0; while ((read = reader.read(buf)) != -1) { if (log != null) log.append(buf, 0, read); } // Consume the "stderr" reader = new InputStreamReader(proc.getErrorStream()); read = 0; while ((read = reader.read(buf)) != -1) { if (log != null) log.append(buf, 0, read); } exitCode = proc.waitFor(); } return exitCode; }