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.ChatView.java

void unregisterChatListener() {
    if (Log.isLoggable(ImApp.LOG_TAG, Log.DEBUG)) {
        log("unregisterChatListener " + mLastChatId);
    }//from   ww w .java2  s . c  om
    try {
        if (getChatSession() != null) {
            getChatSession().unregisterChatListener(mChatListener);
        }
        checkConnection();

        if (mConn != null) {
            IContactListManager listMgr = mConn.getContactListManager();
            listMgr.unregisterContactListListener(mContactListListener);
        }
    } catch (Exception e) {
        Log.w(ImApp.LOG_TAG, "<ChatView> unregisterChatListener fail:" + e.getMessage());
    }
}

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

public static Uri saveBitmapAsPart(Context context, Uri messageUri, Bitmap bitmap) throws MmsException {

    ByteArrayOutputStream os = new ByteArrayOutputStream();
    bitmap.compress(CompressFormat.JPEG, IMAGE_COMPRESSION_QUALITY, os);

    PduPart part = new PduPart();

    part.setContentType("image/jpeg".getBytes());
    String contentId = "Image" + System.currentTimeMillis();
    part.setContentLocation((contentId + ".jpg").getBytes());
    part.setContentId(contentId.getBytes());
    part.setData(os.toByteArray());//from   w  ww .j av a 2 s . co  m

    Uri retVal = PduPersister.getPduPersister(context).persistPart(part, ContentUris.parseId(messageUri), null);

    if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) {
        log("saveBitmapAsPart: persisted part with uri=" + retVal);
    }

    return retVal;
}

From source file:org.awesomeapp.messenger.ui.ConversationView.java

void registerChatListener() {
    if (Log.isLoggable(ImApp.LOG_TAG, Log.DEBUG)) {
        log("registerChatListener " + mLastChatId);
    }//www  . j  a  v  a2  s .c  om
    try {
        if (getChatSession() != null) {
            getChatSession().registerChatListener(mChatListener);
        }

        checkConnection();

        if (mConn != null) {
            IContactListManager listMgr = mConn.getContactListManager();
            listMgr.registerContactListListener(mContactListListener);

        }

    } catch (Exception e) {
        Log.w(ImApp.LOG_TAG, "<ChatView> registerChatListener fail:" + e.getMessage());
    }
}

From source file:finalproject.ece558.edu.pdx.ece.brailleblackjack.PlayBlackJackGameFragment.java

/**
 * Set-up the listener once an Android Wear (smartwatch) device is connected
 * @param bundle Bundle object/*from   w ww.  jav  a  2 s .co m*/
 */
@Override
public void onConnected(Bundle bundle) {
    Log.d(TAG, "Connected to Google Api Service");
    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG, "Connected to Google Api Service");
    }
    Wearable.MessageApi.addListener(mGoogleApiClient, this);
}

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

/**
 * Looks to see if there are any valid parts of the attachment that can be copied to a SD card.
 * @param msgId/*  w w  w.j  a  va  2 s .c  o m*/
 */
private boolean haveSomethingToCopyToSDCard(long msgId) {
    PduBody body = null;
    try {
        body = SlideshowModel.getPduBody(this, ContentUris.withAppendedId(Mms.CONTENT_URI, msgId));
    } catch (MmsException e) {
        Log.e(TAG, "haveSomethingToCopyToSDCard can't load pdu body: " + msgId);
    }
    if (body == null) {
        return false;
    }

    boolean result = false;
    int partNum = body.getPartsNum();
    for (int i = 0; i < partNum; i++) {
        PduPart part = body.getPart(i);
        String type = new String(part.getContentType());

        if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) {
            log("[CMA] haveSomethingToCopyToSDCard: part[" + i + "] contentType=" + type);
        }

        if (ContentType.isImageType(type) || ContentType.isVideoType(type) || ContentType.isAudioType(type)
                || DrmUtils.isDrmType(type)) {
            result = true;
            break;
        }
    }
    return result;
}

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

private void sleepForDebugging(Intent intent) {
    long duration = intent.getLongExtra(EXTRA_SLEEP_DURATION, 1000);
    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG, "sleeping for " + duration + "ms");
    }//www.ja  va  2 s  .c o  m
    try {
        Thread.sleep(duration);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG, "finished sleeping");
    }
}

From source file:app.umitems.greenclock.widget.sgv.StaggeredGridView.java

/**
 * Calculate and cache the {@link LayoutRecord}s for all positions up to mFirstPosition.
 * mFirstPosition is the position that layout will start from, but we need to know where all
 * views preceding it will be laid out so that mFirstPosition will be laid out at the correct
 * position.  If this is not done, mFirstPosition will be laid out at the first empty space
 * possible (i.e., top left), and this may not be the correct position in the overall layout.
 *
 * This can be optimized if we don't need to guard against jagged edges in the grid or if
 * mFirstChangedPosition is set to a non-zero value (so we can skip calculating some views).
 *///www. jav a 2s . c o  m
private void calculateLayoutStartOffsets(int offset) {
    // Bail early if we don't guard against jagged edges or if nothing has changed before
    // mFirstPosition.
    // Also check that we're not at the top of the list because sometimes grid padding isn't set
    // until after mItemTops and mItemBottoms arrays have been initialized, so we should
    // go through and compute the right layout start offset for mFirstPosition = 0.
    if (mFirstPosition != 0 && (!mGuardAgainstJaggedEdges || mFirstPosition < mFirstChangedPosition)) {
        // At this time, we know that mItemTops should be the same, because
        // nothing has changed before view at mFirstPosition. The only thing
        // we need to do is to reset mItemBottoms. The result should be the
        // same, if we don't bail early and execute the following code
        // again. Notice that mItemBottoms always equal to mItemTops after
        // this method.
        System.arraycopy(mItemTops, 0, mItemBottoms, 0, mColCount);
        return;
    }

    final int colWidth = (getWidth() - getPaddingLeft() - getPaddingRight() - mItemMargin * (mColCount - 1))
            / mColCount;

    Arrays.fill(mItemTops, getPaddingTop());
    Arrays.fill(mItemBottoms, getPaddingTop());

    // Since we will be doing a pass to calculate all views up to mFirstPosition, it is likely
    // that all existing {@link LayoutRecord}s will be stale, so clear it out to avoid
    // accidentally the re-use of stale values.
    //
    // Note: We cannot just invalidate all layout records after mFirstPosition because it is
    // possible that this layout pass is caused by a down sync from the server that may affect
    // the layout of views from position 0 to mFirstPosition - 1.
    if (mDataChanged) {
        mLayoutRecords.clear();
    }

    for (int i = 0; i < mFirstPosition; i++) {
        LayoutRecord rec = mLayoutRecords.get(i);

        if (mDataChanged || rec == null) {
            final View view = obtainView(i, null);
            final LayoutParams lp = (LayoutParams) view.getLayoutParams();

            final int heightSpec;
            if (lp.height == LayoutParams.WRAP_CONTENT) {
                heightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
            } else {
                heightSpec = MeasureSpec.makeMeasureSpec(lp.height, MeasureSpec.EXACTLY);
            }

            final int span = Math.min(mColCount, lp.span);
            final int widthSize = colWidth * span + mItemMargin * (span - 1);
            final int widthSpec = MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY);

            view.measure(widthSpec, heightSpec);
            final int height = view.getMeasuredHeight();

            if (rec == null) {
                rec = new LayoutRecord();
                mLayoutRecords.put(i, rec);
            }

            rec.height = height;
            rec.id = lp.id;
            rec.span = span;

            // We're not actually using this view, so add this back to the recycler.
            mRecycler.addScrap(view);
        }

        int nextColumn = getNextColumnDown();

        // Given the span, check if there's enough space to put this view at this column.
        // IMPORTANT Use the same logic in {@link #layoutChildren}.
        if (rec.span > 1) {
            if (mIsRtlLayout) {
                if (nextColumn + 1 < rec.span) {
                    nextColumn = mColCount - 1;
                }
            } else {
                if (mColCount - nextColumn < rec.span) {
                    nextColumn = 0;
                }
            }
        }
        rec.column = nextColumn;

        // Place the top of this child beneath the last by finding the lowest coordinate across
        // the columns that this child will span.  For LTR layout, we scan across from left to
        // right, and for RTL layout, we scan from right to left.
        // TODO: Consolidate this logic with getNextRecordDown() in the future, as that method
        // already calculates the margins for us.  This will keep the implementation consistent
        // with layoutChildren(), fillUp() and fillDown().
        int lowest = mItemBottoms[nextColumn] + mItemMargin;
        if (rec.span > 1) {
            for (int spanIndex = 0; spanIndex < rec.span; spanIndex++) {
                final int index = mIsRtlLayout ? nextColumn - spanIndex : nextColumn + spanIndex;
                final int bottom = mItemBottoms[index] + mItemMargin;
                if (bottom > lowest) {
                    lowest = bottom;
                }
            }
        }

        for (int spanIndex = 0; spanIndex < rec.span; spanIndex++) {
            final int col = mIsRtlLayout ? nextColumn - spanIndex : nextColumn + spanIndex;
            mItemBottoms[col] = lowest + rec.height;

            if (Log.isLoggable(TAG, Log.VERBOSE)) {
                Log.v(TAG, " position: " + i + " bottoms: ");
                for (int j = 0; j < mColCount; j++) {
                    Log.v(TAG, "    mItemBottoms[" + j + "]: " + mItemBottoms[j]);
                }
            }
        }
    }

    // mItemBottoms[] at this point contains the values of all views up to mFirstPosition.  To
    // figure out where view at mFirstPosition will be laid out, we'll need to find the column
    // that is the highest (i.e., i where mItemBottoms[i] <= mItemBottoms[j] for all j
    // from 0 to mColCount.)
    int highestValue = Integer.MAX_VALUE;
    for (int k = 0; k < mColCount; k++) {
        if (mItemBottoms[k] < highestValue) {
            highestValue = mItemBottoms[k];
        }
    }

    // Adjust the offsets in each column so that values in mItemTops[] and mItemBottoms[]
    // reflect coordinates on screen.  These offsets will be the actual values where layout
    // will start from, otherwise, we'd naively start at (leftPadding, topPadding) for
    // mFirstPosition.
    for (int k = 0; k < mColCount; k++) {
        mItemBottoms[k] = mItemBottoms[k] - highestValue + offset;
        mItemTops[k] = mItemBottoms[k];

        // Log.v(TAG, "Adjusting to offset = mItemBottoms[" + k + "]: " + mItemBottoms[k]);
    }
}

From source file:se.oort.clockify.widget.sgv.StaggeredGridView.java

/**
 * Calculate and cache the {@link LayoutRecord}s for all positions up to mFirstPosition.
 * mFirstPosition is the position that layout will start from, but we need to know where all
 * views preceding it will be laid out so that mFirstPosition will be laid out at the correct
 * position.  If this is not done, mFirstPosition will be laid out at the first empty space
 * possible (i.e., top left), and this may not be the correct position in the overall layout.
 *
 * This can be optimized if we don't need to guard against jagged edges in the grid or if
 * mFirstChangedPosition is set to a non-zero value (so we can skip calculating some views).
 *///from  w  ww. ja  v a  2  s  . c  om
private void calculateLayoutStartOffsets(int offset) {
    // Bail early if we don't guard against jagged edges or if nothing has changed before
    // mFirstPosition.
    // Also check that we're not at the top of the list because sometimes grid padding isn't set
    // until after mItemTops and mItemBottoms arrays have been initialized, so we should
    // go through and compute the right layout start offset for mFirstPosition = 0.
    if (mFirstPosition != 0 && (!mGuardAgainstJaggedEdges || mFirstPosition < mFirstChangedPosition)) {
        // At this time, we know that mItemTops should be the same, because
        // nothing has changed before view at mFirstPosition. The only thing
        // we need to do is to reset mItemBottoms. The result should be the
        // same, if we don't bail early and execute the following code
        // again. Notice that mItemBottoms always equal to mItemTops after
        // this method.
        System.arraycopy(mItemTops, 0, mItemBottoms, 0, mColCount);
        return;
    }

    final int colWidth = (getWidth() - getPaddingLeft() - getPaddingRight() - mItemMargin * (mColCount - 1))
            / mColCount;

    Arrays.fill(mItemTops, getPaddingTop());
    Arrays.fill(mItemBottoms, getPaddingTop());

    // Since we will be doing a pass to calculate all views up to mFirstPosition, it is likely
    // that all existing {@link LayoutRecord}s will be stale, so clear it out to avoid
    // accidentally the re-use of stale values.
    //
    // Note: We cannot just invalidate all layout records after mFirstPosition because it is
    // possible that this layout pass is caused by a down sync from the server that may affect
    // the layout of views from position 0 to mFirstPosition - 1.
    if (mDataChanged) {
        mLayoutRecords.clear();
    }

    for (int i = 0; i < mFirstPosition; i++) {
        LayoutRecord rec = mLayoutRecords.get(i);

        if (mDataChanged || rec == null) {
            final View view = obtainView(i, null);
            final LayoutParams lp = (LayoutParams) view.getLayoutParams();

            final int heightSpec;
            if (lp.height == LayoutParams.WRAP_CONTENT) {
                heightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
            } else {
                heightSpec = MeasureSpec.makeMeasureSpec(lp.height, MeasureSpec.EXACTLY);
            }

            final int span = Math.min(mColCount, lp.span);
            final int widthSize = colWidth * span + mItemMargin * (span - 1);
            final int widthSpec = MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY);

            view.measure(widthSpec, heightSpec);
            final int height = view.getMeasuredHeight();

            if (rec == null) {
                rec = new LayoutRecord();
                mLayoutRecords.put(i, rec);
            }

            rec.height = height;
            rec.id = lp.id;
            rec.span = span;

            // We're not actually using this view, so add this back to the recycler.
            mRecycler.addScrap(view);
        }

        int nextColumn = getNextColumnDown();

        // Given the span, check if there's enough space to put this view at this column.
        // IMPORTANT Use the same logic in {@link #layoutChildren}.
        if (rec.span > 1) {
            if (mIsRtlLayout) {
                if (nextColumn + 1 < rec.span) {
                    nextColumn = mColCount - 1;
                }
            } else {
                if (mColCount - nextColumn < rec.span) {
                    nextColumn = 0;
                }
            }
        }
        rec.column = nextColumn;

        // Place the top of this child beneath the last by finding the lowest coordinate across
        // the columns that this child will span.  For LTR layout, we scan across from left to
        // right, and for RTL layout, we scan from right to left.
        // TODO: Consolidate this logic with getNextRecordDown() in the future, as that method
        // already calculates the margins for us.  This will keep the implementation consistent
        // with layoutChildren(), fillUp() and fillDown().
        int lowest = mItemBottoms[nextColumn] + mItemMargin;
        if (rec.span > 1) {
            for (int spanIndex = 0; spanIndex < rec.span; spanIndex++) {
                final int index = mIsRtlLayout ? nextColumn - spanIndex : nextColumn + spanIndex;
                final int bottom = mItemBottoms[index] + mItemMargin;
                if (bottom > lowest) {
                    lowest = bottom;
                }
            }
        }

        for (int spanIndex = 0; spanIndex < rec.span; spanIndex++) {
            final int col = mIsRtlLayout ? nextColumn - spanIndex : nextColumn + spanIndex;
            mItemBottoms[col] = lowest + rec.height;

            if (Log.isLoggable(LOG_TAG, Log.VERBOSE)) {
                Log.v(LOG_TAG, " position: " + i + " bottoms: ");
                for (int j = 0; j < mColCount; j++) {
                    Log.v(LOG_TAG, "    mItemBottoms[" + j + "]: " + mItemBottoms[j]);
                }
            }
        }
    }

    // mItemBottoms[] at this point contains the values of all views up to mFirstPosition.  To
    // figure out where view at mFirstPosition will be laid out, we'll need to find the column
    // that is the highest (i.e., i where mItemBottoms[i] <= mItemBottoms[j] for all j
    // from 0 to mColCount.)
    int highestValue = Integer.MAX_VALUE;
    for (int k = 0; k < mColCount; k++) {
        if (mItemBottoms[k] < highestValue) {
            highestValue = mItemBottoms[k];
        }
    }

    // Adjust the offsets in each column so that values in mItemTops[] and mItemBottoms[]
    // reflect coordinates on screen.  These offsets will be the actual values where layout
    // will start from, otherwise, we'd naively start at (leftPadding, topPadding) for
    // mFirstPosition.
    for (int k = 0; k < mColCount; k++) {
        mItemBottoms[k] = mItemBottoms[k] - highestValue + offset;
        mItemTops[k] = mItemBottoms[k];

        // Log.v(TAG, "Adjusting to offset = mItemBottoms[" + k + "]: " + mItemBottoms[k]);
    }
}

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

private void showSubjectEditor(boolean show) {
    if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) {
        log("" + show);
    }/* w  ww . jav  a2  s. c om*/

    if (mSubjectTextEditor == null) {
        // Don't bother to initialize the subject editor if
        // we're just going to hide it.
        if (show == false) {
            return;
        }
        mSubjectTextEditor = (EditText) findViewById(R.id.subject);
        mSubjectTextEditor.setFilters(new InputFilter[] { new LengthFilter(MmsConfig.getMaxSubjectLength()) });
    }

    mSubjectTextEditor.setOnKeyListener(show ? mSubjectKeyListener : null);

    if (show) {
        mSubjectTextEditor.addTextChangedListener(mSubjectEditorWatcher);
    } else {
        mSubjectTextEditor.removeTextChangedListener(mSubjectEditorWatcher);
    }

    mSubjectTextEditor.setText(mWorkingMessage.getSubject());
    mSubjectTextEditor.setVisibility(show ? View.VISIBLE : View.GONE);
    hideOrShowTopPanel();
}