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.example.android.wearable.mjpegviewwear.MainActivity.java

/**
 * As simple wrapper around Log.d//from w w  w .  j  a  v  a  2  s.  com
 */
private static void LOGD(final String tag, String message) {
    if (Log.isLoggable(tag, Log.DEBUG)) {
        Log.d(tag, message);
    }
}

From source file:org.ametro.app.ApplicationEx.java

private HttpClient createHttpClient() {
    if (Log.isLoggable(Constants.LOG_TAG_MAIN, Log.DEBUG)) {
        Log.d(Constants.LOG_TAG_MAIN, "Create HTTP client");
    }//from ww w  .j  a  v  a  2 s. c o  m
    HttpParams params = new BasicHttpParams();
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params, HTTP.DEFAULT_CONTENT_CHARSET);
    HttpProtocolParams.setUseExpectContinue(params, true);
    HttpConnectionParams.setConnectionTimeout(params, HTTP_CONNECTION_TIMEOUT);
    HttpConnectionParams.setSoTimeout(params, HTTP_SOCKET_TIMEOUT);

    SchemeRegistry schReg = new SchemeRegistry();
    schReg.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    schReg.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
    ClientConnectionManager conMgr = new ThreadSafeClientConnManager(params, schReg);
    return new DefaultHttpClient(conMgr, params);
}

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

/**
 * Performs authentication if necessary, then exchange the data with the
 * server and returns the response/*from  w ww .j  a  v  a  2  s .  c  o  m*/
 * 
 * @param request
 * @return The response to the request, null if none
 * @throws IOException
 * @throws OperationCanceledException
 * @throws AuthenticatorException
 */
public GatewayResponseData exchangeWithServer(final GatewayRequestData request)
        throws IOException, OperationCanceledException, AuthenticatorException {
    final int maxRetries = 10;
    for (int retry = 0; retry < maxRetries; retry++) {
        if (!hasSacsidToken()) {
            /* Gets a Google Auth Token and promotes it to a SACSID Token */
            final GoogleAuthToken googleAuthToken = blockingGetNewAuthToken();
            try {
                promoteToken(googleAuthToken);
            } catch (final InvalidGoogleAuthTokenException e) {
                if (Log.isLoggable(TAG, Log.WARN))
                    Log.w(TAG, "The google auth token is invalid. Refreshing all cookies. ", e);
                invalidatesGoogleAuthToken(googleAuthToken);
                clearSacsidToken();
                continue;
            }
        }
        /* Executes the query */
        try {
            return postData(request);
        } catch (final AuthenticationTokenExpired e) {
            clearSacsidToken();
            if (Log.isLoggable(TAG, Log.WARN))
                Log.w(TAG, "Google and/or SACSID tokens expired. Retried " + retry + " times.", e);
            continue;
        }
    }
    final String failureMessage = "Failed to get valid Google and SACSID tokens !";
    if (Log.isLoggable(TAG, Log.ERROR))
        Log.e(TAG, failureMessage);
    throw new AuthenticatorException(failureMessage);
}

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

@Override
public void onEscrowTokenAdded(byte[] token, long handle, UserHandle user) {
    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG, "onEscrowTokenAdded, handle: " + handle);
    }/*  w  w w .j a v a  2  s . co m*/

    Intent intent = new Intent();
    intent.setAction(ACTION_ADD_TOKEN_RESULT);
    intent.putExtra(INTENT_EXTRA_TOKEN_HANDLE, handle);

    mLocalBroadcastManager.sendBroadcast(intent);
}

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

public void saveToContact() {
    String address = mMsgFrom;//w  w  w  .ja  v a2s  .  co m
    if (TextUtils.isEmpty(address)) {
        if (LogTag.VERBOSE || Log.isLoggable(LogTag.APP, Log.VERBOSE)) {
            Log.v(TAG, "  saveToContact fail for null address! ");
        }
        return;
    }

    // address must be a single recipient
    Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
    intent.setType(Contacts.CONTENT_ITEM_TYPE);
    if (Mms.isEmailAddress(address)) {
        intent.putExtra(ContactsContract.Intents.Insert.EMAIL, address);
    } else {
        intent.putExtra(ContactsContract.Intents.Insert.PHONE, address);
        intent.putExtra(ContactsContract.Intents.Insert.PHONE_TYPE,
                ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE);
    }
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
    this.startActivity(intent);
}

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

private static PercentLayoutInfo setTextSizeSupportVal(TypedArray array, PercentLayoutInfo info) {
    //textSizePercent 
    PercentLayoutInfo.PercentVal percentVal = getPercentVal(array,
            com.zhy.android.percent.support.R.styleable.PercentLayout_Layout_layout_textSizePercent, false);
    if (percentVal != null) {
        if (Log.isLoggable(TAG, Log.VERBOSE)) {
            Log.v(TAG, "percent text size: " + percentVal.percent);
        }//from   w  w  w  .j ava2 s  .  c  o m
        info = checkForInfoExists(info);
        info.textSizePercent = percentVal;
    }

    return info;
}

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

private static PercentLayoutInfo setWidthAndHeightVal(TypedArray array, PercentLayoutInfo info) {
    PercentLayoutInfo.PercentVal percentVal = getPercentVal(array,
            R.styleable.PercentLayout_Layout_layout_widthPercent, true);
    if (percentVal != null) {
        if (Log.isLoggable(TAG, Log.VERBOSE)) {
            Log.v(TAG, "percent width: " + percentVal.percent);
        }/* ww w .  j a  v  a  2s. c  o  m*/
        info = checkForInfoExists(info);
        info.widthPercent = percentVal;
    }
    percentVal = getPercentVal(array, 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.github.vseguip.sweet.rest.SugarRestAPI.java

@Override
/** {@inheritDoc} */
public List<ISweetContact> getNewerContacts(String token, String date, int start, int count)
        throws IOException, AuthenticationException {
    final HttpResponse resp;
    Log.i(TAG, "getNewerContacts()");

    JSONArray jso_array = new JSONArray();
    JSONArray jso_fields = new JSONArray();
    // TODO: add newer fields (adress and other phones)
    jso_fields.put(SUGARCRM_CONTACT_ID_FIELD).put(SUGARCRM_FIRST_NAME_FIELD).put(SUGARCRM_LAST_NAME_FIELD)
            .put(SUGARCRM_TITLE_FIELD).put(SUGARCRM_ACCOUNT_NAME_FIELD).put(SUGARCRM_ACCOUNT_ID_FIELD)
            .put(SUGARCRM_EMAIL1_FIELD).put(SUGARCRM_PHONE_WORK_FIELD).put(SUGARCRM_PHONE_MOBILE_FIELD)
            .put(SUGARCRM_FAX_WORK_FIELD).put(SUGARCRM_STREET_FIELD).put(SUGARCRM_CITY_FIELD)
            .put(SUGARCRM_STATE_FIELD).put(SUGARCRM_POSTAL_CODE_FIELD).put(SUGARCRM_COUNTRY_FIELD)
            .put(SUGARCRM_DATE_MODIFIED_FIELD);
    String sugar_query = SUGAR_CONTACTS_QUERY;
    if (date != null)
        sugar_query = "(contacts.date_modified >= '" + date + "')";
    jso_array.put(token).put(SUGAR_MODULE_CONTACTS).put(sugar_query).put(SUGAR_CONTACTS_ORDER_BY).put(start)
            .put(jso_fields).put(SUGAR_CONTACT_LINK_NAMES).put(count).put(0);

    final HttpPost post = prepareJSONRequest(jso_array.toString(), GET_METHOD);
    HttpClient httpClient = getConnection();
    Log.i(TAG, "Sending request");
    resp = httpClient.execute(post);//from  w  w w  .  ja  v  a2s  . co m
    Log.i(TAG, "Got response");
    if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
        if (Log.isLoggable(TAG, Log.VERBOSE)) {
            Log.v(TAG, "Successful authentication");
        }
        Log.i(TAG, "Buffering request");
        List<ISweetContact> contacts = new ArrayList<ISweetContact>();
        String message = getResponseString(resp);
        JSONArray result;
        JSONObject json = null;
        try {
            Log.i(TAG, "Parsing response");
            json = (JSONObject) new JSONTokener(message).nextValue();
            result = json.getJSONArray("entry_list");
            Log.i(TAG, "Creating contact objects");
            for (int i = 0; i < result.length(); i++) {
                try {
                    // ID, first name and last name are compulsory, the rest
                    // can be skipped
                    JSONObject entrada = result.getJSONObject(i).getJSONObject("name_value_list");
                    contacts.add(new SweetContact(
                            getJSONString(entrada.getJSONObject(SUGARCRM_CONTACT_ID_FIELD).getString("value")),
                            getJSONString(entrada.getJSONObject(SUGARCRM_FIRST_NAME_FIELD).getString("value")),
                            getJSONString(entrada.getJSONObject(SUGARCRM_LAST_NAME_FIELD).getString("value")),
                            getSugarValue(entrada, SUGARCRM_TITLE_FIELD, ""),
                            getSugarValue(entrada, SUGARCRM_ACCOUNT_NAME_FIELD, ""),
                            getSugarValue(entrada, SUGARCRM_ACCOUNT_ID_FIELD, ""),
                            getSugarValue(entrada, SUGARCRM_EMAIL1_FIELD, ""),
                            getSugarValue(entrada, SUGARCRM_PHONE_WORK_FIELD, ""),
                            getSugarValue(entrada, SUGARCRM_PHONE_MOBILE_FIELD, ""),
                            getSugarValue(entrada, SUGARCRM_FAX_WORK_FIELD, ""),
                            getSugarValue(entrada, SUGARCRM_STREET_FIELD, ""),
                            getSugarValue(entrada, SUGARCRM_CITY_FIELD, ""),
                            getSugarValue(entrada, SUGARCRM_STATE_FIELD, ""),
                            getSugarValue(entrada, SUGARCRM_POSTAL_CODE_FIELD, ""),
                            getSugarValue(entrada, SUGARCRM_COUNTRY_FIELD, ""),
                            getSugarValue(entrada, SUGARCRM_DATE_MODIFIED_FIELD, "")));
                } catch (Exception ex) {
                    ex.printStackTrace();
                    Log.e(TAG, "Unknown error parsing, skipping entry");
                }
            }

            return contacts;
        } catch (Exception e) {
            if (json != null) {
                Log.i(TAG, "Error parsing json in getNewerContacts. Auth invalid");
                try {

                    throw new AuthenticationException(json.getString("description"));
                } catch (JSONException ex) {
                    throw new AuthenticationException("Invalid session");
                }
            }
        } finally {
            httpClient.getConnectionManager().closeIdleConnections(100, TimeUnit.MILLISECONDS);
        }
    } else {
        Log.v(TAG, "Error authenticating" + resp.getStatusLine());
        throw new AuthenticationException("Invalid session");
    }
    return null;
}

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

/**
 * Callback received when a permissions request has been completed.
 *///from  w  w w . ja  v a 2s. c o m
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
        @NonNull int[] grantResults) {

    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG, "onRequestPermissionsResult(): " + permissions);
    }

    if (requestCode == REQUEST_CALENDAR_AND_CONTACTS) {
        // BEGIN_INCLUDE(permissions_result)
        // Received permission result for calendar permission.
        Log.i(TAG, "Received response for Calendar permission request.");

        // Check if all required permissions have been granted.
        if ((grantResults.length == 2) && (grantResults[0] == PackageManager.PERMISSION_GRANTED)
                && (grantResults[1] == PackageManager.PERMISSION_GRANTED)) {
            // Calendar/Contact permissions have been granted, pull all calendar events
            Log.i(TAG, "All permission has now been granted. Showing preview.");
            Snackbar.make(mLayout, R.string.permisions_granted, Snackbar.LENGTH_SHORT).show();

            pushCalendarToWear();

        } else {
            Log.i(TAG, "CALENDAR and/or CONTACT permissions were NOT granted.");
            Snackbar.make(mLayout, R.string.permissions_denied, Snackbar.LENGTH_SHORT).show();
        }
        // END_INCLUDE(permissions_result)

    } else {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    }
}

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

public final void unbind() {
    if (Log.isLoggable(LogTag.CONTACT, Log.DEBUG)) {
        Log.v(TAG, "unbind: contacts.removeListeners " + this);
    }//from www  .j  av  a2  s  .  c  o  m
    // Unregister contact update callbacks.
    Contact.removeListener(this);
}