Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
huangshuisheng committed May 5, 2017
2 parents 94c6c47 + e2b923f commit 6071e4c
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ final ConfigBean bean = StyledDialog.buildCustom(customView, Gravity.CENTER);
final Dialog dialog1 = bean.show();
```

![customview-webview](img0\customview-webview.jpg)
![customview-webview](img0/customview-webview.jpg)



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,16 +223,21 @@ public void onStop() {
@OnClick({R.id.btn_common_progress, R.id.btn_context_progress, R.id.btn_material_alert, R.id.btn_ios_alert,
R.id.btn_ios_alert_vertical, R.id.btn_ios_bottom_sheet, R.id.btn_ios_center_list,R.id.btn_input,
R.id.btn_multichoose, R.id.btn_singlechoose,R.id.btn_md_bs,R.id.btn_md_bs_listview,R.id.btn_md_bs_Gridview,
R.id.btn_context_progress_h,R.id.btn_context_progress_c,R.id.btn_customview})
R.id.btn_context_progress_h,R.id.btn_context_progress_c,R.id.btn_customview,R.id.btn_dismiss})
public void onClick(View view) {
switch (view.getId()) {
case R.id.btn_dismiss:
StyledDialog.dismissLoading();
break;
case R.id.btn_common_progress:
new Thread(new Runnable() {
@Override
public void run() {
StyledDialog.buildLoading( "加载中...").show();
}
}).run();
StyledDialog.dismissLoading();
showToast("dismissLoading() called ");

new Timer().schedule(new TimerTask() {
@Override
Expand All @@ -248,7 +253,7 @@ public void run() {
gloablDialog = StyledDialog.buildMdLoading().show();



//StyledDialog.dismissLoading();

handler.postDelayed(new Runnable() {
@Override
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/btn_dismiss"
android:layout_margin="5dp"
android:visibility="gone"
android:text="关闭loading"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<Button
android:id="@+id/btn_common_progress"
android:layout_margin="5dp"
Expand Down
31 changes: 26 additions & 5 deletions dialog/src/main/java/com/hss01248/dialog/StyledDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,17 @@ public static DialogInterface getLoadingDialog() {
}

private static DialogInterface loadingDialog;//缓存加载中的dialog,便于以后可以不需要对象就让它消失
private static TextView tv_msg;
private static long startTime;

/**
* 内部使用
* @param tv_msg
*/
public static void setTv_msg(TextView tv_msg) {
StyledDialog.tv_msg = tv_msg;
}

private static TextView tv_msg;

private static boolean isMiUi8 = false;//miui8用非activity的Context时,无法以TYPE_TOAST的形式弹出对话框.没有好的解决办法.....

public static Handler getMainHandler() {
Expand All @@ -61,9 +65,14 @@ public static void init(Context context){

}

public static void setLoadingObj(DialogInterface loading){
/**
* 内部使用
*/
public static void setLoadingObj( DialogInterface loading){

dismiss(loadingDialog);
loadingDialog = loading;
startTime = System.currentTimeMillis();
if(loading==null){
tv_msg=null;
}
Expand All @@ -78,8 +87,20 @@ public static void setLoadingObj(DialogInterface loading){
public static void dismissLoading(){
if (loadingDialog != null ){
tv_msg=null;
dismiss(loadingDialog);
loadingDialog = null;
long timePassed = System.currentTimeMillis() - startTime;
if(timePassed >= 500){//500ms
dismiss(loadingDialog);
loadingDialog = null;
}else {
getMainHandler().postDelayed(new Runnable() {
@Override
public void run() {
dismiss(loadingDialog);
loadingDialog = null;
}
},500 -timePassed);
}

}
}

Expand Down

0 comments on commit 6071e4c

Please sign in to comment.