/*
* Copyright 2014 - 2016 Henning Dodenhof
*
* 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.angent.defaultavatardemo.widget;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ColorFilter;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.RectF;
import android.graphics.Shader;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.support.annotation.ColorInt;
import android.support.annotation.ColorRes;
import android.support.annotation.DrawableRes;
import android.util.AttributeSet;
import android.widget.ImageView;
import com.angent.defaultavatardemo.R;
public class CircleImageView extends ImageView {
private static final ScaleType SCALE_TYPE = ScaleType.CENTER_CROP;
private static final Bitmap.Config BITMAP_CONFIG = Bitmap.Config.ARGB_8888;
private static final int COLORDRAWABLE_DIMENSION = 2;
private static final int DEFAULT_BORDER_WIDTH = 0;
private static final int DEFAULT_BORDER_COLOR = Color.BLACK;
private static final int DEFAULT_FILL_COLOR = Color.TRANSPARENT;
private static final boolean DEFAULT_BORDER_OVERLAY = false;
private final RectF mDrawableRect = new RectF();
private final RectF mBorderRect = new RectF();
private final Matrix mShaderMatrix = new Matrix();
private final Paint mBitmapPaint = new Paint();
private final Paint mBorderPaint = new Paint();
private final Paint mFillPaint = new Paint();
private int mBorderColor = DEFAULT_BORDER_COLOR;
private int mBorderWidth = DEFAULT_BORDER_WIDTH;
private int mFillColor = DEFAULT_FILL_COLOR;
private Bitmap mBitmap;
private BitmapShader mBitmapShader;
private int mBitmapWidth;
private int mBitmapHeight;
private float mDrawableRadius;
private float mBorderRadius;
private ColorFilter mColorFilter;
private boolean mReady;
private boolean mSetupPending;
private boolean mBorderOverlay;
private boolean mDisableCircularTransformation;
public CircleImageView(Context context) {
this(context, null);
}
public CircleImageView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public CircleImageView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CircleImageView, defStyle, 0);
mBorderWidth = a.getDimensionPixelSize(R.styleable.CircleImageView_civ_border_width, DEFAULT_BORDER_WIDTH);
mBorderColor = a.getColor(R.styleable.CircleImageView_civ_border_color, DEFAULT_BORDER_COLOR);
mBorderOverlay = a.getBoolean(R.styleable.CircleImageView_civ_border_overlay, DEFAULT_BORDER_OVERLAY);
mFillColor = a.getColor(R.styleable.CircleImageView_civ_fill_color, DEFAULT_FILL_COLOR);
a.recycle();
init();
}
private void init() {
super.setScaleType(SCALE_TYPE);
mReady = true;
if (mSetupPending) {
setup();
mSetupPending = false;
}
}
@Override
public ScaleType getScaleType() {
return SCALE_TYPE;
}
@Override
public void setScaleType(ScaleType scaleType) {
if (scaleType != SCALE_TYPE) {
throw new IllegalArgumentException(String.format("ScaleType %s not supported.", scaleType));
}
}
@Override
public void setAdjustViewBounds(boolean adjustViewBounds) {
if (adjustViewBounds) {
throw new IllegalArgumentException("adjustViewBounds not supported.");
}
}
@Override
protected void onDraw(Canvas canvas) {
if (mDisableCircularTransformation) {
super.onDraw(canvas);
return;
}
if (mBitmap == null) {
return;
}
if (mFillColor != Color.TRANSPARENT) {
canvas.drawCircle(mDrawableRect.centerX(), mDrawableRect.centerY(), mDrawableRadius, mFillPaint);
}
canvas.drawCircle(mDrawableRect.centerX(), mDrawableRect.centerY(), mDrawableRadius, mBitmapPaint);
if (mBorderWidth > 0) {
canvas.drawCircle(mBorderRect.centerX(), mBorderRect.centerY(), mBorderRadius, mBorderPaint);
}
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
setup();
}
@Override
public void setPadding(int left, int top, int right, int bottom) {
super.setPadding(left, top, right, bottom);
setup();
}
@Override
public void setPaddingRelative(int start, int top, int end, int bottom) {
super.setPaddingRelative(start, top, end, bottom);
setup();
}
public int getBorderColor() {
return mBorderColor;
}
public void setBorderColor(@ColorInt int borderColor) {
if (borderColor == mBorderColor) {
return;
}
mBorderColor = borderColor;
mBorderPaint.setColor(mBorderColor);
invalidate();
}
/**
* @deprecated Use {@link #setBorderColor(int)} instead
*/
@Deprecated
public void setBorderColorResource(@ColorRes int borderColorRes) {
setBorderColor(getContext().getResources().getColor(borderColorRes));
}
/**
* Return the color drawn behind the circle-shaped drawable.
*
* @return The color drawn behind the drawable
* @deprecated Fill color support is going to be removed in the future
*/
@Deprecated
public int getFillColor() {
return mFillColor;
}
/**
* Set a color to be drawn behind the circle-shaped drawable. Note that
* this has no effect if the drawable is opaque or no drawable is set.
*
* @param fillColor The color to be drawn behind the drawable
* @deprecated Fill color support is going to be removed in the future
*/
@Deprecated
public void setFillColor(@ColorInt int fillColor) {
if (fillColor == mFillColor) {
return;
}
mFillColor = fillColor;
mFillPaint.setColor(fillColor);
invalidate();
}
/**
* Set a color to be drawn behind the circle-shaped drawable. Note that
* this has no effect if the drawable is opaque or no drawable is set.
*
* @param fillColorRes The color resource to be resolved to a color and
* drawn behind the drawable
* @deprecated Fill color support is going to be removed in the future
*/
@Deprecated
public void setFillColorResource(@ColorRes int fillColorRes) {
setFillColor(getContext().getResources().getColor(fillColorRes));
}
public int getBorderWidth() {
return mBorderWidth;
}
public void setBorderWidth(int borderWidth) {
if (borderWidth == mBorderWidth) {
return;
}
mBorderWidth = borderWidth;
setup();
}
public boolean isBorderOverlay() {
return mBorderOverlay;
}
public void setBorderOverlay(boolean borderOverlay) {
if (borderOverlay == mBorderOverlay) {
return;
}
mBorderOve
没有合适的资源?快使用搜索试试~ 我知道了~
Android默认头像那些事儿配套资源
共80个文件
xml:31个
png:12个
java:9个
需积分: 12 15 下载量 52 浏览量
2017-02-28
15:37:23
上传
评论
收藏 894KB ZIP 举报
温馨提示
http://blog.csdn.net/u013904672/article/details/58597964 文章配套资源
资源推荐
资源详情
资源评论
收起资源包目录
DefaultAvatarDemo.zip (80个子文件)
DefaultAvatarDemo
gradlew.bat 2KB
gradlew 5KB
gradle.properties 855B
.gradle
2.10
tasks
_app_compileDebugJavaWithJavac
localJarClasspathSnapshot
localJarClasspathSnapshot.bin 22KB
localJarClasspathSnapshot.lock 17B
localClassSetAnalysis
localClassSetAnalysis.lock 17B
localClassSetAnalysis.bin 85KB
taskArtifacts
fileHashes.bin 165KB
cache.properties.lock 17B
taskArtifacts.bin 138KB
fileSnapshots.bin 4.8MB
cache.properties 30B
outputFileStates.bin 20KB
app
proguard-rules.pro 667B
src
test
java
com
angent
defaultavatardemo
ExampleUnitTest.java 321B
androidTest
java
com
angent
defaultavatardemo
ApplicationTest.java 359B
main
res
mipmap-xxxhdpi
ic_launcher.png 10KB
drawable
mipmap-hdpi
ic_launcher.png 3KB
values
colors.xml 589B
strings.xml 80B
attrs.xml 361B
styles.xml 383B
dimens.xml 211B
mipmap-xxhdpi
ic_launcher.png 8KB
mipmap-mdpi
ic_launcher.png 2KB
mipmap-xhdpi
ic_launcher.png 5KB
random_color_three.png 3KB
default_pic.jpg 3KB
random_color_five.png 3KB
random_color_four.png 3KB
random_color_one.png 3KB
random_color_seven.png 3KB
random_color_two.png 3KB
random_color_six.png 3KB
layout
activity_list.xml 414B
activity_main.xml 2KB
item_user.xml 2KB
values-w820dp
dimens.xml 358B
java
com
angent
defaultavatardemo
ListActivity.java 1KB
bean
UserBean.java 744B
MainActivity.java 2KB
adapter
UserAdapter.java 3KB
widget
CircleImageView.java 13KB
utils
ColorUtils.java 3KB
MakeRandomPhoto.java 6KB
AndroidManifest.xml 1007B
app.iml 10KB
.gitignore 7B
build
.DS_Store 6KB
build.gradle 817B
libs
gradle
wrapper
gradle-wrapper.jar 52KB
gradle-wrapper.properties 231B
.idea
gradle.xml 739B
runConfigurations.xml 564B
misc.xml 4KB
.name 17B
copyright
profiles_settings.xml 74B
modules.xml 371B
encodings.xml 159B
compiler.xml 686B
workspace.xml 168KB
libraries
glide_3_7_0.xml 512B
okhttp3_integration_1_4_0.xml 667B
okio_1_6_0.xml 491B
support_v4_23_2_1.xml 905B
okhttp_3_2_0.xml 507B
appcompat_v7_23_2_1.xml 764B
hamcrest_core_1_3.xml 516B
junit_4_12.xml 467B
animated_vector_drawable_23_2_1.xml 651B
support_annotations_23_2_1.xml 519B
support_vector_drawable_23_2_1.xml 646B
inspectionProfiles
Project_Default.xml 784B
profiles_settings.xml 235B
.gitignore 97B
local.properties 438B
settings.gradle 15B
DefaultAvatarDemo.iml 948B
build
.DS_Store 6KB
build.gradle 498B
共 80 条
- 1
资源评论
冷不冷
- 粉丝: 58
- 资源: 13
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- OpenCv 使用fffffffff
- 正点原子开拓者FPGA多人表决器代码项目
- EOP-Last5Years.txt
- windows 32位、64位系统常见缺少的库
- 毕业设计基于springboot+vue实现的求职招聘类型网站源码+数据库(高分项目).zip
- 535springboot + vue 体质测试数据分析及可视化设计.zip(可运行源码+数据库文件+文档)
- python毕业设计-基于Django+OpenCV的二维码生成与识别系统源码.zip
- 基于springboot+vue实现的求职招聘类型网站源代码+数据库(优质毕设项目).zip
- iOS APP提审checklist
- 第十四届中北大学ACM程序设计竞赛.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功