List of usage examples for android.util Log d
public static int d(String tag, String msg)
From source file:Main.java
public static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) { Cursor cursor = null;//from ww w . ja v a 2 s. com final String column = "_data"; final String[] projection = { column }; try { cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null); if (cursor != null && cursor.moveToFirst()) { final int column_index = cursor.getColumnIndexOrThrow(column); return cursor.getString(column_index); } } catch (Exception e) { Log.d("android_utilities", "the error is " + e); } finally { if (cursor != null) { cursor.close(); } } return null; }
From source file:Main.java
public static String createPubNubSafeBase64Hash(String input) { try {//from w w w. ja va2s.c o m MessageDigest messageDigest = MessageDigest.getInstance("SHA-256"); messageDigest.update(input.getBytes()); String encodedChannelName = Base64.encodeToString(messageDigest.digest(), Base64.URL_SAFE); //pubnub channel names cannot be more than 92 characters if (encodedChannelName.length() > 92) { encodedChannelName = encodedChannelName.substring(0, 91); } //pubnub channel names cannot have whitespace characters return encodedChannelName.trim(); } catch (Exception e) { Log.d("X", "Error in encoding: " + e.getMessage()); return null; } }
From source file:Main.java
public static String decryptData(String ciphertext, String password) throws Exception { int iterationCount = 100; //because polaroid int keyLength = 256; String[] fields = ciphertext.split("]"); byte[] iv = Base64.decode(fields[0], 0); byte[] salt = Base64.decode(fields[1], 0); byte[] cipherBytes = Base64.decode(fields[2], 0); Log.d(TAG, "ciphertext: " + ciphertext + "\n" + "iv length is " + "\n" + iv.length); KeySpec keySpec = new PBEKeySpec(password.toCharArray(), salt, iterationCount, keyLength); SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1"); byte[] keyBytes = keyFactory.generateSecret(keySpec).getEncoded(); SecretKey key = new SecretKeySpec(keyBytes, "AES"); Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); IvParameterSpec ivParams = new IvParameterSpec(iv); cipher.init(Cipher.DECRYPT_MODE, key, ivParams); byte[] plaintext = cipher.doFinal(cipherBytes); String plainStr = new String(plaintext, "UTF-8"); return plainStr; }
From source file:Main.java
/** * Reads in model 83 points and returns a double array float containing the * coordinates x & y./*from w w w . j a v a2 s. c o m*/ */ public static float[][][] readBinSFSV(String dir, String fileName) { float[][][] array3D = new float[60][83][3]; float x; File sdLien = Environment.getExternalStorageDirectory(); File inFile = new File(sdLien + File.separator + dir + File.separator + fileName); Log.d(TAG, "path of file : " + inFile); if (!inFile.exists()) { throw new RuntimeException("File doesn't exist"); } DataInputStream in = null; try { in = new DataInputStream(new FileInputStream(inFile)); } catch (FileNotFoundException e) { e.printStackTrace(); } try { for (int k = 0; k < 3; k++) { for (int j = 0; j < 83; j++) { for (int i = 0; i < 60; i++) { x = in.readFloat(); array3D[i][j][k] = x; } } } } catch (EOFException e) { try { Log.d(TAG, "close"); in.close(); } catch (IOException e1) { e1.printStackTrace(); } } catch (IOException e) { e.printStackTrace(); } finally { if (in != null) { try { //free ressources Log.d(TAG, "close"); in.close(); } catch (IOException e) { e.printStackTrace(); } } } return array3D; }
From source file:Main.java
public static byte[] retrieveImageData_fromUrl(String imageUrl) throws IOException { URL url = new URL(imageUrl); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestProperty("User-Agent", System.getProperties().getProperty("http.agent") + " FacebookAndroidSDK"); // determine the image size and allocate a buffer int fileSize = connection.getContentLength(); byte[] imageData = new byte[fileSize]; // download the file Log.d(TAG, "fetching image " + imageUrl + " (" + fileSize + ")"); if (fileSize > 0) { BufferedInputStream istream = new BufferedInputStream(connection.getInputStream()); int bytesRead = 0; int offset = 0; while (bytesRead != -1 && offset < fileSize) { bytesRead = istream.read(imageData, offset, fileSize - offset); offset += bytesRead;// www.j ava2s. co m } istream.close(); } else Log.d(TAG, "fileSize is 0! skipping"); // clean up connection.disconnect(); return imageData; }
From source file:Main.java
public static File getRealFileName(String baseDir, String absFileName) { String[] dirs = absFileName.split("/"); File ret = new File(baseDir); String substr = null;/* ww w. j av a2 s. c om*/ if (dirs.length > 1) { for (int i = 0; i < dirs.length - 1; i++) { substr = dirs[i]; try { substr = new String(substr.getBytes("8859_1"), "GB2312"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } ret = new File(ret, substr); } Log.d(TAG, "1ret = " + ret); if (!ret.exists()) ret.mkdirs(); substr = dirs[dirs.length - 1]; try { substr = new String(substr.getBytes("8859_1"), "GB2312"); Log.d(TAG, "substr = " + substr); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } ret = new File(ret, substr); Log.d(TAG, "2ret = " + ret); return ret; } // a single file name without relatvie path, try { substr = new String(absFileName.getBytes("8859_1"), "GB2312"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } ret = new File(ret, substr); return ret; }
From source file:Main.java
public static void LogD(String msg) { if (mIsDebug) { Log.d(mLogTag, msg); } }
From source file:Main.java
public static List<CamcorderProfile> getAvailableProfiles(int cameraID) { List<CamcorderProfile> profiles = new ArrayList<>(specificProfileQualities.length); for (int quality : specificProfileQualities) { if (CamcorderProfile.hasProfile(cameraID, quality)) { CamcorderProfile p = CamcorderProfile.get(cameraID, quality); profiles.add(p);/* ww w .j a va2s . c om*/ Log.d("PROFILE", p.videoFrameWidth + "x" + p.videoFrameHeight + " " + p.videoFrameRate + " fps " + p.videoBitRate + " bps "); } } return profiles; }
From source file:Main.java
/** * /*from ww w . ja v a 2 s . c om*/ * @param zipFile * zip file * @param folderName * folder to load * @return list of entry in the folder * @throws ZipException * @throws IOException */ public static List<ZipEntry> loadFiles(File zipFile, String folderName) throws ZipException, IOException { Log.d("loadFiles", folderName); long start = System.currentTimeMillis(); FileInputStream fis = new FileInputStream(zipFile); BufferedInputStream bis = new BufferedInputStream(fis); ZipInputStream zis = new ZipInputStream(bis); ZipEntry zipEntry = null; List<ZipEntry> list = new LinkedList<ZipEntry>(); String folderLowerCase = folderName.toLowerCase(); int counter = 0; while ((zipEntry = zis.getNextEntry()) != null) { counter++; String zipEntryName = zipEntry.getName(); Log.d("loadFiles.zipEntry.getName()", zipEntryName); if (zipEntryName.toLowerCase().startsWith(folderLowerCase) && !zipEntry.isDirectory()) { list.add(zipEntry); } } Log.d("Loaded 1", counter + " files, took: " + (System.currentTimeMillis() - start) + " milliseconds."); zis.close(); bis.close(); fis.close(); return list; }
From source file:Main.java
public static String hashMD5Generate(String s) { try {//from w w w . j a v a 2 s .c om // Create MD5 Hash MessageDigest digest = java.security.MessageDigest.getInstance("MD5"); digest.update(s.getBytes()); byte messageDigest[] = digest.digest(); // Create Hex String StringBuffer hexString = new StringBuffer(); for (int i = 0; i < messageDigest.length; i++) { String h = Integer.toHexString(0xFF & messageDigest[i]); while (h.length() < 2) h = "0" + h; hexString.append(h); } Log.d(DEBUG, hexString.toString()); return hexString.toString(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return ""; }