Skip to content

Commit 2ec53cd

Browse files
committed
[commit] lint
1 parent c7d4fea commit 2ec53cd

File tree

11 files changed

+28
-52
lines changed

11 files changed

+28
-52
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ compile 'com.code19.library:library:0.0.6'
8383
* px2dip 像素转dp
8484
* px2sp 像素转sp
8585
* sp2px sp转像素
86-
* getDialogW 获取dialog宽度
8786
* getScreenW 获取屏幕宽度
8887
* getScreenH 获取屏幕高度
8988
* getScreenRealSize 获取屏幕的真实高度

app/src/main/java/com/code19/androidcommon/ui/activity/DeviceActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ private void initDeviecesInfos() {
7979
sb.append("getUA--" + DeviceUtils.getUA(c) + "\n");
8080
sb.append("getDensity--" + DeviceUtils.getDensity(c) + "\n");
8181
//sb.append("getAccounts--" + DeviceUtils.getGoogleAccounts(c)[0] + "\n");
82-
sb.append("isRunningOnEmulator--" + DeviceUtils.isRunningOnEmulator() + "\n");
82+
sb.append("isRunningOnEmulator--" + SystemUtils.isRunningOnEmulator() + "\n");
8383
sb.append("isRooted--" + SystemUtils.isRooted() + "\n");
8484
sb.append("ScreenWidth x ScreenHeight--" + DensityUtil.getScreenW(c) + "x" + (DensityUtil.getScreenRealH(c)) + "\n");
8585
Log.i("ghost", "StatusBar:" + DensityUtil.getStatusBarH(c) + ",Nav:" + DensityUtil.getNavigationBarrH(c));

library/src/main/java/com/code19/library/AppUtils.java

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import java.io.IOException;
3636
import java.io.InputStreamReader;
3737
import java.lang.reflect.Method;
38-
import java.util.Iterator;
3938
import java.util.List;
4039
import java.util.regex.Pattern;
4140

@@ -216,9 +215,7 @@ public static boolean isServiceRunning(Context context, String className) {
216215
boolean isRunning = false;
217216
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
218217
List<RunningServiceInfo> servicesList = activityManager.getRunningServices(Integer.MAX_VALUE);
219-
Iterator<RunningServiceInfo> l = servicesList.iterator();
220-
while (l.hasNext()) {
221-
RunningServiceInfo si = (RunningServiceInfo) l.next();
218+
for (RunningServiceInfo si : servicesList) {
222219
if (className.equals(si.service.getClassName())) {
223220
isRunning = true;
224221
}
@@ -242,22 +239,15 @@ public static boolean stopRunningService(Context context, String className) {
242239

243240
public static int getNumCores() {
244241
try {
245-
//Get directory containing CPU info
246242
File dir = new File("/sys/devices/system/cpu/");
247-
//Filter to only list the devices we care about
248243
File[] files = dir.listFiles(new FileFilter() {
249244

250245
@Override
251246
public boolean accept(File pathname) {
252-
//Check if filename is "cpu", followed by a single digit number
253-
if (Pattern.matches("cpu[0-9]", pathname.getName())) {
254-
return true;
255-
}
256-
return false;
247+
return Pattern.matches("cpu[0-9]", pathname.getName());
257248
}
258249

259250
});
260-
//Return the number of cores (virtual CPU devices)
261251
return files.length;
262252
} catch (Exception e) {
263253
e.printStackTrace();
@@ -267,9 +257,9 @@ public boolean accept(File pathname) {
267257

268258
public static void killProcesses(Context context, int pid, String processName) {
269259
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
270-
String packageName = null;
260+
String packageName ;
271261
try {
272-
if (processName.indexOf(":") == -1) {
262+
if (!processName.contains(":")) {
273263
packageName = processName;
274264
} else {
275265
packageName = processName.split(":")[0];
@@ -284,7 +274,7 @@ public static void killProcesses(Context context, int pid, String processName) {
284274
}
285275

286276
public static String runScript(String script) {
287-
String sRet = "";
277+
String sRet;
288278
try {
289279
final Process m_process = Runtime.getRuntime().exec(script);
290280
final StringBuilder sbread = new StringBuilder();
@@ -293,7 +283,7 @@ public void run() {
293283
BufferedReader bufferedReader = new BufferedReader(
294284
new InputStreamReader(m_process.getInputStream()),
295285
8192);
296-
String ls_1 = null;
286+
String ls_1;
297287
try {
298288
while ((ls_1 = bufferedReader.readLine()) != null) {
299289
sbread.append(ls_1).append("\n");
@@ -317,7 +307,7 @@ public void run() {
317307
BufferedReader bufferedReader = new BufferedReader(
318308
new InputStreamReader(m_process.getErrorStream()),
319309
8192);
320-
String ls_1 = null;
310+
String ls_1 ;
321311
try {
322312
while ((ls_1 = bufferedReader.readLine()) != null) {
323313
sberr.append(ls_1).append("\n");
@@ -335,7 +325,7 @@ public void run() {
335325
});
336326
terr.start();
337327

338-
int retvalue = m_process.waitFor();
328+
m_process.waitFor();
339329
while (tout.isAlive()) {
340330
Thread.sleep(50);
341331
}

library/src/main/java/com/code19/library/BitmapUtils.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,9 @@ public static Bitmap decodeFile(String pathName, int width, int height) {
7474
}
7575

7676
public static Bitmap getImageThumbnail(String imagePath) {
77-
Bitmap bitmap = null;
7877
BitmapFactory.Options options = new BitmapFactory.Options();
7978
options.inJustDecodeBounds = true;
80-
bitmap = BitmapFactory.decodeFile(imagePath, options);
79+
Bitmap bitmap = BitmapFactory.decodeFile(imagePath, options);
8180
options.inJustDecodeBounds = false;
8281
int h = options.outHeight;
8382
int w = options.outWidth;

library/src/main/java/com/code19/library/CacheUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class CacheUtils {
2929
public static void setCache(Context context, String key, String strCache) {
3030
String encodeName = CipherUtils.encode(key);
3131
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
32-
boolean isCacheSuccess = FileUtils.writeFile(context.getExternalCacheDir() + "/" + encodeName, strCache);
32+
FileUtils.writeFile(context.getExternalCacheDir() + "/" + encodeName, strCache);
3333
}
3434
}
3535

library/src/main/java/com/code19/library/DensityUtil.java

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,6 @@ public static int sp2px(Context c, float spValue) {
5555
return (int) (spValue * fontScale + 0.5f);
5656
}
5757

58-
public static int getDialogW(Context c) {
59-
DisplayMetrics dm = new DisplayMetrics();
60-
dm = c.getResources().getDisplayMetrics();
61-
int w = dm.widthPixels - 100;
62-
// int w = aty.getWindowManager().getDefaultDisplay().getWidth() - 100;
63-
return w;
64-
}
65-
66-
6758
public static int getScreenW(Context c) {
6859
return c.getResources().getDisplayMetrics().widthPixels;
6960
}
@@ -74,7 +65,7 @@ public static int getScreenH(Context c) {
7465

7566
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
7667
public static int getScreenRealH(Context context) {
77-
int h = 0;
68+
int h;
7869
WindowManager winMgr = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
7970
Display display = winMgr.getDefaultDisplay();
8071
DisplayMetrics dm = new DisplayMetrics();
@@ -95,15 +86,15 @@ public static int getScreenRealH(Context context) {
9586
}
9687

9788
public static int getStatusBarH(Context context) {
98-
Class<?> c = null;
99-
Object obj = null;
100-
Field field = null;
101-
int x = 0, statusBarHeight = 0;
89+
Class<?> c;
90+
Object obj;
91+
Field field;
92+
int statusBarHeight = 0;
10293
try {
10394
c = Class.forName("com.android.internal.R$dimen");
10495
obj = c.newInstance();
10596
field = c.getField("status_bar_height");
106-
x = Integer.parseInt(field.get(obj).toString());
97+
int x = Integer.parseInt(field.get(obj).toString());
10798
statusBarHeight = context.getResources().getDimensionPixelSize(x);
10899
} catch (Exception e1) {
109100
e1.printStackTrace();

library/src/main/java/com/code19/library/DeviceUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ public static String getOSVersion() {
232232
* <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
233233
*/
234234
public static String getGSFID(Context context) {
235-
String result = null;
235+
String result;
236236
final Uri URI = Uri.parse("content://com.google.android.gsf.gservices");
237237
final String ID_KEY = "android_id";
238238
String[] params = {ID_KEY};

library/src/main/java/com/code19/library/FileUtils.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public static void zip(InputStream is, OutputStream os) {
115115
try {
116116
gzip = new GZIPOutputStream(os);
117117
byte[] buf = new byte[1024];
118-
int len = 0;
118+
int len;
119119
while ((len = is.read(buf)) != -1) {
120120
gzip.write(buf, 0, len);
121121
gzip.flush();
@@ -133,7 +133,7 @@ public static void unzip(InputStream is, OutputStream os) {
133133
try {
134134
gzip = new GZIPInputStream(is);
135135
byte[] buf = new byte[1024];
136-
int len = 0;
136+
int len;
137137
while ((len = gzip.read(buf)) != -1) {
138138
os.write(buf, 0, len);
139139
}
@@ -151,7 +151,7 @@ public static String formatFileSize(Context context, long size) {
151151

152152
public static void Stream2File(InputStream is, String fileName) {
153153
byte[] b = new byte[1024];
154-
int len = -1;
154+
int len;
155155
FileOutputStream os = null;
156156
try {
157157
os = new FileOutputStream(new File(fileName));

library/src/main/java/com/code19/library/NetUtils.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ public static String getNetworkTypeName(Context context) {
6262
if ("WIFI".equalsIgnoreCase(typeName)) {
6363
type = NETWORK_TYPE_WIFI;
6464
} else if ("MOBILE".equalsIgnoreCase(typeName)) {
65-
String proxyHost = android.net.Proxy.getDefaultHost();
65+
//String proxyHost = android.net.Proxy.getDefaultHost();//deprecated
66+
String proxyHost = System.getProperty("http.proxyHost");
6667
type = TextUtils.isEmpty(proxyHost) ? (isFastMobileNetwork(context) ? NETWORK_TYPE_3G : NETWORK_TYPE_2G) : NETWORK_TYPE_WAP;
6768
} else {
6869
type = NETWORK_TYPE_UNKNOWN;

library/src/main/java/com/code19/library/StringUtils.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public String getSelling(String chs) {
102102
for (int i = 0; i < chs.length(); i++) {
103103
key = chs.substring(i, i + 1);
104104
if (key.getBytes().length >= 2) {
105-
value = (String) convert(key);
105+
value = convert(key);
106106
if (value == null) {
107107
value = "unknown";
108108
}
@@ -122,7 +122,7 @@ public static String parseEmpty(String str) {
122122
}
123123

124124
public static boolean isEmpty(String str) {
125-
return str == null || str.trim().length() == 0 || str.trim().length() == 0;
125+
return str == null || str.trim().length() == 0 || "".equals(str);
126126
}
127127

128128
public static int chineseLength(String str) {
@@ -180,11 +180,7 @@ public static Boolean isChinese(String str) {
180180
if (!isEmpty(str)) {
181181
for (int i = 0; i < str.length(); i++) {
182182
String temp = str.substring(i, i + 1);
183-
if (temp.matches(chinese)) {
184-
isChinese = true;
185-
} else {
186-
isChinese = false;
187-
}
183+
isChinese = temp.matches(chinese);
188184
}
189185
}
190186
return isChinese;

library/src/main/java/com/code19/library/SystemUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public static void installApk(Context context, File apkfile) {
104104
static final String suSearchPaths[] = {"/system/bin/", "/system/xbin/", "/system/sbin/", "/sbin/", "/vendor/bin/"};
105105

106106
public static boolean isRooted() {
107-
File file = null;
107+
File file;
108108
boolean flag1 = false;
109109
for (String suSearchPath : suSearchPaths) {
110110
file = new File(suSearchPath + "su");
@@ -199,7 +199,7 @@ public static int getDeviceUsableMemory(Context cxt) {
199199

200200

201201
public static int gc(Context cxt) {
202-
long i = getDeviceUsableMemory(cxt);
202+
//long i = getDeviceUsableMemory(cxt);
203203
int count = 0;
204204
ActivityManager am = (ActivityManager) cxt.getSystemService(Context.ACTIVITY_SERVICE);
205205
List<RunningServiceInfo> serviceList = am.getRunningServices(100);

0 commit comments

Comments
 (0)