Skip to content

Commit

Permalink
增加input dialog的校验回调,以及控制第二个输入框是否显示为*
Browse files Browse the repository at this point in the history
  • Loading branch information
hss01248 committed Nov 17, 2017
1 parent 96c67b1 commit 0656951
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 11 deletions.
11 changes: 9 additions & 2 deletions app/src/main/java/com/hss01248/dialogutildemo/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

Expand Down Expand Up @@ -462,12 +463,18 @@ public void onSecond() {

}

@Override
public boolean onInputValid(CharSequence input1, CharSequence input2, EditText editText1, EditText editText2) {
showToast("input1--input2:"+input1+"--"+input2 +"is not accepted!");
return false;
}

@Override
public void onGetInput(CharSequence input1, CharSequence input2) {
super.onGetInput(input1, input2);
showToast("input1:"+ input1 +"--input2:"+input2);
}
}).setCancelable(true,true).show();
}).setInput2HideAsPassword(false).setCancelable(true,true).show();

break;
case R.id.btn_multichoose:
Expand Down Expand Up @@ -611,7 +618,7 @@ public void onItemClick(CharSequence text, int position) {
public void onItemClick(CharSequence text, int position) {
showToast(text+"---"+position);
}
}).show();
}).setHasBehaviour(false).show();
break;
case R.id.btn_customview:
ViewGroup customView = (ViewGroup) View.inflate(this,R.layout.customview,null);
Expand Down
13 changes: 8 additions & 5 deletions app/src/main/res/layout/view_custom_holder.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@
android:background="@drawable/bg_ios_roundcorner_top"
android:layout_height="match_parent">
<TextView
android:layout_marginTop="50dp"
android:id="@+id/tv_content"
android:text="djosffdjsofjosdjfosjforerewrewrewerewrewrewrewrsjfosjfosdjfosdjfosdjfojsdofjdsfsd"
android:textColor="@color/ios_btntext_blue"
android:text="i am a custom view you can set any view here hahahah hshshhshshshhshhhhhhhhhhhhhhshhhhhhhhhhhhhhhhshhhhhhhhhhhhhhshhhhhhhhhhhhhhhh"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:text="title"
<ImageView

android:layout_centerHorizontal="true"
android:textSize="20sp"
android:src="@drawable/iosloading004"
android:layout_marginTop="30dp"
android:layout_marginRight="30dp"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

Expand Down
16 changes: 13 additions & 3 deletions dialog/src/main/java/com/hss01248/dialog/Tool.java
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ public static void adjustStyle(final ConfigBean bean) {
Window window = dialog.getWindow();
window.setGravity(bean.gravity);
if(bean.context instanceof Activity){

setHomeKeyListener(window,bean);
}else {
window.setType(WindowManager.LayoutParams.TYPE_TOAST);
WindowManager.LayoutParams params = window.getAttributes();
Expand Down Expand Up @@ -310,7 +310,7 @@ public boolean onKey(View v, int keyCode, KeyEvent event) {

}

private static void setHomeKeyListener(Window window, final ConfigBean bean){
private static void setHomeKeyListener(final Window window, final ConfigBean bean){
//在创建View时注册Receiver
IntentFilter homeFilter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
bean.context.registerReceiver(new BroadcastReceiver() {
Expand All @@ -325,7 +325,13 @@ public void onReceive(Context context, Intent intent) {
String reason = intent.getStringExtra(SYSTEM_DIALOG_REASON_KEY);
if (reason != null && reason.equals(SYSTEM_DIALOG_REASON_HOME_KEY)) {
// 处理自己的逻辑
StyledDialog.dismiss(bean.alertDialog,bean.dialog);
if(bean.type == DefaultConfig.TYPE_IOS_INPUT){
hideKeyBoard(window);
}
if(!(bean.context instanceof Activity)){
StyledDialog.dismiss(bean.alertDialog,bean.dialog);
}

context.unregisterReceiver(this);
}
}
Expand Down Expand Up @@ -709,6 +715,10 @@ public static void hideKeyBoard(View view){
InputMethodManager imm = (InputMethodManager) StyledDialog.context.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0); //强制隐藏键盘
}
public static void hideKeyBoard(Window window){
InputMethodManager imm = (InputMethodManager) StyledDialog.context.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(window.getDecorView().getWindowToken(), 0); //强制隐藏键盘
}


}
12 changes: 11 additions & 1 deletion dialog/src/main/java/com/hss01248/dialog/config/ConfigBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,17 @@ public class ConfigBean extends MyDialogBuilder implements Styleable {
public CharSequence hint2;


public boolean hasBehaviour = true;
public boolean hasBehaviour = false;

public ConfigBean setInput2HideAsPassword(boolean input2HideAsPassword) {
isInput2HideAsPassword = input2HideAsPassword;
return this;
}

/**
* 控制input类dialog中第二个框是否用*号
*/
public boolean isInput2HideAsPassword = true;
public BottomSheetStyle bottomSheetStyle;

public ConfigBean setBottomSheetStyle(BottomSheetStyle bottomSheetStyle){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.hss01248.dialog.interfaces;

import android.widget.EditText;

import java.util.List;

/**
Expand All @@ -22,6 +24,19 @@ public void onGetInput(CharSequence input1,CharSequence input2){

}


/**
* 每次点击btn1,则传回输入值以便校验
* @param input1
* @param input2
* @param editText1
* @param editText2
* @return
*/
public boolean onInputValid(CharSequence input1, CharSequence input2, EditText editText1,EditText editText2){
return true;
}

/**
* 提供给MdSingleChoose的回调
* @param chosen
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

import android.content.Context;
import android.text.TextUtils;
import android.text.method.HideReturnsTransformationMethod;
import android.text.method.PasswordTransformationMethod;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
Expand All @@ -15,6 +17,7 @@
import com.hss01248.dialog.Tool;
import com.hss01248.dialog.adapter.SuperLvHolder;
import com.hss01248.dialog.config.ConfigBean;
import com.hss01248.dialog.config.DefaultConfig;


/**
Expand Down Expand Up @@ -156,6 +159,13 @@ public void assingDatasAndEvents(Context context, final ConfigBean bean) {
et2.setHint(bean.hint2);
et2.setTextColor(Tool.getColor(et2.getContext(),bean.inputTxtColor));
et2.setTextSize(bean.inputTxtSize);
if (bean.isInput2HideAsPassword) {
//设置EditText文本为可见的
et2.setTransformationMethod(PasswordTransformationMethod.getInstance());
} else {
//设置EditText文本为隐藏的
et2.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
}
}
}else {
//设置了content holders时,中央采用自定义view
Expand Down Expand Up @@ -269,6 +279,13 @@ public void onClick(View view) {
btn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
boolean needDismiss = true;
if(bean.type == DefaultConfig.TYPE_IOS_INPUT){
needDismiss = bean.listener.onInputValid(et1.getText().toString().trim(),et2.getText().toString().trim(),et1,et2);
}
if(!needDismiss){
return;
}
hideKeyBoard();
StyledDialog.dismiss(bean.dialog,bean.alertDialog);
bean.listener.onFirst();
Expand Down

0 comments on commit 0656951

Please sign in to comment.