From 311558681a11f2c8faf9903b49630ee935b02495 Mon Sep 17 00:00:00 2001
From: h4de5ing <1229075001@qq.com>
Date: Wed, 26 Jul 2017 13:43:26 +0800
Subject: [PATCH 1/6] add RadixUtils.java
---
README-cn.md | 4 +-
build.gradle | 2 +-
.../java/com/code19/library/RadixUtils.java | 95 +++++++++++++++++++
3 files changed, 99 insertions(+), 2 deletions(-)
create mode 100644 library/src/main/java/com/code19/library/RadixUtils.java
diff --git a/README-cn.md b/README-cn.md
index 73437c1..b9d1336 100644
--- a/README-cn.md
+++ b/README-cn.md
@@ -204,7 +204,9 @@ AppUtils.getAppName(MainActivity.this,com.code19.androidcommon);
* getWifiScanResults 获取wifi列表
* getScanResultsByBSSID 过滤扫描结果
* getWifiConnectionInfo 获取wifi连接信息
-
+
+- RadixUtils 进制工具类
+ *
- SPUtils.java SharedPreferences工具
* setSP 存储SharedPreferences值
* getSp 获取SharedPreferences值
diff --git a/build.gradle b/build.gradle
index b81d782..896591c 100644
--- a/build.gradle
+++ b/build.gradle
@@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
- classpath 'com.android.tools.build:gradle:2.3.0'
+ classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
diff --git a/library/src/main/java/com/code19/library/RadixUtils.java b/library/src/main/java/com/code19/library/RadixUtils.java
new file mode 100644
index 0000000..8cd5d26
--- /dev/null
+++ b/library/src/main/java/com/code19/library/RadixUtils.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright (C) 2016 android@19code.com
+ *
+ * Licensed 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 KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.code19.library;
+
+/**
+ * Created by Gh0st on 2017/7/26.
+ */
+
+public class RadixUtils {
+ //16->2
+ public static String hexString2binaryString(String hexString) {
+ if (hexString.length() % 2 != 0) {
+ hexString = "0" + hexString;
+ }
+ String bString = "", tmp;
+ for (int i = 0; i < hexString.length(); i++) {
+ tmp = "0000" + Integer.toBinaryString(Integer.parseInt(hexString.substring(i, i + 1), 16));
+ bString += tmp.substring(tmp.length() - 4);
+ }
+ return bString;
+ }
+
+ //2->16
+ public static String binaryString2hexString(String bString) {
+ if (bString.length() % 8 != 0) {
+ String sbuwei = "00000000";
+ bString = sbuwei.substring(0, sbuwei.length() - bString.length() % 8) + bString;
+ }
+ StringBuilder tmp = new StringBuilder();
+ int iTmp = 0;
+ for (int i = 0; i < bString.length(); i += 4) {
+ iTmp = 0;
+ for (int j = 0; j < 4; j++) {
+ iTmp += Integer.parseInt(bString.substring(i + j, i + j + 1)) << (4 - j - 1);
+ }
+ tmp.append(Integer.toHexString(iTmp));
+ }
+ return tmp.toString();
+ }
+
+ public static String addBinary(String a, String b) {
+ int carry = 0;
+ int sum = 0;
+ int opa = 0;
+ int opb = 0;
+ StringBuilder result = new StringBuilder();
+ while (a.length() != b.length()) {
+ if (a.length() > b.length()) {
+ b = "0" + b;
+ } else {
+ a = "0" + a;
+ }
+ }
+ for (int i = a.length() - 1; i >= 0; i--) {
+ opa = a.charAt(i) - '0';
+ opb = b.charAt(i) - '0';
+ sum = opa + opb + carry;
+ if (sum >= 2) {
+ result.append((char) (sum - 2 + '0'));
+ carry = 1;
+ } else {
+ result.append((char) (sum + '0'));
+ carry = 0;
+ }
+ }
+ if (carry == 1) {
+ result.append("1");
+ }
+ return result.reverse().toString();
+ }
+
+ public static String hexArray2String(byte[] data) {
+ StringBuilder sb = new StringBuilder(data.length * 2);
+ final char[] HEX = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
+ 'A', 'B', 'C', 'D', 'E', 'F'};
+ for (int i = 0; i < data.length; i++) {
+ int value = data[i] & 0xff;
+ sb.append(HEX[value / 16]).append(HEX[value % 16]).append(" ");
+ }
+ return sb.toString();
+ }
+}
From 5704dd81c292d2f646cf5fc56e9ed23bccd3cfa5 Mon Sep 17 00:00:00 2001
From: h4de5ing <1229075001@qq.com>
Date: Mon, 7 Aug 2017 11:36:44 +0800
Subject: [PATCH 2/6] del android 7.0 method
---
README-cn.md | 4 +-
README.md | 4 +-
library/build.gradle | 12 +--
library/src/main/AndroidManifest.xml | 6 --
.../java/com/code19/library/AppUtils.java | 7 +-
.../java/com/code19/library/FileUtils.java | 8 +-
.../library/service/DownloadService.java | 82 -------------------
7 files changed, 17 insertions(+), 106 deletions(-)
delete mode 100644 library/src/main/java/com/code19/library/service/DownloadService.java
diff --git a/README-cn.md b/README-cn.md
index b9d1336..b469bf0 100644
--- a/README-cn.md
+++ b/README-cn.md
@@ -31,8 +31,8 @@ AppUtils.getAppName(MainActivity.this,com.code19.androidcommon);
* getAppPermissions 获取应用的所有权限
* hasPermission 是否有权限
* isInstalled 应用是否安装
- * installApk 安装应用
- * uninstallApk 卸载应用
+ * ~~installApk 安装应用~~
+ * ~~uninstallApk 卸载应用~~
* isSystemApp 是否是系统应用
* isServiceRunning 服务是否在运行
* stopRunningService 停止服务
diff --git a/README.md b/README.md
index 65f1c84..660405e 100644
--- a/README.md
+++ b/README.md
@@ -31,8 +31,8 @@ AppUtils.getAppName(MainActivity.this,com.code19.androidcommon);
* getAppPermissions
* hasPermission
* isInstalled
- * installApk
- * uninstallApk
+ * ~~installApk~~
+ * ~~uninstallApk~~
* isSystemApp
* isServiceRunning
* stopRunningService
diff --git a/library/build.gradle b/library/build.gradle
index 1337085..b718c8b 100644
--- a/library/build.gradle
+++ b/library/build.gradle
@@ -2,16 +2,16 @@ apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'
-version = "0.1.2" //版本号,更新代码后修改这个值
+version = "0.1.4" //版本号,更新代码后修改这个值
android {
compileSdkVersion 24
- buildToolsVersion '25.0.0'
+ buildToolsVersion '25.0.3'
defaultConfig {
minSdkVersion 15
- targetSdkVersion 24
- versionCode 1
- versionName "1.0"
+ targetSdkVersion 25
+ versionCode 2
+ versionName "0.1.4"
}
buildTypes {
release {
@@ -22,7 +22,7 @@ android {
}
dependencies {
- compile 'com.android.support:appcompat-v7:24.2.1'
+ //compile 'com.android.support:appcompat-v7:24.2.1'
//compile fileTree(include: ['*.jar'], dir: 'libs')
//testCompile 'junit:junit:4.12'
compile 'com.google.code.gson:gson:2+'
diff --git a/library/src/main/AndroidManifest.xml b/library/src/main/AndroidManifest.xml
index 4bd2141..c875181 100644
--- a/library/src/main/AndroidManifest.xml
+++ b/library/src/main/AndroidManifest.xml
@@ -25,12 +25,6 @@
android:allowBackup="true"
android:supportsRtl="true">
-
- * author: Blankj - * blog : http://blankj.com - * time : 16/12/13 - * https://github.com/smuyyh/CommonLibary - * https://github.com/Blankj/AndroidUtilCode - * https://github.com/Blankj/AndroidUtilCode/blob/master/utilcode/src/main/java/com/blankj/utilcode/utils/SpannableStringUtils.java - * doc http://www.jianshu.com/p/ab1a72750824 - *- */ -public class SpannableStringUtils { - - private SpannableStringUtils() { - throw new UnsupportedOperationException("u can't instantiate me..."); - } - - public static Builder getBuilder(Context context, @NonNull CharSequence text) { - return new Builder(context, text); - } - - public static class Builder { - - private int defaultValue = 0x12000000; - private CharSequence text; - - private int flag; - @ColorInt - private int foregroundColor; - @ColorInt - private int backgroundColor; - @ColorInt - private int quoteColor; - - private boolean isLeadingMargin; - private int first; - private int rest; - - private boolean isBullet; - private int gapWidth; - private int bulletColor; - - private float proportion; - private float xProportion; - private boolean isStrikethrough; - private boolean isUnderline; - private boolean isSuperscript; - private boolean isSubscript; - private boolean isBold; - private boolean isItalic; - private boolean isBoldItalic; - private String fontFamily; - private Alignment align; - - private boolean imageIsBitmap; - private Bitmap bitmap; - private boolean imageIsDrawable; - private Drawable drawable; - private boolean imageIsUri; - private Uri uri; - private boolean imageIsResourceId; - @DrawableRes - private int resourceId; - - private ClickableSpan clickSpan; - private String url; - - private boolean isBlur; - private float radius; - private Blur style; - private Context mContext; - - private SpannableStringBuilder mBuilder; - - - private Builder(Context context, @NonNull CharSequence text) { - this.mContext = context; - this.text = text; - flag = Spanned.SPAN_EXCLUSIVE_EXCLUSIVE; - foregroundColor = defaultValue; - backgroundColor = defaultValue; - quoteColor = defaultValue; - proportion = -1; - xProportion = -1; - mBuilder = new SpannableStringBuilder(); - } - - public Builder setFlag(int flag) { - this.flag = flag; - return this; - } - - public Builder setForegroundColor(@ColorInt int color) { - this.foregroundColor = color; - return this; - } - - public Builder setBackgroundColor(@ColorInt int color) { - this.backgroundColor = color; - return this; - } - - public Builder setQuoteColor(@ColorInt int color) { - this.quoteColor = color; - return this; - } - - public Builder setLeadingMargin(int first, int rest) { - this.first = first; - this.rest = rest; - isLeadingMargin = true; - return this; - } - - public Builder setBullet(int gapWidth, int color) { - this.gapWidth = gapWidth; - bulletColor = color; - isBullet = true; - return this; - } - - public Builder setProportion(float proportion) { - this.proportion = proportion; - return this; - } - - public Builder setXProportion(float proportion) { - this.xProportion = proportion; - return this; - } - - public Builder setStrikethrough() { - this.isStrikethrough = true; - return this; - } - - - public Builder setUnderline() { - this.isUnderline = true; - return this; - } - - - public Builder setSuperscript() { - this.isSuperscript = true; - return this; - } - - - public Builder setSubscript() { - this.isSubscript = true; - return this; - } - - - public Builder setBold() { - isBold = true; - return this; - } - - - public Builder setItalic() { - isItalic = true; - return this; - } - - - public Builder setBoldItalic() { - isBoldItalic = true; - return this; - } - - - public Builder setFontFamily(@Nullable String fontFamily) { - this.fontFamily = fontFamily; - return this; - } - - - public Builder setAlign(@Nullable Alignment align) { - this.align = align; - return this; - } - - - public Builder setBitmap(@NonNull Bitmap bitmap) { - this.bitmap = bitmap; - imageIsBitmap = true; - return this; - } - - - public Builder setDrawable(@NonNull Drawable drawable) { - this.drawable = drawable; - imageIsDrawable = true; - return this; - } - - - public Builder setUri(@NonNull Uri uri) { - this.uri = uri; - imageIsUri = true; - return this; - } - - - public Builder setResourceId(@DrawableRes int resourceId) { - this.resourceId = resourceId; - imageIsResourceId = true; - return this; - } - - - public Builder setClickSpan(@NonNull ClickableSpan clickSpan) { - this.clickSpan = clickSpan; - return this; - } - - - public Builder setUrl(@NonNull String url) { - this.url = url; - return this; - } - - - public Builder setBlur(float radius, Blur style) { - this.radius = radius; - this.style = style; - this.isBlur = true; - return this; - } - - - public Builder append(@NonNull CharSequence text) { - setSpan(); - this.text = text; - return this; - } - - public SpannableStringBuilder create() { - setSpan(); - return mBuilder; - } - - private void setSpan() { - int start = mBuilder.length(); - mBuilder.append(this.text); - int end = mBuilder.length(); - if (foregroundColor != defaultValue) { - mBuilder.setSpan(new ForegroundColorSpan(foregroundColor), start, end, flag); - foregroundColor = defaultValue; - } - if (backgroundColor != defaultValue) { - mBuilder.setSpan(new BackgroundColorSpan(backgroundColor), start, end, flag); - backgroundColor = defaultValue; - } - if (isLeadingMargin) { - mBuilder.setSpan(new LeadingMarginSpan.Standard(first, rest), start, end, flag); - isLeadingMargin = false; - } - if (quoteColor != defaultValue) { - mBuilder.setSpan(new QuoteSpan(quoteColor), start, end, 0); - quoteColor = defaultValue; - } - if (isBullet) { - mBuilder.setSpan(new BulletSpan(gapWidth, bulletColor), start, end, 0); - isBullet = false; - } - if (proportion != -1) { - mBuilder.setSpan(new RelativeSizeSpan(proportion), start, end, flag); - proportion = -1; - } - if (xProportion != -1) { - mBuilder.setSpan(new ScaleXSpan(xProportion), start, end, flag); - xProportion = -1; - } - if (isStrikethrough) { - mBuilder.setSpan(new StrikethroughSpan(), start, end, flag); - isStrikethrough = false; - } - if (isUnderline) { - mBuilder.setSpan(new UnderlineSpan(), start, end, flag); - isUnderline = false; - } - if (isSuperscript) { - mBuilder.setSpan(new SuperscriptSpan(), start, end, flag); - isSuperscript = false; - } - if (isSubscript) { - mBuilder.setSpan(new SubscriptSpan(), start, end, flag); - isSubscript = false; - } - if (isBold) { - mBuilder.setSpan(new StyleSpan(Typeface.BOLD), start, end, flag); - isBold = false; - } - if (isItalic) { - mBuilder.setSpan(new StyleSpan(Typeface.ITALIC), start, end, flag); - isItalic = false; - } - if (isBoldItalic) { - mBuilder.setSpan(new StyleSpan(Typeface.BOLD_ITALIC), start, end, flag); - isBoldItalic = false; - } - if (fontFamily != null) { - mBuilder.setSpan(new TypefaceSpan(fontFamily), start, end, flag); - fontFamily = null; - } - if (align != null) { - mBuilder.setSpan(new AlignmentSpan.Standard(align), start, end, flag); - align = null; - } - if (imageIsBitmap || imageIsDrawable || imageIsUri || imageIsResourceId) { - if (imageIsBitmap) { - mBuilder.setSpan(new ImageSpan(mContext, bitmap), start, end, flag); - bitmap = null; - imageIsBitmap = false; - } else if (imageIsDrawable) { - mBuilder.setSpan(new ImageSpan(drawable), start, end, flag); - drawable = null; - imageIsDrawable = false; - } else if (imageIsUri) { - mBuilder.setSpan(new ImageSpan(mContext, uri), start, end, flag); - uri = null; - imageIsUri = false; - } else { - mBuilder.setSpan(new ImageSpan(mContext, resourceId), start, end, flag); - resourceId = 0; - imageIsResourceId = false; - } - } - if (clickSpan != null) { - mBuilder.setSpan(clickSpan, start, end, flag); - clickSpan = null; - } - if (url != null) { - mBuilder.setSpan(new URLSpan(url), start, end, flag); - url = null; - } - if (isBlur) { - mBuilder.setSpan(new MaskFilterSpan(new BlurMaskFilter(radius, style)), start, end, flag); - isBlur = false; - } - flag = Spanned.SPAN_EXCLUSIVE_EXCLUSIVE; - } - } -} \ No newline at end of file diff --git a/library/src/main/java/com/code19/library/SystemUtils.java b/library/src/main/java/com/code19/library/SystemUtils.java index b69da7f..07e4486 100644 --- a/library/src/main/java/com/code19/library/SystemUtils.java +++ b/library/src/main/java/com/code19/library/SystemUtils.java @@ -15,7 +15,6 @@ */ package com.code19.library; -import android.Manifest; import android.annotation.SuppressLint; import android.app.Activity; import android.app.ActivityManager; @@ -32,7 +31,6 @@ import android.net.Uri; import android.os.Build; import android.os.Parcelable; -import android.support.v4.app.ActivityCompat; import android.text.TextUtils; import android.view.inputmethod.InputMethodManager; import android.widget.EditText; @@ -60,15 +58,6 @@ public static void forwardToDial(Activity activity, String phoneNumber) { } } - public static void callPhone(Activity activity, String phoneNumber) { - if (activity != null && !TextUtils.isEmpty(phoneNumber)) { - if (ActivityCompat.checkSelfPermission(activity, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) { - return; - } - activity.startActivity(new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phoneNumber))); - } - } - public static void sendMail(Context mContext, String mailID) { Uri uri = Uri.parse("mailto:" + mailID); mContext.startActivity(new Intent(Intent.ACTION_SENDTO, uri)); diff --git a/library/src/main/java/com/code19/library/ToastUtils.java b/library/src/main/java/com/code19/library/ToastUtils.java deleted file mode 100644 index 5e458f5..0000000 --- a/library/src/main/java/com/code19/library/ToastUtils.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.code19.library; - -import android.content.Context; -import android.widget.Toast; - -/** - * Created by gh0st on 2017/1/17. - */ - -public class ToastUtils { - private static Toast mToast; - - public static void showToast(Context context, int id) { - if (mToast == null) { - mToast = new Toast(context); - mToast.setText(id); - } - mToast.show(); - } - - public static void showToast(Context context, String string) { - if (mToast == null) { - mToast = new Toast(context); - mToast.setText(string); - } - mToast.show(); - } -} diff --git a/library/src/main/java/com/code19/library/ViewUtils.java b/library/src/main/java/com/code19/library/ViewUtils.java deleted file mode 100644 index 80a18cd..0000000 --- a/library/src/main/java/com/code19/library/ViewUtils.java +++ /dev/null @@ -1,238 +0,0 @@ -/* - * Copyright (C) 2016 android@19code.com - * - * Licensed 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 KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.code19.library; - -import android.app.Activity; -import android.content.Context; -import android.content.ContextWrapper; -import android.content.res.Resources; -import android.content.res.TypedArray; -import android.graphics.Bitmap; -import android.graphics.Canvas; -import android.graphics.Matrix; -import android.graphics.Paint; -import android.graphics.drawable.BitmapDrawable; -import android.view.LayoutInflater; -import android.view.MotionEvent; -import android.view.View; -import android.view.View.MeasureSpec; -import android.view.ViewGroup; -import android.view.ViewParent; -import android.widget.PopupWindow; -import android.widget.TextView; -import android.widget.Toast; - - -/** - * Blog : http://blog.csdn.net/u011240877 - */ -public class ViewUtils { - - public static void removeSelfFromParent(View view) { - if (view != null) { - ViewParent parent = view.getParent(); - if (parent != null && parent instanceof ViewGroup) { - ViewGroup group = (ViewGroup) parent; - group.removeView(view); - } - } - } - - - public static void requestLayoutParent(View view, boolean isAll) { - ViewParent parent = view.getParent(); - while (parent != null && parent instanceof View) { - if (!parent.isLayoutRequested()) { - parent.requestLayout(); - if (!isAll) { - break; - } - } - parent = parent.getParent(); - } - } - - - public static boolean isTouchInView(MotionEvent ev, View v) { - int[] vLoc = new int[2]; - v.getLocationOnScreen(vLoc); - float motionX = ev.getRawX(); - float motionY = ev.getRawY(); - return motionX >= vLoc[0] && motionX <= (vLoc[0] + v.getWidth()) && motionY >= vLoc[1] && motionY <= (vLoc[1] + v.getHeight()); - } - - public static Bitmap bigImage(Bitmap bmp, float big) { - int bmpWidth = bmp.getWidth(); - int bmpHeight = bmp.getHeight(); - Matrix matrix = new Matrix(); - matrix.postScale(big, big); - return Bitmap.createBitmap(bmp, 0, 0, bmpWidth, bmpHeight, matrix, true); - } - - - public static void setTVUnderLine(TextView textView) { - textView.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG); - textView.getPaint().setAntiAlias(true); - } - - - static PopupWindow popupWindow; - - public static View showPopupWindow(Context context, int resId, View root, int paramsType) { - View popupView; - popupView = LayoutInflater.from(context).inflate(resId, null); - - switch (paramsType) { - case 1: - popupWindow = new PopupWindow(popupView, - ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, true); - break; - case 2: - popupWindow = new PopupWindow(popupView, - ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, true); - break; - case 3: - popupWindow = new PopupWindow(popupView, - ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT, true); - break; - case 4: - popupWindow = new PopupWindow(popupView, - ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, true); - break; - default: - popupWindow = new PopupWindow(popupView, - ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, true); - break; - } - popupWindow.setFocusable(true); - popupWindow.setOutsideTouchable(true); - popupWindow.setTouchable(true); - popupWindow.setBackgroundDrawable(new BitmapDrawable()); - popupWindow.showAsDropDown(root); - return popupView; - } - - - public static void dismissPopup() { - if (popupWindow != null && popupWindow.isShowing()) { - popupWindow.dismiss(); - popupWindow = null; - } - } - - public static Bitmap captureView(View v) { - v.setDrawingCacheEnabled(true); - v.buildDrawingCache(); - return v.getDrawingCache(); - } - - - public static Bitmap createViewBitmap(View v) { - Bitmap bitmap = Bitmap.createBitmap(v.getWidth(), v.getHeight(), Bitmap.Config.ARGB_8888); - Canvas canvas = new Canvas(bitmap); - v.draw(canvas); - return bitmap; - } - - - public static Bitmap convertViewToBitmap(View view) { - view.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); - view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight()); - view.buildDrawingCache(); - return view.getDrawingCache(); - } - - - public static Bitmap getActivityBitmap(Activity activity) { - View view = activity.getWindow().getDecorView().findViewById(android.R.id.content); - view.setDrawingCacheEnabled(true); - return view.getDrawingCache(); - } - - - public static int getStatusBarHeight(Context context) { - int result = 0; - int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android"); - if (resourceId > 0) { - result = context.getResources().getDimensionPixelSize(resourceId); - } - return result; - } - - - public static int getToolbarHeight(Context context) { - final TypedArray styledAttributes = context.getTheme().obtainStyledAttributes(new int[]{R.attr.actionBarSize}); - int toolbarHeight = (int) styledAttributes.getDimension(0, 0); - styledAttributes.recycle(); - return toolbarHeight; - } - - public static int getNavigationBarHeight(Activity activity) { - Resources resources = activity.getResources(); - int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android"); - if (resourceId > 0) { - return resources.getDimensionPixelSize(resourceId); - } - return 0; - } - - public static void measureView(View view) { - ViewGroup.LayoutParams p = view.getLayoutParams(); - if (p == null) { - p = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); - } - - int childWidthSpec = ViewGroup.getChildMeasureSpec(0, 0, p.width); - int lpHeight = p.height; - int childHeightSpec; - if (lpHeight > 0) { - childHeightSpec = MeasureSpec.makeMeasureSpec(lpHeight, MeasureSpec.EXACTLY); - } else { - childHeightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED); - } - view.measure(childWidthSpec, childHeightSpec); - } - - public static int getViewWidth(View view) { - measureView(view); - return view.getMeasuredWidth(); - } - - public static int getViewHeight(View view) { - measureView(view); - return view.getMeasuredHeight(); - } - - public static Activity getActivity(View view) { - Context context = view.getContext(); - while (context instanceof ContextWrapper) { - if (context instanceof Activity) { - return (Activity) context; - } - context = ((ContextWrapper) context).getBaseContext(); - } - throw new IllegalStateException("View " + view + " is not attached to an Activity"); - } - - public static void showToast(Context context, String content) { - Toast.makeText(context, content, Toast.LENGTH_SHORT).show(); - } - - public static void showToast(Context context, int res) { - Toast.makeText(context, res, Toast.LENGTH_SHORT).show(); - } -} From aa875a922567c51832b513b8d8bf29c1e8e54b02 Mon Sep 17 00:00:00 2001 From: h4de5ing <1229075001@qq.com> Date: Wed, 9 Aug 2017 12:12:19 +0800 Subject: [PATCH 5/6] update README.md --- README.md | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index c6c3cd8..5516916 100644 --- a/README.md +++ b/README.md @@ -2,13 +2,17 @@ ```gradle compile 'com.code19.library:library:0.1.4' ``` + +# notes +[0.1.4 removed](https://github.com/h4de5ing/AndroidCommon/commit/f4cb414ce8a7732fb152c510833f782b0cf0fd6d "0.1.4 we removed") ``ToastUtils``,``ViewUtils.java``,``SpannableStringUtils.java``,if you used then,you can use 0.1.2. + # Common Utils -- Collection Chop Issues -- Show Me The Best Code Pull request +- Collection Chop [Issues](https://github.com/h4de5ing/AndroidCommon/issues) +- Show Me The Best Code [Pull request](https://github.com/h4de5ing/AndroidCommon/pulls) ``` Demo: -AppUtils.getAppName(MainActivity.this,com.code19.androidcommon); +AppUtils.getAppName(MainActivity.this,"com.code19.androidcommon"); ``` ## [中文文档](README-cn.md) ## library Module: @@ -42,7 +46,6 @@ AppUtils.getAppName(MainActivity.this,com.code19.androidcommon); * cleanCache * cleanDatabases * cleanSharedPreference - - CipherUtils.java * md5(String input) @@ -81,7 +84,7 @@ AppUtils.getAppName(MainActivity.this,com.code19.androidcommon); * getScreenRealSize * getStatusBarH * getNavigationBarrH - + - DeviceUtils.java * getAndroidID * getIMEI @@ -165,7 +168,7 @@ AppUtils.getAppName(MainActivity.this,com.code19.androidcommon); * collection2Json * object2Json * string2JSONObject - + - L.java * init //Init the Log set Debug and Tag * v VERBOSE @@ -176,7 +179,7 @@ AppUtils.getAppName(MainActivity.this,com.code19.androidcommon); * a ASSERT * json * xml - + - NetUtils.java * getNetworkType * getNetworkTypeName @@ -261,17 +264,17 @@ AppUtils.getAppName(MainActivity.this,com.code19.androidcommon); License ---- - Copyright (C) 2016 android@19code.com - - Licensed 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 - + Copyright (C) 2016 moxi1992@gmail.com + + Licensed 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 KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + + 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 KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. From abbc53dc3d6bae05589c2696e5c30838e481cb14 Mon Sep 17 00:00:00 2001 From: h4de5ing <1229075001@qq.com> Date: Thu, 24 Aug 2017 11:44:01 +0800 Subject: [PATCH 6/6] fix long log #issues/4 --- .../src/main/java/com/code19/library/L.java | 46 ++++++++----------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/library/src/main/java/com/code19/library/L.java b/library/src/main/java/com/code19/library/L.java index 5038caa..58f01b7 100644 --- a/library/src/main/java/com/code19/library/L.java +++ b/library/src/main/java/com/code19/library/L.java @@ -33,7 +33,6 @@ import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; -import static android.util.Log.getStackTraceString; /** * Created by Gh0st on 2016/6/7 007. @@ -97,7 +96,7 @@ public static void e(String msg) { } public static void e(String tag, String msg, Throwable tr) { - log(ERROR, tag, msg + '\n' + getStackTraceString(tr)); + log(ERROR, tag, msg + '\n' + Log.getStackTraceString(tr)); } public static void a(String msg) { @@ -155,49 +154,44 @@ private static void printDefault(int type, String tag, String msg) { if (TextUtils.isEmpty(tag)) { tag = TAG; } - int index = 0; + printLine(tag, true); int maxLength = 4000; - int countOfSub = msg.length() / maxLength; - - if (countOfSub > 0) { // The log is so long - for (int i = 0; i < countOfSub; i++) { - String sub = msg.substring(index, index + maxLength); - printSub(type, tag, sub); - index += maxLength; + int countOfSub = msg.length(); + if (countOfSub > maxLength) { + for (int i = 0; i < countOfSub; i += maxLength) { + if (i + maxLength < countOfSub) { + printSub(type, tag, msg.substring(i, i + maxLength)); + } else { + printSub(type, tag, msg.substring(i, countOfSub)); + } } - //printSub(type, msg.substring(index, msg.length())); } else { printSub(type, tag, msg); } - + printLine(tag, false); } - private static void printSub(int type, String tag, String sub) { - if (tag == null) { - tag = TAG; - } - printLine(tag, true); + private static void printSub(int type, String tag, String msg) { switch (type) { case VERBOSE: - Log.v(tag, sub); + Log.v(tag, msg); break; case DEBUG: - Log.d(tag, sub); + Log.d(tag, msg); break; case INFO: - Log.i(tag, sub); + Log.i(tag, msg); break; case WARN: - Log.w(tag, sub); + Log.w(tag, msg); break; case ERROR: - Log.e(tag, sub); + Log.e(tag, msg); break; case ASSERT: - Log.wtf(tag, sub); + Log.wtf(tag, msg); break; } - printLine(tag, false); } private static void printJson(String tag, String json, String headString) { @@ -228,7 +222,7 @@ private static void printJson(String tag, String json, String headString) { message = headString + LINE_SEPARATOR + message; String[] lines = message.split(LINE_SEPARATOR); for (String line : lines) { - Log.d(tag, "|" + line); + printSub(DEBUG, tag, "|" + line); } printLine(tag, false); } @@ -258,7 +252,7 @@ private static void printXml(String tag, String xml, String headString) { String[] lines = xml.split(LINE_SEPARATOR); for (String line : lines) { if (!TextUtils.isEmpty(line)) { - Log.d(tag, "|" + line); + printSub(DEBUG, tag, "|" + line); } } printLine(tag, false);