新增动画dialog,上部分是加载动画,下方是提示,自动高度
|
|
@ -0,0 +1,194 @@
|
||||||
|
package com.tfq.library.dialog;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.graphics.drawable.AnimationDrawable;
|
||||||
|
import android.view.KeyEvent;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import androidx.appcompat.app.AppCompatDialog;
|
||||||
|
|
||||||
|
import com.tfq.library.R;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加载进度条弹窗
|
||||||
|
*
|
||||||
|
* <p>使用示例:
|
||||||
|
* <pre>
|
||||||
|
* // 方式1:显示默认加载动画
|
||||||
|
* MusicLoadingView dialog = new MusicLoadingView(context);
|
||||||
|
* dialog.show();
|
||||||
|
*
|
||||||
|
* // 方式2:显示带消息的加载弹窗
|
||||||
|
* dialog.setMessage("加载中...");
|
||||||
|
* dialog.show();
|
||||||
|
*
|
||||||
|
* // 方式3:一步显示带消息的弹窗
|
||||||
|
* dialog.showMessage("正在处理...");
|
||||||
|
*
|
||||||
|
* // 关闭弹窗
|
||||||
|
* dialog.dismiss();
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* @author TinyHung@outlook.com
|
||||||
|
* @date 2017/3/25 15:16
|
||||||
|
*/
|
||||||
|
public class LoadingViewAnimation extends AppCompatDialog {
|
||||||
|
|
||||||
|
private final ImageView mLoadingIcon;
|
||||||
|
private final TextView mTextContent;
|
||||||
|
private final TextView mTextViewUp;
|
||||||
|
private final TextView mTextViewDown;
|
||||||
|
private AnimationDrawable mAnimationDrawable;
|
||||||
|
private OnDialogBackListener mOnDialogBackListener;
|
||||||
|
|
||||||
|
@SuppressLint("MissingInflatedId")
|
||||||
|
public LoadingViewAnimation(Context context) {
|
||||||
|
super(context, R.style.CenterDialogAnimationStyle);
|
||||||
|
setContentView(R.layout.library_dialog_progress_animation_layout);
|
||||||
|
|
||||||
|
// 初始化视图
|
||||||
|
mLoadingIcon = findViewById(R.id.music_loading_icon);
|
||||||
|
mTextContent = findViewById(R.id.music_content);
|
||||||
|
mTextViewUp = findViewById(R.id.tv_no_content_up);
|
||||||
|
mTextViewDown = findViewById(R.id.tv_no_content_down);
|
||||||
|
|
||||||
|
// 初始化动画
|
||||||
|
if (mLoadingIcon != null) {
|
||||||
|
mAnimationDrawable = (AnimationDrawable) mLoadingIcon.getDrawable();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置弹窗默认不可取消
|
||||||
|
setCanceledOnTouchOutside(false);
|
||||||
|
setCancelable(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void show() {
|
||||||
|
super.show();
|
||||||
|
startAnimation();
|
||||||
|
updateContentVisibility();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 显示弹窗并设置消息(一步完成显示和设置消息)
|
||||||
|
*
|
||||||
|
* @param message 要显示的消息,为空或null时只显示动画
|
||||||
|
*/
|
||||||
|
public void showMessage(String message) {
|
||||||
|
setMessage(message);
|
||||||
|
show();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置加载消息(可单独调用,不自动显示弹窗)
|
||||||
|
*
|
||||||
|
* @param message 要显示的消息,为空或null时不显示文字内容
|
||||||
|
*/
|
||||||
|
public void setMessage(String message) {
|
||||||
|
if (mTextContent != null) {
|
||||||
|
mTextContent.setText(message != null ? message : "");
|
||||||
|
updateContentVisibility();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void dismiss() {
|
||||||
|
stopAnimation();
|
||||||
|
super.dismiss();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置返回键监听器
|
||||||
|
*
|
||||||
|
* @param listener 返回键监听器,返回true允许关闭弹窗,false拦截返回键
|
||||||
|
*/
|
||||||
|
public void setOnDialogBackListener(OnDialogBackListener listener) {
|
||||||
|
mOnDialogBackListener = listener;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 启动加载动画
|
||||||
|
*/
|
||||||
|
private void startAnimation() {
|
||||||
|
if (mLoadingIcon != null) {
|
||||||
|
mLoadingIcon.setVisibility(View.VISIBLE);
|
||||||
|
if (mAnimationDrawable != null && !mAnimationDrawable.isRunning()) {
|
||||||
|
mAnimationDrawable.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 停止加载动画
|
||||||
|
*/
|
||||||
|
private void stopAnimation() {
|
||||||
|
if (mAnimationDrawable != null && mAnimationDrawable.isRunning()) {
|
||||||
|
mAnimationDrawable.stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新内容区域的可见性
|
||||||
|
* 当有文字内容时:显示文字,隐藏装饰TextView
|
||||||
|
* 当无文字内容时:隐藏文字,显示装饰TextView
|
||||||
|
*/
|
||||||
|
private void updateContentVisibility() {
|
||||||
|
boolean hasContent = hasTextContent();
|
||||||
|
|
||||||
|
// 更新内容文字的可见性
|
||||||
|
if (mTextContent != null) {
|
||||||
|
mTextContent.setVisibility(hasContent ? View.VISIBLE : View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新装饰TextView的可见性
|
||||||
|
int decorationVisibility = hasContent ? View.GONE : View.VISIBLE;
|
||||||
|
if (mTextViewUp != null) {
|
||||||
|
mTextViewUp.setVisibility(decorationVisibility);
|
||||||
|
}
|
||||||
|
if (mTextViewDown != null) {
|
||||||
|
mTextViewDown.setVisibility(decorationVisibility);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查是否有文字内容需要显示
|
||||||
|
*
|
||||||
|
* @return true-有内容,false-无内容
|
||||||
|
*/
|
||||||
|
private boolean hasTextContent() {
|
||||||
|
return mTextContent != null
|
||||||
|
&& mTextContent.getText() != null
|
||||||
|
&& mTextContent.getText().length() > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理返回键事件,将控制权交给监听器
|
||||||
|
*/
|
||||||
|
@SuppressLint("GestureBackNavigation")
|
||||||
|
@Override
|
||||||
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||||
|
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||||
|
if (mOnDialogBackListener != null && !mOnDialogBackListener.isBack()) {
|
||||||
|
// 监听器返回false,拦截返回键
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return super.onKeyDown(keyCode, event);
|
||||||
|
}
|
||||||
|
return super.onKeyDown(keyCode, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回键监听器接口
|
||||||
|
*/
|
||||||
|
public interface OnDialogBackListener {
|
||||||
|
/**
|
||||||
|
* 是否允许返回并关闭弹窗
|
||||||
|
*
|
||||||
|
* @return true-允许返回并关闭弹窗,false-拦截返回键
|
||||||
|
*/
|
||||||
|
boolean isBack();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
After Width: | Height: | Size: 2.0 KiB |
|
After Width: | Height: | Size: 2.0 KiB |
|
After Width: | Height: | Size: 2.0 KiB |
|
After Width: | Height: | Size: 1.9 KiB |
|
After Width: | Height: | Size: 2.0 KiB |
|
After Width: | Height: | Size: 1.9 KiB |
|
After Width: | Height: | Size: 2.0 KiB |
|
After Width: | Height: | Size: 2.0 KiB |
|
After Width: | Height: | Size: 1.9 KiB |
|
After Width: | Height: | Size: 2.0 KiB |
|
After Width: | Height: | Size: 1.9 KiB |
|
After Width: | Height: | Size: 1.9 KiB |
|
|
@ -0,0 +1,12 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<solid android:color="#88000000"/>
|
||||||
|
<!--<corners android:radius="12px"/>-->
|
||||||
|
<padding
|
||||||
|
android:top="10dp"
|
||||||
|
android:bottom="10dp"
|
||||||
|
android:left="10dp"
|
||||||
|
android:right="10dp"
|
||||||
|
/>
|
||||||
|
<corners android:bottomLeftRadius="5dp" android:bottomRightRadius="5dp" android:topLeftRadius="5dp" android:topRightRadius="5dp"></corners>
|
||||||
|
</shape>
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<animation-list android:id="@+id/loading_animation" android:oneshot="false"
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<item android:duration="@integer/loading_anmi_durtion" android:drawable="@drawable/library_loading_1" />
|
||||||
|
<item android:duration="@integer/loading_anmi_durtion" android:drawable="@drawable/library_loading_2" />
|
||||||
|
<item android:duration="@integer/loading_anmi_durtion" android:drawable="@drawable/library_loading_3" />
|
||||||
|
<item android:duration="@integer/loading_anmi_durtion" android:drawable="@drawable/library_loading_4" />
|
||||||
|
<item android:duration="@integer/loading_anmi_durtion" android:drawable="@drawable/library_loading_5" />
|
||||||
|
<item android:duration="@integer/loading_anmi_durtion" android:drawable="@drawable/library_loading_6" />
|
||||||
|
<item android:duration="@integer/loading_anmi_durtion" android:drawable="@drawable/library_loading_7" />
|
||||||
|
<item android:duration="@integer/loading_anmi_durtion" android:drawable="@drawable/library_loading_8" />
|
||||||
|
<item android:duration="@integer/loading_anmi_durtion" android:drawable="@drawable/library_loading_9" />
|
||||||
|
<item android:duration="@integer/loading_anmi_durtion" android:drawable="@drawable/library_loading_10" />
|
||||||
|
<item android:duration="@integer/loading_anmi_durtion" android:drawable="@drawable/library_loading_11" />
|
||||||
|
<item android:duration="@integer/loading_anmi_durtion" android:drawable="@drawable/library_loading_12" />
|
||||||
|
</animation-list>
|
||||||
|
|
@ -0,0 +1,50 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:gravity="center_vertical|center_horizontal"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="180dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="@drawable/library_dialog_loading_bg_animation"
|
||||||
|
android:gravity="center"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tv_no_content_up"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_horizontal"
|
||||||
|
android:padding="2dp" />
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/music_loading_icon"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_horizontal"
|
||||||
|
android:src="@drawable/library_loading_anim" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tv_no_content_down"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_horizontal"
|
||||||
|
android:padding="2dp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/music_content"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_horizontal"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:gravity="center_vertical|center_horizontal"
|
||||||
|
android:padding="5dp"
|
||||||
|
android:singleLine="true"
|
||||||
|
android:textColor="#FFFFFF"
|
||||||
|
android:textSize="14dp" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<integer name="loading_anmi_durtion">60</integer>
|
||||||
|
</resources>
|
||||||
|
|
@ -25,4 +25,17 @@
|
||||||
<item name="android:windowExitAnimation">@anim/zoom_out</item>
|
<item name="android:windowExitAnimation">@anim/zoom_out</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
<!--从屏幕中间出场的动画样式-->
|
||||||
|
<style name="CenterDialogAnimationStyle" parent="Animation.AppCompat.Dialog">
|
||||||
|
<!-- 是否有标题-->
|
||||||
|
<item name="android:windowNoTitle">true</item>
|
||||||
|
<!--背景颜色及透明程度-->
|
||||||
|
<item name="android:windowBackground">@android:color/transparent</item>
|
||||||
|
<!--是否浮现在activity之上-->
|
||||||
|
<item name="android:windowIsFloating">true</item>
|
||||||
|
<!--是否模糊-->
|
||||||
|
<item name="android:backgroundDimEnabled">true</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
cf37179c5451ef8f324f85b6b5d5a609
|
ad674ab399963d77dbe3b30252397161
|
||||||
|
|
@ -1 +1 @@
|
||||||
0c2d562a65249d77b06a7aaf947961f5514357e2
|
02ba57a737b968b4ba275c994b34e3aaaf87e58a
|
||||||
|
|
@ -1 +1 @@
|
||||||
cd47b4b04dde3e9b942c69a93c5423e9f1161d72e4359cb1128263ec4ae32cee
|
24a19294eabb61a9ea38707038b0adc6ca6a84c397d88b1d90803109ff43d0f0
|
||||||
|
|
@ -1 +1 @@
|
||||||
e3bb60f0b568365870f244bb79152d5158a2a193af8a9f7d4036a88774ebbb545cf51f243971e84acd2a622f197c5201f39bd95acab27f418f1234800445bd21
|
daeb64e99aafa0c63bf4a2e8e01ef5855263e168c20c7f67835113962b592096f890486ce241a88939d8444c82ffccc6021af51453323ec2d54d8c279e4be9fa
|
||||||
|
|
@ -10,6 +10,6 @@
|
||||||
<version>1.0.1</version>
|
<version>1.0.1</version>
|
||||||
<version>1.1.0</version>
|
<version>1.1.0</version>
|
||||||
</versions>
|
</versions>
|
||||||
<lastUpdated>20260106091431</lastUpdated>
|
<lastUpdated>20260112010551</lastUpdated>
|
||||||
</versioning>
|
</versioning>
|
||||||
</metadata>
|
</metadata>
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
51c88f0916999049fb5a6fd98af37db6
|
890b378841c1dfa446e675ab4959e931
|
||||||
|
|
@ -1 +1 @@
|
||||||
49fdac034b8afac0df55d99d9ecc8b4c84a910ab
|
a680c4873b7d3b25fb4e1fcd2c3ea8ace4cdcc7c
|
||||||
|
|
@ -1 +1 @@
|
||||||
87b2089e46a4961bac0afaff94b899de0d19ea92ec09d9735a1decb905feb2bc
|
33343dcda6d86941c9a6c7345cca1a0c8891be557f59548c799eec028d56f6ff
|
||||||
|
|
@ -1 +1 @@
|
||||||
33b3eb3ce66bbf7f7b2ab4790243fdf44997c1c40f35a18514c5f7df45f71871d34fcb17eeba71c135b1d2b109b0136d4c42396f03eb2e79f18399c8a11d2370
|
ded7f88c2eae7902a703eca8a275bc0cc9bf4c8811df1b56bfa4c2e86efb2c4e95bcb26e47e2de54b69437dd6432c056970f10f38b2c0396c561decd170b388c
|
||||||