Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

Commit

Permalink
[Android] Fix problems in Android Lint (#2777)
Browse files Browse the repository at this point in the history
  • Loading branch information
YorkShen authored and lucky-chen committed Aug 1, 2019
1 parent 529a56f commit 756eb78
Show file tree
Hide file tree
Showing 17 changed files with 78 additions and 43 deletions.
1 change: 1 addition & 0 deletions android/sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ dependencies {
testImplementation 'org.hamcrest:hamcrest-core:1.3'
testImplementation 'org.javassist:javassist:3.20.0-GA'
testImplementation 'org.mockito:mockito-core:1.10.19'
//noinspection GradleDependency
testImplementation 'org.objenesis:objenesis:2.1'
testImplementation 'org.powermock:powermock-core:1.6.4'
testImplementation 'org.powermock:powermock-api-mockito:1.6.4'
Expand Down
9 changes: 5 additions & 4 deletions android/sdk/src/main/java/com/taobao/weex/WXEnvironment.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
Expand Down Expand Up @@ -48,6 +48,7 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

Expand All @@ -58,10 +59,10 @@ public class WXEnvironment {
public static final String OS = "android";
public static String SYS_VERSION = android.os.Build.VERSION.RELEASE;
static{
if(SYS_VERSION != null && SYS_VERSION.toUpperCase().equals("P")){
if(SYS_VERSION != null && SYS_VERSION.toUpperCase(Locale.ROOT).equals("P")){
SYS_VERSION = "9.0.0";
}
if(SYS_VERSION != null && SYS_VERSION.toUpperCase().equals("Q")){
if(SYS_VERSION != null && SYS_VERSION.toUpperCase(Locale.ROOT).equals("Q")){
SYS_VERSION = "10.0.0";
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,7 @@ public boolean shouldReloadCurrentInstance(String aUrl) {
public void callReportCrash(String crashFile, final String instanceId, final String url) {
// statistic weex core process crash
Date date = new Date();
DateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
DateFormat format = new SimpleDateFormat("yyyyMMddHHmmss", Locale.US);
String time = format.format(date);
final String origin_filename = crashFile + "." + time;
File oldfile = new File(crashFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ public WXJSObject(Object object) {
data = object;
if (object instanceof Integer) {
type = NUMBER;
data = new Double(((Integer) object).intValue());
data = (double) (Integer) object;
} else if (object instanceof Double) {
type = NUMBER;
} else if (object instanceof Float) {
type = NUMBER;
data = new Double(((Float) object).intValue());
data = (double) ((Float) object).intValue();
} else if (object instanceof String) {
type = String;
} else if (object instanceof Object) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -76,7 +77,7 @@ public void sendHttp(JSONObject paramsObj, final String callback) {
String body = paramsObj.getString("body");
int timeout = paramsObj.getIntValue("timeout");

if (method != null) method = method.toUpperCase();
if (method != null) method = method.toUpperCase(Locale.ROOT);
Options.Builder builder = new Options.Builder()
.setMethod(!"GET".equals(method)
&&!"POST".equals(method)
Expand Down Expand Up @@ -157,7 +158,7 @@ public void fetch(JSONObject optionsObj , final JSCallback callback, JSCallback
}
}

if (method != null) method = method.toUpperCase();
if (method != null) method = method.toUpperCase(Locale.ROOT);
Options.Builder builder = new Options.Builder()
.setMethod(!"GET".equals(method)
&&!"POST".equals(method)
Expand Down Expand Up @@ -234,7 +235,7 @@ static String getHeader(Map<String,String> headers,String key){
if(headers.containsKey(key)){
return headers.get(key);
}else{
return headers.get(key.toLowerCase());
return headers.get(key.toLowerCase(Locale.ROOT));
}
}

Expand All @@ -243,7 +244,7 @@ static String getHeader(Map<String,String> headers,String key){
static String readAsString(byte[] data,String cType){
String charset = "utf-8";
if(cType != null){
Matcher matcher = CHARSET_PATTERN.matcher(cType.toLowerCase());
Matcher matcher = CHARSET_PATTERN.matcher(cType.toLowerCase(Locale.ROOT));
if(matcher.find()){
charset = matcher.group(1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentLinkedQueue;
Expand Down Expand Up @@ -979,7 +980,7 @@ public void setLayout(WXComponent component) {
mInstance.getWXPerformance().cellExceedNum++;
if (WXAnalyzerDataTransfer.isOpenPerformance){
WXAnalyzerDataTransfer.transferPerformance(getInstanceId(),"details",WXInstanceApm.KEY_PAGE_STATS_CELL_EXCEED_NUM,
String.format("cell:[w:%d,h:%d],attrs:%s,styles:%s",realWidth,realHeight,getAttrs(),getStyles())
String.format(Locale.ROOT, "cell:[w:%d,h:%d],attrs:%s,styles:%s",realWidth,realHeight,getAttrs(),getStyles())
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import android.Manifest;
Expand Down Expand Up @@ -484,7 +485,7 @@ private void monitorImgSize(ImageView imageView,String currentImgUrlStr){

if (WXAnalyzerDataTransfer.isOpenPerformance){
WXAnalyzerDataTransfer.transferPerformance(getInstanceId(),"details",WXInstanceApm.KEY_PAGE_STATS_WRONG_IMG_SIZE_COUNT,
String.format("imgSize:[%d,%d],viewSize:[%d,%d],urL:%s",imgWidth,imgHeight,imageView.getMeasuredWidth(),imageView.getMeasuredHeight()
String.format(Locale.ROOT, "imgSize:[%d,%d],viewSize:[%d,%d],urL:%s",imgWidth,imgHeight,imageView.getMeasuredWidth(),imageView.getMeasuredHeight()
,currentImgUrlStr)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,7 @@
*/
package com.taobao.weex.ui.component;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Point;
Expand All @@ -33,12 +27,10 @@
import android.os.Handler;
import android.os.Looper;
import android.support.annotation.NonNull;
import android.support.annotation.RequiresApi;
import android.support.v4.view.ViewCompat;
import android.text.TextUtils;
import android.view.Gravity;
import android.util.Log;
import android.view.GestureDetector;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
Expand Down Expand Up @@ -68,6 +60,12 @@
import com.taobao.weex.utils.WXLogUtils;
import com.taobao.weex.utils.WXUtils;
import com.taobao.weex.utils.WXViewUtils;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

/**
* Component for scroller. It also support features like
Expand Down Expand Up @@ -389,6 +387,7 @@ public void destroy() {
}
}

@SuppressLint("RtlHardcoded")
@Override
public void setMarginsSupportRTL(ViewGroup.MarginLayoutParams lp, int left, int top, int right, int bottom) {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
Expand Down Expand Up @@ -419,7 +418,7 @@ public void setLayout(WXComponent component) {
return;
}
if (component.getHostView() != null) {
int layoutDirection = component.isLayoutRTL() ? View.LAYOUT_DIRECTION_RTL : View.LAYOUT_DIRECTION_LTR;
int layoutDirection = component.isLayoutRTL() ? ViewCompat.LAYOUT_DIRECTION_RTL : ViewCompat.LAYOUT_DIRECTION_LTR;
ViewCompat.setLayoutDirection(component.getHostView(), layoutDirection);
}
super.setLayout(component);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public void setMarginsSupportRTL(ViewGroup.MarginLayoutParams lp, int left, int
@Override
public void setLayout(WXComponent component) {
if (component.getHostView() != null) {
int layoutDirection = component.isLayoutRTL() ? View.LAYOUT_DIRECTION_RTL : View.LAYOUT_DIRECTION_LTR;
int layoutDirection = component.isLayoutRTL() ? ViewCompat.LAYOUT_DIRECTION_RTL : ViewCompat.LAYOUT_DIRECTION_LTR;
ViewCompat.setLayoutDirection(component.getHostView(), layoutDirection);
}
super.setLayout(component);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package com.taobao.weex.ui.view;

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Build;
import android.view.ActionMode;
Expand All @@ -33,6 +34,7 @@
/**
* Wrapper class for editText
*/
@SuppressLint("AppCompatCustomView")
public class WXEditText extends EditText implements WXGestureObservable {

private WXGesture wxGesture;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package com.taobao.weex.ui.view;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
Expand All @@ -39,6 +40,7 @@
import java.lang.ref.WeakReference;
import java.util.Arrays;

@SuppressLint("AppCompatCustomView")
public class WXImageView extends ImageView implements WXGestureObservable,
IRenderStatus<WXImage>,
IRenderResult<WXImage>, WXImage.Measurable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package com.taobao.weex.ui.view.refresh.circlebar;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Canvas;
Expand All @@ -35,6 +36,7 @@
/**
* Modify of android.support.v4
*/
@SuppressLint("AppCompatCustomView")
public class CircleProgressBar extends ImageView {

private static final int KEY_SHADOW_COLOR = 0x1E000000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import android.animation.Animator;
import android.animation.ValueAnimator;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Color;
Expand Down Expand Up @@ -692,11 +693,14 @@ private void resetLoadmoreState() {
* Whether child view can scroll up
* @return
*/
@SuppressLint("ObsoleteSdkInt")
public boolean canChildScrollUp() {
if (mTargetView == null) {
return false;
}
if (Build.VERSION.SDK_INT < 14) {
//The minimum version of Android platform that Weex supports is API 14,
//so this block should never enter.
if (mTargetView instanceof AbsListView) {
final AbsListView absListView = (AbsListView) mTargetView;
return absListView.getChildCount() > 0
Expand All @@ -714,11 +718,14 @@ public boolean canChildScrollUp() {
* Whether child view can scroll down
* @return
*/
@SuppressLint("ObsoleteSdkInt")
public boolean canChildScrollDown() {
if (mTargetView == null) {
return false;
}
if (Build.VERSION.SDK_INT < 14) {
//The minimum version of Android platform that Weex supports is API 14,
//so this block should never enter.
if (mTargetView instanceof AbsListView) {
final AbsListView absListView = (AbsListView) mTargetView;
if (absListView.getChildCount() > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@
import android.graphics.LinearGradient;
import android.graphics.Shader;
import android.support.annotation.NonNull;
import android.support.v4.util.LruCache;
import android.util.Pair;
import android.text.TextUtils;

import android.util.Pair;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.StringTokenizer;

Expand Down Expand Up @@ -334,7 +333,7 @@ private static float[] parseGradientDirection(String direction, float width, flo
float[] points = {0, 0, 0, 0};

if (!TextUtils.isEmpty(direction)) {
direction = direction.replaceAll("\\s*", "").toLowerCase();
direction = direction.replaceAll("\\s*", "").toLowerCase(Locale.ROOT);
}

switch (direction) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,27 @@
*/
package com.taobao.weex.utils;

import android.annotation.SuppressLint;
import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.os.Build;
import android.preference.PreferenceManager;
import android.text.TextUtils;
import android.util.Log;

import com.taobao.weex.IWXStatisticsListener;
import com.taobao.weex.WXEnvironment;
import com.taobao.weex.adapter.IWXSoLoaderAdapter;
import com.taobao.weex.adapter.IWXUserTrackAdapter;
import com.taobao.weex.common.WXErrorCode;
import dalvik.system.PathClassLoader;
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.util.Enumeration;
import java.util.Locale;
import java.util.zip.ZipEntry;
import java.util.zip.ZipException;
import java.util.zip.ZipFile;
Expand Down Expand Up @@ -76,13 +69,13 @@ public class WXSoInstallMgrSdk {
private final static String STARTUPSO = "/libweexjsb.so";
private final static String STARTUPSOANDROID15 = "/libweexjst.so";

static Context mContext = null;
static Application mContext = null;
private static IWXSoLoaderAdapter mSoLoader = null;
private static IWXStatisticsListener mStatisticsListener = null;

private static String mAbi = null;

public static void init(Context c,
public static void init(Application c,
IWXSoLoaderAdapter loader,
IWXStatisticsListener listener) {
mContext = c;
Expand Down Expand Up @@ -358,7 +351,7 @@ private static String _cpuType() {
if (TextUtils.isEmpty(mAbi)){
mAbi = ARMEABI;
}
mAbi = mAbi.toLowerCase();
mAbi = mAbi.toLowerCase(Locale.ROOT);
}
return mAbi;
}
Expand Down Expand Up @@ -455,6 +448,7 @@ static boolean isExist(String libName, int version) {
/**
* Load .so library
*/
@SuppressLint("UnsafeDynamicallyLoadedCode")
static boolean _loadUnzipSo(String libName,
int version,
IWXUserTrackAdapter utAdapter) {
Expand Down
Loading

0 comments on commit 756eb78

Please sign in to comment.