Skip to content
This repository was archived by the owner on Dec 27, 2024. It is now read-only.

Commit 8bc84e4

Browse files
authored
Merge pull request #630 from jswong65/fix-errorprone
Fix error-prone issues part1
2 parents 9d88195 + afd155a commit 8bc84e4

27 files changed

+89
-121
lines changed

constraintlayout/constraintlayout/src/main/java/androidx/constraintlayout/motion/utils/CustomSupport.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
public class CustomSupport {
3131
private static final String TAG = "CustomSupport";
32-
32+
private static final boolean DEBUG = false;
3333
/**
3434
* sets the interpolated value
3535
* @param att
@@ -83,6 +83,10 @@ public static void setInterpolatedValue(ConstraintAttribute att, View view, floa
8383
method = viewClass.getMethod(methodName, Float.TYPE);
8484
method.invoke(view, value[0]);
8585
break;
86+
default:
87+
if (DEBUG) {
88+
Log.v(TAG, att.getType().toString());
89+
}
8690
}
8791
} catch (NoSuchMethodException e) {
8892
Log.e(TAG, "no method " + methodName + " on View \"" + Debug.getName(view) + "\"");

constraintlayout/constraintlayout/src/main/java/androidx/constraintlayout/motion/utils/ViewOscillator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ static class CustomSet extends ViewOscillator {
181181
float[] mValue = new float[1];
182182
protected ConstraintAttribute mCustom;
183183

184+
@Override
184185
protected void setCustom(Object custom) {
185186
mCustom = (ConstraintAttribute) custom;
186187
}

constraintlayout/constraintlayout/src/main/java/androidx/constraintlayout/motion/utils/ViewSpline.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ public void setup(int curveType) {
242242
* @param position the position
243243
* @param value the value
244244
*/
245+
@Override
245246
public void setPoint(int position, float value) {
246247
throw new RuntimeException("call of custom attribute setPoint");
247248
}

constraintlayout/constraintlayout/src/main/java/androidx/constraintlayout/motion/utils/ViewTimeCycle.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ public CustomSet(String attribute, SparseArray<ConstraintAttribute> attrList) {
272272
* Setup the curve
273273
* @param curveType
274274
*/
275+
@Override
275276
public void setup(int curveType) {
276277
int size = mConstraintAttributeList.size();
277278
int dimensionality =
@@ -303,6 +304,7 @@ public void setup(int curveType) {
303304
* @param shape
304305
* @param offset
305306
*/
307+
@Override
306308
public void setPoint(int position, float value, float period, int shape, float offset) {
307309
throw new RuntimeException("Wrong call for custom attribute");
308310
}

constraintlayout/constraintlayout/src/main/java/androidx/constraintlayout/motion/widget/Key.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ public Key copy(Key src) {
154154
* Return a copy of this
155155
* @return
156156
*/
157+
@Override
157158
public abstract Key clone();
158159

159160
/**

constraintlayout/constraintlayout/src/main/java/androidx/constraintlayout/motion/widget/KeyAttributes.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ public void getAttributeNames(HashSet<String> attributes) {
138138
* create the interpolations associated with this KeyAttribute
139139
* @param interpolation will be added to with keyAttributes
140140
*/
141+
@Override
141142
public void setInterpolation(HashMap<String, Integer> interpolation) {
142143
if (mCurveFit == -1) {
143144
return;
@@ -472,6 +473,7 @@ public static void read(KeyAttributes c, TypedArray a) {
472473
* @param src to be copied
473474
* @return self
474475
*/
476+
@Override
475477
public Key copy(Key src) {
476478
super.copy(src);
477479
KeyAttributes k = (KeyAttributes) src;
@@ -499,6 +501,7 @@ public Key copy(Key src) {
499501
* Clone this KeyAttributes
500502
* @return
501503
*/
504+
@Override
502505
public Key clone() {
503506
return new KeyAttributes().copy(this);
504507
}

constraintlayout/constraintlayout/src/main/java/androidx/constraintlayout/motion/widget/KeyCycle.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ public class KeyCycle extends Key {
8585
* @param context
8686
* @param attrs
8787
*/
88+
@Override
8889
public void load(Context context, AttributeSet attrs) {
8990
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.KeyCycle);
9091
Loader.read(this, a);
@@ -491,6 +492,7 @@ public void setValue(String tag, Object value) {
491492
* @param src to be copied
492493
* @return self
493494
*/
495+
@Override
494496
public Key copy(Key src) {
495497
super.copy(src);
496498
KeyCycle k = (KeyCycle) src;
@@ -521,6 +523,7 @@ public Key copy(Key src) {
521523
* Clone this KeyAttributes
522524
* @return
523525
*/
526+
@Override
524527
public Key clone() {
525528
return new KeyCycle().copy(this);
526529
}

constraintlayout/constraintlayout/src/main/java/androidx/constraintlayout/motion/widget/KeyTimeCycle.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ public void getAttributeNames(HashSet<String> attributes) {
136136
*
137137
* @param interpolation
138138
*/
139+
@Override
139140
public void setInterpolation(HashMap<String, Integer> interpolation) {
140141
if (mCurveFit == -1) {
141142
return;
@@ -357,6 +358,7 @@ public void setValue(String tag, Object value) {
357358
* @param src to be copied
358359
* @return self
359360
*/
361+
@Override
360362
public Key copy(Key src) {
361363
super.copy(src);
362364
KeyTimeCycle k = (KeyTimeCycle) src;
@@ -386,6 +388,7 @@ public Key copy(Key src) {
386388
*
387389
* @return
388390
*/
391+
@Override
389392
public Key clone() {
390393
return new KeyTimeCycle().copy(this);
391394
}

constraintlayout/constraintlayout/src/main/java/androidx/constraintlayout/motion/widget/MotionInterpolator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public abstract class MotionInterpolator implements Interpolator {
2828
* @param v
2929
* @return
3030
*/
31+
@Override
3132
public abstract float getInterpolation(float v);
3233

3334
/**

constraintlayout/constraintlayout/src/main/java/androidx/constraintlayout/motion/widget/MotionLayout.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,7 +1473,7 @@ protected void setTransition(MotionScene.Transition transition) {
14731473
mTransitionGoalPosition = 0;
14741474
}
14751475
mTransitionLastTime =
1476-
(transition.isTransitionFlag(TRANSITION_FLAG_FIRST_DRAW)) ? -1 : getNanoTime();
1476+
transition.isTransitionFlag(TRANSITION_FLAG_FIRST_DRAW) ? -1 : getNanoTime();
14771477
if (DEBUG) {
14781478
Log.v(TAG, Debug.getLocation() + " new mTransitionLastPosition = "
14791479
+ mTransitionLastPosition + "");
@@ -1910,7 +1910,7 @@ private void setupMotionViews() {
19101910
}
19111911
float x = f.getFinalX();
19121912
float y = f.getFinalY();
1913-
float mdist = (flip) ? (y - x) : (y + x);
1913+
float mdist = flip ? (y - x) : (y + x);
19141914
min = Math.min(min, mdist);
19151915
max = Math.max(max, mdist);
19161916
}
@@ -1944,9 +1944,9 @@ private void setupMotionViews() {
19441944
MotionController f = mFrameArrayList.get(getChildAt(i));
19451945
float x = f.getFinalX();
19461946
float y = f.getFinalY();
1947-
float mdist = (flip) ? (y - x) : (y + x);
1947+
float mdist = flip ? (y - x) : (y + x);
19481948
f.mStaggerScale = 1 / (1 - stagger);
1949-
f.mStaggerOffset = stagger - stagger * (mdist - (min)) / (max - (min));
1949+
f.mStaggerOffset = stagger - stagger * (mdist - min) / (max - min);
19501950
}
19511951
}
19521952
}
@@ -2519,7 +2519,7 @@ public void transitionToState(int id, int screenWidth, int screenHeight, int dur
25192519
float x = f.getFinalX();
25202520
float y = f.getFinalY();
25212521
f.mStaggerScale = 1 / (1 - stagger);
2522-
f.mStaggerOffset = stagger - stagger * (x + y - (min)) / (max - (min));
2522+
f.mStaggerOffset = stagger - stagger * (x + y - min) / (max - min);
25232523
}
25242524
}
25252525

@@ -2723,8 +2723,8 @@ private void setupConstraintWidget(ConstraintWidgetContainer base, ConstraintSet
27232723
if (view instanceof Barrier) {
27242724
((Barrier) view).validateParams();
27252725
if (DEBUG) {
2726-
Log.v(TAG, ">>>>>>>>>> Barrier " + (Debug.getName(getContext(),
2727-
((Barrier) view).getReferencedIds())));
2726+
Log.v(TAG, ">>>>>>>>>> Barrier " + Debug.getName(getContext(),
2727+
((Barrier) view).getReferencedIds()));
27282728
}
27292729
}
27302730
}
@@ -3001,7 +3001,7 @@ private Rect toRect(ConstraintWidget cw) {
30013001

30023002
@Override
30033003
public void requestLayout() {
3004-
if (!(mMeasureDuringTransition)) {
3004+
if (!mMeasureDuringTransition) {
30053005
if (mCurrentState == UNSET && mScene != null
30063006
&& mScene.mCurrentTransition != null) {
30073007
int mode = mScene.mCurrentTransition.getLayoutDuringTransition();
@@ -3779,8 +3779,8 @@ void evaluate(boolean force) {
37793779
}
37803780

37813781
boolean newState = false;
3782-
if (mKeepAnimating || mInTransition
3783-
&& (force || mTransitionGoalPosition != mTransitionLastPosition)) {
3782+
if (mKeepAnimating || (mInTransition
3783+
&& (force || mTransitionGoalPosition != mTransitionLastPosition))) {
37843784
float dir = Math.signum(mTransitionGoalPosition - mTransitionLastPosition);
37853785
long currentTime = getNanoTime();
37863786

@@ -3818,7 +3818,7 @@ void evaluate(boolean force) {
38183818
position = mInterpolator.getInterpolation(time);
38193819
if (mInterpolator == mStopLogic) {
38203820
boolean dp = mStopLogic.isStopped();
3821-
stopLogicDone = (dp) ? stopLogicStop : stopLogicContinue;
3821+
stopLogicDone = dp ? stopLogicStop : stopLogicContinue;
38223822
}
38233823

38243824
if (DEBUG) {
@@ -4037,10 +4037,10 @@ private void init(AttributeSet attrs) {
40374037
apply = a.getBoolean(attr, apply);
40384038
} else if (attr == R.styleable.MotionLayout_showPaths) {
40394039
if (mDebugPath == 0) { // favor motionDebug
4040-
mDebugPath = (a.getBoolean(attr, false)) ? DEBUG_SHOW_PATH : 0;
4040+
mDebugPath = a.getBoolean(attr, false) ? DEBUG_SHOW_PATH : 0;
40414041
}
40424042
} else if (attr == R.styleable.MotionLayout_motionDebug) {
4043-
mDebugPath = (a.getInt(attr, 0));
4043+
mDebugPath = a.getInt(attr, 0);
40444044
}
40454045
}
40464046
a.recycle();
@@ -4281,7 +4281,7 @@ public boolean onInterceptTouchEvent(MotionEvent event) {
42814281
if (event.getAction() == MotionEvent.ACTION_DOWN) {
42824282
RectF region = touchResponse.getTouchRegion(this, new RectF());
42834283
if (region != null
4284-
&& (!region.contains(event.getX(), event.getY()))) {
4284+
&& !region.contains(event.getX(), event.getY())) {
42854285
return false;
42864286
}
42874287
}

constraintlayout/constraintlayout/src/main/java/androidx/constraintlayout/motion/widget/MotionScene.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -328,12 +328,12 @@ public Transition bestTransitionFor(int currentState,
328328
transition.mTouchResponse.setRTL(mRtl);
329329
RectF region = transition.mTouchResponse.getTouchRegion(mMotionLayout, cache);
330330
if (region != null && lastTouchDown != null
331-
&& (!region.contains(lastTouchDown.getX(), lastTouchDown.getY()))) {
331+
&& !region.contains(lastTouchDown.getX(), lastTouchDown.getY())) {
332332
continue;
333333
}
334334
region = transition.mTouchResponse.getLimitBoundsTo(mMotionLayout, cache);
335335
if (region != null && lastTouchDown != null
336-
&& (!region.contains(lastTouchDown.getX(), lastTouchDown.getY()))) {
336+
&& !region.contains(lastTouchDown.getX(), lastTouchDown.getY())) {
337337
continue;
338338
}
339339

@@ -1708,8 +1708,8 @@ void processTouchEvent(MotionEvent event, int currentState, MotionLayout motionL
17081708
region = mCurrentTransition.mTouchResponse
17091709
.getTouchRegion(mMotionLayout, cache);
17101710
if (region != null
1711-
&& (!region.contains(mLastTouchDown.getX(),
1712-
mLastTouchDown.getY()))) {
1711+
&& !region.contains(mLastTouchDown.getX(),
1712+
mLastTouchDown.getY())) {
17131713
mMotionOutsideRegion = true;
17141714
} else {
17151715
mMotionOutsideRegion = false;
@@ -1729,7 +1729,7 @@ void processTouchEvent(MotionEvent event, int currentState, MotionLayout motionL
17291729
if (DEBUG) {
17301730
Log.v(TAG, "----- ACTION_MOVE " + dx + "," + dy);
17311731
}
1732-
if (dx == 0.0 && dy == 0.0 || mLastTouchDown == null) {
1732+
if ((dx == 0.0 && dy == 0.0) || mLastTouchDown == null) {
17331733
return;
17341734
}
17351735

constraintlayout/constraintlayout/src/main/java/androidx/constraintlayout/widget/ConstraintAttribute.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
*/
4040
public class ConstraintAttribute {
4141
private static final String TAG = "TransitionLayout";
42+
private static final boolean DEBUG = false;
4243
private boolean mMethod = false;
4344
String mName;
4445
private AttributeType mType;
@@ -179,7 +180,7 @@ public void getValuesToInterpolate(float[] ret) {
179180
int a = 0xFF & (mColorValue >> 24);
180181
int r = 0xFF & (mColorValue >> 16);
181182
int g = 0xFF & (mColorValue >> 8);
182-
int b = 0xFF & (mColorValue);
183+
int b = 0xFF & mColorValue;
183184
float f_r = (float) Math.pow(r / 255.0f, 2.2);
184185
float f_g = (float) Math.pow(g / 255.0f, 2.2);
185186
float f_b = (float) Math.pow(b / 255.0f, 2.2);
@@ -196,6 +197,10 @@ public void getValuesToInterpolate(float[] ret) {
196197
case DIMENSION_TYPE:
197198
ret[0] = mFloatValue;
198199
break;
200+
default:
201+
if (DEBUG) {
202+
Log.v(TAG, mType.toString());
203+
}
199204
}
200205
}
201206

@@ -224,6 +229,10 @@ public void setValue(float[] value) {
224229
break;
225230
case DIMENSION_TYPE:
226231
mFloatValue = value[0];
232+
default:
233+
if (DEBUG) {
234+
Log.v(TAG, mType.toString());
235+
}
227236

228237
}
229238
}

constraintlayout/constraintlayout/src/main/java/androidx/constraintlayout/widget/ConstraintLayout.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,7 @@ public final void measure(ConstraintWidget widget,
800800
== BasicMeasure.Measure.USE_GIVEN_DIMENSIONS
801801
|| !shouldDoWrap
802802
|| (shouldDoWrap && otherDimensionStable)
803-
|| (child instanceof Placeholder)
803+
|| child instanceof Placeholder
804804
|| widget.isResolvedHorizontally();
805805
if (useCurrent) {
806806
horizontalSpec = MeasureSpec.makeMeasureSpec(widget.getWidth(),

constraintlayout/constraintlayout/src/main/java/androidx/constraintlayout/widget/ConstraintSet.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2275,6 +2275,7 @@ private void setColorValue(String attributeName, int value) {
22752275
* Return a copy of the Constraint
22762276
* @return
22772277
*/
2278+
@Override
22782279
public Constraint clone() {
22792280
Constraint clone = new Constraint();
22802281
clone.layout.copyFrom(layout);
@@ -6148,10 +6149,10 @@ String lookup(int id) {
61486149
if (id != -1) {
61496150
return mContext.getResources().getResourceEntryName(id);
61506151
} else {
6151-
return "unknown" + (++mUnknownCount);
6152+
return "unknown" + ++mUnknownCount;
61526153
}
61536154
} catch (Exception ex) {
6154-
return "unknown" + (++mUnknownCount);
6155+
return "unknown" + ++mUnknownCount;
61556156
}
61566157
}
61576158

@@ -6404,10 +6405,10 @@ String lookup(int id) {
64046405
if (id != -1) {
64056406
return mContext.getResources().getResourceEntryName(id);
64066407
} else {
6407-
return "unknown" + (++mUnknownCount);
6408+
return "unknown" + ++mUnknownCount;
64086409
}
64096410
} catch (Exception ex) {
6410-
return "unknown" + (++mUnknownCount);
6411+
return "unknown" + ++mUnknownCount;
64116412
}
64126413
}
64136414

constraintlayout/core/src/main/java/androidx/constraintlayout/core/motion/CustomAttribute.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public void getValuesToInterpolate(float[] ret) {
150150
int a = 0xFF & (mColorValue >> 24);
151151
int r = 0xFF & (mColorValue >> 16);
152152
int g = 0xFF & (mColorValue >> 8);
153-
int b = 0xFF & (mColorValue);
153+
int b = 0xFF & mColorValue;
154154
float f_r = (float) Math.pow(r / 255.0f, 2.2);
155155
float f_g = (float) Math.pow(g / 255.0f, 2.2);
156156
float f_b = (float) Math.pow(b / 255.0f, 2.2);

constraintlayout/core/src/main/java/androidx/constraintlayout/core/motion/CustomVariable.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ public void getValuesToInterpolate(float[] ret) {
208208
int a = 0xFF & (mIntegerValue >> 24);
209209
int r = 0xFF & (mIntegerValue >> 16);
210210
int g = 0xFF & (mIntegerValue >> 8);
211-
int b = 0xFF & (mIntegerValue);
211+
int b = 0xFF & mIntegerValue;
212212
float f_r = (float) Math.pow(r / 255.0f, 2.2);
213213
float f_g = (float) Math.pow(g / 255.0f, 2.2);
214214
float f_b = (float) Math.pow(b / 255.0f, 2.2);

0 commit comments

Comments
 (0)