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">
-
- * 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; - } - } - - - } -}