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.kth.common.utils.etc.LogUtil.java

/**
 * ERROR  ? ?  ?.
 */
public static boolean isErrorEnabled() {
    return Log.isLoggable(TAG, Log.ERROR);
}

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

private static PercentLayoutInfo setMarginRelatedVal(TypedArray array, PercentLayoutInfo info) {
    //margin?//from   w  w  w . j  a va2 s .  c  om
    PercentLayoutInfo.PercentVal percentVal = getPercentVal(array,
            com.zhy.android.percent.support.R.styleable.PercentLayout_Layout_layout_marginPercent, true);

    if (percentVal != null) {
        if (Log.isLoggable(TAG, Log.VERBOSE)) {
            Log.v(TAG, "percent margin: " + percentVal.percent);
        }
        info = checkForInfoExists(info);
        info.leftMarginPercent = percentVal;
        info.topMarginPercent = percentVal;
        info.rightMarginPercent = percentVal;
        info.bottomMarginPercent = percentVal;
    }

    percentVal = getPercentVal(array,
            com.zhy.android.percent.support.R.styleable.PercentLayout_Layout_layout_marginLeftPercent, true);
    if (percentVal != null) {
        if (Log.isLoggable(TAG, Log.VERBOSE)) {
            Log.v(TAG, "percent left margin: " + percentVal.percent);
        }
        info = checkForInfoExists(info);
        info.leftMarginPercent = percentVal;
    }

    percentVal = getPercentVal(array,
            com.zhy.android.percent.support.R.styleable.PercentLayout_Layout_layout_marginTopPercent, false);
    if (percentVal != null) {
        if (Log.isLoggable(TAG, Log.VERBOSE)) {
            Log.v(TAG, "percent top margin: " + percentVal.percent);
        }
        info = checkForInfoExists(info);
        info.topMarginPercent = percentVal;
    }

    percentVal = getPercentVal(array,
            com.zhy.android.percent.support.R.styleable.PercentLayout_Layout_layout_marginRightPercent, true);
    if (percentVal != null) {
        if (Log.isLoggable(TAG, Log.VERBOSE)) {
            Log.v(TAG, "percent right margin: " + percentVal.percent);
        }
        info = checkForInfoExists(info);
        info.rightMarginPercent = percentVal;
    }

    percentVal = getPercentVal(array,
            com.zhy.android.percent.support.R.styleable.PercentLayout_Layout_layout_marginBottomPercent, false);
    if (percentVal != null) {
        if (Log.isLoggable(TAG, Log.VERBOSE)) {
            Log.v(TAG, "percent bottom margin: " + percentVal.percent);
        }
        info = checkForInfoExists(info);
        info.bottomMarginPercent = percentVal;
    }
    percentVal = getPercentVal(array,
            com.zhy.android.percent.support.R.styleable.PercentLayout_Layout_layout_marginStartPercent, true);
    if (percentVal != null) {
        if (Log.isLoggable(TAG, Log.VERBOSE)) {
            Log.v(TAG, "percent start margin: " + percentVal.percent);
        }
        info = checkForInfoExists(info);
        info.startMarginPercent = percentVal;
    }

    percentVal = getPercentVal(array,
            com.zhy.android.percent.support.R.styleable.PercentLayout_Layout_layout_marginEndPercent, true);
    if (percentVal != null) {
        if (Log.isLoggable(TAG, Log.VERBOSE)) {
            Log.v(TAG, "percent end margin: " + percentVal.percent);
        }
        info = checkForInfoExists(info);
        info.endMarginPercent = percentVal;
    }

    return info;
}

From source file:com.android.calendar.month.MonthByWeekFragment.java

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    if (mIsMiniMonth) {
        return null;
    }//from   w ww . j  a  va 2 s .c  om
    CursorLoader loader;
    synchronized (mUpdateLoader) {
        mFirstLoadedJulianDay = Time.getJulianDay(mSelectedDay.toMillis(true), mSelectedDay.gmtoff)
                - (mNumWeeks * 7 / 2);
        mEventUri = updateUri();
        String where = updateWhere();

        loader = new CursorLoader(getActivity(), mEventUri, Event.EVENT_PROJECTION, where,
                null /* WHERE_CALENDARS_SELECTED_ARGS */, INSTANCES_SORT_ORDER);
        loader.setUpdateThrottle(LOADER_THROTTLE_DELAY);
    }
    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG, "Returning new loader with uri: " + mEventUri);
    }
    return loader;
}

From source file:com.example.android.wearable.speedtracker.WearableMainActivity.java

private void requestLocation() {
    Log.d(TAG, "requestLocation()");

    /*//from w w  w  . j  a  va2s. c  o  m
     * mGpsPermissionApproved covers 23+ (M+) style permissions. If that is already approved or
     * the device is pre-23, the app uses mSaveGpsLocation to save the user's location
     * preference.
     */
    if (mGpsPermissionApproved) {

        LocationRequest locationRequest = LocationRequest.create()
                .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY).setInterval(UPDATE_INTERVAL_MS)
                .setFastestInterval(FASTEST_INTERVAL_MS);

        LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, locationRequest, this)
                .setResultCallback(new ResultCallback<Status>() {

                    @Override
                    public void onResult(Status status) {
                        if (status.getStatus().isSuccess()) {
                            if (Log.isLoggable(TAG, Log.DEBUG)) {
                                Log.d(TAG, "Successfully requested location updates");
                            }
                        } else {
                            Log.e(TAG, "Failed in requesting location updates, " + "status code: "
                                    + status.getStatusCode() + ", message: " + status.getStatusMessage());
                        }
                    }
                });
    }
}

From source file:com.google.android.dialer.provider.DialerProvider.java

private Location getLastLocation() {
    LocationManager locationManager = (LocationManager) getContext().getSystemService(Context.LOCATION_SERVICE);
    locationManager.requestSingleUpdate(new Criteria(), new LocationListener() {
        @Override//from  w ww .j  a v a  2s. com
        public void onLocationChanged(Location location) {
            if (Log.isLoggable("DialerProvider", Log.VERBOSE)) {
                Log.v("DialerProvider", "onLocationChanged: " + location);
            }
        }

        @Override
        public void onProviderDisabled(String provider) {
            if (Log.isLoggable("DialerProvider", Log.VERBOSE)) {
                Log.v("DialerProvider", "onProviderDisabled: " + provider);
            }
        }

        @Override
        public void onProviderEnabled(String provider) {
            if (Log.isLoggable("DialerProvider", Log.VERBOSE)) {
                Log.v("DialerProvider", "onProviderEnabled: " + provider);
            }
        }

        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) {
            if (Log.isLoggable("DialerProvider", Log.VERBOSE)) {
                Log.v("DialerProvider", "onStatusChanged: " + provider + ", " + status + ", " + extras);
            }
        }
    }, DialerProvider.mLooper);
    return locationManager.getLastLocation();
}

From source file:com.android.im.imps.HttpDataChannel.java

private void trySend(Primitive p) throws IOException {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    try {/*from   www.  j ava2s.c o  m*/
        mSerializer.serialize(p, out);
    } catch (SerializerException e) {
        mTxManager.notifyErrorResponse(p.getTransactionID(), ImErrorInfo.SERIALIZER_ERROR,
                "Internal serializer error, primitive: " + p.getType());
        out.close();
        return;
    }

    HttpPost req = new HttpPost(mPostUri);
    req.addHeader(mContentTypeHeader);
    if (mMsisdnHeader != null) {
        req.addHeader(mMsisdnHeader);
    }
    ByteArrayEntity entity = new ByteArrayEntity(out.toByteArray());
    req.setEntity(entity);

    mLastActive = SystemClock.elapsedRealtime();
    if (Log.isLoggable(ImpsLog.TAG, Log.DEBUG)) {
        long sendBytes = entity.getContentLength() + 176 /* approx. header length */;
        ImpsLog.log(mConnection.getLoginUserName() + " >> " + p.getType() + " HTTP payload approx. " + sendBytes
                + " bytes");
    }
    if (Log.isLoggable(ImpsLog.PACKET_TAG, Log.DEBUG)) {
        ImpsLog.dumpRawPacket(out.toByteArray());
        ImpsLog.dumpPrimitive(p);
    }

    HttpResponse res = mHttpClient.execute(req);
    StatusLine statusLine = res.getStatusLine();
    HttpEntity resEntity = res.getEntity();

    InputStream in = resEntity.getContent();

    if (Log.isLoggable(ImpsLog.PACKET_TAG, Log.DEBUG)) {
        Log.d(ImpsLog.PACKET_TAG, statusLine.toString());
        Header[] headers = res.getAllHeaders();
        for (Header h : headers) {
            Log.d(ImpsLog.PACKET_TAG, h.toString());
        }
        int len = (int) resEntity.getContentLength();
        if (len > 0) {
            byte[] content = new byte[len];
            int offset = 0;
            int bytesRead = 0;
            do {
                bytesRead = in.read(content, offset, len);
                offset += bytesRead;
                len -= bytesRead;
            } while (bytesRead > 0);
            in.close();
            ImpsLog.dumpRawPacket(content);
            in = new ByteArrayInputStream(content);
        }
    }

    try {
        if (statusLine.getStatusCode() != HttpURLConnection.HTTP_OK) {
            mTxManager.notifyErrorResponse(p.getTransactionID(), statusLine.getStatusCode(),
                    statusLine.getReasonPhrase());
            return;
        }
        if (resEntity.getContentLength() == 0) {
            // empty responses are only valid for Polling-Request or
            // server initiated transactions
            if ((p.getTransactionMode() != TransactionMode.Response)
                    && !p.getType().equals(ImpsTags.Polling_Request)) {
                mTxManager.notifyErrorResponse(p.getTransactionID(), ImErrorInfo.ILLEGAL_SERVER_RESPONSE,
                        "bad response from server");
            }
            return;
        }

        Primitive response = mParser.parse(in);

        if (Log.isLoggable(ImpsLog.PACKET_TAG, Log.DEBUG)) {
            ImpsLog.dumpPrimitive(response);
        }

        if (Log.isLoggable(ImpsLog.TAG, Log.DEBUG)) {
            long len = 2 + resEntity.getContentLength() + statusLine.toString().length() + 2;
            Header[] headers = res.getAllHeaders();
            for (Header header : headers) {
                len += header.getName().length() + header.getValue().length() + 4;
            }
            ImpsLog.log(mConnection.getLoginUserName() + " << " + response.getType() + " HTTP payload approx. "
                    + len + "bytes");
        }

        if (!mReceiveQueue.offer(response)) {
            // This is almost impossible for a LinkedBlockingQueue.
            // We don't even bother to assign an error code for it.
            mTxManager.notifyErrorResponse(p.getTransactionID(), ImErrorInfo.UNKNOWN_ERROR,
                    "receiving queue full");
        }
    } catch (ParserException e) {
        ImpsLog.logError(e);
        mTxManager.notifyErrorResponse(p.getTransactionID(), ImErrorInfo.PARSER_ERROR,
                "Parser error, received a bad response from server");
    } finally {
        //consume all the content so that the connection can be re-used.
        resEntity.consumeContent();
    }
}

From source file:com.android.contacts.ContactSaveService.java

@Override
protected void onHandleIntent(final Intent intent) {
    if (intent == null) {
        if (Log.isLoggable(TAG, Log.DEBUG)) {
            Log.d(TAG, "onHandleIntent: could not handle null intent");
        }/*from   ww w . j  a v  a 2s  .c o m*/
        return;
    }
    if (!PermissionsUtil.hasPermission(this, WRITE_CONTACTS)) {
        Log.w(TAG, "No WRITE_CONTACTS permission, unable to write to CP2");
        // TODO: add more specific error string such as "Turn on Contacts
        // permission to update your contacts"
        showToast(R.string.contactSavedErrorToast);
        return;
    }

    // Call an appropriate method. If we're sure it affects how incoming phone calls are
    // handled, then notify the fact to in-call screen.
    String action = intent.getAction();
    if (ACTION_NEW_RAW_CONTACT.equals(action)) {
        createRawContact(intent);
    } else if (ACTION_SAVE_CONTACT.equals(action)) {
        saveContact(intent);
    } else if (ACTION_CREATE_GROUP.equals(action)) {
        createGroup(intent);
    } else if (ACTION_RENAME_GROUP.equals(action)) {
        renameGroup(intent);
    } else if (ACTION_DELETE_GROUP.equals(action)) {
        deleteGroup(intent);
    } else if (ACTION_UPDATE_GROUP.equals(action)) {
        updateGroup(intent);
    } else if (ACTION_SET_STARRED.equals(action)) {
        setStarred(intent);
    } else if (ACTION_SET_SUPER_PRIMARY.equals(action)) {
        setSuperPrimary(intent);
    } else if (ACTION_CLEAR_PRIMARY.equals(action)) {
        clearPrimary(intent);
    } else if (ACTION_DELETE_MULTIPLE_CONTACTS.equals(action)) {
        deleteMultipleContacts(intent);
    } else if (ACTION_DELETE_CONTACT.equals(action)) {
        deleteContact(intent);
    } else if (ACTION_SPLIT_CONTACT.equals(action)) {
        splitContact(intent);
    } else if (ACTION_JOIN_CONTACTS.equals(action)) {
        joinContacts(intent);
    } else if (ACTION_JOIN_SEVERAL_CONTACTS.equals(action)) {
        joinSeveralContacts(intent);
    } else if (ACTION_SET_SEND_TO_VOICEMAIL.equals(action)) {
        setSendToVoicemail(intent);
    } else if (ACTION_SET_RINGTONE.equals(action)) {
        setRingtone(intent);
    } else if (ACTION_UNDO.equals(action)) {
        undo(intent);
    } else if (ACTION_SLEEP.equals(action)) {
        sleepForDebugging(intent);
    }

    sState.onFinish(intent);
    notifyStateChanged();
}

From source file:com.samsung.richnotification.RichNotification.java

/**
 * Executes the request and returns PluginResult.
 *
 * @param action/*  ww  w  . j  a  va 2 s . co  m*/
 *            The action to execute.
 * @param data
 *            JSONArray of arguments for the plugin.
 * @param callbackContext
 *            The callback id used when calling back into JavaScript.
 * @return A PluginResult object with a status and message.
 */
@Override
public boolean execute(String action, JSONArray data, CallbackContext callbackContext) throws JSONException {

    if (Log.isLoggable(RICHNOTI, Log.DEBUG))
        Log.d(TAG, "execute(): callbackID - " + callbackContext.getCallbackId());
    mContext = this.cordova.getActivity();

    // Do not allow apis if metadata is missing
    if (!pluginMetadata) {
        callbackContext.error("METADATA_MISSING");
        Log.e(TAG, "Metadata is missing");
        return false;
    }

    if (action.equals("isSupported")) {
        if (isRichNotificationSupported(callbackContext)) {
            callbackContext.success();
            return true;
        }
        return false;
    }

    else if (action.equals("registerEventListeners")) {
        return registerRichNotificationEventListeners(callbackContext);
    }

    else if (action.equals("send")) {
        return sendRichNotification(data, callbackContext);
    }

    else if (action.equals("dismiss")) {
        String uuid = data.getString(0); // There will be just one array-element i.e. the UUID
        return dismissRichNotification(uuid, callbackContext);
    }

    else if (action.equals("isConnected")) {
        // initRichNotification will throw the DEVICE_NOT_CONNECTED error
        if (!initRichNotification(callbackContext)) {
            Log.e(TAG, "Initialization failed.");
            return false;
        } else {
            if (Log.isLoggable(RICHNOTI, Log.DEBUG))
                Log.d(TAG, "Connected to gear");
            callbackContext.success();
            return true;
        }
    }
    return true;
}

From source file:com.android.mms.transaction.MessagingNotification.java

/**
 * Checks to see if there are any "unseen" messages or delivery
 * reports and builds a sorted (by delivery date) list of unread notifications.
 *
 * @param context the context to use/* ww  w. j  a va2 s. c o m*/
 * @param newMsgThreadId The thread ID of a new message that we're to notify about; if there's
 *  no new message, use THREAD_NONE. If we should notify about multiple or unknown thread IDs,
 *  use THREAD_ALL.
 * @param isStatusMessage
 */
public static void blockingUpdateNewMessageIndicator(Context context, long newMsgThreadId,
        boolean isStatusMessage) {
    if (DEBUG) {
        Contact.logWithTrace(TAG, "blockingUpdateNewMessageIndicator: newMsgThreadId: " + newMsgThreadId);
    }
    final boolean isDefaultSmsApp = MmsConfig.isSmsEnabled(context);
    if (!isDefaultSmsApp) {
        cancelNotification(context, NOTIFICATION_ID);
        if (DEBUG || Log.isLoggable(LogTag.APP, Log.VERBOSE)) {
            Log.d(TAG,
                    "blockingUpdateNewMessageIndicator: not the default sms app - skipping " + "notification");
        }
        return;
    }

    // notificationSet is kept sorted by the incoming message delivery time, with the
    // most recent message first.
    SortedSet<NotificationInfo> notificationSet = new TreeSet<NotificationInfo>(INFO_COMPARATOR);

    Set<Long> threads = new HashSet<Long>(4);

    addMmsNotificationInfos(context, threads, notificationSet);
    addSmsNotificationInfos(context, threads, notificationSet);

    if (notificationSet.isEmpty()) {
        if (DEBUG) {
            Log.d(TAG, "blockingUpdateNewMessageIndicator: notificationSet is empty, "
                    + "canceling existing notifications");
        }
        cancelNotification(context, NOTIFICATION_ID);
    } else {
        if (DEBUG || Log.isLoggable(LogTag.APP, Log.VERBOSE)) {
            Log.d(TAG, "blockingUpdateNewMessageIndicator: count=" + notificationSet.size()
                    + ", newMsgThreadId=" + newMsgThreadId);
        }

        if (isInCurrentConversation(newMsgThreadId, threads)) {
            if (DEBUG) {
                Log.d(TAG,
                        "blockingUpdateNewMessageIndicator: newMsgThreadId == "
                                + "sCurrentlyDisplayedThreadId so NOT showing notification,"
                                + " but playing soft sound. threadId: " + newMsgThreadId);
            }
            playInConversationNotificationSound(context, newMsgThreadId);
            return;
        }
        updateNotification(context, newMsgThreadId, threads.size(), notificationSet);
    }

    // And deals with delivery reports (which use Toasts). It's safe to call in a worker
    // thread because the toast will eventually get posted to a handler.
    MmsSmsDeliveryInfo delivery = getSmsNewDeliveryInfo(context);
    if (delivery != null) {
        delivery.deliver(context, isStatusMessage);
    }

    notificationSet.clear();
    threads.clear();
}

From source file:de.madvertise.android.sdk.MadUtil.java

/**
 * Simple logging helper to prevent producing duplicate code blocks.
 * //ww w  .  j a va  2s .c om
 * Log-Message is only printed to LogCat if logging is enabled in MadUtils
 * and message is logable with specified tag and level. 
 *  
 * @param tag
 *     use a given tag for logging or use default tag if nil. Default tag can be defined in MadUtil class.
 * @param level
 *     log level from {@link android.util.Log}
 * @param message
 * @see 
 *     android.util.Log
 */
protected static void logMessage(String tag, int level, String message) {
    if (!PRINT_LOG) {
        if (!Log.isLoggable(tag, level))
            return;
    }
    if (tag == null)
        tag = MadUtil.LOG;
    Log.println(level, tag, message);
}