Giter Site home page Giter Site logo

maning0303 / mnprogresshud Goto Github PK

View Code? Open in Web Editor NEW
400.0 12.0 68.0 1.63 MB

一个常用的自定义弹框封装(适配AndroidX),加载ProgressDialog,状态显示的StatusDialog和自定义Toast,全部支持背景颜色,圆角,边框和文字的自定义,构建者模式,链式调用。

License: Apache License 2.0

Java 100.00%

mnprogresshud's Introduction

MNProgressDialog

一个常用的自定义弹框封装(适配AndroidX),加载ProgressDialog,状态显示的StatusDialog和自定义Toast,全部支持背景颜色,圆角,边框和文字的自定义,构建者模式,链式调用。

截图:

MProgressDialog

MProgressBarDialog (水平进度条和圆形进度条)

MStatusDialog

MSToast

如何添加

1:Gradle添加:

1.在Project的build.gradle中添加仓库地址

    allprojects {
    	repositories {
    		...
    		maven { url "https://jitpack.io" }
    	}
    }

2.在app目录下的build.gradle中添加依赖

    //android support library
    dependencies {
        implementation 'com.android.support:appcompat-v7:28.0.0'
        implementation 'com.android.support:support-v4:28.0.0'
        implementation 'com.github.maning0303:MNProgressHUD:V2.0.0'
    }

    //android x 适配
    dependencies {
        implementation 'androidx.appcompat:appcompat:1.1.0'
        implementation 'androidx.legacy:legacy-support-v4:1.0.0'
        implementation 'com.github.maning0303:MNProgressHUD:V2.0.0X'
    }

2:源码Module添加:

直接关联mndialoglibrary(需要 android x 适配,切换到androidx分支。)

    implementation project(':mndialoglibrary')

使用方法(查看Demo详情):

1:MProgressDialog 加载Dialog代码使用:

        
        //默认
        MProgressDialog.showProgress(this);
        //自定义文字
        MProgressDialog.showProgress(this,"自定义文字");
        //不需要文字
        MProgressDialog.showProgress(this,"");
        
        //自定义背景
        MDialogConfig mDialogConfig = new MDialogConfig.Builder()
                 //设置dialog最小宽度和最小高度
                 .setMinWidthAndHeight(50,50)
                 //全屏模式
                 .isWindowFullscreen(true)
                 //Progress大小(宽高)
                 .setProgressSize(60)
                 //点击外部是否可以取消
                 .isCanceledOnTouchOutside(true)
                 //物理返回键可以取消
                 .isCancelable(true)
                 //全屏背景窗体的颜色
                 .setBackgroundWindowColor(getMyColor(R.color.colorDialogWindowBg))
                 //View背景的颜色
                 .setBackgroundViewColor(getMyColor(R.color.colorDialogViewBg))
                 //View背景的圆角
                 .setCornerRadius(20)
                 //View 边框的颜色
                 .setStrokeColor(getMyColor(R.color.colorAccent))
                 //View 边框的宽度
                 .setStrokeWidth(2)
                 //Progress 颜色
                 .setProgressColor(getMyColor(R.color.colorDialogProgressBarColor))
                 //Progress 宽度
                 .setProgressWidth(3)
                 //Progress 内圈颜色
                 .setProgressRimColor(Color.YELLOW)
                 //Progress 内圈宽度
                 .setProgressRimWidth(4)
                 //文字的颜色
                 .setTextColor(getMyColor(R.color.colorDialogTextColor))
                 //ProgressBar 颜色
                 .setProgressColor(Color.GREEN)
                 //dialog动画
                 .setAnimationID(R.style.animate_dialog_custom)
                 //文字的大小:sp
                 .setTextSize(15)
                 //padding
                 .setPadding(40, 10, 40, 10)
                 //关闭的监听
                 .setOnDialogDismissListener(new OnDialogDismissListener() {
                     @Override
                     public void onDismiss() {
                         MToast.makeTextShort(mContext,"监听到了ProgressDialog关闭了");
                     }
                 })
                 .build();
        MProgressDialog.showProgress(this,"数据上传中...",mDialogConfig);

2:MStatusDialog 状态Dialog代码使用:

        //默认
        MStatusDialog mStatusDialog = new MStatusDialog(this);
        //显示
        mStatusDialog.show("保存成功", mContext.getResources().getDrawable(R.drawable.mn_icon_dialog_ok));
        //手动取消
        mStatusDialog.dismiss();
        
        //自定义
        MDialogConfig mDialogConfig = new MDialogConfig.Builder()
                        //全屏模式
                        .isWindowFullscreen(true)
                        //全屏背景窗体的颜色
                        .setBackgroundWindowColor(getMyColor(R.color.colorDialogWindowBg))
                        //View背景的颜色
                        .setBackgroundViewColor(getMyColor(R.color.colorDialogViewBg2))
                        //字体的颜色
                        .setTextColor(getMyColor(R.color.colorAccent))
                        //View边框的颜色
                        .setStrokeColor(getMyColor(R.color.white))
                        //View边框的宽度
                        .setStrokeWidth(2)
                        //View圆角大小
                        .setCornerRadius(10)
                        //dialog动画
                        .setAnimationID(R.style.animate_dialog_custom)
                        //文字的大小sp
                        .setTextSize(15)
                        //paddingdp
                        .setPadding(40, 10, 40, 10)
                        //图片的宽高dp
                        .setImgWidthAndHeight(60, 60)
                        //关闭的监听
                        .setOnDialogDismissListener(new OnDialogDismissListener() {
                            @Override
                            public void onDismiss() {
                                MToast.makeTextShort(mContext,"监听到了MStatusDialog关闭了");
                            }
                        })
                        .build();
        new MStatusDialog(mContext,mDialogConfig).show("提交数据失败,请重新尝试!", mContext.getResources().getDrawable(R.mipmap.ic_launcher), 1000);

3:MToast 代码使用:

        MToastConfig config = new MToastConfig.Builder()
                //设置显示的位置
                .setGravity(MToastConfig.MToastGravity.CENTRE)
                //文字的颜色
                .setTextColor(getMyColor(R.color.colorAccent))
                //背景色
                .setBackgroundColor(getMyColor(R.color.colorDialogTest))
                //背景圆角
                .setBackgroundCornerRadius(10)
                //背景边框的颜色
                .setBackgroundStrokeColor(Color.WHITE)
                //背景边框的宽度
                .setBackgroundStrokeWidth(1)
                //文字的大小:sp
                .setTextSize(15)
                //padding
                .setPadding(40, 10, 40, 10)
                //图片的宽高dp
                .setImgWidthAndHeight(60, 60)
                .build();

        //多种方法
        MToast.makeTextShort(mContext, "Toast", config);
        MToast.makeTextShort(mContext, "Toast");
        
        //取消Toast
        MToast.cancleToast();

4:MProgressBarDialog 进度条Dialog代码使用:

        //新建一个Dialog
        mProgressBarDialog = new MProgressBarDialog.Builder(mContext)
               //全屏模式
               .isWindowFullscreen(true)
               .setStyle(MProgressBarDialog.MProgressBarDialogStyle_Circle)
               //全屏背景窗体的颜色
               .setBackgroundWindowColor(getMyColor(R.color.colorDialogWindowBg))
               //View背景的颜色
               .setBackgroundViewColor(getMyColor(R.color.colorDialogViewBg2))
               //字体的颜色
               .setTextColor(getMyColor(R.color.colorAccent))
               //View边框的颜色
               .setStrokeColor(getMyColor(R.color.white))
               //View边框的宽度
               .setStrokeWidth(2)
               //View圆角大小
               .setCornerRadius(10)
               //ProgressBar背景色
               .setProgressbarBackgroundColor(Color.BLUE)
               //ProgressBar 颜色
               .setProgressColor(Color.GREEN)
               //圆形内圈的宽度
               .setCircleProgressBarWidth(4)
               //圆形外圈的宽度
               .setCircleProgressBarBackgroundWidth(4)
               //水平进度条Progress圆角
               .setProgressCornerRadius(0)
               //水平进度条的高度
               .setHorizontalProgressBarHeight(10)
               //dialog动画
               .setAnimationID(R.style.animate_dialog_custom)
               .build();
       /**
        * 显示dialog
        *
        * @param progress       当前进度
        * @param secondProgress 二级进度
        * @param message        消息体
        * @param animate        是否平滑过度动画
        */
        mMProgressDialog.showProgress(int progress,int secondProgress, String message, boolean animate);

版本记录:

V2.0.0:
    1.修复动画不居中问题
    2.监听dialog消失方法优化
    3.MProgressDialog添加最小宽度和最小高度的设置
    4.MProgressDialog默认不显示文字

V1.1.9:
    1.当设置应用的theme背景为黑色后,加载框会覆盖覆盖全屏,是全屏变黑 问题优化
    2.MToast支持异步线程
    3.去掉FragmentDialog

感谢:

源码里面使用了下面库,改了个名字,以免冲突,非常感谢!

推荐:

Name Describe
GankMM (Material Design & MVP & Retrofit + OKHttp & RecyclerView ...)Gank.io Android客户端:每天一张美女图片,一个视频短片,若干Android,iOS等程序干货,周一到周五每天更新,数据全部由 干货集中营 提供,持续更新。
MNUpdateAPK Android APK 版本更新的下载和安装,适配7.0,8.0,简单方便。
MNImageBrowser 交互特效的图片浏览框架,微信向下滑动动态关闭
MNCalendar 简单的日历控件练习,水平方向日历支持手势滑动切换,跳转月份;垂直方向日历选取区间范围。
MClearEditText 带有删除功能的EditText
MNCrashMonitor Debug监听程序崩溃日志,展示崩溃日志列表,方便自己平时调试。
MNProgressHUD MNProgressHUD是对常用的自定义弹框封装,加载ProgressDialog,状态显示的StatusDialog和自定义Toast,支持背景颜色,圆角,边框和文字的自定义。
MNXUtilsDB xUtils3 数据库模块单独抽取出来,方便使用。
MNVideoPlayer SurfaceView + MediaPlayer 实现的视频播放器,支持横竖屏切换,手势快进快退、调节音量,亮度等。------代码简单,新手可以看一看。
MNZXingCode 快速集成二维码扫描和生成二维码
MNChangeSkin Android夜间模式,通过Theme实现
SwitcherView 垂直滚动的广告栏文字展示。
MNPasswordEditText 类似微信支付宝的密码输入框。
MNSwipeToLoadDemo 利用SwipeToLoadLayout实现的各种下拉刷新效果(饿了吗,京东,百度外卖,美团外卖,天猫下拉刷新等)。

mnprogresshud's People

Contributors

maning0303 avatar qqzhangqingqq avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mnprogresshud's Issues

这里有个空指针异常

java.lang.NullPointerException: Attempt to read from field 'int com.maning.mndialoglibrary.MProgressBarDialog$Builder.style' on a null object reference
at com.maning.mndialoglibrary.MProgressBarDialog.showProgress(MProgressBarDialog.java:190)
at com.maning.mndialoglibrary.MProgressBarDialog.showProgress(MProgressBarDialog.java:174)
at package name.BackUpActivity$11.onProgress(BackUpActivity.java:1070)
at me.jessyan.progressmanager.body.ProgressResponseBody$1$1.run(ProgressResponseBody.java:119)
at android.os.Handler.handleCallback(Handler.java:743)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:150)
at android.app.ActivityThread.main(ActivityThread.java:5546)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:682)
这个问题碰到过几次 有时showProgress的时候就会出现

在上一个progress还没关闭之前又打开一个progress的话,会报错

Process: com.maning.mnprogressdialog, PID: 29915
java.lang.NullPointerException: Attempt to read from field 'int com.maning.mndialoglibrary.config.MDialogConfig.animationID' on a null object reference
at com.maning.mndialoglibrary.MProgressDialog.configView(MProgressDialog.java:82)
at com.maning.mndialoglibrary.MProgressDialog.initDialog(MProgressDialog.java:67)
at com.maning.mndialoglibrary.MProgressDialog.showProgress(MProgressDialog.java:157)
at com.maning.mndialoglibrary.MProgressDialog.showProgress(MProgressDialog.java:139)
at com.maning.mnprogressdialog.MainActivity$2.run(MainActivity.java:211)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6776)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1518)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408)

混淆规则

如果开启混淆,有什么不能加入混淆的么?

空指针异常

快速点击的时候出现了
java.lang.NullPointerException: Attempt to read from field 'int com.maning.mndialoglibrary.config.MDialogConfig.animationID' on a null object reference
at com.maning.mndialoglibrary.MProgressDialog.configView(MProgressDialog.java:81)
at com.maning.mndialoglibrary.MProgressDialog.initDialog(MProgressDialog.java:66)
at com.maning.mndialoglibrary.MProgressDialog.showProgress(MProgressDialog.java:120)
at com.maning.mndialoglibrary.MProgressDialog.showProgress(MProgressDialog.java:106)
atxxxxxxx.onClick(RankActivity.java:277)
at xxxxx_ViewBinding$1.doClick(RankActivity_ViewBinding.java:45)
at butterknife.internal.DebouncingOnClickListener.onClick(DebouncingOnClickListener.java:22)
at android.view.View.performClick(View.java:4809)
at android.view.View$PerformClick.run(View.java:20006)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5321)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:963)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:758)

建议加一个取消监听。

既然有了可以点击外部取消。希望继续把取消的监听暴露出来,
举个栗子一个场景,我在请求接口的时候调用progressDialog 设置了可取消的属性,当dialog取消的时候直接把请求的接口也取消掉。 最后,感谢作者提供这么好的裤子,为我们减少了造轮子的时间。感谢!

关于MProgressBarDialog平滑过渡

请问在MProgressBarDialog加载的时候能否平滑过渡呢?比如从1%加载到10%,用动画平滑过渡,而不是目前较生硬的展示方式

mDialogConfig可能为空

//判断是不是有监听
if(mDialogConfig != null && mDialogConfig.onDialogDismissListener != null){
mDialogConfig.onDialogDismissListener.onDismiss();
}

show方法显示不出来

MProgressDialog.Builder a = new MProgressDialog.Builder(this)
.isCanceledOnTouchOutside(true);
a.show();

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.