Skip to content

Commit 3021dc0

Browse files
cketchamwcshi
authored andcommitted
Add @nonnull and @nullable annotations
PiperOrigin-RevId: 264856214
1 parent 06b1501 commit 3021dc0

3 files changed

Lines changed: 62 additions & 42 deletions

File tree

lib/java/com/google/android/material/chip/Chip.java

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public class Chip extends AppCompatCheckBox implements Delegate, Shapeable {
160160
private static final String COMPOUND_BUTTON_ACCESSIBILITY_CLASS_NAME =
161161
"android.widget.CompoundButton";
162162

163-
private final ChipTouchHelper touchHelper;
163+
@NonNull private final ChipTouchHelper touchHelper;
164164
private final Rect rect = new Rect();
165165
private final RectF rectF = new RectF();
166166
private final TextAppearanceFontCallback fontCallback =
@@ -259,7 +259,7 @@ public void setElevation(float elevation) {
259259
}
260260

261261
@Override
262-
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
262+
public void onInitializeAccessibilityNodeInfo(@NonNull AccessibilityNodeInfo info) {
263263
super.onInitializeAccessibilityNodeInfo(info);
264264
if (isCheckable() || isClickable()) {
265265
info.setClassName(
@@ -284,7 +284,7 @@ private void updateAccessibilityDelegate() {
284284
}
285285
}
286286

287-
private void initMinTouchTarget(Context context, AttributeSet attrs, int defStyleAttr) {
287+
private void initMinTouchTarget(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
288288
if (attrs == null) {
289289
return;
290290
}
@@ -383,7 +383,7 @@ private void initOutlineProvider() {
383383
new ViewOutlineProvider() {
384384
@Override
385385
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
386-
public void getOutline(View view, Outline outline) {
386+
public void getOutline(View view, @NonNull Outline outline) {
387387
if (chipDrawable != null) {
388388
chipDrawable.getOutline(outline);
389389
} else {
@@ -431,6 +431,7 @@ private void ensureChipDrawableHasCallback() {
431431
}
432432
}
433433

434+
@Nullable
434435
public Drawable getBackgroundDrawable() {
435436
if (insetBackgroundDrawable == null) {
436437
return chipDrawable;
@@ -606,6 +607,7 @@ public void setCompoundDrawablesRelativeWithIntrinsicBounds(
606607
super.setCompoundDrawablesRelativeWithIntrinsicBounds(start, top, end, bottom);
607608
}
608609

610+
@Nullable
609611
@Override
610612
public TruncateAt getEllipsize() {
611613
return chipDrawable != null ? chipDrawable.getEllipsize() : null;
@@ -732,7 +734,7 @@ public boolean performCloseIconClick() {
732734
}
733735

734736
@Override
735-
public boolean onTouchEvent(MotionEvent event) {
737+
public boolean onTouchEvent(@NonNull MotionEvent event) {
736738
boolean handled = false;
737739

738740
int action = event.getActionMasked();
@@ -768,7 +770,7 @@ public boolean onTouchEvent(MotionEvent event) {
768770
}
769771

770772
@Override
771-
public boolean onHoverEvent(MotionEvent event) {
773+
public boolean onHoverEvent(@NonNull MotionEvent event) {
772774
int action = event.getActionMasked();
773775
switch (action) {
774776
case MotionEvent.ACTION_HOVER_MOVE:
@@ -788,7 +790,7 @@ public boolean onHoverEvent(MotionEvent event) {
788790
// Until the accessibility focus bug is fixed in ExploreByTouchHelper, we simulate the correct
789791
// behavior here. Once that bug is fixed we can remove this.
790792
@SuppressLint("PrivateApi")
791-
private boolean handleAccessibilityExit(MotionEvent event) {
793+
private boolean handleAccessibilityExit(@NonNull MotionEvent event) {
792794
if (event.getAction() == MotionEvent.ACTION_HOVER_EXIT) {
793795
try {
794796
Field f = ExploreByTouchHelper.class.getDeclaredField("mHoveredVirtualViewId");
@@ -820,7 +822,7 @@ private boolean handleAccessibilityExit(MotionEvent event) {
820822
}
821823

822824
@Override
823-
protected boolean dispatchHoverEvent(MotionEvent event) {
825+
protected boolean dispatchHoverEvent(@NonNull MotionEvent event) {
824826
return handleAccessibilityExit(event)
825827
|| touchHelper.dispatchHoverEvent(event)
826828
|| super.dispatchHoverEvent(event);
@@ -849,7 +851,7 @@ protected void onFocusChanged(boolean focused, int direction, Rect previouslyFoc
849851
}
850852

851853
@Override
852-
public void getFocusedRect(Rect r) {
854+
public void getFocusedRect(@NonNull Rect r) {
853855
if (touchHelper.getKeyboardFocusedVirtualViewId() == CLOSE_ICON_VIRTUAL_ID
854856
|| touchHelper.getAccessibilityFocusedVirtualViewId() == CLOSE_ICON_VIRTUAL_ID) {
855857
r.set(getCloseIconTouchBoundsInt());
@@ -887,6 +889,7 @@ protected void drawableStateChanged() {
887889
}
888890
}
889891

892+
@NonNull
890893
private int[] createCloseIconDrawableState() {
891894
int count = 0;
892895
if (isEnabled()) {
@@ -935,6 +938,7 @@ private boolean hasCloseIcon() {
935938
return chipDrawable != null && chipDrawable.getCloseIcon() != null;
936939
}
937940

941+
@NonNull
938942
private RectF getCloseIconTouchBounds() {
939943
rectF.setEmpty();
940944

@@ -946,15 +950,17 @@ private RectF getCloseIconTouchBounds() {
946950
return rectF;
947951
}
948952

953+
@NonNull
949954
private Rect getCloseIconTouchBoundsInt() {
950955
RectF bounds = getCloseIconTouchBounds();
951956
rect.set((int) bounds.left, (int) bounds.top, (int) bounds.right, (int) bounds.bottom);
952957
return rect;
953958
}
954959

960+
@Nullable
955961
@Override
956962
@TargetApi(VERSION_CODES.N)
957-
public PointerIcon onResolvePointerIcon(MotionEvent event, int pointerIndex) {
963+
public PointerIcon onResolvePointerIcon(@NonNull MotionEvent event, int pointerIndex) {
958964
if (getCloseIconTouchBounds().contains(event.getX(), event.getY()) && isEnabled()) {
959965
return PointerIcon.getSystemIcon(getContext(), PointerIcon.TYPE_HAND);
960966
}
@@ -976,7 +982,7 @@ protected int getVirtualViewAt(float x, float y) {
976982
}
977983

978984
@Override
979-
protected void getVisibleVirtualViews(List<Integer> virtualViewIds) {
985+
protected void getVisibleVirtualViews(@NonNull List<Integer> virtualViewIds) {
980986
virtualViewIds.add(CHIP_BODY_VIRTUAL_ID);
981987
if (hasCloseIcon() && isCloseIconVisible()) {
982988
virtualViewIds.add(CLOSE_ICON_VIRTUAL_ID);
@@ -993,7 +999,7 @@ protected void onVirtualViewKeyboardFocusChanged(int virtualViewId, boolean hasF
993999

9941000
@Override
9951001
protected void onPopulateNodeForVirtualView(
996-
int virtualViewId, AccessibilityNodeInfoCompat node) {
1002+
int virtualViewId, @NonNull AccessibilityNodeInfoCompat node) {
9971003
if (virtualViewId == CLOSE_ICON_VIRTUAL_ID) {
9981004
CharSequence closeIconContentDescription = getCloseIconContentDescription();
9991005
if (closeIconContentDescription != null) {
@@ -1017,7 +1023,7 @@ protected void onPopulateNodeForVirtualView(
10171023
}
10181024

10191025
@Override
1020-
protected void onPopulateNodeForHost(AccessibilityNodeInfoCompat node) {
1026+
protected void onPopulateNodeForHost(@NonNull AccessibilityNodeInfoCompat node) {
10211027
node.setCheckable(isCheckable());
10221028
node.setClickable(isClickable());
10231029
if (isCheckable() || isClickable()) {

0 commit comments

Comments
 (0)