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:info.guardianproject.otr.app.im.app.WelcomeActivity.java

private void signIn(long accountId) {
    if (accountId == 0) {
        Log.w(TAG, "signIn: account id is 0, bail");
        return;/*ww w . j av a  2s  . co m*/
    }

    boolean isAccountEditable = mProviderCursor.getInt(ACTIVE_ACCOUNT_LOCKED) == 0;
    if (isAccountEditable && mProviderCursor.isNull(ACTIVE_ACCOUNT_PW_COLUMN)) {
        // no password, edit the account
        if (Log.isLoggable(TAG, Log.DEBUG))
            Log.i(TAG, "no pw for account " + accountId);
        Intent intent = getEditAccountIntent();
        startActivity(intent);
        finish();
        return;
    }

    long providerId = mProviderCursor.getLong(PROVIDER_ID_COLUMN);
    String password = mProviderCursor.getString(ACTIVE_ACCOUNT_PW_COLUMN);
    boolean isActive = false; // TODO(miron)
    mSignInHelper.signIn(password, providerId, accountId, isActive);
}

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

private static PercentLayoutInfo setWidthAndHeightVal(TypedArray array, PercentLayoutInfo info) {
    PercentLayoutInfo.PercentVal percentVal = getPercentVal(array,
            com.zhy.android.percent.support.R.styleable.PercentLayout_Layout_layout_widthPercent, true);
    if (percentVal != null) {
        if (Log.isLoggable(TAG, Log.VERBOSE)) {
            Log.v(TAG, "percent width: " + percentVal.percent);
        }/*from ww  w.  ja va2  s  . c  o  m*/
        info = checkForInfoExists(info);
        info.widthPercent = percentVal;
    }
    percentVal = getPercentVal(array,
            com.zhy.android.percent.support.R.styleable.PercentLayout_Layout_layout_heightPercent, false);

    if (percentVal != null) {
        if (Log.isLoggable(TAG, Log.VERBOSE)) {
            Log.v(TAG, "percent height: " + percentVal.percent);
        }
        info = checkForInfoExists(info);
        info.heightPercent = percentVal;
    }

    return info;
}

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

private <T> T execute(Callable<T> callable, String name, long time, TimeUnit timeUnit) {
    FutureCallable<T> futureCallable = new FutureCallable<T>(callable);
    FutureTask<T> future = new FutureTask<T>(futureCallable);
    futureCallable.setFuture(future);//ww w  . j ava 2s.c om

    synchronized (mActiveTasks) {
        mActiveTasks.addLast(future);
        if (Log.isLoggable("DialerProvider", Log.VERBOSE)) {
            Log.v("DialerProvider", "Currently running tasks: " + mActiveTasks.size());
        }
        while (mActiveTasks.size() > 8) {
            Log.w("DialerProvider", "Too many tasks, canceling one");
            mActiveTasks.removeFirst().cancel(true);
        }
    }

    if (Log.isLoggable("DialerProvider", Log.VERBOSE)) {
        Log.v("DialerProvider", "Starting task " + name);
    }

    new Thread(future, name).start();
    try {
        if (Log.isLoggable("DialerProvider", Log.VERBOSE)) {
            Log.v("DialerProvider", "Getting future " + name);
        }
        return future.get(time, timeUnit);
    } catch (InterruptedException e) {
        Log.w("DialerProvider", "Task was interrupted: " + name);
        Thread.currentThread().interrupt();
    } catch (ExecutionException e) {
        Log.w("DialerProvider", "Task threw an exception: " + name, e);
    } catch (TimeoutException e) {
        Log.w("DialerProvider", "Task timed out: " + name);
        future.cancel(true);
    } catch (CancellationException e) {
        Log.w("DialerProvider", "Task was cancelled: " + name);
    }

    // TODO: Is this appropriate?
    return null;
}

From source file:com.android.contacts.activities.PeopleActivity.java

@Override
protected void onCreate(Bundle savedState) {
    if (Log.isLoggable(Constants.PERFORMANCE_TAG, Log.DEBUG)) {
        Log.d(Constants.PERFORMANCE_TAG, "PeopleActivity.onCreate start");
    }//from w  w w .j ava2 s .c  o m
    super.onCreate(savedState);

    if (RequestPermissionsActivity.startPermissionActivity(this)) {
        return;
    }

    if (!processIntent(false)) {
        finish();
        return;
    }
    mContactListFilterController = ContactListFilterController.getInstance(this);
    mContactListFilterController.checkFilterValidity(false);
    mContactListFilterController.addListener(this);

    mProviderStatusWatcher.addListener(this);

    mIsRecreatedInstance = (savedState != null);
    createViewsAndFragments(savedState);

    if (Log.isLoggable(Constants.PERFORMANCE_TAG, Log.DEBUG)) {
        Log.d(Constants.PERFORMANCE_TAG, "PeopleActivity.onCreate finish");
    }
    getWindow().setBackgroundDrawable(null);
}

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

@Override
public void onEscrowTokenRemoved(long handle, boolean successful) {
    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG, "onEscrowTokenRemoved. Handle: " + handle + " successful? " + successful);
    }/*  www .  jav  a2s . com*/
}

From source file:mobisocial.noteshere.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.
 *//*from  w  w  w.  java2 s .c om*/
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.
            }
            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.example.android.wearable.agendadata.MainActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG, "onActivityResult request/result codes: " + requestCode + "/" + resultCode);
    }//  w  w w . j a  va 2  s .  c o  m

    if (requestCode == REQUEST_RESOLVE_ERROR) {
        mResolvingError = false;
        if (resultCode == RESULT_OK) {
            // Make sure the app is not already connected or attempting to connect
            if (!mGoogleApiClient.isConnecting() && !mGoogleApiClient.isConnected()) {
                mGoogleApiClient.connect();
            }
        }
    }
}

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

public final void bind(Context context, final Conversation conversation) {
    //if (DEBUG) Log.v(TAG, "bind()");
    boolean sameItem = mConversation != null && mConversation.getThreadId() == conversation.getThreadId();

    mConversation = conversation;/*from  w  w  w . java  2 s.  c  o m*/

    LayoutParams attachmentLayout = (LayoutParams) mAttachmentView.getLayoutParams();
    boolean hasError = conversation.hasError();
    // When there's an error icon, the attachment icon is left of the error icon.
    // When there is not an error icon, the attachment icon is left of the date text.
    // As far as I know, there's no way to specify that relationship in xml.
    if (hasError) {
        attachmentLayout.addRule(RelativeLayout.LEFT_OF, R.id.error);
    } else {
        attachmentLayout.addRule(RelativeLayout.LEFT_OF, R.id.date);
    }

    boolean hasAttachment = conversation.hasAttachment();
    mAttachmentView.setVisibility(hasAttachment ? VISIBLE : GONE);

    // Date
    mDateView.setText(MessageUtils.formatTimeStampString(context, conversation.getDate()));

    // From.
    mFromView.setText(formatMessage());

    // Register for updates in changes of any of the contacts in this conversation.
    ContactList contacts = conversation.getRecipients();

    if (Log.isLoggable(LogTag.CONTACT, Log.DEBUG)) {
        Log.v(TAG, "bind: contacts.addListeners " + this);
    }
    Contact.addListener(this);

    // Subject
    SmileyParser parser = SmileyParser.getInstance();
    final String snippet = conversation.getSnippet();
    if (mConversation.hasUnreadMessages()) {
        SpannableStringBuilder buf = new SpannableStringBuilder(parser.addSmileySpans(snippet));
        buf.setSpan(STYLE_BOLD, 0, buf.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
        mSubjectView.setText(buf);
    } else {
        mSubjectView.setText(parser.addSmileySpans(snippet));
    }

    // Transmission error indicator.
    mErrorIndicator.setVisibility(hasError ? VISIBLE : GONE);

    updateAvatarView();
    mAvatarView.setChecked(isChecked(), sameItem);
}

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

@Override
public void onEscrowTokenStateReceived(long handle, int tokenState) {
    boolean isActive = tokenState == TOKEN_STATE_ACTIVE;
    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG, "Token handle: " + handle + " isActive: " + isActive);
    }/*from  w  ww .j a  v  a  2s.  com*/

    Intent intent = new Intent();
    intent.setAction(ACTION_TOKEN_STATUS_RESULT);
    intent.putExtra(INTENT_EXTRA_TOKEN_STATUS, isActive);

    mLocalBroadcastManager.sendBroadcast(intent);
}

From source file:android.percent.support.PercentLayoutHelper.java

/**
 * Constructs a PercentLayoutInfo from attributes associated with a View. Call this method from
 * {@code LayoutParams(Context c, AttributeSet attrs)} constructor.
 *///from  w w  w .  j a  v  a  2  s .  c  o m
public static PercentLayoutInfo getPercentLayoutInfo(Context context, AttributeSet attrs) {
    PercentLayoutInfo info = null;
    TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.PercentLayout_Layout);

    info = setWidthAndHeightVal(array, info);

    info = setMarginRelatedVal(array, info);

    info = setTextSizeSupportVal(array, info);

    info = setMinMaxWidthHeightRelatedVal(array, info);

    info = setPaddingRelatedVal(array, info);

    array.recycle();

    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG, "constructed: " + info);
    }
    return info;
}