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: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("SU", "Unable to create external cache directory");
            return null;
        }//from w  ww  .  j a  v a  2s. com
        try {
            new File(appCacheDir, ".nomedia").createNewFile();
        } catch (IOException e) {
            Log.w("SU", "Can't create \".nomedia\" file in application external cache directory");
        }
    }
    return appCacheDir;
}

From source file:Main.java

public static String toAppPath(String fullpath) {
    String path = getOdkFolder() + File.separator;
    if (fullpath.startsWith(path)) {
        String partialPath = fullpath.substring(path.length());
        String[] app = partialPath.split(File.separator);
        if (app == null || app.length < 1) {
            Log.w(t, "Missing file path (nothing under '" + ODK_FOLDER_NAME + "'): " + fullpath);
            return null;
        }//  w ww. j  a v a 2  s . c  o  m
        return partialPath;
    } else {

        String[] parts = fullpath.split(File.separator);
        int i = 0;
        while (parts.length > i && !parts[i].equals(ODK_FOLDER_NAME)) {
            ++i;
        }
        if (i == parts.length) {
            Log.w(t, "File path is not under expected '" + ODK_FOLDER_NAME + "' Folder (" + path
                    + ") conversion failed for: " + fullpath);
            return null;
        }
        int len = 0; // trailing slash
        while (i >= 0) {
            len += parts[i].length() + 1;
            --i;
        }

        String partialPath = fullpath.substring(len);
        String[] app = partialPath.split(File.separator);
        if (app == null || app.length < 1) {
            Log.w(t, "File path is not under expected '" + ODK_FOLDER_NAME + "' Folder (" + path
                    + ") missing file path (nothing under '" + ODK_FOLDER_NAME + "'): " + fullpath);
            return null;
        }

        Log.w(t, "File path is not under expected '" + ODK_FOLDER_NAME + "' Folder -- remapped " + fullpath
                + " as: " + path + partialPath);
        return partialPath;
    }
}

From source file:Main.java

public static Point findBestPreviewSizeValue(Camera.Parameters parameters, Point screenResolution) {

    List<Camera.Size> rawSupportedSizes = parameters.getSupportedPreviewSizes();
    if (rawSupportedSizes == null) {
        Log.w(TAG, "Device returned no supported preview sizes; using default");
        Camera.Size defaultSize = parameters.getPreviewSize();
        if (defaultSize == null) {
            throw new IllegalStateException("Parameters contained no preview size!");
        }/*from   w w w .ja  v  a 2  s .  c om*/
        return new Point(defaultSize.width, defaultSize.height);
    }

    if (Log.isLoggable(TAG, Log.INFO)) {
        StringBuilder previewSizesString = new StringBuilder();
        for (Camera.Size size : rawSupportedSizes) {
            previewSizesString.append(size.width).append('x').append(size.height).append(' ');
        }
        Log.i(TAG, "Supported preview sizes: " + previewSizesString);
    }

    double screenAspectRatio = screenResolution.x / (double) screenResolution.y;

    // Find a suitable size, with max resolution
    int maxResolution = 0;
    Camera.Size maxResPreviewSize = null;
    for (Camera.Size size : rawSupportedSizes) {
        int realWidth = size.width;
        int realHeight = size.height;
        int resolution = realWidth * realHeight;
        if (resolution < MIN_PREVIEW_PIXELS) {
            continue;
        }

        boolean isCandidatePortrait = realWidth < realHeight;
        int maybeFlippedWidth = isCandidatePortrait ? realHeight : realWidth;
        int maybeFlippedHeight = isCandidatePortrait ? realWidth : realHeight;
        double aspectRatio = maybeFlippedWidth / (double) maybeFlippedHeight;
        double distortion = Math.abs(aspectRatio - screenAspectRatio);
        if (distortion > MAX_ASPECT_DISTORTION) {
            continue;
        }

        if (maybeFlippedWidth == screenResolution.x && maybeFlippedHeight == screenResolution.y) {
            Point exactPoint = new Point(realWidth, realHeight);
            Log.i(TAG, "Found preview size exactly matching screen size: " + exactPoint);
            return exactPoint;
        }

        // Resolution is suitable; record the one with max resolution
        if (resolution > maxResolution) {
            maxResolution = resolution;
            maxResPreviewSize = size;
        }
    }

    // If no exact match, use largest preview 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 (maxResPreviewSize != null) {
        Point largestSize = new Point(maxResPreviewSize.width, maxResPreviewSize.height);
        Log.i(TAG, "Using largest suitable preview size: " + largestSize);
        return largestSize;
    }

    // If there is nothing at all suitable, return current preview size
    Camera.Size defaultPreview = parameters.getPreviewSize();
    if (defaultPreview == null) {
        throw new IllegalStateException("Parameters contained no preview size!");
    }
    Point defaultSize = new Point(defaultPreview.width, defaultPreview.height);
    Log.i(TAG, "No suitable preview sizes, using default: " + defaultSize);
    return defaultSize;
}

From source file:com.arellomobile.android.push.DeviceFeature2_5.java

static void sendPushStat(Context context, String hash) {
    final Map<String, Object> data = new HashMap<String, Object>();

    data.putAll(RequestHelper.getSendPushStatData(context, hash, NetworkUtils.PUSH_VERSION));

    Log.w(TAG, "Try To sent PushStat");

    NetworkUtils.NetworkResult res = new NetworkUtils.NetworkResult(-1, null);
    Exception exception = new Exception();
    for (int i = 0; i < NetworkUtils.MAX_TRIES; ++i) {
        try {//from www . j  ava2  s .c  o  m
            res = NetworkUtils.makeRequest(data, PUSH_STAT);
            if (200 == res.getResultCode()) {
                Log.w(TAG, "Send PushStat success");
                return;
            }
        } catch (Exception e) {
            exception = e;
        }
    }

    Log.e(TAG, "ERROR: Try To sent PushStat " + exception.getMessage() + ". Response = " + res.getResultData(),
            exception);
}

From source file:Main.java

/**
 * @return the version name of the application
 *//*  w  w w .j ava2 s .c o  m*/
public static String getVersionName(Context context) {
    String versionName = "unknown version";
    try {
        PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
        versionName = packageInfo.versionName;
    } catch (PackageManager.NameNotFoundException e) {
        Log.w(TAG, e);
    }
    return versionName;
}

From source file:Main.java

/**
 * Loads a texture from a resource ID, returning the OpenGL ID for that
 * texture. Returns 0 if the load failed.
 * //w  w  w.ja  v a  2s  . c  o  m
 * @param context
 * @param resourceId
 * @return
 */
public static int loadTexture(Context context, int resourceId) {
    final int[] textureObjectIds = new int[1];
    glGenTextures(1, textureObjectIds, 0);

    if (textureObjectIds[0] == 0) {
        Log.w(TAG, "Could not generate a new OpenGL texture object.");
        return 0;
    }

    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inScaled = false;

    // Read in the resource
    final Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), resourceId, options);

    if (bitmap == null) {
        Log.w(TAG, "Resource ID " + resourceId + " could not be decoded.");
        glDeleteTextures(1, textureObjectIds, 0);
        return 0;
    }

    // Bind to the texture in OpenGL
    glBindTexture(GL_TEXTURE_2D, textureObjectIds[0]);

    // Set filtering: a default must be set, or the texture will be
    // black.
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    // Load the bitmap into the bound texture.
    texImage2D(GL_TEXTURE_2D, 0, bitmap, 0);

    // Note: Following code may cause an error to be reported in the
    // ADB log as follows: E/IMGSRV(20095): :0: HardwareMipGen:
    // Failed to generate texture mipmap levels (error=3)
    // No OpenGL error will be encountered (glGetError() will return
    // 0). If this happens, just squash the source image to be
    // square. It will look the same because of texture coordinates,
    // and mipmap generation will work.

    glGenerateMipmap(GL_TEXTURE_2D);

    // Recycle the bitmap, since its data has been loaded into
    // OpenGL.
    bitmap.recycle();

    // Unbind from the texture.
    glBindTexture(GL_TEXTURE_2D, 0);

    return textureObjectIds[0];
}

From source file:Main.java

/**
 * Get the application version code./*from  w  w  w .  j ava  2  s .  co  m*/
 * @param context The current context.
 * @return The application version code.
 */
public static int getApplicationVersionCode(Context context) {

    int result = -1;

    try {

        PackageManager manager = context.getPackageManager();
        PackageInfo info = manager.getPackageInfo(context.getPackageName(), 0);

        result = info.versionCode;

    } catch (NameNotFoundException e) {
        Log.w("ApplicationUtils", "Unable to get application version: " + e.getMessage());
        result = -1;
    }

    return result;
}

From source file:Main.java

public static Point findBestPreviewSizeValue(Camera.Parameters parameters, Point screenResolution) {

    List<Camera.Size> rawSupportedSizes = parameters.getSupportedPreviewSizes();
    if (rawSupportedSizes == null) {
        Log.w(TAG, "Device returned no supported preview sizes; using default");
        Camera.Size defaultSize = parameters.getPreviewSize();
        if (defaultSize == null) {
            throw new IllegalStateException("Parameters contained no preview size!");
        }// w w  w .  ja v  a2  s  . com
        return new Point(defaultSize.width, defaultSize.height);
    }

    // Sort by size, descending
    List<Camera.Size> supportedPreviewSizes = new ArrayList<Camera.Size>(rawSupportedSizes);
    Collections.sort(supportedPreviewSizes, 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 previewSizesString = new StringBuilder();
        for (Camera.Size supportedPreviewSize : supportedPreviewSizes) {
            previewSizesString.append(supportedPreviewSize.width).append('x')
                    .append(supportedPreviewSize.height).append(' ');
        }
        Log.i(TAG, "Supported preview sizes: " + previewSizesString);
    }

    double screenAspectRatio = (double) screenResolution.x / (double) screenResolution.y;

    // Remove sizes that are unsuitable
    Iterator<Camera.Size> it = supportedPreviewSizes.iterator();
    while (it.hasNext()) {
        Camera.Size supportedPreviewSize = it.next();
        int realWidth = supportedPreviewSize.width;
        int realHeight = supportedPreviewSize.height;
        if (realWidth * realHeight < MIN_PREVIEW_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 preview size exactly matching screen size: " + exactPoint);
            return exactPoint;
        }
    }

    // If no exact match, use largest preview 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 (!supportedPreviewSizes.isEmpty()) {
        Camera.Size largestPreview = supportedPreviewSizes.get(0);
        Point largestSize = new Point(largestPreview.width, largestPreview.height);
        Log.i(TAG, "Using largest suitable preview size: " + largestSize);
        return largestSize;
    }

    // If there is nothing at all suitable, return current preview size
    Camera.Size defaultPreview = parameters.getPreviewSize();
    if (defaultPreview == null) {
        throw new IllegalStateException("Parameters contained no preview size!");
    }
    Point defaultSize = new Point(defaultPreview.width, defaultPreview.height);
    Log.i(TAG, "No suitable preview sizes, using default: " + defaultSize);
    return defaultSize;
}

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;
        }//w  w w  .j  a  v  a2s  . c  om
        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 String getAppMetadata(Context context, String key) {
    String strValue = "";
    try {//from w  w  w.  java2 s .  c o m
        PackageManager mgr = context.getPackageManager();
        Bundle bundle = mgr.getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA).metaData;
        //Bundle bundle = context.getApplicationInfo().metaData;
        if (bundle != null && bundle.containsKey(key)) {
            strValue = bundle.getString(key);
        }
    } catch (Exception e) {
        Log.w(LOG_TAG, e);
    }

    return strValue;
}