├── .gitignore
├── .idea
├── compiler.xml
├── copyright
│ └── profiles_settings.xml
├── gradle.xml
├── misc.xml
├── modules.xml
├── runConfigurations.xml
└── vcs.xml
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── codekong
│ │ └── customview
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── codekong
│ │ │ └── customview
│ │ │ ├── activity
│ │ │ ├── MainActivity.java
│ │ │ └── SecondActivity.java
│ │ │ └── view
│ │ │ ├── AudioBarGraph.java
│ │ │ ├── FlowLayout.java
│ │ │ ├── PercentageGraph.java
│ │ │ ├── StickyScrollView.java
│ │ │ ├── TextFlashingTextView.java
│ │ │ └── TopBar.java
│ └── res
│ │ ├── layout
│ │ ├── activity_main.xml
│ │ └── activity_second.xml
│ │ ├── mipmap-hdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ └── ic_launcher.png
│ │ ├── values-w820dp
│ │ └── dimens.xml
│ │ └── values
│ │ ├── attrs.xml
│ │ ├── audiobargraph_attrs.xml
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── percentagegraph_attrs.xml
│ │ ├── strings.xml
│ │ ├── styles.xml
│ │ └── topbar_attrs.xml
│ └── test
│ └── java
│ └── com
│ └── codekong
│ └── customview
│ └── ExampleUnitTest.java
├── build.gradle
├── example.gif
├── example.png
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
17 |
18 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | 1.8
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## 自定义View合集
2 | ## 截图示例
3 | 
4 | 
5 | ## 1. FlowLayout 流式布局
6 |
7 | ### 使用方法:
8 | #### (1) 直接在布局文件中写入子元素
9 |
10 | ```
11 |
15 |
24 |
33 |
42 |
43 | ```
44 |
45 | #### (2) 通过addView()添加子元素
46 |
47 | ```
48 | FlowLayout fl = (FlowLayout) findViewById(R.id.id_fl);
49 | fl.addView(childView);
50 | ```
51 |
52 | ## 2. TextFlashingTextView 文字闪动变色TextView
53 | ### 使用方法:
54 | ```
55 |
62 | ```
63 |
64 | #### 可配置属性:
65 | TextView的所有属性
66 |
67 | ## 3. TopBar 高度可定制TopBar
68 | ### 使用方法:
69 |
70 | ```
71 |
79 |
80 | ```
81 | #### 可配置属性:
82 | ```
83 | title ---------- TopBar的标题
84 | titleTextSize ---------- TopBar的标题字体大小
85 | titleTextColor ---------- TopBar的标题字体颜色
86 | leftText ---------- TopBar的左边按钮标题
87 | leftTextSize ---------- TopBar的左边按钮标题字体大小
88 | leftTextColor ---------- TopBar的左边按钮标题字体颜色
89 | leftBackground ---------- TopBar的左边按钮标题的背景
90 | rightText ---------- TopBar的右边按钮标题
91 | rightTextSize ---------- TopBar的右边按钮标题字体大小
92 | rightTextColor ---------- TopBar的右边按钮标题字体颜色
93 | rightBackground ---------- TopBar的右边按钮标题的背景
94 | ```
95 | #### 代码设置:
96 | ```
97 | TopBar topBar = (TopBar) findViewById(R.id.id_topbar);
98 | //设置TopBar左右按钮的点击事件
99 | topBar.setTopbarClickListener(new TopBar.TopbarClickListener() {
100 | @Override
101 | public void leftClick(View v) {
102 | //左边按钮点击事件
103 | }
104 |
105 | @Override
106 | public void rightClick(View v) {
107 | //右边按钮点击事件
108 | }
109 | });
110 |
111 | //显示左边按钮
112 | topBar.setBtnVisibility(0, true);
113 | //隐藏右边按钮
114 | topBar.setBtnVisibility(1, false);
115 | ```
116 |
117 | ## 4. 百分比图示
118 | ### 使用方法:
119 | ```
120 |
130 | ```
131 | #### 可配置属性
132 | ```
133 | innerCircleColor ---------- 内圆的颜色
134 | outerCircleColor ---------- 外圆(弧线)的颜色
135 | outerCircleStrokeWidth ---------- 外圆(弧线)的宽度
136 | textColor ---------- 内部文字的颜色
137 | textSize ---------- 内部文字的字体大小
138 | textContent ---------- 内部文字的内容
139 | startAngle ---------- 外圆(弧线)的开始角度
140 | sweepAngle ---------- 外圆(弧线)的扫过的角度
141 | ```
142 |
143 | ## 5. 音频条形图
144 | ### 使用方法:
145 | ```
146 |
151 | ```
152 | #### 可配置属性
153 | ```
154 | rectCount ---------- 小矩形的数目
155 | rectOffset ---------- 每一个小矩形之间的偏移量
156 | topColor ---------- 一个小矩形渐变的顶部颜色
157 | bottomColor ---------- 一个小矩形渐变的底部部颜色
158 | delayTime ---------- 小矩形变化的延时时间(毫秒)
159 | ```
160 | #### 代码设置:
161 | ```
162 | final AudioBarGraph audioBarGraph = (AudioBarGraph) findViewById(R.id.id_abg);
163 | final float[] m = new float[20];
164 | new Thread(new Runnable() {
165 | @Override
166 | public void run() {
167 | while (true){
168 | for (int i = 0; i < m.length; i++) {
169 | m[i] = (float) (Math.random() * 100);
170 | }
171 | audioBarGraph.setCurrentHeight(m);
172 | try {
173 | Thread.sleep(300);
174 | } catch (InterruptedException e) {
175 | e.printStackTrace();
176 | }
177 | }
178 | }
179 | }).start();
180 | ```
181 | ## 6. 有黏性的ScrollView
182 | > 每个子View占一整个屏幕,当上滑或下滑的距离超过屏幕的1/3时,子View自动向上和向下滑动到
183 | 邻近的View
184 |
185 | ### 使用方法:
186 | ```
187 |
191 |
192 |
196 |
200 |
201 | ```
202 | > 也可以通过`addView向其中添加子元素`
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 24
5 | buildToolsVersion "25.0.0"
6 | defaultConfig {
7 | applicationId "com.codekong.customview"
8 | minSdkVersion 15
9 | targetSdkVersion 24
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
25 | exclude group: 'com.android.support', module: 'support-annotations'
26 | })
27 | compile 'com.android.support:appcompat-v7:24.2.1'
28 | testCompile 'junit:junit:4.12'
29 | }
30 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in G:\SDK\android-sdk-windows/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/codekong/customview/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.codekong.customview;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.codekong.customview", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codekong/customview/activity/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.codekong.customview.activity;
2 |
3 | import android.graphics.Color;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.view.View;
7 |
8 | import com.codekong.customview.R;
9 | import com.codekong.customview.view.AudioBarGraph;
10 | import com.codekong.customview.view.FlowLayout;
11 | import com.codekong.customview.view.TextFlashingTextView;
12 | import com.codekong.customview.view.TopBar;
13 |
14 | public class MainActivity extends AppCompatActivity {
15 |
16 | @Override
17 | protected void onCreate(Bundle savedInstanceState) {
18 | super.onCreate(savedInstanceState);
19 | setContentView(R.layout.activity_main);
20 |
21 | TextFlashingTextView textView = (TextFlashingTextView) findViewById(R.id.mytv);
22 | textView.setMiddleColor(Color.GREEN);
23 |
24 | FlowLayout fl = (FlowLayout) findViewById(R.id.id_fl);
25 | //fl.addView(childView);
26 |
27 | TopBar topBar = (TopBar) findViewById(R.id.id_topbar);
28 | //设置TopBar左右按钮的点击事件
29 | topBar.setTopbarClickListener(new TopBar.TopbarClickListener() {
30 | @Override
31 | public void leftClick(View v) {
32 | //左边按钮点击事件
33 | }
34 |
35 | @Override
36 | public void rightClick(View v) {
37 | //右边按钮点击事件
38 | }
39 | });
40 |
41 | //显示左边按钮
42 | topBar.setBtnVisibility(0, true);
43 | //隐藏右边按钮
44 | topBar.setBtnVisibility(1, false);
45 | final AudioBarGraph audioBarGraph = (AudioBarGraph) findViewById(R.id.id_abg);
46 | final float[] m = new float[20];
47 | new Thread(new Runnable() {
48 | @Override
49 | public void run() {
50 | while (true){
51 | for (int i = 0; i < m.length; i++) {
52 | m[i] = (float) (Math.random() * 100);
53 | }
54 | audioBarGraph.setCurrentHeight(m);
55 | try {
56 | Thread.sleep(300);
57 | } catch (InterruptedException e) {
58 | e.printStackTrace();
59 | }
60 | }
61 | }
62 | }).start();
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codekong/customview/activity/SecondActivity.java:
--------------------------------------------------------------------------------
1 | package com.codekong.customview.activity;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v7.app.AppCompatActivity;
6 |
7 | import com.codekong.customview.R;
8 |
9 | /**
10 | * Created by szh on 2017/1/25.
11 | */
12 |
13 | public class SecondActivity extends AppCompatActivity {
14 | @Override
15 | protected void onCreate(@Nullable Bundle savedInstanceState) {
16 | super.onCreate(savedInstanceState);
17 | setContentView(R.layout.activity_second);
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codekong/customview/view/AudioBarGraph.java:
--------------------------------------------------------------------------------
1 | package com.codekong.customview.view;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.graphics.Canvas;
6 | import android.graphics.Color;
7 | import android.graphics.LinearGradient;
8 | import android.graphics.Paint;
9 | import android.graphics.Shader;
10 | import android.util.AttributeSet;
11 | import android.view.View;
12 |
13 | import com.codekong.customview.R;
14 |
15 | /**
16 | * Created by szh on 2017/1/24.
17 | * 音频条形图
18 | */
19 |
20 | public class AudioBarGraph extends View {
21 | //渐变色顶部颜色
22 | private int mTopColor;
23 | //渐变色底部颜色
24 | private int mBottomColor;
25 | //View重绘延时时间
26 | private int mDelayTime;
27 |
28 | //小矩形的数目
29 | private int mRectCount;
30 | //每个小矩形的宽度
31 | private int mRectWidth;
32 | //每个小矩形的高度
33 | private int mRectHeight;
34 | //每个小矩形之间的偏移量
35 | private float mOffset;
36 | //绘制小矩形的画笔
37 | private Paint mPaint;
38 | //View的宽度
39 | private int mViewWidth;
40 | //产生渐变效果
41 | private LinearGradient mLinearGradient;
42 | //每个小矩形的当前高度
43 | private float[] mCurrentHeight;
44 |
45 | /**
46 | * 代码中直接new时调用
47 | *
48 | * @param context
49 | */
50 | public AudioBarGraph(Context context) {
51 | this(context, null);
52 | }
53 |
54 | /**
55 | * 在xml中使用自定义View并且没有自定义属性时调用
56 | * @param context
57 | * @param attrs
58 | */
59 | public AudioBarGraph(Context context, AttributeSet attrs) {
60 | this(context, attrs, 0);
61 | }
62 |
63 | /**
64 | * 在xml中使用自定义View并且使用自定义属性时调用
65 | * @param context
66 | * @param attrs
67 | * @param defStyleAttr
68 | */
69 | public AudioBarGraph(Context context, AttributeSet attrs, int defStyleAttr) {
70 | super(context, attrs, defStyleAttr);
71 | mOffset = 5;
72 | mRectCount = 10;
73 | mPaint = new Paint();
74 | mPaint.setAntiAlias(true);
75 | mPaint.setStyle(Paint.Style.FILL);
76 |
77 | TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.AudioBarGraph);
78 | mRectCount = ta.getInt(R.styleable.AudioBarGraph_rectCount, 10);
79 | mOffset = ta.getFloat(R.styleable.AudioBarGraph_rectOffset, 3);
80 | mDelayTime = ta.getInt(R.styleable.AudioBarGraph_delayTime, 300);
81 | mTopColor = ta.getColor(R.styleable.AudioBarGraph_topColor, Color.YELLOW);
82 | mBottomColor = ta.getColor(R.styleable.AudioBarGraph_bottomColor, Color.BLUE);
83 | ta.recycle();
84 | }
85 |
86 | @Override
87 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
88 | int widthMode = MeasureSpec.getMode(widthMeasureSpec);
89 | int heightMode = MeasureSpec.getMode(heightMeasureSpec);
90 | int widthSize = MeasureSpec.getSize(widthMeasureSpec);
91 | int heightSize = MeasureSpec.getSize(heightMeasureSpec);
92 |
93 | int width = 200;
94 | int height = 200;
95 |
96 | setMeasuredDimension(widthMode == MeasureSpec.EXACTLY ? widthSize : width,
97 | heightMode == MeasureSpec.EXACTLY ? heightSize : height);
98 | }
99 |
100 | @Override
101 | protected void onDraw(Canvas canvas) {
102 | super.onDraw(canvas);
103 | if (mCurrentHeight != null) {
104 | //使用者指定了每个小矩形当前的高度则使用
105 | for (int i = 0; i < mRectCount; i++) {
106 | int random = 0;
107 | canvas.drawRect((float) (mViewWidth * 0.4 / 2 + mRectWidth * i + mOffset), mCurrentHeight[i] + random,
108 | (float) (mViewWidth * 0.4 / 2 + mRectWidth * (i + 1)), mRectHeight, mPaint);
109 | }
110 | } else {
111 | //没有指定则使用随机数的高度
112 | for (int i = 0; i < mRectCount; i++) {
113 | int currentHeight = 0;
114 | canvas.drawRect((float) (mViewWidth * 0.4 / 2 + mRectWidth * i + mOffset), currentHeight,
115 | (float) (mViewWidth * 0.4 / 2 + mRectWidth * (i + 1)), mRectHeight, mPaint);
116 | }
117 | }
118 | //让View延时mDelayTime毫秒再重绘
119 | postInvalidateDelayed(mDelayTime);
120 | }
121 |
122 | @Override
123 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
124 | super.onSizeChanged(w, h, oldw, oldh);
125 | mViewWidth = getMeasuredWidth();
126 | mRectHeight = getMeasuredHeight();
127 | mRectWidth = (int) (mViewWidth * 0.6 / mRectCount);
128 | mLinearGradient = new LinearGradient(0, 0, mRectWidth, mRectHeight,
129 | mTopColor, mBottomColor, Shader.TileMode.CLAMP);
130 | mPaint.setShader(mLinearGradient);
131 | }
132 |
133 | /**
134 | * 公开方法设置小矩形高度
135 | * @param currentHeight
136 | */
137 | public void setCurrentHeight(float[] currentHeight){
138 | mCurrentHeight = currentHeight;
139 | }
140 | }
141 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codekong/customview/view/FlowLayout.java:
--------------------------------------------------------------------------------
1 | package com.codekong.customview.view;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 |
8 | import java.util.ArrayList;
9 | import java.util.List;
10 |
11 | /**
12 | * 自定义浮动布局
13 | */
14 | public class FlowLayout extends ViewGroup {
15 |
16 | public FlowLayout(Context context) {
17 | this(context, null);
18 | }
19 |
20 | public FlowLayout(Context context, AttributeSet attrs) {
21 | this(context, attrs, 0);
22 | }
23 |
24 | public FlowLayout(Context context, AttributeSet attrs, int defStyleAttr) {
25 | super(context, attrs, defStyleAttr);
26 | }
27 |
28 | @Override
29 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
30 | //布局为match_parent时处理
31 | int sizeWidth = MeasureSpec.getSize(widthMeasureSpec);
32 | int modeWidth = MeasureSpec.getMode(widthMeasureSpec);
33 | int sizeHeight = MeasureSpec.getSize(heightMeasureSpec);
34 | int modeHeight = MeasureSpec.getMode(heightMeasureSpec);
35 |
36 | //布局为wrap_content时处理
37 | int width = 0;
38 | int height = 0;
39 |
40 | //记录每一行的宽度和高度
41 | int lineWidth = 0;
42 | int lineHeight = 0;
43 | //得到内部元素的个数
44 | int cCount = getChildCount();
45 | for (int i = 0; i < cCount; i++) {
46 | View child = getChildAt(i);
47 | //测量子View的宽和高
48 | measureChild(child, widthMeasureSpec, heightMeasureSpec);
49 | //得到LayoutParams
50 | MarginLayoutParams lp = (MarginLayoutParams) child.getLayoutParams();
51 | //子View占据的宽度
52 | int childWidth = child.getMeasuredWidth() + lp.leftMargin + lp.rightMargin;
53 | //子View占据的高度
54 | int childHeight = child.getMeasuredHeight() + lp.topMargin + lp.bottomMargin;
55 |
56 | //换行
57 | if (lineWidth + childWidth > sizeWidth - getPaddingLeft() - getPaddingRight()){
58 | //对比得到最大的宽度
59 | width = Math.max(width, lineHeight);
60 | //重置lineWidth
61 | lineWidth = childWidth;
62 | //记录行高
63 | height += lineHeight;
64 |
65 | lineHeight = childHeight;
66 | }else {//未换行
67 | //叠加行宽
68 | lineWidth += childWidth;
69 | //得到当前行最大的高度
70 | lineHeight = Math.max(lineHeight, childHeight);
71 | }
72 |
73 | //最后一个控件
74 | if (i == cCount - 1){
75 | width = Math.max(lineHeight, width);
76 | height += lineHeight;
77 | }
78 | }
79 |
80 | setMeasuredDimension(
81 | modeWidth == MeasureSpec.EXACTLY ? sizeWidth : width + getPaddingLeft() + getPaddingRight(),
82 | modeHeight == MeasureSpec.EXACTLY ? sizeHeight : height + getPaddingTop() + getPaddingBottom());
83 | }
84 |
85 | //与当前ViewGroup对应的LayoutParams
86 | @Override
87 | public LayoutParams generateLayoutParams(AttributeSet attrs) {
88 | return new MarginLayoutParams(getContext(), attrs);
89 | }
90 |
91 | //存储所有的View(按行存储,每一个子元素为一行的View)
92 | private List> mAllViews = new ArrayList<>();
93 |
94 | //存储每行的高度
95 | private List mLineHeight = new ArrayList<>();
96 |
97 | @Override
98 | protected void onLayout(boolean b, int i, int i1, int i2, int i3) {
99 | mAllViews.clear();
100 | mLineHeight.clear();
101 |
102 | //当前ViewGroup的宽度
103 | int width = getWidth();
104 |
105 | List lineViews = new ArrayList<>();
106 |
107 | int lineWidth = 0;
108 | int lineHeight = 0;
109 |
110 | int cCount = getChildCount();
111 |
112 | for (int j = 0; j < cCount; j++) {
113 | View child = getChildAt(j);
114 | MarginLayoutParams lp = (MarginLayoutParams) child.getLayoutParams();
115 |
116 | int childWidth = child.getMeasuredWidth();
117 | int childHeight = child.getMeasuredHeight();
118 |
119 | //如果需要换行
120 | if (childWidth + lineWidth + lp.rightMargin + lp.leftMargin > width - getPaddingLeft() - getPaddingRight()){
121 | //记录lineHeight
122 | mLineHeight.add(lineHeight);
123 | //记录当前行的Views
124 | mAllViews.add(lineViews);
125 |
126 | //重置我们的行宽和行高
127 | lineWidth = 0;
128 | lineHeight = childHeight + lp.topMargin + lp.bottomMargin;
129 |
130 | //重置View集合
131 | lineViews = new ArrayList<>();
132 | }
133 |
134 | lineWidth += childWidth + lp.leftMargin + lp.rightMargin;
135 |
136 | lineHeight = Math.max(lineHeight, childHeight + lp.topMargin + lp.bottomMargin);
137 |
138 | lineViews.add(child);
139 | }
140 | //处理最后一行
141 | mLineHeight.add(lineHeight);
142 | mAllViews.add(lineViews);
143 |
144 | //设置子View的位置
145 |
146 | int left = getPaddingLeft();
147 | int top = getPaddingTop();
148 |
149 | //行数
150 | int lineNum = mAllViews.size();
151 | for (int j = 0; j < lineNum; j++) {
152 | //当前行所有View
153 | lineViews = mAllViews.get(j);
154 | lineHeight = mLineHeight.get(j);
155 |
156 | for (int k = 0; k < lineViews.size(); k++) {
157 | View child = lineViews.get(k);
158 | //判断child的状态
159 | if (child.getVisibility() == View.GONE){
160 | continue;
161 | }
162 |
163 | MarginLayoutParams lp = (MarginLayoutParams) child.getLayoutParams();
164 |
165 | //child的左,上,右,下
166 | int lc = left + lp.leftMargin;
167 | int tc = top + lp.topMargin;
168 | int rc = lc + child.getMeasuredWidth();
169 | int bc = tc + child.getMeasuredHeight();
170 |
171 | //为子View进行布局,参数依次为左,上,右,下
172 | child.layout(lc, tc, rc, bc);
173 |
174 | left += child.getMeasuredWidth() + lp.leftMargin + lp.rightMargin;
175 | }
176 | //布局下一行
177 | left = getPaddingLeft();
178 | top += lineHeight;
179 | }
180 | }
181 | }
182 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codekong/customview/view/PercentageGraph.java:
--------------------------------------------------------------------------------
1 | package com.codekong.customview.view;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.graphics.Canvas;
6 | import android.graphics.Color;
7 | import android.graphics.Paint;
8 | import android.graphics.RectF;
9 | import android.text.TextUtils;
10 | import android.util.AttributeSet;
11 | import android.view.View;
12 |
13 | import com.codekong.customview.R;
14 |
15 | /**
16 | * Created by szh on 2017/1/24.
17 | * 百分比图(比例图)
18 | */
19 |
20 | public class PercentageGraph extends View {
21 | //实心圆的画笔
22 | private Paint mCirclePaint;
23 | //外面圆弧的画笔
24 | private Paint mArcPaint;
25 | //内部文字的画笔
26 | private Paint mTextPaint;
27 |
28 | private int mCircleColor;
29 | private int mArcColor;
30 |
31 | private int mTextColor;
32 | private float mTextSize;
33 |
34 | //文字内容
35 | private String mTextContent = "HelloWorld";
36 |
37 | private int mCircleX;
38 | private int mCircleY;
39 | private float mRadius;
40 |
41 | private int mViewWidth;
42 | private int mViewHeight;
43 |
44 | private RectF mArcRectF;
45 | //开始的角度
46 | private float mStartAngle;
47 | //扫过的角度
48 | private float mSweepAngle;
49 | private float mArcPaintStrokeWidth;
50 |
51 | public PercentageGraph(Context context) {
52 | this(context, null);
53 | }
54 |
55 | public PercentageGraph(Context context, AttributeSet attrs) {
56 | this(context, attrs, 0);
57 | }
58 |
59 | public PercentageGraph(Context context, AttributeSet attrs, int defStyleAttr) {
60 | super(context, attrs, defStyleAttr);
61 | TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.PercentageGraph);
62 | mCircleColor = ta.getColor(R.styleable.PercentageGraph_innerCircleColor, Color.parseColor("#abcdef"));
63 | mArcColor = ta.getColor(R.styleable.PercentageGraph_outerCircleColor, Color.parseColor("#fedcba"));
64 | mArcPaintStrokeWidth = ta.getDimension(R.styleable.PercentageGraph_outerCircleStrokeWidth, 50);
65 | mStartAngle = ta.getFloat(R.styleable.PercentageGraph_startAngle, 0);
66 | mSweepAngle = ta.getFloat(R.styleable.PercentageGraph_sweepAngle, 270);
67 | mTextContent = ta.getString(R.styleable.PercentageGraph_textContent);
68 | mTextColor = ta.getColor(R.styleable.PercentageGraph_textColor, Color.parseColor("black"));
69 | mTextSize = ta.getDimension(R.styleable.PercentageGraph_textSize, 30);
70 |
71 | ta.recycle();
72 |
73 | mCirclePaint = new Paint();
74 | mCirclePaint.setColor(mCircleColor);
75 | mCirclePaint.setStyle(Paint.Style.FILL);
76 | mCirclePaint.setAntiAlias(true);
77 |
78 | mArcPaint = new Paint();
79 | mArcPaint.setColor(mArcColor);
80 | mArcPaint.setStyle(Paint.Style.STROKE);
81 | mArcPaint.setAntiAlias(true);
82 |
83 | mTextPaint = new Paint();
84 | mTextPaint.setColor(mTextColor);
85 | mTextPaint.setAntiAlias(true);
86 | mTextPaint.setTextSize(mTextSize);
87 | mTextPaint.setTextAlign(Paint.Align.CENTER);
88 | }
89 |
90 | @Override
91 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
92 | int widthMode = MeasureSpec.getMode(widthMeasureSpec);
93 | int heightMode = MeasureSpec.getMode(heightMeasureSpec);
94 | int widthSize = MeasureSpec.getSize(widthMeasureSpec);
95 | int heightSize = MeasureSpec.getSize(heightMeasureSpec);
96 |
97 | int width = 200;
98 | int height = 200;
99 |
100 | setMeasuredDimension(widthMode == MeasureSpec.EXACTLY ? widthSize : width,
101 | heightMode == MeasureSpec.EXACTLY ? heightSize : height);
102 | }
103 |
104 | @Override
105 | protected void onDraw(Canvas canvas) {
106 | super.onDraw(canvas);
107 | //画出内部的实心圆
108 | canvas.drawCircle(mCircleX, mCircleY, mRadius, mCirclePaint);
109 | //绘制外层环
110 | canvas.drawArc(mArcRectF, mStartAngle, mSweepAngle, false, mArcPaint);
111 | if (!TextUtils.isEmpty(mTextContent)){
112 | //绘制最中间的文字
113 | canvas.drawText(mTextContent, 0, mTextContent.length(),
114 | mCircleX, mCircleY, mTextPaint);
115 | }
116 | }
117 |
118 | @Override
119 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
120 | super.onSizeChanged(w, h, oldw, oldh);
121 | if (mViewWidth == 0) {
122 | mViewWidth = getMeasuredWidth();
123 | }
124 | if (mViewHeight == 0) {
125 | mViewHeight = getMeasuredHeight();
126 | }
127 | if (mViewWidth > 0 && mViewHeight > 0) {
128 | //获得圆心坐标
129 | mCircleX = getPaddingLeft() + mViewWidth / 2;
130 | mCircleY = getPaddingTop() + mViewHeight / 2;
131 | //半径为宽高的较小值除去内边距的0.4倍
132 | if (mViewHeight >= mViewWidth) {
133 | mRadius = (float) ((mViewWidth / 2 - getPaddingLeft()) * 0.5);
134 | } else {
135 | mRadius = (float) ((mViewHeight / 2 - getPaddingTop()) * 0.5);
136 | }
137 | }
138 |
139 | mArcRectF = new RectF((float) (mViewWidth * 0.1), (float) (mViewHeight * 0.1),
140 | (float) (mViewWidth * 0.9), (float) (mViewHeight * 0.9));
141 | mArcPaint.setStrokeWidth(mArcPaintStrokeWidth);
142 | }
143 | }
144 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codekong/customview/view/StickyScrollView.java:
--------------------------------------------------------------------------------
1 | package com.codekong.customview.view;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.util.AttributeSet;
6 | import android.util.DisplayMetrics;
7 | import android.view.MotionEvent;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 | import android.widget.Scroller;
11 |
12 | /**
13 | * Created by szh on 2017/1/25.
14 | * 有黏性的ScrollView
15 | */
16 |
17 | public class StickyScrollView extends ViewGroup {
18 | //屏幕高度
19 | private int mScreenHeight;
20 | //上一次滑动的y坐标
21 | private float mLastY;
22 | //开始的坐标
23 | private float mStartY;
24 | //结束的坐标
25 | private float mEndY;
26 | //滚动协助
27 | private Scroller mScroller;
28 |
29 | public StickyScrollView(Context context) {
30 | this(context, null);
31 | }
32 |
33 | public StickyScrollView(Context context, AttributeSet attrs) {
34 | this(context, attrs, 0);
35 | }
36 |
37 | public StickyScrollView(Context context, AttributeSet attrs, int defStyleAttr) {
38 | super(context, attrs, defStyleAttr);
39 | mScreenHeight = getScreenHeight((Activity) context);
40 | mScroller = new Scroller(context);
41 |
42 | }
43 |
44 | /**
45 | * 得到屏幕的高度
46 | * @param activity
47 | * @return
48 | */
49 | public int getScreenHeight(Activity activity) {
50 | DisplayMetrics dm = new DisplayMetrics();
51 | activity.getWindowManager().getDefaultDisplay().getMetrics(dm);
52 | return dm.heightPixels;
53 | }
54 |
55 | @Override
56 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
57 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
58 | int childCount = getChildCount();
59 | //通知子View测量自身
60 | for (int i = 0; i < childCount; i++) {
61 | View childView = getChildAt(i);
62 | measureChild(childView, widthMeasureSpec, heightMeasureSpec);
63 | }
64 | }
65 |
66 | @Override
67 | protected void onLayout(boolean changed, int l, int t, int r, int b) {
68 | int childCount = getChildCount();
69 | MarginLayoutParams mlp = (MarginLayoutParams) getLayoutParams();
70 | //每个子View占一个屏幕
71 | mlp.height = mScreenHeight * childCount;
72 | setLayoutParams(mlp);
73 |
74 | for (int i = 0; i < childCount; i++) {
75 | View childView = getChildAt(i);
76 | if (childView.getVisibility() != View.GONE){
77 | childView.layout(l, i * mScreenHeight, r, (i + 1) * mScreenHeight);
78 | }
79 | }
80 | }
81 |
82 | @Override
83 | public boolean onTouchEvent(MotionEvent event) {
84 | float y = event.getY();
85 | switch (event.getAction()){
86 | case MotionEvent.ACTION_DOWN:
87 | mLastY = y;
88 | mStartY = getScrollY();
89 | break;
90 | case MotionEvent.ACTION_MOVE:
91 | float dy;
92 | if (!mScroller.isFinished()){
93 | mScroller.abortAnimation();
94 | }
95 | dy = mLastY - y;
96 | if (getScrollY() < 0){
97 | dy = 0;
98 | }
99 | if (getScrollY() > getHeight() - mScreenHeight){
100 | dy = 0;
101 | }
102 | scrollBy(0, (int) dy);
103 | mLastY = y;
104 | break;
105 | case MotionEvent.ACTION_UP:
106 | mEndY = getScrollY();
107 | float dScrollY = mEndY - mStartY;
108 | if (dScrollY > 0){
109 | if (dScrollY < mScreenHeight / 3){
110 | mScroller.startScroll(0, getScrollY(), 0, (int) -dScrollY);
111 | }else{
112 | mScroller.startScroll(0, getScrollY(), 0, (int) (mScreenHeight - dScrollY));
113 | }
114 | }else{
115 | if (-dScrollY < mScreenHeight / 3){
116 | mScroller.startScroll(0, getScrollY(), 0, (int) -dScrollY);
117 | }else{
118 | mScroller.startScroll(0, getScrollY(), 0, (int) (-mScreenHeight - dScrollY));
119 | }
120 | }
121 | break;
122 | }
123 | postInvalidate();
124 | return true;
125 | }
126 |
127 | @Override
128 | public void computeScroll() {
129 | super.computeScroll();
130 | if (mScroller.computeScrollOffset()){
131 | scrollTo(0, mScroller.getCurrY());
132 | postInvalidate();
133 | }
134 | }
135 | }
136 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codekong/customview/view/TextFlashingTextView.java:
--------------------------------------------------------------------------------
1 | package com.codekong.customview.view;
2 |
3 | import android.content.Context;
4 | import android.graphics.Canvas;
5 | import android.graphics.LinearGradient;
6 | import android.graphics.Matrix;
7 | import android.graphics.Paint;
8 | import android.graphics.Shader;
9 | import android.util.AttributeSet;
10 | import android.widget.TextView;
11 |
12 | /**
13 | * Created by szh on 2017/1/17.
14 | */
15 |
16 | public class TextFlashingTextView extends TextView{
17 | private int mViewWidth;
18 | private LinearGradient mLinearGradient;
19 | private Matrix mGradientMatrix;
20 | private int mTranslate;
21 | private int middleColor = 0xffffff;
22 |
23 | public TextFlashingTextView(Context context) {
24 | this(context, null);
25 | }
26 |
27 | public TextFlashingTextView(Context context, AttributeSet attrs) {
28 | this(context, attrs, 0);
29 | }
30 |
31 | public TextFlashingTextView(Context context, AttributeSet attrs, int defStyleAttr) {
32 | super(context, attrs, defStyleAttr);
33 | }
34 |
35 | @Override
36 | protected void onDraw(Canvas canvas) {
37 | super.onDraw(canvas);
38 | if (mGradientMatrix != null){
39 | mTranslate += mViewWidth / 5;
40 | if (mTranslate > 2 * mViewWidth){
41 | mTranslate = -mViewWidth;
42 | }
43 | mGradientMatrix.setTranslate(mTranslate, 0);
44 | mLinearGradient.setLocalMatrix(mGradientMatrix);
45 | postInvalidateDelayed(100);
46 | }
47 | }
48 |
49 | @Override
50 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
51 | super.onSizeChanged(w, h, oldw, oldh);
52 |
53 | if (mViewWidth == 0){
54 | mViewWidth = getMeasuredWidth();
55 | if (mViewWidth > 0){
56 | Paint mPaint = getPaint();
57 | int currentTextColor = getCurrentTextColor();
58 | mLinearGradient = new LinearGradient(0, 0, mViewWidth, 0,
59 | new int[]{currentTextColor, middleColor, currentTextColor}, null,
60 | Shader.TileMode.CLAMP);
61 | mPaint.setShader(mLinearGradient);
62 | mGradientMatrix = new Matrix();
63 | }
64 | }
65 | }
66 |
67 | public void setMiddleColor(int middleColor){
68 | this.middleColor = middleColor;
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codekong/customview/view/TopBar.java:
--------------------------------------------------------------------------------
1 | package com.codekong.customview.view;
2 |
3 | import android.app.ActionBar;
4 | import android.content.Context;
5 | import android.content.res.TypedArray;
6 | import android.graphics.Color;
7 | import android.graphics.Matrix;
8 | import android.graphics.drawable.Drawable;
9 | import android.util.AttributeSet;
10 | import android.view.Gravity;
11 | import android.view.View;
12 | import android.view.ViewGroup;
13 | import android.widget.Button;
14 | import android.widget.LinearLayout;
15 | import android.widget.RelativeLayout;
16 | import android.widget.TextView;
17 | import android.widget.Toolbar;
18 |
19 | import com.codekong.customview.R;
20 |
21 | /**
22 | * Created by szh on 2017/1/17.
23 | */
24 |
25 |
26 | public class TopBar extends RelativeLayout {
27 | private TopbarClickListener mTopbarClickListener;
28 |
29 | private String mTitle;
30 | private float mTitleTextSize;
31 | private int mTitleTextColor;
32 | private String mLeftText;
33 | private float mLeftTextSize;
34 | private int mLeftTextColor;
35 | private Drawable mLeftBackground;
36 | private String mRightText;
37 | private float mRightTextSize;
38 | private int mRightTextColor;
39 | private Drawable mRightBackground;
40 |
41 | private Button mLeftButton;
42 | private Button mRightButton;
43 | private TextView mTitleView;
44 |
45 | private LayoutParams mLeftParams;
46 | private LayoutParams mRightParams;
47 | private LayoutParams mTitleParams;
48 |
49 | public TopBar(Context context) {
50 | this(context, null);
51 | }
52 |
53 | public TopBar(Context context, AttributeSet attrs) {
54 | this(context, attrs, 0);
55 | }
56 |
57 | public TopBar(Context context, AttributeSet attrs, int defStyleAttr) {
58 | super(context, attrs, defStyleAttr);
59 | TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.TopBar);
60 | mTitle = typedArray.getString(R.styleable.TopBar_title);
61 | mTitleTextSize = typedArray.getDimensionPixelSize(R.styleable.TopBar_titleTextSize, 15);
62 | mTitleTextColor = typedArray.getColor(R.styleable.TopBar_titleTextColor, Color.parseColor("#000000"));
63 |
64 | mLeftText = typedArray.getString(R.styleable.TopBar_leftText);
65 | mLeftTextSize = typedArray.getDimensionPixelSize(R.styleable.TopBar_leftTextSize, 15);
66 | mLeftTextColor = typedArray.getColor(R.styleable.TopBar_leftTextColor, Color.parseColor("#000000"));
67 | mLeftBackground = typedArray.getDrawable(R.styleable.TopBar_leftBackground);
68 |
69 | mRightText = typedArray.getString(R.styleable.TopBar_rightText);
70 | mRightTextSize = typedArray.getDimensionPixelSize(R.styleable.TopBar_rightTextSize, 15);
71 | mRightTextColor = typedArray.getColor(R.styleable.TopBar_rightTextColor, Color.parseColor("#000000"));
72 | mRightBackground = typedArray.getDrawable(R.styleable.TopBar_rightBackground);
73 |
74 | typedArray.recycle();
75 |
76 | mLeftButton = new Button(context);
77 | mRightButton = new Button(context);
78 | mTitleView = new TextView(context);
79 |
80 | mLeftButton.setText(mLeftText);
81 | mLeftButton.setTextSize(mLeftTextSize);
82 | mLeftButton.setTextColor(mLeftTextColor);
83 | mLeftButton.setBackground(mLeftBackground);
84 |
85 |
86 | mRightButton.setText(mRightText);
87 | mRightButton.setTextSize(mRightTextSize);
88 | mRightButton.setTextColor(mRightTextColor);
89 | mRightButton.setBackground(mRightBackground);
90 |
91 | mTitleView.setText(mTitle);
92 | mTitleView.setTextSize(mTitleTextSize);
93 | mTitleView.setTextColor(mTitleTextColor);
94 | mTitleView.setGravity(Gravity.CENTER);
95 |
96 | mLeftParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
97 | mLeftParams.addRule(ALIGN_PARENT_LEFT, TRUE);
98 | addView(mLeftButton, mLeftParams);
99 |
100 | mRightParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
101 | mRightParams.addRule(ALIGN_PARENT_RIGHT, TRUE);
102 | addView(mRightButton, mRightParams);
103 |
104 | mTitleParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
105 | mTitleParams.addRule(CENTER_IN_PARENT, TRUE);
106 | addView(mTitleView, mTitleParams);
107 |
108 | mLeftButton.setOnClickListener(new OnClickListener() {
109 | @Override
110 | public void onClick(View v) {
111 | if (mTopbarClickListener != null){
112 | mTopbarClickListener.leftClick(v);
113 | }
114 | }
115 | });
116 |
117 | mRightButton.setOnClickListener(new OnClickListener() {
118 | @Override
119 | public void onClick(View v) {
120 | if (mTopbarClickListener != null){
121 | mTopbarClickListener.rightClick(v);
122 | }
123 | }
124 | });
125 | }
126 |
127 | public interface TopbarClickListener{
128 | void leftClick(View v);
129 | void rightClick(View v);
130 | }
131 |
132 | public void setTopbarClickListener(TopbarClickListener topbarClickListener){
133 | this.mTopbarClickListener = topbarClickListener;
134 | }
135 |
136 | public void setBtnVisibility(int id, boolean flag){
137 | if (flag){
138 | if (id == 0){
139 | mLeftButton.setVisibility(View.VISIBLE);
140 | }else if (id == 1){
141 | mRightButton.setVisibility(View.VISIBLE);
142 | }
143 | }else{
144 | if (id == 0){
145 | mLeftButton.setVisibility(View.GONE);
146 | }else if (id == 1){
147 | mRightButton.setVisibility(View.GONE);
148 | }
149 | }
150 | }
151 | }
152 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
13 |
14 |
18 |
27 |
36 |
45 |
46 |
47 |
54 |
63 |
64 |
74 |
79 |
82 |
85 |
86 |
87 |
88 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_second.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
15 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/linkecoding/CustomView/87e6db5193033a4867c378553cb09c1295e6cccd/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/linkecoding/CustomView/87e6db5193033a4867c378553cb09c1295e6cccd/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/linkecoding/CustomView/87e6db5193033a4867c378553cb09c1295e6cccd/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/linkecoding/CustomView/87e6db5193033a4867c378553cb09c1295e6cccd/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/linkecoding/CustomView/87e6db5193033a4867c378553cb09c1295e6cccd/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/audiobargraph_attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/percentagegraph_attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | CustomView
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/values/topbar_attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/app/src/test/java/com/codekong/customview/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.codekong.customview;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.2.3'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
21 | task clean(type: Delete) {
22 | delete rootProject.buildDir
23 | }
24 |
--------------------------------------------------------------------------------
/example.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/linkecoding/CustomView/87e6db5193033a4867c378553cb09c1295e6cccd/example.gif
--------------------------------------------------------------------------------
/example.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/linkecoding/CustomView/87e6db5193033a4867c378553cb09c1295e6cccd/example.png
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/linkecoding/CustomView/87e6db5193033a4867c378553cb09c1295e6cccd/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------