Fix linting

This commit is contained in:
Mikael Sand
2019-06-09 14:30:21 +03:00
parent 7e8d7428f3
commit 81f817eca3
21 changed files with 77 additions and 67 deletions
+1 -2
View File
@@ -1,3 +1,2 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.horcrux.svg">
<manifest package="com.horcrux.svg">
</manifest>
@@ -12,7 +12,6 @@ package com.horcrux.svg;
import android.graphics.Bitmap;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.LinearGradient;
import android.graphics.Matrix;
import android.graphics.Paint;
@@ -32,7 +31,7 @@ class Brush {
private final boolean mUseObjectBoundingBox;
// TODO implement pattern units
@SuppressWarnings({"FieldCanBeLocal", "unused"})
@SuppressWarnings({"unused"})
private boolean mUseContentObjectBoundingBoxUnits;
private Matrix mMatrix;
@@ -66,7 +66,6 @@ class FontData {
return PropHelper.fromRelative(
string,
0,
0,
scale,
fontSize
);
@@ -84,7 +83,6 @@ class FontData {
fontSize = PropHelper.fromRelative(
string,
parentFontSize,
0,
1,
parentFontSize
);
@@ -29,7 +29,7 @@ import javax.annotation.Nullable;
@SuppressLint("ViewConstructor")
class GroupView extends RenderableView {
@Nullable ReadableMap mFont;
GlyphContext mGlyphContext;
private GlyphContext mGlyphContext;
public GroupView(ReactContext reactContext) {
super(reactContext);
@@ -203,6 +203,7 @@ class ImageView extends RenderableView {
Paint alphaPaint = new Paint();
alphaPaint.setAlpha((int) (opacity * 255));
canvas.drawBitmap(bitmap, null, vbRect, alphaPaint);
//noinspection deprecation
canvas.getMatrix().mapRect(vbRect);
this.setClientRect(vbRect);
}
@@ -62,12 +62,11 @@ class PropHelper {
*
* @param length length string
* @param relative relative size for percentages
* @param offset offset for all units
* @param scale scaling parameter
* @param fontSize current font size
* @return value in the current user coordinate system
*/
static double fromRelative(String length, double relative, double offset, double scale, double fontSize) {
static double fromRelative(String length, double relative, double scale, double fontSize) {
/*
TODO list
@@ -94,9 +93,9 @@ class PropHelper {
int stringLength = length.length();
int percentIndex = stringLength - 1;
if (stringLength == 0 || length.equals("normal")) {
return offset;
return 0d;
} else if (length.codePointAt(percentIndex) == '%') {
return Double.valueOf(length.substring(0, percentIndex)) / 100 * relative + offset;
return Double.valueOf(length.substring(0, percentIndex)) / 100 * relative;
} else {
int twoLetterUnitIndex = stringLength - 2;
if (twoLetterUnitIndex > 0) {
@@ -144,9 +143,9 @@ class PropHelper {
end = stringLength;
}
return Double.valueOf(length.substring(0, end)) * unit * scale + offset;
return Double.valueOf(length.substring(0, end)) * unit * scale;
} else {
return Double.valueOf(length) * scale + offset;
return Double.valueOf(length) * scale;
}
}
}
@@ -36,6 +36,7 @@ import java.util.regex.Pattern;
import javax.annotation.Nullable;
@SuppressWarnings({"WeakerAccess", "RedundantSuppression"})
abstract public class RenderableView extends VirtualView {
RenderableView(ReactContext reactContext) {
@@ -57,17 +58,16 @@ abstract public class RenderableView extends VirtualView {
static final int FILL_RULE_NONZERO = 1;
// vectorEffect
static final int VECTOR_EFFECT_DEFAULT = 0;
static final int VECTOR_EFFECT_NON_SCALING_STROKE = 1;
static final int VECTOR_EFFECT_INHERIT = 2;
static final int VECTOR_EFFECT_URI = 3;
public int vectorEffect = VECTOR_EFFECT_DEFAULT;
private static final int VECTOR_EFFECT_DEFAULT = 0;
private static final int VECTOR_EFFECT_NON_SCALING_STROKE = 1;
//static final int VECTOR_EFFECT_INHERIT = 2;
//static final int VECTOR_EFFECT_URI = 3;
/*
Used in mergeProperties, keep public
*/
public int vectorEffect = VECTOR_EFFECT_DEFAULT;
public @Nullable ReadableArray stroke;
public @Nullable SVGLength[] strokeDasharray;
@@ -86,15 +86,14 @@ abstract public class RenderableView extends VirtualView {
/*
End merged properties
*/
@Nullable ArrayList<String> mLastMergedList;
@Nullable ArrayList<Object> mOriginProperties;
@Nullable ArrayList<String> mPropList;
@Nullable ArrayList<String> mAttributeList;
private @Nullable ArrayList<String> mLastMergedList;
private @Nullable ArrayList<Object> mOriginProperties;
private @Nullable ArrayList<String> mPropList;
private @Nullable ArrayList<String> mAttributeList;
private static final Pattern regex = Pattern.compile("[0-9.-]+");
@ReactProp(name = "vectorEffect", defaultInt = VECTOR_EFFECT_DEFAULT)
@ReactProp(name = "vectorEffect")
public void setVectorEffect(int vectorEffect) {
this.vectorEffect = vectorEffect;
invalidate();
@@ -116,7 +115,7 @@ abstract public class RenderableView extends VirtualView {
Matcher m = regex.matcher(fill.asString());
int i = 0;
while (m.find()) {
Double parsed = Double.parseDouble(m.group());
double parsed = Double.parseDouble(m.group());
arr.pushDouble(i++ < 3 ? parsed / 255 : parsed);
}
this.fill = arr;
@@ -161,7 +160,7 @@ abstract public class RenderableView extends VirtualView {
arr.pushInt(0);
Matcher m = regex.matcher(strokeColors.asString());
while (m.find()) {
Double parsed = Double.parseDouble(m.group());
double parsed = Double.parseDouble(m.group());
arr.pushDouble(parsed);
}
stroke = arr;
@@ -340,6 +339,7 @@ abstract public class RenderableView extends VirtualView {
Path path = mPath;
if (nonScalingStroke) {
Path scaled = new Path();
//noinspection deprecation
mPath.transform(canvas.getMatrix(), scaled);
canvas.setMatrix(null);
path = scaled;
@@ -28,6 +28,7 @@ import com.facebook.react.uimanager.ViewGroupManager;
import com.facebook.react.uimanager.annotations.ReactProp;
import com.facebook.react.uimanager.annotations.ReactPropGroup;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import static com.facebook.react.uimanager.MatrixMathHelper.determinant;
@@ -44,7 +45,6 @@ import static com.facebook.react.uimanager.ViewProps.*;
import static com.horcrux.svg.RenderableView.CAP_ROUND;
import static com.horcrux.svg.RenderableView.FILL_RULE_NONZERO;
import static com.horcrux.svg.RenderableView.JOIN_ROUND;
import static com.horcrux.svg.RenderableView.VECTOR_EFFECT_DEFAULT;
/**
* ViewManager for all RNSVG views
@@ -74,7 +74,7 @@ class RenderableViewManager extends ViewGroupManager<VirtualView> {
class RenderableShadowNode extends LayoutShadowNode {
@SuppressWarnings("unused")
@SuppressWarnings({"unused", "EmptyMethod"})
@ReactPropGroup(
names = {
ALIGN_SELF,
@@ -178,9 +178,6 @@ class RenderableViewManager extends ViewGroupManager<VirtualView> {
}
private static void decomposeMatrix() {
if (sTransformDecompositionArray.length != 16) {
throw new AssertionError();
}
// output values
final double[] perspective = sMatrixDecompositionContext.perspective;
@@ -934,6 +931,7 @@ class RenderableViewManager extends ViewGroupManager<VirtualView> {
mClassName = svgclass.toString();
}
@Nonnull
@Override
public String getName() {
return mClassName;
@@ -955,7 +953,7 @@ class RenderableViewManager extends ViewGroupManager<VirtualView> {
}
@ReactProp(name = "opacity", defaultFloat = 1f)
public void setOpacity(VirtualView node, float opacity) {
public void setOpacity(@Nonnull VirtualView node, float opacity) {
node.setOpacity(opacity);
}
@@ -1015,7 +1013,7 @@ class RenderableViewManager extends ViewGroupManager<VirtualView> {
node.setStrokeLinejoin(strokeLinejoin);
}
@ReactProp(name = "vectorEffect", defaultInt = VECTOR_EFFECT_DEFAULT)
@ReactProp(name = "vectorEffect")
public void setVectorEffect(RenderableView node, int vectorEffect) {
node.setVectorEffect(vectorEffect);
}
@@ -1067,7 +1065,7 @@ class RenderableViewManager extends ViewGroupManager<VirtualView> {
}
@Override
protected void addEventEmitters(ThemedReactContext reactContext, VirtualView view) {
protected void addEventEmitters(@Nonnull ThemedReactContext reactContext, @Nonnull VirtualView view) {
super.addEventEmitters(reactContext, view);
view.setOnHierarchyChangeListener(new ViewGroup.OnHierarchyChangeListener() {
@Override
@@ -1093,13 +1091,14 @@ class RenderableViewManager extends ViewGroupManager<VirtualView> {
* the parent class of the ViewManager may rely on callback being executed.
*/
@Override
protected void onAfterUpdateTransaction(VirtualView node) {
protected void onAfterUpdateTransaction(@Nonnull VirtualView node) {
super.onAfterUpdateTransaction(node);
invalidateSvgView(node);
}
@Nonnull
@Override
protected VirtualView createViewInstance(ThemedReactContext reactContext) {
protected VirtualView createViewInstance(@Nonnull ThemedReactContext reactContext) {
switch (svgClass) {
case RNSVGGroup:
return new GroupView(reactContext);
@@ -23,7 +23,7 @@ enum SVGLengthUnitType {
class SVGLength {
final double value;
final SVGLengthUnitType unit;
SVGLength() {
private SVGLength() {
value = 0;
unit = SVGLengthUnitType.SVG_LENGTHTYPE_UNKNOWN;
}
@@ -31,7 +31,7 @@ class SVGLength {
value = number;
unit = SVGLengthUnitType.SVG_LENGTHTYPE_NUMBER;
}
SVGLength(String length) {
private SVGLength(String length) {
length = length.trim();
int stringLength = length.length();
int percentIndex = stringLength - 1;
@@ -19,12 +19,15 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import javax.annotation.Nonnull;
import static com.horcrux.svg.RenderableViewManager.*;
public class SvgPackage implements ReactPackage {
@Nonnull
@Override
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
public List<ViewManager> createViewManagers(@Nonnull ReactApplicationContext reactContext) {
return Arrays.<ViewManager>asList(
new GroupViewManager(),
new PathViewManager(),
@@ -47,8 +50,9 @@ public class SvgPackage implements ReactPackage {
new SvgViewManager());
}
@Nonnull
@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
public List<NativeModule> createNativeModules(@Nonnull ReactApplicationContext reactContext) {
return Collections.<NativeModule>singletonList(new SvgViewModule(reactContext));
}
@@ -33,6 +33,7 @@ import java.io.ByteArrayOutputStream;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
/**
@@ -56,6 +57,7 @@ public class SvgView extends ReactViewGroup implements ReactCompoundView, ReactC
mName = name;
}
@Nonnull
public String toString() {
return mName;
}
@@ -149,8 +151,8 @@ public class SvgView extends ReactViewGroup implements ReactCompoundView, ReactC
private boolean mRendered = false;
int mTintColor = 0;
boolean isRendered() {
return mRendered;
boolean notRendered() {
return !mRendered;
}
private void clearChildCache() {
@@ -17,6 +17,7 @@ import com.facebook.react.uimanager.annotations.ReactProp;
import com.facebook.react.views.view.ReactViewGroup;
import com.facebook.react.views.view.ReactViewManager;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
/**
@@ -47,11 +48,13 @@ class SvgViewManager extends ReactViewManager {
return mTagToSvgView.get(tag);
}
@Nonnull
@Override
public String getName() {
return REACT_CLASS;
}
@Nonnull
@Override
public SvgView createViewInstance(ThemedReactContext reactContext) {
return new SvgView(reactContext);
@@ -64,7 +67,7 @@ class SvgViewManager extends ReactViewManager {
}
@Override
public void onDropViewInstance(ReactViewGroup view) {
public void onDropViewInstance(@Nonnull ReactViewGroup view) {
super.onDropViewInstance(view);
mTagToSvgView.remove(view.getId());
}
@@ -16,17 +16,20 @@ import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.UiThreadUtil;
import javax.annotation.Nonnull;
class SvgViewModule extends ReactContextBaseJavaModule {
SvgViewModule(ReactApplicationContext reactContext) {
super(reactContext);
}
@Nonnull
@Override
public String getName() {
return "RNSVGSvgViewManager";
}
static public void toDataURL(final int tag, final ReadableMap options, final Callback successCallback, final int attempt) {
private static void toDataURL(final int tag, final ReadableMap options, final Callback successCallback, final int attempt) {
UiThreadUtil.runOnUiThread(
new Runnable() {
@Override
@@ -49,7 +52,7 @@ class SvgViewModule extends ReactContextBaseJavaModule {
});
}
});
} else if (!svg.isRendered()) {
} else if (svg.notRendered()) {
svg.setToDataUrlTask(new Runnable() {
@Override
public void run() {
@@ -73,6 +76,7 @@ class SvgViewModule extends ReactContextBaseJavaModule {
);
}
@SuppressWarnings("unused")
@ReactMethod
public void toDataURL(int tag, ReadableMap options, Callback successCallback) {
toDataURL(tag, options, successCallback, 0);
@@ -51,8 +51,8 @@ class TSpanView extends TextView {
private Path mCachedPath;
@Nullable String mContent;
private TextPathView textPath;
ArrayList<String> emoji = new ArrayList<>();
ArrayList<Matrix> emojiTransforms = new ArrayList<>();
private final ArrayList<String> emoji = new ArrayList<>();
private final ArrayList<Matrix> emojiTransforms = new ArrayList<>();
public TSpanView(ReactContext reactContext) {
super(reactContext);
@@ -746,7 +746,7 @@ class TSpanView extends TextView {
break;
default:
baselineShift -= PropHelper.fromRelative(baselineShiftString, mScale * fontSize, 0, mScale, fontSize);
baselineShift -= PropHelper.fromRelative(baselineShiftString, mScale * fontSize, mScale, fontSize);
}
break;
}
@@ -781,7 +781,7 @@ class TSpanView extends TextView {
if (nextWidth > 0) {
break;
}
String nextLigature = current + String.valueOf(chars[nextIndex]);
String nextLigature = current + chars[nextIndex];
ligature[nextIndex] = true;
current = nextLigature;
hasLigature = true;
@@ -103,7 +103,7 @@ class TextPathView extends TextView {
SvgView svg = getSvgView();
VirtualView template = svg.getDefinedTemplate(mHref);
if (template == null || !(template instanceof RenderableView)) {
if (!(template instanceof RenderableView)) {
// warning about this.
return null;
}
@@ -3,6 +3,8 @@ package com.horcrux.svg;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Nonnull;
class TextProperties {
/*
@@ -67,6 +69,7 @@ class TextProperties {
}
}
@Nonnull
@Override
public String toString() {
return alignment;
@@ -125,6 +128,7 @@ class TextProperties {
}
}
@Nonnull
@Override
public String toString() {
return weight;
@@ -165,6 +169,7 @@ class TextProperties {
}
}
@Nonnull
@Override
public String toString() {
return decoration;
@@ -31,14 +31,14 @@ import static com.horcrux.svg.TextProperties.TextLengthAdjust;
@SuppressLint("ViewConstructor")
class TextView extends GroupView {
SVGLength mTextLength = null;
String mBaselineShift = null;
private String mBaselineShift = null;
TextLengthAdjust mLengthAdjust = TextLengthAdjust.spacing;
AlignmentBaseline mAlignmentBaseline;
@Nullable ArrayList<SVGLength> mPositionX;
@Nullable ArrayList<SVGLength> mPositionY;
@Nullable ArrayList<SVGLength> mRotate;
@Nullable ArrayList<SVGLength> mDeltaX;
@Nullable ArrayList<SVGLength> mDeltaY;
private AlignmentBaseline mAlignmentBaseline;
@Nullable private ArrayList<SVGLength> mPositionX;
@Nullable private ArrayList<SVGLength> mPositionY;
@Nullable private ArrayList<SVGLength> mRotate;
@Nullable private ArrayList<SVGLength> mDeltaX;
@Nullable private ArrayList<SVGLength> mDeltaY;
double cachedAdvance = Double.NaN;
public TextView(ReactContext reactContext) {
@@ -13,7 +13,6 @@ import android.view.ViewParent;
import com.facebook.common.logging.FLog;
import com.facebook.react.bridge.Dynamic;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableType;
import com.facebook.react.common.ReactConstants;
import com.facebook.react.uimanager.DisplayMetricsHolder;
@@ -23,8 +22,6 @@ import com.facebook.react.uimanager.annotations.ReactProp;
import com.facebook.react.uimanager.events.EventDispatcher;
import com.facebook.react.views.view.ReactViewGroup;
import java.util.ArrayList;
import javax.annotation.Nullable;
import static com.horcrux.svg.FontData.DEFAULT_FONT_SIZE;
@@ -57,7 +54,7 @@ abstract public class VirtualView extends ReactViewGroup {
Matrix mMatrix = new Matrix();
Matrix mTransform = new Matrix();
Matrix mInvMatrix = new Matrix();
Matrix mInvTransform = new Matrix();
final Matrix mInvTransform = new Matrix();
boolean mInvertible = true;
boolean mTransformInvertible = true;
private RectF mClientRect;
@@ -384,7 +381,7 @@ abstract public class VirtualView extends ReactViewGroup {
* @param length length string
* @return value in the current user coordinate system
*/
double fromRelativeFast(SVGLength length) {
private double fromRelativeFast(SVGLength length) {
double unit;
switch (length.unit) {
case SVG_LENGTHTYPE_EMS: