Пример #1
0
  private static int compareGraphObjects(
      GraphObject a, GraphObject b, Collection<String> sortFields, Collator collator) {
    for (String sortField : sortFields) {
      String sa = (String) a.getProperty(sortField);
      String sb = (String) b.getProperty(sortField);

      if (sa != null && sb != null) {
        int result = collator.compare(sa, sb);
        if (result != 0) {
          return result;
        }
      } else if (!(sa == null && sb == null)) {
        return (sa == null) ? -1 : 1;
      }
    }
    return 0;
  }
 private static String safeGetStringFromResponse(GraphObject response, String propertyName) {
   Object result = "";
   if (response != null) {
     result = response.getProperty(propertyName);
   }
   if (!(result instanceof String)) {
     result = "";
   }
   return (String) result;
 }
 private static boolean safeGetBooleanFromResponse(GraphObject response, String propertyName) {
   Object result = false;
   if (response != null) {
     result = response.getProperty(propertyName);
   }
   if (!(result instanceof Boolean)) {
     result = false;
   }
   return (Boolean) result;
 }
  private void deleteTestAccount(String testAccountId, String appAccessToken) {
    Bundle parameters = new Bundle();
    parameters.putString("access_token", appAccessToken);

    Request request = new Request(null, testAccountId, parameters, HttpMethod.DELETE);
    Response response = request.executeAndWait();

    FacebookRequestError error = response.getError();
    GraphObject graphObject = response.getGraphObject();
    if (error != null) {
      Log.w(
          LOG_TAG,
          String.format(
              "Could not delete test account %s: %s",
              testAccountId, error.getException().toString()));
    } else if (graphObject.getProperty(Response.NON_JSON_RESPONSE_PROPERTY) == (Boolean) false) {
      Log.w(
          LOG_TAG,
          String.format("Could not delete test account %s: unknown reason", testAccountId));
    }
  }
 @Override
 public void onCompleted(Response response) {
   FacebookRequestError error = response.getError();
   if (error != null) {
     JSONObject jsonObject = new JSONObject();
     try {
       jsonObject.put("type", error.getErrorType());
       jsonObject.put("message", error.getErrorMessage());
       nativeCallback(mCallbackIndex, "{\"error\":" + jsonObject.toString() + "}");
     } catch (JSONException e) {
       e.printStackTrace();
     }
   } else {
     GraphObject object = response.getGraphObject();
     Object tObject = object.getProperty(Response.NON_JSON_RESPONSE_PROPERTY);
     if (tObject == null && object != null) {
       JSONObject jsonObject = object.getInnerJSONObject();
       if (jsonObject != null) nativeCallback(mCallbackIndex, jsonObject.toString());
     } else {
       nativeCallback(mCallbackIndex, tObject.toString());
     }
   }
 }