├── .gitignore
├── README.md
├── res
└── values
│ └── attrs.xml
└── src
└── com
└── nudorm
└── widget
└── RoundedImageView.java
/.gitignore:
--------------------------------------------------------------------------------
1 | # built application files
2 | *.apk
3 | *.ap_
4 |
5 | # files for the dex VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # generated files
12 | bin/
13 | gen/
14 |
15 | # Local configuration file (sdk path, etc)
16 | local.properties
17 |
18 | # Eclipse project files
19 | .classpath
20 | .project
21 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Android-RoundedImageView
2 | ========================
3 |
4 | Imageview with customisable rounded corners.
5 |
6 |
7 | Usage
8 | =====
9 |
10 | ```XML
11 |
15 |
16 |
24 |
25 | ```
26 |
27 | Developed By
28 | ============
29 |
30 | * Haydar Ciftci -
31 |
32 |
33 |
34 | License
35 | =======
36 |
37 | Copyright 2013 Haydar Ciftci
38 |
39 | Licensed under the Apache License, Version 2.0 (the "License");
40 | you may not use this file except in compliance with the License.
41 | You may obtain a copy of the License at
42 |
43 | http://www.apache.org/licenses/LICENSE-2.0
44 |
45 | Unless required by applicable law or agreed to in writing, software
46 | distributed under the License is distributed on an "AS IS" BASIS,
47 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
48 | See the License for the specific language governing permissions and
49 | limitations under the License.
50 |
51 |
52 | [](https://bitdeli.com/free "Bitdeli Badge")
53 |
54 |
--------------------------------------------------------------------------------
/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/src/com/nudorm/widget/RoundedImageView.java:
--------------------------------------------------------------------------------
1 | package com.nudorm.widget.RoundedImageView;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.graphics.*;
6 | import android.graphics.drawable.BitmapDrawable;
7 | import android.graphics.drawable.shapes.RoundRectShape;
8 | import android.util.AttributeSet;
9 | import android.view.View;
10 | import android.widget.ImageView;
11 |
12 | public class RoundedImageView extends ImageView {
13 | private float mTopLeft = 0;
14 | private float mTopRight = 0;
15 | private float mBottomRight = 0;
16 | private float mBottomLeft = 0;
17 | private RoundRectShape mRoundRectShape;
18 | private final Paint paint = new Paint();
19 | private Bitmap mBitmap;
20 | private BitmapShader mBitmapShader;
21 |
22 | public RoundedImageView(Context context) {
23 | super(context);
24 | setLayerType(View.LAYER_TYPE_HARDWARE, null);
25 | }
26 |
27 | public RoundedImageView(Context context, AttributeSet attrs) {
28 | super(context, attrs);
29 | setLayerType(View.LAYER_TYPE_HARDWARE, null);
30 | getAttributes(context, attrs);
31 | }
32 |
33 | public RoundedImageView(Context context, AttributeSet attrs, int defStyle) {
34 | super(context, attrs, defStyle);
35 | setLayerType(View.LAYER_TYPE_HARDWARE, null);
36 | getAttributes(context, attrs);
37 | }
38 |
39 | private void getAttributes(Context context, AttributeSet attrs) {
40 |
41 | final TypedArray typedArrayAttributes = getContext().obtainStyledAttributes(attrs, R.styleable.RoundedImageView);
42 |
43 | mTopLeft = typedArrayAttributes.getDimensionPixelSize(R.styleable.RoundedImageView_topLeftRadius, 0);
44 | mTopRight = typedArrayAttributes.getDimensionPixelSize(R.styleable.RoundedImageView_topRightRadius, 0);
45 | mBottomLeft = typedArrayAttributes.getDimensionPixelSize(R.styleable.RoundedImageView_bottomLeftRadius, 0);
46 | mBottomRight = typedArrayAttributes.getDimensionPixelSize(R.styleable.RoundedImageView_bottomRightRadius, 0);
47 |
48 | mRoundRectShape = new RoundRectShape(new float[]{
49 | mTopLeft, mTopLeft,
50 | mTopRight, mTopRight,
51 | mBottomRight, mBottomRight,
52 | mBottomLeft, mBottomLeft
53 | }, null, null);
54 |
55 | }
56 |
57 | @Override
58 | protected void onDraw(Canvas canvas) {
59 | if (((BitmapDrawable) getDrawable()) != null) {
60 | mBitmap = ((BitmapDrawable) getDrawable()).getBitmap();
61 | mBitmapShader = new BitmapShader(mBitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
62 | }
63 |
64 | paint.setAntiAlias(true);
65 | paint.setShader(mBitmapShader);
66 |
67 | mRoundRectShape.resize(getWidth(), getHeight());
68 | mRoundRectShape.draw(canvas, paint);
69 | }
70 |
71 | public float getTopLeftRadius() {
72 | return mTopLeft;
73 | }
74 |
75 | public void setTopLeftRadius(float radius) {
76 | this.mTopLeft = radius;
77 | }
78 |
79 | public float getTopRightRadius() {
80 | return mTopRight;
81 | }
82 |
83 | public void setTopRightRadius(float radius) {
84 | this.mTopRight = radius;
85 | }
86 |
87 | public float getBottomRightRadius() {
88 | return mBottomRight;
89 | }
90 |
91 | public void setBottomRightRadius(float radius) {
92 | this.mBottomRight = radius;
93 | }
94 |
95 | public float getBottomLeftRadius() {
96 | return mBottomLeft;
97 | }
98 |
99 | public void setBottomLeftRadius(float radius) {
100 | this.mBottomLeft = radius;
101 | }
102 | }
--------------------------------------------------------------------------------