diff --git a/README-cn.md b/README-cn.md index 73437c1..5926baf 100644 --- a/README-cn.md +++ b/README-cn.md @@ -1,6 +1,6 @@ # gradle使用方式 ```gradle -compile 'com.code19.library:library:0.1.2' +compile 'com.code19.library:library:0.1.4' ``` # 常用工具类 - 常用代码片段收集 Issues @@ -31,8 +31,8 @@ AppUtils.getAppName(MainActivity.this,com.code19.androidcommon); * getAppPermissions 获取应用的所有权限 * hasPermission 是否有权限 * isInstalled 应用是否安装 - * installApk 安装应用 - * uninstallApk 卸载应用 + * ~~installApk 安装应用~~ + * ~~uninstallApk 卸载应用~~ * isSystemApp 是否是系统应用 * isServiceRunning 服务是否在运行 * stopRunningService 停止服务 @@ -204,7 +204,9 @@ AppUtils.getAppName(MainActivity.this,com.code19.androidcommon); * getWifiScanResults 获取wifi列表 * getScanResultsByBSSID 过滤扫描结果 * getWifiConnectionInfo 获取wifi连接信息 - + +- RadixUtils 进制工具类 + * - SPUtils.java SharedPreferences工具 * setSP 存储SharedPreferences值 * getSp 获取SharedPreferences值 @@ -228,7 +230,6 @@ AppUtils.getAppName(MainActivity.this,com.code19.androidcommon); - SystemUtils.java 系统工具 * sendSMS 调用系统发送短信 * forwardToDial 跳转到拨号 - * callPhone 直接呼叫号码 * sendMail 发邮件 * openWeb 打开浏览器 * openContacts 打开联系人 @@ -324,27 +325,7 @@ AppUtils.getAppName(MainActivity.this,com.code19.androidcommon); * isNumeric 是否数值型 * testRegex 是否匹配正则 * checkPostcode 匹配中国邮政编码 - -- ViewUtils.java View工具 - * removeSelfFromParent - * requestLayoutParent - * isTouchInView - * bigImage - * setTVUnderLine 给TextView设置下划线 - * showPopupWindow - * dismissPopup - * captureView 截图 - * createViewBitmap 截图 - * convertViewToBitmap 截图 - * getActivityBitmap 获取Activity的截图 - * getStatusBarHeight 获取状态栏高度 - * getToolbarHeight 获取工具栏高度 - * getNavigationBarHeight 获取导航栏高度 - * measureView 测量view - * getViewWidth 获取view的宽度 - * getViewHeight 获取view的高度 - * getActivity 获取view的上下文 - + ```shell diff --git a/README.md b/README.md index 65f1c84..5516916 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,18 @@ # How to use In Android Studio ```gradle -compile 'com.code19.library:library:0.1.2' +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: @@ -31,8 +35,8 @@ AppUtils.getAppName(MainActivity.this,com.code19.androidcommon); * getAppPermissions * hasPermission * isInstalled - * installApk - * uninstallApk + * ~~installApk~~ + * ~~uninstallApk~~ * isSystemApp * isServiceRunning * stopRunningService @@ -42,10 +46,6 @@ AppUtils.getAppName(MainActivity.this,com.code19.androidcommon); * cleanCache * cleanDatabases * cleanSharedPreference - -- CacheUtils.java - * setCache - * getCache - CipherUtils.java * md5(String input) @@ -84,7 +84,7 @@ AppUtils.getAppName(MainActivity.this,com.code19.androidcommon); * getScreenRealSize * getStatusBarH * getNavigationBarrH - + - DeviceUtils.java * getAndroidID * getIMEI @@ -168,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 @@ -179,7 +179,7 @@ AppUtils.getAppName(MainActivity.this,com.code19.androidcommon); * a ASSERT * json * xml - + - NetUtils.java * getNetworkType * getNetworkTypeName @@ -216,7 +216,6 @@ AppUtils.getAppName(MainActivity.this,com.code19.androidcommon); - SystemUtils.java * sendSMS * forwardToDial - * callPhone * sendMail * openWeb * openContacts @@ -261,41 +260,21 @@ AppUtils.getAppName(MainActivity.this,com.code19.androidcommon); * isNumeric * testRegex -- ViewUtils.java - * removeSelfFromParent - * requestLayoutParent - * isTouchInView - * bigImage - * setTVUnderLine - * showPopupWindow - * dismissPopup - * captureView - * createViewBitmap - * convertViewToBitmap - * getActivityBitmap - * getStatusBarHeight - * getToolbarHeight - * getNavigationBarHeight - * measureView - * getViewWidth - * getViewHeight - * getActivity - # Thanks to all the open source programmers 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. 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/build.gradle b/library/build.gradle index 1337085..5639ca7 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,11 +22,11 @@ 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+' - //compile 'com.android.support:design:24.2.1' + //compile 'com.google.code.gson:gson:2+' + compile 'com.google.code.gson:gson:2.2.4' } def siteUrl = 'https://github.com/h4de5ing/AndroidCommon' def gitUrl = 'https://github.com/h4de5ing/AndroidCommon.git' 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"> - - - diff --git a/library/src/main/java/com/code19/library/AppUtils.java b/library/src/main/java/com/code19/library/AppUtils.java index d37c48f..3dc38a2 100644 --- a/library/src/main/java/com/code19/library/AppUtils.java +++ b/library/src/main/java/com/code19/library/AppUtils.java @@ -8,7 +8,7 @@ * 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, + * 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. @@ -264,6 +264,7 @@ public static boolean isInstalled(Context context, String packageName) { return installed; } + @Deprecated public static boolean installApk(Context context, String filePath) { File file = new File(filePath); if (!file.exists() || !file.isFile() || file.length() <= 0) { @@ -276,6 +277,7 @@ public static boolean installApk(Context context, String filePath) { return true; } + @Deprecated public static boolean uninstallApk(Context context, String packageName) { if (TextUtils.isEmpty(packageName)) { return false; @@ -419,15 +421,18 @@ public static void runApp(Context context, String packagename) { context.startActivity(new Intent(context.getPackageManager().getLaunchIntentForPackage(packagename))); } + @Deprecated public static void cleanCache(Context context) { FileUtils.deleteFileByDirectory(context.getCacheDir()); } + @Deprecated public static void cleanDatabases(Context context) { String filepath = String.format(String.format(context.getFilesDir().getParent() + File.separator + "%s", "databases")); FileUtils.deleteFileByDirectory(new File(filepath)); } + @Deprecated public static void cleanSharedPreference(Context context) { String filepath = String.format(String.format(context.getFilesDir().getParent() + File.separator + "%s", "shared_prefs")); FileUtils.deleteFileByDirectory(new File(filepath)); diff --git a/library/src/main/java/com/code19/library/CipherUtils.java b/library/src/main/java/com/code19/library/CipherUtils.java index 204f760..81ac808 100644 --- a/library/src/main/java/com/code19/library/CipherUtils.java +++ b/library/src/main/java/com/code19/library/CipherUtils.java @@ -20,25 +20,11 @@ import java.io.File; import java.io.FileInputStream; -import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; -import java.io.OutputStream; import java.security.DigestInputStream; -import java.security.InvalidAlgorithmParameterException; -import java.security.InvalidKeyException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; -import java.security.SecureRandom; -import java.security.spec.InvalidKeySpecException; - -import javax.crypto.Cipher; -import javax.crypto.CipherInputStream; -import javax.crypto.NoSuchPaddingException; -import javax.crypto.SecretKey; -import javax.crypto.SecretKeyFactory; -import javax.crypto.spec.DESKeySpec; -import javax.crypto.spec.IvParameterSpec; /** * Create by h4de5ing 2016/5/7 007 diff --git a/library/src/main/java/com/code19/library/FileUtils.java b/library/src/main/java/com/code19/library/FileUtils.java index 338366e..f931483 100644 --- a/library/src/main/java/com/code19/library/FileUtils.java +++ b/library/src/main/java/com/code19/library/FileUtils.java @@ -24,8 +24,6 @@ import android.text.TextUtils; import android.text.format.Formatter; -import com.code19.library.service.DownloadService; - import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.Closeable; @@ -355,11 +353,6 @@ public static void downloadFile(Context context, String fileurl) { downloadManager.enqueue(request); } - public static void upgradeApp(Context context, String fileurl) { - Intent intent = new Intent(context, DownloadService.class); - intent.putExtra("fileurl", fileurl); - context.startService(intent); - } public static boolean isSDCardAvailable() { return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()); @@ -375,6 +368,7 @@ public static String getAppExternalPath(Context context) { return context.getObbDir().getAbsolutePath(); } + @Deprecated public static String getExtraPath(String folder) { String storagePath = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + folder; File file = new File(storagePath); diff --git a/library/src/main/java/com/code19/library/L.java b/library/src/main/java/com/code19/library/L.java index b507678..58f01b7 100644 --- a/library/src/main/java/com/code19/library/L.java +++ b/library/src/main/java/com/code19/library/L.java @@ -33,6 +33,7 @@ import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; + /** * Created by Gh0st on 2016/6/7 007. * https://github.com/ZhaoKaiQiang/KLog @@ -94,8 +95,8 @@ public static void e(String msg) { log(ERROR, null, msg); } - public static void e(String tag, String msg) { - log(ERROR, tag, msg); + public static void e(String tag, String msg, Throwable tr) { + log(ERROR, tag, msg + '\n' + Log.getStackTraceString(tr)); } public static void a(String msg) { @@ -153,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) { @@ -226,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); } @@ -256,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); 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(); + } +} diff --git a/library/src/main/java/com/code19/library/SpannableStringUtils.java b/library/src/main/java/com/code19/library/SpannableStringUtils.java deleted file mode 100644 index fe2d197..0000000 --- a/library/src/main/java/com/code19/library/SpannableStringUtils.java +++ /dev/null @@ -1,383 +0,0 @@ -package com.code19.library; - -import android.content.Context; -import android.graphics.Bitmap; -import android.graphics.BlurMaskFilter; -import android.graphics.Typeface; -import android.graphics.drawable.Drawable; -import android.net.Uri; -import android.support.annotation.ColorInt; -import android.support.annotation.DrawableRes; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.text.Layout.Alignment; -import android.text.SpannableStringBuilder; -import android.text.Spanned; -import android.text.style.AlignmentSpan; -import android.text.style.BackgroundColorSpan; -import android.text.style.BulletSpan; -import android.text.style.ClickableSpan; -import android.text.style.ForegroundColorSpan; -import android.text.style.ImageSpan; -import android.text.style.LeadingMarginSpan; -import android.text.style.MaskFilterSpan; -import android.text.style.QuoteSpan; -import android.text.style.RelativeSizeSpan; -import android.text.style.ScaleXSpan; -import android.text.style.StrikethroughSpan; -import android.text.style.StyleSpan; -import android.text.style.SubscriptSpan; -import android.text.style.SuperscriptSpan; -import android.text.style.TypefaceSpan; -import android.text.style.URLSpan; -import android.text.style.UnderlineSpan; - -import static android.graphics.BlurMaskFilter.Blur; - -/** - *
- *     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(); - } -} diff --git a/library/src/main/java/com/code19/library/service/DownloadService.java b/library/src/main/java/com/code19/library/service/DownloadService.java deleted file mode 100644 index 33e9d56..0000000 --- a/library/src/main/java/com/code19/library/service/DownloadService.java +++ /dev/null @@ -1,82 +0,0 @@ -package com.code19.library.service; - -import android.app.DownloadManager; -import android.app.Service; -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.content.IntentFilter; -import android.database.Cursor; -import android.net.Uri; -import android.os.IBinder; - -import com.code19.library.AppUtils; -import com.code19.library.L; - -public class DownloadService extends Service { - - private long mTaskId; - private DownloadManager mDownloadManager; - private String filePath; - - public DownloadService() { - } - - @Override - public void onCreate() { - super.onCreate(); - } - - @Override - public int onStartCommand(Intent intent, int flags, int startId) { - L.w("onStartCommand:" + intent.getStringExtra("fileurl")); - String fileurl = intent.getStringExtra("fileurl"); - downloadFile(fileurl); - return super.onStartCommand(intent, flags, startId); - } - - @Override - public IBinder onBind(Intent intent) { - return null; - } - - private void downloadFile(String fileurl) { - filePath = "/sdcard/Download/" + fileurl.substring(fileurl.lastIndexOf("/") + 1); - DownloadManager.Request request = new DownloadManager.Request(Uri.parse(fileurl)); - request.setDestinationInExternalPublicDir("/Download/", fileurl.substring(fileurl.lastIndexOf("/") + 1)); - mDownloadManager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE); - mTaskId = mDownloadManager.enqueue(request); - registerReceiver(mReceiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); - } - - private BroadcastReceiver mReceiver = new BroadcastReceiver() { - @Override - public void onReceive(Context context, Intent intent) { - checkDownloadStatus(); - } - }; - - private void checkDownloadStatus() { - DownloadManager.Query query = new DownloadManager.Query(); - query.setFilterById(mTaskId); - Cursor c = mDownloadManager.query(query); - if (c.moveToFirst()) { - int status = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_STATUS)); - switch (status) { - /* case DownloadManager.STATUS_PAUSED: - break; - case DownloadManager.STATUS_FAILED: - break; - case DownloadManager.STATUS_PENDING: - break; - case DownloadManager.STATUS_RUNNING: - break;*/ - case DownloadManager.STATUS_SUCCESSFUL: - AppUtils.installApk(this, filePath); - break; - } - } - - - } -}