com.facebook.internal.Validate Java Examples
The following examples show how to use
com.facebook.internal.Validate.
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: LegacyTokenHelper.java From kognitivo with Apache License 2.0 | 6 votes |
public void save(Bundle bundle) { Validate.notNull(bundle, "bundle"); SharedPreferences.Editor editor = cache.edit(); for (String key : bundle.keySet()) { try { serializeKey(key, bundle, editor); } catch (JSONException e) { // Error in the bundle. Don't store a partial cache. Logger.log( LoggingBehavior.CACHE, Log.WARN, TAG, "Error processing value for key: '" + key + "' -- " + e); // Bypass the commit and just return. This cancels the entire edit transaction return; } } editor.apply(); }
Example #2
Source File: NativeAppCallAttachmentStore.java From Klyph with MIT License | 6 votes |
/** * Adds a number of bitmap attachments associated with a native app call. The attachments will be * served via {@link NativeAppCallContentProvider#openFile(android.net.Uri, String) openFile}. * * @param context the Context the call is being made from * @param callId the unique ID of the call * @param imageAttachments a Map of attachment names to Bitmaps; the attachment names will be part of * the URI processed by openFile * @throws java.io.IOException */ public void addAttachmentsForCall(Context context, UUID callId, Map<String, Bitmap> imageAttachments) { Validate.notNull(context, "context"); Validate.notNull(callId, "callId"); Validate.containsNoNulls(imageAttachments.values(), "imageAttachments"); Validate.containsNoNullOrEmpty(imageAttachments.keySet(), "imageAttachments"); addAttachments(context, callId, imageAttachments, new ProcessAttachment<Bitmap>() { @Override public void processAttachment(Bitmap attachment, File outputFile) throws IOException { FileOutputStream outputStream = new FileOutputStream(outputFile); try { attachment.compress(Bitmap.CompressFormat.JPEG, 100, outputStream); } finally { Utility.closeQuietly(outputStream); } } }); }
Example #3
Source File: NativeAppCallAttachmentStore.java From barterli_android with Apache License 2.0 | 6 votes |
/** * Adds a number of bitmap attachments associated with a native app call. The attachments will be * served via {@link NativeAppCallContentProvider#openFile(android.net.Uri, String) openFile}. * * @param context the Context the call is being made from * @param callId the unique ID of the call * @param imageAttachments a Map of attachment names to Bitmaps; the attachment names will be part of * the URI processed by openFile * @throws java.io.IOException */ public void addAttachmentsForCall(Context context, UUID callId, Map<String, Bitmap> imageAttachments) { Validate.notNull(context, "context"); Validate.notNull(callId, "callId"); Validate.containsNoNulls(imageAttachments.values(), "imageAttachments"); Validate.containsNoNullOrEmpty(imageAttachments.keySet(), "imageAttachments"); addAttachments(context, callId, imageAttachments, new ProcessAttachment<Bitmap>() { @Override public void processAttachment(Bitmap attachment, File outputFile) throws IOException { FileOutputStream outputStream = new FileOutputStream(outputFile); try { attachment.compress(Bitmap.CompressFormat.JPEG, 100, outputStream); } finally { Utility.closeQuietly(outputStream); } } }); }
Example #4
Source File: AppLinkData.java From facebook-api-android-maven with Apache License 2.0 | 6 votes |
/** * Asynchronously fetches app link information that might have been stored for use * after installation of the app * @param context The context * @param applicationId Facebook application Id. If null, it is taken from the manifest * @param completionHandler CompletionHandler to be notified with the AppLinkData object or null if none is * available. Must not be null. */ public static void fetchDeferredAppLinkData( Context context, String applicationId, final CompletionHandler completionHandler) { Validate.notNull(context, "context"); Validate.notNull(completionHandler, "completionHandler"); if (applicationId == null) { applicationId = Utility.getMetadataApplicationId(context); } Validate.notNull(applicationId, "applicationId"); final Context applicationContext = context.getApplicationContext(); final String applicationIdCopy = applicationId; Settings.getExecutor().execute(new Runnable() { @Override public void run() { fetchDeferredAppLinkFromServer(applicationContext, applicationIdCopy, completionHandler); } }); }
Example #5
Source File: AppLinkData.java From facebook-api-android-maven with Apache License 2.0 | 6 votes |
/** * Parses out any app link data from the Intent of the Activity passed in. * @param activity Activity that was started because of an app link * @return AppLinkData if found. null if not. */ public static AppLinkData createFromActivity(Activity activity) { Validate.notNull(activity, "activity"); Intent intent = activity.getIntent(); if (intent == null) { return null; } AppLinkData appLinkData = createFromAlApplinkData(intent); if (appLinkData == null) { String appLinkArgsJsonString = intent.getStringExtra(BUNDLE_APPLINK_ARGS_KEY); appLinkData = createFromJson(appLinkArgsJsonString); } if (appLinkData == null) { // Try regular app linking appLinkData = createFromUri(intent.getData()); } return appLinkData; }
Example #6
Source File: FacebookDialog.java From platform-friends-android with BSD 2-Clause "Simplified" License | 6 votes |
/** * Constructor. * @param activity the Activity which is presenting the native Open Graph action publish dialog; * must not be null * @param action the Open Graph action to be published, which must contain a reference to at least one * Open Graph object with the property name specified by setPreviewPropertyName; the action * must have had its type specified via the {@link OpenGraphAction#setType(String)} method * @param actionType the type of the Open Graph action to be published, which should be the namespace-qualified * name of the action type (e.g., "myappnamespace:myactiontype"); this will override the type * of the action passed in. * @param previewPropertyName the name of a property on the Open Graph action that contains the * Open Graph object which will be displayed as a preview to the user */ @Deprecated public OpenGraphActionDialogBuilder(Activity activity, OpenGraphAction action, String actionType, String previewPropertyName) { super(activity); Validate.notNull(action, "action"); Validate.notNullOrEmpty(actionType, "actionType"); Validate.notNullOrEmpty(previewPropertyName, "previewPropertyName"); if (action.getProperty(previewPropertyName) == null) { throw new IllegalArgumentException( "A property named \"" + previewPropertyName + "\" was not found on the action. The name of " + "the preview property must match the name of an action property."); } String typeOnAction = action.getType(); if (!Utility.isNullOrEmpty(typeOnAction) && !typeOnAction.equals(actionType)) { throw new IllegalArgumentException("'actionType' must match the type of 'action' if it is specified. " + "Consider using OpenGraphActionDialogBuilder(Activity activity, OpenGraphAction action, " + "String previewPropertyName) instead."); } this.action = action; this.actionType = actionType; this.previewPropertyName = previewPropertyName; }
Example #7
Source File: SharedPreferencesTokenCachingStrategy.java From FacebookNewsfeedSample-Android with Apache License 2.0 | 6 votes |
/** * Persists all supported data types present in the passed in Bundle, to the * cache * * @param bundle * The Bundle containing information to be cached */ public void save(Bundle bundle) { Validate.notNull(bundle, "bundle"); SharedPreferences.Editor editor = cache.edit(); for (String key : bundle.keySet()) { try { serializeKey(key, bundle, editor); } catch (JSONException e) { // Error in the bundle. Don't store a partial cache. Logger.log(LoggingBehavior.CACHE, Log.WARN, TAG, "Error processing value for key: '" + key + "' -- " + e); // Bypass the commit and just return. This cancels the entire edit transaction return; } } boolean successfulCommit = editor.commit(); if (!successfulCommit) { Logger.log(LoggingBehavior.CACHE, Log.WARN, TAG, "SharedPreferences.Editor.commit() was not successful"); } }
Example #8
Source File: FacebookDialog.java From FacebookImageShareIntent with MIT License | 5 votes |
Builder(Activity activity) { Validate.notNull(activity, "activity"); this.activity = activity; applicationId = Utility.getMetadataApplicationId(activity); appCall = new PendingCall(NativeProtocol.DIALOG_REQUEST_CODE); }
Example #9
Source File: GraphObject.java From platform-friends-android with BSD 2-Clause "Simplified" License | 5 votes |
public GraphObjectListImpl(JSONArray state, Class<?> itemType) { Validate.notNull(state, "state"); Validate.notNull(itemType, "itemType"); this.state = state; this.itemType = itemType; }
Example #10
Source File: NativeAppCallAttachmentStore.java From Abelana-Android with Apache License 2.0 | 5 votes |
/** * Adds a number of bitmap attachment files associated with a native app call. The attachments will be * served via {@link NativeAppCallContentProvider#openFile(android.net.Uri, String) openFile}. * * @param context the Context the call is being made from * @param callId the unique ID of the call * @param imageAttachments a Map of attachment names to Files containing the bitmaps; the attachment names will be * part of the URI processed by openFile * @throws java.io.IOException */ public void addAttachmentFilesForCall(Context context, UUID callId, Map<String, File> imageAttachmentFiles) { Validate.notNull(context, "context"); Validate.notNull(callId, "callId"); Validate.containsNoNulls(imageAttachmentFiles.values(), "imageAttachmentFiles"); Validate.containsNoNullOrEmpty(imageAttachmentFiles.keySet(), "imageAttachmentFiles"); addAttachments(context, callId, imageAttachmentFiles, new ProcessAttachment<File>() { @Override public void processAttachment(File attachment, File outputFile) throws IOException { FileOutputStream outputStream = new FileOutputStream(outputFile); FileInputStream inputStream = null; try { inputStream = new FileInputStream(attachment); byte[] buffer = new byte[1024]; int len; while ((len = inputStream.read(buffer)) > 0) { outputStream.write(buffer, 0, len); } } finally { Utility.closeQuietly(outputStream); Utility.closeQuietly(inputStream); } } }); }
Example #11
Source File: TokenCachingStrategy.java From facebook-api-android-maven with Apache License 2.0 | 5 votes |
/** * Gets the cached enum indicating the source of the token from the Bundle. * * @param bundle * A Bundle in which the enum was stored. * @return enum indicating the source of the token * * @throws NullPointerException if the passed in Bundle is null */ public static AccessTokenSource getSource(Bundle bundle) { Validate.notNull(bundle, "bundle"); if (bundle.containsKey(TokenCachingStrategy.TOKEN_SOURCE_KEY)) { return (AccessTokenSource) bundle.getSerializable(TokenCachingStrategy.TOKEN_SOURCE_KEY); } else { boolean isSSO = bundle.getBoolean(TokenCachingStrategy.IS_SSO_KEY); return isSSO ? AccessTokenSource.FACEBOOK_APPLICATION_WEB : AccessTokenSource.WEB_VIEW; } }
Example #12
Source File: FacebookSdk.java From kognitivo with Apache License 2.0 | 5 votes |
/** * Sets the Executor used by the SDK for non-AsyncTask background work. * * @param executor * the Executor to use; must not be null. */ public static void setExecutor(Executor executor) { Validate.notNull(executor, "executor"); synchronized (LOCK) { FacebookSdk.executor = executor; } }
Example #13
Source File: WebDialog.java From FacebookNewsfeedSample-Android with Apache License 2.0 | 5 votes |
protected BuilderBase(Context context, Session session, String action, Bundle parameters) { Validate.notNull(session, "session"); if (!session.isOpened()) { throw new FacebookException("Attempted to use a Session that was not open."); } this.session = session; finishInit(context, action, parameters); }
Example #14
Source File: AccessTokenCache.java From kognitivo with Apache License 2.0 | 5 votes |
public void save(AccessToken accessToken) { Validate.notNull(accessToken, "accessToken"); JSONObject jsonObject = null; try { jsonObject = accessToken.toJSONObject(); sharedPreferences.edit().putString(CACHED_ACCESS_TOKEN_KEY, jsonObject.toString()) .apply(); } catch (JSONException e) { // Can't recover } }
Example #15
Source File: WebDialog.java From platform-friends-android with BSD 2-Clause "Simplified" License | 5 votes |
protected BuilderBase(Context context, Session session, String action, Bundle parameters) { Validate.notNull(session, "session"); if (!session.isOpened()) { throw new FacebookException("Attempted to use a Session that was not open."); } this.session = session; finishInit(context, action, parameters); }
Example #16
Source File: TokenCachingStrategy.java From Abelana-Android with Apache License 2.0 | 5 votes |
/** * Puts the list of permissions into a Bundle. * * @param bundle * A Bundle in which the list of permissions should be stored. * @param value * The List<String> representing the list of permissions, * or null. * * @throws NullPointerException if the passed in Bundle or permissions list are null */ public static void putPermissions(Bundle bundle, List<String> value) { Validate.notNull(bundle, "bundle"); Validate.notNull(value, "value"); ArrayList<String> arrayList; if (value instanceof ArrayList<?>) { arrayList = (ArrayList<String>) value; } else { arrayList = new ArrayList<String>(value); } bundle.putStringArrayList(PERMISSIONS_KEY, arrayList); }
Example #17
Source File: TokenCachingStrategy.java From FacebookNewsfeedSample-Android with Apache License 2.0 | 5 votes |
/** * Puts the list of permissions into a Bundle. * * @param bundle * A Bundle in which the list of permissions should be stored. * @param value * The List<String> representing the list of permissions, * or null. * * @throws NullPointerException if the passed in Bundle or permissions list are null */ public static void putPermissions(Bundle bundle, List<String> value) { Validate.notNull(bundle, "bundle"); Validate.notNull(value, "value"); ArrayList<String> arrayList; if (value instanceof ArrayList<?>) { arrayList = (ArrayList<String>) value; } else { arrayList = new ArrayList<String>(value); } bundle.putStringArrayList(PERMISSIONS_KEY, arrayList); }
Example #18
Source File: AccessToken.java From FacebookNewsfeedSample-Android with Apache License 2.0 | 5 votes |
/** * Creates a new AccessToken using the information contained in an Intent populated by the Facebook * application in order to launch a native link. For more information on native linking, please see * https://developers.facebook.com/docs/mobile/android/deep_linking/. * * @param intent the Intent that was used to start an Activity; must not be null * @return a new AccessToken, or null if the Intent did not contain enough data to create one */ public static AccessToken createFromNativeLinkingIntent(Intent intent) { Validate.notNull(intent, "intent"); if (intent.getExtras() == null) { return null; } return createFromBundle(null, intent.getExtras(), AccessTokenSource.FACEBOOK_APPLICATION_WEB, new Date()); }
Example #19
Source File: TestSession.java From FacebookNewsfeedSample-Android with Apache License 2.0 | 5 votes |
TestSession(Activity activity, List<String> permissions, TokenCachingStrategy tokenCachingStrategy, String sessionUniqueUserTag, Mode mode) { super(activity, TestSession.testApplicationId, tokenCachingStrategy); Validate.notNull(permissions, "permissions"); // Validate these as if they were arguments even though they are statics. Validate.notNullOrEmpty(testApplicationId, "testApplicationId"); Validate.notNullOrEmpty(testApplicationSecret, "testApplicationSecret"); this.sessionUniqueUserTag = sessionUniqueUserTag; this.mode = mode; this.requestedPermissions = permissions; }
Example #20
Source File: TokenCachingStrategy.java From android-skeleton-project with MIT License | 5 votes |
/** * Gets the cached enum indicating the source of the token from the Bundle. * * @param bundle * A Bundle in which the enum was stored. * @return enum indicating the source of the token * * @throws NullPointerException if the passed in Bundle is null */ public static AccessTokenSource getSource(Bundle bundle) { Validate.notNull(bundle, "bundle"); if (bundle.containsKey(TokenCachingStrategy.TOKEN_SOURCE_KEY)) { return (AccessTokenSource) bundle.getSerializable(TokenCachingStrategy.TOKEN_SOURCE_KEY); } else { boolean isSSO = bundle.getBoolean(TokenCachingStrategy.IS_SSO_KEY); return isSSO ? AccessTokenSource.FACEBOOK_APPLICATION_WEB : AccessTokenSource.WEB_VIEW; } }
Example #21
Source File: GraphObject.java From HypFacebook with BSD 2-Clause "Simplified" License | 5 votes |
public GraphObjectListImpl(JSONArray state, Class<?> itemType) { Validate.notNull(state, "state"); Validate.notNull(itemType, "itemType"); this.state = state; this.itemType = itemType; }
Example #22
Source File: Settings.java From Klyph with MIT License | 5 votes |
/** * Sets the Executor used by the SDK for non-AsyncTask background work. * * @param executor * the Executor to use; must not be null. */ public static void setExecutor(Executor executor) { Validate.notNull(executor, "executor"); synchronized (LOCK) { Settings.executor = executor; } }
Example #23
Source File: TokenCachingStrategy.java From aws-mobile-self-paced-labs-samples with Apache License 2.0 | 5 votes |
/** * Puts the list of permissions into a Bundle. * * @param bundle * A Bundle in which the list of permissions should be stored. * @param value * The List<String> representing the list of permissions, * or null. * * @throws NullPointerException if the passed in Bundle or permissions list are null */ public static void putPermissions(Bundle bundle, List<String> value) { Validate.notNull(bundle, "bundle"); Validate.notNull(value, "value"); ArrayList<String> arrayList; if (value instanceof ArrayList<?>) { arrayList = (ArrayList<String>) value; } else { arrayList = new ArrayList<String>(value); } bundle.putStringArrayList(PERMISSIONS_KEY, arrayList); }
Example #24
Source File: TokenCachingStrategy.java From aws-mobile-self-paced-labs-samples with Apache License 2.0 | 5 votes |
/** * Gets the cached enum indicating the source of the token from the Bundle. * * @param bundle * A Bundle in which the enum was stored. * @return enum indicating the source of the token * * @throws NullPointerException if the passed in Bundle is null */ public static AccessTokenSource getSource(Bundle bundle) { Validate.notNull(bundle, "bundle"); if (bundle.containsKey(TokenCachingStrategy.TOKEN_SOURCE_KEY)) { return (AccessTokenSource) bundle.getSerializable(TokenCachingStrategy.TOKEN_SOURCE_KEY); } else { boolean isSSO = bundle.getBoolean(TokenCachingStrategy.IS_SSO_KEY); return isSSO ? AccessTokenSource.FACEBOOK_APPLICATION_WEB : AccessTokenSource.WEB_VIEW; } }
Example #25
Source File: GraphObject.java From FacebookNewsfeedSample-Android with Apache License 2.0 | 5 votes |
public GraphObjectListImpl(JSONArray state, Class<?> itemType) { Validate.notNull(state, "state"); Validate.notNull(itemType, "itemType"); this.state = state; this.itemType = itemType; }
Example #26
Source File: NativeAppCallAttachmentStore.java From facebook-api-android-maven with Apache License 2.0 | 5 votes |
/** * Adds a number of bitmap attachment files associated with a native app call. The attachments will be * served via {@link NativeAppCallContentProvider#openFile(android.net.Uri, String) openFile}. * * @param context the Context the call is being made from * @param callId the unique ID of the call * @param imageAttachments a Map of attachment names to Files containing the bitmaps; the attachment names will be * part of the URI processed by openFile * @throws java.io.IOException */ public void addAttachmentFilesForCall(Context context, UUID callId, Map<String, File> imageAttachmentFiles) { Validate.notNull(context, "context"); Validate.notNull(callId, "callId"); Validate.containsNoNulls(imageAttachmentFiles.values(), "imageAttachmentFiles"); Validate.containsNoNullOrEmpty(imageAttachmentFiles.keySet(), "imageAttachmentFiles"); addAttachments(context, callId, imageAttachmentFiles, new ProcessAttachment<File>() { @Override public void processAttachment(File attachment, File outputFile) throws IOException { FileOutputStream outputStream = new FileOutputStream(outputFile); FileInputStream inputStream = null; try { inputStream = new FileInputStream(attachment); byte[] buffer = new byte[1024]; int len; while ((len = inputStream.read(buffer)) > 0) { outputStream.write(buffer, 0, len); } } finally { Utility.closeQuietly(outputStream); Utility.closeQuietly(inputStream); } } }); }
Example #27
Source File: ImageRequest.java From HypFacebook with BSD 2-Clause "Simplified" License | 5 votes |
static URL getProfilePictureUrl( String userId, int width, int height) throws MalformedURLException { Validate.notNullOrEmpty(userId, "userId"); width = Math.max(width, UNSPECIFIED_DIMENSION); height = Math.max(height, UNSPECIFIED_DIMENSION); if (width == UNSPECIFIED_DIMENSION && height == UNSPECIFIED_DIMENSION) { throw new IllegalArgumentException("Either width or height must be greater than 0"); } Uri.Builder builder = new Uri.Builder().encodedPath(String.format(PROFILEPIC_URL_FORMAT, userId)); if (height != UNSPECIFIED_DIMENSION) { builder.appendQueryParameter(HEIGHT_PARAM, String.valueOf(height)); } if (width != UNSPECIFIED_DIMENSION) { builder.appendQueryParameter(WIDTH_PARAM, String.valueOf(width)); } builder.appendQueryParameter(MIGRATION_PARAM, MIGRATION_VALUE); return new URL(builder.toString()); }
Example #28
Source File: TestSession.java From HypFacebook with BSD 2-Clause "Simplified" License | 5 votes |
TestSession(Activity activity, List<String> permissions, TokenCachingStrategy tokenCachingStrategy, String sessionUniqueUserTag, Mode mode) { super(activity, TestSession.testApplicationId, tokenCachingStrategy); Validate.notNull(permissions, "permissions"); // Validate these as if they were arguments even though they are statics. Validate.notNullOrEmpty(testApplicationId, "testApplicationId"); Validate.notNullOrEmpty(testApplicationSecret, "testApplicationSecret"); this.sessionUniqueUserTag = sessionUniqueUserTag; this.mode = mode; this.requestedPermissions = permissions; }
Example #29
Source File: LegacyTokenHelper.java From kognitivo with Apache License 2.0 | 5 votes |
public static Set<String> getPermissions(Bundle bundle) { Validate.notNull(bundle, "bundle"); ArrayList<String> arrayList = bundle.getStringArrayList(PERMISSIONS_KEY); if (arrayList == null) { return null; } return new HashSet<String>(arrayList); }
Example #30
Source File: ValidateTests.java From FacebookImageShareIntent with MIT License | 4 votes |
@SmallTest public void testNotEmptyOnNonEmpty() { Validate.notEmpty(Arrays.asList(new String[] { "hi" }), "name"); }