Skip to content

Commit

Permalink
CommonDialog
Browse files Browse the repository at this point in the history
CommonDialog
  • Loading branch information
maqiang committed Sep 20, 2018
1 parent 356a7a8 commit ef9aa0e
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 203 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import org.ninetripods.mq.study.R;
import org.ninetripods.mq.study.popup.dialog.DialogUtil;

public class CommonDialogActivity extends BaseActivity implements IDialog.OnBuildListener {
public class CommonDialogActivity extends BaseActivity {
private SYDialog dialog;

@Override
Expand Down Expand Up @@ -54,7 +54,7 @@ public void showDefaultDialog(View view) {
DialogUtil.createDefaultDialog(this, "我是标题", "你好,我们将在30分钟处理,稍后通知您订单结果!",
"", new IDialog.OnClickListener() {
@Override
public void onClick(IDialog dialog) {
public void onClick(IDialog dialog) {
dialog.dismiss();
}
});
Expand Down Expand Up @@ -91,45 +91,44 @@ public void onClick(IDialog dialog) {
* @param view View
*/
public void showBaseUseDialog(View view) {
view.setId(R.id.btn_ok);
new SYDialog.Builder(this)
.setDialogView(R.layout.dialog_phone_login)
.setAnimStyle(R.style.translate_style)
.setScreenWidthP(0.8f)
.setGravity(Gravity.CENTER)
.setWindowBackgroundP(0.2f)
.setCancelable(true)
.setCancelableOutSide(true)
.setBuildChildListener(this)
.show();
}

@Override
public void onBuildChildView(final IDialog dialog, View view, int layoutRes) {
switch (layoutRes) {
case R.layout.layout_dialog:
final EditText editText = view.findViewById(R.id.et_content);
Button btn_ok = view.findViewById(R.id.btn_ok);
btn_ok.setOnClickListener(new View.OnClickListener() {
.setDialogView(R.layout.layout_dialog)//设置dialog布局
.setAnimStyle(R.style.translate_style)//设置动画 默认没有动画
.setScreenWidthP(0.85f) //设置屏幕宽度比例 0.0f-1.0f
.setGravity(Gravity.CENTER)//设置Gravity
.setWindowBackgroundP(0.2f)//设置背景透明度 0.0f-1.0f 1.0f完全不透明
.setCancelable(true)//设置是否屏蔽物理返回键 true不屏蔽 false屏蔽
.setCancelableOutSide(true)//设置dialog外点击是否可以让dialog消失
.setBuildChildListener(new IDialog.OnBuildListener() {
//设置子View
@Override
public void onClick(View v) {
String editTextStr = null;
if (!TextUtils.isEmpty(editText.getText())) {
editTextStr = editText.getText().toString();
}
dialog.dismiss();
Toast.makeText(MyApplication.getApplication(), editTextStr, Toast.LENGTH_SHORT).show();
public void onBuildChildView(final IDialog dialog, View view, int layoutRes) {
//dialog: IDialog
//view: DialogView
//layoutRes :Dialog的资源文件 如果一个Activity里有多个dialog 可以通过layoutRes来区分
final EditText editText = view.findViewById(R.id.et_content);
Button btn_ok = view.findViewById(R.id.btn_ok);
btn_ok.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String editTextStr = null;
if (!TextUtils.isEmpty(editText.getText())) {
editTextStr = editText.getText().toString();
}
dialog.dismiss();
Toast.makeText(MyApplication.getApplication(), editTextStr, Toast.LENGTH_SHORT).show();
}
});
}
});
break;
}
}).show();
}

/**
* 4、展示进度条
*
* @param view View
*/

public void showLoadingDialog(View view) {
DialogUtil.createLoadingDialog(this);
new Handler().postDelayed(new Runnable() {
Expand Down Expand Up @@ -362,6 +361,7 @@ public ShareHolder(View itemView) {
ll_share = itemView.findViewById(R.id.ll_share);
}
}

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static void createDefaultDialog(Context context, String title, String con
builder.setNegativeButton(btn2Str, negativeClickListener);
}
}
builder.showDefault();
builder.show();
}

private static HashMap<String, SYDialog> hashMap = new HashMap<>();
Expand Down
77 changes: 0 additions & 77 deletions app/src/main/res/layout/dialog_phone_login.xml

This file was deleted.

131 changes: 52 additions & 79 deletions app/src/main/res/layout/layout_dialog.xml
Original file line number Diff line number Diff line change
@@ -1,99 +1,72 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ll_parent"
android:layout_width="match_parent"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:background="@android:color/transparent">
android:background="@drawable/roundlayout"
android:gravity="center_horizontal"
android:orientation="vertical">

<LinearLayout
android:id="@+id/layout_content"
android:layout_width="fill_parent"
android:id="@+id/layout_havemsg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="@drawable/roundlayout"
android:gravity="center_horizontal"
android:orientation="vertical">
android:orientation="vertical"
android:paddingLeft="15dp"
android:paddingRight="15dp">

<LinearLayout
android:id="@+id/layout_havemsg"
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="15dp"
android:paddingRight="15dp">
android:layout_marginTop="15dp"
android:gravity="center_horizontal"
android:lineSpacingExtra="6dp"
android:text="我是标题"
android:textColor="#292d33"
android:textSize="18sp" />

<TextView
android:id="@id/dialog_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:gravity="center_horizontal"
android:lineSpacingExtra="6dp"
android:text="订单提交成功"
android:textColor="#292d33"
android:textSize="18sp"
android:visibility="visible" />
<EditText
android:id="@+id/et_content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:layout_marginTop="15dp"
android:gravity="start|center_horizontal"
android:hint="请输入想要的内容"
android:lineSpacingExtra="6dp"
android:textColor="#525a66"
android:textSize="15sp" />

<EditText
android:id="@+id/et_content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:layout_marginTop="15dp"
android:gravity="center_horizontal"
android:hint="请输入想要的内容"
android:lineSpacingExtra="6dp"
android:textColor="#525a66"
android:textSize="15sp" />
</LinearLayout>
</LinearLayout>

<TextView
android:id="@+id/txt_onlytitle"
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<Button
android:id="@id/btn_cancel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/selector_btn_cancel_border_bg"
android:gravity="center"
android:lineSpacingExtra="6dp"
android:minHeight="106dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:text="订单提交成功"
android:textColor="#292d33"
android:minHeight="44dp"
android:text="取消"
android:textColor="#f7595a"
android:textSize="17sp"
android:visibility="gone" />

<LinearLayout
<Button
android:id="@id/btn_ok"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<Button
android:id="@id/btn_cancel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/selector_btn_cancel_border_bg"
android:gravity="center"
android:minHeight="44dp"
android:text="取消"
android:textColor="#f7595a"
android:textSize="17sp"
android:visibility="gone" />

<Button
android:id="@id/btn_ok"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/selector_btn_assuere_border_bg"
android:gravity="center"
android:minHeight="44dp"
android:text="确定"
android:textColor="#f7595a"
android:textSize="17sp" />
</LinearLayout>
android:layout_weight="1"
android:background="@drawable/selector_btn_assuere_border_bg"
android:gravity="center"
android:minHeight="44dp"
android:text="确定"
android:textColor="#f7595a"
android:textSize="17sp" />
</LinearLayout>

</RelativeLayout>
</LinearLayout>
19 changes: 5 additions & 14 deletions sydialoglib/src/main/java/com/fastgo/sydialoglib/SYDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -317,24 +317,15 @@ private SYDialog create() {
}

/**
* 展示自定义布局的Dialog
* 展示Dialog
*
* @return SYDialog
*/
public SYDialog show() {
SYDialog dialog = create();
removePreDialog();
dialog.show(params.fragmentManager, FTag);
return dialog;
}

/**
* 展示默认的dialog
*
* @return SYDialog
*/
public SYDialog showDefault() {
setDefaultOption();
if (params.layoutRes <= 0 && params.dialogView == null) {
//如果没有设置布局 提供默认设置
setDefaultOption();
}
SYDialog dialog = create();
removePreDialog();
dialog.show(params.fragmentManager, FTag);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public static class SYParams {
int dialogHeight;
float dimAmount = 0.2f;
public int gravity = Gravity.CENTER;
boolean isCancelableOutside = false;
boolean isCancelableOutside = true;
boolean cancelable = false;
View dialogView;
Context context;
Expand Down

0 comments on commit ef9aa0e

Please sign in to comment.