Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

带输入框的confrim弹窗增加可设置输入类型inputType,在hint参数后面 #676

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.content.Intent;
import android.os.Build;
import android.os.Handler;
import android.text.InputType;
import android.util.Log;
import android.view.View;
import androidx.annotation.RequiresApi;
Expand Down
64 changes: 55 additions & 9 deletions library/src/main/java/com/lxj/xpopup/XPopup.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;

import androidx.annotation.RequiresApi;

import com.lxj.xpopup.animator.PopupAnimator;
import com.lxj.xpopup.core.AttachPopupView;
import com.lxj.xpopup.core.BasePopupView;
Expand All @@ -35,11 +37,13 @@
import com.lxj.xpopup.interfaces.XPopupCallback;
import com.lxj.xpopup.interfaces.XPopupImageLoader;
import com.lxj.xpopup.util.XPermission;

import java.util.List;


public class XPopup {
private XPopup() { }
private XPopup() {
}

/**
* 全局弹窗的设置
Expand All @@ -48,9 +52,11 @@ private XPopup() { }
private static int animationDuration = 350;
public static int statusBarShadowColor = Color.parseColor("#55000000");
private static int shadowBgColor = Color.parseColor("#7F000000");

public static void setShadowBgColor(int color) {
shadowBgColor = color;
}

public static int getShadowBgColor() {
return shadowBgColor;
}
Expand All @@ -76,21 +82,23 @@ public static void setAnimationDuration(int duration) {

/**
* 在长按弹出弹窗后,能保证下层View不能滑动
*
* @param v
*/
public static PointF longClickPoint = null;
public static void fixLongClick(View v){

public static void fixLongClick(View v) {
v.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction()==MotionEvent.ACTION_DOWN){
if (event.getAction() == MotionEvent.ACTION_DOWN) {
longClickPoint = new PointF(event.getRawX(), event.getRawY());
}
if("xpopup".equals(v.getTag()) && event.getAction()==MotionEvent.ACTION_MOVE){
if ("xpopup".equals(v.getTag()) && event.getAction() == MotionEvent.ACTION_MOVE) {
//长按发送,阻断父View拦截
v.getParent().requestDisallowInterceptTouchEvent(true);
}
if(event.getAction()==MotionEvent.ACTION_UP){
if (event.getAction() == MotionEvent.ACTION_UP) {
//长按结束,恢复阻断
v.getParent().requestDisallowInterceptTouchEvent(false);
v.setTag(null);
Expand Down Expand Up @@ -195,7 +203,7 @@ public Builder watchView(View watchView) {
this.popupInfo.watchView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN){
if (event.getAction() == MotionEvent.ACTION_DOWN) {
popupInfo.touchPoint = new PointF(event.getRawX(), event.getRawY());
}
return false;
Expand Down Expand Up @@ -229,6 +237,7 @@ public Builder customAnimator(PopupAnimator customAnimator) {
/**
* 设置高度,如果重写了弹窗的getPopupHeight,则以重写的为准
* 并且受最大高度限制
*
* @param height
* @return
*/
Expand All @@ -240,6 +249,7 @@ public Builder popupHeight(int height) {
/**
* 设置宽度,如果重写了弹窗的getPopupWidth,则以重写的为准
* 并且受最大宽度限制
*
* @param width
* @return
*/
Expand Down Expand Up @@ -443,6 +453,7 @@ public Builder isClickThrough(boolean isClickThrough) {
/**
* 是否允许应用在后台的时候也能弹出弹窗,默认是false。注意如果开启这个开关,需要申请悬浮窗权限才能生效。
* 直接使用 XPopup.requestOverlayPermission()即可申请
*
* @param enableShowWhenAppBackground
* @return
*/
Expand Down Expand Up @@ -488,9 +499,9 @@ public Builder borderRadius(float borderRadius) {
/**
* 是否已屏幕中心进行定位,默认是false,为false时根据Material范式进行定位,主要影响Attach系列弹窗
* Material范式下是:
* 弹窗优先显示在目标下方,下方距离不够才显示在上方
* 弹窗优先显示在目标下方,下方距离不够才显示在上方
* 已屏幕中心进行定位:
* 目标在屏幕上半方弹窗显示在目标下面,目标在屏幕下半方则弹窗显示在目标上面
* 目标在屏幕上半方弹窗显示在目标下面,目标在屏幕下半方则弹窗显示在目标上面
*
* @param positionByWindowCenter
* @return
Expand Down Expand Up @@ -577,7 +588,7 @@ public ConfirmPopupView asConfirm(CharSequence title, CharSequence content, OnCo
* @param hint 输入框默认文字
* @param confirmListener 点击确认的监听器
* @param cancelListener 点击取消的监听器
* @param bindLayoutId 自定义布局的id,没有传0。 要求布局中必须包含的TextView以及id有:tv_title,tv_content,tv_cancel,tv_confirm
* @param bindLayoutId 自定义布局的id,没有传0。 要求布局中必须包含的TextView以及id有:tv_title,tv_content,tv_cancel,tv_confirm
* @return
*/
public InputConfirmPopupView asInputConfirm(CharSequence title, CharSequence content, CharSequence inputContent, CharSequence hint, OnInputConfirmListener confirmListener, OnCancelListener cancelListener, int bindLayoutId) {
Expand All @@ -590,18 +601,53 @@ public InputConfirmPopupView asInputConfirm(CharSequence title, CharSequence con
return popupView;
}

/**
* 可以选择ediText输入类型inputType
*/
public InputConfirmPopupView asInputConfirm(CharSequence title, CharSequence content, CharSequence inputContent, CharSequence hint, int inputType, OnInputConfirmListener confirmListener, OnCancelListener cancelListener, int bindLayoutId) {
popupType(PopupType.Center);
InputConfirmPopupView popupView = new InputConfirmPopupView(this.context, bindLayoutId, inputType);
popupView.setTitleContent(title, content, hint);
popupView.inputContent = inputContent;
popupView.setListener(confirmListener, cancelListener);
popupView.popupInfo = this.popupInfo;
return popupView;
}

public InputConfirmPopupView asInputConfirm(CharSequence title, CharSequence content, CharSequence inputContent, CharSequence hint, OnInputConfirmListener confirmListener) {
return asInputConfirm(title, content, inputContent, hint, confirmListener, null, 0);
}

/**
* 支持inputType
*/
public InputConfirmPopupView asInputConfirm(CharSequence title, CharSequence content, CharSequence inputContent, CharSequence hint, int inputType, OnInputConfirmListener confirmListener) {
return asInputConfirm(title, content, inputContent, hint, inputType, confirmListener, null, 0);
}

public InputConfirmPopupView asInputConfirm(CharSequence title, CharSequence content, CharSequence hint, OnInputConfirmListener confirmListener) {
return asInputConfirm(title, content, null, hint, confirmListener, null, 0);
}

/**
* 支持inputType
*/
public InputConfirmPopupView asInputConfirm(CharSequence title, CharSequence content, CharSequence hint, int inputType, OnInputConfirmListener confirmListener) {
return asInputConfirm(title, content, null, hint, inputType, confirmListener, null, 0);
}


public InputConfirmPopupView asInputConfirm(CharSequence title, CharSequence content, OnInputConfirmListener confirmListener) {
return asInputConfirm(title, content, null, null, confirmListener, null, 0);
}

/**
* 支持inputType
*/
public InputConfirmPopupView asInputConfirm(CharSequence title, CharSequence content, int inputType, OnInputConfirmListener confirmListener) {
return asInputConfirm(title, content, null, null, inputType, confirmListener, null, 0);
}

/**
* 显示在中间的列表Popup
*
Expand Down
46 changes: 34 additions & 12 deletions library/src/main/java/com/lxj/xpopup/impl/ConfirmPopupView.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.lxj.xpopup.impl;

import android.content.Context;

import androidx.annotation.NonNull;

import android.graphics.Color;
import android.text.InputType;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.view.View;
Expand Down Expand Up @@ -31,9 +33,9 @@ public class ConfirmPopupView extends CenterPopupView implements View.OnClickLis
EditText et_input;
View divider1, divider2;
public boolean isHideCancel = false;
public int et_input_type = InputType.TYPE_CLASS_TEXT;

/**
*
* @param context
* @param bindLayoutId layoutId 要求布局中必须包含的TextView以及id有:tv_title,tv_content,tv_cancel,tv_confirm
*/
Expand All @@ -43,6 +45,18 @@ public ConfirmPopupView(@NonNull Context context, int bindLayoutId) {
addInnerContent();
}

/**
* @param context
* @param bindLayoutId layoutId 要求布局中必须包含的TextView以及id有:tv_title,tv_content,tv_cancel,tv_confirm
* @param inputType
*/
public ConfirmPopupView(@NonNull Context context, int bindLayoutId, int inputType) {
super(context);
this.bindLayoutId = bindLayoutId;
this.et_input_type = inputType;
addInnerContent();
}

@Override
protected int getImplLayoutId() {
return bindLayoutId != 0 ? bindLayoutId : R.layout._xpopup_center_impl_confirm;
Expand All @@ -59,7 +73,10 @@ protected void initPopupContent() {
et_input = findViewById(R.id.et_input);
divider1 = findViewById(R.id.xpopup_divider1);
divider2 = findViewById(R.id.xpopup_divider2);

/**
*输入类型
*/
et_input.setInputType(et_input_type);
tv_cancel.setOnClickListener(this);
tv_confirm.setOnClickListener(this);

Expand All @@ -71,7 +88,7 @@ protected void initPopupContent() {

if (!TextUtils.isEmpty(content)) {
tv_content.setText(content);
}else {
} else {
tv_content.setVisibility(GONE);
}
if (!TextUtils.isEmpty(cancelText)) {
Expand All @@ -82,7 +99,7 @@ protected void initPopupContent() {
}
if (isHideCancel) {
tv_cancel.setVisibility(GONE);
if(divider2!=null) divider2.setVisibility(GONE);
if (divider2 != null) divider2.setVisibility(GONE);
}
applyTheme();
}
Expand All @@ -93,34 +110,39 @@ protected void applyLightTheme() {
tv_content.setTextColor(getResources().getColor(R.color._xpopup_content_color));
tv_cancel.setTextColor(Color.parseColor("#666666"));
tv_confirm.setTextColor(XPopup.getPrimaryColor());
if(divider1!=null)divider1.setBackgroundColor(getResources().getColor(R.color._xpopup_list_divider));
if(divider2!=null)divider2.setBackgroundColor(getResources().getColor(R.color._xpopup_list_divider));
if (divider1 != null)
divider1.setBackgroundColor(getResources().getColor(R.color._xpopup_list_divider));
if (divider2 != null)
divider2.setBackgroundColor(getResources().getColor(R.color._xpopup_list_divider));
}

public TextView getTitleTextView(){
public TextView getTitleTextView() {
return findViewById(R.id.tv_title);
}

public TextView getContentTextView(){
public TextView getContentTextView() {
return findViewById(R.id.tv_content);
}

public TextView getCancelTextView(){
public TextView getCancelTextView() {
return findViewById(R.id.tv_cancel);
}

public TextView getConfirmTextView(){
public TextView getConfirmTextView() {
return findViewById(R.id.tv_confirm);
}

@Override
protected void applyDarkTheme() {
super.applyDarkTheme();
tv_title.setTextColor(getResources().getColor(R.color._xpopup_white_color));
tv_content.setTextColor(getResources().getColor(R.color._xpopup_white_color));
tv_cancel.setTextColor(getResources().getColor(R.color._xpopup_white_color));
tv_confirm.setTextColor(getResources().getColor(R.color._xpopup_white_color));
if(divider1!=null)divider1.setBackgroundColor(getResources().getColor(R.color._xpopup_list_dark_divider));
if(divider2!=null)divider2.setBackgroundColor(getResources().getColor(R.color._xpopup_list_dark_divider));
if (divider1 != null)
divider1.setBackgroundColor(getResources().getColor(R.color._xpopup_list_dark_divider));
if (divider2 != null)
divider2.setBackgroundColor(getResources().getColor(R.color._xpopup_list_dark_divider));
}

public ConfirmPopupView setListener(OnConfirmListener confirmListener, OnCancelListener cancelListener) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ public InputConfirmPopupView(@NonNull Context context, int bindLayoutId) {
super(context, bindLayoutId);
}

/**
* @param context
* @param bindLayoutId 在Confirm弹窗基础上需要增加一个id为et_input的EditText
* @param inputType 输入类型
*/
public InputConfirmPopupView(@NonNull Context context, int bindLayoutId, int inputType) {
super(context, bindLayoutId, inputType);
}

public CharSequence inputContent;

@Override
Expand Down