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.contacts.activities.PeopleActivity.java

/**
 * Resolve the intent and initialize {@link #mRequest}, and launch another activity if redirect
 * is needed.// w w  w  .  jav  a  2 s  . c om
 *
 * @param forNewIntent set true if it's called from {@link #onNewIntent(Intent)}.
 * @return {@code true} if {@link PeopleActivity} should continue running.  {@code false}
 *         if it shouldn't, in which case the caller should finish() itself and shouldn't do
 *         farther initialization.
 */
private boolean processIntent(boolean forNewIntent) {
    // Extract relevant information from the intent
    mRequest = mIntentResolver.resolveIntent(getIntent());
    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG, this + " processIntent: forNewIntent=" + forNewIntent + " intent=" + getIntent()
                + " request=" + mRequest);
    }
    if (!mRequest.isValid()) {
        setResult(RESULT_CANCELED);
        return false;
    }

    if (mRequest.getActionCode() == ContactsRequest.ACTION_VIEW_CONTACT) {
        final Intent intent = ImplicitIntentsUtil.composeQuickContactIntent(mRequest.getContactUri(),
                QuickContactActivity.MODE_FULLY_EXPANDED);
        intent.putExtra(QuickContactActivity.EXTRA_PREVIOUS_SCREEN_TYPE, ScreenType.UNKNOWN);
        ImplicitIntentsUtil.startActivityInApp(this, intent);
        return false;
    }
    return true;
}

From source file:com.dirkgassen.wator.ui.activity.MainActivity.java

/** Notifies all {@link #worldObservers} of a world change */
private void worldUpdated() {
    synchronized (worldObserverMutex) {
        if (worldObserverCount > 0) {
            Simulator.WorldInspector world = simulator.getWorldToPaint();
            try {
                for (int observerNo = 0; observerNo < worldObserverCount; observerNo++) {
                    worldObservers[observerNo].worldUpdated(world);
                    world.reset();/*ww w .j a  v  a  2  s .c  o m*/
                }
                if (Log.isLoggable("Wa-Tor", Log.VERBOSE)) {
                    Log.v("Wa-Tor", "Fish: " + world.getFishCount() + "; sharks: " + world.getSharkCount());
                }
                if (world.getSharkCount() == 0) {
                    simulatorRunnable.stopTicking();
                }
            } finally {
                world.release();
            }
        }
    }
    // Note: not synchronizing here, but rather a rudimentary check to avoid posting if it's not
    // necessary. If the drawer opens while we are executing and one of these fields change to non-null
    // then the frame rate will be update next time. If it's the other way around the updateFpsRunnable
    // should synchronize and check again.
    if (currentSimFps != null || currentDrawFps != null && nextFpsUpdate < System.currentTimeMillis()) {
        handler.post(updateFpsRunnable);
        nextFpsUpdate = System.currentTimeMillis() + 6000L;
    }
}

From source file:com.kth.common.utils.etc.LogUtil.java

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

From source file:net.vleu.par.android.rpc.Transceiver.java

/**
 * Invalidates the {@link GoogleAuthToken} stored in the
 * {@link AccountManager}/*from w w  w.  ja va2s .  c o m*/
 */
private void invalidatesGoogleAuthToken(final GoogleAuthToken token) {
    if (token != null) {
        final AccountManager am = AccountManager.get(this.context);
        if (Log.isLoggable(TAG, Log.DEBUG))
            Log.d(TAG, "Invalidating GoogleAuthToken : " + token.value);
        am.invalidateAuthToken(GOOGLE_ACCOUNT_TYPE, token.value);
    }
}

From source file:com.kth.common.utils.etc.LogUtil.java

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

From source file:com.philliphsu.bottomsheetpickers.date.PagingDayPickerView.java

/**
 * This moves to the specified time in the view. If the time is not already
 * in range it will move the list so that the first of the month containing
 * the time is at the top of the view. If the new time is already in view
 * the list will not be scrolled unless forceScroll is true. This time may
 * optionally be highlighted as selected as well.
 *
 * @param day The time to move to/*w ww.j a  va2s.c  om*/
 * @param animate Whether to scroll to the given time or just redraw at the
 *            new location
 * @param setSelected Whether to set the given time as selected
 * @param forceScroll Whether to recenter even if the time is already
 *            visible
 * @return Whether or not the view animated to the new location
 */
public boolean goTo(CalendarDay day, boolean animate, boolean setSelected, boolean forceScroll) {
    final int selectedPosition = getPosition(mSelectedDay);

    // Set the selected day
    if (setSelected) {
        mSelectedDay.set(day);
    }

    mTempDay.set(day);
    final int position = getPosition(day);

    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG, "GoTo position " + position);
    }
    // Check if the selected day is now outside of our visible range
    // and if so scroll to the month that contains it
    if (position != selectedPosition || forceScroll) {
        setMonthAndYearDisplayed(mTempDay);
        if (animate) {
            mViewPager.setCurrentItem(position, true);
            if (setSelected) {
                setSelectedDay(mSelectedDay);
            }
            return true;
        } else {
            postSetSelection(position, setSelected);
        }
    } else if (setSelected) {
        setMonthAndYearDisplayed(mSelectedDay);
        setSelectedDay(mSelectedDay);
    }
    return false;
}

From source file:com.kth.common.utils.etc.LogUtil.java

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

From source file:net.dian1.player.service.PlayerService.java

/**
 * Send changes to selected scrobbling application
 *///from   w  w  w . j  a va 2 s . c  o m
private void scrobblerMetaChanged() {
    PlaylistEntry entry = mPlayerEngine.getPlaylist().getSelectedTrack();

    if (entry != null) {
        String scrobblerApp = PreferenceManager.getDefaultSharedPreferences(PlayerService.this)
                .getString("scrobbler_app", "");
        assert (scrobblerApp.length() > 0);

        if (Log.isLoggable(Dian1Application.TAG, Log.INFO)) {
            Log.i(Dian1Application.TAG,
                    "Scrobbling track " + entry.getMusic().getName() + " via " + scrobblerApp);
        }

        if (scrobblerApp.equalsIgnoreCase("lastfm")) {
            Intent i = new Intent(LASTFM_INTENT);
            i.putExtra("artist", entry.getAlbum().getArtistName());
            i.putExtra("album", entry.getAlbum().getName());
            i.putExtra("track", entry.getMusic().getName());
            i.putExtra("duration", entry.getMusic().getDuration() * 1000); // duration in milliseconds
            sendBroadcast(i);
        } else if (scrobblerApp.equalsIgnoreCase("simplefm")) {
            Intent i = new Intent(SIMPLEFM_INTENT);
            i.putExtra("app-name", getResources().getString(R.string.app_name));
            i.putExtra("app-package", "net.dian1.player");
            i.putExtra("state", 0); // state 0 = START - track has started playing
            i.putExtra("artist", entry.getAlbum().getArtistName());
            i.putExtra("track", entry.getMusic().getName());
            i.putExtra("duration", entry.getMusic().getDuration()); // duration in seconds
            i.putExtra("album", entry.getAlbum().getName());
            i.putExtra("track-no", entry.getMusic().getNumAlbum());
            sendBroadcast(i);
        } else {
            // somehow the scrobbling app is not selected properly
        }
    }
}

From source file:com.ntsync.android.sync.syncadapter.SyncAdapter.java

private void performSync(Account account, Bundle extras, SyncResult syncResult,
        AccountSyncResult appSyncResult) {
    String authtoken = null;/*from ww  w  .  j a v  a2 s  .c om*/
    try {

        long contactSyncMarker = getContactSyncMarker(account);
        long contactGroupMarker = getContactGroupSyncMarker(account);
        SyncAnchor syncAnchor = new SyncAnchor();

        if (contactSyncMarker == 0) {
            // By default, contacts from a 3rd party provider are hidden
            // in the contacts list.
            ContactManager.setAccountContactsVisibility(mContext, account, true);

            // Add Default Group, otherwise group selection is not
            // visible
            // in the default editor.
            ContactManager.ensureSampleGroupExists(mContext, account);
        }

        authtoken = NetworkUtilities.blockingGetAuthToken(mAccountManager, account, null);
        if (authtoken == null) {
            syncResult.stats.numIoExceptions++;
            appSyncResult.setState(SyncResultState.AUTH_FAILED);
            return;
        }

        boolean getRestrictions = extras != null ? extras.containsKey(Constants.PARAM_GETRESTRICTIONS) : false;
        Restrictions restr = SyncUtils.getRestrictions(account, mAccountManager);
        if (restr == null || getRestrictions) {
            Restrictions oldRestr = restr;
            restr = NetworkUtilities.getRestrictions(mContext, account, authtoken, mAccountManager);
            processRestrictions(oldRestr, restr, account);
            // Return-Value is not processed because we don't have to
            // restart for a full sync because all relevant data values will
            // be read after here.
        }

        PrivateKeyState readyState = ClientKeyHelper.isReadyForSync(mContext, account, mAccountManager,
                authtoken);
        boolean retryLater = false;
        switch (readyState) {
        case AUTH_FAILED:
            retryLater = true;
            appSyncResult.setState(SyncResultState.AUTH_FAILED);
            break;
        case CHECK_FAILED:
            // Retry later -> delay sync
            retryLater = true;
            appSyncResult.setState(SyncResultState.SERVER_ERROR);
            break;
        case NETWORK_ERROR:
            appSyncResult.setState(SyncResultState.NETWORK_ERROR);
            appSyncResult.setErrorMsg(readyState.getErrorMsg());
            retryLater = true;
            break;
        case MISSING_KEY:
            sendMissingKey(account, authtoken, readyState.getCurrSalt());
            appSyncResult.setState(SyncResultState.MISSING_KEY);
            return;
        default:
            clearMissingKeyNotification(account);
            break;
        }
        if (retryLater) {
            syncResult.delayUntil = SYNC_RETRY_DELAY;
            syncResult.fullSyncRequested = true;
            return;
        }

        SecretKey privKey = ClientKeyHelper.getOrCreatePrivateKey(account, mAccountManager);

        authtoken = checkIfSaltSaved(account, authtoken);
        if (authtoken == null) {
            syncResult.stats.numIoExceptions++;
            appSyncResult.setState(SyncResultState.AUTH_FAILED);
            return;
        }

        // Update ClientMod if not already set.
        ContactManager.updateClientModDate(mContext, account);
        // Get local Dirty Groups
        List<ContactGroup> dirtyGroups = ContactManager.getDirtyGroups(mContext, account, restr);
        boolean syncContacts = true;
        if (!dirtyGroups.isEmpty()) {
            // sync only Groups if some new groups are available, to
            // make
            // sure, that ids are available
            for (ContactGroup contactGroup : dirtyGroups) {
                if (contactGroup.getSourceId() == null) {
                    syncContacts = false;
                    break;
                }
            }
        }
        syncAnchor.setAnchor(ContactConstants.TYPE_CONTACTGROUP, contactGroupMarker);

        List<RawContact> dirtyContacts = null;
        Map<Long, String> newIdMap = null;
        if (syncContacts) {

            // Get local Dirty contacts
            dirtyContacts = ContactManager.getDirtyContacts(mContext, account, restr,
                    new SyncRestConflictHandler(account.name));

            newIdMap = ContactManager.getNewIdMap(mContext, account);
            syncAnchor.setAnchor(ContactConstants.TYPE_CONTACT, contactSyncMarker);
        }

        // Send the dirty contacts to the server, and retrieve the
        // server-side changes
        String saltStr = ClientKeyHelper.getSalt(account, mAccountManager);
        boolean explizitPhotoSave = getExplicitSavePhoto(account);
        SyncResponse result = NetworkUtilities.syncContacts(account, authtoken, syncAnchor, dirtyContacts,
                dirtyGroups, privKey, mAccountManager, mContext, syncResult, saltStr, newIdMap, restr,
                explizitPhotoSave);

        if (result.newGroupIdMap != null && !result.newGroupIdMap.isEmpty()) {
            if (Log.isLoggable(TAG, Log.INFO)) {
                Log.i(TAG, "Calling contactManager's set new GroupIds. Count Updates:"
                        + result.newGroupIdMap.size());
            }

            ContactManager.saveGroupIds(mContext, account.name, result.newGroupIdMap);
        }
        if (result.newContactIdMap != null && !result.newContactIdMap.isEmpty()) {
            if (Log.isLoggable(TAG, Log.INFO)) {
                Log.i(TAG, "Calling contactManager's set new ContactIds. Count Updates:"
                        + result.newContactIdMap.size());
            }

            ContactManager.saveContactIds(mContext, account.name, result.newContactIdMap);
        }

        Set<Long> updatedGroupIds = null;
        if (result.serverGroups != null && !result.serverGroups.isEmpty()) {
            // Update the local groups database with the changes.
            if (Log.isLoggable(TAG, Log.INFO)) {
                Log.i(TAG,
                        "Calling contactManager's update groups. Count Updates:" + result.serverGroups.size());
            }
            updatedGroupIds = ContactManager.updateGroups(mContext, account.name, result.serverGroups);
        }
        Set<Long> updatedContactIds = null;
        if (result.serverContacts != null && !result.serverContacts.isEmpty()) {
            // Update the local contacts database with the changes.
            if (Log.isLoggable(TAG, Log.INFO)) {
                Log.i(TAG, "Calling contactManager's update contacts. Count Updates:"
                        + result.serverContacts.size());
            }
            updatedContactIds = ContactManager.updateContacts(mContext, account.name, result.serverContacts,
                    true, restr);
        }

        SyncAnchor newSyncAnchor = result.newServerAnchor;
        if (newSyncAnchor != null) {
            setContactSyncMarker(account, newSyncAnchor.getAnchor(ContactConstants.TYPE_CONTACT));
            setContactGroupSyncMarker(account, newSyncAnchor.getAnchor(ContactConstants.TYPE_CONTACTGROUP));
        }

        if (result.syncstate != null) {
            switch (result.syncstate) {
            case INVALID_KEY:
                // Reset Key-Info && do FullSync
                mAccountManager.invalidateAuthToken(Constants.ACCOUNT_TYPE, authtoken);
                ClientKeyHelper.clearPrivateKeyData(account, mAccountManager);
                ContactManager.setDirtyFlag(mContext, account);
                setContactSyncMarker(account, FULLSYNC_MARKER);
                setContactGroupSyncMarker(account, FULLSYNC_MARKER);
                syncResult.fullSyncRequested = true;
                appSyncResult.setState(SyncResultState.SUCCESS);
                return;
            case FORCE_FULLSYNC:
                ContactManager.setDirtyFlag(mContext, account);
                setContactSyncMarker(account, FULLSYNC_MARKER);
                setContactGroupSyncMarker(account, FULLSYNC_MARKER);
                syncResult.fullSyncRequested = true;
                appSyncResult.setState(SyncResultState.SUCCESS);
                return;
            default:
                LogHelper.logI(TAG, "Ignoring unknown SyncState:" + result.syncstate);
                break;
            }
        }

        boolean resync = processRestrictions(restr, result.restrictions, account);
        if (resync) {
            ContactManager.setDirtyFlag(mContext, account);
            syncResult.fullSyncRequested = true;
            appSyncResult.setState(SyncResultState.SUCCESS);
            return;
        }

        if (!dirtyGroups.isEmpty()) {
            ContactManager.clearGroupSyncFlags(mContext, dirtyGroups, result.newGroupIdMap, updatedGroupIds);
        }

        if (dirtyContacts != null && !dirtyContacts.isEmpty()) {
            ContactManager.clearSyncFlags(mContext, dirtyContacts, account.name, result.newContactIdMap,
                    updatedContactIds);
        }

        if (newIdMap != null && !newIdMap.isEmpty()) {
            ContactManager.clearServerId(mContext, newIdMap);
        }

        if (!syncContacts) {
            // if only groups were synced, restart for syncing contacts.
            syncResult.fullSyncRequested = true;
        }

        if (explizitPhotoSave) {
            // Clear Explizit Flag
            setExplicitSavePhoto(account, false);
        }

        appSyncResult.setState(SyncResultState.SUCCESS);
    } catch (final AuthenticatorException e) {
        LogHelper.logE(TAG, "AuthenticatorException", e);
        syncResult.stats.numParseExceptions++;
        setPrgErrorMsg(appSyncResult, e);
    } catch (final OperationCanceledException e) {
        LogHelper.logI(TAG, "OperationCanceledExcetpion", e);
        appSyncResult.setState(SyncResultState.AUTH_FAILED);
    } catch (final IOException e) {
        LogHelper.logE(TAG, "IOException", e);
        syncResult.stats.numIoExceptions++;
        setPrgErrorMsg(appSyncResult, e);
    } catch (final AuthenticationException e) {
        LogHelper.logI(TAG, "AuthenticationException", e);
        syncResult.stats.numAuthExceptions++;
        appSyncResult.setState(SyncResultState.AUTH_FAILED);
    } catch (final ParseException e) {
        LogHelper.logE(TAG, "ParseException", e);
        syncResult.stats.numParseExceptions++;
        setPrgErrorMsg(appSyncResult, e);
    } catch (InvalidKeyException e) {
        mAccountManager.invalidateAuthToken(Constants.ACCOUNT_TYPE, authtoken);
        ClientKeyHelper.clearPrivateKeyData(account, mAccountManager);
        LogHelper.logW(TAG, "InvalidKeyException", e);
        syncResult.stats.numAuthExceptions++;
    } catch (NetworkErrorException e) {
        syncResult.stats.numIoExceptions++;
        LogHelper.logWCause(TAG, "Sync failed because of a NetworkException", e);
        appSyncResult.setState(SyncResultState.NETWORK_ERROR);
        appSyncResult.setErrorMsg(String.format(getText(R.string.sync_network_error), e.getLocalizedMessage()));
    } catch (ServerException e) {
        syncResult.stats.numIoExceptions++;
        LogHelper.logWCause(TAG, "Sync failed because of a ServerException", e);
        appSyncResult.setState(SyncResultState.SERVER_ERROR);
        appSyncResult.setErrorMsg(getText(R.string.sync_server_error));
    } catch (OperationApplicationException e) {
        LogHelper.logW(TAG, "Sync failed because a DB-Operation failed", e);
        syncResult.databaseError = true;
        setPrgErrorMsg(appSyncResult, e);
    } catch (HeaderParseException e) {
        syncResult.stats.numIoExceptions++;
        LogHelper.logWCause(TAG, "Sync failed because of server reponse could not be parsed", e);
        setPrgErrorMsg(appSyncResult, e);
    } catch (HeaderCreateException e) {
        syncResult.databaseError = true;
        LogHelper.logE(TAG, "Sync failed because header could not be created", e);
        setPrgErrorMsg(appSyncResult, e);
    }
}

From source file:com.kth.common.utils.etc.LogUtil.java

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