Code Monkey home page Code Monkey logo

dialogutil's Introduction

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)

dialogutil's People

Contributors

hss01248 avatar sky-walkrr 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dialogutil's Issues

又发现一个bug不显示菊花请看图

1111

菊花弹不出来·debug 已经 打印 都走了·但是就显示不出来· 然而魅族 MX6 上又可以显示出来··· 还有就是我下面画红线的那个 dialog 是另外的一个·他就可以在别的机子上弹出来·

请加多一个构造方法 如下图

qq 20170913211031

代码如下:
@OverRide
public ConfigBean setBtnText(CharSequence positiveTxt) {
return setBtnText(positiveTxt,"");
}

另外就是把弹出的 对话框 稍微小一点吧·这里可以 当做 很多地方用例如 条件不满足的情况下就可以弹出来·提示 然后就只有一个确认按钮 爽多了·如果 弹出的框太大 ·就不好看了···或者暴露出一个 修改 边距 paiding 之类的 接口也可以

距离屏幕的左右边距能否自己设置

目前非底部的弹窗感觉离屏幕太近.

还有按钮有能看出来的淡灰色圆边框;
标题为null的时候能否隐藏掉标题部分,因为标题加粗了,不想要加粗的标题只能放到内容里,但标题为null目前依旧占位;

buildNormalInput

buildNormalInput 如何只显示一个输入框呢 现在只需要显示一个

您好辛苦了:StyledDialog.buildBottomSheetGv()这个有bug

正常show以后,用手指下滑,这个弹窗会消失——问题来了:当再次show的时候,就不再显示了(但是界面会有遮罩,只是弹窗不显示);
重新进界面则可以显示(provinceDialog重新创建了实例),但假设我不进行下滑把弹窗弄没,而是按返回键,则没有这个bug的

�代码如下:
` if (provinceDialog == null) {
int columnsNum = 3;
List datas = new ArrayList<>();
datas.add(new BottomSheetBean(R.mipmap.ic_launcher,"1"));
datas.add(new BottomSheetBean(R.mipmap.ic_launcher,"222"));
datas.add(new BottomSheetBean(R.mipmap.ic_launcher,"333333"));
datas.add(new BottomSheetBean(R.mipmap.ic_launcher,"444"));
datas.add(new BottomSheetBean(R.mipmap.ic_launcher,"55"));
datas.add(new BottomSheetBean(R.mipmap.ic_launcher,"666"));

        datas.add(new BottomSheetBean(R.mipmap.ic_launcher,"7777"));
        datas.add(new BottomSheetBean(R.mipmap.ic_launcher,"fddsf"));
        datas.add(new BottomSheetBean(R.mipmap.ic_launcher,"67gfhfg"));
        datas.add(new BottomSheetBean(R.mipmap.ic_launcher,"oooooppp"));

        ConfigBean configBean = StyledDialog.buildBottomSheetGv("title", datas, "bottomTxt", columnsNum, new MyItemDialogListener() {
            @Override
            public void onItemClick(CharSequence charSequence, int i) {
                LogUtil.d(TAG,"onItemClick(),charSequence:"+ charSequence + "/// i:"+i);
            }
        });
        provinceDialog = configBean.show();
    }else
        provinceDialog.show();`

is fail to set cancelable and outsideTouchable

like:

public ConfigBean assignLoading(Context context, CharSequence msg, boolean cancleable, boolean outsideTouchable) {
        ConfigBean bean = new ConfigBean();
        bean.context = context;
        bean.msg = msg;
        bean.type = 14;
        return bean;
    }

the cancleable and outsideTouchable is not use in these functions, and the bean's setCancelable also not use.

Dialog显示问题

StyledDialog.buildLoading().setActivity(mContext).show()或StyledDialog.buildLoading().show() 立即调用 StyledDialog.dismissLoading();取消不掉Dialog,使用情景是:初始化调用show();然后读取数据库的数据,有则加载数据,然后立即dismissLoading() 没有成功dismiss,否则加载网络数据在dismissLoading()。加载网络数据的回调中dismissLoading()能成功dismiss掉。

onGetInput 输入框,怎么获取输入到的内容呢?

我设定一个全局变量,在onGetInput这个方法里面,赋值,然后,再在onSecond或者onFirst里获取这个变量,没法获取呢?null。而且,在onGetInput 里输出toast也获取不到输入内容。是我用的方式不对?跟你的例子一摸一样啊???

androidTV的适配

对androidTV的适配不是特别好,主要是焦点的问题处理上,我期待的功能:

  1. 当show()的时候焦点默认在第一个可选项上,也可自定
    2.当dismiss()的时候焦点回到show()之前的控件之上
    3.对选项btn的焦点样式配置

现在在其他Activity界面调用的 Dialog 只显示在 第一层 Activity ,不会显示在当前调用的Activity 界面上。

现在在其他Activity界面调用的 Dialog 只显示在 第一层 Activity ,不会显示在当前调用的Activity 界面上。

比如 我从MainActivity(第一层 Activity) 跳转到 SecondActivity,然后再 SecondActivity执行 StyledDialog.buildLoading,结果SecondActivity没有弹出 Dialog,然后按返回键回到 MainActivity,发现Dialog显示在了MainActivit上。

请问是我哪里没设置好,还是bug 啊?

进度条闪屏

在从主页跳转到其他页面时,菊花进度条导致屏幕闪烁,就是突然一黑那种,不加没问题

新电脑的新环境导入时的失败

compileSdkVersion 25
buildToolsVersion '25.0.2'
    minSdkVersion 15
    targetSdkVersion 25

distributionUrl=https://services.gradle.org/distributions/gradle-4.0-rc-1-all.zip
classpath 'com.android.tools.build:gradle:3.0.0-alpha4'
Android Studio 3.0 Canary 4

导入项目的时候,DialogUtil:1.1.3 - DialogUtil:1.1.5都会定位到
<style name="mystyle" parent="android:Animation">
@anim/dialog_enter //进入时的动画
@anim/dialog_exit //退出时的动画

Messages提示
style attribute '@android:attr/windowEnterAnimation' not found
style attribute '@android:attr/windowExitAnimation' not found

Error:Execution failed for task ':app:processDebugResources'.

Failed to execute aapt

多个dialogDismiss不会消失

把buildloading放在网络请求开始前,把dissmissloading放在请求结束后,但是同时进行多个网络请求的时候会出现loading无法消失的问题,这种情况多出现在fragment中

项目依赖不通啊

dependencies {
compile 'com.github.hss01248:DialogUtil:1.0.4'
}
依赖连接不上,能否看下

偶发性的崩溃

在activity的button点击事件中,弹出提示的dialog
StyledDialog.buildLoading("加载中...").show();
的时候会偶发性的崩溃:java.lang.IllegalArgumentException: View not attached to window manager

点击buildLoading的小菊花会崩溃

java.lang.IllegalStateException: Could not find method onGifClick(View) in a parent or ancestor Context for android:onClick attribute defined on view class com.hss01248.dialog.view.GifMovieView with id 'iv_loading'

报错 has leaked window com.android.internal.policy.PhoneWindow$DecorView

作者您好,根据您的Demo,将setCurrentActivity放在base类中获取顶层activity,发现会出现has leaked window com.android.internal.policy.PhoneWindow$DecorView的bug,我debug跟踪了一下,发现是添加了activity引用之后,在窗体关闭之后,dialog还持有之前窗体的引用造成的,建议:可以添加针对activity的监听,生命周期同传入的activity;

自定义布局弹窗里面布局宽度设置无效

ViewGroup customView = (ViewGroup) View.inflate(MainActivity.this,R.layout.loadingnew,null);
StyledDialog.buildCustom(customView, Gravity.CENTER).show();
其中布局的宽度是100 但是最后显示出来的还是默认的很宽

显示文字msg的建议

StyledDialog.buildLoading("初始化...").show();有必要加个方法来动态的修改msg,比如我loading提示进度百分数。。

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.