Example usage for android.util Log isLoggable

List of usage examples for android.util Log isLoggable

Introduction

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

Prototype

public static native boolean isLoggable(String tag, int level);

Source Link

Document

Checks to see whether or not a log for the specified tag is loggable at the specified level.

Usage

From source file:com.icenler.lib.view.support.percentlayout.PercentLayoutHelper.java

private void invokeMethod(String methodName, int widthHint, int heightHint, View view, Class clazz,
        PercentLayoutInfo.PercentVal percentVal)
        throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
    if (Log.isLoggable(TAG, Log.DEBUG))
        Log.d(TAG, methodName + " ==> " + percentVal);
    if (percentVal != null) {
        Method setMaxWidthMethod = clazz.getMethod(methodName, int.class);
        setMaxWidthMethod.setAccessible(true);
        int base = percentVal.isBaseWidth ? widthHint : heightHint;
        setMaxWidthMethod.invoke(view, (int) (base * percentVal.percent));
    }/*from   w ww .j av a 2 s .co m*/
}

From source file:com.binomed.showtime.android.util.localisation.LocationUtils.java

public static void unRegisterListener(Context context, ProviderEnum provider, LocalisationManagement listener) {
    switch (provider) {
    case GPS_PROVIDER:
    case GSM_PROVIDER: {
        LocationManager locationManager = getLocationManager(context);
        if (locationManager != null) {
            locationManager.removeUpdates(listener);
        } else {// w w  w .  java 2 s .  c  o  m
            if (Log.isLoggable(TAG, Log.DEBUG)) {
                Log.d(TAG, "No listener Put"); //$NON-NLS-1$
            }
        }
        break;
    }
    case WIFI_PROVIDER:
    case XPS_PROVIDER: {
        XPS xps = listener.getXps();
        if (xps != null) {
            xps.abort();
        }
        break;
    }
    default:
        break;
    }
}

From source file:com.magicmod.mmweather.engine.YahooWeatherProvider.java

private JSONObject fetchResults(String url) {
    String response = HttpRetriever.retrieve(url);
    if (response == null) {
        return null;
    }//from w w  w  . j a va  2s . c om

    if (Log.isLoggable(TAG, Log.VERBOSE)) {
        Log.v(TAG, "Request URL is " + url + ", response is " + response);
    }

    try {
        JSONObject rootObject = new JSONObject(response);
        return rootObject.getJSONObject("query").getJSONObject("results");
    } catch (JSONException e) {
        Log.w(TAG, "Received malformed places data (url=" + url + ")", e);
    }

    return null;
}

From source file:mobisocial.musubi.util.UriImage.java

/**
 * Returns the bytes for this UriImage. If the uri for the image is remote,
 * then this code must not be run on the main thread.
 *///w w w . j  a  v a  2s  . c  o  m
public byte[] getResizedImageData(int widthLimit, int heightLimit, int byteLimit, boolean square)
        throws IOException {
    if (!mDecodedBounds) {
        decodeBoundsInfo();
        mDecodedBounds = true;
    }
    InputStream input = null;
    try {
        int inDensity = 0;
        int targetDensity = 0;
        BitmapFactory.Options read_options = new BitmapFactory.Options();
        read_options.inJustDecodeBounds = true;
        input = openInputStream(mUri);
        BitmapFactory.decodeStream(input, null, read_options);
        if (read_options.outWidth > widthLimit || read_options.outHeight > heightLimit) {
            //we need to scale
            if (read_options.outWidth / widthLimit > read_options.outHeight / heightLimit) {
                //width is the large edge
                if (read_options.outWidth * heightLimit > widthLimit * read_options.outHeight) {
                    //incoming image is wider than target
                    inDensity = read_options.outWidth;
                    targetDensity = widthLimit;
                } else {
                    //incoming image is taller than target
                    inDensity = read_options.outHeight;
                    targetDensity = heightLimit;

                }
            } else {
                //height is the long edge, swap the limits
                if (read_options.outWidth * widthLimit > heightLimit * read_options.outHeight) {
                    //incoming image is wider than target
                    inDensity = read_options.outWidth;
                    targetDensity = heightLimit;
                } else {
                    //incoming image is taller than target
                    inDensity = read_options.outHeight;
                    targetDensity = widthLimit;

                }
            }
        } else {
            //no scale
            if (read_options.outWidth > read_options.outHeight) {
                inDensity = targetDensity = read_options.outWidth;
            } else {
                inDensity = targetDensity = read_options.outHeight;
            }
        }

        if (Log.isLoggable(TAG, Log.VERBOSE)) {
            Log.v(TAG,
                    "getResizedImageData: wlimit=" + widthLimit + ", hlimit=" + heightLimit + ", sizeLimit="
                            + byteLimit + ", mWidth=" + mWidth + ", mHeight=" + mHeight + ", initialRatio="
                            + targetDensity + "/" + inDensity);
        }

        ByteArrayOutputStream os = null;
        int attempts = 1;

        int lowMemoryReduce = 1;
        do {
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inDensity = inDensity;
            options.inSampleSize = lowMemoryReduce;
            options.inScaled = lowMemoryReduce == 1;
            options.inTargetDensity = targetDensity;
            //no purgeable because we are only trying to resave this
            if (input != null)
                input.close();
            input = openInputStream(mUri);
            int quality = IMAGE_COMPRESSION_QUALITY;
            try {
                Bitmap b = BitmapFactory.decodeStream(input, null, options);
                if (b == null) {
                    return null;
                }
                if (options.outWidth > widthLimit + 1 || options.outHeight > heightLimit + 1) {
                    // The decoder does not support the inSampleSize option.
                    // Scale the bitmap using Bitmap library.
                    int scaledWidth;
                    int scaledHeight;
                    scaledWidth = options.outWidth * targetDensity / inDensity;
                    scaledHeight = options.outHeight * targetDensity / inDensity;

                    if (Log.isLoggable(TAG, Log.VERBOSE)) {
                        Log.v(TAG, "getResizedImageData: retry scaling using " + "Bitmap.createScaledBitmap: w="
                                + scaledWidth + ", h=" + scaledHeight);
                    }

                    if (square) {
                        int w = b.getWidth();
                        int h = b.getHeight();
                        int dim = Math.min(w, h);
                        b = Bitmap.createBitmap(b, (w - dim) / 2, (h - dim) / 2, dim, dim);
                        scaledWidth = dim;
                        scaledHeight = dim;
                    }
                    Bitmap b2 = Bitmap.createScaledBitmap(b, scaledWidth, scaledHeight, false);
                    b.recycle();
                    b = b2;
                    if (b == null) {
                        return null;
                    }
                }

                Matrix matrix = new Matrix();
                if (mRotation != 0f) {
                    matrix.preRotate(mRotation);
                }

                Bitmap old = b;
                b = Bitmap.createBitmap(old, 0, 0, old.getWidth(), old.getHeight(), matrix, true);

                // Compress the image into a JPG. Start with MessageUtils.IMAGE_COMPRESSION_QUALITY.
                // In case that the image byte size is still too large reduce the quality in
                // proportion to the desired byte size. Should the quality fall below
                // MINIMUM_IMAGE_COMPRESSION_QUALITY skip a compression attempt and we will enter
                // the next round with a smaller image to start with.
                os = new ByteArrayOutputStream();
                b.compress(CompressFormat.JPEG, quality, os);
                int jpgFileSize = os.size();
                if (jpgFileSize > byteLimit) {
                    int reducedQuality = quality * byteLimit / jpgFileSize;
                    //always try to squish it before computing the new size
                    if (reducedQuality < MINIMUM_IMAGE_COMPRESSION_QUALITY) {
                        reducedQuality = MINIMUM_IMAGE_COMPRESSION_QUALITY;
                    }
                    quality = reducedQuality;

                    if (Log.isLoggable(TAG, Log.VERBOSE)) {
                        Log.v(TAG, "getResizedImageData: compress(2) w/ quality=" + quality);
                    }

                    os = new ByteArrayOutputStream();
                    b.compress(CompressFormat.JPEG, quality, os);
                }
                b.recycle(); // done with the bitmap, release the memory
            } catch (java.lang.OutOfMemoryError e) {
                Log.w(TAG, "getResizedImageData - image too big (OutOfMemoryError), will try "
                        + " with smaller scale factor, cur scale factor", e);
                lowMemoryReduce *= 2;
                // fall through and keep trying with a smaller scale factor.
            }
            if (true || Log.isLoggable(TAG, Log.VERBOSE)) {
                Log.v(TAG,
                        "attempt=" + attempts + " size=" + (os == null ? 0 : os.size()) + " width="
                                + options.outWidth + " height=" + options.outHeight + " Ratio=" + targetDensity
                                + "/" + inDensity + " quality=" + quality);
            }
            //move halfway to the target
            targetDensity = (os == null) ? (int) (targetDensity * .8)
                    : (targetDensity * byteLimit / os.size() + targetDensity) / 2;
            attempts++;
        } while ((os == null || os.size() > byteLimit) && attempts < NUMBER_OF_RESIZE_ATTEMPTS);

        return os == null ? null : os.toByteArray();
    } catch (Throwable t) {
        Log.e(TAG, t.getMessage(), t);
        return null;
    } finally {
        if (input != null) {
            try {
                input.close();
            } catch (IOException e) {
                Log.e(TAG, e.getMessage(), e);
            }
        }
    }
}

From source file:com.android.mms.ui.ConversationListItem.java

public void onUpdate(Contact updated) {
    if (Log.isLoggable(LogTag.CONTACT, Log.DEBUG)) {
        Log.v(TAG, "onUpdate: " + this + " contact: " + updated);
    }/* w  ww  . j a  va2  s  .  c  o  m*/
    mHandler.post(new Runnable() {
        public void run() {
            updateFromView();
        }
    });
}

From source file:cm.confide.ex.chips.RecipientAlternatesAdapter.java

private static HashMap<String, RecipientEntry> processContactEntries(Cursor c) {
    HashMap<String, RecipientEntry> recipientEntries = new HashMap<String, RecipientEntry>();
    if (c != null && c.moveToFirst()) {
        do {/*from w w w. j  a  v a 2 s  .c  om*/
            String address = c.getString(Queries.Query.DESTINATION);

            final RecipientEntry newRecipientEntry = RecipientEntry.constructTopLevelEntry(
                    c.getString(Queries.Query.NAME), c.getInt(Queries.Query.DISPLAY_NAME_SOURCE),
                    c.getString(Queries.Query.DESTINATION), c.getInt(Queries.Query.DESTINATION_TYPE),
                    c.getString(Queries.Query.DESTINATION_LABEL), c.getLong(Queries.Query.CONTACT_ID),
                    c.getLong(Queries.Query.DATA_ID), c.getString(Queries.Query.PHOTO_THUMBNAIL_URI), true,
                    false /* isGalContact TODO(skennedy) We should look these up eventually */);

            /*
             * In certain situations, we may have two results for one address, where one of the
             * results is just the email address, and the other has a name and photo, so we want
             * to use the better one.
             */
            final RecipientEntry recipientEntry = getBetterRecipient(recipientEntries.get(address),
                    newRecipientEntry);

            recipientEntries.put(address, recipientEntry);
            if (Log.isLoggable(TAG, Log.DEBUG)) {
                Log.d(TAG,
                        "Received reverse look up information for " + address + " RESULTS: " + " NAME : "
                                + c.getString(Queries.Query.NAME) + " CONTACT ID : "
                                + c.getLong(Queries.Query.CONTACT_ID) + " ADDRESS :"
                                + c.getString(Queries.Query.DESTINATION));
            }
        } while (c.moveToNext());
    }
    return recipientEntries;
}

From source file:com.android.calendar.alerts.AlarmScheduler.java

/**
 * Queries for all the reminders of the events in the instancesCursor, and schedules
 * the alarm for the next upcoming reminder.
 *//*  www. j a  v  a2s  . c  o m*/
private static void queryNextReminderAndSchedule(Cursor instancesCursor, Context context,
        ContentResolver contentResolver, AlarmManagerInterface alarmManager, int batchSize,
        long currentMillis) {
    if (AlertService.DEBUG) {
        int eventCount = instancesCursor.getCount();
        if (eventCount == 0) {
            Log.d(TAG, "No events found starting within 1 week.");
        } else {
            Log.d(TAG, "Query result count for events starting within 1 week: " + eventCount);
        }
    }

    // Put query results of all events starting within some interval into map of event ID to
    // local start time.
    Map<Integer, List<Long>> eventMap = new HashMap<Integer, List<Long>>();
    Time timeObj = new Time();
    long nextAlarmTime = Long.MAX_VALUE;
    int nextAlarmEventId = 0;
    instancesCursor.moveToPosition(-1);
    while (!instancesCursor.isAfterLast()) {
        int index = 0;
        eventMap.clear();
        StringBuilder eventIdsForQuery = new StringBuilder();
        eventIdsForQuery.append('(');
        while (index++ < batchSize && instancesCursor.moveToNext()) {
            int eventId = instancesCursor.getInt(INSTANCES_INDEX_EVENTID);
            long begin = instancesCursor.getLong(INSTANCES_INDEX_BEGIN);
            boolean allday = instancesCursor.getInt(INSTANCES_INDEX_ALL_DAY) != 0;
            long localStartTime;
            if (allday) {
                // Adjust allday to local time.
                localStartTime = Utils.convertAlldayUtcToLocal(timeObj, begin, Time.getCurrentTimezone());
            } else {
                localStartTime = begin;
            }
            List<Long> startTimes = eventMap.get(eventId);
            if (startTimes == null) {
                startTimes = new ArrayList<Long>();
                eventMap.put(eventId, startTimes);
                eventIdsForQuery.append(eventId);
                eventIdsForQuery.append(",");
            }
            startTimes.add(localStartTime);

            // Log for debugging.
            if (Log.isLoggable(TAG, Log.DEBUG)) {
                timeObj.set(localStartTime);
                StringBuilder msg = new StringBuilder();
                msg.append("Events cursor result -- eventId:").append(eventId);
                msg.append(", allDay:").append(allday);
                msg.append(", start:").append(localStartTime);
                msg.append(" (").append(timeObj.format("%a, %b %d, %Y %I:%M%P")).append(")");
                Log.d(TAG, msg.toString());
            }
        }
        if (eventIdsForQuery.charAt(eventIdsForQuery.length() - 1) == ',') {
            eventIdsForQuery.deleteCharAt(eventIdsForQuery.length() - 1);
        }
        eventIdsForQuery.append(')');

        // Query the reminders table for the events found.
        Cursor cursor = null;
        try {
            cursor = contentResolver.query(Reminders.CONTENT_URI, REMINDERS_PROJECTION,
                    REMINDERS_WHERE + eventIdsForQuery, null, null);

            // Process the reminders query results to find the next reminder time.
            cursor.moveToPosition(-1);
            while (cursor.moveToNext()) {
                int eventId = cursor.getInt(REMINDERS_INDEX_EVENT_ID);
                int reminderMinutes = cursor.getInt(REMINDERS_INDEX_MINUTES);
                List<Long> startTimes = eventMap.get(eventId);
                if (startTimes != null) {
                    for (Long startTime : startTimes) {
                        long alarmTime = startTime - reminderMinutes * DateUtils.MINUTE_IN_MILLIS;
                        if (alarmTime > currentMillis && alarmTime < nextAlarmTime) {
                            nextAlarmTime = alarmTime;
                            nextAlarmEventId = eventId;
                        }

                        if (Log.isLoggable(TAG, Log.DEBUG)) {
                            timeObj.set(alarmTime);
                            StringBuilder msg = new StringBuilder();
                            msg.append("Reminders cursor result -- eventId:").append(eventId);
                            msg.append(", startTime:").append(startTime);
                            msg.append(", minutes:").append(reminderMinutes);
                            msg.append(", alarmTime:").append(alarmTime);
                            msg.append(" (").append(timeObj.format("%a, %b %d, %Y %I:%M%P")).append(")");
                            Log.d(TAG, msg.toString());
                        }
                    }
                }
            }
        } finally {
            if (cursor != null) {
                cursor.close();
            }
        }
    }

    // Schedule the alarm for the next reminder time.
    if (nextAlarmTime < Long.MAX_VALUE) {
        scheduleAlarm(context, nextAlarmEventId, nextAlarmTime, currentMillis, alarmManager);
    }
}

From source file:com.android.car.trust.CarBleTrustAgent.java

private void unlock(byte[] token, long handle) {
    UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);

    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG, "About to unlock user. Current handle: " + handle + " Time: " + System.currentTimeMillis());
    }/*  w ww .j  av a2 s. c  o m*/
    unlockUserWithToken(handle, token, getCurrentUserHandle());

    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG, "Attempted to unlock user, is user unlocked? " + um.isUserUnlocked() + " Time: "
                + System.currentTimeMillis());
    }
    setManagingTrust(true);

    if (um.isUserUnlocked()) {
        if (Log.isLoggable(TAG, Log.DEBUG)) {
            Log.d(TAG, getString(R.string.trust_granted_explanation));
        }
        grantTrust("Granting trust from escrow token", TRUST_DURATION_MS, FLAG_GRANT_TRUST_DISMISS_KEYGUARD);
        // Trust has been granted, disable the BLE server. This trust agent service does
        // not need to receive additional BLE data.
        unbindService(mServiceConnection);
    }
}

From source file:com.example.android.wearable.agendadata.MainActivity.java

@Override
public void onConnected(Bundle connectionHint) {
    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG, "Connected to Google Api Service.");
    }//from www.  ja v a2  s .c  o  m
    mResolvingError = false;
}

From source file:com.taxicop.client.NetworkUtilities.java

public static String authenticate(String username, String password, String country, Handler handler,
        final Context context) {
    final HttpResponse resp;
    final ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair(PARAM_USERNAME, username));
    params.add(new BasicNameValuePair(PARAM_PASSWORD, password));
    params.add(new BasicNameValuePair(PARAM_COUNTRY, country));
    HttpEntity entity = null;/*from  w  ww  .  j av  a  2 s.c  o  m*/
    try {
        entity = new UrlEncodedFormEntity(params);
    } catch (final UnsupportedEncodingException e) {
        throw new AssertionError(e);
    }
    final HttpPost post = new HttpPost(BASE_URL + URL + AUTH_URI);
    Log.d(TAG, "URI= " + (BASE_URL + URL + AUTH_URI));
    post.addHeader(entity.getContentType());
    post.setEntity(entity);
    CreateHttpClient();
    Log.i(TAG, "authenticate(): obtencion de autenticacion. ");

    try {
        resp = mHttpClient.execute(post);
        ByteArrayOutputStream outstream = new ByteArrayOutputStream();
        resp.getEntity().writeTo(outstream);
        byte[] responseBody = outstream.toByteArray();
        String response = new String(responseBody);
        //         response = response.replaceAll("Status: 200", "")
        //               .replaceAll("OK", "")
        //               .replaceAll("Content\\-Type: text\\/html", "")
        //               .replaceAll("charset=utf\\-8", "")
        //               .replaceAll(";", "")
        //               .replaceAll("\\\n", "").trim();

        Log.i(TAG, "authenticate(): respuesta obtenida del servidor. response=" + response);
        if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
            if (Log.isLoggable(TAG, Log.VERBOSE)) {
                Log.v(TAG, "Successful authentication");
            }
            sendResult(true, handler, context);
            return response;
        } else {
            if (Log.isLoggable(TAG, Log.VERBOSE)) {
                Log.v(TAG, "Error authenticating" + resp.getStatusLine());
            }
            sendResult(false, handler, context);
            return response;
        }
    } catch (final IOException e) {
        if (Log.isLoggable(TAG, Log.VERBOSE)) {
            Log.v(TAG, "IOException when getting authtoken", e);
        }
        sendResult(false, handler, context);
        return null;
    } finally {
        if (Log.isLoggable(TAG, Log.VERBOSE)) {
            Log.v(TAG, "getAuthtoken completing");
        }
    }
}