项目作者: hss01248

项目描述 :
common used dialog with material style ( in support v7),ios style,get top activity automatically, invoke everywhere (any thread , any window)
高级语言: Java
项目地址: git://github.com/hss01248/DialogUtil.git
创建时间: 2016-09-23T06:01:21Z
项目社区:https://github.com/hss01248/DialogUtil

开源协议:Apache License 2.0

下载


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 :

  1. 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
  2. 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

  1. FullScreenDialog dialog = new FullScreenDialog(this);
  2. //or : Dialog dialog = new Dialog(this,R.style.Dialog_FullScreen);
  3. // FullScreenDialog.setDialogToFullScreen(dialog);
  4. TextView textView = new TextView(this);
  5. textView.setText("test text Toast.makeText(MainActivity.this, msg, Toast.LENGTH_SHORT).show();\n " +
  6. "Toast.makeText(MainActivity.this, msg, Toast.LENGTH_SHORT).show();");
  7. textView.setTextColor(Color.BLACK);
  8. textView.setBackgroundColor(Color.GREEN);
  9. dialog.setContentView(textView);
  10. dialog.show();

effect:

@main/imagemac3/image-20230106172535563.png" alt="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:

  1. allprojects {
  2. repositories {
  3. ...
  4. maven { url "https://jitpack.io" }
  5. }
  6. }

Step 2. Add the dependency

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

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

init

  1. //in oncreate() of BaseApplication:
  2. StyledDialog.init(this);
  3. //get activity instance in ActivityLifecycleCallbacks:
  4. registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {
  5. @Override
  6. public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
  7. ActivityStackManager.getInstance().addActivity(activity);
  8. }
  9. @Override
  10. public void onActivityStarted(Activity activity) {
  11. }
  12. @Override
  13. public void onActivityResumed(Activity activity) {
  14. }
  15. @Override
  16. public void onActivityPaused(Activity activity) {
  17. }
  18. @Override
  19. public void onActivityStopped(Activity activity) {
  20. }
  21. @Override
  22. public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
  23. }
  24. @Override
  25. public void onActivityDestroyed(Activity activity) {
  26. ActivityStackManager.getInstance().removeActivity(activity);
  27. }
  28. });

demo code( in MainActivity)

  1. //use default style:
  2. StyledDialog.buildLoading().show();
  3. //set some style:
  4. StyledDialog.buildMdAlert("title", msg, new MyDialogListener() {
  5. @Override
  6. public void onFirst() {
  7. showToast("onFirst");
  8. }
  9. @Override
  10. public void onSecond() {
  11. showToast("onSecond");
  12. }
  13. @Override
  14. public void onThird() {
  15. showToast("onThird");
  16. }
  17. })
  18. .setBtnSize(20)
  19. .setBtnText("i","b","3")
  20. .show();

callback

MyDialogListener

  1. public abstract void onFirst();//md-sure button
  2. public abstract void onSecond();//md-cancel button
  3. public void onThird(){}//md-netural button
  4. public void onCancle(){}
  5. /**
  6. * callback for Input
  7. * @param input1
  8. * @param input2
  9. */
  10. public void onGetInput(CharSequence input1,CharSequence input2){
  11. }
  12. /**
  13. * callback for MdSingleChoose
  14. * @param chosen
  15. * @param chosenTxt
  16. */
  17. public void onGetChoose(int chosen,CharSequence chosenTxt){
  18. }
  19. /**
  20. * callback for MdMultiChoose
  21. * @param states
  22. */
  23. public void onChoosen( List<Integer> selectedIndex, List<CharSequence> selectedStrs,boolean[] states){
  24. }

MyItemDialogListener

  1. /**
  2. * for IosSingleChoose,BottomItemDialog
  3. * @param text
  4. * @param position
  5. */
  6. public abstract void onItemClick(CharSequence text, int position);
  7. /**
  8. * for BottomItemDialog
  9. */
  10. 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

  1. StyledDialog.dismiss(DialogInterface... dialogs);

the loading dialog can be dismissed by call :

  1. StyledDialog.dismissLoading();

progress dialog

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