Example usage for android.util Log w

List of usage examples for android.util Log w

Introduction

In this page you can find the example usage for android.util Log w.

Prototype

public static int w(String tag, Throwable tr) 

Source Link

Usage

From source file:eu.trentorise.smartcampus.portfolio.utils.NetUtility.java

public static Bitmap loadBitmapfromUrl(String imageUrl) {
    Bitmap resultImage = null;//w w w  .  j av a  2  s .c o  m
    HttpGet getRequest = new HttpGet();
    try {
        URI imageURI = new URI(imageUrl);
        getRequest.setURI(imageURI);
        HttpClient httpClient = HttpClientFactory.INSTANCE.getThreadSafeHttpClient();
        HttpResponse response = httpClient.execute(getRequest);
        final int statusCode = response.getStatusLine().getStatusCode();
        if (statusCode != HttpStatus.SC_OK) {
            Log.w(NetUtility.class.getName(), "Error: " + statusCode + " image url: " + imageUrl);
        } else {
            final HttpEntity entity = response.getEntity();
            if (entity != null) {
                InputStream inputStream = null;
                try {
                    inputStream = new FlushedInputStream(entity.getContent());
                    resultImage = BitmapFactory.decodeStream(inputStream);
                } finally {
                    if (inputStream != null) {
                        inputStream.close();
                    }
                    entity.consumeContent();
                }
            }
        }
    } catch (Exception e) {
        getRequest.abort();
        e.printStackTrace();
        Log.w(NetUtility.class.getName(), "Error image url: " + imageUrl);
    }
    return resultImage;
}

From source file:Main.java

/**
 * Configures the connection to serve as a transparent proxy to a remote machine.
 * The given streams must belong to a socket created by createSocket().
 *
 * @param inputStream inputStream of the socket we want to configure
 * @param outputStream outputStream of the socket we want to configure
 * @param remoteAddress address of the remote machine (as you would type in a browser
 *      in a machine that the device is connected to via adb)
 * @param remotePort port on which to connect
 * @return if the configuration suceeded
 * @throws IOException/*  ww w .j  a  v  a2s  .  c  o  m*/
 */
public static boolean configureConnection(InputStream inputStream, OutputStream outputStream,
        String remoteAddress, int remotePort) throws IOException {
    String cmd = "tcp:" + remotePort + ":" + remoteAddress;
    cmd = String.format("%04X", cmd.length()) + cmd;

    byte[] buf = new byte[ADB_RESPONSE_SIZE];
    outputStream.write(cmd.getBytes());
    int read = inputStream.read(buf);
    if (read != ADB_RESPONSE_SIZE || !ADB_OK.equals(new String(buf))) {
        Log.w(LOG_TAG, "adb cmd failed.");
        return false;
    }
    return true;
}

From source file:com.rp.justcast.video.VideoProvider.java

public static List<MediaInfo> buildMedia() throws JSONException {

    if (null != mediaList) {
        return mediaList;
    }/*from   w w w. java 2 s .c  o  m*/

    String[] columns = { MediaStore.Video.Media._ID, MediaStore.Video.Media.DATA, MediaStore.Video.Media.TITLE,
            MediaStore.Video.Media.DURATION };
    String orderBy = MediaStore.Images.Media.DATE_TAKEN + " desc";
    Cursor videoCursor = null;
    try {
        videoCursor = JustCast.getmAppContext().getContentResolver()
                .query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, columns, null, null, orderBy);
        videoCursor.moveToFirst();
        long fileId = videoCursor.getLong(videoCursor.getColumnIndex(MediaStore.Video.Media._ID));
        Log.w(TAG, "Building Media");
        Log.w(TAG, "Video Count" + videoCursor.getCount());
        int count = videoCursor.getCount();
        Log.d(TAG, "Count of images" + count);
        mediaList = new ArrayList<MediaInfo>();
        for (int i = 0; i < count; i++) {
            videoCursor.moveToPosition(i);
            int dataColumnIndex = videoCursor.getColumnIndex(MediaStore.Video.Media.DATA);
            int titleIndex = videoCursor.getColumnIndex(MediaStore.Video.Media.TITLE);
            Log.w(TAG, "Video added" + videoCursor.getString(dataColumnIndex));
            String path = videoCursor.getString(dataColumnIndex);
            String title = videoCursor.getString(titleIndex);
            MediaMetadata movieMetadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MOVIE);
            movieMetadata.putString("VIDEO_PATH", path);
            movieMetadata.putString(MediaMetadata.KEY_SUBTITLE, title);
            movieMetadata.putString(MediaMetadata.KEY_TITLE, title);
            movieMetadata.putString(MediaMetadata.KEY_STUDIO, title);
            path = JustCast.addJustCastServerParam(path);
            MediaInfo mediaInfo = new MediaInfo.Builder(path).setStreamType(MediaInfo.STREAM_TYPE_BUFFERED)
                    .setContentType(getMediaType()).setMetadata(movieMetadata).build();
            mediaList.add(mediaInfo);
        }
    } finally {
        videoCursor.close();
    }
    return mediaList;
}

From source file:Main.java

/**
 * Parses a string as an opaque color, either as a decimal hue (example: {@code 330}) using a
 * standard set of saturation and value) or as six digit hex code (example: {@code #BB66FF}).
 * If the string is null or cannot  otherwise be parsed, any error is logged and
 * {@code defaultColor} is returned.//from   w ww .  j  ava  2s.  co  m
 *
 * @param str The input to parse.
 * @param tempHsvArray An optional previously allocated array for HSV calculations.
 * @param defaultColor The default color to return if the color cannot be parsed.
 * @return The parsed color, in {@code int} form.
 */
public static int parseColor(@Nullable String str, @Nullable float[] tempHsvArray, int defaultColor) {
    if (str == null) {
        return defaultColor;
    }
    str = str.trim();
    if (str.isEmpty()) {
        return defaultColor;
    }
    try {
        return parseColor(str, tempHsvArray);
    } catch (ParseException e) {
        Log.w(TAG, e.toString());
        return defaultColor;
    }
}

From source file:Main.java

/**
 * Attempts to find a preview size that matches the provided width and height (which
 * specify the dimensions of the encoded video).  If it fails to find a match it just
 * uses the default preview size for video.
 * <p>//from  w ww.  j ava  2 s .  co m
 * TODO: should do a best-fit match, e.g.
 * https://github.com/commonsguy/cwac-camera/blob/master/camera/src/com/commonsware/cwac/camera/CameraUtils.java
 */
public static Camera.Size choosePreviewSize(Camera.Parameters parms, int width, int height) {
    // We should make sure that the requested MPEG size is less than the preferred
    // size, and has the same aspect ratio.
    Camera.Size ppsfv = parms.getPreferredPreviewSizeForVideo();
    if (ppsfv != null) {
        Log.d(TAG, "Camera preferred preview size for video is " + ppsfv.width + "x" + ppsfv.height);
    }

    //for (Camera.Size size : parms.getSupportedPreviewSizes()) {
    //    Log.d(TAG, "supported: " + size.width + "x" + size.height);
    //}

    for (Camera.Size size : parms.getSupportedPreviewSizes()) {
        if (size.width == width && size.height == height) {
            parms.setPreviewSize(width, height);
            return size;
        }
    }

    Log.w(TAG, "Unable to set preview size to " + width + "x" + height);
    if (ppsfv != null) {
        parms.setPreviewSize(ppsfv.width, ppsfv.height);
    }
    // else use whatever the default size is
    return ppsfv;
}

From source file:Main.java

private static int generateIterationCount(String passphrase, byte[] salt) {
    int TARGET_ITERATION_TIME = 50; //ms
    int MINIMUM_ITERATION_COUNT = 100; //default for low-end devices
    int BENCHMARK_ITERATION_COUNT = 10000; //baseline starting iteration count

    try {/*from  w  w  w.  ja  v a 2  s .c  om*/
        PBEKeySpec keyspec = new PBEKeySpec(passphrase.toCharArray(), salt, BENCHMARK_ITERATION_COUNT);
        SecretKeyFactory skf = SecretKeyFactory.getInstance("PBEWITHSHA1AND128BITAES-CBC-BC");

        long startTime = System.currentTimeMillis();
        skf.generateSecret(keyspec);
        long finishTime = System.currentTimeMillis();

        int scaledIterationTarget = (int) (((double) BENCHMARK_ITERATION_COUNT
                / (double) (finishTime - startTime)) * TARGET_ITERATION_TIME);

        if (scaledIterationTarget < MINIMUM_ITERATION_COUNT)
            return MINIMUM_ITERATION_COUNT;
        else
            return scaledIterationTarget;
    } catch (NoSuchAlgorithmException e) {
        Log.w("MasterSecretUtil", e);
        return MINIMUM_ITERATION_COUNT;
    } catch (InvalidKeySpecException e) {
        Log.w("MasterSecretUtil", e);
        return MINIMUM_ITERATION_COUNT;
    }
}

From source file:Main.java

public static String getSuVersion() {
    Process process = null;/* w w  w . j a v  a 2s.  co m*/
    String inLine = null;

    try {
        process = Runtime.getRuntime().exec("sh");
        DataOutputStream os = new DataOutputStream(process.getOutputStream());
        BufferedReader is = new BufferedReader(
                new InputStreamReader(new DataInputStream(process.getInputStream())), 64);
        os.writeBytes("su -v\n");

        // We have to hold up the thread to make sure that we're ready to read
        // the stream, using increments of 5ms makes it return as quick as
        // possible, and limiting to 1000ms makes sure that it doesn't hang for
        // too long if there's a problem.
        for (int i = 0; i < 400; i++) {
            if (is.ready()) {
                break;
            }
            try {
                Thread.sleep(5);
            } catch (InterruptedException e) {
                Log.w(TAG, "Sleep timer got interrupted...");
            }
        }
        if (is.ready()) {
            inLine = is.readLine();
            if (inLine != null) {
                return inLine;
            }
        } else {
            os.writeBytes("exit\n");
        }
    } catch (IOException e) {
        Log.e(TAG, "Problems reading current version.", e);
        return null;
    } finally {
        if (process != null) {
            process.destroy();
        }
    }

    return null;
}

From source file:Main.java

public static String getIpWithoutWifi() {
    try {// w  w w .j a  v  a2 s .  c o m
        for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en
                .hasMoreElements();) {
            NetworkInterface intf = en.nextElement();
            for (Enumeration<InetAddress> enumeration = intf.getInetAddresses(); en.hasMoreElements();) {
                InetAddress inetAddress = enumeration.nextElement();
                if (inetAddress.isLoopbackAddress()) {
                    return inetAddress.getHostAddress().toString();
                }
            }
        }
    } catch (Exception e) {
        Log.w(TAG, "getIpWithoutWifi error:" + e.getMessage());
    }
    return null;
}

From source file:Main.java

private static File getExternalCacheDir(Context context, String dirName) {
    File dataDir = new File(new File(Environment.getExternalStorageDirectory(), "Android"), "data");
    File appCacheDir = new File(new File(dataDir, context.getPackageName()), dirName);
    //      File appCacheDir = new File(appCacheDir2, dirName);
    if (!appCacheDir.exists()) {
        if (!appCacheDir.mkdirs()) {
            Log.w(TAG, "Unable to create external cache directory");
            return null;
        }/*from w ww  . j a  v  a 2s.  c  o 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

public static Object toSerializableObject(Object obj) {
    // Case for objects have no specified method to JSON string.
    if (obj.getClass().isArray()) {
        JSONArray result = new JSONArray();
        Object[] arr = (Object[]) obj;
        for (int i = 0; i < arr.length; ++i) {
            try {
                result.put(i, toSerializableObject(arr[i]));
            } catch (Exception e) {
                e.printStackTrace();//w ww. j a  v a  2 s . co m
            }
        }
        return result;
    }
    // The original serializable object.
    if (isSerializable(obj))
        return obj;

    // Customized serializable object.
    //
    // If the object is not directly serializable, we check if it is customised
    // serializable. That means the developer implemented the public serialization
    // method "toJSONString".
    try {
        Method m = obj.getClass().getMethod("toJSONString", new Class<?>[0]);
        String jsonStr = (String) (m.invoke(obj, new Object[0]));
        if (jsonStr.trim().charAt(0) == '[') {
            return new JSONArray(jsonStr);
        } else {
            return new JSONObject(jsonStr);
        }
    } catch (Exception e) {
        Log.w(TAG, "No serialization method: \"toJSONString\", or errors happened.");
    }

    /*
     * For ordinary objects, we will just serialize the accessible fields.
     */
    try {
        Class<?> c = obj.getClass();
        JSONObject json = new JSONObject();
        Field[] fields = c.getFields();
        for (Field f : fields) {
            json.put(f.getName(), f.get(obj));
        }
        return json;
    } catch (Exception e) {
        Log.e(TAG, "Field to serialize object to JSON.");
        e.printStackTrace();
        return null;
    }
}