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:br.com.bioscada.apps.biotracks.io.gdata.AndroidGDataClient.java

private InputStream createAndExecuteMethod(HttpRequestCreator creator, String uriString, String authToken)
        throws HttpException, IOException {

    HttpResponse response = null;// w  w w .ja v a2s  .  c o m
    int status = 500;
    int redirectsLeft = MAX_REDIRECTS;

    URI uri;
    try {
        uri = new URI(uriString);
    } catch (URISyntaxException use) {
        Log.w(TAG, "Unable to parse " + uriString + " as URI.", use);
        throw new IOException("Unable to parse " + uriString + " as URI: " + use.getMessage());
    }

    // we follow redirects ourselves, since we want to follow redirects even on
    // POSTs, which
    // the HTTP library does not do. following redirects ourselves also allows
    // us to log
    // the redirects using our own logging.
    while (redirectsLeft > 0) {

        HttpUriRequest request = creator.createRequest(uri);
        request.addHeader("User-Agent", "Android-GData");
        request.addHeader("Accept-Encoding", "gzip");

        // only add the auth token if not null (to allow for GData feeds that do
        // not require
        // authentication.)
        if (!TextUtils.isEmpty(authToken)) {
            request.addHeader("Authorization", "GoogleLogin auth=" + authToken);
        }
        if (DEBUG) {
            for (Header h : request.getAllHeaders()) {
                Log.v(TAG, h.getName() + ": " + h.getValue());
            }
            Log.d(TAG, "Executing " + request.getRequestLine().toString());
        }

        response = null;

        try {
            response = httpClient.execute(request);
        } catch (IOException ioe) {
            Log.w(TAG, "Unable to execute HTTP request." + ioe);
            throw ioe;
        }

        StatusLine statusLine = response.getStatusLine();
        if (statusLine == null) {
            Log.w(TAG, "StatusLine is null.");
            throw new NullPointerException("StatusLine is null -- should not happen.");
        }

        if (Log.isLoggable(TAG, Log.DEBUG)) {
            Log.d(TAG, response.getStatusLine().toString());
            for (Header h : response.getAllHeaders()) {
                Log.d(TAG, h.getName() + ": " + h.getValue());
            }
        }
        status = statusLine.getStatusCode();

        HttpEntity entity = response.getEntity();

        if ((status >= 200) && (status < 300) && entity != null) {
            return getUngzippedContent(entity);
        }

        // TODO: handle 301, 307?
        // TODO: let the http client handle the redirects, if we can be sure we'll
        // never get a
        // redirect on POST.
        if (status == 302) {
            // consume the content, so the connection can be closed.
            entity.consumeContent();
            Header location = response.getFirstHeader("Location");
            if (location == null) {
                if (Log.isLoggable(TAG, Log.DEBUG)) {
                    Log.d(TAG, "Redirect requested but no Location " + "specified.");
                }
                break;
            }
            if (Log.isLoggable(TAG, Log.DEBUG)) {
                Log.d(TAG, "Following redirect to " + location.getValue());
            }
            try {
                uri = new URI(location.getValue());
            } catch (URISyntaxException use) {
                if (Log.isLoggable(TAG, Log.DEBUG)) {
                    Log.d(TAG, "Unable to parse " + location.getValue() + " as URI.", use);
                    throw new IOException("Unable to parse " + location.getValue() + " as URI.");
                }
                break;
            }
            --redirectsLeft;
        } else {
            break;
        }
    }

    if (Log.isLoggable(TAG, Log.VERBOSE)) {
        Log.v(TAG, "Received " + status + " status code.");
    }
    String errorMessage = null;
    HttpEntity entity = response.getEntity();
    try {
        if (entity != null) {
            InputStream in = entity.getContent();
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            byte[] buf = new byte[8192];
            int bytesRead = -1;
            while ((bytesRead = in.read(buf)) != -1) {
                baos.write(buf, 0, bytesRead);
            }
            // TODO: use appropriate encoding, picked up from Content-Type.
            errorMessage = new String(baos.toByteArray());
            if (Log.isLoggable(TAG, Log.VERBOSE)) {
                Log.v(TAG, errorMessage);
            }
        }
    } finally {
        if (entity != null) {
            entity.consumeContent();
        }
    }
    String exceptionMessage = "Received " + status + " status code";
    if (errorMessage != null) {
        exceptionMessage += (": " + errorMessage);
    }
    throw new HttpException(exceptionMessage, status, null /* InputStream */);
}

From source file:com.wordpress.tonytam.avatar.AvatarWearActivity.java

@Override
protected void onResume() {
    super.onResume();
    if (mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_NORMAL)) {
        if (Log.isLoggable(TAG, Log.DEBUG)) {
            Log.d(TAG, "Successfully registered for the sensor updates");
        }//  ww w  . j  av a  2 s . c  om

    }
    // TODO:
    if (false) {
        if (mSensorManager.registerListener(this, mSensorAccelerometer, SensorManager.SENSOR_DELAY_NORMAL)) {
            if (Log.isLoggable(TAG, Log.DEBUG)) {
                Log.d(TAG, "Successfully registered for the sensor updates");
            }

        }
    }
}

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

private void maybeStartBleUnlockService() {
    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG, "Trying to open a Ble GATT server");
    }/*from  w w w  .jav a2 s.co m*/

    BluetoothManager btManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
    BluetoothGattServer mGattServer = btManager.openGattServer(this, new BluetoothGattServerCallback() {
        @Override
        public void onConnectionStateChange(BluetoothDevice device, int status, int newState) {
            super.onConnectionStateChange(device, status, newState);
        }
    });

    // The BLE stack is started up before the trust agent service, however Gatt capabilities
    // might not be ready just yet. Keep trying until a GattServer can open up before proceeding
    // to start the rest of the BLE services.
    if (mGattServer == null) {
        Log.e(TAG, "Gatt not available, will try again...in " + BLE_RETRY_MS + "ms");

        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                maybeStartBleUnlockService();
            }
        }, BLE_RETRY_MS);
    } else {
        mGattServer.close();
        if (Log.isLoggable(TAG, Log.DEBUG)) {
            Log.d(TAG, "GATT available, starting up UnlockService");
        }
        mCarUnlockService.start();
    }
}

From source file:jp.yojio.triplog.Common.DataApi.gdata.AndroidGDataClient.java

private InputStream createAndExecuteMethod(HttpRequestCreator creator, String uriString, String authToken)
        throws HttpException, IOException {

    HttpResponse response = null;/* w  ww. j a  v  a  2  s .c o m*/
    int status = 500;
    int redirectsLeft = MAX_REDIRECTS;

    URI uri;
    try {
        uri = new URI(uriString);
    } catch (URISyntaxException use) {
        Log.w(TAG, "Unable to parse " + uriString + " as URI.", use);
        throw new IOException("Unable to parse " + uriString + " as URI: " + use.getMessage());
    }

    // we follow redirects ourselves, since we want to follow redirects even on
    // POSTs, which
    // the HTTP library does not do. following redirects ourselves also allows
    // us to log
    // the redirects using our own logging.
    while (redirectsLeft > 0) {

        HttpUriRequest request = creator.createRequest(uri);
        request.addHeader("Accept-Encoding", "gzip");

        // only add the auth token if not null (to allow for GData feeds that do
        // not require
        // authentication.)
        if (!TextUtils.isEmpty(authToken)) {
            request.addHeader("Authorization", "GoogleLogin auth=" + authToken);
        }
        if (LOCAL_LOGV) {
            for (Header h : request.getAllHeaders()) {
                Log.v(TAG, h.getName() + ": " + h.getValue());
            }
            Log.d(TAG, "Executing " + request.getRequestLine().toString());
        }

        response = null;

        try {
            response = httpClient.execute(request);
        } catch (IOException ioe) {
            Log.w(TAG, "Unable to execute HTTP request." + ioe);
            throw ioe;
        }

        StatusLine statusLine = response.getStatusLine();
        if (statusLine == null) {
            Log.w(TAG, "StatusLine is null.");
            throw new NullPointerException("StatusLine is null -- should not happen.");
        }

        if (Log.isLoggable(TAG, Log.DEBUG)) {
            Log.d(TAG, response.getStatusLine().toString());
            for (Header h : response.getAllHeaders()) {
                Log.d(TAG, h.getName() + ": " + h.getValue());
            }
        }
        status = statusLine.getStatusCode();

        HttpEntity entity = response.getEntity();

        if ((status >= 200) && (status < 300) && entity != null) {
            return getUngzippedContent(entity);
        }

        // TODO: handle 301, 307?
        // TODO: let the http client handle the redirects, if we can be sure we'll
        // never get a
        // redirect on POST.
        if (status == 302) {
            // consume the content, so the connection can be closed.
            entity.consumeContent();
            Header location = response.getFirstHeader("Location");
            if (location == null) {
                if (Log.isLoggable(TAG, Log.DEBUG)) {
                    Log.d(TAG, "Redirect requested but no Location " + "specified.");
                }
                break;
            }
            if (Log.isLoggable(TAG, Log.DEBUG)) {
                Log.d(TAG, "Following redirect to " + location.getValue());
            }
            try {
                uri = new URI(location.getValue());
            } catch (URISyntaxException use) {
                if (Log.isLoggable(TAG, Log.DEBUG)) {
                    Log.d(TAG, "Unable to parse " + location.getValue() + " as URI.", use);
                    throw new IOException("Unable to parse " + location.getValue() + " as URI.");
                }
                break;
            }
            --redirectsLeft;
        } else {
            break;
        }
    }

    if (Log.isLoggable(TAG, Log.VERBOSE)) {
        Log.v(TAG, "Received " + status + " status code.");
    }
    String errorMessage = null;
    HttpEntity entity = response.getEntity();
    try {
        if (response != null && entity != null) {
            InputStream in = entity.getContent();
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            byte[] buf = new byte[8192];
            int bytesRead = -1;
            while ((bytesRead = in.read(buf)) != -1) {
                baos.write(buf, 0, bytesRead);
            }
            // TODO: use appropriate encoding, picked up from Content-Type.
            errorMessage = new String(baos.toByteArray());
            if (Log.isLoggable(TAG, Log.VERBOSE)) {
                Log.v(TAG, errorMessage);
            }
        }
    } finally {
        if (entity != null) {
            entity.consumeContent();
        }
    }
    String exceptionMessage = "Received " + status + " status code";
    if (errorMessage != null) {
        exceptionMessage += (": " + errorMessage);
    }
    throw new HttpException(exceptionMessage, status, null /* InputStream */);
}

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

/**
 * Returns the position of the center of the thumb that correlates to the current {@link #value}.
 *
 * @param paddingLeft left padding of this slider
 * @param paddingRight right padding of this slider
 * @return position of the center of the thumb
 *//* w ww  .  j av  a2s  .  com*/
private float positionFromValue(int paddingLeft, int paddingRight) {
    if (valueSet != null) {
        // Calculate for a value set: find the index of the value. We are finding the index of the first entry
        // which is larger than or equal to the value. The value _should_ always be an entry of the index, though.
        for (int no = 0; no < valueSet.length; no++) {
            if (value <= valueSet[no]) {
                if (Log.isLoggable("Wa-Tor", Log.DEBUG)) {
                    Log.d("Wa-Tor", "Found current value " + value + " @ position " + no);
                }
                return (getWidth() - paddingLeft - paddingRight - thumbSize) * ((float) no)
                        / (valueSet.length - 1) + paddingLeft + thumbSize / 2;
            }
        }
        return paddingLeft + thumbSize / 2;
    }

    // Calculate for a linear range
    return (getWidth() - paddingLeft - paddingRight - thumbSize) * ((float) value - minValue)
            / (maxValue - minValue) + paddingLeft + thumbSize / 2;
}

From source file:com.ameron32.apps.tapnotes._unused.original.LoginActivity.java

private Bundle getMergedOptions() {
    // Read activity metadata from AndroidManifest.xml
    ActivityInfo activityInfo = null;/*from ww  w . j  ava  2  s  .c  om*/
    try {
        activityInfo = getPackageManager().getActivityInfo(this.getComponentName(),
                PackageManager.GET_META_DATA);
    } catch (NameNotFoundException e) {
        if (Parse.getLogLevel() <= Parse.LOG_LEVEL_ERROR && Log.isLoggable(LOG_TAG, Log.WARN)) {
            Log.w(LOG_TAG, e.getMessage());
        }
    }

    // The options specified in the Intent (from ParseLoginBuilder) will
    // override any duplicate options specified in the activity metadata
    Bundle mergedOptions = new Bundle();
    if (activityInfo != null && activityInfo.metaData != null) {
        mergedOptions.putAll(activityInfo.metaData);
    }
    if (getIntent().getExtras() != null) {
        mergedOptions.putAll(getIntent().getExtras());
    }

    return mergedOptions;
}

From source file:com.infine.android.devoxx.service.RestService.java

/**
 * Charge les fichiers de donnees statiques
 * /*from   w  w  w. j av  a2  s . c  om*/
 * @throws HandlerException
 */
private void loadStaticFiles() throws HandlerException {
    final long startLocal = System.currentTimeMillis();
    // final boolean localParse = localVersion < latestVersion;
    // if (localParse || localVersion == VERSION_NONE) {
    // Load static local data
    // chargement des blocks
    mLocalExecutor.execute(R.raw.schedule,
            new JsonScheduleHandler(mApplicationContext, PREFS_SCHEDULE_VERSION, 0));
    // chargement des sessions
    mLocalExecutor.execute(R.raw.session,
            new JsonSessionHandler(mApplicationContext, PREFS_SESSION_VERSION, 0));
    // Room loading
    mLocalExecutor.execute(R.raw.room, new JsonRoomHandler());
    // Speaker loading
    mLocalExecutor.execute(R.raw.speaker,
            new JsonSpeakerHandler(mApplicationContext, PREFS_SPEAKER_VERSION, 0));

    // Save local parsed version
    // if (localVersion > VERSION_NONE) {
    // prefs.edit().putInt(Prefs.LOCAL_VERSION, latestVersion).commit();
    // }
    // }
    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG, "local sync took " + (System.currentTimeMillis() - startLocal) + "ms");
    }
}

From source file:com.parse.starter.ParseLoginActivity.java

/**
 * @see android.app.Activity#isDestroyed()
 *///  ww  w  . j  a  va  2  s.c  o  m
//  @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1)
//  @Override
//  public boolean isDestroyed() {
//    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
//      return super.isDestroyed();
//    }
//    return destroyed;
//  }

private Bundle getMergedOptions() {
    // Read activity metadata from AndroidManifest.xml
    ActivityInfo activityInfo = null;
    try {
        activityInfo = getPackageManager().getActivityInfo(this.getComponentName(),
                PackageManager.GET_META_DATA);
    } catch (NameNotFoundException e) {
        if (Parse.getLogLevel() <= Parse.LOG_LEVEL_ERROR && Log.isLoggable(LOG_TAG, Log.WARN)) {
            Log.w(LOG_TAG, e.getMessage());
        }
    }

    // The options specified in the Intent (from ParseLoginBuilder) will
    // override any duplicate options specified in the activity metadata
    Bundle mergedOptions = new Bundle();
    if (activityInfo != null && activityInfo.metaData != null) {
        mergedOptions.putAll(activityInfo.metaData);
    }
    if (getIntent().getExtras() != null) {
        mergedOptions.putAll(getIntent().getExtras());
    }

    return mergedOptions;
}

From source file:com.example.android.jumpingjack.MainActivity.java

/**
 * Resets the FLAG_KEEP_SCREEN_ON flag so activity can go into background.
 *///from  w w  w. j a v a  2 s. com
private void resetFlag() {
    mHandler.post(new Runnable() {
        @Override
        public void run() {
            if (Log.isLoggable(TAG, Log.DEBUG)) {
                Log.d(TAG, "Resetting FLAG_KEEP_SCREEN_ON flag to allow going to background");
            }
            getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
            finish();
        }
    });
}

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

@VisibleForTesting
void updatePinned() {
    final List<ShortcutInfo> updates = new ArrayList<>();
    final List<String> removedIds = new ArrayList<>();
    final List<String> enable = new ArrayList<>();

    for (ShortcutInfo shortcut : mShortcutManager.getPinnedShortcuts()) {
        final PersistableBundle extras = shortcut.getExtras();

        if (extras == null
                || extras.getInt(EXTRA_SHORTCUT_TYPE, SHORTCUT_TYPE_UNKNOWN) != SHORTCUT_TYPE_CONTACT_URI) {
            continue;
        }/*from   w  ww . ja  v a  2 s  .co m*/

        // The contact ID may have changed but that's OK because it is just an optimization
        final long contactId = extras.getLong(Contacts._ID);

        final ShortcutInfo update = createShortcutForUri(Contacts.getLookupUri(contactId, shortcut.getId()));
        if (update != null) {
            updates.add(update);
            if (!shortcut.isEnabled()) {
                // Handle the case that a contact is disabled because it doesn't exist but
                // later is created (for instance by a sync)
                enable.add(update.getId());
            }
        } else if (shortcut.isEnabled()) {
            removedIds.add(shortcut.getId());
        }
    }

    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG, "updating " + updates);
        Log.d(TAG, "enabling " + enable);
        Log.d(TAG, "disabling " + removedIds);
    }

    mShortcutManager.updateShortcuts(updates);
    mShortcutManager.enableShortcuts(enable);
    mShortcutManager.disableShortcuts(removedIds,
            mContext.getString(R.string.dynamic_shortcut_contact_removed_message));
}