Skip to content

Commit

Permalink
fix lint error/warnings (#23333)
Browse files Browse the repository at this point in the history
Summary:
Fix lint errors and warning, which might be a cause of various crashes on older Android OS, using Android Support Library.

```bash
./gradlew :ReactAndroid:lint
```

[Android] [Changed] - fix lint error/warnings
Pull Request resolved: #23333

Differential Revision: D14019322

Pulled By: mdvacca

fbshipit-source-id: 74c98da269c318cf3b114c8d9c876186369f2b8c
  • Loading branch information
dulmandakh authored and facebook-github-bot committed Feb 10, 2019
1 parent 8ccc55f commit d2fc19f
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 12 deletions.
Expand Up @@ -12,6 +12,7 @@
import java.util.Set; import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet; import java.util.concurrent.CopyOnWriteArraySet;


import android.annotation.SuppressLint;
import android.app.Service; import android.app.Service;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
Expand Down Expand Up @@ -67,6 +68,7 @@ public int onStartCommand(Intent intent, int flags, int startId) {
/** /**
* Acquire a wake lock to ensure the device doesn't go to sleep while processing background tasks. * Acquire a wake lock to ensure the device doesn't go to sleep while processing background tasks.
*/ */
@SuppressLint("WakelockTimeout")
public static void acquireWakeLockNow(Context context) { public static void acquireWakeLockNow(Context context) {
if (sWakeLock == null || !sWakeLock.isHeld()) { if (sWakeLock == null || !sWakeLock.isHeld()) {
PowerManager powerManager = PowerManager powerManager =
Expand Down
Expand Up @@ -7,6 +7,7 @@


package com.facebook.react.modules.systeminfo; package com.facebook.react.modules.systeminfo;


import android.annotation.SuppressLint;
import android.app.UiModeManager; import android.app.UiModeManager;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.os.Build; import android.os.Build;
Expand All @@ -29,6 +30,7 @@
* Module that exposes Android Constants to JS. * Module that exposes Android Constants to JS.
*/ */
@ReactModule(name = AndroidInfoModule.NAME) @ReactModule(name = AndroidInfoModule.NAME)
@SuppressLint("HardwareIds")
public class AndroidInfoModule extends ReactContextBaseJavaModule { public class AndroidInfoModule extends ReactContextBaseJavaModule {
public static final String NAME = "PlatformConstants"; public static final String NAME = "PlatformConstants";
private static final String IS_TESTING = "IS_TESTING"; private static final String IS_TESTING = "IS_TESTING";
Expand Down
Expand Up @@ -7,6 +7,7 @@


import android.graphics.Color; import android.graphics.Color;
import android.os.Build; import android.os.Build;
import android.support.v4.view.ViewCompat;
import android.view.View; import android.view.View;
import android.view.ViewParent; import android.view.ViewParent;
import com.facebook.react.R; import com.facebook.react.R;
Expand Down Expand Up @@ -156,13 +157,13 @@ public void setViewStates(T view, ReadableArray accessibilityStates) {
@ReactProp(name = PROP_IMPORTANT_FOR_ACCESSIBILITY) @ReactProp(name = PROP_IMPORTANT_FOR_ACCESSIBILITY)
public void setImportantForAccessibility(T view, String importantForAccessibility) { public void setImportantForAccessibility(T view, String importantForAccessibility) {
if (importantForAccessibility == null || importantForAccessibility.equals("auto")) { if (importantForAccessibility == null || importantForAccessibility.equals("auto")) {
view.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_AUTO); ViewCompat.setImportantForAccessibility(view, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO);
} else if (importantForAccessibility.equals("yes")) { } else if (importantForAccessibility.equals("yes")) {
view.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_YES); ViewCompat.setImportantForAccessibility(view, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
} else if (importantForAccessibility.equals("no")) { } else if (importantForAccessibility.equals("no")) {
view.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO); ViewCompat.setImportantForAccessibility(view, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO);
} else if (importantForAccessibility.equals("no-hide-descendants")) { } else if (importantForAccessibility.equals("no-hide-descendants")) {
view.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS); ViewCompat.setImportantForAccessibility(view, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
} }
} }


Expand Down
Expand Up @@ -6,6 +6,7 @@
package com.facebook.react.views.scroll; package com.facebook.react.views.scroll;


import android.content.Context; import android.content.Context;
import android.support.v4.view.ViewCompat;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.HorizontalScrollView; import android.widget.HorizontalScrollView;
import com.facebook.react.modules.i18nmanager.I18nUtil; import com.facebook.react.modules.i18nmanager.I18nUtil;
Expand All @@ -19,7 +20,7 @@ public class ReactHorizontalScrollContainerView extends ViewGroup {
public ReactHorizontalScrollContainerView(Context context) { public ReactHorizontalScrollContainerView(Context context) {
super(context); super(context);
mLayoutDirection = mLayoutDirection =
I18nUtil.getInstance().isRTL(context) ? LAYOUT_DIRECTION_RTL : LAYOUT_DIRECTION_LTR; I18nUtil.getInstance().isRTL(context) ? ViewCompat.LAYOUT_DIRECTION_RTL : ViewCompat.LAYOUT_DIRECTION_LTR;
mCurrentWidth = 0; mCurrentWidth = 0;
} }


Expand Down
Expand Up @@ -305,7 +305,7 @@ public void fling(int velocityX) {
// as there is content. See #onOverScrolled() to see the second part of this change which properly // as there is content. See #onOverScrolled() to see the second part of this change which properly
// aborts the scroller animation when we get to the bottom of the ScrollView content. // aborts the scroller animation when we get to the bottom of the ScrollView content.


int scrollWindowWidth = getWidth() - getPaddingStart() - getPaddingEnd(); int scrollWindowWidth = getWidth() - ViewCompat.getPaddingStart(this) - ViewCompat.getPaddingEnd(this);


mScroller.fling( mScroller.fling(
getScrollX(), // startX getScrollX(), // startX
Expand Down Expand Up @@ -501,7 +501,7 @@ private int predictFinalScrollPosition(int velocityX) {


// predict where a fling would end up so we can scroll to the nearest snap offset // predict where a fling would end up so we can scroll to the nearest snap offset
int maximumOffset = Math.max(0, computeHorizontalScrollRange() - getWidth()); int maximumOffset = Math.max(0, computeHorizontalScrollRange() - getWidth());
int width = getWidth() - getPaddingStart() - getPaddingEnd(); int width = getWidth() - ViewCompat.getPaddingStart(this) - ViewCompat.getPaddingEnd(this);
scroller.fling( scroller.fling(
getScrollX(), // startX getScrollX(), // startX
getScrollY(), // startY getScrollY(), // startY
Expand Down Expand Up @@ -583,7 +583,7 @@ private void flingAndSnap(int velocityX) {
int largerOffset = maximumOffset; int largerOffset = maximumOffset;
int firstOffset = 0; int firstOffset = 0;
int lastOffset = maximumOffset; int lastOffset = maximumOffset;
int width = getWidth() - getPaddingStart() - getPaddingEnd(); int width = getWidth() - ViewCompat.getPaddingStart(this) - ViewCompat.getPaddingEnd(this);


// offsets are from the right edge in RTL layouts // offsets are from the right edge in RTL layouts
boolean isRTL = TextUtilsCompat.getLayoutDirectionFromLocale(Locale.getDefault()) == ViewCompat.LAYOUT_DIRECTION_RTL; boolean isRTL = TextUtilsCompat.getLayoutDirectionFromLocale(Locale.getDefault()) == ViewCompat.LAYOUT_DIRECTION_RTL;
Expand Down
Expand Up @@ -6,6 +6,7 @@
*/ */
package com.facebook.react.views.text; package com.facebook.react.views.text;


import android.annotation.TargetApi;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.os.Build; import android.os.Build;
Expand Down Expand Up @@ -37,6 +38,7 @@
* <p>This also node calculates {@link Spannable} object based on subnodes of the same type, which * <p>This also node calculates {@link Spannable} object based on subnodes of the same type, which
* can be used in concrete classes to feed native views and compute layout. * can be used in concrete classes to feed native views and compute layout.
*/ */
@TargetApi(Build.VERSION_CODES.M)
public abstract class ReactBaseTextShadowNode extends LayoutShadowNode { public abstract class ReactBaseTextShadowNode extends LayoutShadowNode {


private static final String INLINE_IMAGE_PLACEHOLDER = "I"; private static final String INLINE_IMAGE_PLACEHOLDER = "I";
Expand Down
Expand Up @@ -6,6 +6,7 @@
*/ */
package com.facebook.react.views.text; package com.facebook.react.views.text;


import android.annotation.TargetApi;
import android.os.Build; import android.os.Build;
import android.text.BoringLayout; import android.text.BoringLayout;
import android.text.Layout; import android.text.Layout;
Expand Down Expand Up @@ -37,6 +38,7 @@
* <p>The class measures text in {@code <Text>} view and feeds native {@link TextView} using {@code * <p>The class measures text in {@code <Text>} view and feeds native {@link TextView} using {@code
* Spannable} object constructed in superclass. * Spannable} object constructed in superclass.
*/ */
@TargetApi(Build.VERSION_CODES.M)
public class ReactTextShadowNode extends ReactBaseTextShadowNode { public class ReactTextShadowNode extends ReactBaseTextShadowNode {


// It's important to pass the ANTI_ALIAS_FLAG flag to the constructor rather than setting it // It's important to pass the ANTI_ALIAS_FLAG flag to the constructor rather than setting it
Expand Down
Expand Up @@ -7,7 +7,9 @@


package com.facebook.react.views.textinput; package com.facebook.react.views.textinput;


import android.annotation.TargetApi;
import android.os.Build; import android.os.Build;
import android.support.v4.view.ViewCompat;
import android.text.Layout; import android.text.Layout;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.ViewGroup; import android.view.ViewGroup;
Expand All @@ -33,6 +35,7 @@
import javax.annotation.Nullable; import javax.annotation.Nullable;


@VisibleForTesting @VisibleForTesting
@TargetApi(Build.VERSION_CODES.M)
public class ReactTextInputShadowNode extends ReactBaseTextShadowNode public class ReactTextInputShadowNode extends ReactBaseTextShadowNode
implements YogaMeasureFunction { implements YogaMeasureFunction {


Expand All @@ -49,7 +52,7 @@ public class ReactTextInputShadowNode extends ReactBaseTextShadowNode


public ReactTextInputShadowNode() { public ReactTextInputShadowNode() {
mTextBreakStrategy = (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) ? mTextBreakStrategy = (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) ?
0 : Layout.BREAK_STRATEGY_SIMPLE; Layout.BREAK_STRATEGY_SIMPLE : Layout.BREAK_STRATEGY_HIGH_QUALITY;


initMeasureFunction(); initMeasureFunction();
} }
Expand All @@ -71,9 +74,9 @@ public void setThemedContext(ThemedReactContext themedContext) {
// So, we have to enforce it as a default padding. // So, we have to enforce it as a default padding.
// TODO #7120264: Cache this stuff better. // TODO #7120264: Cache this stuff better.
EditText editText = new EditText(getThemedContext()); EditText editText = new EditText(getThemedContext());
setDefaultPadding(Spacing.START, editText.getPaddingStart()); setDefaultPadding(Spacing.START, ViewCompat.getPaddingStart(editText));
setDefaultPadding(Spacing.TOP, editText.getPaddingTop()); setDefaultPadding(Spacing.TOP, editText.getPaddingTop());
setDefaultPadding(Spacing.END, editText.getPaddingEnd()); setDefaultPadding(Spacing.END, ViewCompat.getPaddingEnd(editText));
setDefaultPadding(Spacing.BOTTOM, editText.getPaddingBottom()); setDefaultPadding(Spacing.BOTTOM, editText.getPaddingBottom());


mDummyEditText = editText; mDummyEditText = editText;
Expand Down
Expand Up @@ -11,6 +11,7 @@
import android.content.res.Resources; import android.content.res.Resources;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import android.graphics.Color; import android.graphics.Color;
import android.support.v4.view.ViewCompat;
import android.util.LayoutDirection; import android.util.LayoutDirection;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
Expand Down Expand Up @@ -62,7 +63,7 @@ public void setOverflowIcon(ReactToolbar view, @Nullable ReadableMap overflowIco


@ReactProp(name = "rtl") @ReactProp(name = "rtl")
public void setRtl(ReactToolbar view, boolean rtl) { public void setRtl(ReactToolbar view, boolean rtl) {
view.setLayoutDirection(rtl ? LayoutDirection.RTL : LayoutDirection.LTR); ViewCompat.setLayoutDirection(view, rtl ? ViewCompat.LAYOUT_DIRECTION_RTL : ViewCompat.LAYOUT_DIRECTION_LTR);
} }


@ReactProp(name = "subtitle") @ReactProp(name = "subtitle")
Expand Down
Expand Up @@ -7,6 +7,7 @@


package com.facebook.react.views.view; package com.facebook.react.views.view;


import android.annotation.TargetApi;
import android.content.Context; import android.content.Context;
import android.content.res.ColorStateList; import android.content.res.ColorStateList;
import android.graphics.Color; import android.graphics.Color;
Expand All @@ -29,6 +30,7 @@ public class ReactDrawableHelper {


private static final TypedValue sResolveOutValue = new TypedValue(); private static final TypedValue sResolveOutValue = new TypedValue();


@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static Drawable createDrawableFromJSDescription( public static Drawable createDrawableFromJSDescription(
Context context, Context context,
ReadableMap drawableDescriptionDict) { ReadableMap drawableDescriptionDict) {
Expand Down
Expand Up @@ -504,6 +504,7 @@ public void setUserAgent(WebView view, @Nullable String userAgent) {
} }


@ReactProp(name = "mediaPlaybackRequiresUserAction") @ReactProp(name = "mediaPlaybackRequiresUserAction")
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public void setMediaPlaybackRequiresUserAction(WebView view, boolean requires) { public void setMediaPlaybackRequiresUserAction(WebView view, boolean requires) {
view.getSettings().setMediaPlaybackRequiresUserGesture(requires); view.getSettings().setMediaPlaybackRequiresUserGesture(requires);
} }
Expand Down

0 comments on commit d2fc19f

Please sign in to comment.