├── .gitignore
├── LICENSE
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── flyjingfish
│ │ └── highlightview
│ │ ├── MainActivity.java
│ │ ├── MyFragment.java
│ │ └── MyViewpagerActivity.java
│ └── res
│ ├── color
│ └── press.xml
│ ├── drawable-v24
│ └── ic_launcher_foreground.xml
│ ├── drawable
│ └── ic_launcher_background.xml
│ ├── layout
│ ├── activity_main.xml
│ ├── activity_my_viewpager.xml
│ └── item_anim.xml
│ ├── mipmap-anydpi-v26
│ ├── ic_launcher.xml
│ └── ic_launcher_round.xml
│ ├── mipmap-hdpi
│ ├── ic_launcher.webp
│ └── ic_launcher_round.webp
│ ├── mipmap-mdpi
│ ├── ic_launcher.webp
│ └── ic_launcher_round.webp
│ ├── mipmap-xhdpi
│ ├── ic_launcher.webp
│ └── ic_launcher_round.webp
│ ├── mipmap-xxhdpi
│ ├── camera.png
│ ├── camera2.png
│ ├── e_bank.png
│ ├── ic_launcher.webp
│ └── ic_launcher_round.webp
│ ├── mipmap-xxxhdpi
│ ├── ic_launcher.webp
│ └── ic_launcher_round.webp
│ ├── values-night
│ └── themes.xml
│ └── values
│ ├── colors.xml
│ ├── strings.xml
│ └── themes.xml
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── library
├── build.gradle
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── flyjingfish
│ │ └── highlightviewlib
│ │ ├── AnimHolder.java
│ │ ├── EnsureFragmentX.java
│ │ ├── HighlightAnimHolder.java
│ │ ├── HighlightDraw.java
│ │ ├── HighlightDrawView.java
│ │ ├── HighlightFrameLayout.java
│ │ ├── HighlightImageView.java
│ │ ├── HighlightLinearLayout.java
│ │ ├── HighlightRelativeLayout.java
│ │ ├── HighlightTextView.java
│ │ ├── HighlightView.java
│ │ └── InitAttrs.java
│ └── res
│ └── values
│ └── values.xml
├── screenshot
└── screenrecording-20221109-134351.gif
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/caches
5 | /.idea/libraries
6 | /.idea/modules.xml
7 | /.idea/workspace.xml
8 | /.idea/navEditor.xml
9 | /.idea/assetWizardSettings.xml
10 | .DS_Store
11 | /build
12 | /captures
13 | .externalNativeBuild
14 | .cxx
15 | local.properties
16 |
17 | # Project exclude paths
18 | /library/build/
19 | /library/build/intermediates/javac/debug/classes/
20 |
21 | build/
22 | .idea
23 | androidTest/
24 | test/
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [2022] [FlyJingFish]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # HighlightView
2 | [](https://jitpack.io/#FlyJingFish/HighlightView)
3 | [](https://github.com/FlyJingFish/HighlightView/stargazers)
4 | [](https://github.com/FlyJingFish/HighlightView/network)
5 | [](https://github.com/FlyJingFish/HighlightView/issues)
6 | [](https://github.com/FlyJingFish/HighlightView/blob/master/LICENSE)
7 |
8 | ## 支持高亮灯光移动效果的 TextView、ImageView、FrameLayout、LinearLayout、RelativeLayout
9 |
10 |
11 |
12 |
13 | ## 第一步,根目录build.gradle
14 |
15 | ```gradle
16 | allprojects {
17 | repositories {
18 | ...
19 | maven { url 'https://jitpack.io' }
20 | }
21 | }
22 | ```
23 | ## 第二步,需要引用的build.gradle (最新版本[](https://jitpack.io/#FlyJingFish/HighlightView))
24 |
25 | ```gradle
26 | dependencies {
27 | implementation 'com.github.FlyJingFish:HighlightView:1.2.1'
28 | }
29 | ```
30 | ## 第三步,使用说明
31 |
32 | **设置 HighlightTextView 示例**
33 |
34 | ```xml
35 |
53 | ```
54 |
55 | **设置 HighlightImageView 示例**
56 |
57 | ```xml
58 |
59 |
74 | ```
75 |
76 | **设置 ViewGroup 示例**
77 |
78 | ```xml
79 |
80 |
94 |
100 |
108 |
109 |
110 | ```
111 |
112 | ### 属性一览
113 |
114 | | attr | format | description |
115 | |---------------------------------------|:---------------:|:---------------------------------------------------------------------------:|
116 | | highlight_view_highlightColor | reference/color | 高亮中心区域颜色 |
117 | | highlight_view_highlightWidth | dimension | 高亮区域宽度 |
118 | | highlight_view_highlightRotateDegrees | float | 高亮区域旋转角度 |
119 | | highlight_view_startDirection | enum | 高亮动画开始位置(from_left 从左边开始/from_top 从上边开始/from_right 从右边开始/from_bottom 从下边开始) |
120 | | highlight_view_repeatCount | integer | 动画循环次数 |
121 | | highlight_view_repeatMode | enum | 动画循环模式(restart 动画结束后从开始位置循环下一次/reverse 动画结束后从结束位置循环下一次) |
122 | | highlight_view_duration | integer | 动画循环一次的时间 |
123 | | highlight_view_autoStart | boolean | 开始显示控件时,是否自动开始高亮动画 |
124 |
125 | ### HighlightAnimHolder 部分方法介绍(更多方法自行探索吧~~)
126 |
127 | | attr | description |
128 | |-----------------------|:-------------------:|
129 | | startHighlightEffect | 开始动画(动画相关参数设置后在此起效) |
130 | | stopHighlightEffect | 结束动画 |
131 | | resumeHighlightEffect | 继续动画 |
132 | | pauseHighlightEffect | 暂停动画 |
133 | | isPaused | 是否暂停动画 |
134 | | setInterpolator | 设置插值器 |
135 |
136 | **例如**
137 |
138 | ```java
139 |
140 | highlightTextView.getHighlightAnimHolder().stopHighlightEffect()
141 |
142 | ```
143 |
144 |
145 |
146 | ## 最后推荐我写的另外一些库
147 |
148 | - [OpenImage 轻松实现在应用内点击小图查看大图的动画放大效果](https://github.com/FlyJingFish/OpenImage)
149 |
150 | - [AndroidAOP 一个注解就可请求权限,禁止多点,切换线程等等,更可定制出属于你的 Aop 代码](https://github.com/FlyJingFish/AndroidAOP)
151 |
152 | - [主页查看更多开源库](https://github.com/FlyJingFish)
153 |
154 |
155 |
156 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'com.android.application'
3 | }
4 |
5 | android {
6 | compileSdkVersion rootProject.ext.sdkVersion
7 |
8 | defaultConfig {
9 | applicationId "com.flyjingfish.highlightview"
10 | minSdkVersion 21
11 | targetSdkVersion rootProject.ext.sdkVersion
12 | versionCode 1
13 | versionName "1.0"
14 |
15 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
16 | }
17 | buildFeatures {
18 | viewBinding true
19 | }
20 |
21 | buildTypes {
22 | release {
23 | minifyEnabled false
24 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
25 | }
26 | }
27 | compileOptions {
28 | sourceCompatibility JavaVersion.VERSION_1_8
29 | targetCompatibility JavaVersion.VERSION_1_8
30 | }
31 | }
32 | dependencies {
33 |
34 | implementation 'androidx.appcompat:appcompat:1.3.1'
35 | implementation 'com.google.android.material:material:1.3.0'
36 | implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
37 | implementation project(path: ':library')
38 | testImplementation 'junit:junit:4.+'
39 | androidTestImplementation 'androidx.test.ext:junit:1.1.3'
40 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
41 |
42 | }
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/app/src/main/java/com/flyjingfish/highlightview/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.flyjingfish.highlightview;
2 |
3 | import androidx.annotation.NonNull;
4 | import androidx.appcompat.app.AppCompatActivity;
5 | import androidx.fragment.app.Fragment;
6 | import androidx.lifecycle.LifecycleOwner;
7 | import androidx.recyclerview.widget.LinearLayoutManager;
8 | import androidx.recyclerview.widget.RecyclerView;
9 |
10 | import android.os.Bundle;
11 | import android.view.LayoutInflater;
12 | import android.view.View;
13 | import android.view.ViewGroup;
14 | import android.widget.LinearLayout;
15 |
16 | import com.flyjingfish.highlightviewlib.HighlightImageView;
17 | import com.flyjingfish.highlightviewlib.HighlightLinearLayout;
18 | import com.flyjingfish.highlightviewlib.HighlightTextView;
19 |
20 | public class MainActivity extends AppCompatActivity {
21 |
22 | @Override
23 | protected void onCreate(Bundle savedInstanceState) {
24 | super.onCreate(savedInstanceState);
25 | setContentView(R.layout.activity_main);
26 |
27 | // RecyclerView recyclerView = findViewById(R.id.recyclerView);
28 | LinearLayout llRoot = findViewById(R.id.ll_root);
29 | HighlightImageView highlightImageView = findViewById(R.id.highlightImageView);
30 | HighlightTextView highlightTextView = findViewById(R.id.highlightTextView);
31 | HighlightLinearLayout highlightLinearLayout = findViewById(R.id.highlightLinearLayout);
32 | highlightTextView.setOnClickListener(v -> highlightTextView.getHighlightAnimHolder().stopHighlightEffect());
33 |
34 | highlightLinearLayout.setOnClickListener(new View.OnClickListener() {
35 | @Override
36 | public void onClick(View v) {
37 | // if (highlightLinearLayout.getHighlightAnimHolder().isPaused()){
38 | // highlightLinearLayout.getHighlightAnimHolder().resumeHighlightEffect();
39 | // }else {
40 | // highlightLinearLayout.getHighlightAnimHolder().pauseHighlightEffect();
41 | // }
42 | }
43 | });
44 | highlightImageView.setOnClickListener(new View.OnClickListener() {
45 | boolean isRemove;
46 | @Override
47 | public void onClick(View v) {
48 | // if (highlightImageView.getHighlightAnimHolder().isPaused()){
49 | // highlightImageView.getHighlightAnimHolder().resumeHighlightEffect();
50 | // }else {
51 | // highlightImageView.getHighlightAnimHolder().pauseHighlightEffect();
52 | // }
53 | if (isRemove){
54 | llRoot.addView(highlightLinearLayout);
55 | }else {
56 | llRoot.removeView(highlightLinearLayout);
57 | }
58 | isRemove = !isRemove;
59 | }
60 | });
61 | // R.id.view_tree_lifecycle_owner;
62 | // highlightImageView.getTag()
63 | highlightTextView.getHighlightAnimHolder().addLifecycleObserver(this);
64 | highlightLinearLayout.getHighlightAnimHolder().addLifecycleObserver(this);
65 | // highlightTextView.getHighlightAnimHolder().setHighlightColor(Color.BLUE);
66 | // highlightTextView.getHighlightAnimHolder().setHighlightWidth(90);
67 | // highlightTextView.getHighlightAnimHolder().setDuration(2000);
68 | // highlightTextView.getHighlightAnimHolder().setHighlightRotateDegrees(60);
69 | // highlightTextView.getHighlightAnimHolder().setRepeatMode(HighlightAnimHolder.REVERSE);
70 | // highlightTextView.getHighlightAnimHolder().setRepeatCount(4);
71 | // highlightTextView.getHighlightAnimHolder().setStartDirection(HighlightAnimHolder.FROM_RIGHT);
72 | // highlightTextView.getHighlightAnimHolder().startHighlightEffect();
73 |
74 | // recyclerView.setLayoutManager(new LinearLayoutManager(this));
75 | // recyclerView.setAdapter(new ItemAnimAdapter());
76 | }
77 |
78 | private static class ItemAnimAdapter extends RecyclerView.Adapter {
79 |
80 | @NonNull
81 | @Override
82 | public ItemAnimHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
83 | return new ItemAnimHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_anim,parent,false));
84 | }
85 |
86 | @Override
87 | public void onBindViewHolder(@NonNull ItemAnimHolder holder, int position) {
88 | HighlightLinearLayout highlightLinearLayout = holder.itemView.findViewById(R.id.highlightLinearLayout);
89 | highlightLinearLayout.getHighlightAnimHolder().addLifecycleObserver((LifecycleOwner) holder.itemView.getContext());
90 | }
91 |
92 | @Override
93 | public int getItemCount() {
94 | return 100;
95 | }
96 |
97 | private static class ItemAnimHolder extends RecyclerView.ViewHolder {
98 |
99 | public ItemAnimHolder(@NonNull View itemView) {
100 | super(itemView);
101 | }
102 | }
103 |
104 | }
105 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/flyjingfish/highlightview/MyFragment.java:
--------------------------------------------------------------------------------
1 | package com.flyjingfish.highlightview;
2 |
3 | import android.os.Bundle;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 |
8 | import androidx.annotation.NonNull;
9 | import androidx.annotation.Nullable;
10 | import androidx.fragment.app.Fragment;
11 |
12 | public class MyFragment extends Fragment {
13 | public MyFragment(int contentLayoutId) {
14 | super(contentLayoutId);
15 | }
16 |
17 | @Nullable
18 | @Override
19 | public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
20 | return super.onCreateView(inflater, container, savedInstanceState);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/app/src/main/java/com/flyjingfish/highlightview/MyViewpagerActivity.java:
--------------------------------------------------------------------------------
1 | package com.flyjingfish.highlightview;
2 |
3 | import android.os.Bundle;
4 |
5 | import androidx.annotation.NonNull;
6 | import androidx.annotation.Nullable;
7 | import androidx.appcompat.app.AppCompatActivity;
8 | import androidx.fragment.app.Fragment;
9 | import androidx.viewpager2.adapter.FragmentStateAdapter;
10 | import androidx.viewpager2.widget.ViewPager2;
11 |
12 | public class MyViewpagerActivity extends AppCompatActivity {
13 | @Override
14 | protected void onCreate(@Nullable Bundle savedInstanceState) {
15 | super.onCreate(savedInstanceState);
16 | setContentView(R.layout.activity_my_viewpager);
17 | ViewPager2 viewpager = findViewById(R.id.viewpager);
18 | viewpager.setAdapter(new FragmentStateAdapter(this) {
19 | @NonNull
20 | @Override
21 | public Fragment createFragment(int position) {
22 | return new MyFragment(R.layout.item_anim);
23 | }
24 |
25 | @Override
26 | public int getItemCount() {
27 | return 10;
28 | }
29 | });
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/app/src/main/res/color/press.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
15 |
18 |
21 |
22 |
23 |
24 |
30 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
31 |
32 |
33 |
48 |
49 |
50 |
65 |
71 |
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 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_my_viewpager.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_anim.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
23 |
29 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FlyJingFish/HighlightView/b63d587f4dde8280c34d3242b509d52d272d9555/app/src/main/res/mipmap-hdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FlyJingFish/HighlightView/b63d587f4dde8280c34d3242b509d52d272d9555/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FlyJingFish/HighlightView/b63d587f4dde8280c34d3242b509d52d272d9555/app/src/main/res/mipmap-mdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FlyJingFish/HighlightView/b63d587f4dde8280c34d3242b509d52d272d9555/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FlyJingFish/HighlightView/b63d587f4dde8280c34d3242b509d52d272d9555/app/src/main/res/mipmap-xhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FlyJingFish/HighlightView/b63d587f4dde8280c34d3242b509d52d272d9555/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/camera.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FlyJingFish/HighlightView/b63d587f4dde8280c34d3242b509d52d272d9555/app/src/main/res/mipmap-xxhdpi/camera.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/camera2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FlyJingFish/HighlightView/b63d587f4dde8280c34d3242b509d52d272d9555/app/src/main/res/mipmap-xxhdpi/camera2.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/e_bank.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FlyJingFish/HighlightView/b63d587f4dde8280c34d3242b509d52d272d9555/app/src/main/res/mipmap-xxhdpi/e_bank.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FlyJingFish/HighlightView/b63d587f4dde8280c34d3242b509d52d272d9555/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FlyJingFish/HighlightView/b63d587f4dde8280c34d3242b509d52d272d9555/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FlyJingFish/HighlightView/b63d587f4dde8280c34d3242b509d52d272d9555/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FlyJingFish/HighlightView/b63d587f4dde8280c34d3242b509d52d272d9555/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/values-night/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FFBB86FC
4 | #FF6200EE
5 | #FF3700B3
6 | #FF03DAC5
7 | #FF018786
8 | #FF000000
9 | #FFFFFFFF
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | HighlightView
3 |
--------------------------------------------------------------------------------
/app/src/main/res/values/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
16 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 | buildscript {
3 | repositories {
4 | google()
5 | maven { url 'https://jitpack.io' }
6 | mavenCentral()
7 | }
8 | dependencies {
9 | classpath 'com.android.tools.build:gradle:4.0.1'
10 |
11 | // NOTE: Do not place your application dependencies here; they belong
12 | // in the individual module build.gradle files
13 | }
14 | }
15 | allprojects {
16 | repositories {
17 | google()
18 | maven { url 'https://jitpack.io' }
19 | mavenCentral()
20 | }
21 | }
22 | task clean(type: Delete) {
23 | delete rootProject.buildDir
24 | }
25 |
26 | ext {
27 | sdkVersion = 30
28 | minSdkVersion = 19
29 | }
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app's APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Enables namespacing of each library's R class so that its R class includes only the
19 | # resources declared in the library itself and none from the library's dependencies,
20 | # thereby reducing the size of the R class for that library
21 | android.nonTransitiveRClass=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FlyJingFish/HighlightView/b63d587f4dde8280c34d3242b509d52d272d9555/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Oct 11 11:29:56 CST 2022
2 | distributionBase=GRADLE_USER_HOME
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
4 | distributionPath=wrapper/dists
5 | zipStorePath=wrapper/dists
6 | zipStoreBase=GRADLE_USER_HOME
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | #
4 | # Copyright 2015 the original author or authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | ##############################################################################
20 | ##
21 | ## Gradle start up script for UN*X
22 | ##
23 | ##############################################################################
24 |
25 | # Attempt to set APP_HOME
26 | # Resolve links: $0 may be a link
27 | PRG="$0"
28 | # Need this for relative symlinks.
29 | while [ -h "$PRG" ] ; do
30 | ls=`ls -ld "$PRG"`
31 | link=`expr "$ls" : '.*-> \(.*\)$'`
32 | if expr "$link" : '/.*' > /dev/null; then
33 | PRG="$link"
34 | else
35 | PRG=`dirname "$PRG"`"/$link"
36 | fi
37 | done
38 | SAVED="`pwd`"
39 | cd "`dirname \"$PRG\"`/" >/dev/null
40 | APP_HOME="`pwd -P`"
41 | cd "$SAVED" >/dev/null
42 |
43 | APP_NAME="Gradle"
44 | APP_BASE_NAME=`basename "$0"`
45 |
46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
48 |
49 | # Use the maximum available, or set MAX_FD != -1 to use that value.
50 | MAX_FD="maximum"
51 |
52 | warn () {
53 | echo "$*"
54 | }
55 |
56 | die () {
57 | echo
58 | echo "$*"
59 | echo
60 | exit 1
61 | }
62 |
63 | # OS specific support (must be 'true' or 'false').
64 | cygwin=false
65 | msys=false
66 | darwin=false
67 | nonstop=false
68 | case "`uname`" in
69 | CYGWIN* )
70 | cygwin=true
71 | ;;
72 | Darwin* )
73 | darwin=true
74 | ;;
75 | MINGW* )
76 | msys=true
77 | ;;
78 | NONSTOP* )
79 | nonstop=true
80 | ;;
81 | esac
82 |
83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
84 |
85 |
86 | # Determine the Java command to use to start the JVM.
87 | if [ -n "$JAVA_HOME" ] ; then
88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
89 | # IBM's JDK on AIX uses strange locations for the executables
90 | JAVACMD="$JAVA_HOME/jre/sh/java"
91 | else
92 | JAVACMD="$JAVA_HOME/bin/java"
93 | fi
94 | if [ ! -x "$JAVACMD" ] ; then
95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
96 |
97 | Please set the JAVA_HOME variable in your environment to match the
98 | location of your Java installation."
99 | fi
100 | else
101 | JAVACMD="java"
102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
103 |
104 | Please set the JAVA_HOME variable in your environment to match the
105 | location of your Java installation."
106 | fi
107 |
108 | # Increase the maximum file descriptors if we can.
109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
110 | MAX_FD_LIMIT=`ulimit -H -n`
111 | if [ $? -eq 0 ] ; then
112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
113 | MAX_FD="$MAX_FD_LIMIT"
114 | fi
115 | ulimit -n $MAX_FD
116 | if [ $? -ne 0 ] ; then
117 | warn "Could not set maximum file descriptor limit: $MAX_FD"
118 | fi
119 | else
120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
121 | fi
122 | fi
123 |
124 | # For Darwin, add options to specify how the application appears in the dock
125 | if $darwin; then
126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
127 | fi
128 |
129 | # For Cygwin or MSYS, switch paths to Windows format before running java
130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
133 |
134 | JAVACMD=`cygpath --unix "$JAVACMD"`
135 |
136 | # We build the pattern for arguments to be converted via cygpath
137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
138 | SEP=""
139 | for dir in $ROOTDIRSRAW ; do
140 | ROOTDIRS="$ROOTDIRS$SEP$dir"
141 | SEP="|"
142 | done
143 | OURCYGPATTERN="(^($ROOTDIRS))"
144 | # Add a user-defined pattern to the cygpath arguments
145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
147 | fi
148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
149 | i=0
150 | for arg in "$@" ; do
151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
153 |
154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
156 | else
157 | eval `echo args$i`="\"$arg\""
158 | fi
159 | i=`expr $i + 1`
160 | done
161 | case $i in
162 | 0) set -- ;;
163 | 1) set -- "$args0" ;;
164 | 2) set -- "$args0" "$args1" ;;
165 | 3) set -- "$args0" "$args1" "$args2" ;;
166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;;
167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
172 | esac
173 | fi
174 |
175 | # Escape application args
176 | save () {
177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
178 | echo " "
179 | }
180 | APP_ARGS=`save "$@"`
181 |
182 | # Collect all arguments for the java command, following the shell quoting and substitution rules
183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
184 |
185 | exec "$JAVACMD" "$@"
186 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%" == "" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%" == "" set DIRNAME=.
29 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34 |
35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
37 |
38 | @rem Find java.exe
39 | if defined JAVA_HOME goto findJavaFromJavaHome
40 |
41 | set JAVA_EXE=java.exe
42 | %JAVA_EXE% -version >NUL 2>&1
43 | if "%ERRORLEVEL%" == "0" goto execute
44 |
45 | echo.
46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
47 | echo.
48 | echo Please set the JAVA_HOME variable in your environment to match the
49 | echo location of your Java installation.
50 |
51 | goto fail
52 |
53 | :findJavaFromJavaHome
54 | set JAVA_HOME=%JAVA_HOME:"=%
55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
56 |
57 | if exist "%JAVA_EXE%" goto execute
58 |
59 | echo.
60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
61 | echo.
62 | echo Please set the JAVA_HOME variable in your environment to match the
63 | echo location of your Java installation.
64 |
65 | goto fail
66 |
67 | :execute
68 | @rem Setup the command line
69 |
70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
71 |
72 |
73 | @rem Execute Gradle
74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
75 |
76 | :end
77 | @rem End local scope for the variables with windows NT shell
78 | if "%ERRORLEVEL%"=="0" goto mainEnd
79 |
80 | :fail
81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
82 | rem the _cmd.exe /c_ return code!
83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84 | exit /b 1
85 |
86 | :mainEnd
87 | if "%OS%"=="Windows_NT" endlocal
88 |
89 | :omega
90 |
--------------------------------------------------------------------------------
/library/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | android {
3 | compileSdkVersion rootProject.ext.sdkVersion
4 |
5 | defaultConfig {
6 | minSdkVersion rootProject.ext.minSdkVersion
7 | targetSdkVersion rootProject.ext.sdkVersion
8 | }
9 | }
10 |
11 | dependencies {
12 | implementation 'androidx.appcompat:appcompat:1.3.1'
13 | }
--------------------------------------------------------------------------------
/library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
--------------------------------------------------------------------------------
/library/src/main/java/com/flyjingfish/highlightviewlib/AnimHolder.java:
--------------------------------------------------------------------------------
1 | package com.flyjingfish.highlightviewlib;
2 |
3 | interface AnimHolder {
4 | HighlightAnimHolder getHighlightAnimHolder();
5 | }
6 |
--------------------------------------------------------------------------------
/library/src/main/java/com/flyjingfish/highlightviewlib/EnsureFragmentX.java:
--------------------------------------------------------------------------------
1 | package com.flyjingfish.highlightviewlib;
2 |
3 | import androidx.lifecycle.LifecycleOwner;
4 |
5 | class EnsureFragmentX{
6 | LifecycleOwner lifecycleOwner;
7 | boolean isInFragmentX;
8 |
9 | public EnsureFragmentX(LifecycleOwner lifecycleOwner, boolean isInFragmentX) {
10 | this.lifecycleOwner = lifecycleOwner;
11 | this.isInFragmentX = isInFragmentX;
12 | }
13 |
14 | @Override
15 | public String toString() {
16 | return "EnsureFragmentX{" +
17 | "lifecycleOwner=" + lifecycleOwner +
18 | ", isInFragmentX=" + isInFragmentX +
19 | '}';
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/library/src/main/java/com/flyjingfish/highlightviewlib/HighlightAnimHolder.java:
--------------------------------------------------------------------------------
1 | package com.flyjingfish.highlightviewlib;
2 |
3 | import android.animation.Animator;
4 | import android.animation.ObjectAnimator;
5 | import android.animation.TimeInterpolator;
6 | import android.animation.ValueAnimator;
7 | import android.content.Context;
8 | import android.content.res.ColorStateList;
9 | import android.util.Log;
10 | import android.view.View;
11 | import android.view.animation.DecelerateInterpolator;
12 |
13 | import androidx.annotation.ColorInt;
14 | import androidx.annotation.IntDef;
15 | import androidx.annotation.NonNull;
16 | import androidx.fragment.app.Fragment;
17 | import androidx.lifecycle.Lifecycle;
18 | import androidx.lifecycle.LifecycleEventObserver;
19 | import androidx.lifecycle.LifecycleOwner;
20 |
21 | import java.lang.annotation.Retention;
22 | import java.lang.annotation.RetentionPolicy;
23 |
24 | public class HighlightAnimHolder {
25 | public static final int INFINITE = ValueAnimator.INFINITE;
26 | public static final int RESTART = ValueAnimator.RESTART;
27 | public static final int REVERSE = ValueAnimator.REVERSE;
28 | public static final int FROM_LEFT = 1;
29 | public static final int FROM_RIGHT = 2;
30 | public static final int FROM_TOP = 3;
31 | public static final int FROM_BOTTOM = 4;
32 | private final HighlightDrawView mHighlightDrawView;
33 | private final HighlightView mHighlightView;
34 | private int mRepeatCount = 0;
35 | private int mRepeatMode = ValueAnimator.RESTART;
36 | private TimeInterpolator mInterpolator = new DecelerateInterpolator();
37 | private long mDuration;
38 | private ObjectAnimator mHighlightEffectAnim;
39 | private boolean isFinishLayout;
40 | private boolean isStartBeforeLayout;
41 |
42 | private float mHighlightRotateDegrees = 0;
43 |
44 | public HighlightAnimHolder(final HighlightDrawView highlightDrawView, final HighlightView highlightView) {
45 | this.mHighlightDrawView = highlightDrawView;
46 | this.mHighlightView = highlightView;
47 | if (highlightView.thisView() != null) {
48 | highlightView.thisView().addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() {
49 | @Override
50 | public void onViewAttachedToWindow(View v) {
51 | if (mHighlightEffectAnim != null && !mHighlightEffectAnim.isStarted()){
52 | mHighlightEffectAnim.start();
53 | }
54 | }
55 |
56 | @Override
57 | public void onViewDetachedFromWindow(View v) {
58 | if (mHighlightEffectAnim != null){
59 | mHighlightEffectAnim.removeAllListeners();
60 | mHighlightEffectAnim.cancel();
61 | }
62 | }
63 | });
64 |
65 | highlightView.thisView().addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() {
66 | @Override
67 | public void onViewAttachedToWindow(View v) {
68 | highlightView.thisView().removeOnAttachStateChangeListener(this);
69 | EnsureFragmentX ensureFragmentX = InitAttrs.ensureInFragmentX(highlightView.thisView());
70 | if (ensureFragmentX.isInFragmentX){
71 | addObserver(ensureFragmentX.lifecycleOwner);
72 | }else if (highlightView.thisView().getContext() instanceof LifecycleOwner){
73 | addObserver((LifecycleOwner) highlightView.thisView().getContext());
74 | }
75 | }
76 |
77 | @Override
78 | public void onViewDetachedFromWindow(View v) {
79 | highlightView.thisView().removeOnAttachStateChangeListener(this);
80 | }
81 | });
82 | }
83 | }
84 |
85 | @IntDef({RESTART, REVERSE})
86 | @Retention(RetentionPolicy.SOURCE)
87 | public @interface RepeatMode {
88 | }
89 |
90 | @IntDef({FROM_LEFT, FROM_RIGHT, FROM_TOP, FROM_BOTTOM})
91 | @Retention(RetentionPolicy.SOURCE)
92 | public @interface StartDirection {
93 | }
94 |
95 | /**
96 | * 此方法已被弃用,不用调用也可以,内部已经调用过了
97 | * @param owner
98 | */
99 | @Deprecated
100 | public void addLifecycleObserver(LifecycleOwner owner) {
101 | addObserver(owner);
102 | }
103 |
104 | private void addObserver(LifecycleOwner owner) {
105 | if (owner != null) {
106 | if (owner instanceof Fragment){
107 | owner = ((Fragment) owner).getViewLifecycleOwner();
108 | }
109 | owner.getLifecycle().removeObserver(mLifecycleEventObserver);
110 | owner.getLifecycle().addObserver(mLifecycleEventObserver);
111 | }
112 | }
113 |
114 | private final LifecycleEventObserver mLifecycleEventObserver = new LifecycleEventObserver() {
115 | @Override
116 | public void onStateChanged(@NonNull LifecycleOwner source, @NonNull Lifecycle.Event event) {
117 | if (mHighlightEffectAnim == null) {
118 | return;
119 | }
120 | if (event == Lifecycle.Event.ON_START && mHighlightEffectAnim.isPaused()) {
121 | mHighlightEffectAnim.resume();
122 | } else if (event == Lifecycle.Event.ON_STOP && mHighlightEffectAnim.isRunning()) {
123 | mHighlightEffectAnim.pause();
124 | }else if (event == Lifecycle.Event.ON_DESTROY) {
125 | mHighlightEffectAnim.cancel();
126 | }
127 | }
128 | };
129 |
130 | private int getWidth() {
131 | return mHighlightView.thisView().getWidth();
132 | }
133 |
134 | private int getHeight() {
135 | return mHighlightView.thisView().getHeight();
136 | }
137 |
138 | public float getStartHighlightOffset() {
139 | return mHighlightDrawView.getHighlightDraw().setStartHighlightOffset();
140 | }
141 |
142 | /**
143 | * 这个可以设置高亮部分位移量,如果动画在运动中不建议调用这个方法
144 | * @param startHighlightOffset 高亮部分位移量
145 | */
146 | public void setStartHighlightOffset(float startHighlightOffset) {
147 | mHighlightDrawView.getHighlightDraw().setStartHighlightOffset(startHighlightOffset);
148 | mHighlightView.thisView().invalidate();
149 | }
150 |
151 | public void startHighlightEffect() {
152 | if (isFinishLayout) {
153 | startAnim();
154 | } else {
155 | isStartBeforeLayout = true;
156 | }
157 | }
158 |
159 | public void stopHighlightEffect() {
160 | if (mHighlightEffectAnim != null) {
161 | mHighlightEffectAnim.removeAllListeners();
162 | mHighlightEffectAnim.cancel();
163 |
164 | float[] location = getStartEndLocation();
165 | setStartHighlightOffset(location[0]);
166 | }
167 | isStartBeforeLayout = false;
168 | }
169 |
170 | public void resumeHighlightEffect() {
171 | if (mHighlightEffectAnim != null) {
172 | mHighlightEffectAnim.resume();
173 | } else {
174 | startHighlightEffect();
175 | }
176 | }
177 |
178 | public void pauseHighlightEffect() {
179 | if (mHighlightEffectAnim != null) {
180 | mHighlightEffectAnim.pause();
181 | }
182 | }
183 |
184 | public boolean isPaused() {
185 | if (mHighlightEffectAnim != null) {
186 | return mHighlightEffectAnim.isPaused();
187 | }
188 | return true;
189 | }
190 |
191 | public void addListener(Animator.AnimatorListener listener) {
192 | if (mHighlightEffectAnim != null){
193 | mHighlightEffectAnim.addListener(listener);
194 | }
195 | }
196 |
197 | public void addUpdateListener(ValueAnimator.AnimatorUpdateListener listener) {
198 | if (mHighlightEffectAnim != null){
199 | mHighlightEffectAnim.addUpdateListener(listener);
200 | }
201 | }
202 |
203 | public void addPauseListener(Animator.AnimatorPauseListener listener) {
204 | if (mHighlightEffectAnim != null){
205 | mHighlightEffectAnim.addPauseListener(listener);
206 | }
207 | }
208 |
209 | protected void startAnim() {
210 | if (mHighlightEffectAnim == null) {
211 | int viewWidth = getWidth();
212 | mHighlightEffectAnim = ObjectAnimator.ofFloat(this, "startHighlightOffset", -getHighlightWidth(), viewWidth + getHighlightWidth());
213 | } else {
214 | mHighlightEffectAnim.cancel();
215 | }
216 | mHighlightEffectAnim.setFloatValues(getStartEndLocation());
217 | mHighlightEffectAnim.setDuration(mDuration);
218 | mHighlightEffectAnim.setInterpolator(mInterpolator);
219 | mHighlightEffectAnim.setRepeatCount(mRepeatCount);
220 | mHighlightEffectAnim.setRepeatMode(mRepeatMode);
221 | mHighlightEffectAnim.start();
222 | }
223 |
224 | private float[] getStartEndLocation() {
225 | int viewWidth = getWidth();
226 | int viewHeight = getHeight();
227 | float[] location;
228 | float offset = getStartOffset();
229 | if (getStartDirection() == FROM_RIGHT) {
230 | location = new float[]{viewWidth + offset, -(offset + getHighlightWidth())};
231 | } else if (getStartDirection() == FROM_TOP) {
232 | location = new float[]{-(offset + getHighlightWidth()), viewHeight + offset};
233 | } else if (getStartDirection() == FROM_BOTTOM) {
234 | location = new float[]{viewHeight + offset, -(offset + getHighlightWidth())};
235 | } else {
236 | location = new float[]{-(offset + getHighlightWidth()), viewWidth + offset};
237 | }
238 | return location;
239 | }
240 |
241 | private float getStartOffset() {
242 | int viewWidth = getWidth();
243 | int viewHeight = getHeight();
244 | double offset;
245 | if (getStartDirection() == FROM_RIGHT || getStartDirection() == FROM_LEFT) {
246 | double value1 = tan() * viewWidth / 2;
247 | if (value1 < viewHeight / 2f) {
248 | offset = (viewHeight / 2d - value1) * sin() + viewWidth / 2d / cos() - viewWidth / 2d;
249 | } else {
250 | offset = ((value1 - viewHeight / 2d) / tan()) * cos() + (viewHeight / 2d / sin()) - viewWidth / 2d;
251 | }
252 | } else {
253 | double value1 = tan() * viewHeight / 2;
254 | if (value1 < viewWidth / 2f) {
255 | offset = (viewWidth / 2d - value1) * sin() + viewHeight / 2d / cos() - viewHeight / 2d;
256 | } else {
257 | offset = ((value1 - viewWidth / 2d) / tan()) * cos() + (viewWidth / 2d / sin()) - viewHeight / 2d;
258 | }
259 |
260 | }
261 | return (float) offset;
262 | }
263 |
264 | private double tan() {
265 | double radians = Math.toRadians(Math.abs(mHighlightRotateDegrees));
266 | return Math.tan(radians);
267 | }
268 |
269 | private double sin() {
270 | double radians = Math.toRadians(Math.abs(mHighlightRotateDegrees));
271 | return Math.sin(radians);
272 | }
273 |
274 | private double cos() {
275 | double radians = Math.toRadians(Math.abs(mHighlightRotateDegrees));
276 | return Math.cos(radians);
277 | }
278 |
279 | public float getHighlightRotateDegrees() {
280 | return mHighlightDrawView.getHighlightDraw().getHighlightRotateDegrees();
281 | }
282 |
283 | public void setHighlightRotateDegrees(float rotateDegrees) {
284 | mHighlightRotateDegrees = rotateDegrees;
285 | mHighlightDrawView.getHighlightDraw().setHighlightRotateDegrees(rotateDegrees);
286 | mHighlightView.thisView().invalidate();
287 | }
288 |
289 | public float getHighlightWidth() {
290 | return mHighlightDrawView.getHighlightDraw().getHighlightWidth();
291 | }
292 |
293 | public void setHighlightWidth(float highlightWidth) {
294 | mHighlightDrawView.getHighlightDraw().setHighlightWidth(highlightWidth);
295 | mHighlightView.thisView().invalidate();
296 | }
297 |
298 |
299 | public void setDuration(long duration) {
300 | mDuration = duration;
301 | }
302 |
303 | public long getDuration() {
304 | return mDuration;
305 | }
306 |
307 | public void setInterpolator(TimeInterpolator value) {
308 | if (value != null) {
309 | mInterpolator = value;
310 | } else {
311 | mInterpolator = new DecelerateInterpolator();
312 | }
313 | }
314 |
315 | public TimeInterpolator getInterpolator() {
316 | return mInterpolator;
317 | }
318 |
319 | public void setRepeatCount(int value) {
320 | mRepeatCount = value;
321 | }
322 |
323 | public int getRepeatCount() {
324 | return mRepeatCount;
325 | }
326 |
327 | public void setRepeatMode(@HighlightAnimHolder.RepeatMode int value) {
328 | mRepeatMode = value;
329 | }
330 |
331 | public int getRepeatMode() {
332 | return mRepeatMode;
333 | }
334 |
335 | public int getStartDirection() {
336 | return mHighlightDrawView.getHighlightDraw().getStartDirection();
337 | }
338 |
339 | public void setStartDirection(@HighlightAnimHolder.StartDirection int startDirection) {
340 | mHighlightDrawView.getHighlightDraw().setStartDirection(startDirection);
341 | }
342 |
343 | @ColorInt
344 | public int getHighlightColor() {
345 | return mHighlightDrawView.getHighlightDraw().getHighlightColor();
346 | }
347 |
348 | public ColorStateList getHighlightColors() {
349 | return mHighlightDrawView.getHighlightDraw().getHighlightColors();
350 | }
351 |
352 | public void setHighlightColor(@ColorInt int highlightColor) {
353 | mHighlightDrawView.getHighlightDraw().setHighlightColor(highlightColor);
354 | }
355 |
356 | public void setHighlightColor(ColorStateList highlightColor) {
357 | mHighlightDrawView.getHighlightDraw().setHighlightColor(highlightColor);
358 | }
359 |
360 | protected boolean isFinishLayout() {
361 | return isFinishLayout;
362 | }
363 |
364 | protected void setFinishLayout(boolean finishLayout) {
365 | isFinishLayout = finishLayout;
366 | }
367 |
368 | protected boolean isStartBeforeLayout() {
369 | return isStartBeforeLayout;
370 | }
371 |
372 | protected void setStartBeforeLayout(boolean startBeforeLayout) {
373 | isStartBeforeLayout = startBeforeLayout;
374 | }
375 |
376 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
377 | setFinishLayout(true);
378 | if (isStartBeforeLayout()) {
379 | startAnim();
380 | }
381 | }
382 |
383 | protected void drawableStateChanged() {
384 | mHighlightDrawView.getHighlightDraw().setGradientColors();
385 | }
386 | }
387 |
--------------------------------------------------------------------------------
/library/src/main/java/com/flyjingfish/highlightviewlib/HighlightDraw.java:
--------------------------------------------------------------------------------
1 | package com.flyjingfish.highlightviewlib;
2 |
3 | import static com.flyjingfish.highlightviewlib.HighlightAnimHolder.FROM_BOTTOM;
4 | import static com.flyjingfish.highlightviewlib.HighlightAnimHolder.FROM_LEFT;
5 | import static com.flyjingfish.highlightviewlib.HighlightAnimHolder.FROM_TOP;
6 |
7 | import android.annotation.SuppressLint;
8 | import android.content.res.ColorStateList;
9 | import android.graphics.Canvas;
10 | import android.graphics.Color;
11 | import android.graphics.LinearGradient;
12 | import android.graphics.Paint;
13 | import android.graphics.PorterDuff;
14 | import android.graphics.PorterDuffXfermode;
15 | import android.graphics.RectF;
16 | import android.graphics.Shader;
17 |
18 | import androidx.annotation.ColorInt;
19 |
20 | import java.util.ArrayList;
21 | import java.util.List;
22 |
23 | class HighlightDraw {
24 |
25 | private final RectF mRectF = new RectF();
26 | private final PorterDuffXfermode mDstInXfermode = new PorterDuffXfermode(PorterDuff.Mode.DST_IN);
27 | private final float[] mGradientPosition = new float[]{0, .45f, .55f, 1};
28 | private final int[] mGradientColors = new int[4];
29 | private float mStartHighlightOffset = 0;
30 | private float mHighlightWidth = 0;
31 | private final Paint mImagePaint = InitAttrs.initPaint();
32 | private float mHighlightRotateDegrees = 0;
33 | private ColorStateList mHighlightColor;
34 | private int mCurHighlightColor;
35 | private int mStartDirection = FROM_LEFT;
36 | private final HighlightDrawView mHighlightDrawView;
37 |
38 |
39 | protected HighlightDraw(HighlightDrawView highlightDrawView) {
40 | this.mHighlightDrawView = highlightDrawView;
41 | }
42 |
43 | private int getWidth() {
44 | return mHighlightDrawView.thisView().getWidth();
45 | }
46 |
47 | private int getHeight() {
48 | return mHighlightDrawView.thisView().getHeight();
49 | }
50 |
51 | @SuppressLint("DrawAllocation")
52 | protected void onDraw(Canvas canvas) {
53 | int viewWidth = getWidth();
54 | int viewHeight = getHeight();
55 | int hypotenuseLength = (int) Math.sqrt(Math.pow(viewWidth, 2) + Math.pow(viewHeight, 2));
56 | int left = -(hypotenuseLength - viewWidth) / 2;
57 | int top = -(hypotenuseLength - viewHeight) / 2;
58 | int right = viewWidth + (hypotenuseLength - viewWidth) / 2;
59 | int bottom = viewHeight + (hypotenuseLength - viewHeight) / 2;
60 |
61 | canvas.rotate(mHighlightRotateDegrees, viewWidth / 2f, viewHeight / 2f);
62 |
63 | mImagePaint.setXfermode(null);
64 | mRectF.set(left, top, right, bottom);
65 | canvas.saveLayer(mRectF, mImagePaint, Canvas.ALL_SAVE_FLAG);
66 | if (mStartDirection == FROM_TOP || mStartDirection == FROM_BOTTOM) {
67 | LinearGradient linearGradient =
68 | new LinearGradient(0, mStartHighlightOffset, 0, mStartHighlightOffset + mHighlightWidth,
69 | mGradientColors, mGradientPosition, Shader.TileMode.CLAMP);
70 | mImagePaint.setShader(linearGradient);
71 | canvas.drawRect(left, mStartHighlightOffset, right, mStartHighlightOffset + mHighlightWidth, mImagePaint);
72 | } else {
73 | LinearGradient linearGradient =
74 | new LinearGradient(mStartHighlightOffset, 0, mStartHighlightOffset + mHighlightWidth, 0,
75 | mGradientColors, mGradientPosition, Shader.TileMode.CLAMP);
76 | mImagePaint.setShader(linearGradient);
77 | canvas.drawRect(mStartHighlightOffset, top, mStartHighlightOffset + mHighlightWidth, bottom, mImagePaint);
78 | }
79 | mImagePaint.setXfermode(mDstInXfermode);
80 | canvas.saveLayer(mRectF, mImagePaint, Canvas.ALL_SAVE_FLAG);
81 | canvas.rotate(-mHighlightRotateDegrees, viewWidth / 2f, viewHeight / 2f);
82 |
83 | }
84 |
85 | protected float getHighlightRotateDegrees() {
86 | return mHighlightRotateDegrees;
87 | }
88 |
89 | protected void setHighlightRotateDegrees(float highlightRotateDegrees) {
90 | this.mHighlightRotateDegrees = highlightRotateDegrees;
91 | }
92 |
93 | protected float setStartHighlightOffset() {
94 | return mStartHighlightOffset;
95 | }
96 |
97 | protected void setStartHighlightOffset(float startHighlightOffset) {
98 | this.mStartHighlightOffset = startHighlightOffset;
99 | }
100 |
101 | protected float getHighlightWidth() {
102 | return mHighlightWidth;
103 | }
104 |
105 | protected void setHighlightWidth(float highlightWidth) {
106 | this.mHighlightWidth = highlightWidth;
107 | }
108 |
109 | @ColorInt
110 | protected int getHighlightColor() {
111 | return mCurHighlightColor;
112 | }
113 |
114 | protected ColorStateList getHighlightColors() {
115 | return mHighlightColor;
116 | }
117 |
118 | protected void setHighlightColor(ColorStateList highlightColor) {
119 | this.mHighlightColor = highlightColor;
120 | setGradientColors();
121 | }
122 |
123 | protected void setHighlightColor(@ColorInt int highlightColor) {
124 | setHighlightColor(ColorStateList.valueOf(highlightColor));
125 | }
126 |
127 | void setGradientColors(){
128 | if (mHighlightColor == null){
129 | return;
130 | }
131 | boolean inval = false;
132 | final int[] drawableState = mHighlightDrawView.thisView().getDrawableState();
133 | int highlightColor = mHighlightColor.getColorForState(drawableState, 0);
134 | if (highlightColor != mCurHighlightColor) {
135 | mCurHighlightColor = highlightColor;
136 | float[] resourceColorHsv = new float[3];
137 | Color.colorToHSV(highlightColor, resourceColorHsv);
138 |
139 | int mHighlightEndColor = Color.HSVToColor(1, resourceColorHsv);
140 |
141 | mGradientColors[0] = mHighlightEndColor;
142 | mGradientColors[1] = highlightColor;
143 | mGradientColors[2] = highlightColor;
144 | mGradientColors[3] = mHighlightEndColor;
145 | inval = true;
146 | }
147 | if (inval){
148 | mHighlightDrawView.thisView().invalidate();
149 | }
150 | }
151 |
152 | protected int getStartDirection() {
153 | return mStartDirection;
154 | }
155 |
156 | protected void setStartDirection(@HighlightAnimHolder.StartDirection int startDirection) {
157 | this.mStartDirection = startDirection;
158 | }
159 | }
--------------------------------------------------------------------------------
/library/src/main/java/com/flyjingfish/highlightviewlib/HighlightDrawView.java:
--------------------------------------------------------------------------------
1 | package com.flyjingfish.highlightviewlib;
2 |
3 |
4 | interface HighlightDrawView extends HighlightView {
5 | HighlightDraw getHighlightDraw();
6 | }
7 |
--------------------------------------------------------------------------------
/library/src/main/java/com/flyjingfish/highlightviewlib/HighlightFrameLayout.java:
--------------------------------------------------------------------------------
1 | package com.flyjingfish.highlightviewlib;
2 |
3 |
4 | import android.content.Context;
5 | import android.graphics.Canvas;
6 | import android.graphics.Paint;
7 | import android.graphics.PorterDuff;
8 | import android.graphics.PorterDuffXfermode;
9 | import android.graphics.RectF;
10 | import android.util.AttributeSet;
11 | import android.view.View;
12 | import android.widget.FrameLayout;
13 |
14 | import androidx.annotation.NonNull;
15 | import androidx.annotation.Nullable;
16 |
17 | public class HighlightFrameLayout extends FrameLayout implements HighlightView, HighlightDrawView, AnimHolder {
18 | private final HighlightAnimHolder mHighlightAnimHolder = new HighlightAnimHolder(this, this);
19 | private final HighlightDraw mHighlightDraw = new HighlightDraw(this);
20 | private final Paint mImagePaint = InitAttrs.initPaint();
21 |
22 | private final RectF mRectF = new RectF();
23 | private final PorterDuffXfermode mSrcInXfermode = new PorterDuffXfermode(PorterDuff.Mode.SRC_IN);
24 |
25 | public HighlightFrameLayout(@NonNull Context context) {
26 | this(context, null);
27 | }
28 |
29 | public HighlightFrameLayout(@NonNull Context context, @Nullable AttributeSet attrs) {
30 | this(context, attrs, 0);
31 | }
32 |
33 | public HighlightFrameLayout(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
34 | super(context, attrs, defStyleAttr);
35 | InitAttrs.init(context, attrs, mHighlightAnimHolder);
36 | }
37 |
38 | @Override
39 | protected void dispatchDraw(Canvas canvas) {
40 | mRectF.set(0, 0, getWidth(), getHeight());
41 | mImagePaint.setXfermode(null);
42 | canvas.saveLayer(mRectF, mImagePaint, Canvas.ALL_SAVE_FLAG);
43 | super.dispatchDraw(canvas);
44 |
45 |
46 | mImagePaint.setXfermode(mSrcInXfermode);
47 | canvas.saveLayer(mRectF, mImagePaint, Canvas.ALL_SAVE_FLAG);
48 | canvas.drawRect(mRectF, mImagePaint);
49 |
50 | mImagePaint.setXfermode(null);
51 | canvas.saveLayer(mRectF, mImagePaint, Canvas.ALL_SAVE_FLAG);
52 | super.dispatchDraw(canvas);
53 | mHighlightDraw.onDraw(canvas);
54 | super.dispatchDraw(canvas);
55 | }
56 |
57 | @Override
58 | public View thisView() {
59 | return this;
60 | }
61 |
62 | @Override
63 | public HighlightAnimHolder getHighlightAnimHolder() {
64 | return mHighlightAnimHolder;
65 | }
66 |
67 |
68 | @Override
69 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
70 | super.onLayout(changed, left, top, right, bottom);
71 | mHighlightAnimHolder.onLayout(changed, left, top, right, bottom);
72 | }
73 |
74 | @Override
75 | public HighlightDraw getHighlightDraw() {
76 | return mHighlightDraw;
77 | }
78 |
79 | @Override
80 | protected void drawableStateChanged() {
81 | super.drawableStateChanged();
82 | mHighlightAnimHolder.drawableStateChanged();
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/library/src/main/java/com/flyjingfish/highlightviewlib/HighlightImageView.java:
--------------------------------------------------------------------------------
1 | package com.flyjingfish.highlightviewlib;
2 |
3 |
4 | import android.content.Context;
5 | import android.graphics.Canvas;
6 | import android.util.AttributeSet;
7 | import android.view.View;
8 |
9 | import androidx.annotation.NonNull;
10 | import androidx.annotation.Nullable;
11 | import androidx.appcompat.widget.AppCompatImageView;
12 |
13 | public class HighlightImageView extends AppCompatImageView implements HighlightView, HighlightDrawView, AnimHolder {
14 | private final HighlightAnimHolder mHighlightAnimHolder = new HighlightAnimHolder(this, this);
15 | private final HighlightDraw mHighlightDraw = new HighlightDraw(this);
16 |
17 | public HighlightImageView(@NonNull Context context) {
18 | this(context, null);
19 | }
20 |
21 | public HighlightImageView(@NonNull Context context, @Nullable AttributeSet attrs) {
22 | this(context, attrs, 0);
23 | }
24 |
25 | public HighlightImageView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
26 | super(context, attrs, defStyleAttr);
27 |
28 | InitAttrs.init(context, attrs, mHighlightAnimHolder);
29 | }
30 |
31 | @Override
32 | protected void onDraw(Canvas canvas) {
33 | super.onDraw(canvas);
34 |
35 | mHighlightDraw.onDraw(canvas);
36 | super.onDraw(canvas);
37 | }
38 |
39 | @Override
40 | public View thisView() {
41 | return this;
42 | }
43 |
44 | @Override
45 | public HighlightAnimHolder getHighlightAnimHolder() {
46 | return mHighlightAnimHolder;
47 | }
48 |
49 | @Override
50 | public HighlightDraw getHighlightDraw() {
51 | return mHighlightDraw;
52 | }
53 |
54 | @Override
55 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
56 | super.onLayout(changed, left, top, right, bottom);
57 | mHighlightAnimHolder.onLayout(changed, left, top, right, bottom);
58 | }
59 |
60 | @Override
61 | protected void drawableStateChanged() {
62 | super.drawableStateChanged();
63 | mHighlightAnimHolder.drawableStateChanged();
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/library/src/main/java/com/flyjingfish/highlightviewlib/HighlightLinearLayout.java:
--------------------------------------------------------------------------------
1 | package com.flyjingfish.highlightviewlib;
2 |
3 |
4 | import android.content.Context;
5 | import android.graphics.Canvas;
6 | import android.graphics.Paint;
7 | import android.graphics.PorterDuff;
8 | import android.graphics.PorterDuffXfermode;
9 | import android.graphics.RectF;
10 | import android.util.AttributeSet;
11 | import android.view.View;
12 | import android.widget.LinearLayout;
13 |
14 | import androidx.annotation.NonNull;
15 | import androidx.annotation.Nullable;
16 |
17 | public class HighlightLinearLayout extends LinearLayout implements HighlightView, HighlightDrawView, AnimHolder {
18 | private final HighlightAnimHolder mHighlightAnimHolder = new HighlightAnimHolder(this, this);
19 | private final HighlightDraw mHighlightDraw = new HighlightDraw(this);
20 | private final Paint mImagePaint = InitAttrs.initPaint();
21 |
22 | private final RectF mRectF = new RectF();
23 | private final PorterDuffXfermode mSrcInXfermode = new PorterDuffXfermode(PorterDuff.Mode.SRC_IN);
24 |
25 | public HighlightLinearLayout(@NonNull Context context) {
26 | this(context, null);
27 | }
28 |
29 | public HighlightLinearLayout(@NonNull Context context, @Nullable AttributeSet attrs) {
30 | this(context, attrs, 0);
31 | }
32 |
33 | public HighlightLinearLayout(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
34 | super(context, attrs, defStyleAttr);
35 | InitAttrs.init(context, attrs, mHighlightAnimHolder);
36 | }
37 |
38 | @Override
39 | protected void dispatchDraw(Canvas canvas) {
40 | mRectF.set(0, 0, getWidth(), getHeight());
41 | mImagePaint.setXfermode(null);
42 | canvas.saveLayer(mRectF, mImagePaint, Canvas.ALL_SAVE_FLAG);
43 | super.dispatchDraw(canvas);
44 |
45 |
46 | mImagePaint.setXfermode(mSrcInXfermode);
47 | canvas.saveLayer(mRectF, mImagePaint, Canvas.ALL_SAVE_FLAG);
48 | canvas.drawRect(mRectF, mImagePaint);
49 |
50 | mImagePaint.setXfermode(null);
51 | canvas.saveLayer(mRectF, mImagePaint, Canvas.ALL_SAVE_FLAG);
52 | super.dispatchDraw(canvas);
53 | mHighlightDraw.onDraw(canvas);
54 | super.dispatchDraw(canvas);
55 | }
56 |
57 | @Override
58 | public View thisView() {
59 | return this;
60 | }
61 |
62 | @Override
63 | public HighlightAnimHolder getHighlightAnimHolder() {
64 | return mHighlightAnimHolder;
65 | }
66 |
67 | @Override
68 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
69 | super.onLayout(changed, left, top, right, bottom);
70 | mHighlightAnimHolder.onLayout(changed, left, top, right, bottom);
71 | }
72 |
73 | @Override
74 | public HighlightDraw getHighlightDraw() {
75 | return mHighlightDraw;
76 | }
77 |
78 | @Override
79 | protected void drawableStateChanged() {
80 | super.drawableStateChanged();
81 | mHighlightAnimHolder.drawableStateChanged();
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/library/src/main/java/com/flyjingfish/highlightviewlib/HighlightRelativeLayout.java:
--------------------------------------------------------------------------------
1 | package com.flyjingfish.highlightviewlib;
2 |
3 |
4 | import android.content.Context;
5 | import android.graphics.Canvas;
6 | import android.graphics.Paint;
7 | import android.graphics.PorterDuff;
8 | import android.graphics.PorterDuffXfermode;
9 | import android.graphics.RectF;
10 | import android.util.AttributeSet;
11 | import android.view.View;
12 | import android.widget.RelativeLayout;
13 |
14 | import androidx.annotation.NonNull;
15 | import androidx.annotation.Nullable;
16 |
17 | public class HighlightRelativeLayout extends RelativeLayout implements HighlightView, HighlightDrawView, AnimHolder {
18 | private final HighlightAnimHolder mHighlightAnimHolder = new HighlightAnimHolder(this, this);
19 | private final HighlightDraw mHighlightDraw = new HighlightDraw(this);
20 | private final Paint mImagePaint = InitAttrs.initPaint();
21 |
22 | private final RectF mRectF = new RectF();
23 | private final PorterDuffXfermode mSrcInXfermode = new PorterDuffXfermode(PorterDuff.Mode.SRC_IN);
24 |
25 | public HighlightRelativeLayout(@NonNull Context context) {
26 | this(context, null);
27 | }
28 |
29 | public HighlightRelativeLayout(@NonNull Context context, @Nullable AttributeSet attrs) {
30 | this(context, attrs, 0);
31 | }
32 |
33 | public HighlightRelativeLayout(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
34 | super(context, attrs, defStyleAttr);
35 | InitAttrs.init(context, attrs, mHighlightAnimHolder);
36 | }
37 |
38 |
39 | @Override
40 | protected void dispatchDraw(Canvas canvas) {
41 | mRectF.set(0, 0, getWidth(), getHeight());
42 | mImagePaint.setXfermode(null);
43 | canvas.saveLayer(mRectF, mImagePaint, Canvas.ALL_SAVE_FLAG);
44 | super.dispatchDraw(canvas);
45 |
46 |
47 | mImagePaint.setXfermode(mSrcInXfermode);
48 | canvas.saveLayer(mRectF, mImagePaint, Canvas.ALL_SAVE_FLAG);
49 | canvas.drawRect(mRectF, mImagePaint);
50 |
51 | mImagePaint.setXfermode(null);
52 | canvas.saveLayer(mRectF, mImagePaint, Canvas.ALL_SAVE_FLAG);
53 | super.dispatchDraw(canvas);
54 | mHighlightDraw.onDraw(canvas);
55 | super.dispatchDraw(canvas);
56 | }
57 |
58 | @Override
59 | public View thisView() {
60 | return this;
61 | }
62 |
63 | @Override
64 | public HighlightAnimHolder getHighlightAnimHolder() {
65 | return mHighlightAnimHolder;
66 | }
67 |
68 | @Override
69 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
70 | super.onLayout(changed, left, top, right, bottom);
71 | mHighlightAnimHolder.onLayout(changed, left, top, right, bottom);
72 | }
73 |
74 | @Override
75 | public HighlightDraw getHighlightDraw() {
76 | return mHighlightDraw;
77 | }
78 |
79 | @Override
80 | protected void drawableStateChanged() {
81 | super.drawableStateChanged();
82 | mHighlightAnimHolder.drawableStateChanged();
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/library/src/main/java/com/flyjingfish/highlightviewlib/HighlightTextView.java:
--------------------------------------------------------------------------------
1 | package com.flyjingfish.highlightviewlib;
2 |
3 |
4 | import android.content.Context;
5 | import android.graphics.Canvas;
6 | import android.graphics.Paint;
7 | import android.graphics.PorterDuff;
8 | import android.graphics.PorterDuffXfermode;
9 | import android.graphics.RectF;
10 | import android.util.AttributeSet;
11 | import android.view.View;
12 |
13 | import androidx.annotation.NonNull;
14 | import androidx.annotation.Nullable;
15 | import androidx.appcompat.widget.AppCompatTextView;
16 |
17 | public class HighlightTextView extends AppCompatTextView implements HighlightView, HighlightDrawView, AnimHolder {
18 | private final HighlightAnimHolder mHighlightAnimHolder = new HighlightAnimHolder(this, this);
19 | private final RectF mRectF = new RectF();
20 | private final PorterDuffXfermode mSrcInXfermode = new PorterDuffXfermode(PorterDuff.Mode.SRC_IN);
21 | private final HighlightDraw mHighlightDraw = new HighlightDraw(this);
22 |
23 | public HighlightTextView(@NonNull Context context) {
24 | this(context, null);
25 | }
26 |
27 | public HighlightTextView(@NonNull Context context, @Nullable AttributeSet attrs) {
28 | this(context, attrs, 0);
29 | }
30 |
31 | public HighlightTextView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
32 | super(context, attrs, defStyleAttr);
33 | InitAttrs.init(context, attrs, mHighlightAnimHolder);
34 | }
35 |
36 | @Override
37 | public View thisView() {
38 | return this;
39 | }
40 |
41 | @Override
42 | public HighlightAnimHolder getHighlightAnimHolder() {
43 | return mHighlightAnimHolder;
44 | }
45 |
46 | @Override
47 | protected void onDraw(Canvas canvas) {
48 | mRectF.set(0, 0, getWidth(), getHeight());
49 | Paint paint = getPaint();
50 | paint.setXfermode(null);
51 | canvas.saveLayer(mRectF, paint, Canvas.ALL_SAVE_FLAG);
52 | super.onDraw(canvas);
53 |
54 |
55 | paint.setXfermode(mSrcInXfermode);
56 | canvas.saveLayer(mRectF, paint, Canvas.ALL_SAVE_FLAG);
57 | canvas.drawRect(mRectF, paint);
58 |
59 | paint.setXfermode(null);
60 | canvas.saveLayer(mRectF, paint, Canvas.ALL_SAVE_FLAG);
61 | super.onDraw(canvas);
62 |
63 | mHighlightDraw.onDraw(canvas);
64 | super.onDraw(canvas);
65 | }
66 |
67 | @Override
68 | public HighlightDraw getHighlightDraw() {
69 | return mHighlightDraw;
70 | }
71 |
72 | @Override
73 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
74 | super.onLayout(changed, left, top, right, bottom);
75 | mHighlightAnimHolder.onLayout(changed, left, top, right, bottom);
76 | }
77 |
78 | @Override
79 | protected void drawableStateChanged() {
80 | super.drawableStateChanged();
81 | mHighlightAnimHolder.drawableStateChanged();
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/library/src/main/java/com/flyjingfish/highlightviewlib/HighlightView.java:
--------------------------------------------------------------------------------
1 | package com.flyjingfish.highlightviewlib;
2 |
3 | import android.view.View;
4 |
5 | interface HighlightView {
6 | View thisView();
7 | }
8 |
--------------------------------------------------------------------------------
/library/src/main/java/com/flyjingfish/highlightviewlib/InitAttrs.java:
--------------------------------------------------------------------------------
1 | package com.flyjingfish.highlightviewlib;
2 |
3 | import static com.flyjingfish.highlightviewlib.HighlightAnimHolder.FROM_LEFT;
4 | import static com.flyjingfish.highlightviewlib.HighlightAnimHolder.RESTART;
5 |
6 | import android.app.Activity;
7 | import android.content.Context;
8 | import android.content.res.ColorStateList;
9 | import android.content.res.TypedArray;
10 | import android.graphics.Color;
11 | import android.graphics.Paint;
12 | import android.graphics.PorterDuff;
13 | import android.graphics.PorterDuffXfermode;
14 | import android.util.AttributeSet;
15 | import android.view.View;
16 | import android.view.ViewGroup;
17 |
18 | import androidx.annotation.NonNull;
19 | import androidx.annotation.Nullable;
20 | import androidx.lifecycle.LifecycleOwner;
21 | import androidx.lifecycle.ViewModelStoreOwner;
22 | import androidx.savedstate.SavedStateRegistryOwner;
23 |
24 | class InitAttrs {
25 | static void init(@NonNull Context context, @Nullable AttributeSet attrs, @NonNull HighlightAnimHolder highlightAnimHolder) {
26 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.HighlightAnimView);
27 | ColorStateList highlightColor = a.getColorStateList(R.styleable.HighlightAnimView_highlight_view_highlightColor);
28 | long duration = a.getInteger(R.styleable.HighlightAnimView_highlight_view_duration, 1000);
29 | int repeatCount = a.getInteger(R.styleable.HighlightAnimView_highlight_view_repeatCount, 0);
30 | int repeatMode = a.getInt(R.styleable.HighlightAnimView_highlight_view_repeatMode, RESTART);
31 | float highlightWidth = a.getDimension(R.styleable.HighlightAnimView_highlight_view_highlightWidth, 10);
32 | float highlightRotateDegrees = a.getFloat(R.styleable.HighlightAnimView_highlight_view_highlightRotateDegrees, 0);
33 | int startDirection = a.getColor(R.styleable.HighlightAnimView_highlight_view_startDirection, FROM_LEFT);
34 | boolean autoStart = a.getBoolean(R.styleable.HighlightAnimView_highlight_view_autoStart, false);
35 | a.recycle();
36 | if (highlightColor == null){
37 | highlightColor = ColorStateList.valueOf(Color.WHITE);
38 | }
39 |
40 | highlightAnimHolder.setDuration(duration);
41 | highlightAnimHolder.setRepeatCount(repeatCount);
42 | highlightAnimHolder.setRepeatMode(repeatMode);
43 | highlightAnimHolder.setHighlightWidth(highlightWidth);
44 | highlightAnimHolder.setHighlightRotateDegrees(highlightRotateDegrees);
45 | highlightAnimHolder.setStartDirection(startDirection);
46 | highlightAnimHolder.setHighlightColor(highlightColor);
47 |
48 | if (autoStart) {
49 | highlightAnimHolder.startHighlightEffect();
50 | }
51 | }
52 |
53 | static Paint initPaint() {
54 | Paint paint = new Paint();
55 | paint.setColor(Color.BLACK);
56 | paint.setAntiAlias(true);
57 | paint.setStyle(Paint.Style.FILL_AND_STROKE);
58 | paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT));
59 | return paint;
60 | }
61 |
62 | static EnsureFragmentX ensureInFragmentX(@Nullable View view) {
63 | if (view == null) {
64 | return new EnsureFragmentX(null,false);
65 | } else if (view.getParent() instanceof ViewGroup) {
66 | ViewGroup viewGroup = (ViewGroup) view.getParent();
67 | if (isInFragment(viewGroup)) {
68 | Object object1 = viewGroup.getTag(R.id.view_tree_lifecycle_owner);
69 | return new EnsureFragmentX((LifecycleOwner) object1,true);
70 | } else {
71 | return ensureInFragmentX(viewGroup);
72 | }
73 | } else {
74 | return new EnsureFragmentX(null,false);
75 | }
76 | }
77 |
78 | private static boolean isInFragment(View view){
79 | Object object1 = view.getTag(R.id.view_tree_lifecycle_owner);
80 | Object object2 = view.getTag(R.id.view_tree_view_model_store_owner);
81 | Object object3 = view.getTag(R.id.view_tree_saved_state_registry_owner);
82 | return object1 instanceof LifecycleOwner && object2 instanceof ViewModelStoreOwner && object3 instanceof SavedStateRegistryOwner && !(object1 instanceof Activity);
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/library/src/main/res/values/values.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/screenshot/screenrecording-20221109-134351.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FlyJingFish/HighlightView/b63d587f4dde8280c34d3242b509d52d272d9555/screenshot/screenrecording-20221109-134351.gif
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | rootProject.name = "HighlightView"
2 | include ':app'
3 | include ':library'
4 |
--------------------------------------------------------------------------------