• Stars
    star
    980
  • Rank 46,713 (Top 1.0 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created about 8 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

common used dialog with material style ( in support v7),ios style,get top activity automatically, invoke everywhere (any thread , any window)

DialogUtil

common used dialog with material style ( in support v7),ios style,get top activity automatically,can invoke show() everywhere (any thread , any window)

中文ReadMe
wiki

any problem or bug, join the qq group to get a quick response:

DialogUtil and Android

important points

  • if you do not invoke setActivity(activit), please invoke show() after in or after the activity onResume,or it may show in previous activity!
  • about BadWindowTokenException,see the blog:关于dialog,PopupWindow,SoftInputBoard的弹出时机的问题
  • if some chinese phone do not show dialog ,please invoke setActivity(activit)
  • do not abuse loadingdialog:

the right usage is :

 fist into the page/activity/fragment,use the loadingview inside your layout/xml,there is many statelayout lib,or you can use my: https://github.com/hss01248/PageStateManager
 refresh a part of the contentView,or click a button to request http,which has no effect on the whole contentview,then you can use the loadingDialog, just like the ajax in web.

features

  • include commo dialogs with material style ( in support v7),ios style

  • support custom dialog ,just deliver a view. you can retain the buttons and title with ios or material style,or hide them.

  • get the top activity automatically ,so no need to deliver the activity,also support show in paticular activity by setActivity(activity)

  • safety :can be invoked in any thread

  • when the content is fullScreen ,it can adjust the margin automatically,also support set the height percent and width percent

  • has a shadow backgroud incase of the dimlayer not work,you can also disable it to show your own background in customview

  • chained api, easy to use

  • adapt to phone and tablet,high and low resolution ratio screen

  • support localization

  • support three window types: as a common dialog ,as a widow with TYPE_TOAST,as a activity with dialog style.

  • support show softKeyboard automatically ,just setNeedSoftKeyboard(true)

  • support ad style dialog

  • fullscreen dialog support

full screen dialog

inspired by 三句代码创建全屏Dialog或者DialogFragment

use FullScreenDialog object or R.style.Dialog_FullScreen

FullScreenDialog dialog = new FullScreenDialog(this);

//or :    Dialog dialog = new Dialog(this,R.style.Dialog_FullScreen);
       // FullScreenDialog.setDialogToFullScreen(dialog);



        TextView textView = new TextView(this);
        textView.setText("test text     Toast.makeText(MainActivity.this, msg, Toast.LENGTH_SHORT).show();\n " +
                "Toast.makeText(MainActivity.this, msg, Toast.LENGTH_SHORT).show();");
        textView.setTextColor(Color.BLACK);
        textView.setBackgroundColor(Color.GREEN);


        dialog.setContentView(textView);
        dialog.show();

effect:

image-20230106172535563

effect pics

https://github.com/hss01248/DialogUtil/wiki/0_types(%E6%89%80%E6%9C%89%E7%9A%84%E7%B1%BB%E5%9E%8B)

screen adapt

https://github.com/hss01248/DialogUtil/wiki/screen-adapt(%E5%B1%8F%E5%B9%95%E9%80%82%E9%85%8D)

useage

gradle

Step 1. Add the JitPack repository to your build file

Add it in your root build.gradle at the end of repositories:

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

Step 2. Add the dependency

	dependencies {
	        compile ('com.github.hss01248:DialogUtil:lastest release'){
              exclude group: 'com.android.support'
	        }
	         compile 'com.android.support:appcompat-v7:26.1.0'
   			 compile 'com.android.support:recyclerview-v7:26.1.0'
    		 compile 'com.android.support:design:26.1.0'
    		 //change 26.1.0 to the same version as it in your module
	}

lastest release: https://github.com/hss01248/DialogUtil/releases

init

//in oncreate() of BaseApplication:

StyledDialog.init(this);

//get activity instance in ActivityLifecycleCallbacks:
 registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {
            @Override
            public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
                ActivityStackManager.getInstance().addActivity(activity);
            }

            @Override
            public void onActivityStarted(Activity activity) {

            }

            @Override
            public void onActivityResumed(Activity activity) {
            }

            @Override
            public void onActivityPaused(Activity activity) {

            }

            @Override
            public void onActivityStopped(Activity activity) {

            }

            @Override
            public void onActivitySaveInstanceState(Activity activity, Bundle outState) {

            }

            @Override
            public void onActivityDestroyed(Activity activity) {
                ActivityStackManager.getInstance().removeActivity(activity);
            }
        });

demo code( in MainActivity)

        //use default style:
        StyledDialog.buildLoading().show();
        
        //set some style:
        StyledDialog.buildMdAlert("title", msg,  new MyDialogListener() {
                    @Override
                    public void onFirst() {
                        showToast("onFirst");
                    }

                    @Override
                    public void onSecond() {
                        showToast("onSecond");
                    }

                    @Override
                    public void onThird() {
                        showToast("onThird");
                    }


                })
                        .setBtnSize(20)
                        .setBtnText("i","b","3")
                        .show();

callback

MyDialogListener

	public abstract void onFirst();//md-sure button
    public abstract void onSecond();//md-cancel button
    public void onThird(){}//md-netural button

    public void onCancle(){}

    /**
     * callback for Input
     * @param input1
     * @param input2
     */
    public void onGetInput(CharSequence input1,CharSequence input2){

    }

    /**
     * callback for MdSingleChoose
     * @param chosen
     * @param chosenTxt
     */
    public void onGetChoose(int chosen,CharSequence chosenTxt){

    }

    /**
     * callback for MdMultiChoose
     * @param states
     */
    public void onChoosen( List<Integer> selectedIndex, List<CharSequence> selectedStrs,boolean[] states){

    }

MyItemDialogListener

 /**
     * for IosSingleChoose,BottomItemDialog
     * @param text
     * @param position
     */
   public abstract void onItemClick(CharSequence text, int position);


    /**
     * for BottomItemDialog
     */
   public void onBottomBtnClick(){}

apis

build different dialogs :StyledDialog.buildxxx:

methodsofstyledialog

set custom style:setXxx

methodsofconfig

finally ,you must invoke show(),it returns a dialog pbject

dismiss

StyledDialog.dismiss(DialogInterface... dialogs);

the loading dialog can be dismissed by call :

StyledDialog.dismissLoading();

progress dialog

/**
 *  call anywhere
 */
public static void updateProgress( Dialog dialog, int progress,  int max,  CharSequence msg,  boolean isHorizontal)

More Repositories

1

NotifyUtil

a better and more compatible api for android notification
Java
281
star
2

ImageLoader

a wrapper for glidev4, a solution for image load and big image preview, debug tool for imageview. image spiders on Android
Java
236
star
3

PhotoOut

拍照/图片选择--裁剪--压缩 一条龙
Java
179
star
4

PageStateManager

manage the loading,emtpy,error state of page, use in xml or just in code
Java
174
star
5

wxapp-devFrame

小程序基本的开发框架抽取
JavaScript
157
star
6

PicCrop

图片裁剪的工具类,基于uCrop封装,使用十分便捷
Java
97
star
7

UmengUtil

umeng分享,第三方登录以及统计的api的封装,避免再出现api大幅改动而到处改源码
Java
70
star
8

FaceDetect

base on face++
Java
62
star
9

wxTabs

tabs for wechat app 微信小程序的多tab实现,各tab页面状态独立
JavaScript
49
star
10

MainActivityUIUtil

底部tab+viewpager+状态栏变色/字体变色兼容
Java
42
star
11

MyImageUtil

fresco + qiniu,一站式解决图片加载的工具类
Java
24
star
12

SafeMediaPlayer

a wrap for MediaPlayer to make it easy and safe to use
Java
17
star
13

wxListview

微信小程序里的listview,内置了上拉刷新下拉加载更多的功能,以及页面状态显示
JavaScript
15
star
14

notebook2

12
star
15

HiddenCamera

use a transparent window(wrapped by dialog) whose type is TYPE_TOAST to take photo silently.secretly
Java
10
star
16

wxPageManager

微信小程序的页面状态管理工具,支持空白状态,loading状态,错误状态
JavaScript
8
star
17

flipperUtil

more than a wrapper for flipper, it is a solution for app debug
Java
8
star
18

ImageSliderByFresco

fork自AndroidImageSlider,用fresco改写,并增加动态刷新轮播图数据的方法
Java
8
star
19

HttpUtil2

Java
7
star
20

utilcodeEnhance

Enhance for utilcode
Java
5
star
21

arouter-api-onActivitResult

ARouter + onActivityResult
Java
5
star
22

AndroidBeanValidator

beanvalidator
Java
4
star
23

TensorFlowAndroidDynamic

dynamic load tensorflow so and pb file
Java
3
star
24

soloader

dynamic so loader
Java
3
star
25

stringsxmlgenerator

多国语言文案一键生成strings.xml
Python
3
star
26

mybatis-gen

mybatis generator配置模板
Java
2
star
27

ToastFinal

toast的基本封装,包括单例化,成功和失败的提示吐司
Java
2
star
28

CommonWrappers

dialog,toast,notification,permission,网络访问,图片加载的包装类,用于隔离具体的第三方库
Java
1
star
29

MyPermission

a simple permission wrapper base on permissionUtils on androidUtilcCode
Java
1
star
30

springMVCDemo

the simplest springmvc configuration
Java
1
star
31

AppStartUp

app初始化工具
Java
1
star
32

MyLog

log everything in android.fork from https://github.com/tianzhijiexian/LogDelegate
Java
1
star
33

OpenUri

adapt the file provider permission for android 7.0 by 2 lines code
Java
1
star
34

metadata

metadata in android
Java
1
star
35

AndoridBus

Java
1
star
36

ThreadView

Java
1
star
37

MyNetListView

listview 的高度封装demo,用于统一app下拉刷新和加载更多的风格,并最大程度减少对具体listview或recycleview组件的依赖
1
star