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.xandy.calendar.month.SimpleDayPickerFragment.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 time The time to move to/*from   w  w w .j  a v  a 2  s .  c  o m*/
 * @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(long time, boolean animate, boolean setSelected, boolean forceScroll) {
    if (time == -1) {
        Log.e(TAG, "time is invalid");
        return false;
    }

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

    // If this view isn't returned yet we won't be able to load the lists
    // current position, so return after setting the selected day.
    if (!isResumed()) {
        if (Log.isLoggable(TAG, Log.DEBUG)) {
            Log.d(TAG, "We're not visible yet");
        }
        return false;
    }

    mTempTime.set(time);
    long millis = mTempTime.normalize(true);
    // Get the week we're going to
    // TODO push Util function into Calendar public api.
    int position = Utils.getWeeksSinceEpochFromJulianDay(Time.getJulianDay(millis, mTempTime.gmtoff),
            mFirstDayOfWeek);

    View child;
    int i = 0;
    int top = 0;
    // Find a child that's completely in the view
    do {
        child = mListView.getChildAt(i++);
        if (child == null) {
            break;
        }
        top = child.getTop();
        if (Log.isLoggable(TAG, Log.DEBUG)) {
            Log.d(TAG, "child at " + (i - 1) + " has top " + top);
        }
    } while (top < 0);

    // Compute the first and last position visible
    int firstPosition;
    if (child != null) {
        firstPosition = mListView.getPositionForView(child);
    } else {
        firstPosition = 0;
    }
    int lastPosition = firstPosition + mNumWeeks - 1;
    if (top > BOTTOM_BUFFER) {
        lastPosition--;
    }

    if (setSelected) {
        mAdapter.setSelectedDay(mSelectedDay);
    }

    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 < firstPosition || position > lastPosition || forceScroll) {
        mFirstDayOfMonth.set(mTempTime);
        mFirstDayOfMonth.monthDay = 1;
        millis = mFirstDayOfMonth.normalize(true);
        setMonthDisplayed(mFirstDayOfMonth, true);
        position = Utils.getWeeksSinceEpochFromJulianDay(Time.getJulianDay(millis, mFirstDayOfMonth.gmtoff),
                mFirstDayOfWeek);

        mPreviousScrollState = OnScrollListener.SCROLL_STATE_FLING;
        if (animate) {
            mListView.smoothScrollToPositionFromTop(position, LIST_TOP_OFFSET, GOTO_SCROLL_DURATION);
            return true;
        } else {
            mListView.setSelectionFromTop(position, LIST_TOP_OFFSET);
            // Perform any after scroll operations that are needed
            onScrollStateChanged(mListView, OnScrollListener.SCROLL_STATE_IDLE);
        }
    } else if (setSelected) {
        // Otherwise just set the selection
        setMonthDisplayed(mSelectedDay, true);
    }
    return false;
}

From source file:com.google.android.gms.common.zze.java

public static boolean zzf(Context context, int i) {
    boolean z = false;
    if (!zzb(context, i, GOOGLE_PLAY_SERVICES_PACKAGE)) {
        return z;
    }/*from w  w w .j a va  2s .  c  o m*/
    try {
        return zzf.zzoO().zza(context.getPackageManager(),
                context.getPackageManager().getPackageInfo(GOOGLE_PLAY_SERVICES_PACKAGE, 64));
    } catch (NameNotFoundException e) {
        if (!Log.isLoggable("GooglePlayServicesUtil", 3)) {
            return z;
        }
        Log.d("GooglePlayServicesUtil",
                "Package manager can't find google play services package, defaulting to false");
        return z;
    }
}

From source file:com.ntsync.android.sync.activities.ShopActivity.java

@Override
protected void onResumeFragments() {
    super.onResumeFragments();
    // Process a PaymentResult from onActivityResult
    if (paymentResult != null) {
        int resultCode = paymentResult.resultCode;
        PaymentConfirmation confirm = paymentResult.confirmation;
        paymentResult = null;//from ww  w.  j  av  a  2s .  c om
        if (resultCode == Activity.RESULT_OK && confirm != null) {
            if (selectedPriceId == null) {
                MessageDialog.show(R.string.shop_activity_missingprice, this);
                return;
            }

            JSONObject paymentJson = confirm.toJSONObject();
            // Save Payment, so that payment can be verified later.
            Account account = new Account(accountName, Constants.ACCOUNT_TYPE);
            AccountManager accountManager = AccountManager.get(this);
            SyncUtils.savePayment(account, accountManager, paymentJson, selectedPriceId);

            SyncUtils.startPaymentVerification();
            // Start Timer to verify Payment if Verification could not be
            // done now.
            PaymentVerificationService.startVerificationTimer(getApplicationContext());

            // Send Confirmation to server
            boolean verifStarted = false;
            try {
                String jsonData = paymentJson.toString(1);
                VerifyPaymentProgressDialog progressDialog = VerifyPaymentProgressDialog
                        .newInstance(selectedPriceId, jsonData, accountName);
                progressDialog.show(this.getSupportFragmentManager(), "VerifyPaymentProgressDialog");
                if (Log.isLoggable(TAG, Log.DEBUG)) {
                    Log.d(TAG, "PaymentConfirmation: " + jsonData);
                }
                verifStarted = true;
            } catch (JSONException e) {
                MessageDialog.show(R.string.shop_activity_invalidsyntax, this);
                Log.e(TAG, "Failed to convert Payment to JSON.", e);
                SyncUtils.savePayment(account, accountManager, null, null);
            } finally {
                if (!verifStarted) {
                    SyncUtils.stopPaymentVerification();
                }
            }
        } else if (resultCode == Activity.RESULT_CANCELED) {
            Log.i(TAG, "The user canceled the payment-flow");
        } else if (resultCode == PaymentActivity.RESULT_PAYMENT_INVALID) {
            MessageDialog.show(R.string.shop_activity_invalidpayment, this);
            Log.i(TAG, "An invalid payment was submitted.");
        } else {
            MessageDialog.show(R.string.shop_activity_invalidpayment, this);
            Log.e(TAG, "PaymentResult is unknown. Result:" + resultCode + " Confirmation:" + confirm);
        }
    }
    getSupportLoaderManager().initLoader(LOADID_PRICES, null, this);
    View progressBar = findViewById(R.id.progressBar);
    View reloadBtn = findViewById(R.id.reloadBtn);
    reloadBtn.setVisibility(View.GONE);
    progressBar.setVisibility(View.VISIBLE);
    getListView().setEmptyView(progressBar);

    // Show a Message from a delayed Verification
    String msg = getIntent().getStringExtra(PARM_MSG);
    if (msg != null) {
        MessageDialog.show(msg, this);
        getIntent().removeExtra(PARM_MSG);
    }
}

From source file:br.com.bioscada.apps.biotracks.io.gdata.AndroidGDataClient.java

private HttpEntity createEntityForEntry(GDataSerializer entry, int format) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {/*from ww w.  j a va 2 s  .  c o m*/
        entry.serialize(baos, format);
    } catch (IOException ioe) {
        Log.e(TAG, "Unable to serialize entry.", ioe);
        throw ioe;
    } catch (ParseException pe) {
        Log.e(TAG, "Unable to serialize entry.", pe);
        throw new IOException("Unable to serialize entry: " + pe.getMessage());
    }

    byte[] entryBytes = baos.toByteArray();

    if (entryBytes != null && Log.isLoggable(TAG, Log.DEBUG)) {
        try {
            Log.d(TAG, "Serialized entry: " + new String(entryBytes, "UTF-8"));
        } catch (UnsupportedEncodingException uee) {
            // should not happen
            throw new IllegalStateException("UTF-8 should be supported!", uee);
        }
    }

    AbstractHttpEntity entity = new ByteArrayEntity(entryBytes);
    entity.setContentType(entry.getContentType());
    return entity;
}

From source file:com.android.calendar.month.SimpleDayPickerFragment.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 time/*from  w ww. j  a va  2  s. c o  m*/
 *            The time to move to
 * @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(long time, boolean animate, boolean setSelected, boolean forceScroll) {
    if (time == -1) {
        Log.e(TAG, "time is invalid");
        return false;
    }

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

    // If this view isn't returned yet we won't be able to load the lists
    // current position, so return after setting the selected day.
    if (!isResumed()) {
        if (Log.isLoggable(TAG, Log.DEBUG)) {
            Log.d(TAG, "We're not visible yet");
        }
        return false;
    }

    mTempTime.set(time);
    long millis = mTempTime.normalize(true);
    // Get the week we're going to
    // TODO push Util function into Calendar public api.
    int position = Utils.getWeeksSinceEpochFromJulianDay(Time.getJulianDay(millis, mTempTime.gmtoff),
            mFirstDayOfWeek);

    View child;
    int i = 0;
    int top = 0;
    // Find a child that's completely in the view
    do {
        child = mListView.getChildAt(i++);
        if (child == null) {
            break;
        }
        top = child.getTop();
        if (Log.isLoggable(TAG, Log.DEBUG)) {
            Log.d(TAG, "child at " + (i - 1) + " has top " + top);
        }
    } while (top < 0);

    // Compute the first and last position visible
    int firstPosition;
    if (child != null) {
        firstPosition = mListView.getPositionForView(child);
    } else {
        firstPosition = 0;
    }
    int lastPosition = firstPosition + mNumWeeks - 1;
    if (top > BOTTOM_BUFFER) {
        lastPosition--;
    }

    if (setSelected) {
        mAdapter.setSelectedDay(mSelectedDay);
    }

    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 < firstPosition || position > lastPosition || forceScroll) {
        JalaliDate jDate = Jalali.gregorianToJalali(mTempTime);
        jDate.day = 1;
        mFirstDayOfMonth.set(Jalali.jalaliToGregorianTime(jDate));
        mFirstDayOfMonth.normalize(true);
        setMonthDisplayed(mFirstDayOfMonth, jDate.month - 1, true);
        position = Utils.getWeeksSinceEpochFromJulianDay(
                Time.getJulianDay(Jalali.jalaliToGregorianTime(jDate).toMillis(true), mFirstDayOfMonth.gmtoff),
                mFirstDayOfWeek);

        mPreviousScrollState = OnScrollListener.SCROLL_STATE_FLING;
        if (animate) {
            mListView.smoothScrollToPositionFromTop(position, LIST_TOP_OFFSET, GOTO_SCROLL_DURATION);
            return true;
        } else {
            mListView.setSelectionFromTop(position, LIST_TOP_OFFSET);
            // Perform any after scroll operations that are needed
            onScrollStateChanged(mListView, OnScrollListener.SCROLL_STATE_IDLE);
        }
    } else if (setSelected) {
        // Otherwise just set the selection
        setMonthDisplayed(mSelectedDay, Jalali.gregorianToJalali(mSelectedDay).month - 1, true);
    }
    return false;
}

From source file:com.samsung.richnotification.RichNotification.java

@Override
public void onDestroy() {
    super.onDestroy();
    if (richRemoteInputReceiver != null) {
        try {/* w  w  w.  j av  a 2 s  .c om*/
            this.cordova.getActivity().unregisterReceiver(richRemoteInputReceiver);
            richRemoteInputReceiver = null;
        } catch (IllegalArgumentException e) {
            //not an error case
            if (Log.isLoggable(RICHNOTI, Log.DEBUG))
                Log.d(TAG, "unregistering receiver in onDestroy: " + e.getMessage());
            e.printStackTrace();
        }
    }
}

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

private void getServerPhotos(SyncContext context, String feedUrl, int maxDownloads, GDataSyncData syncData,
        SyncResult syncResult) {/*from  w w  w .  ja v  a 2  s  . co  m*/
    final ContentResolver cr = getContext().getContentResolver();
    Cursor cursor = cr.query(Photos.CONTENT_URI,
            new String[] { Photos._SYNC_ID, Photos._SYNC_VERSION, Photos.PERSON_ID, Photos.DOWNLOAD_REQUIRED,
                    Photos._ID },
            "" + "_sync_account=? AND download_required != 0", new String[] { getAccount() }, null);
    try {
        int numFetched = 0;
        while (cursor.moveToNext()) {
            if (numFetched >= maxDownloads) {
                break;
            }
            String photoSyncId = cursor.getString(0);
            String photoVersion = cursor.getString(1);
            long person = cursor.getLong(2);
            String photoUrl = feedUrl + "/" + photoSyncId;
            long photoId = cursor.getLong(4);

            try {
                context.setStatusText("Downloading photo " + photoSyncId);
                ++numFetched;
                ++mPhotoDownloads;
                InputStream inputStream = mContactsClient.getMediaEntryAsStream(photoUrl, getAuthToken());
                savePhoto(person, inputStream, photoVersion);
                syncResult.stats.numUpdates++;
            } catch (IOException e) {
                if (Log.isLoggable(TAG, Log.VERBOSE)) {
                    Log.d(TAG, "error downloading " + photoUrl, e);
                }
                syncResult.stats.numIoExceptions++;
                return;
            } catch (HttpException e) {
                switch (e.getStatusCode()) {
                case HttpException.SC_UNAUTHORIZED:
                    if (Config.LOGD) {
                        Log.d(TAG, "not authorized to download " + photoUrl, e);
                    }
                    syncResult.stats.numAuthExceptions++;
                    return;
                case HttpException.SC_FORBIDDEN:
                case HttpException.SC_NOT_FOUND:
                    final String exceptionMessage = e.getMessage();
                    if (Config.LOGD) {
                        Log.d(TAG, "unable to download photo " + photoUrl + ", " + exceptionMessage
                                + ", ignoring");
                    }
                    ContentValues values = new ContentValues();
                    values.put(Photos.SYNC_ERROR, exceptionMessage);
                    Uri photoUri = Uri.withAppendedPath(ContentUris.withAppendedId(People.CONTENT_URI, photoId),
                            Photos.CONTENT_DIRECTORY);
                    cr.update(photoUri, values, null /* where */, null /* where args */);
                    break;
                default:
                    if (Config.LOGD) {
                        Log.d(TAG, "error downloading " + photoUrl, e);
                    }
                    syncResult.stats.numIoExceptions++;
                    return;
                }
            }
        }
        final boolean hasMoreToSync = numFetched < cursor.getCount();
        GDataSyncData.FeedData feedData = new GDataSyncData.FeedData(0 /* no update time */, numFetched,
                hasMoreToSync, null /* no lastId */, 0 /* no feed index */);
        syncData.feedData.put(feedUrl, feedData);
    } finally {
        cursor.close();
    }
}

From source file:com.samsung.multiwindow.MultiWindow.java

/**
 * Checks if the device supports Multiwindow feature of specified window
 * type./*from   w w  w .  ja va2  s. co m*/
 * 
 * @param windowType
 *            The window type freestyle or splitstyle.
 * @param callbackContext
 *            The callback id used when calling back into JavaScript.
 * @return true if window type is supported or false if windowType is not supported.
 * 
 */
private boolean isMultiWindowSupported(final String windowType) {

    if (Log.isLoggable(MULTIWINDOW, Log.DEBUG)) {
        Log.d(TAG, "Inside isMultiWindowSupported");
    }

    if (windowType.equalsIgnoreCase("freestyle") && mMultiWindow.isFeatureEnabled(SMultiWindow.FREE_STYLE)) {
        return true;
    } else if (windowType.equalsIgnoreCase("splitstyle")
            && mMultiWindow.isFeatureEnabled(SMultiWindow.MULTIWINDOW)) {
        return true;
    }

    return false;
}

From source file:com.google.android.gms.common.GooglePlayServicesUtilLight.java

public static boolean zze(Context context, int i) {
    boolean z = false;
    if (!zza(context, i, "com.google.android.gms")) {
        return z;
    }/*from  ww w . j a  v  a 2 s . c o m*/
    try {
        return GoogleSignatureVerifier.getInstance().zza(context.getPackageManager(),
                context.getPackageManager().getPackageInfo("com.google.android.gms", 64));
    } catch (NameNotFoundException e) {
        if (!Log.isLoggable("GooglePlayServicesUtil", 3)) {
            return z;
        }
        Log.d("GooglePlayServicesUtil",
                "Package manager can't find google play services package, defaulting to false");
        return z;
    }
}

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

public void showFacebookDialog(final String action, final Bundle params) {
    Log.d(TAG, "showFacebookDialog action=" + action + " params=" + toString(params));

    if (mInstance == null || !mInstance.isOnFacebook()) {
        Log.e(TAG, "You are not on Facebook");
        return;/*ww  w.j  av a2  s . c  om*/
    }

    new AsyncTask<Void, Void, JSONObject>() {
        private final IFacebookService facebookService = mFacebookService;

        protected JSONObject doInBackground(Void... nada) {
            JSONObject result = null;

            try {
                JSONObject jsonRequest = new JSONObject();
                jsonRequest.put("method", action);
                for (String key : params.keySet()) {
                    jsonRequest.put(key, params.get(key));
                }
                String resultAsStr = facebookService.ui(jsonRequest.toString());
                if (resultAsStr != null) {
                    result = new JSONObject(resultAsStr);
                }
            } catch (JSONException e) {
                Log.e(TAG, "Exception: ", e);
            } catch (RemoteException e) {
                Log.e(TAG, "Failed to invoke FacebookService", e);
            }

            return result;
        }

        protected void onPostExecute(JSONObject result) {
            Bundle bundle = null;
            if (result != null) {
                try {
                    bundle = toBundle(result);
                } catch (JSONException e) {
                    // Nothing to do. We'll return a Facebook
                    // exception below.
                }

                if (Log.isLoggable(TAG, Log.DEBUG)) {
                    Log.d(TAG, "Response from Facebook: ");
                    for (String key : bundle.keySet()) {
                        Log.d(TAG, "\t" + key + "=" + bundle.get(key));
                    }
                }
                //                    listener.onComplete(bundle, null);
            } else {
                //                    listener.onComplete(null, new FacebookException());
            }
        }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}