├── .gitignore
├── .idea
├── caches
│ └── build_file_checksums.ser
└── workspace.xml
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── ai
│ │ │ └── code
│ │ │ └── customview
│ │ │ ├── MainActivity.java
│ │ │ ├── activity
│ │ │ ├── BlurActivity.java
│ │ │ ├── CommonWindowActivity.java
│ │ │ ├── IndicatorActivity.java
│ │ │ ├── PeriscopeActivity.java
│ │ │ └── SlideSelectActivity.java
│ │ │ └── view
│ │ │ ├── BlurView.java
│ │ │ ├── IndicatorView.java
│ │ │ ├── PeriscopeLayout.java
│ │ │ └── SlideSelectView.java
│ └── res
│ │ ├── drawable
│ │ ├── img_haizeiwang.jpg
│ │ ├── ytm_icon_like_png.png
│ │ ├── ytm_taobao_zan1.png
│ │ ├── ytm_taobao_zan2.png
│ │ └── ytm_taobao_zan3.png
│ │ ├── layout
│ │ ├── activity_blur.xml
│ │ ├── activity_indicator.xml
│ │ ├── activity_main.xml
│ │ ├── activity_periscope.xml
│ │ └── activity_slide_select.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
│ │ ├── attr.xml
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── ai
│ └── code
│ └── customview
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── libs
├── armeabi-v7a
│ ├── libijkffmpeg.so
│ ├── libijkplayer.so
│ └── libijksdl.so
└── armeabi
│ ├── libijkffmpeg.so
│ ├── libijkplayer.so
│ └── libijksdl.so
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | .idea/
5 | .DS_Store
6 | /build
7 | /captures
8 | .externalNativeBuild
9 | *.log
10 | build/
--------------------------------------------------------------------------------
/.idea/caches/build_file_checksums.ser:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AICode-Pan/Open-View/df9fedf9dbafdbbf75bb63dd699a57384ac39f27/.idea/caches/build_file_checksums.ser
--------------------------------------------------------------------------------
/.idea/workspace.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 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 | 1578992710632
151 |
152 |
153 | 1578992710632
154 |
155 |
156 |
157 |
158 |
159 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 |
233 |
234 |
235 |
236 |
237 |
238 | file://$PROJECT_DIR$/app/src/main/java/com/ai/code/customview/view/BlurView.java
239 | 168
240 |
241 |
242 |
243 | file://$PROJECT_DIR$/app/src/main/java/com/ai/code/customview/view/BlurView.java
244 | 84
245 |
246 |
247 |
248 |
249 |
250 |
251 |
252 |
253 |
254 | 1.8
255 |
256 |
257 |
258 |
259 |
260 |
261 |
262 |
263 |
264 |
265 |
266 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## 简介
2 | 通过Canvas或者继承View,写的一些常用的控件,记录一下。有需要的朋友可以自取。
3 |
4 | ### PersicopeLayout [效果](https://aicode-pan.oss-cn-beijing.aliyuncs.com/video/1592570155492374.mp4)
5 | 点赞动画,通过贝塞尔曲线绘制悬浮路径,图片复用。
6 |
7 |
8 | ### BlurView [效果](https://aicode-pan.oss-cn-beijing.aliyuncs.com/video/20200620110203.MP4)
9 | 仿IOS Blur控件。因为Android手机计算能力问题,Android没有类似控件。其实实现原理很简单,先裁剪View获取相应位
10 | 置Bitmap,再对Bitmap进行压缩处理和模糊处理,最后绘制出来就好了。为了使效果更像IOS的,我加了一个透明白色蒙板。
11 |
12 |
13 | ### IndicatorView [效果](https://aicode-pan.oss-cn-beijing.aliyuncs.com/video/1592570074332320.mp4)
14 | 指示器,用于画廊,导览,开屏广告,viewpager
15 |
16 |
17 | ### SlideSelectView [效果](https://aicode-pan.oss-cn-beijing.aliyuncs.com/video/1592570074324749.mp4)
18 | 滑动选择器
19 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'kotlin-android'
3 |
4 | android {
5 | compileSdkVersion 29
6 | buildToolsVersion "29.0.1"
7 | defaultConfig {
8 | applicationId "com.ai.code.customview"
9 | minSdkVersion 21
10 | targetSdkVersion 29
11 | versionCode 1
12 | versionName "1.0"
13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
14 | }
15 | buildTypes {
16 | release {
17 | minifyEnabled false
18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19 | }
20 | }
21 | }
22 |
23 | allprojects {
24 | repositories {
25 | jcenter()
26 | }
27 | }
28 |
29 | dependencies {
30 | implementation fileTree(dir: 'libs', include: ['*.jar'])
31 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
32 | exclude group: 'com.android.support', module: 'support-annotations'
33 | })
34 | implementation 'com.android.support:appcompat-v7:+'
35 | implementation 'com.android.support:recyclerview-v7:+'
36 | testImplementation 'junit:junit:4.12'
37 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
38 | }
39 | repositories {
40 | mavenCentral()
41 | }
42 |
--------------------------------------------------------------------------------
/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 /Users/pan/Downloads/sdk/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/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ai/code/customview/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.ai.code.customview;
2 |
3 | import android.app.Activity;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.view.View;
7 |
8 | import com.ai.code.customview.activity.BlurActivity;
9 | import com.ai.code.customview.activity.IndicatorActivity;
10 | import com.ai.code.customview.activity.PeriscopeActivity;
11 | import com.ai.code.customview.activity.SlideSelectActivity;
12 |
13 | public class MainActivity extends Activity {
14 | private final String TAG = MainActivity.class.getName();
15 |
16 | @Override
17 | protected void onCreate(Bundle savedInstanceState) {
18 | super.onCreate(savedInstanceState);
19 | setContentView(R.layout.activity_main);
20 | }
21 |
22 | @Override
23 | protected void onPause() {
24 | super.onPause();
25 | }
26 |
27 | public void onPeriscopeClick(View view) {
28 | Intent intent = new Intent();
29 | intent.setClass(this, PeriscopeActivity.class);
30 | startActivity(intent);
31 | }
32 |
33 | public void onFuzzyClick(View view) {
34 | Intent intent = new Intent();
35 | intent.setClass(this, BlurActivity.class);
36 | startActivity(intent);
37 | }
38 |
39 | public void onIndicator(View view) {
40 | Intent intent = new Intent();
41 | intent.setClass(this, IndicatorActivity.class);
42 | startActivity(intent);
43 | }
44 |
45 | public void onSlideSelectClick(View view) {
46 | Intent intent = new Intent();
47 | intent.setClass(this, SlideSelectActivity.class);
48 | startActivity(intent);
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ai/code/customview/activity/BlurActivity.java:
--------------------------------------------------------------------------------
1 | package com.ai.code.customview.activity;
2 |
3 | import android.app.Activity;
4 | import android.graphics.Color;
5 | import android.os.Build;
6 | import android.os.Bundle;
7 | import android.support.annotation.NonNull;
8 | import android.support.annotation.Nullable;
9 | import android.support.v7.app.AppCompatActivity;
10 | import android.support.v7.widget.LinearLayoutManager;
11 | import android.support.v7.widget.RecyclerView;
12 | import android.util.Log;
13 | import android.view.View;
14 | import android.view.ViewGroup;
15 | import android.widget.ImageView;
16 |
17 | import com.ai.code.customview.R;
18 | import com.ai.code.customview.view.BlurView;
19 |
20 | public class BlurActivity extends Activity {
21 | private BlurView blurView;
22 | private RecyclerView recyclerview;
23 | private int totalDy = 0;
24 | private int color = Color.parseColor("#FFFFFF");
25 |
26 | @Override
27 | protected void onCreate(@Nullable Bundle savedInstanceState) {
28 | super.onCreate(savedInstanceState);
29 | setContentView(R.layout.activity_blur);
30 | recyclerview = findViewById(R.id.recyclerview);
31 | blurView = findViewById(R.id.blurview);
32 |
33 | recyclerview.setLayoutManager(new LinearLayoutManager(this));
34 | recyclerview.setAdapter(new ImageAdapter());
35 |
36 |
37 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
38 | recyclerview.addOnScrollListener(new RecyclerView.OnScrollListener() {
39 |
40 | @Override
41 | public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
42 | super.onScrolled(recyclerView, dx, dy);
43 | totalDy += dy;
44 | if (totalDy < 3000) {
45 | float i = Float.valueOf(totalDy) / 6000;
46 | int alpha = (int) Math.round(i * 255f);
47 | Log.e("BlurView", "onScrolled i = " + i + " alpha=" + alpha);
48 |
49 | if (i == 0) {
50 | blurView.setBlurRadius(0);
51 | } else {
52 | blurView.setBlurRadius((int) (i * 5) + 3);
53 | }
54 | blurView.setMaskColor(setAlpha(color, i));
55 | }
56 |
57 | blurView.requestLayout();
58 | }
59 | });
60 | }
61 | }
62 |
63 | public int setAlpha(int color, float alpha) {
64 | return color & 0x00FFFFFF | Math.round(0xFF * alpha) << 24;
65 | }
66 |
67 | private class ImageAdapter extends RecyclerView.Adapter {
68 |
69 | @NonNull
70 | @Override
71 | public ItemViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
72 | ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
73 | ImageView imageView = new ImageView(viewGroup.getContext());
74 | imageView.setLayoutParams(lp);
75 | imageView.setImageResource(R.drawable.img_haizeiwang);
76 | return new ItemViewHolder(imageView);
77 | }
78 |
79 | @Override
80 | public void onBindViewHolder(@NonNull ItemViewHolder itemViewHolder, int i) {
81 |
82 | }
83 |
84 | @Override
85 | public int getItemCount() {
86 | return 10;
87 | }
88 |
89 | private class ItemViewHolder extends RecyclerView.ViewHolder {
90 | public ItemViewHolder(@NonNull View itemView) {
91 | super(itemView);
92 | }
93 | }
94 |
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ai/code/customview/activity/CommonWindowActivity.java:
--------------------------------------------------------------------------------
1 | package com.ai.code.customview.activity;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v7.app.AppCompatActivity;
6 |
7 | public class CommonWindowActivity extends AppCompatActivity {
8 | @Override
9 | protected void onCreate(@Nullable Bundle savedInstanceState) {
10 | super.onCreate(savedInstanceState);
11 | setTitle("仿苹果 通用弹窗");
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ai/code/customview/activity/IndicatorActivity.java:
--------------------------------------------------------------------------------
1 | package com.ai.code.customview.activity;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.NonNull;
5 | import android.support.annotation.Nullable;
6 | import android.support.v4.view.PagerAdapter;
7 | import android.support.v4.view.ViewPager;
8 | import android.support.v7.app.AppCompatActivity;
9 | import android.view.Gravity;
10 | import android.view.View;
11 | import android.view.ViewGroup;
12 | import android.widget.TextView;
13 |
14 | import com.ai.code.customview.R;
15 | import com.ai.code.customview.view.IndicatorView;
16 |
17 | public class IndicatorActivity extends AppCompatActivity {
18 | private ViewPager viewPager;
19 | private IndicatorView indicatorView1;
20 | private IndicatorView indicatorView2;
21 |
22 | private int count = 4;
23 |
24 | @Override
25 | protected void onCreate(@Nullable Bundle savedInstanceState) {
26 | super.onCreate(savedInstanceState);
27 | setTitle("指示器");
28 | setContentView(R.layout.activity_indicator);
29 | viewPager = findViewById(R.id.viewpager);
30 |
31 | indicatorView1 = findViewById(R.id.indicator1);
32 | indicatorView2 = findViewById(R.id.indicator2);
33 | indicatorView1.setCount(count);
34 | indicatorView2.setCount(count);
35 |
36 | viewPager.setAdapter(new PagerAdapter() {
37 | @Override
38 | public int getCount() {
39 | return count;
40 | }
41 |
42 | @Override
43 | public boolean isViewFromObject(@NonNull View view, @NonNull Object o) {
44 | return view == o;
45 | }
46 |
47 | @NonNull
48 | @Override
49 | public Object instantiateItem(@NonNull ViewGroup container, int position) {
50 | TextView textView = new TextView(IndicatorActivity.this);
51 | textView.setText("页面" + (position + 1));
52 | textView.setGravity(Gravity.CENTER);
53 | ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
54 | textView.setLayoutParams(lp);
55 |
56 | container.addView(textView);
57 | return textView;
58 | }
59 |
60 | @Override
61 | public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
62 | container.removeView((View) object);
63 | }
64 | });
65 |
66 | viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
67 | @Override
68 | public void onPageScrolled(int i, float v, int i1) {
69 |
70 | }
71 |
72 | @Override
73 | public void onPageSelected(int i) {
74 | indicatorView1.setSelectPosition(i);
75 | indicatorView2.setSelectPosition(i);
76 | }
77 |
78 | @Override
79 | public void onPageScrollStateChanged(int i) {
80 |
81 | }
82 | });
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ai/code/customview/activity/PeriscopeActivity.java:
--------------------------------------------------------------------------------
1 | package com.ai.code.customview.activity;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.view.View;
6 | import android.widget.Button;
7 |
8 | import com.ai.code.customview.view.PeriscopeLayout;
9 | import com.ai.code.customview.R;
10 |
11 | public class PeriscopeActivity extends AppCompatActivity {
12 | private PeriscopeLayout ll_heart;
13 | private Button ll_btn;
14 |
15 | @Override
16 | protected void onCreate(Bundle savedInstanceState) {
17 | super.onCreate(savedInstanceState);
18 | setTitle("点赞动画");
19 | setContentView(R.layout.activity_periscope);
20 | ll_heart = findViewById(R.id.ll_heart);
21 | ll_btn = findViewById(R.id.ll_btn);
22 |
23 | ll_btn.setOnClickListener(new View.OnClickListener() {
24 | @Override
25 | public void onClick(View view) {
26 | ll_heart.addHeart();
27 | }
28 | });
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ai/code/customview/activity/SlideSelectActivity.java:
--------------------------------------------------------------------------------
1 | package com.ai.code.customview.activity;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.widget.TextView;
7 | import android.widget.Toast;
8 |
9 | import com.ai.code.customview.R;
10 | import com.ai.code.customview.view.SlideSelectView;
11 |
12 | public class SlideSelectActivity extends AppCompatActivity {
13 | String[] s1 = {"1", "2", "3", "4"};
14 | String[] s2 = {"极小", "小", "中", "大", "很大"};
15 | @Override
16 | protected void onCreate(@Nullable Bundle savedInstanceState) {
17 | super.onCreate(savedInstanceState);
18 | setTitle("SlideSelectActivity");
19 | setContentView(R.layout.activity_slide_select);
20 |
21 | SlideSelectView slideview1 = findViewById(R.id.slideview1);
22 | SlideSelectView slideview2 = findViewById(R.id.slideview2);
23 | SlideSelectView slideview3 = findViewById(R.id.slideview3);
24 | final TextView tvTips = findViewById(R.id.tips);
25 |
26 | slideview1.setOnSelectListener(new SlideSelectView.onSelectListener() {
27 | @Override
28 | public void onSelect(int index) {
29 | Toast.makeText(SlideSelectActivity.this, "选择了第" + index + "个Index", Toast.LENGTH_SHORT).show();
30 | }
31 | });
32 |
33 |
34 | slideview2.setString(s1);
35 |
36 |
37 | slideview3.setString(s2);
38 | slideview3.setCurrentPosition(2);
39 | slideview3.setOnSelectListener(new SlideSelectView.onSelectListener() {
40 | @Override
41 | public void onSelect(int index) {
42 | tvTips.setText("您选择了 " + s2[index]);
43 | }
44 | });
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ai/code/customview/view/BlurView.java:
--------------------------------------------------------------------------------
1 | package com.ai.code.customview.view;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.graphics.Bitmap;
6 | import android.graphics.BitmapFactory;
7 | import android.graphics.Canvas;
8 | import android.graphics.Color;
9 | import android.graphics.Matrix;
10 | import android.graphics.Paint;
11 | import android.graphics.Path;
12 | import android.graphics.Rect;
13 | import android.graphics.RectF;
14 | import android.renderscript.Allocation;
15 | import android.renderscript.Element;
16 | import android.renderscript.RenderScript;
17 | import android.renderscript.ScriptIntrinsicBlur;
18 | import android.util.AttributeSet;
19 | import android.util.Log;
20 | import android.view.View;
21 | import android.view.ViewGroup;
22 |
23 | import com.ai.code.customview.R;
24 |
25 | /**
26 | * Created by AICode-Pan on 20/06/20.
27 | */
28 | public class BlurView extends View {
29 | private Bitmap bitmap = null;
30 | private Paint paint = null;
31 | private BitmapFactory.Options options = null;
32 | private long lastActionTime = 0;
33 | //缩减比例,太小会失真
34 | private float downScaleFactor = 0.8f;
35 | //视图圆角处理
36 | private float mRadius = 0;
37 | //为了使效果更接近IOS的效果,最后绘制一个蒙板盖上面。
38 | private int maskColor = 0;
39 | //模糊程度, 25f是最大模糊度, 越大绘制也越慢。
40 | private float mBlurRadius = 0;
41 | // 创建RenderScript内核对象
42 | private RenderScript rs = null;
43 | // 创建一个模糊效果的RenderScript的工具对象
44 | private ScriptIntrinsicBlur blurScript = null;
45 |
46 | private int alpha = 255;
47 |
48 | public BlurView(Context context) {
49 | super(context);
50 | init();
51 | }
52 |
53 | public BlurView(Context context, AttributeSet attrs) {
54 | super(context, attrs);
55 | init();
56 | getAttr(context, attrs);
57 | }
58 |
59 | public BlurView(Context context, AttributeSet attrs, int defStyleAttr) {
60 | super(context, attrs, defStyleAttr);
61 | init();
62 | getAttr(context, attrs);
63 | }
64 |
65 | private void init() {
66 | //关闭硬件加速
67 | setLayerType(View.LAYER_TYPE_HARDWARE, null);
68 |
69 | paint = new Paint();
70 | options = new BitmapFactory.Options();
71 | //NORMAL: 内外都模糊绘制
72 | //SOLID: 内部正常绘制,外部模糊
73 | //INNER: 内部模糊,外部不绘制
74 | // paint.setMaskFilter(new BlurMaskFilter(50, BlurMaskFilter.Blur.NORMAL));
75 |
76 | rs = RenderScript.create(getContext());
77 | blurScript = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
78 | }
79 |
80 | /**
81 | * 设置遮罩颜色
82 | * @param color
83 | */
84 | public void setMaskColor(int color) {
85 | this.maskColor = color;
86 | }
87 |
88 | /**
89 | * 设置模糊程度
90 | * @param radius
91 | */
92 | public void setBlurRadius(int radius) {
93 | this.mBlurRadius = radius;
94 | }
95 |
96 | public void setAlpha(int alpha) {
97 | this.alpha = alpha;
98 | }
99 |
100 | private void getAttr(Context context, AttributeSet attrs) {
101 | TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.BlurView);
102 | //压缩比例,
103 | downScaleFactor = typedArray.getFloat(R.styleable.BlurView_downScale, 0.8f);
104 | //是否裁剪圆角
105 | mRadius = typedArray.getDimensionPixelSize(R.styleable.BlurView_circleRadius, 0);
106 | //背景色
107 | maskColor = typedArray.getColor(R.styleable.BlurView_maskColor, 0);
108 | //模糊度
109 | mBlurRadius = typedArray.getFloat(R.styleable.BlurView_blurRadius, 0);
110 | typedArray.recycle();
111 | }
112 |
113 | /**
114 | * 获取需要Bitmap
115 | * @param left
116 | * @param top
117 | * @param right
118 | * @param bottom
119 | */
120 | private void setBlurBitmapFromView(int left, int top, int right, int bottom) {
121 | //获取父View
122 | ViewGroup parent = (ViewGroup) getParent();
123 | //将此布局从父View移除,在截图不截进此视图。
124 | parent.removeView(this);
125 | //获取对应位置的Bitmap对象
126 | bitmap = getDownscaledBitmapForView(parent, new Rect(left, top, right, bottom), downScaleFactor);
127 | //截完图获取到bitmap之后,再把此View加载到父布局上
128 | parent.addView(this);
129 | printfActionTime("图片处理");
130 |
131 | //模糊处理
132 | bitmap = blurBitmap(bitmap, mBlurRadius);
133 | printfActionTime("模糊处理");
134 | }
135 |
136 | @Override
137 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
138 | super.onLayout(changed, left, top, right, bottom);
139 | // Log.i("BlurView", "onLayoutBlurView changed=" + changed + " left=" + left + " ,top=" + top + " ,right=" + right + " ,bottom=" + bottom);
140 |
141 | lastActionTime = System.currentTimeMillis();
142 | //获取Bitmap从View
143 |
144 | if (mBlurRadius > 0 && mBlurRadius < 25) {
145 | setBlurBitmapFromView(getLeft(), getTop(), getRight(), getBottom());
146 | } else {
147 | bitmap = null;
148 | }
149 | }
150 |
151 | @Override
152 | protected void onDraw(Canvas canvas) {
153 | super.onDraw(canvas);
154 | Path mPath = new Path();
155 |
156 | paint.setAlpha(alpha);
157 |
158 | if (mRadius > 0) {
159 | mPath.addRoundRect(new RectF(0, 0, getWidth(), getHeight()) , mRadius, mRadius, Path.Direction.CW);
160 | canvas.clipPath(mPath);
161 | }
162 |
163 | //绘制
164 | if (bitmap != null) {
165 | canvas.drawBitmap(bitmap, null, new Rect(0, 0, getWidth(), getHeight()), paint);
166 | }
167 | printfActionTime("绘制完成");
168 |
169 | if (maskColor != 0) {
170 | canvas.drawColor(maskColor);
171 | }
172 | }
173 |
174 | /**
175 | * 模糊处理
176 | * @param image
177 | * @param blurRadius
178 | * @return
179 | */
180 | public Bitmap blurBitmap(Bitmap image, float blurRadius) {
181 | // 创建一张渲染后的输出图片
182 | Bitmap outputBitmap = Bitmap.createBitmap(image);
183 | // Log.i("BlurView", "onLayoutBlurView bitmap.size=" + inputBitmap.getByteCount());
184 |
185 | // 由于RenderScript并没有使用VM来分配内存,所以需要使用Allocation类来创建和分配内存空间
186 | // 创建Allocation对象的时候其实内存是空的,需要使用copyTo()将数据填充进去
187 | Allocation tmpIn = Allocation.createFromBitmap(rs, image);
188 | Allocation tmpOut = Allocation.createFromBitmap(rs, outputBitmap);
189 |
190 | // 设置渲染的模糊程度, 25f是最大模糊度
191 | blurScript.setRadius(blurRadius);
192 | // 设置blurScript对象的输入内存
193 | blurScript.setInput(tmpIn);
194 | // 将输出数据保存到输出内存中
195 | blurScript.forEach(tmpOut);
196 |
197 | // 将数据填充到Allocation中
198 | tmpOut.copyTo(outputBitmap);
199 | image.recycle();
200 | rs.destroy();
201 |
202 | return outputBitmap;
203 | }
204 |
205 | /**
206 | * 打印方法执行时间
207 | * @param function
208 | */
209 | private void printfActionTime(String function) {
210 | long time = System.currentTimeMillis();
211 | Log.i("ActionTime", function + " time=" + (time - lastActionTime));
212 | lastActionTime = time;
213 | }
214 |
215 | /**
216 | * 裁剪View,View转Bitmap,同时进行Bitmap压缩
217 | * @param view
218 | * @param crop
219 | * @param downscaleFactor 压缩比例
220 | * @return
221 | */
222 | private Bitmap getDownscaledBitmapForView(View view, Rect crop, float downscaleFactor) {
223 | int width = Math.round(crop.width() * downscaleFactor);
224 | int height = Math.round(crop.height() * downscaleFactor);
225 |
226 | if (view.getWidth() <= 0 || view.getHeight() <= 0 || width <= 0 || height <= 0) {
227 | throw new IllegalArgumentException("No screen available (width or height = 0)");
228 | }
229 |
230 | float dx = -crop.left * downscaleFactor;
231 | float dy = -crop.top * downscaleFactor;
232 |
233 | Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
234 | Canvas canvas = new Canvas(bitmap);
235 | Matrix matrix = new Matrix();
236 | matrix.preScale(downscaleFactor, downscaleFactor);
237 | matrix.postTranslate(dx, dy);
238 | canvas.setMatrix(matrix);
239 | view.draw(canvas);
240 |
241 | return bitmap;
242 | }
243 | }
244 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ai/code/customview/view/IndicatorView.java:
--------------------------------------------------------------------------------
1 | package com.ai.code.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.util.AttributeSet;
9 | import android.util.Log;
10 | import android.view.View;
11 |
12 | import com.ai.code.customview.R;
13 |
14 | /**
15 | * 指示器
16 | * Created by AICode-Pan on 20/05/10.
17 | */
18 | public class IndicatorView extends View {
19 |
20 | private Paint mCirclePaint;
21 | private int mCount = 3; // indicator 的数量
22 | private int mRadius = 10;//半径
23 | private int mSelectWidth = 0;
24 | private int mSelectColor = Color.RED;
25 | private int mDotNormalColor = Color.WHITE;// 小圆点默认颜色
26 | private int mSpace = 20;// 圆点之间的间距
27 | private int mSelectPosition = 0; // 选中的位置
28 |
29 | public IndicatorView(Context context) {
30 | super(context);
31 | init();
32 | }
33 |
34 | public IndicatorView(Context context, AttributeSet attrs) {
35 | super(context, attrs);
36 | init();
37 | getAttr(context, attrs);
38 | }
39 |
40 | public IndicatorView(Context context, AttributeSet attrs, int defStyleAttr) {
41 | super(context, attrs, defStyleAttr);
42 | init();
43 | getAttr(context, attrs);
44 | }
45 |
46 | /**
47 | * 获取自定义属性
48 | *
49 | * @param context
50 | * @param attrs
51 | */
52 | private void getAttr(Context context, AttributeSet attrs) {
53 | TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.IndicatorView);
54 | mRadius = typedArray.getDimensionPixelSize(R.styleable.IndicatorView_indicatorRadius, 10);
55 | mSpace = typedArray.getDimensionPixelSize(R.styleable.IndicatorView_indicatorSpace, 20);
56 | // color
57 | mSelectColor = typedArray.getColor(R.styleable.IndicatorView_indicatorSelectColor, Color.WHITE);
58 | mDotNormalColor = typedArray.getColor(R.styleable.IndicatorView_indicatorColor, Color.GRAY);
59 | mSelectWidth = typedArray.getDimensionPixelSize(R.styleable.IndicatorView_indicatorSelectWidth, 0);
60 |
61 | typedArray.recycle();
62 | }
63 |
64 | private void init() {
65 | mCirclePaint = new Paint();
66 | mCirclePaint.setDither(true);
67 | mCirclePaint.setAntiAlias(true);
68 | mCirclePaint.setStyle(Paint.Style.FILL);
69 | mCirclePaint.setStrokeCap(Paint.Cap.ROUND);
70 | mCirclePaint.setColor(mDotNormalColor);
71 | }
72 |
73 | @Override
74 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
75 | int width = mRadius * 2 * mCount + mSpace * (mCount - 1) + mSelectWidth;
76 | int height = mRadius * 2 + mSpace * 2;
77 |
78 | Log.d("IndicatorView", "onMeasure width=" + width + " ,height=" + height);
79 | setMeasuredDimension(width, height);
80 | }
81 |
82 | @Override
83 | protected void onDraw(Canvas canvas) {
84 | int cx = 0;
85 | int cy = getMeasuredHeight() / 2;
86 | for (int i = 0; i < mCount; i++) {
87 | if (i == 0) {
88 | cx = mRadius;
89 | } else {
90 | cx += mRadius * 2 + mSpace;
91 | }
92 |
93 | float x = cx;
94 | float y = cy;
95 |
96 | Log.d("IndicatorView", "onDraw isSelected=" + (mSelectPosition == i) + " view.x=" + x + " ,view.y=" + y);
97 |
98 | if (mSelectPosition == i) {
99 | mCirclePaint.setColor(mSelectColor);
100 | if (mSelectWidth == 0) {
101 | canvas.drawCircle(x, y, mRadius, mCirclePaint);
102 | } else {
103 | mCirclePaint.setStrokeWidth(mRadius * 2);
104 | canvas.drawLine(x, y, x + mSelectWidth, y, mCirclePaint);
105 | cx += mSelectWidth;
106 | }
107 | } else {
108 | mCirclePaint.setColor(mDotNormalColor);
109 | canvas.drawCircle(x, y, mRadius, mCirclePaint);
110 | }
111 | }
112 | }
113 |
114 | public void setCount(int count) {
115 | this.mCount = count;
116 | invalidate();
117 | }
118 |
119 | /**
120 | * 设置选中的item
121 | * @param position
122 | */
123 | public void setSelectPosition(int position) {
124 | if (mCount > 0 && mSelectPosition < mCount) {
125 | this.mSelectPosition = position;
126 | invalidate();
127 | }
128 | }
129 |
130 | /**
131 | * 设置半径
132 | * @param radius
133 | */
134 | public void setRadius(int radius) {
135 | this.mRadius = radius;
136 | }
137 |
138 | /**
139 | * 设置选中的颜色
140 | * @param color
141 | */
142 | public void setSelectColor(int color) {
143 | this.mSelectColor = color;
144 | }
145 |
146 | /**
147 | * 设置间距
148 | * @param space
149 | */
150 | public void setSpace(int space) {
151 | this.mSpace = space;
152 | }
153 |
154 | public void setDotNormalColor(int color) {
155 | this.mDotNormalColor = color;
156 | }
157 | }
158 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ai/code/customview/view/PeriscopeLayout.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015, 程序亦非猿
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ai.code.customview.view;
18 |
19 | import android.animation.Animator;
20 | import android.animation.AnimatorListenerAdapter;
21 | import android.animation.AnimatorSet;
22 | import android.animation.ObjectAnimator;
23 | import android.animation.TypeEvaluator;
24 | import android.animation.ValueAnimator;
25 | import android.annotation.TargetApi;
26 | import android.content.Context;
27 | import android.graphics.PointF;
28 | import android.graphics.drawable.Drawable;
29 | import android.os.Build;
30 | import android.util.AttributeSet;
31 | import android.view.View;
32 | import android.view.animation.AccelerateDecelerateInterpolator;
33 | import android.view.animation.AccelerateInterpolator;
34 | import android.view.animation.DecelerateInterpolator;
35 | import android.view.animation.Interpolator;
36 | import android.view.animation.LinearInterpolator;
37 | import android.widget.ImageView;
38 | import android.widget.RelativeLayout;
39 |
40 | import com.ai.code.customview.R;
41 |
42 | import java.util.ArrayList;
43 | import java.util.List;
44 | import java.util.Random;
45 |
46 | /**
47 | * Created by AICode-Pan on 18/09/10.
48 | */
49 | public class PeriscopeLayout extends RelativeLayout {
50 |
51 | private Interpolator line = new LinearInterpolator();//线性
52 | private Interpolator acc = new AccelerateInterpolator();//加速
53 | private Interpolator dce = new DecelerateInterpolator();//减速
54 | private Interpolator accdec = new AccelerateDecelerateInterpolator();//先加速后减速
55 | private Interpolator[] interpolators;
56 |
57 | private int mHeight;
58 | private int mWidth;
59 | private LayoutParams lp;
60 | private Drawable[] drawables;
61 | private Random random = new Random();
62 | private List heartViews;
63 |
64 | private int dHeight;
65 | private int dWidth;
66 |
67 | public PeriscopeLayout(Context context) {
68 | super(context);
69 | init();
70 | }
71 |
72 | public PeriscopeLayout(Context context, AttributeSet attrs) {
73 | super(context, attrs);
74 | init();
75 | }
76 |
77 | public PeriscopeLayout(Context context, AttributeSet attrs, int defStyleAttr) {
78 | super(context, attrs, defStyleAttr);
79 | init();
80 | }
81 |
82 | @TargetApi(Build.VERSION_CODES.LOLLIPOP)
83 | public PeriscopeLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
84 | super(context, attrs, defStyleAttr, defStyleRes);
85 | init();
86 | }
87 |
88 | private void init() {
89 |
90 | //初始化显示的图片
91 | drawables = new Drawable[3];
92 | Drawable red = getResources().getDrawable(R.drawable.ytm_taobao_zan1);
93 | Drawable yellow = getResources().getDrawable(R.drawable.ytm_taobao_zan2);
94 | Drawable blue = getResources().getDrawable(R.drawable.ytm_taobao_zan3);
95 |
96 | drawables[0] = red;
97 | drawables[1] = yellow;
98 | drawables[2] = blue;
99 | //获取图的宽高 用于后面的计算
100 | //注意 我这里3张图片的大小都是一样的,所以我只取了一个
101 | dHeight = red.getIntrinsicHeight();
102 | dWidth = red.getIntrinsicWidth();
103 |
104 | //底部 并且 水平居中
105 | lp = new LayoutParams(dWidth, dHeight);
106 | lp.addRule(CENTER_HORIZONTAL, TRUE);//这里的TRUE 要注意 不是true
107 | lp.addRule(ALIGN_PARENT_BOTTOM, TRUE);
108 |
109 | // 初始化插补器
110 | interpolators = new Interpolator[4];
111 | interpolators[0] = line;
112 | interpolators[1] = acc;
113 | interpolators[2] = dce;
114 | interpolators[3] = accdec;
115 |
116 | heartViews = new ArrayList<>();
117 | }
118 |
119 |
120 | @Override
121 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
122 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
123 | mWidth = getMeasuredWidth();
124 | mHeight = getMeasuredHeight();
125 | }
126 |
127 | private ImageView heartView;
128 | public void addHeart() {
129 | if (heartViews.size() == 0) {
130 | heartView = new ImageView(getContext());
131 | } else {
132 | synchronized (heartViews) {
133 | heartView = heartViews.remove(0);
134 | }
135 | }
136 | //随机选一个
137 | heartView.setImageDrawable(drawables[random.nextInt(3)]);
138 | heartView.setLayoutParams(lp);
139 |
140 | addView(heartView);
141 |
142 | Animator set = getAnimator(heartView);
143 | set.addListener(new AnimEndListener(heartView));
144 | set.start();
145 |
146 | }
147 |
148 | private Animator getAnimator(View target) {
149 | AnimatorSet set = getEnterAnimtor(target);
150 |
151 | ValueAnimator bezierValueAnimator = getBezierValueAnimator(target);
152 |
153 | AnimatorSet finalSet = new AnimatorSet();
154 | finalSet.playSequentially(set);
155 | finalSet.playSequentially(set, bezierValueAnimator);
156 | finalSet.setInterpolator(interpolators[random.nextInt(4)]);
157 | finalSet.setTarget(target);
158 | return finalSet;
159 | }
160 |
161 | private AnimatorSet getEnterAnimtor(final View target) {
162 |
163 | ObjectAnimator alpha = ObjectAnimator.ofFloat(target, View.ALPHA, 0.2f, 1f);
164 | ObjectAnimator scaleX = ObjectAnimator.ofFloat(target, View.SCALE_X, 0.2f, 1f);
165 | ObjectAnimator scaleY = ObjectAnimator.ofFloat(target, View.SCALE_Y, 0.2f, 1f);
166 | AnimatorSet enter = new AnimatorSet();
167 | enter.setDuration(500);
168 | enter.setInterpolator(new LinearInterpolator());
169 | enter.playTogether(alpha, scaleX, scaleY);
170 | enter.setTarget(target);
171 | return enter;
172 | }
173 |
174 | private ValueAnimator getBezierValueAnimator(View target) {
175 |
176 | //初始化一个贝塞尔计算器- - 传入
177 | BezierEvaluator evaluator = new BezierEvaluator(getPointF(2), getPointF(1));
178 |
179 | //这里最好画个图 理解一下 传入了起点 和 终点
180 | ValueAnimator animator = ValueAnimator.ofObject(evaluator, new PointF((mWidth - dWidth) / 2, mHeight - dHeight), new PointF(random.nextInt(getWidth()), 0));
181 | animator.addUpdateListener(new BezierListener(target));
182 | animator.setTarget(target);
183 | animator.setDuration(3000);
184 | return animator;
185 | }
186 |
187 | /**
188 | * 获取中间的两个 点
189 | *
190 | * @param scale
191 | */
192 | private PointF getPointF(int scale) {
193 |
194 | PointF pointF = new PointF();
195 | pointF.x = random.nextInt((mWidth - 100));//减去100 是为了控制 x轴活动范围,看效果 随意~~
196 | //再Y轴上 为了确保第二个点 在第一个点之上,我把Y分成了上下两半 这样动画效果好一些 也可以用其他方法
197 | pointF.y = random.nextInt((mHeight - 100)) / scale;
198 | return pointF;
199 | }
200 |
201 | private class BezierListener implements ValueAnimator.AnimatorUpdateListener {
202 |
203 | private View target;
204 |
205 | public BezierListener(View target) {
206 | this.target = target;
207 | }
208 |
209 | @Override
210 | public void onAnimationUpdate(ValueAnimator animation) {
211 | //这里获取到贝塞尔曲线计算出来的的x y值 赋值给view 这样就能让爱心随着曲线走啦
212 | PointF pointF = (PointF) animation.getAnimatedValue();
213 | target.setX(pointF.x);
214 | target.setY(pointF.y);
215 | // 这里顺便做一个alpha动画
216 | target.setAlpha(1 - animation.getAnimatedFraction());
217 | }
218 | }
219 |
220 |
221 | private class AnimEndListener extends AnimatorListenerAdapter {
222 | private ImageView target;
223 |
224 | public AnimEndListener(ImageView target) {
225 | this.target = target;
226 | }
227 |
228 | @Override
229 | public void onAnimationEnd(Animator animation) {
230 | super.onAnimationEnd(animation);
231 | //因为不停的add 导致子view数量只增不减,所以在view动画结束后remove掉
232 | removeView(target);
233 | target.clearAnimation();
234 | target.setX(getWidth() / 2);
235 | target.setY(getHeight());
236 | synchronized (heartViews) {
237 | heartViews.add(target);
238 | }
239 | }
240 | }
241 |
242 | public class BezierEvaluator implements TypeEvaluator {
243 |
244 |
245 | private PointF pointF1;
246 | private PointF pointF2;
247 | public BezierEvaluator(PointF pointF1, PointF pointF2){
248 | this.pointF1 = pointF1;
249 | this.pointF2 = pointF2;
250 | }
251 | @Override
252 | public PointF evaluate(float time, PointF startValue,
253 | PointF endValue) {
254 |
255 | float timeLeft = 1.0f - time;
256 | PointF point = new PointF();//结果
257 |
258 | point.x = timeLeft * timeLeft * timeLeft * (startValue.x)
259 | + 3 * timeLeft * timeLeft * time * (pointF1.x)
260 | + 3 * timeLeft * time * time * (pointF2.x)
261 | + time * time * time * (endValue.x);
262 |
263 | point.y = timeLeft * timeLeft * timeLeft * (startValue.y)
264 | + 3 * timeLeft * timeLeft * time * (pointF1.y)
265 | + 3 * timeLeft * time * time * (pointF2.y)
266 | + time * time * time * (endValue.y);
267 | return point;
268 | }
269 | }
270 |
271 | public void clear() {
272 | heartViews.clear();
273 | }
274 | }
275 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ai/code/customview/view/SlideSelectView.java:
--------------------------------------------------------------------------------
1 | package com.ai.code.customview.view;
2 |
3 | import android.animation.ValueAnimator;
4 | import android.content.Context;
5 | import android.content.res.TypedArray;
6 | import android.graphics.Canvas;
7 | import android.graphics.Paint;
8 | import android.text.TextPaint;
9 | import android.util.AttributeSet;
10 | import android.util.DisplayMetrics;
11 | import android.util.TypedValue;
12 | import android.view.MotionEvent;
13 | import android.view.View;
14 | import android.view.WindowManager;
15 | import android.view.animation.AccelerateInterpolator;
16 |
17 | import com.ai.code.customview.R;
18 |
19 | /**
20 | * Created by AICode-Pan on 20/05/10.
21 | */
22 | public class SlideSelectView extends View {
23 | //线距离两头的边距
24 | private static float MARGEN_LINE = 60;
25 | //小圆半径
26 | private int smallCircleRadius;
27 | //大圆半径
28 | private float bigCircleRadius;
29 | //大圆圆心半径
30 | private float bigCircleCenterRadius;
31 | //小圆的数量
32 | private int countOfSmallCircle;
33 | //小圆的横坐标
34 | private float circlesX[];
35 | private Context mContext;
36 | //线的画笔
37 | private Paint mLinePaint;
38 | //小圆画笔
39 | private Paint mSmallCirclePaint;
40 | //大圆画笔
41 | private Paint mBigCirclePaint;
42 | //圆心画笔
43 | private Paint mBigCircleCenterPaint;
44 | //文字画笔
45 | private TextPaint mTextPaint;
46 | //控件高度
47 | private float mHeight;
48 | //控件宽度
49 | private float mWidth;
50 | //大圆的横坐标
51 | private float bigCircleX;
52 | //是否是手指跟随模式
53 | private boolean isFollowMode;
54 | //手指按下的x坐标
55 | private float startX;
56 | //线的颜色
57 | private int lineColor;
58 | //线的宽度
59 | private int lineStrokeWidth;
60 | //小圆颜色
61 | private int smallCircleColor;
62 | //大圆颜色
63 | private int bigCircleColor;
64 | //圆心颜色
65 | private int bigCircleCenterColor;
66 | //文字大小
67 | private float textSize;
68 | //文字颜色
69 | private int textColor;
70 | //文字选中颜色
71 | private int textSelectColor;
72 | //文字宽度
73 | private float textWidth;
74 | //当前大球距离最近的位置
75 | private int currentPosition;
76 | //小圆之间的间距
77 | private float distanceX;
78 | //文字顶部间距
79 | private int textTopMargin;
80 | //利率文字
81 | private String[] text4Rates = {};
82 | //依附效果实现
83 | private ValueAnimator valueAnimator;
84 | //用于纪录松手后的x坐标
85 | private float currentPositionX;
86 |
87 | private onSelectListener selectListener;
88 |
89 |
90 | public SlideSelectView(Context context) {
91 | this(context, null);
92 | }
93 |
94 | public SlideSelectView(Context context, AttributeSet attrs) {
95 | super(context, attrs);
96 | mContext = context;
97 |
98 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SlideSelectView);
99 | lineColor = a.getColor(R.styleable.SlideSelectView_lineColor, 0xff717171);
100 | lineStrokeWidth = a.getDimensionPixelSize(R.styleable.SlideSelectView_lineStrokeWidth, 10);
101 | smallCircleColor = a.getColor(R.styleable.SlideSelectView_smallCircleColor, 0xff717171);
102 | smallCircleRadius = a.getDimensionPixelSize(R.styleable.SlideSelectView_smallCircleRadius, 0);
103 | bigCircleColor = a.getColor(R.styleable.SlideSelectView_bigCircleColor, 0xffEB535E);
104 | bigCircleRadius = a.getDimensionPixelSize(R.styleable.SlideSelectView_bigCircleRadius, 30);
105 | bigCircleCenterColor = a.getColor(R.styleable.SlideSelectView_bigCenterColor, 0xffffffff);
106 | bigCircleCenterRadius = a.getDimensionPixelSize(R.styleable.SlideSelectView_bigCenterRadius, 0);
107 | countOfSmallCircle = a.getInt(R.styleable.SlideSelectView_circleCount, 5);
108 | textSize = a.getDimensionPixelSize(R.styleable.SlideSelectView_textSize, (int) TypedValue.applyDimension(
109 | TypedValue.COMPLEX_UNIT_SP, 10, getResources().getDisplayMetrics()));
110 | textTopMargin = a.getDimensionPixelSize(R.styleable.SlideSelectView_textTopMargin, 4);
111 | textColor = a.getColor(R.styleable.SlideSelectView_textColor, 0xff717171);
112 | textSelectColor = a.getColor(R.styleable.SlideSelectView_textSelectColor, 0xffEB535E);
113 | a.recycle();
114 | MARGEN_LINE = bigCircleRadius + 20;
115 | mLinePaint = new Paint();
116 | mLinePaint.setStyle(Paint.Style.STROKE);
117 | mLinePaint.setColor(lineColor);
118 | mLinePaint.setStrokeWidth(lineStrokeWidth);
119 | mLinePaint.setAntiAlias(true);
120 |
121 | if (smallCircleRadius != 0) {
122 | mSmallCirclePaint = new Paint();
123 | mSmallCirclePaint.setStyle(Paint.Style.FILL);
124 | mSmallCirclePaint.setColor(smallCircleColor);
125 | mSmallCirclePaint.setAntiAlias(true);
126 | }
127 |
128 | mBigCirclePaint = new Paint();
129 | mBigCirclePaint.setStyle(Paint.Style.FILL);
130 | mBigCirclePaint.setColor(bigCircleColor);
131 | mBigCirclePaint.setAntiAlias(true);
132 |
133 | if (bigCircleCenterRadius != 0) {
134 | mBigCircleCenterPaint = new Paint();
135 | mBigCircleCenterPaint.setStyle(Paint.Style.FILL);
136 | mBigCircleCenterPaint.setColor(bigCircleCenterColor);
137 | mBigCircleCenterPaint.setAntiAlias(true);
138 | }
139 |
140 | mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
141 | mTextPaint.setColor(textColor);
142 | mTextPaint.setTextSize(textSize);
143 |
144 | currentPosition = countOfSmallCircle / 2;
145 |
146 | }
147 |
148 | /**
149 | * 设置显示文本
150 | *
151 | * @param strings
152 | */
153 | public void setString(String[] strings) {
154 | text4Rates = strings;
155 | textWidth = mTextPaint.measureText(text4Rates[0]);
156 |
157 | if (countOfSmallCircle != text4Rates.length) {
158 | throw new IllegalArgumentException("the count of small circle must be equal to the " +
159 | "text array length !");
160 | }
161 |
162 | }
163 |
164 | /**
165 | * 设置监听器
166 | *
167 | * @param listener
168 | */
169 | public void setOnSelectListener(onSelectListener listener) {
170 | selectListener = listener;
171 | }
172 |
173 |
174 | @Override
175 | protected void onDraw(Canvas canvas) {
176 |
177 | //画中间的线
178 | drawLine(canvas);
179 |
180 | //画小圆
181 | if (smallCircleRadius != 0) {
182 | for (int i = 0; i < countOfSmallCircle; i++) {
183 | canvas.drawCircle(circlesX[i], mHeight / 2, smallCircleRadius, mSmallCirclePaint);
184 | }
185 | }
186 |
187 | //画大圆的默认位置
188 | canvas.drawCircle(bigCircleX, mHeight / 2, bigCircleRadius, mBigCirclePaint);
189 |
190 | //如果圆心半径不为0,绘制圆心
191 | if (bigCircleCenterRadius != 0) {
192 | canvas.drawCircle(bigCircleX, mHeight / 2, bigCircleCenterRadius, mBigCircleCenterPaint);
193 | }
194 |
195 | //画文字
196 | for (int i = 0, size = text4Rates.length; i < size; i++) {
197 | textWidth = mTextPaint.measureText(text4Rates[i]);
198 | if (i == currentPosition) {
199 | mTextPaint.setColor(textSelectColor);
200 | } else {
201 | mTextPaint.setColor(textColor);
202 | }
203 | canvas.drawText(text4Rates[i],
204 | circlesX[i] - textWidth / 2,
205 | (mHeight / 2) + bigCircleRadius * 2 + textTopMargin,
206 | mTextPaint);
207 | }
208 | }
209 |
210 | //修改线的类型,如果为true,线一直未一种颜色,如果为false,头到大圆的位置为大圆的颜色,大圆到尾,是线原本的颜色。
211 | private boolean lineMode = false;
212 |
213 | private void drawLine(Canvas canvas) {
214 | if (lineMode) {
215 | canvas.drawLine(MARGEN_LINE, mHeight / 2, mWidth - MARGEN_LINE, mHeight / 2,
216 | mLinePaint);
217 | } else {
218 | mLinePaint.setColor(bigCircleColor);
219 | canvas.drawLine(MARGEN_LINE, mHeight / 2, bigCircleX, mHeight / 2,
220 | mLinePaint);
221 | mLinePaint.setColor(lineColor);
222 | canvas.drawLine(bigCircleX, mHeight / 2, mWidth - MARGEN_LINE, mHeight / 2, mLinePaint);
223 | }
224 | }
225 |
226 | @Override
227 | public boolean onTouchEvent(MotionEvent event) {
228 |
229 | switch (event.getActionMasked()) {
230 | case MotionEvent.ACTION_DOWN:
231 |
232 | startX = event.getX();
233 | //如果手指按下的x坐标与大圆的x坐标的距离小于半径,则是follow模式
234 | if (Math.abs(startX - bigCircleX) <= bigCircleRadius) {
235 | isFollowMode = true;
236 | } else {
237 | isFollowMode = false;
238 | }
239 |
240 | break;
241 | case MotionEvent.ACTION_MOVE:
242 |
243 | //如果是follow模式,则大圆跟随手指移动
244 | if (isFollowMode) {
245 | //防止滑出边界
246 | if (event.getX() >= MARGEN_LINE && event.getX() <= (mWidth - MARGEN_LINE)) {
247 | //LogHelper.d("TAG", "event.getX()=" + event.getX() + "__mWidth=" + mWidth);
248 | bigCircleX = event.getX();
249 | int position = (int) ((event.getX() - MARGEN_LINE) / (distanceX / 2));
250 | //更新当前位置
251 | currentPosition = (position + 1) / 2;
252 | invalidate();
253 | }
254 |
255 | }
256 |
257 | break;
258 | case MotionEvent.ACTION_UP:
259 |
260 | if (isFollowMode) {
261 | float endX = event.getX();
262 | //当前位置距离最近的小白点的距离
263 | float currentDistance = endX - MARGEN_LINE - currentPosition * distanceX;
264 | //拉到最后或者最头
265 | if ((currentPosition == 0 && currentDistance < 0) || (currentPosition == (text4Rates.length - 1) && currentDistance > 0)) {
266 | bigCircleX = currentPosition * distanceX + MARGEN_LINE;
267 | invalidate();
268 | if (null != selectListener) {
269 | selectListener.onSelect(currentPosition);
270 | }
271 | return true;
272 | }
273 |
274 | currentPositionX = bigCircleX;
275 |
276 | valueAnimator = ValueAnimator.ofFloat(currentDistance);
277 | valueAnimator.setInterpolator(new AccelerateInterpolator());
278 | valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
279 | @Override
280 | public void onAnimationUpdate(ValueAnimator animation) {
281 | float slideDistance = (float) animation.getAnimatedValue();
282 | bigCircleX = currentPositionX - slideDistance;
283 | invalidate();
284 | }
285 | });
286 |
287 | valueAnimator.setDuration(100);
288 | valueAnimator.start();
289 | if (null != selectListener) {
290 | selectListener.onSelect(currentPosition);
291 | }
292 | } else {
293 | float endX = event.getX();
294 | //当前位置距离最近的小白点的距离
295 | float currentDistance = endX - MARGEN_LINE - currentPosition * distanceX;
296 |
297 | // 是否点击到小圆,点击误差小于allowDistanErr
298 | float distanceErr = currentDistance % distanceX;
299 | int allowDistanErr = 20; // 允许出错范围
300 | boolean isClickCircle = Math.abs(distanceErr) < allowDistanErr || distanceX - Math.abs(distanceErr) < allowDistanErr;
301 | if (isClickCircle) {
302 | // 计算当前点击的pos位置
303 | int currentDistancePositon = (int) (currentDistance / distanceX);
304 | if (distanceErr > 0 && distanceErr > allowDistanErr) {
305 | currentDistancePositon++;
306 | } else if (distanceErr < 0 && Math.abs(distanceErr) > allowDistanErr) {
307 | currentDistancePositon--;
308 | }
309 |
310 | currentDistance = currentDistancePositon * distanceX;
311 | currentPosition = currentPosition + currentDistancePositon;
312 | currentPositionX = bigCircleX;
313 | bigCircleX = currentPositionX + currentDistance;
314 | invalidate();
315 | if (null != selectListener) {
316 | selectListener.onSelect(currentPosition);
317 | }
318 | }
319 | }
320 |
321 | break;
322 | }
323 |
324 |
325 | return true;
326 | }
327 |
328 | @Override
329 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
330 | super.onSizeChanged(w, h, oldw, oldh);
331 | mHeight = h;
332 | mWidth = w;
333 | //计算每个小圆点的x坐标
334 | circlesX = new float[countOfSmallCircle];
335 | distanceX = (mWidth - MARGEN_LINE * 2) / (countOfSmallCircle - 1);
336 | for (int i = 0; i < countOfSmallCircle; i++) {
337 | circlesX[i] = i * distanceX + MARGEN_LINE;
338 | }
339 |
340 | bigCircleX = circlesX[currentPosition];
341 | }
342 |
343 | @Override
344 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
345 |
346 | int screenSize[] = getScreenSize();
347 |
348 | int resultWidth;
349 | int widthSize = MeasureSpec.getSize(widthMeasureSpec);
350 | int widthMode = MeasureSpec.getMode(widthMeasureSpec);
351 |
352 | if (widthMode == MeasureSpec.EXACTLY) {
353 | resultWidth = widthSize;
354 | } else {
355 | resultWidth = screenSize[0];
356 |
357 | if (widthMode == MeasureSpec.AT_MOST) {
358 | resultWidth = Math.min(widthSize, screenSize[0]);
359 | }
360 | }
361 |
362 | int resultHeight;
363 | int heightSize = MeasureSpec.getSize(heightMeasureSpec);
364 | int heightMode = MeasureSpec.getMode(heightMeasureSpec);
365 |
366 | if (heightMode == MeasureSpec.EXACTLY) {
367 | resultHeight = heightSize;
368 | } else {
369 | resultHeight = (int) (bigCircleRadius * 6);
370 |
371 | if (heightMode == MeasureSpec.AT_MOST) {
372 | resultHeight = Math.min(heightSize, resultHeight);
373 | }
374 | }
375 |
376 | setMeasuredDimension(resultWidth, resultHeight);
377 |
378 | }
379 |
380 | private int[] getScreenSize() {
381 | WindowManager windowManager = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
382 | DisplayMetrics displayMetrics = new DisplayMetrics();
383 | windowManager.getDefaultDisplay().getMetrics(displayMetrics);
384 | return new int[]{displayMetrics.widthPixels, displayMetrics.heightPixels};
385 | }
386 |
387 | public interface onSelectListener {
388 | public void onSelect(int index);
389 | }
390 |
391 | /**
392 | * 上一个
393 | */
394 | public void pre() {
395 | if (currentPosition > 0) {
396 | currentPosition--;
397 | bigCircleX = currentPositionX = bigCircleX - distanceX;
398 | invalidate();
399 | if (null != selectListener) {
400 | selectListener.onSelect(currentPosition);
401 | }
402 | }
403 |
404 | }
405 |
406 | /**
407 | * 下一个
408 | */
409 | public void next() {
410 | if (currentPosition < (text4Rates.length - 1)) {
411 | currentPosition++;
412 | bigCircleX = currentPositionX = bigCircleX + distanceX;
413 | invalidate();
414 | if (null != selectListener) {
415 | selectListener.onSelect(currentPosition);
416 | }
417 | }
418 | }
419 |
420 | //设置当前颜色
421 | public void setCurrentPosition(int currentPosition) {
422 | this.currentPosition = currentPosition;
423 | bigCircleX = currentPositionX = currentPosition * distanceX;
424 | invalidate();
425 | }
426 |
427 |
428 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable/img_haizeiwang.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AICode-Pan/Open-View/df9fedf9dbafdbbf75bb63dd699a57384ac39f27/app/src/main/res/drawable/img_haizeiwang.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ytm_icon_like_png.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AICode-Pan/Open-View/df9fedf9dbafdbbf75bb63dd699a57384ac39f27/app/src/main/res/drawable/ytm_icon_like_png.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ytm_taobao_zan1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AICode-Pan/Open-View/df9fedf9dbafdbbf75bb63dd699a57384ac39f27/app/src/main/res/drawable/ytm_taobao_zan1.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ytm_taobao_zan2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AICode-Pan/Open-View/df9fedf9dbafdbbf75bb63dd699a57384ac39f27/app/src/main/res/drawable/ytm_taobao_zan2.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ytm_taobao_zan3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AICode-Pan/Open-View/df9fedf9dbafdbbf75bb63dd699a57384ac39f27/app/src/main/res/drawable/ytm_taobao_zan3.png
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_blur.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
17 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_indicator.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
10 |
11 |
22 |
23 |
33 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
20 |
21 |
26 |
27 |
32 |
33 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_periscope.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
18 |
19 |
23 |
24 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_slide_select.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
24 |
25 |
42 |
43 |
49 |
50 |
65 |
66 |
75 |
76 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AICode-Pan/Open-View/df9fedf9dbafdbbf75bb63dd699a57384ac39f27/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AICode-Pan/Open-View/df9fedf9dbafdbbf75bb63dd699a57384ac39f27/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AICode-Pan/Open-View/df9fedf9dbafdbbf75bb63dd699a57384ac39f27/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AICode-Pan/Open-View/df9fedf9dbafdbbf75bb63dd699a57384ac39f27/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AICode-Pan/Open-View/df9fedf9dbafdbbf75bb63dd699a57384ac39f27/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values/attr.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 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #00000000
4 | #fff
5 | #000
6 | #3F51B5
7 | #303F9F
8 | #FF4081
9 | #f92a2a
10 | #d8d8d8
11 | #eb535e
12 | #717171
13 | #33ffffff
14 |
15 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 | 1sp
3 | 2sp
4 | 3sp
5 | 4sp
6 | 5sp
7 | 6sp
8 | 7sp
9 | 8sp
10 | 9sp
11 | 10sp
12 | 11sp
13 | 12sp
14 | 13sp
15 | 14sp
16 | 15sp
17 | 16sp
18 | 17sp
19 | 18sp
20 | 19sp
21 | 20sp
22 | 21sp
23 | 22sp
24 | 23sp
25 | 24sp
26 | 25sp
27 | 26sp
28 | 27sp
29 | 28sp
30 | 29sp
31 | 30sp
32 | 31sp
33 | 32sp
34 | 33sp
35 | 34sp
36 | 35sp
37 | 36sp
38 | 37sp
39 | 38sp
40 | 39sp
41 | 40sp
42 |
43 |
44 | 1dp
45 | 2dp
46 | 2.5dp
47 | 3dp
48 | 4dp
49 | 4.5dp
50 | 5dp
51 | 6dp
52 | 7dp
53 | 7.5dp
54 | 8dp
55 | 9dp
56 | 10dp
57 | 11dp
58 | 12dp
59 | 13dp
60 | 14dp
61 | 15dp
62 | 16dp
63 | 17dp
64 | 17.5dp
65 | 18dp
66 | 19dp
67 | 20dp
68 | 20.5dp
69 | 21dp
70 | 22dp
71 | 22.5dp
72 | 23dp
73 | 24dp
74 | 25dp
75 | 26dp
76 | 27dp
77 | 27.5dp
78 | 28dp
79 | 29dp
80 | 30dp
81 | 31dp
82 | 32dp
83 | 33dp
84 | 34dp
85 | 34.5dp
86 | 35dp
87 | 36dp
88 | 37dp
89 | 38dp
90 | 39dp
91 | 39.5dp
92 | 40dp
93 | 41dp
94 | 42dp
95 | 43dp
96 | 44dp
97 | 45dp
98 | 45.5dp
99 | 46dp
100 | 47dp
101 | 48dp
102 | 49dp
103 | 50dp
104 | 51dp
105 | 52dp
106 | 53dp
107 | 54dp
108 | 55dp
109 | 56dp
110 | 57dp
111 | 58dp
112 | 59dp
113 | 60dp
114 | 61dp
115 | 62dp
116 | 63dp
117 | 64dp
118 | 65dp
119 | 66dp
120 | 67dp
121 | 68dp
122 | 69dp
123 | 70dp
124 | 71dp
125 | 72dp
126 | 73dp
127 | 74dp
128 | 74.5dp
129 | 75dp
130 | 76dp
131 | 77dp
132 | 78dp
133 | 79dp
134 | 80dp
135 | 81dp
136 | 82dp
137 | 83dp
138 | 84dp
139 | 85dp
140 | 86dp
141 | 87dp
142 | 88dp
143 | 89dp
144 | 90dp
145 | 91dp
146 | 92dp
147 | 93dp
148 | 94dp
149 | 95dp
150 | 96dp
151 | 97dp
152 | 98dp
153 | 99dp
154 | 100dp
155 | 101dp
156 | 102dp
157 | 103dp
158 | 104dp
159 | 105dp
160 | 106dp
161 | 107dp
162 | 108dp
163 | 109dp
164 | 110dp
165 | 111dp
166 | 112dp
167 | 113dp
168 | 114dp
169 | 114.5dp
170 | 115dp
171 | 116dp
172 | 117dp
173 | 118dp
174 | 119dp
175 | 120dp
176 | 121dp
177 | 122dp
178 | 123dp
179 | 124dp
180 | 125dp
181 | 126dp
182 | 127dp
183 | 128dp
184 | 129dp
185 | 130dp
186 | 135dp
187 | 143dp
188 | 145dp
189 | 149dp
190 | 150dp
191 | 160dp
192 | 162dp
193 | 165dp
194 | 169dp
195 | 170dp
196 | 180dp
197 | 181dp
198 | 192dp
199 | 194dp
200 | 195dp
201 | 200dp
202 | 201dp
203 | 210dp
204 | 216dp
205 | 220dp
206 | 221dp
207 | 235dp
208 | 240dp
209 | 250dp
210 | 260dp
211 | 283dp
212 | 300dp
213 | 345dp
214 | 375dp
215 | 440dp
216 | 514dp
217 | 1200dp
218 |
219 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | 自定义UI
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/test/java/com/ai/code/customview/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.ai.code.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 | ext.kotlin_version = '1.3.72'
5 | repositories {
6 | jcenter()
7 | maven {
8 | url 'https://maven.google.com/'
9 | name 'Google'
10 | }
11 | }
12 | dependencies {
13 | classpath 'com.android.tools.build:gradle:3.6.3'
14 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
15 |
16 | // NOTE: Do not place your application dependencies here; they belong
17 | // in the individual module build.gradle files
18 | }
19 | }
20 |
21 | allprojects {
22 | repositories {
23 | jcenter()
24 | maven {
25 | url 'https://maven.google.com/'
26 | name 'Google'
27 | }
28 | }
29 | }
30 |
31 | task clean(type: Delete) {
32 | delete rootProject.buildDir
33 | }
34 |
--------------------------------------------------------------------------------
/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 | android.injected.testOnly=false
19 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AICode-Pan/Open-View/df9fedf9dbafdbbf75bb63dd699a57384ac39f27/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-5.6.4-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 |
--------------------------------------------------------------------------------
/libs/armeabi-v7a/libijkffmpeg.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AICode-Pan/Open-View/df9fedf9dbafdbbf75bb63dd699a57384ac39f27/libs/armeabi-v7a/libijkffmpeg.so
--------------------------------------------------------------------------------
/libs/armeabi-v7a/libijkplayer.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AICode-Pan/Open-View/df9fedf9dbafdbbf75bb63dd699a57384ac39f27/libs/armeabi-v7a/libijkplayer.so
--------------------------------------------------------------------------------
/libs/armeabi-v7a/libijksdl.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AICode-Pan/Open-View/df9fedf9dbafdbbf75bb63dd699a57384ac39f27/libs/armeabi-v7a/libijksdl.so
--------------------------------------------------------------------------------
/libs/armeabi/libijkffmpeg.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AICode-Pan/Open-View/df9fedf9dbafdbbf75bb63dd699a57384ac39f27/libs/armeabi/libijkffmpeg.so
--------------------------------------------------------------------------------
/libs/armeabi/libijkplayer.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AICode-Pan/Open-View/df9fedf9dbafdbbf75bb63dd699a57384ac39f27/libs/armeabi/libijkplayer.so
--------------------------------------------------------------------------------
/libs/armeabi/libijksdl.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AICode-Pan/Open-View/df9fedf9dbafdbbf75bb63dd699a57384ac39f27/libs/armeabi/libijksdl.so
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------