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.android.launcher3.Utilities.java

public static boolean isPropertyEnabled(String propertyName) {
    return Log.isLoggable(propertyName, Log.VERBOSE);
}

From source file:android.support.wear.widget.drawer.WearableDrawerLayout.java

/**
 * Peek the given {@link WearableDrawerView}, which may either be the top drawer or bottom
 * drawer. This should only be used after the drawer has been added as a child of the {@link
 * WearableDrawerLayout}./* w  w w. ja  va  2 s.c o m*/
 */
void peekDrawer(WearableDrawerView drawer) {
    if (drawer == null) {
        throw new IllegalArgumentException("peekDrawer(WearableDrawerView) received a null drawer.");
    } else if (drawer != mTopDrawerView && drawer != mBottomDrawerView) {
        throw new IllegalArgumentException(
                "peekDrawer(WearableDrawerView) received a drawer that isn't a child.");
    }

    if (!isLaidOut()) {
        // If this view is not laid out yet, postpone the peek until onLayout is called.
        if (Log.isLoggable(TAG, Log.DEBUG)) {
            Log.d(TAG, "WearableDrawerLayout not laid out yet. Postponing peek.");
        }
        if (drawer == mTopDrawerView) {
            mShouldPeekTopDrawerAfterLayout = true;
        } else if (drawer == mBottomDrawerView) {
            mShouldPeekBottomDrawerAfterLayout = true;
        }
        return;
    }

    maybePeekDrawer(drawer);
}

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

/**
 * Resets the current quiz when Reset Quiz is pressed.
 *//*from www .j ava2 s. c  o  m*/
public void resetQuiz(View view) {
    // Reset quiz status in phone layout.
    for (int i = 0; i < questionsContainer.getChildCount(); i++) {
        LinearLayout questionStatusElement = (LinearLayout) questionsContainer.getChildAt(i);
        TextView questionText = (TextView) questionStatusElement.findViewById(R.id.question);
        TextView questionStatus = (TextView) questionStatusElement.findViewById(R.id.status);
        questionText.setTextColor(Color.WHITE);
        questionStatus.setText(R.string.question_unanswered);
    }
    // Reset data items and notifications on wearable.
    if (mGoogleApiClient.isConnected()) {
        Wearable.DataApi.getDataItems(mGoogleApiClient).setResultCallback(new ResultCallback<DataItemBuffer>() {
            @Override
            public void onResult(DataItemBuffer result) {
                try {
                    if (result.getStatus().isSuccess()) {
                        resetDataItems(result);
                    } else {
                        if (Log.isLoggable(TAG, Log.DEBUG)) {
                            Log.d(TAG, "Reset quiz: failed to get Data Items to reset");
                        }
                    }
                } finally {
                    result.release();
                }
            }
        });
    } else {
        Log.e(TAG, "Failed to reset data items because client is disconnected from " + "Google Play Services");
    }
    setHasQuestionBeenAsked(false);
    mNumCorrect = 0;
    mNumIncorrect = 0;
    mNumSkipped = 0;
}

From source file:com.kevin.percentsupportextends.PercentLayoutHelper.java

public void restoreOriginalParams() {
    for (int i = 0, N = mHost.getChildCount(); i < N; i++) {
        View view = mHost.getChildAt(i);
        ViewGroup.LayoutParams params = view.getLayoutParams();
        if (Log.isLoggable(TAG, Log.DEBUG)) {
            Log.d(TAG, "should restore " + view + " " + params);
        }//from   ww w  . j  a v  a  2  s.  c  o  m
        if (params instanceof PercentLayoutParams) {
            PercentLayoutInfo info = ((PercentLayoutParams) params).getPercentLayoutInfo();
            if (Log.isLoggable(TAG, Log.DEBUG)) {
                Log.d(TAG, "using " + info);
            }
            if (info != null) {
                if (params instanceof ViewGroup.MarginLayoutParams) {
                    info.restoreMarginLayoutParams((ViewGroup.MarginLayoutParams) params);
                } else {
                    info.restoreLayoutParams(params);
                }
            }
        }
    }
}

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

@Override
public Cursor query(Uri uri, final String[] projection, String selection, String[] selectionArgs,
        String sortOrder) {/*from   w w w  .j a  va  2s.c o  m*/
    if (Log.isLoggable("DialerProvider", 2)) {
        Log.v("DialerProvider", "query: " + uri);
    }

    switch (sURIMatcher.match(uri)) {
    case 0:
        Context context = getContext();
        if (!GoogleLocationSettingHelper.isGoogleLocationServicesEnabled(context)
                || !GoogleLocationSettingHelper.isSystemLocationSettingEnabled(context)) {
            if (Log.isLoggable("DialerProvider", Log.VERBOSE)) {
                Log.v("DialerProvider", "Location settings is disabled, ignoring query.");
            }
            return null;
        }

        final Location lastLocation = getLastLocation();
        if (lastLocation == null) {
            if (Log.isLoggable("DialerProvider", Log.VERBOSE)) {
                Log.v("DialerProvider", "No location available, ignoring query.");
            }
            return null;
        }

        final String filter = Uri.encode(uri.getLastPathSegment());
        String limit = uri.getQueryParameter("limit");

        try {
            final int limitInt;
            if (limit == null) {
                limitInt = -1;
            } else {
                limitInt = Integer.parseInt(limit);
            }

            return execute(new Callable<Cursor>() {
                @Override
                public Cursor call() {
                    return handleFilter(projection, filter, limitInt, lastLocation);
                }
            }, "FilterThread", 10000L, TimeUnit.MILLISECONDS);
        } catch (NumberFormatException e) {
            Log.e("DialerProvider", "query: invalid limit parameter: '" + limit + "'");
        }

        break;
    }

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

From source file:de.tubs.ibr.dtn.service.DaemonService.java

@Override
public void onStart(Intent intent, int startId) {
    /*//from   w  w w.j  a  v  a 2 s.c om
     * If no explicit intent is given start as ACTION_STARTUP. When this
     * service crashes, Android restarts it without an Intent. Thus
     * ACTION_STARTUP is executed!
     */
    if (intent == null || intent.getAction() == null) {
        Log.d(TAG, "intent == null or intent.getAction() == null -> default to ACTION_STARTUP");

        intent = new Intent(ACTION_STARTUP);
    }

    String action = intent.getAction();

    if (Log.isLoggable(TAG, Log.DEBUG))
        Log.d(TAG, "Received start id " + startId + ": " + intent);
    if (Log.isLoggable(TAG, Log.DEBUG))
        Log.d(TAG, "Intent Action: " + action);

    Message msg = mServiceHandler.obtainMessage();
    msg.arg1 = startId;
    msg.obj = intent;
    mServiceHandler.sendMessage(msg);
}

From source file:com.cloudzilla.fb.FacebookServiceProxy.java

private com.facebook.AccessToken getAccessToken() {
    String accessTokenString = null;
    List<String> permissions = null;
    List<String> declinedPermissions = null;
    String applicationId = null;//w w w . j ava  2  s . c om
    String userId = null;
    Date expirationTime = null;
    Date lastRefreshTime = null;
    try {
        int resultCode = mFacebookService.isOnFacebook(FACEBOOK_SERVICE_API_VERSION);
        if (resultCode == 0) {
            if (Log.isLoggable(TAG, Log.DEBUG)) {
                Log.d(TAG, "You are on Facebook");
            }
            accessTokenString = mFacebookService.getAccessToken();
            permissions = mFacebookService.getPermissions();
            applicationId = mFacebookService.getApplicationId();
            userId = mFacebookService.getUserId();
            expirationTime = new Date(mFacebookService.getAccessTokenExpirationTimeInMs());
            lastRefreshTime = new Date(mFacebookService.getAccessTokenLastRefreshTimeInMs());
        } else {
            Log.e(TAG, "You are not on Facebook: " + resultCode);
        }
    } catch (RemoteException e) {
        Log.e(TAG, "Failed to invoke FacebookService", e);
    }

    if (accessTokenString == null || permissions == null || applicationId == null || userId == null) {
        Log.e(TAG, "Some session information is missing");
        return null;
    }

    com.facebook.AccessTokenSource accessTokenSource = com.facebook.AccessTokenSource.WEB_VIEW;
    com.facebook.AccessToken accessToken = new com.facebook.AccessToken(accessTokenString, applicationId,
            userId, permissions, declinedPermissions, accessTokenSource, expirationTime, lastRefreshTime);

    return accessToken;
}

From source file:com.android.providers.contacts.ContactsSyncAdapter.java

protected void sendClientPhotos(SyncContext context, ContentProvider clientDiffs, Object syncInfo,
        SyncResult syncResult) {//from  w ww  .  j  a  va 2s.  c  om
    Entry entry = new MediaEntry();

    GDataServiceClient client = getGDataServiceClient();
    String authToken = getAuthToken();
    ContentResolver cr = getContext().getContentResolver();
    final String account = getAccount();

    Cursor c = clientDiffs.query(Photos.CONTENT_URI, null /* all columns */, null /* no where */,
            null /* no where args */, null /* default sort order */);
    try {
        int personColumn = c.getColumnIndexOrThrow(Photos.PERSON_ID);
        int dataColumn = c.getColumnIndexOrThrow(Photos.DATA);
        int numRows = c.getCount();
        while (c.moveToNext()) {
            if (mSyncCanceled) {
                if (Config.LOGD)
                    Log.d(TAG, "stopping since the sync was canceled");
                break;
            }

            entry.clear();
            context.setStatusText("Updating, " + (numRows - 1) + " to go");

            cursorToBaseEntry(entry, account, c);
            String editUrl = entry.getEditUri();

            if (TextUtils.isEmpty(editUrl)) {
                if (Config.LOGD) {
                    Log.d(TAG, "skipping photo edit for unsynced contact");
                }
                continue;
            }

            // Send the request and receive the response
            InputStream inputStream = null;
            byte[] imageData = c.getBlob(dataColumn);
            if (imageData != null) {
                inputStream = new ByteArrayInputStream(imageData);
            }
            Uri photoUri = Uri.withAppendedPath(People.CONTENT_URI,
                    c.getString(personColumn) + "/" + Photos.CONTENT_DIRECTORY);
            try {
                if (inputStream != null) {
                    if (Log.isLoggable(TAG, Log.VERBOSE)) {
                        Log.v(TAG, "Updating photo " + entry.toString());
                    }
                    ++mPhotoUploads;
                    client.updateMediaEntry(editUrl, inputStream, IMAGE_MIME_TYPE, authToken);
                } else {
                    if (Log.isLoggable(TAG, Log.VERBOSE)) {
                        Log.v(TAG, "Deleting photo " + entry.toString());
                    }
                    client.deleteEntry(editUrl, authToken);
                }

                // Mark that this photo is no longer dirty. The next time we sync (which
                // should be soon), we will get the new version of the photo and whether
                // or not there is a new one to download (e.g. if we deleted our version
                // yet there is an evergreen version present).
                ContentValues values = new ContentValues();
                values.put(Photos.EXISTS_ON_SERVER, inputStream == null ? 0 : 1);
                values.put(Photos._SYNC_DIRTY, 0);
                if (cr.update(photoUri, values, null /* no where */, null /* no where args */) != 1) {
                    Log.e(TAG, "error updating photo " + photoUri + " with values " + values);
                    syncResult.stats.numParseExceptions++;
                } else {
                    syncResult.stats.numUpdates++;
                }
                continue;
            } catch (ParseException e) {
                Log.e(TAG, "parse error during update of " + ", skipping");
                syncResult.stats.numParseExceptions++;
            } catch (IOException e) {
                if (Config.LOGD) {
                    Log.d(TAG, "io error during update of " + entry.toString() + ", skipping");
                }
                syncResult.stats.numIoExceptions++;
            } catch (HttpException e) {
                switch (e.getStatusCode()) {
                case HttpException.SC_UNAUTHORIZED:
                    if (syncResult.stats.numAuthExceptions == 0) {
                        if (Config.LOGD) {
                            Log.d(TAG, "auth error during update of " + entry + ", skipping");
                        }
                    }
                    syncResult.stats.numAuthExceptions++;
                    try {
                        GoogleLoginServiceBlockingHelper.invalidateAuthToken(getContext(), authToken);
                    } catch (GoogleLoginServiceNotFoundException e1) {
                        if (Config.LOGD) {
                            Log.d(TAG, "could not invalidate auth token", e1);
                        }
                    }
                    return;

                case HttpException.SC_CONFLICT:
                    if (Config.LOGD) {
                        Log.d(TAG, "conflict detected during update of " + entry + ", skipping");
                    }
                    syncResult.stats.numConflictDetectedExceptions++;
                    break;
                case HttpException.SC_BAD_REQUEST:
                case HttpException.SC_FORBIDDEN:
                case HttpException.SC_NOT_FOUND:
                case HttpException.SC_INTERNAL_SERVER_ERROR:
                default:
                    if (Config.LOGD) {
                        Log.d(TAG, "error " + e.getMessage() + " during update of " + entry.toString()
                                + ", skipping");
                    }
                    syncResult.stats.numIoExceptions++;
                }
            }
        }
    } finally {
        c.close();
    }
}

From source file:com.kevin.percentsupportextends.PercentLayoutHelper.java

public boolean handleMeasuredStateTooSmall() {
    boolean needsSecondMeasure = false;
    for (int i = 0, N = mHost.getChildCount(); i < N; i++) {
        View view = mHost.getChildAt(i);
        ViewGroup.LayoutParams params = view.getLayoutParams();
        if (Log.isLoggable(TAG, Log.DEBUG)) {
            Log.d(TAG, "should handle measured state too small " + view + " " + params);
        }//w  ww.j  av  a 2s. c  o  m
        if (params instanceof PercentLayoutParams) {
            PercentLayoutInfo info = ((PercentLayoutParams) params).getPercentLayoutInfo();
            if (info != null) {
                if (shouldHandleMeasuredWidthTooSmall(view, info)) {
                    needsSecondMeasure = true;
                    params.width = ViewGroup.LayoutParams.WRAP_CONTENT;
                }
                if (shouldHandleMeasuredHeightTooSmall(view, info)) {
                    needsSecondMeasure = true;
                    params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
                }
            }
        }
    }
    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG, "should trigger second measure pass: " + needsSecondMeasure);
    }
    return needsSecondMeasure;
}

From source file:com.dirkgassen.wator.ui.view.RangeSlider.java

/**
 * Handle touch events: drag the thumb to new values. This method also detects clicks.
 *
 * @param event the touch event//from www.ja va  2 s  .  co  m
 * @return {@code true} if the event was handled; {@code false} otherwise
 */
@Override
public boolean onTouchEvent(@NonNull MotionEvent event) {
    if (Log.isLoggable("Wa-Tor", Log.DEBUG)) {
        Log.d("Wa-Tor", "Got touch event: " + event);
    }
    int paddingLeft = getPaddingLeft();
    int paddingRight = getPaddingRight();
    switch (event.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
        touchEventStartTime = System.currentTimeMillis();
        valueBeforeDragging = value;
        activePointerId = event.getPointerId(0);
        float valuePos = positionFromValue(paddingLeft, paddingRight);
        float x = event.getX();
        if (x < valuePos - thumbSize / 2 || x > valuePos + thumbSize / 2) {
            int newValue = valueFromPosition(x, paddingLeft, paddingRight);
            if (Log.isLoggable("Wa-Tor", Log.DEBUG)) {
                Log.d("Wa-Tor", "Starting to drag thumb OUTSIDE of thumb");
            }
            if (newValue != value) {
                touchEventStartTime = 0L; // Not a click
                updateValue(newValue, true /* from user */);
            }
            touchOffset = 0f;
        } else {
            touchOffset = x - valuePos;
            if (Log.isLoggable("Wa-Tor", Log.DEBUG)) {
                Log.d("Wa-Tor", "Starting to drag thumb INSIDE of thumb; offset = " + touchOffset);
            }
        }
        isDragging = true;
        return true;
    case MotionEvent.ACTION_MOVE:
        if (activePointerId != -1) {
            final int pointerIndex = event.findPointerIndex(activePointerId);
            float currentPos = event.getX(pointerIndex) - touchOffset;
            int newValue = valueFromPosition(currentPos, paddingLeft, paddingRight);
            if (newValue != value) {
                if (Log.isLoggable("Wa-Tor", Log.DEBUG)) {
                    Log.d("Wa-Tor", "Got new value " + newValue + " (old = " + value + ")");
                }
                touchEventStartTime = 0L; // Not a click
                updateValue(newValue, true /* from user */);
            }
        }
        return true;
    case MotionEvent.ACTION_UP:
        if (touchEventStartTime > 0L && System.currentTimeMillis() - touchEventStartTime < MAX_CLICK_DURATION) {
            performClick();
        }
        isDragging = false;
        break;
    case MotionEvent.ACTION_CANCEL:
        isDragging = false;
        updateValue(valueBeforeDragging, true /* from user */);
        break;
    case MotionEvent.ACTION_POINTER_UP:
        isDragging = false;
        break;
    }

    return super.onTouchEvent(event);
}