diff --git a/circleprogress/src/main/java/com/littlejie/circleprogress/utils/ViewUtils.java b/circleprogress/src/main/java/com/littlejie/circleprogress/utils/ViewUtils.java index 67ce51b5d22b51106b529da9b2d871651d40db28..56cd5ff463a932c1897375df9ac1e295c135d94e 100644 --- a/circleprogress/src/main/java/com/littlejie/circleprogress/utils/ViewUtils.java +++ b/circleprogress/src/main/java/com/littlejie/circleprogress/utils/ViewUtils.java @@ -3,9 +3,9 @@ * 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 an 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.
@@ -41,6 +41,9 @@ import java.util.Optional;
public class ViewUtils {
private static ViewUtils instance = null;
+ /** 构造方法
+ * @return ViewUtils
+ */
public static synchronized ViewUtils getInstance() {
if (instance == null) {
instance = new ViewUtils();
@@ -61,6 +64,12 @@ public class ViewUtils {
return vp * displayAttributes.scalDensity;
}
+ /** 获取自定义值
+ * @param attrSet
+ * @param key
+ * @param defValue
+ * @return String
+ */
public String getAttrStringValue(AttrSet attrSet, String key, String defValue) {
if (attrSet.getAttr(key).isPresent()) {
return attrSet.getAttr(key).get().getStringValue();
@@ -69,7 +78,13 @@ public class ViewUtils {
}
}
- public Integer getAttrIntValue(AttrSet attrSet, String key, Integer defValue) {
+ /** 获取自定义值
+ * @param attrSet
+ * @param key
+ * @param defValue
+ * @return Integer
+ */
+ public int getAttrIntValue(AttrSet attrSet, String key, int defValue) {
if (attrSet.getAttr(key).isPresent()) {
return attrSet.getAttr(key).get().getIntegerValue();
} else {
@@ -77,7 +92,13 @@ public class ViewUtils {
}
}
- public Boolean getAttrBoolValue(AttrSet attrSet, String key, Boolean defValue) {
+ /** 获取自定义值
+ * @param attrSet
+ * @param key
+ * @param defValue
+ * @return Boolean
+ */
+ public boolean getAttrBoolValue(AttrSet attrSet, String key, boolean defValue) {
if (attrSet.getAttr(key).isPresent()) {
return attrSet.getAttr(key).get().getBoolValue();
} else {
@@ -85,7 +106,13 @@ public class ViewUtils {
}
}
- public Float getFloatValue(AttrSet attrSet, String key, float defValue) {
+ /** 获取自定义值
+ * @param attrSet
+ * @param key
+ * @param defValue
+ * @return Float
+ */
+ public float getFloatValue(AttrSet attrSet, String key, float defValue) {
if (attrSet.getAttr(key).isPresent()) {
return attrSet.getAttr(key).get().getFloatValue();
} else {
@@ -93,7 +120,13 @@ public class ViewUtils {
}
}
- public Integer getDimensionValue(AttrSet attrSet, String key, int defValue) {
+ /** 获取自定义值
+ * @param attrSet
+ * @param key
+ * @param defValue
+ * @return Integer
+ */
+ public int getDimensionValue(AttrSet attrSet, String key, int defValue) {
if (attrSet.getAttr(key).isPresent()) {
return attrSet.getAttr(key).get().getDimensionValue();
} else {
@@ -101,6 +134,12 @@ public class ViewUtils {
}
}
+ /** 获取自定义值
+ * @param attrSet
+ * @param key
+ * @param defValue
+ * @return Element
+ */
public Element getAttrElementValue(AttrSet attrSet, String key, Element defValue) {
if (attrSet.getAttr(key).isPresent()) {
return attrSet.getAttr(key).get().getElement();
@@ -109,6 +148,12 @@ public class ViewUtils {
}
}
+ /** 获取自定义值
+ * @param attrSet
+ * @param key
+ * @param defValue
+ * @return Color
+ */
public Color getAttrColorValue(AttrSet attrSet, String key, Color defValue) {
if (attrSet.getAttr(key).isPresent()) {
return attrSet.getAttr(key).get().getColorValue();
@@ -117,9 +162,17 @@ public class ViewUtils {
}
}
- public PixelMap getPixelMapFromMedia(Context context, int mediaId) throws NotExistException, WrongTypeException, IOException {
+ /** 从资源文件获取bitmap
+ * @param context
+ * @param mediaId
+ * @return PixelMap
+ * @throws NotExistException
+ * @throws WrongTypeException
+ * @throws IOException
+ */
+ public PixelMap getPixelMapFromMedia(Context context, int mediaId) throws
+ NotExistException, WrongTypeException, IOException {
ImageSource.SourceOptions options = new ImageSource.SourceOptions();
-// options.formatHint = "image/jpg";
ImageSource.DecodingOptions decodingOptions = new ImageSource.DecodingOptions();
ResourceManager manager = context.getResourceManager();
String path = manager.getMediaPath(mediaId);
@@ -128,11 +181,20 @@ public class ViewUtils {
return source.createPixelmap(decodingOptions);
}
+ /** vp转px
+ * @param context
+ * @param dpValue
+ * @return float
+ */
protected static float dip2px(Context context, float dpValue) {
DisplayAttributes displayAttributes = getScreenPiex(context);
return dpValue * displayAttributes.scalDensity;
}
+ /** 获取屏幕密度
+ * @param context
+ * @return DisplayAttributes
+ */
public static DisplayAttributes getScreenPiex(Context context) {
// 获取屏幕密度
Optional