List of usage examples for android.util Log i
public static int i(String tag, String msg)
From source file:Main.java
/** * Download the avatar image from the server. * * @param avatarUrl the URL pointing to the avatar image * @return a byte array with the raw JPEG avatar image *//*from w ww . ja v a2s. c o m*/ public static byte[] downloadAvatar(final String avatarUrl) { // If there is no avatar, we're done if (TextUtils.isEmpty(avatarUrl)) { return null; } try { Log.i(TAG, "Downloading avatar: " + avatarUrl); // Request the avatar image from the server, and create a bitmap // object from the stream we get back. URL url = new URL(avatarUrl); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.connect(); try { final BitmapFactory.Options options = new BitmapFactory.Options(); final Bitmap avatar = BitmapFactory.decodeStream(connection.getInputStream(), null, options); // Take the image we received from the server, whatever format it // happens to be in, and convert it to a JPEG image. Note: we're // not resizing the avatar - we assume that the image we get from // the server is a reasonable size... Log.i(TAG, "Converting avatar to JPEG"); ByteArrayOutputStream convertStream = new ByteArrayOutputStream( avatar.getWidth() * avatar.getHeight() * 4); avatar.compress(Bitmap.CompressFormat.JPEG, 95, convertStream); convertStream.flush(); convertStream.close(); // On pre-Honeycomb systems, it's important to call recycle on bitmaps avatar.recycle(); return convertStream.toByteArray(); } finally { connection.disconnect(); } } catch (MalformedURLException muex) { // A bad URL - nothing we can really do about it here... Log.e(TAG, "Malformed avatar URL: " + avatarUrl); } catch (IOException ioex) { // If we're unable to download the avatar, it's a bummer but not the // end of the world. We'll try to get it next time we sync. Log.e(TAG, "Failed to download user avatar: " + avatarUrl); } return null; }
From source file:org.muckebox.android.net.ApiHelper.java
public static String callApi(String query, String id, String[] keys, String[] values) throws IOException, JSONException, AuthenticationException { String str_url = getApiUrl(query, id, keys, values); Log.i(LOG_TAG, "Connecting to " + str_url); MuckeboxHttpClient httpClient = new MuckeboxHttpClient(); HttpGet httpGet = null;//from w w w. j a v a 2 s.c o m try { httpGet = new HttpGet(str_url); HttpResponse httpResponse = httpClient.execute(httpGet); return getResponseAsString(httpResponse); } finally { if (httpGet != null) httpGet.abort(); if (httpClient != null) httpClient.destroy(); } }
From source file:Main.java
public static void sendWoLMagicPacket(final String broadcastIp, final String macAddress) { new Thread(new Runnable() { @Override/* www . j a va2s.com*/ public void run() { try { byte[] macBytes = getMacBytes(macAddress); byte[] bytes = new byte[6 + 16 * macBytes.length]; for (int i = 0; i < 6; i++) { bytes[i] = (byte) 0xff; } for (int i = 6; i < bytes.length; i += macBytes.length) { System.arraycopy(macBytes, 0, bytes, i, macBytes.length); } InetAddress address = InetAddress.getByName(broadcastIp); DatagramPacket packet = new DatagramPacket(bytes, bytes.length, address, 9); DatagramSocket socket = new DatagramSocket(); socket.send(packet); socket.close(); packet = new DatagramPacket(bytes, bytes.length, address, 7); socket = new DatagramSocket(); socket.send(packet); socket.close(); Log.e("WAKE_UP", "Wake-on-LAN packet sent."); final String output = getStringFromBytes(bytes); Log.i("WAKE_UP", output); } catch (Exception e) { Log.e("WAKE_UP", "Failed to send Wake-on-LAN packet: " + e); } } }).start(); }
From source file:Main.java
/** * Load the libtango_client_api.so library based on different Tango device setup. * * @return returns the loaded architecture id. *//*from ww w .j a v a2s. c o m*/ public static final int loadTangoSharedLibrary() { int loadedSoId = ARCH_ERROR; String basePath = "/data/data/com.google.tango/libfiles/"; if (!(new File(basePath).exists())) { basePath = "/data/data/com.projecttango.tango/libfiles/"; } Log.i("TangoInitHelper", "basePath: " + basePath); try { System.load(basePath + "arm64-v8a/libtango_client_api.so"); loadedSoId = ARCH_ARM64; Log.i("TangoInitHelper", "Success! Using arm64-v8a/libtango_client_api."); } catch (UnsatisfiedLinkError e) { } if (loadedSoId < ARCH_DEFAULT) { try { System.load(basePath + "armeabi-v7a/libtango_client_api.so"); loadedSoId = ARCH_ARM32; Log.i("TangoInitHelper", "Success! Using armeabi-v7a/libtango_client_api."); } catch (UnsatisfiedLinkError e) { } } if (loadedSoId < ARCH_DEFAULT) { try { System.load(basePath + "x86_64/libtango_client_api.so"); loadedSoId = ARCH_X86_64; Log.i("TangoInitHelper", "Success! Using x86_64/libtango_client_api."); } catch (UnsatisfiedLinkError e) { } } if (loadedSoId < ARCH_DEFAULT) { try { System.load(basePath + "x86/libtango_client_api.so"); loadedSoId = ARCH_X86; Log.i("TangoInitHelper", "Success! Using x86/libtango_client_api."); } catch (UnsatisfiedLinkError e) { } } if (loadedSoId < ARCH_DEFAULT) { try { System.load(basePath + "default/libtango_client_api.so"); loadedSoId = ARCH_DEFAULT; Log.i("TangoInitHelper", "Success! Using default/libtango_client_api."); } catch (UnsatisfiedLinkError e) { } } if (loadedSoId < ARCH_DEFAULT) { try { System.loadLibrary("tango_client_api"); loadedSoId = ARCH_FALLBACK; Log.i("TangoInitHelper", "Falling back to libtango_client_api.so symlink."); } catch (UnsatisfiedLinkError e) { } } return loadedSoId; }
From source file:Main.java
public static Bitmap getScaledScreenshot(final Activity activity, int scaleWidth, int scaleHeight, boolean relativeScaleIfTrue) { final View someView = activity.findViewById(android.R.id.content); final View rootView = someView.getRootView(); final boolean originalCacheState = rootView.isDrawingCacheEnabled(); rootView.setDrawingCacheEnabled(true); rootView.buildDrawingCache(true);//from ww w.j a v a 2 s . co m // We could get a null or zero px bitmap if the rootView hasn't been measured // appropriately, or we grab it before layout. // This is ok, and we should handle it gracefully. final Bitmap original = rootView.getDrawingCache(); Bitmap scaled = null; if (null != original && original.getWidth() > 0 && original.getHeight() > 0) { if (relativeScaleIfTrue) { scaleWidth = original.getWidth() / scaleWidth; scaleHeight = original.getHeight() / scaleHeight; } if (scaleWidth > 0 && scaleHeight > 0) { try { scaled = Bitmap.createScaledBitmap(original, scaleWidth, scaleHeight, false); } catch (OutOfMemoryError error) { Log.i(LOGTAG, "Not enough memory to produce scaled image, returning a null screenshot"); } } } if (!originalCacheState) { rootView.setDrawingCacheEnabled(false); } return scaled; }
From source file:Main.java
private static File getExternalCacheDir(Context context) { File dataDir = new File(new File(Environment.getExternalStorageDirectory(), "Android"), "data"); File appCacheDir = new File(new File(dataDir, context.getPackageName()), "cache"); if (!appCacheDir.exists()) { if (!appCacheDir.mkdirs()) { Log.w(TAG, "Unable to create external cache directory"); return null; }/*from ww w . j av a 2 s.co m*/ 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
@SuppressLint("NewApi") public static void getURL(String path) { String fileName = ""; String dir = "/IndoorNavi/"; File sdRoot = Environment.getExternalStorageDirectory(); try {/* w w w . j a v a 2 s . co m*/ // Open the URLConnection for reading URL u = new URL(path); // URL u = new URL("http://www.baidu.com/"); HttpURLConnection uc = (HttpURLConnection) u.openConnection(); int code = uc.getResponseCode(); String response = uc.getResponseMessage(); //System.out.println("HTTP/1.x " + code + " " + response); for (int j = 1;; j++) { String key = uc.getHeaderFieldKey(j); String header = uc.getHeaderField(j); if (!(key == null)) { if (key.equals("Content-Name")) fileName = header; } if (header == null || key == null) break; //System.out.println(uc.getHeaderFieldKey(j) + ": " + header); } Log.i("zhr", fileName); //System.out.println(); try (InputStream in = new BufferedInputStream(uc.getInputStream())) { // chain the InputStream to a Reader Reader r = new InputStreamReader(in); int c; File mapFile = new File(sdRoot, dir + fileName); mapFile.createNewFile(); FileOutputStream filecon = new FileOutputStream(mapFile); while ((c = r.read()) != -1) { //System.out.print((char) c); filecon.write(c); filecon.flush(); } filecon.close(); } } catch (MalformedURLException ex) { System.err.println(path + " is not a parseable URL"); } catch (IOException ex) { System.err.println(ex); } }
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; }/* w w 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:Main.java
@TargetApi(Build.VERSION_CODES.GINGERBREAD) public static void setBestPreviewFPS(Camera.Parameters parameters, int minFPS, int maxFPS) { List<int[]> supportedPreviewFpsRanges = parameters.getSupportedPreviewFpsRange(); Log.i(TAG, "Supported FPS ranges: " + toString(supportedPreviewFpsRanges)); if (supportedPreviewFpsRanges != null && !supportedPreviewFpsRanges.isEmpty()) { int[] suitableFPSRange = null; for (int[] fpsRange : supportedPreviewFpsRanges) { int thisMin = fpsRange[Camera.Parameters.PREVIEW_FPS_MIN_INDEX]; int thisMax = fpsRange[Camera.Parameters.PREVIEW_FPS_MAX_INDEX]; if (thisMin >= minFPS * 1000 && thisMax <= maxFPS * 1000) { suitableFPSRange = fpsRange; break; }/*from w w w .ja v a 2 s . co m*/ } if (suitableFPSRange == null) { Log.i(TAG, "No suitable FPS range?"); } else { int[] currentFpsRange = new int[2]; parameters.getPreviewFpsRange(currentFpsRange); if (Arrays.equals(currentFpsRange, suitableFPSRange)) { Log.i(TAG, "FPS range already set to " + Arrays.toString(suitableFPSRange)); } else { Log.i(TAG, "Setting FPS range to " + Arrays.toString(suitableFPSRange)); parameters.setPreviewFpsRange(suitableFPSRange[Camera.Parameters.PREVIEW_FPS_MIN_INDEX], suitableFPSRange[Camera.Parameters.PREVIEW_FPS_MAX_INDEX]); } } } }
From source file:Main.java
public static void setTorch(Camera.Parameters parameters, boolean on) { List<String> supportedFlashModes = parameters.getSupportedFlashModes(); String flashMode;/*w w w . j a v a 2 s . com*/ if (on) { flashMode = findSettableValue("flash mode", supportedFlashModes, Camera.Parameters.FLASH_MODE_TORCH, Camera.Parameters.FLASH_MODE_ON); } else { flashMode = findSettableValue("flash mode", supportedFlashModes, Camera.Parameters.FLASH_MODE_OFF); } if (flashMode != null) { if (flashMode.equals(parameters.getFlashMode())) { Log.i(TAG, "Flash mode already set to " + flashMode); } else { Log.i(TAG, "Setting flash mode to " + flashMode); parameters.setFlashMode(flashMode); } } }