Java 类com.facebook.android.Util 实例源码

项目:facebook-android-sdk    文件:Tests.java   
public boolean testPublicApi() {
    Facebook fb = new Facebook(APP_ID);
    try {
        Log.d("Tests", "Testing standard API call");
        JSONObject response = Util.parseJson(fb.request("4"));
        if (!response.getString("name").equals("Mark Zuckerberg")) {
            return false;
        }

        Log.d("Tests", "Testing an API call with a specific method");
        response = Util.parseJson(
                fb.request("soneff", new Bundle(), "GET"));
        if (!response.getString("name").equals("Steven Soneff")) {
            return false;
        }

        Log.d("Tests", "Testing a public search query");
        Bundle params = new Bundle();
        params.putString("q", "facebook");
        response = Util.parseJson(fb.request("search", params));
        if (response.getJSONArray("data").length() == 0) return false;

        Log.d("Tests", "Public API Tests passed"); 
        return true;
    } catch (Throwable e) {
        e.printStackTrace();
        return false;
    }
}
项目:facebook-android-sdk    文件:Tests.java   
public void onComplete(final String response, final Object state) {
    Log.d("Tests", "Got response: " + response);
    try {
        JSONObject json = Util.parseJson(response);
        //final String message = json.getString("message");
        String postId = json.getString("id");
        Tests.this.runOnUiThread(new Runnable() {
            public void run() {
                wallPostText.setText("Wall Post Success");
                wallPostText.setTextColor(Color.GREEN);
            }
        });

        Log.d("Tests", "Testing wall post delete");
        if (testPostDelete(postId)) {
            Tests.this.runOnUiThread(new Runnable() {
                public void run() {
                    deletedPostText.setText("Deleted Post Success");
                    deletedPostText.setTextColor(Color.GREEN);
                }
            });
        } else {
            Tests.this.runOnUiThread(new Runnable() {
                public void run() {
                    deletedPostText.setText("Deleted Post Failure");
                    deletedPostText.setTextColor(Color.RED);
                }
            });
        }
    } catch (Throwable e) {
        e.printStackTrace();
        Tests.this.runOnUiThread(new Runnable() {
            public void run() {
                wallPostText.setText("Wall Post Failure");
                wallPostText.setTextColor(Color.RED);
            }
        });
    }
}
项目:yelo-android    文件:WebDialog.java   
@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;
}
项目:Qtino.SharingKit    文件:WebDialog.java   
@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;
}
项目:p2psafety    文件:WebDialog.java   
@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;
}
项目:StoryTeller    文件:WebDialog.java   
@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;
}
项目:Abelana-Android    文件:WebDialog.java   
@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;
}
项目:localhost-android    文件:WebDialog.java   
@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;
}
项目:facebook-android-sdk    文件:Tests.java   
public boolean testAuthenticatedApi() {
    if (!authenticatedFacebook.isSessionValid()) return false;
    try {
        Log.d("Tests", "Testing request for 'me'");
        String response = authenticatedFacebook.request("me");
        JSONObject obj = Util.parseJson(response);
        if (obj.getString("name") == null || 
                obj.getString("name").equals("")) {
            return false;
        }

        Log.d("Tests", "Testing graph API wall post");
        Bundle parameters = new Bundle();
        parameters.putString("message", "hello world");
        parameters.putString("description", "test test test");
        response = authenticatedFacebook.request("me/feed", parameters, 
                "POST");
        Log.d("Tests", "got response: " + response);
        if (response == null || response.equals("") || 
                response.equals("false")) {
            return false;
        }

        Log.d("Tests", "Testing graph API delete");
        response = response.replaceAll("\\{\"id\":\"", "");
        response = response.replaceAll("\"\\}", "");
        response = authenticatedFacebook.request(response, new Bundle(), 
                "DELETE");
        if (!response.equals("true")) return false;

        Log.d("Tests", "Testing old API wall post");
        parameters = new Bundle();
        parameters.putString("method", "stream.publish");
        parameters.putString("attachment", 
            "{\"name\":\"Name=Title\"," +
            "\"href\":\"http://www.google.fr/\",\"" +
            "caption\":\"Caption\",\"description\":\"Description" +
            "\",\"media\":[{\"type\":\"image\",\"src\":" +
            "\"http://www.kratiroff.com/logo-facebook.jpg\"," +
            "\"href\":\"http://developers.facebook.com/\"}]," +
            "\"properties\":{\"another link\":{\"text\":\"" +
            "Facebook homepage\",\"href\":\"http://www.facebook." +
            "com\"}}}");;
        response = authenticatedFacebook.request(parameters);
        Log.d("Tests", "got response: " + response);
        if (response == null || response.equals("") || 
                response.equals("false")) {
            return false;
        }

        Log.d("Tests", "Testing wall post delete");
        response = response.replaceAll("\"", "");
        response = authenticatedFacebook.request(
                response, new Bundle(), "DELETE");
        if (!response.equals("true")) return false;

        Log.d("Tests", "All Authenticated Tests Passed");
        return true;
    } catch (Throwable e) {
        e.printStackTrace();
        return false;
    }
}
项目:facebook-api-android-maven    文件:WebDialog.java   
@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;
}