float. This type-specific subclass enables performance benefit by allowing
23 | * calls to a {@link #set(Object, Float) set()} function that takes the primitive
24 | * float type and avoids autoboxing and other overhead associated with the
25 | * Float class.
26 | *
27 | * @param float.
38 | */
39 | public abstract void setValue(T object, float value);
40 |
41 | @Override
42 | final public void set(T object, Float value) {
43 | setValue(object, value);
44 | }
45 |
46 | }
--------------------------------------------------------------------------------
/HTLoading/src/main/kotlin/com/superlht/htloading/spinkit/animation/IntProperty.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android Open Source Project
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 | package com.superlht.htloading.spinkit.animation;
17 |
18 | import android.util.Property;
19 |
20 | /**
21 | * An implementation of {@link Property} to be used specifically with fields of type
22 | * int. This type-specific subclass enables performance benefit by allowing
23 | * calls to a {@link #set(Object, Integer) set()} function that takes the primitive
24 | * int type and avoids autoboxing and other overhead associated with the
25 | * Integer class.
26 | *
27 | * @param int.
38 | */
39 | public abstract void setValue(T object, int value);
40 |
41 | @Override
42 | final public void set(T object, Integer value) {
43 | setValue(object, value);
44 | }
45 |
46 | }
--------------------------------------------------------------------------------
/HTLoading/src/main/kotlin/com/superlht/htloading/spinkit/animation/interpolator/PathInterpolatorCompatApi21.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 The Android Open Source Project
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.superlht.htloading.spinkit.animation.interpolator;
18 |
19 | import android.annotation.TargetApi;
20 | import android.graphics.Path;
21 | import android.os.Build;
22 | import android.view.animation.Interpolator;
23 | import android.view.animation.PathInterpolator;
24 |
25 | /**
26 | * API 21+ implementation for path interpolator compatibility.
27 | */
28 | class PathInterpolatorCompatApi21 {
29 |
30 | private PathInterpolatorCompatApi21() {
31 | // prevent instantiation
32 | }
33 |
34 | @TargetApi(Build.VERSION_CODES.LOLLIPOP)
35 | public static Interpolator create(Path path) {
36 | return new PathInterpolator(path);
37 | }
38 |
39 | @TargetApi(Build.VERSION_CODES.LOLLIPOP)
40 | public static Interpolator create(float controlX, float controlY) {
41 | return new PathInterpolator(controlX, controlY);
42 | }
43 |
44 | @TargetApi(Build.VERSION_CODES.LOLLIPOP)
45 | public static Interpolator create(float controlX1, float controlY1,
46 | float controlX2, float controlY2) {
47 | return new PathInterpolator(controlX1, controlY1, controlX2, controlY2);
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/HTLoading/src/main/res/layout/loading_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 |
20 | ## 基本使用
21 |
22 | 步骤1.将依赖添加到项目的bulid.gradle里:
23 |
24 | Android Gradle plugin 3.0+
25 | ```groovy
26 | implementation 'com.superlht:HTLoading:1.0.1'
27 | ```
28 | else
29 | ```groovy
30 | compile 'com.superlht:HTLoading:1.0.1'
31 | ```
32 |
33 | ## 使用方法
34 |
35 | ### 显示默认动画
36 |
37 | 如果全部使用默认配置,需要显示Loading的地方只需要调用:
38 |
39 | ```kotlin
40 | HTLoading(this).show()
41 | ```
42 |
43 | 需要设置展示的文字:
44 |
45 | ```kotlin
46 | HTLoading(this).setLoadingText("加载中...").show()
47 | ```
48 |
49 | 加载成功:
50 |
51 | ```kotlin
52 | HTLoading(this).setSuccessText("加载成功!").showSuccess()
53 | ```
54 |
55 | HTLoading支持链式调用,如HTLoading(this).setLoadingText("加载中...").setsetFailedText("加载失败").show(),调用show方法后不支持链式调用
56 |
57 | ### 显示自定义View
58 |
59 | ### 显示SpinKit动画
60 |
61 |
62 |
63 | | Style | Preview |
64 | | -------------- | --------------------------- |
65 | | RotatingPlane |  |
66 | | DoubleBounce |  |
67 | | Wave |  |
68 | | WanderingCubes |  |
69 | | Pulse |  |
70 | | ChasingDots |  |
71 | | ThreeBounce |  |
72 | | Circle |  |
73 | | CubeGrid |  |
74 | | FadingCircle |  |
75 | | FoldingCube |  |
76 | | RotatingCircle |  |
77 |
78 | ##
79 |
80 | ## API文档
81 |
82 | | fun(方法) | describe(描述) |
83 | | ---------------------------------------- | ------------------- |
84 | | show() | 显示默认的Loading Dialog |
85 | | showSuccess() | 显示默认的成功dialog |
86 | | showFailed() | 显示默认的失败dialog |
87 | | showCustomFailed() | 显示自定义的失败界面 |
88 | | showCustomSuccess() | 显示自定义的成功界面 |
89 | | showCustomLoading() | 显示自定义的加载界面 |
90 | | setSuccessView(view:View) | 设置自定义成功界面 |
91 | | setFailedView(view:View) | 设置自定义失败界面 |
92 | | setLoadingView(view:View) | 设置自定义加载界面 |
93 | | setOnDialogDismissListener(listener: OnDialogDismissListener) | 设置对话框消失的监听器 |
94 |
95 | ## 全局设置
96 |
97 | 有需要在全局都使用统一Loading样式或内容的,可以在Application中进行全局初始化设置,如:
98 |
99 | ```kotlin
100 | HTLoadingManager.loadText("正在加载...").successText("加载成功")
101 | ```
102 |
103 | 目前支持全局设置的方法有:
104 |
105 | - textSize(size:Float) :字体尺寸
106 | - loadText() /failedText()/successText() :加载/失败/成功时显示的文字
107 | - delay(time:Long) :成功和失败显示后延迟多少毫秒(ms)消失
108 | - drawColor(color:Int) : 图形的颜色
109 | - isAutoDismiss(boolean:Boolean) : 成功/失败后Dialog是否自动消失
110 |
111 | ### 感谢
112 |
113 | [ForgetAll/LoadingDialog](https://github.com/ForgetAll/LoadingDialog)
114 |
115 | [ybq/Android-SpinKit](https://github.com/ybq/Android-SpinKit)
116 |
117 | 有任何问题欢迎issue提出
118 |
119 | ### [更新日志](CHANGELOG.md)
120 |
121 | ## License
122 |
123 | ```
124 | Licensed under the Apache License, Version 2.0 (the "License");
125 | you may not use this file except in compliance with the License.
126 | You may obtain a copy of the License at
127 |
128 | http://www.apache.org/licenses/LICENSE-2.0
129 |
130 | Unless required by applicable law or agreed to in writing, software
131 | distributed under the License is distributed on an "AS IS" BASIS,
132 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
133 | See the License for the specific language governing permissions and
134 | limitations under the License.
135 | ```
--------------------------------------------------------------------------------
/HTLoading/src/main/kotlin/com/superlht/htloading/spinkit/animation/interpolator/PathInterpolatorCompat.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 The Android Open Source Project
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.superlht.htloading.spinkit.animation.interpolator;
18 |
19 | import android.graphics.Path;
20 | import android.os.Build;
21 | import android.view.animation.Interpolator;
22 |
23 | /**
24 | * Helper for creating path-based {@link Interpolator} instances. On API 21 or newer, the
25 | * platform implementation will be used and on older platforms a compatible alternative
26 | * implementation will be used.
27 | */
28 | public class PathInterpolatorCompat {
29 |
30 | private PathInterpolatorCompat() {
31 | // prevent instantiation
32 | }
33 |
34 | /**
35 | * Create an {@link Interpolator} for an arbitrary {@link Path}. The {@link Path}
36 | * must begin at {@code (0, 0)} and end at {@code (1, 1)}. The x-coordinate along the
37 | * {@link Path} is the input value and the output is the y coordinate of the line at that
38 | * point. This means that the Path must conform to a function {@code y = f(x)}.
39 | *
40 | * The {@link Path} must not have gaps in the x direction and must not
41 | * loop back on itself such that there can be two points sharing the same x coordinate.
42 | *
43 | * @param path the {@link Path} to use to make the line representing the {@link Interpolator}
44 | * @return the {@link Interpolator} representing the {@link Path}
45 | */
46 | @SuppressWarnings("unused")
47 | public static Interpolator create(Path path) {
48 | if (Build.VERSION.SDK_INT >= 21) {
49 | return PathInterpolatorCompatApi21.create(path);
50 | }
51 | return PathInterpolatorCompatBase.create(path);
52 | }
53 |
54 | /**
55 | * Create an {@link Interpolator} for a quadratic Bezier curve. The end points
56 | * {@code (0, 0)} and {@code (1, 1)} are assumed.
57 | *
58 | * @param controlX the x coordinate of the quadratic Bezier control point
59 | * @param controlY the y coordinate of the quadratic Bezier control point
60 | * @return the {@link Interpolator} representing the quadratic Bezier curve
61 | */
62 | @SuppressWarnings("unused")
63 | public static Interpolator create(float controlX, float controlY) {
64 | if (Build.VERSION.SDK_INT >= 21) {
65 | return PathInterpolatorCompatApi21.create(controlX, controlY);
66 | }
67 | return PathInterpolatorCompatBase.create(controlX, controlY);
68 | }
69 |
70 | /**
71 | * Create an {@link Interpolator} for a cubic Bezier curve. The end points
72 | * {@code (0, 0)} and {@code (1, 1)} are assumed.
73 | *
74 | * @param controlX1 the x coordinate of the first control point of the cubic Bezier
75 | * @param controlY1 the y coordinate of the first control point of the cubic Bezier
76 | * @param controlX2 the x coordinate of the second control point of the cubic Bezier
77 | * @param controlY2 the y coordinate of the second control point of the cubic Bezier
78 | * @return the {@link Interpolator} representing the cubic Bezier curve
79 | */
80 | public static Interpolator create(float controlX1, float controlY1,
81 | float controlX2, float controlY2) {
82 | if (Build.VERSION.SDK_INT >= 21) {
83 | return PathInterpolatorCompatApi21.create(controlX1, controlY1, controlX2, controlY2);
84 | }
85 | return PathInterpolatorCompatBase.create(controlX1, controlY1, controlX2, controlY2);
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/HTLoading/src/main/kotlin/com/superlht/htloading/spinkit/animation/interpolator/PathInterpolatorDonut.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 The Android Open Source Project
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 | package com.superlht.htloading.spinkit.animation.interpolator;
17 |
18 | import android.graphics.Path;
19 | import android.graphics.PathMeasure;
20 | import android.view.animation.Interpolator;
21 |
22 | /**
23 | * A path interpolator implementation compatible with API 4+.
24 | */
25 | class PathInterpolatorDonut implements Interpolator {
26 |
27 | /**
28 | * Governs the accuracy of the approximation of the {@link Path}.
29 | */
30 | private static final float PRECISION = 0.002f;
31 |
32 | private final float[] mX;
33 | private final float[] mY;
34 |
35 | public PathInterpolatorDonut(Path path) {
36 | final PathMeasure pathMeasure = new PathMeasure(path, false /* forceClosed */);
37 |
38 | final float pathLength = pathMeasure.getLength();
39 | final int numPoints = (int) (pathLength / PRECISION) + 1;
40 |
41 | mX = new float[numPoints];
42 | mY = new float[numPoints];
43 |
44 | final float[] position = new float[2];
45 | for (int i = 0; i < numPoints; ++i) {
46 | final float distance = (i * pathLength) / (numPoints - 1);
47 | pathMeasure.getPosTan(distance, position, null /* tangent */);
48 |
49 | mX[i] = position[0];
50 | mY[i] = position[1];
51 | }
52 | }
53 |
54 | public PathInterpolatorDonut(float controlX, float controlY) {
55 | this(createQuad(controlX, controlY));
56 | }
57 |
58 | public PathInterpolatorDonut(float controlX1, float controlY1,
59 | float controlX2, float controlY2) {
60 | this(createCubic(controlX1, controlY1, controlX2, controlY2));
61 | }
62 |
63 | @Override
64 | public float getInterpolation(float t) {
65 | if (t <= 0.0f) {
66 | return 0.0f;
67 | } else if (t >= 1.0f) {
68 | return 1.0f;
69 | }
70 |
71 | // Do a binary search for the correct x to interpolate between.
72 | int startIndex = 0;
73 | int endIndex = mX.length - 1;
74 | while (endIndex - startIndex > 1) {
75 | int midIndex = (startIndex + endIndex) / 2;
76 | if (t < mX[midIndex]) {
77 | endIndex = midIndex;
78 | } else {
79 | startIndex = midIndex;
80 | }
81 | }
82 |
83 | final float xRange = mX[endIndex] - mX[startIndex];
84 | if (xRange == 0) {
85 | return mY[startIndex];
86 | }
87 |
88 | final float tInRange = t - mX[startIndex];
89 | final float fraction = tInRange / xRange;
90 |
91 | final float startY = mY[startIndex];
92 | final float endY = mY[endIndex];
93 |
94 | return startY + (fraction * (endY - startY));
95 | }
96 |
97 | private static Path createQuad(float controlX, float controlY) {
98 | final Path path = new Path();
99 | path.moveTo(0.0f, 0.0f);
100 | path.quadTo(controlX, controlY, 1.0f, 1.0f);
101 | return path;
102 | }
103 |
104 | private static Path createCubic(float controlX1, float controlY1,
105 | float controlX2, float controlY2) {
106 | final Path path = new Path();
107 | path.moveTo(0.0f, 0.0f);
108 | path.cubicTo(controlX1, controlY1, controlX2, controlY2, 1.0f, 1.0f);
109 | return path;
110 | }
111 | }
112 |
--------------------------------------------------------------------------------
/sample/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |