Java Code Examples for com.facebook.internal.Utility#isNullOrEmpty()
The following examples show how to use
com.facebook.internal.Utility#isNullOrEmpty() .
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: FacebookDialog.java From android-skeleton-project with MIT License | 6 votes |
@Override Bundle setBundleExtras(Bundle extras) { putExtra(extras, NativeProtocol.EXTRA_APPLICATION_ID, applicationId); putExtra(extras, NativeProtocol.EXTRA_APPLICATION_NAME, applicationName); putExtra(extras, NativeProtocol.EXTRA_TITLE, name); putExtra(extras, NativeProtocol.EXTRA_SUBTITLE, caption); putExtra(extras, NativeProtocol.EXTRA_DESCRIPTION, description); putExtra(extras, NativeProtocol.EXTRA_LINK, link); putExtra(extras, NativeProtocol.EXTRA_IMAGE, picture); putExtra(extras, NativeProtocol.EXTRA_PLACE_TAG, place); putExtra(extras, NativeProtocol.EXTRA_TITLE, name); putExtra(extras, NativeProtocol.EXTRA_REF, ref); extras.putBoolean(NativeProtocol.EXTRA_DATA_FAILURES_FATAL, dataErrorsFatal); if (!Utility.isNullOrEmpty(friends)) { extras.putStringArrayList(NativeProtocol.EXTRA_FRIEND_TAGS, friends); } return extras; }
Example 2
Source File: FacebookDialog.java From barterli_android with Apache License 2.0 | 6 votes |
@Override Intent handleBuild(Bundle extras) { putExtra(extras, NativeProtocol.EXTRA_APPLICATION_ID, applicationId); putExtra(extras, NativeProtocol.EXTRA_APPLICATION_NAME, applicationName); putExtra(extras, NativeProtocol.EXTRA_TITLE, name); putExtra(extras, NativeProtocol.EXTRA_SUBTITLE, caption); putExtra(extras, NativeProtocol.EXTRA_DESCRIPTION, description); putExtra(extras, NativeProtocol.EXTRA_LINK, link); putExtra(extras, NativeProtocol.EXTRA_IMAGE, picture); putExtra(extras, NativeProtocol.EXTRA_PLACE_TAG, place); putExtra(extras, NativeProtocol.EXTRA_TITLE, name); putExtra(extras, NativeProtocol.EXTRA_REF, ref); extras.putBoolean(NativeProtocol.EXTRA_DATA_FAILURES_FATAL, dataErrorsFatal); if (!Utility.isNullOrEmpty(friends)) { extras.putStringArrayList(NativeProtocol.EXTRA_FRIEND_TAGS, friends); } int protocolVersion = getProtocolVersionForNativeDialog(activity, MIN_NATIVE_SHARE_PROTOCOL_VERSION); Intent intent = NativeProtocol.createPlatformActivityIntent(activity, NativeProtocol.ACTION_FEED_DIALOG, protocolVersion, extras); return intent; }
Example 3
Source File: NativeProtocol.java From FacebookNewsfeedSample-Android with Apache License 2.0 | 6 votes |
private static ArrayList<String> ensureDefaultPermissions(ArrayList<String> permissions) { ArrayList<String> updated; // Return if we are doing publish, or if basic_info is already included if (Utility.isNullOrEmpty(permissions)) { updated = new ArrayList<String>(); } else { for (String permission : permissions) { if (Session.isPublishPermission(permission) || BASIC_INFO.equals(permission)) { return permissions; } } updated = new ArrayList<String>(permissions); } updated.add(BASIC_INFO); return updated; }
Example 4
Source File: TestSession.java From KlyphMessenger with MIT License | 5 votes |
private static synchronized TestSession createTestSession(Activity activity, List<String> permissions, Mode mode, String sessionUniqueUserTag) { if (Utility.isNullOrEmpty(testApplicationId) || Utility.isNullOrEmpty(testApplicationSecret)) { throw new FacebookException("Must provide app ID and secret"); } if (Utility.isNullOrEmpty(permissions)) { permissions = Arrays.asList("email", "publish_actions"); } return new TestSession(activity, permissions, new TestTokenCachingStrategy(), sessionUniqueUserTag, mode); }
Example 5
Source File: Request.java From aws-mobile-self-paced-labs-samples with Apache License 2.0 | 5 votes |
private static String getBatchAppId(RequestBatch batch) { if (!Utility.isNullOrEmpty(batch.getBatchApplicationId())) { return batch.getBatchApplicationId(); } for (Request request : batch) { Session session = request.session; if (session != null) { return session.getApplicationId(); } } return Request.defaultBatchApplicationId; }
Example 6
Source File: LoginButton.java From Abelana-Android with Apache License 2.0 | 5 votes |
private boolean validatePermissions(List<String> permissions, SessionAuthorizationType authType, Session currentSession) { if (SessionAuthorizationType.PUBLISH.equals(authType)) { if (Utility.isNullOrEmpty(permissions)) { throw new IllegalArgumentException("Permissions for publish actions cannot be null or empty."); } } if (currentSession != null && currentSession.isOpened()) { if (!Utility.isSubset(permissions, currentSession.getPermissions())) { Log.e(TAG, "Cannot set additional permissions when session is already open."); return false; } } return true; }
Example 7
Source File: NativeProtocol.java From FacebookNewsfeedSample-Android with Apache License 2.0 | 5 votes |
static Intent createProxyAuthIntent(Context context, String applicationId, List<String> permissions) { Intent intent = new Intent() .setClassName(KATANA_PACKAGE, KATANA_PROXY_AUTH_ACTIVITY) .putExtra(KATANA_PROXY_AUTH_APP_ID_KEY, applicationId); if (!Utility.isNullOrEmpty(permissions)) { intent.putExtra(KATANA_PROXY_AUTH_PERMISSIONS_KEY, TextUtils.join(",", permissions)); } return validateKatanaActivityIntent(context, intent); }
Example 8
Source File: TestSession.java From android-skeleton-project with MIT License | 5 votes |
private static synchronized TestSession createTestSession(Activity activity, List<String> permissions, Mode mode, String sessionUniqueUserTag) { if (Utility.isNullOrEmpty(testApplicationId) || Utility.isNullOrEmpty(testApplicationSecret)) { throw new FacebookException("Must provide app ID and secret"); } if (Utility.isNullOrEmpty(permissions)) { permissions = Arrays.asList("email", "publish_actions"); } return new TestSession(activity, permissions, new TestTokenCachingStrategy(), sessionUniqueUserTag, mode); }
Example 9
Source File: LoginButton.java From HypFacebook with BSD 2-Clause "Simplified" License | 5 votes |
private boolean validatePermissions(List<String> permissions, SessionAuthorizationType authType, Session currentSession) { if (SessionAuthorizationType.PUBLISH.equals(authType)) { if (Utility.isNullOrEmpty(permissions)) { throw new IllegalArgumentException("Permissions for publish actions cannot be null or empty."); } } if (currentSession != null && currentSession.isOpened()) { if (!Utility.isSubset(permissions, currentSession.getPermissions())) { Log.e(TAG, "Cannot set additional permissions when session is already open."); return false; } } return true; }
Example 10
Source File: AccessToken.java From Klyph with MIT License | 5 votes |
private static AccessToken createNew( List<String> requestedPermissions, String accessToken, Date expires, AccessTokenSource source) { if (Utility.isNullOrEmpty(accessToken) || (expires == null)) { return createEmptyToken(requestedPermissions); } else { return new AccessToken(accessToken, expires, requestedPermissions, source, new Date()); } }
Example 11
Source File: FacebookDialog.java From FacebookImageShareIntent with MIT License | 5 votes |
@Override Bundle setBundleExtras(Bundle extras) { putExtra(extras, NativeProtocol.EXTRA_APPLICATION_ID, applicationId); putExtra(extras, NativeProtocol.EXTRA_APPLICATION_NAME, applicationName); putExtra(extras, NativeProtocol.EXTRA_PLACE_TAG, place); extras.putStringArrayList(NativeProtocol.EXTRA_PHOTOS, imageAttachmentUrls); if (!Utility.isNullOrEmpty(friends)) { extras.putStringArrayList(NativeProtocol.EXTRA_FRIEND_TAGS, friends); } return extras; }
Example 12
Source File: LikeActionController.java From kognitivo with Apache License 2.0 | 5 votes |
private static void serializeToDiskAsync(LikeActionController controller) { String controllerJson = serializeToJson(controller); String cacheKey = getCacheKeyForObjectId(controller.objectId); if (!Utility.isNullOrEmpty(controllerJson) && !Utility.isNullOrEmpty(cacheKey)) { diskIOWorkQueue.addActiveWorkItem( new SerializeToDiskWorkItem(cacheKey, controllerJson)); } }
Example 13
Source File: AuthorizationClient.java From Abelana-Android with Apache License 2.0 | 5 votes |
private Result handleResultOk(Intent data) { Bundle extras = data.getExtras(); String error = extras.getString("error"); if (error == null) { error = extras.getString("error_type"); } String errorCode = extras.getString("error_code"); String errorMessage = extras.getString("error_message"); if (errorMessage == null) { errorMessage = extras.getString("error_description"); } String e2e = extras.getString(NativeProtocol.FACEBOOK_PROXY_AUTH_E2E_KEY); if (!Utility.isNullOrEmpty(e2e)) { logWebLoginCompleted(applicationId, e2e); } if (error == null && errorCode == null && errorMessage == null) { AccessToken token = AccessToken.createFromWebBundle(pendingRequest.getPermissions(), extras, AccessTokenSource.FACEBOOK_APPLICATION_WEB); return Result.createTokenResult(pendingRequest, token); } else if (ServerProtocol.errorsProxyAuthDisabled.contains(error)) { return null; } else if (ServerProtocol.errorsUserCanceled.contains(error)) { return Result.createCancelResult(pendingRequest, null); } else { return Result.createErrorResult(pendingRequest, error, errorMessage, errorCode); } }
Example 14
Source File: Request.java From HypFacebook with BSD 2-Clause "Simplified" License | 5 votes |
private static String getBatchAppId(RequestBatch batch) { if (!Utility.isNullOrEmpty(batch.getBatchApplicationId())) { return batch.getBatchApplicationId(); } for (Request request : batch) { Session session = request.session; if (session != null) { return session.getApplicationId(); } } return Request.defaultBatchApplicationId; }
Example 15
Source File: AuthorizationClient.java From Klyph with MIT License | 4 votes |
void onWebDialogComplete(AuthorizationRequest request, Bundle values, FacebookException error) { Result outcome; if (values != null) { // Actual e2e we got from the dialog should be used for logging. if (values.containsKey(ServerProtocol.DIALOG_PARAM_E2E)) { e2e = values.getString(ServerProtocol.DIALOG_PARAM_E2E); } AccessToken token = AccessToken .createFromWebBundle(request.getPermissions(), values, AccessTokenSource.WEB_VIEW); outcome = Result.createTokenResult(pendingRequest, token); // Ensure any cookies set by the dialog are saved // This is to work around a bug where CookieManager may fail to instantiate if CookieSyncManager // has never been created. CookieSyncManager syncManager = CookieSyncManager.createInstance(context); syncManager.sync(); saveCookieToken(token.getToken()); } else { if (error instanceof FacebookOperationCanceledException) { outcome = Result.createCancelResult(pendingRequest, "User canceled log in."); } else { // Something went wrong, don't log a completion event since it will skew timing results. e2e = null; String errorCode = null; String errorMessage = error.getMessage(); if (error instanceof FacebookServiceException) { FacebookRequestError requestError = ((FacebookServiceException)error).getRequestError(); errorCode = String.format("%d", requestError.getErrorCode()); errorMessage = requestError.toString(); } outcome = Result.createErrorResult(pendingRequest, null, errorMessage, errorCode); } } if (!Utility.isNullOrEmpty(e2e)) { logWebLoginCompleted(applicationId, e2e); } completeAndValidate(outcome); }
Example 16
Source File: GraphObject.java From FacebookImageShareIntent with MIT License | 4 votes |
private static <T extends GraphObject> void verifyCanProxyClass(Class<T> graphObjectClass) { if (hasClassBeenVerified(graphObjectClass)) { return; } if (!graphObjectClass.isInterface()) { throw new FacebookGraphObjectException("Factory can only wrap interfaces, not class: " + graphObjectClass.getName()); } Method[] methods = graphObjectClass.getMethods(); for (Method method : methods) { String methodName = method.getName(); int parameterCount = method.getParameterTypes().length; Class<?> returnType = method.getReturnType(); boolean hasPropertyNameOverride = method.isAnnotationPresent(PropertyName.class); if (method.getDeclaringClass().isAssignableFrom(GraphObject.class)) { // Don't worry about any methods from GraphObject or one of its base classes. continue; } else if (parameterCount == 1 && returnType == Void.TYPE) { if (hasPropertyNameOverride) { // If a property override is present, it MUST be valid. We don't fallback // to using the method name if (!Utility.isNullOrEmpty(method.getAnnotation(PropertyName.class).value())) { continue; } } else if (methodName.startsWith("set") && methodName.length() > 3) { // Looks like a valid setter continue; } } else if (parameterCount == 0 && returnType != Void.TYPE) { if (hasPropertyNameOverride) { // If a property override is present, it MUST be valid. We don't fallback // to using the method name if (!Utility.isNullOrEmpty(method.getAnnotation(PropertyName.class).value())) { continue; } } else if (methodName.startsWith("get") && methodName.length() > 3) { // Looks like a valid getter continue; } } throw new FacebookGraphObjectException("Factory can't proxy method: " + method.toString()); } recordClassHasBeenVerified(graphObjectClass); }
Example 17
Source File: LikeActionController.java From kognitivo with Apache License 2.0 | 4 votes |
private void fetchVerifiedObjectId(final RequestCompletionCallback completionHandler) { if (!Utility.isNullOrEmpty(verifiedObjectId)) { if (completionHandler != null) { completionHandler.onComplete(); } return; } final GetOGObjectIdRequestWrapper objectIdRequest = new GetOGObjectIdRequestWrapper(objectId, objectType); final GetPageIdRequestWrapper pageIdRequest = new GetPageIdRequestWrapper(objectId, objectType); GraphRequestBatch requestBatch = new GraphRequestBatch(); objectIdRequest.addToBatch(requestBatch); pageIdRequest.addToBatch(requestBatch); requestBatch.addCallback(new GraphRequestBatch.Callback() { @Override public void onBatchCompleted(GraphRequestBatch batch) { verifiedObjectId = objectIdRequest.verifiedObjectId; if (Utility.isNullOrEmpty(verifiedObjectId)) { verifiedObjectId = pageIdRequest.verifiedObjectId; objectIsPage = pageIdRequest.objectIsPage; } if (Utility.isNullOrEmpty(verifiedObjectId)) { Logger.log(LoggingBehavior.DEVELOPER_ERRORS, TAG, "Unable to verify the FB id for '%s'. Verify that it is a valid FB" + " object or page", objectId); logAppEventForError("get_verified_id", pageIdRequest.getError() != null ? pageIdRequest.getError() : objectIdRequest.getError()); } if (completionHandler != null) { completionHandler.onComplete(); } } }); requestBatch.executeAsync(); }
Example 18
Source File: Session.java From HypFacebook with BSD 2-Clause "Simplified" License | 4 votes |
private void open(OpenRequest openRequest, SessionAuthorizationType authType) { validatePermissions(openRequest, authType); validateLoginBehavior(openRequest); SessionState newState; synchronized (this.lock) { if (pendingRequest != null) { postStateChange(state, state, new UnsupportedOperationException( "Session: an attempt was made to open a session that has a pending request.")); return; } final SessionState oldState = this.state; switch (this.state) { case CREATED: this.state = newState = SessionState.OPENING; if (openRequest == null) { throw new IllegalArgumentException("openRequest cannot be null when opening a new Session"); } pendingRequest = openRequest; break; case CREATED_TOKEN_LOADED: if (openRequest != null && !Utility.isNullOrEmpty(openRequest.getPermissions())) { if (!Utility.isSubset(openRequest.getPermissions(), getPermissions())) { pendingRequest = openRequest; } } if (pendingRequest == null) { this.state = newState = SessionState.OPENED; } else { this.state = newState = SessionState.OPENING; } break; default: throw new UnsupportedOperationException( "Session: an attempt was made to open an already opened session."); } if (openRequest != null) { addCallback(openRequest.getCallback()); } this.postStateChange(oldState, newState, null); } if (newState == SessionState.OPENING) { authorize(openRequest); } }
Example 19
Source File: Request.java From FacebookNewsfeedSample-Android with Apache License 2.0 | 4 votes |
final static void serializeToUrlConnection(RequestBatch requests, HttpURLConnection connection) throws IOException, JSONException { Logger logger = new Logger(LoggingBehavior.REQUESTS, "Request"); int numRequests = requests.size(); HttpMethod connectionHttpMethod = (numRequests == 1) ? requests.get(0).httpMethod : HttpMethod.POST; connection.setRequestMethod(connectionHttpMethod.name()); URL url = connection.getURL(); logger.append("Request:\n"); logger.appendKeyValue("Id", requests.getId()); logger.appendKeyValue("URL", url); logger.appendKeyValue("Method", connection.getRequestMethod()); logger.appendKeyValue("User-Agent", connection.getRequestProperty("User-Agent")); logger.appendKeyValue("Content-Type", connection.getRequestProperty("Content-Type")); connection.setConnectTimeout(requests.getTimeout()); connection.setReadTimeout(requests.getTimeout()); // If we have a single non-POST request, don't try to serialize anything or HttpURLConnection will // turn it into a POST. boolean isPost = (connectionHttpMethod == HttpMethod.POST); if (!isPost) { logger.log(); return; } connection.setDoOutput(true); BufferedOutputStream outputStream = new BufferedOutputStream(connection.getOutputStream()); try { Serializer serializer = new Serializer(outputStream, logger); if (numRequests == 1) { Request request = requests.get(0); logger.append(" Parameters:\n"); serializeParameters(request.parameters, serializer); logger.append(" Attachments:\n"); serializeAttachments(request.parameters, serializer); if (request.graphObject != null) { processGraphObject(request.graphObject, url.getPath(), serializer); } } else { String batchAppID = getBatchAppId(requests); if (Utility.isNullOrEmpty(batchAppID)) { throw new FacebookException("At least one request in a batch must have an open Session, or a " + "default app ID must be specified."); } serializer.writeString(BATCH_APP_ID_PARAM, batchAppID); // We write out all the requests as JSON, remembering which file attachments they have, then // write out the attachments. Bundle attachments = new Bundle(); serializeRequestsAsJSON(serializer, requests, attachments); logger.append(" Attachments:\n"); serializeAttachments(attachments, serializer); } } finally { outputStream.close(); } logger.log(); }
Example 20
Source File: GraphObject.java From android-skeleton-project with MIT License | 4 votes |
private static <T extends GraphObject> void verifyCanProxyClass(Class<T> graphObjectClass) { if (hasClassBeenVerified(graphObjectClass)) { return; } if (!graphObjectClass.isInterface()) { throw new FacebookGraphObjectException("Factory can only wrap interfaces, not class: " + graphObjectClass.getName()); } Method[] methods = graphObjectClass.getMethods(); for (Method method : methods) { String methodName = method.getName(); int parameterCount = method.getParameterTypes().length; Class<?> returnType = method.getReturnType(); boolean hasPropertyNameOverride = method.isAnnotationPresent(PropertyName.class); if (method.getDeclaringClass().isAssignableFrom(GraphObject.class)) { // Don't worry about any methods from GraphObject or one of its base classes. continue; } else if (parameterCount == 1 && returnType == Void.TYPE) { if (hasPropertyNameOverride) { // If a property override is present, it MUST be valid. We don't fallback // to using the method name if (!Utility.isNullOrEmpty(method.getAnnotation(PropertyName.class).value())) { continue; } } else if (methodName.startsWith("set") && methodName.length() > 3) { // Looks like a valid setter continue; } } else if (parameterCount == 0 && returnType != Void.TYPE) { if (hasPropertyNameOverride) { // If a property override is present, it MUST be valid. We don't fallback // to using the method name if (!Utility.isNullOrEmpty(method.getAnnotation(PropertyName.class).value())) { continue; } } else if (methodName.startsWith("get") && methodName.length() > 3) { // Looks like a valid getter continue; } } throw new FacebookGraphObjectException("Factory can't proxy method: " + method.toString()); } recordClassHasBeenVerified(graphObjectClass); }