fix lint error/warnings (#23333)

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: https://github.com/facebook/react-native/pull/23333

Differential Revision: D14019322

Pulled By: mdvacca

fbshipit-source-id: 74c98da269c318cf3b114c8d9c876186369f2b8c
This commit is contained in:
Dulmandakh
2019-02-09 22:21:40 -08:00
committed by Facebook Github Bot
parent 8ccc55fbd3
commit d2fc19f4aa
11 changed files with 29 additions and 12 deletions
@@ -12,6 +12,7 @@ import javax.annotation.Nullable;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;
import android.annotation.SuppressLint;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
@@ -67,6 +68,7 @@ public abstract class HeadlessJsTaskService extends Service implements HeadlessJ
/**
* 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) {
if (sWakeLock == null || !sWakeLock.isHeld()) {
PowerManager powerManager =
@@ -7,6 +7,7 @@
package com.facebook.react.modules.systeminfo;
import android.annotation.SuppressLint;
import android.app.UiModeManager;
import android.content.res.Configuration;
import android.os.Build;
@@ -29,6 +30,7 @@ import static android.content.Context.UI_MODE_SERVICE;
* Module that exposes Android Constants to JS.
*/
@ReactModule(name = AndroidInfoModule.NAME)
@SuppressLint("HardwareIds")
public class AndroidInfoModule extends ReactContextBaseJavaModule {
public static final String NAME = "PlatformConstants";
private static final String IS_TESTING = "IS_TESTING";
@@ -7,6 +7,7 @@ package com.facebook.react.uimanager;
import android.graphics.Color;
import android.os.Build;
import android.support.v4.view.ViewCompat;
import android.view.View;
import android.view.ViewParent;
import com.facebook.react.R;
@@ -156,13 +157,13 @@ public abstract class BaseViewManager<T extends View, C extends LayoutShadowNode
@ReactProp(name = PROP_IMPORTANT_FOR_ACCESSIBILITY)
public void setImportantForAccessibility(T view, String importantForAccessibility) {
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")) {
view.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_YES);
ViewCompat.setImportantForAccessibility(view, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
} 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")) {
view.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
ViewCompat.setImportantForAccessibility(view, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
}
}
@@ -6,6 +6,7 @@
package com.facebook.react.views.scroll;
import android.content.Context;
import android.support.v4.view.ViewCompat;
import android.view.ViewGroup;
import android.widget.HorizontalScrollView;
import com.facebook.react.modules.i18nmanager.I18nUtil;
@@ -19,7 +20,7 @@ public class ReactHorizontalScrollContainerView extends ViewGroup {
public ReactHorizontalScrollContainerView(Context context) {
super(context);
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;
}
@@ -305,7 +305,7 @@ public class ReactHorizontalScrollView extends HorizontalScrollView implements
// 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.
int scrollWindowWidth = getWidth() - getPaddingStart() - getPaddingEnd();
int scrollWindowWidth = getWidth() - ViewCompat.getPaddingStart(this) - ViewCompat.getPaddingEnd(this);
mScroller.fling(
getScrollX(), // startX
@@ -501,7 +501,7 @@ public class ReactHorizontalScrollView extends HorizontalScrollView implements
// predict where a fling would end up so we can scroll to the nearest snap offset
int maximumOffset = Math.max(0, computeHorizontalScrollRange() - getWidth());
int width = getWidth() - getPaddingStart() - getPaddingEnd();
int width = getWidth() - ViewCompat.getPaddingStart(this) - ViewCompat.getPaddingEnd(this);
scroller.fling(
getScrollX(), // startX
getScrollY(), // startY
@@ -583,7 +583,7 @@ public class ReactHorizontalScrollView extends HorizontalScrollView implements
int largerOffset = maximumOffset;
int firstOffset = 0;
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
boolean isRTL = TextUtilsCompat.getLayoutDirectionFromLocale(Locale.getDefault()) == ViewCompat.LAYOUT_DIRECTION_RTL;
@@ -6,6 +6,7 @@
*/
package com.facebook.react.views.text;
import android.annotation.TargetApi;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Build;
@@ -37,6 +38,7 @@ import javax.annotation.Nullable;
* <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.
*/
@TargetApi(Build.VERSION_CODES.M)
public abstract class ReactBaseTextShadowNode extends LayoutShadowNode {
private static final String INLINE_IMAGE_PLACEHOLDER = "I";
@@ -6,6 +6,7 @@
*/
package com.facebook.react.views.text;
import android.annotation.TargetApi;
import android.os.Build;
import android.text.BoringLayout;
import android.text.Layout;
@@ -37,6 +38,7 @@ import javax.annotation.Nullable;
* <p>The class measures text in {@code <Text>} view and feeds native {@link TextView} using {@code
* Spannable} object constructed in superclass.
*/
@TargetApi(Build.VERSION_CODES.M)
public class ReactTextShadowNode extends ReactBaseTextShadowNode {
// It's important to pass the ANTI_ALIAS_FLAG flag to the constructor rather than setting it
@@ -7,7 +7,9 @@
package com.facebook.react.views.textinput;
import android.annotation.TargetApi;
import android.os.Build;
import android.support.v4.view.ViewCompat;
import android.text.Layout;
import android.util.TypedValue;
import android.view.ViewGroup;
@@ -33,6 +35,7 @@ import com.facebook.yoga.YogaNode;
import javax.annotation.Nullable;
@VisibleForTesting
@TargetApi(Build.VERSION_CODES.M)
public class ReactTextInputShadowNode extends ReactBaseTextShadowNode
implements YogaMeasureFunction {
@@ -49,7 +52,7 @@ public class ReactTextInputShadowNode extends ReactBaseTextShadowNode
public ReactTextInputShadowNode() {
mTextBreakStrategy = (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) ?
0 : Layout.BREAK_STRATEGY_SIMPLE;
Layout.BREAK_STRATEGY_SIMPLE : Layout.BREAK_STRATEGY_HIGH_QUALITY;
initMeasureFunction();
}
@@ -71,9 +74,9 @@ public class ReactTextInputShadowNode extends ReactBaseTextShadowNode
// So, we have to enforce it as a default padding.
// TODO #7120264: Cache this stuff better.
EditText editText = new EditText(getThemedContext());
setDefaultPadding(Spacing.START, editText.getPaddingStart());
setDefaultPadding(Spacing.START, ViewCompat.getPaddingStart(editText));
setDefaultPadding(Spacing.TOP, editText.getPaddingTop());
setDefaultPadding(Spacing.END, editText.getPaddingEnd());
setDefaultPadding(Spacing.END, ViewCompat.getPaddingEnd(editText));
setDefaultPadding(Spacing.BOTTOM, editText.getPaddingBottom());
mDummyEditText = editText;
@@ -11,6 +11,7 @@ import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.support.v4.view.ViewCompat;
import android.util.LayoutDirection;
import android.view.MenuItem;
import android.view.View;
@@ -62,7 +63,7 @@ public class ReactToolbarManager extends ViewGroupManager<ReactToolbar> {
@ReactProp(name = "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")
@@ -7,6 +7,7 @@
package com.facebook.react.views.view;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.Color;
@@ -29,6 +30,7 @@ public class ReactDrawableHelper {
private static final TypedValue sResolveOutValue = new TypedValue();
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static Drawable createDrawableFromJSDescription(
Context context,
ReadableMap drawableDescriptionDict) {
@@ -504,6 +504,7 @@ public class ReactWebViewManager extends SimpleViewManager<WebView> {
}
@ReactProp(name = "mediaPlaybackRequiresUserAction")
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public void setMediaPlaybackRequiresUserAction(WebView view, boolean requires) {
view.getSettings().setMediaPlaybackRequiresUserGesture(requires);
}