Java Code Examples for com.facebook.internal.Validate#notNull()

The following examples show how to use com.facebook.internal.Validate#notNull() . 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: AppLinkData.java    From Klyph with MIT License 7 votes vote down vote up
/**
 * 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;
    }

    String appLinkArgsJsonString = intent.getStringExtra(BUNDLE_APPLINK_ARGS_KEY);
    // Try v2 app linking first
    AppLinkData appLinkData = createFromJson(appLinkArgsJsonString);
    if (appLinkData == null) {
        // Try regular app linking
        appLinkData = createFromUri(intent.getData());
    }

    return appLinkData;
}
 
Example 2
Source File: SharedPreferencesTokenCachingStrategy.java    From FacebookNewsfeedSample-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a {@link SharedPreferencesTokenCachingStrategy SharedPreferencesTokenCachingStrategy} instance
 * that is distinct for the passed in cacheKey.
 *
 * @param context
 *              The Context object to use to get the SharedPreferences object.
 *
 * @param cacheKey
 *              Identifies a distinct set of token information.
 *
 * @throws NullPointerException if the passed in Context is null
 */
public SharedPreferencesTokenCachingStrategy(Context context, String cacheKey) {
    Validate.notNull(context, "context");

    this.cacheKey = Utility.isNullOrEmpty(cacheKey) ? DEFAULT_CACHE_KEY : cacheKey;

    // If the application context is available, use that. However, if it isn't
    // available (possibly because of a context that was created manually), use
    // the passed in context directly.
    Context applicationContext = context.getApplicationContext();
    context = applicationContext != null ? applicationContext : context;

    this.cache = context.getSharedPreferences(
            this.cacheKey,
            Context.MODE_PRIVATE);
}
 
Example 3
Source File: InsightsLogger.java    From HypFacebook with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Constructor is private, newLogger() methods should be used to build an instance.
 */
private InsightsLogger(Context context, String clientToken, String applicationId, Session session) {

    Validate.notNull(context, "context");

    // Always ensure the client token is present, even if not needed for this particular logging (because at
    // some point it will be required).  Be harsh by throwing an exception because this is all too easy to miss
    // and things will work with authenticated sessions, but start failing with users that don't have
    // authenticated sessions.
    Validate.notNullOrEmpty(clientToken, "clientToken");

    if (applicationId == null) {
        applicationId = Utility.getMetadataApplicationId(context);
    }

    this.context = context;
    this.clientToken = clientToken;
    this.applicationId = applicationId;
    this.specifiedSession = session;
}
 
Example 4
Source File: AppLinkData.java    From Abelana-Android with Apache License 2.0 6 votes vote down vote up
/**
 * 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: SharedPreferencesTokenCachingStrategy.java    From platform-friends-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Creates a {@link SharedPreferencesTokenCachingStrategy SharedPreferencesTokenCachingStrategy} instance
 * that is distinct for the passed in cacheKey.
 *
 * @param context
 *              The Context object to use to get the SharedPreferences object.
 *
 * @param cacheKey
 *              Identifies a distinct set of token information.
 *
 * @throws NullPointerException if the passed in Context is null
 */
public SharedPreferencesTokenCachingStrategy(Context context, String cacheKey) {
    Validate.notNull(context, "context");

    this.cacheKey = Utility.isNullOrEmpty(cacheKey) ? DEFAULT_CACHE_KEY : cacheKey;

    // If the application context is available, use that. However, if it isn't
    // available (possibly because of a context that was created manually), use
    // the passed in context directly.
    Context applicationContext = context.getApplicationContext();
    context = applicationContext != null ? applicationContext : context;

    this.cache = context.getSharedPreferences(
            this.cacheKey,
            Context.MODE_PRIVATE);
}
 
Example 6
Source File: FacebookDialog.java    From KlyphMessenger with MIT License 6 votes vote down vote up
/**
 * 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: NativeAppCallAttachmentStore.java    From barterli_android with Apache License 2.0 6 votes vote down vote up
/**
 * 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 8
Source File: NativeDialogParameters.java    From kognitivo with Apache License 2.0 5 votes vote down vote up
public static Bundle create(
        UUID callId,
        ShareContent shareContent,
        boolean shouldFailOnDataError) {
    Validate.notNull(shareContent, "shareContent");
    Validate.notNull(callId, "callId");

    Bundle nativeParams = null;
    if (shareContent instanceof ShareLinkContent) {
        final ShareLinkContent linkContent = (ShareLinkContent) shareContent;
        nativeParams = create(linkContent, shouldFailOnDataError);
    } else if (shareContent instanceof SharePhotoContent) {
        final SharePhotoContent photoContent = (SharePhotoContent) shareContent;
        List<String> photoUrls = ShareInternalUtility.getPhotoUrls(
                photoContent,
                callId);

        nativeParams = create(photoContent, photoUrls, shouldFailOnDataError);
    } else if (shareContent instanceof ShareVideoContent) {
        final ShareVideoContent videoContent = (ShareVideoContent) shareContent;
        String videoUrl = ShareInternalUtility.getVideoUrl(videoContent, callId);

        nativeParams = create(videoContent, videoUrl, shouldFailOnDataError);
    } else if (shareContent instanceof ShareOpenGraphContent) {
        final ShareOpenGraphContent openGraphContent = (ShareOpenGraphContent) shareContent;
        try {
            JSONObject openGraphActionJSON = ShareInternalUtility.toJSONObjectForCall(
                    callId, openGraphContent);
            openGraphActionJSON = ShareInternalUtility.removeNamespacesFromOGJsonObject(
                    openGraphActionJSON, false);
            nativeParams = create(openGraphContent, openGraphActionJSON, shouldFailOnDataError);
        } catch (final JSONException e) {
            throw new FacebookException(
                    "Unable to create a JSON Object from the provided ShareOpenGraphContent: "
                            + e.getMessage());
        }
    }

    return nativeParams;
}
 
Example 9
Source File: Settings.java    From FacebookImageShareIntent with MIT License 5 votes vote down vote up
/**
 * 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 10
Source File: TokenCachingStrategy.java    From FacebookImageShareIntent with MIT License 5 votes vote down vote up
/**
 * 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 11
Source File: TokenCachingStrategy.java    From FacebookNewsfeedSample-Android with Apache License 2.0 5 votes vote down vote up
/**
 * 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&lt;String&gt; 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 12
Source File: ValidateTests.java    From FacebookImageShareIntent with MIT License 5 votes vote down vote up
@SmallTest
public void testNotNullOnNull() {
    try {
        Validate.notNull(null, "name");
        fail("expected exception");
    } catch (Exception e) {
    }
}
 
Example 13
Source File: FacebookDialog.java    From Klyph with MIT License 5 votes vote down vote up
Builder(Activity activity) {
    Validate.notNull(activity, "activity");

    this.activity = activity;
    applicationId = Utility.getMetadataApplicationId(activity);
    appCall = new PendingCall(NativeProtocol.DIALOG_REQUEST_CODE);
}
 
Example 14
Source File: LegacyTokenHelper.java    From kognitivo with Apache License 2.0 4 votes vote down vote up
public static long getExpirationMilliseconds(Bundle bundle) {
    Validate.notNull(bundle, "bundle");
    return bundle.getLong(EXPIRATION_DATE_KEY);
}
 
Example 15
Source File: TokenCachingStrategy.java    From platform-friends-android with BSD 2-Clause "Simplified" License 2 votes vote down vote up
/**
 * Puts the last refresh date into a Bundle.
 * 
 * @param bundle
 *            A Bundle in which the last refresh date should be stored.
 * @param value
 *            The Date representing the last refresh date, or null.
 *
 * @throws NullPointerException if the passed in Bundle or date value are null
 */
public static void putLastRefreshDate(Bundle bundle, Date value) {
    Validate.notNull(bundle, "bundle");
    Validate.notNull(value, "value");
    putDate(bundle, LAST_REFRESH_DATE_KEY, value);
}
 
Example 16
Source File: TokenCachingStrategy.java    From barterli_android with Apache License 2.0 2 votes vote down vote up
/**
 * Gets the cached token value from a Bundle.
 * 
 * @param bundle
 *            A Bundle in which the token value was stored.
 * @return the cached token value, or null.
 *
 * @throws NullPointerException if the passed in Bundle is null
 */
public static String getToken(Bundle bundle) {
    Validate.notNull(bundle, "bundle");
    return bundle.getString(TOKEN_KEY);
}
 
Example 17
Source File: TokenCachingStrategy.java    From HypFacebook with BSD 2-Clause "Simplified" License 2 votes vote down vote up
/**
 * Gets the cached last refresh date from a Bundle.
 * 
 * @param bundle
 *            A Bundle in which the last refresh date was stored.
 * @return the cached last refresh date in milliseconds since the epoch.
 *
 * @throws NullPointerException if the passed in Bundle is null
 */
public static long getLastRefreshMilliseconds(Bundle bundle) {
    Validate.notNull(bundle, "bundle");
    return bundle.getLong(LAST_REFRESH_DATE_KEY);
}
 
Example 18
Source File: TokenCachingStrategy.java    From Abelana-Android with Apache License 2.0 2 votes vote down vote up
/**
 * Gets the cached token value from a Bundle.
 * 
 * @param bundle
 *            A Bundle in which the token value was stored.
 * @return the cached token value, or null.
 *
 * @throws NullPointerException if the passed in Bundle is null
 */
public static String getToken(Bundle bundle) {
    Validate.notNull(bundle, "bundle");
    return bundle.getString(TOKEN_KEY);
}
 
Example 19
Source File: TokenCachingStrategy.java    From Abelana-Android with Apache License 2.0 2 votes vote down vote up
/**
 * Puts the expiration date into a Bundle.
 * 
 * @param bundle
 *            A Bundle in which the expiration date should be stored.
 * @param value
 *            The long representing the expiration date in milliseconds
 *            since the epoch.
 *
 * @throws NullPointerException if the passed in Bundle is null
 */
public static void putExpirationMilliseconds(Bundle bundle, long value) {
    Validate.notNull(bundle, "bundle");
    bundle.putLong(EXPIRATION_DATE_KEY, value);
}
 
Example 20
Source File: TokenCachingStrategy.java    From platform-friends-android with BSD 2-Clause "Simplified" License 2 votes vote down vote up
/**
 * Gets the cached expiration date from a Bundle.
 * 
 * @param bundle
 *            A Bundle in which the expiration date was stored.
 * @return the long representing the cached expiration date in milliseconds
 *         since the epoch, or 0.
 *
 * @throws NullPointerException if the passed in Bundle is null
 */
public static long getExpirationMilliseconds(Bundle bundle) {
    Validate.notNull(bundle, "bundle");
    return bundle.getLong(EXPIRATION_DATE_KEY);
}