com.facebook.android.Util Java Examples

The following examples show how to use com.facebook.android.Util. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WebDialog.java    From Abelana-Android with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("deprecation")
public boolean shouldOverrideUrlLoading(WebView view, String url) {
    Utility.logd(LOG_TAG, "Redirect URL: " + url);
    if (url.startsWith(WebDialog.REDIRECT_URI)) {
        Bundle values = Util.parseUrl(url);

        String error = values.getString("error");
        if (error == null) {
            error = values.getString("error_type");
        }

        String errorMessage = values.getString("error_msg");
        if (errorMessage == null) {
            errorMessage = values.getString("error_description");
        }
        String errorCodeString = values.getString("error_code");
        int errorCode = FacebookRequestError.INVALID_ERROR_CODE;
        if (!Utility.isNullOrEmpty(errorCodeString)) {
            try {
                errorCode = Integer.parseInt(errorCodeString);
            } catch (NumberFormatException ex) {
                errorCode = FacebookRequestError.INVALID_ERROR_CODE;
            }
        }

        if (Utility.isNullOrEmpty(error) && Utility
                .isNullOrEmpty(errorMessage) && errorCode == FacebookRequestError.INVALID_ERROR_CODE) {
            sendSuccessToListener(values);
        } else if (error != null && (error.equals("access_denied") ||
                error.equals("OAuthAccessDeniedException"))) {
            sendCancelToListener();
        } else {
            FacebookRequestError requestError = new FacebookRequestError(errorCode, error, errorMessage);
            sendErrorToListener(new FacebookServiceException(requestError, errorMessage));
        }

        WebDialog.this.dismiss();
        return true;
    } else if (url.startsWith(WebDialog.CANCEL_URI)) {
        sendCancelToListener();
        WebDialog.this.dismiss();
        return true;
    } else if (url.contains(DISPLAY_TOUCH)) {
        return false;
    }
    // launch non-dialog URLs in a full browser
    getContext().startActivity(
            new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
    return true;
}
 
Example #2
Source File: WebDialog.java    From facebook-api-android-maven with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("deprecation")
public boolean shouldOverrideUrlLoading(WebView view, String url) {
    Utility.logd(LOG_TAG, "Redirect URL: " + url);
    if (url.startsWith(WebDialog.REDIRECT_URI)) {
        Bundle values = Util.parseUrl(url);

        String error = values.getString("error");
        if (error == null) {
            error = values.getString("error_type");
        }

        String errorMessage = values.getString("error_msg");
        if (errorMessage == null) {
            errorMessage = values.getString("error_description");
        }
        String errorCodeString = values.getString("error_code");
        int errorCode = FacebookRequestError.INVALID_ERROR_CODE;
        if (!Utility.isNullOrEmpty(errorCodeString)) {
            try {
                errorCode = Integer.parseInt(errorCodeString);
            } catch (NumberFormatException ex) {
                errorCode = FacebookRequestError.INVALID_ERROR_CODE;
            }
        }

        if (Utility.isNullOrEmpty(error) && Utility
                .isNullOrEmpty(errorMessage) && errorCode == FacebookRequestError.INVALID_ERROR_CODE) {
            sendSuccessToListener(values);
        } else if (error != null && (error.equals("access_denied") ||
                error.equals("OAuthAccessDeniedException"))) {
            sendCancelToListener();
        } else {
            FacebookRequestError requestError = new FacebookRequestError(errorCode, error, errorMessage);
            sendErrorToListener(new FacebookServiceException(requestError, errorMessage));
        }

        WebDialog.this.dismiss();
        return true;
    } else if (url.startsWith(WebDialog.CANCEL_URI)) {
        sendCancelToListener();
        WebDialog.this.dismiss();
        return true;
    } else if (url.contains(DISPLAY_TOUCH)) {
        return false;
    }
    // launch non-dialog URLs in a full browser
    getContext().startActivity(
            new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
    return true;
}