diff --git a/README.md b/README.md index ea9d2b1..b559947 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ allprojects { ``` dependencies { - compile 'com.github.AllenCoder.SuperUtils:apputils:1.0.4' + compile 'com.github.AllenCoder.SuperUtils:apputils:1.0.5' } ``` @@ -53,7 +53,7 @@ dependencies { | SecretUtils | 3DES 加密/解密 | [SecretUtils][24] | | | ToastUtils | Toast工具类(需要Utils.init(context)) | [ToastUtils][25] | | | IOUtil | IOUtil (文件操作工具) | [IOUtil][26] | | - +| PaintUtil | PaintUtil (测量字体大小和字体高度) | [PaintUtil][27] | | ### 2.Android 数据库处理工具类 @@ -65,7 +65,7 @@ dependencies { ``` dependencies { - compile 'com.github.AllenCoder.SuperUtils:dbutils:1.0.4' + compile 'com.github.AllenCoder.SuperUtils:dbutils:1.0.5' } ``` @@ -79,7 +79,7 @@ dependencies { ``` dependencies { - compile 'com.github.AllenCoder.SuperUtils:mediautil:1.0.4' + compile 'com.github.AllenCoder.SuperUtils:mediautil:1.0.5' } ``` @@ -130,3 +130,4 @@ dependencies { [24]: https://github.com/AllenCoder/SuperUtils/blob/master/apputils/src/main/java/com/allen/apputils/SecretUtils.java [25]: https://github.com/AllenCoder/SuperUtils/blob/master/apputils/src/main/java/com/allen/apputils/ToastUtils.java [26]: https://github.com/AllenCoder/SuperUtils/blob/master/apputils/src/main/java/com/allen/apputils/IOUtil.java + [27]: https://github.com/AllenCoder/SuperUtils/blob/master/apputils/src/main/java/com/allen/apputils/PaintUtil.java diff --git a/app/build.gradle b/app/build.gradle index 7488eb9..cc5ca86 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -23,8 +23,8 @@ android { applicationId "com.allen.supperutils" minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion - versionCode 1 - versionName "1.0" + versionCode rootProject.ext.versionCode + versionName rootProject.ext.versionName } buildTypes { release { diff --git a/apputils/build.gradle b/apputils/build.gradle index f10bccc..1542da4 100644 --- a/apputils/build.gradle +++ b/apputils/build.gradle @@ -24,8 +24,8 @@ android { defaultConfig { minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion - versionCode 1 - versionName "1.0" + versionCode rootProject.ext.versionCode + versionName rootProject.ext.versionName } buildTypes { release { diff --git a/apputils/src/main/java/com/allen/apputils/PaintUtil.java b/apputils/src/main/java/com/allen/apputils/PaintUtil.java new file mode 100644 index 0000000..6f5cbbb --- /dev/null +++ b/apputils/src/main/java/com/allen/apputils/PaintUtil.java @@ -0,0 +1,69 @@ +/* + * Copyright 2017 [AllenCoderr] + * + * 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.allen.apputils; + +import android.graphics.Paint; +import android.graphics.Rect; + +/** + * 文 件 名: PaintUtil + * 创 建 人: Allen + * 创建日期: 2017/5/3 11:15 + * 修改时间: + * 修改备注: + */ + +public class PaintUtil { + private PaintUtil() { + } + + /** + * calculates the approximate width of a text, depending on a demo text + * avoid repeated calls (e.g. inside drawing methods) + * + * @param paint + * @param demoText + * @return + */ + public static int calcTextWidth(Paint paint, String demoText) { + return (int) paint.measureText(demoText); + } + /** + * calculates the approximate height of a text, depending on a demo text + * avoid repeated calls (e.g. inside drawing methods) + * + * @param paint + * @param demoText + * @return + */ + public static int calcTextHeight(Paint paint, String demoText) { + + Rect r = new Rect(); + paint.getTextBounds(demoText, 0, demoText.length(), r); + return r.height(); + } + + public static float getLineHeight(Paint paint) { + Paint.FontMetrics metrics = paint.getFontMetrics(); + return metrics.descent - metrics.ascent; + } + + public static float getLineSpacing(Paint paint) { + Paint.FontMetrics metrics = paint.getFontMetrics(); + return metrics.ascent - metrics.top + metrics.bottom; + } +} diff --git a/build.gradle b/build.gradle index 8ec0290..11f472f 100644 --- a/build.gradle +++ b/build.gradle @@ -45,6 +45,7 @@ ext { minSdkVersion = 14 targetSdkVersion = 25 - + versionCode =2 + versionName="1.0.5" supportVersion = "25.2.0" } diff --git a/dbutils/build.gradle b/dbutils/build.gradle index ea8b2d9..67e9aad 100644 --- a/dbutils/build.gradle +++ b/dbutils/build.gradle @@ -23,8 +23,8 @@ android { defaultConfig { minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion - versionCode 1 - versionName "1.0" + versionCode rootProject.ext.versionCode + versionName rootProject.ext.versionName testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" diff --git a/mediautil/build.gradle b/mediautil/build.gradle index a2f1a61..939241c 100644 --- a/mediautil/build.gradle +++ b/mediautil/build.gradle @@ -21,10 +21,10 @@ android { buildToolsVersion rootProject.ext.buildToolsVersion defaultConfig { - minSdkVersion 15 - targetSdkVersion 25 - versionCode 1 - versionName "1.0" + minSdkVersion rootProject.ext.minSdkVersion + targetSdkVersion rootProject.ext.targetSdkVersion + versionCode rootProject.ext.versionCode + versionName rootProject.ext.versionName } buildTypes {