Search in sources :

Example 1 with Nullable

use of androidx.annotation.Nullable in project butterknife by JakeWharton.

the class ButterKnife method parseBindDimen.

@Nullable
private static Unbinder parseBindDimen(Object target, Field field, View source) {
    BindDimen bindDimen = field.getAnnotation(BindDimen.class);
    if (bindDimen == null) {
        return null;
    }
    validateMember(field);
    int id = bindDimen.value();
    Resources resources = source.getContext().getResources();
    Class<?> fieldType = field.getType();
    Object value;
    if (fieldType == int.class) {
        value = resources.getDimensionPixelSize(id);
    } else if (fieldType == float.class) {
        value = resources.getDimension(id);
    } else {
        throw new IllegalStateException("@BindDimen field type must be 'int' or 'float'. (" + field.getDeclaringClass().getName() + '.' + field.getName() + ')');
    }
    trySet(field, target, value);
    return Unbinder.EMPTY;
}
Also used : AccessibleObject(java.lang.reflect.AccessibleObject) Resources(android.content.res.Resources) Nullable(androidx.annotation.Nullable)

Example 2 with Nullable

use of androidx.annotation.Nullable in project butterknife by JakeWharton.

the class ButterKnife method parseOnTouch.

@Nullable
private static Unbinder parseOnTouch(final Object target, final Method method, View source) {
    OnTouch onTouch = method.getAnnotation(OnTouch.class);
    if (onTouch == null) {
        return null;
    }
    validateMember(method);
    final boolean propagateReturn = validateReturnType(method, boolean.class);
    final ArgumentTransformer argumentTransformer = createArgumentTransformer(method, ON_TOUCH_TYPES);
    List<View> views = findViews(source, onTouch.value(), isRequired(method), method.getName(), View.class);
    ViewCollections.set(views, ON_TOUCH, (v, event) -> {
        Object returnValue = tryInvoke(method, target, argumentTransformer.transform(v, event));
        // noinspection SimplifiableConditionalExpression
        return propagateReturn ? (boolean) returnValue : true;
    });
    return new ListenerUnbinder<>(views, ON_TOUCH);
}
Also used : AccessibleObject(java.lang.reflect.AccessibleObject) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) Nullable(androidx.annotation.Nullable)

Example 3 with Nullable

use of androidx.annotation.Nullable in project butterknife by JakeWharton.

the class ButterKnife method parseBindDrawable.

@Nullable
private static Unbinder parseBindDrawable(Object target, Field field, View source) {
    BindDrawable bindDrawable = field.getAnnotation(BindDrawable.class);
    if (bindDrawable == null) {
        return null;
    }
    validateMember(field);
    int id = bindDrawable.value();
    int tint = bindDrawable.tint();
    Context context = source.getContext();
    Class<?> fieldType = field.getType();
    Object value;
    if (fieldType == Drawable.class) {
        value = tint != Constants.NO_RES_ID ? Utils.getTintedDrawable(context, id, tint) : ContextCompat.getDrawable(context, id);
    } else {
        throw new IllegalStateException("@BindDrawable field type must be 'Drawable'. (" + field.getDeclaringClass().getName() + '.' + field.getName() + ')');
    }
    trySet(field, target, value);
    return Unbinder.EMPTY;
}
Also used : Context(android.content.Context) AccessibleObject(java.lang.reflect.AccessibleObject) Nullable(androidx.annotation.Nullable)

Example 4 with Nullable

use of androidx.annotation.Nullable in project butterknife by JakeWharton.

the class ButterKnife method parseBindColor.

@Nullable
private static Unbinder parseBindColor(Object target, Field field, View source) {
    BindColor bindColor = field.getAnnotation(BindColor.class);
    if (bindColor == null) {
        return null;
    }
    validateMember(field);
    int id = bindColor.value();
    Context context = source.getContext();
    Object value;
    Class<?> fieldType = field.getType();
    if (fieldType == int.class) {
        value = ContextCompat.getColor(context, id);
    } else if (fieldType == ColorStateList.class) {
        value = ContextCompat.getColorStateList(context, id);
    } else {
        throw new IllegalStateException("@BindColor field type must be 'int' or 'ColorStateList'. (" + field.getDeclaringClass().getName() + '.' + field.getName() + ')');
    }
    trySet(field, target, value);
    return Unbinder.EMPTY;
}
Also used : Context(android.content.Context) ColorStateList(android.content.res.ColorStateList) AccessibleObject(java.lang.reflect.AccessibleObject) Nullable(androidx.annotation.Nullable)

Example 5 with Nullable

use of androidx.annotation.Nullable in project butterknife by JakeWharton.

the class ButterKnife method parseOnEditorAction.

@Nullable
private static Unbinder parseOnEditorAction(final Object target, final Method method, View source) {
    OnEditorAction onEditorAction = method.getAnnotation(OnEditorAction.class);
    if (onEditorAction == null) {
        return null;
    }
    validateMember(method);
    final boolean propagateReturn = validateReturnType(method, boolean.class);
    final ArgumentTransformer argumentTransformer = createArgumentTransformer(method, ON_EDITOR_ACTION_TYPES);
    List<TextView> views = findViews(source, onEditorAction.value(), isRequired(method), method.getName(), TextView.class);
    ViewCollections.set(views, ON_EDITOR_ACTION, (v, actionId, event) -> {
        Object value = tryInvoke(method, target, argumentTransformer.transform(v, actionId, event));
        // noinspection SimplifiableConditionalExpression
        return propagateReturn ? (boolean) value : true;
    });
    return new ListenerUnbinder<>(views, ON_EDITOR_ACTION);
}
Also used : TextView(android.widget.TextView) AccessibleObject(java.lang.reflect.AccessibleObject) Nullable(androidx.annotation.Nullable)

Aggregations

Nullable (androidx.annotation.Nullable)1124 View (android.view.View)188 Bundle (android.os.Bundle)111 IOException (java.io.IOException)99 NonNull (androidx.annotation.NonNull)96 ArrayList (java.util.ArrayList)95 Context (android.content.Context)93 TextView (android.widget.TextView)92 Cursor (android.database.Cursor)71 SuppressLint (android.annotation.SuppressLint)69 Uri (android.net.Uri)66 RecyclerView (androidx.recyclerview.widget.RecyclerView)59 List (java.util.List)58 ViewGroup (android.view.ViewGroup)56 Test (org.junit.Test)55 Intent (android.content.Intent)53 Recipient (org.thoughtcrime.securesms.recipients.Recipient)52 R (org.thoughtcrime.securesms.R)46 LayoutInflater (android.view.LayoutInflater)45 ImageView (android.widget.ImageView)43