Commit 1d52dfe1 by 王宇航

模塊搭建完成,登陸功能未完善

parent 121e4351
/**
* @company: JOE工作室
* @Copyright: Copyright © 2013 - 2016 joe.All Rights Reserved.
* @Filename: ConvertDpAndPx.java
* @Description: TODO(用一句话描述该文件做什么)
* @Author: JOE
* @Date: 2016-9-2 下午6:16:29
**/
package com.joe.base.utils.screen;
/**
* @company: JOE工作室
* @ClassName: ConvertDpAndPx
* @Description: TODO(这里用一句话描述这个类的作用)
* @Author: JOE
* @Date: 2016-9-2 下午6:16:29
*/
import android.content.Context;
public class ConvertDpAndPx {
/**
* dp转换成px,代码写的是像素,而XML中写的是单位密度
* @param context
* @param dp
* @return
*/
public static int Dp2Px(Context context, float dp) {
final float scale = context.getResources().getDisplayMetrics().density;
return (int) (dp * scale + 0.5f);
}
/**
* px转换成dp,代码写的是像素,而XML中(dp)写的是单位密度
* @param context
* @param px
* @return
*/
public static int Px2Dp(Context context, float px) {
final float scale = context.getResources().getDisplayMetrics().density;
return (int) (px / scale + 0.5f);
}
}
...@@ -3,27 +3,37 @@ package com.joe.base.widget.view; ...@@ -3,27 +3,37 @@ package com.joe.base.widget.view;
import android.content.Context; import android.content.Context;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Build;
import android.text.Editable;
import android.text.InputFilter; import android.text.InputFilter;
import android.text.InputType; import android.text.InputType;
import android.text.Layout;
import android.text.Spanned; import android.text.Spanned;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.text.method.HideReturnsTransformationMethod;
import android.text.method.PasswordTransformationMethod; import android.text.method.PasswordTransformationMethod;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.joe.base.R; import com.joe.base.R;
import com.joe.base.utils.other.TextUtil; import com.joe.base.utils.screen.ConvertDpAndPx;
import com.joe.base.utils.toast.ToastUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import androidx.appcompat.widget.AppCompatEditText;
/** /**
* Created by Wyh on 2019/12/19. * Created by Wyh on 2019/12/19.
*/ */
public class MyEditText extends AppCompatEditText { public class MyEditText extends RelativeLayout {
private Context context; private Context context;
//輸入最大長度 //輸入最大長度
...@@ -34,11 +44,20 @@ public class MyEditText extends AppCompatEditText { ...@@ -34,11 +44,20 @@ public class MyEditText extends AppCompatEditText {
private boolean isShowMaxLenght; private boolean isShowMaxLenght;
private int maxLenghtTextColor; private int maxLenghtTextColor;
private int maxLenghtTextSize; private int maxLenghtTextSize;
private int maxTextMarginLeft;
private int maxTextMarginRight;
private int maxTextMarginTop;
private int maxTextMarginBottom;
//是否允許輸入表情 //是否允許輸入表情
private boolean isInputIcon; private boolean isInputIcon;
//輸入表情時提示的內容,不設置內容不提示 //輸入表情時提示的內容,不設置內容不提示
private String inputIconTipText; private String inputIconTipText;
private String hint;
private int hintColor;
private int edTextColor;
private String edText;
private int edTextSize;
//清除按鈕的大小 //清除按鈕的大小
private int clearIconSiZe; private int clearIconSiZe;
//清除按鈕圖標 //清除按鈕圖標
...@@ -46,7 +65,7 @@ public class MyEditText extends AppCompatEditText { ...@@ -46,7 +65,7 @@ public class MyEditText extends AppCompatEditText {
//清除按鈕右間距 //清除按鈕右間距
private int clearRightMargin; private int clearRightMargin;
//清除按鈕點擊事件 //清除按鈕點擊事件
private View.OnClickListener clearOnClickListener; private OnClickListener clearOnClickListener;
//查看密碼按鈕圖標 //查看密碼按鈕圖標
private Drawable lookIcon; private Drawable lookIcon;
...@@ -57,22 +76,33 @@ public class MyEditText extends AppCompatEditText { ...@@ -57,22 +76,33 @@ public class MyEditText extends AppCompatEditText {
//查看密碼按鈕點擊事件 //查看密碼按鈕點擊事件
private OnClickListener lookOnClickListener; private OnClickListener lookOnClickListener;
private int btnMarginTop;
private int btnMarginRight;
private int btnMarginBottom;
private int btnMarginLeft;
//設置輸入密碼替換符 //設置輸入密碼替換符
private String pwdChar; private String pwdChar;
//是否換行 //是否換行
private boolean singLeLine; private boolean singleLine;
private int inputType; private int inputType;
// private EditText editText; private int contentGravity;
private int btnGravity;
private EditText editText;
//顯示最大字數的textview //顯示最大字數的textview
// private TextView maxLenghtTextView; private TextView maxLenghtTextView;
//
// private ImageView ivClear; private ImageView ivClear;
// private ImageView ivLook; private CheckBox ivLook;
private List<InputFilter> mInputFilter = new ArrayList<>(); private List<InputFilter> mInputFilter = new ArrayList<>();
private AsteriskPasswordTransformationMethod passwordTransformationMethod;
public MyEditText(Context context) { public MyEditText(Context context) {
this(context, null); this(context, null);
...@@ -88,93 +118,221 @@ public class MyEditText extends AppCompatEditText { ...@@ -88,93 +118,221 @@ public class MyEditText extends AppCompatEditText {
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.MyEditText); TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.MyEditText);
maxLeght = typedArray.getInt(R.styleable.MyEditText_ed_MaxLength, 0); maxLeght = typedArray.getInt(R.styleable.MyEditText_ed_MaxLength, 0);
maxLengthTip = typedArray.getString(R.styleable.MyEditText_ed_MaxLengthTip); maxLengthTip = typedArray.getString(R.styleable.MyEditText_ed_MaxLengthTip);
isShowMaxLenght = typedArray.getBoolean(R.styleable.MyEditText_ed_showMaxLenght, false); isShowMaxLenght = typedArray.getBoolean(R.styleable.MyEditText_ed_showMaxLenght, false);
maxLenghtTextColor = typedArray.getColor(R.styleable.MyEditText_ed_maxLengthTextColor, -1); maxLenghtTextColor = typedArray.getColor(R.styleable.MyEditText_ed_maxLengthTextColor, 0x10);
maxLenghtTextSize = typedArray.getDimensionPixelSize(R.styleable.MyEditText_ed_maxLengthTextSize, 12); maxLenghtTextSize = ConvertDpAndPx.Px2Dp(context, typedArray.getDimensionPixelSize(R.styleable.MyEditText_ed_maxLengthTextSize, 12));
isInputIcon = typedArray.getBoolean(R.styleable.MyEditText_ed_isInputIcon, false); isInputIcon = typedArray.getBoolean(R.styleable.MyEditText_ed_isInputIcon, false);
inputIconTipText = typedArray.getString(R.styleable.MyEditText_ed_putIconTip); inputIconTipText = typedArray.getString(R.styleable.MyEditText_ed_putIconTip);
clearIconSiZe = typedArray.getDimensionPixelSize(R.styleable.MyEditText_ed_clearIconSize, 0);
clearIconSiZe = typedArray.getDimensionPixelSize(R.styleable.MyEditText_ed_clearIconSize, 12);
clearIcon = typedArray.getDrawable(R.styleable.MyEditText_ed_clearRes); clearIcon = typedArray.getDrawable(R.styleable.MyEditText_ed_clearRes);
clearRightMargin = typedArray.getDimensionPixelSize(R.styleable.MyEditText_ed_clearMarginRight, 0); clearRightMargin = ConvertDpAndPx.Px2Dp(context, typedArray.getDimensionPixelSize(R.styleable.MyEditText_ed_clearMarginRight, 0));
lookIcon = typedArray.getDrawable(R.styleable.MyEditText_ed_lookIcon); lookIcon = typedArray.getDrawable(R.styleable.MyEditText_ed_lookIcon);
lookIconSiZe = typedArray.getDimensionPixelSize(R.styleable.MyEditText_ed_lookIconSize, 12); lookIconSiZe = ConvertDpAndPx.Px2Dp(context, typedArray.getDimensionPixelSize(R.styleable.MyEditText_ed_lookIconSize, 0));
lookRightMargin = typedArray.getDimensionPixelSize(R.styleable.MyEditText_ed_lookMarginRight, 0); lookRightMargin = ConvertDpAndPx.Px2Dp(context, typedArray.getDimensionPixelSize(R.styleable.MyEditText_ed_lookMarginRight, 0));
pwdChar = typedArray.getString(R.styleable.MyEditText_ed_pwdChar); pwdChar = typedArray.getString(R.styleable.MyEditText_ed_pwdChar);
singleLine = typedArray.getBoolean(R.styleable.MyEditText_ed_singLeLine, false);
inputType = typedArray.getInteger(R.styleable.MyEditText_inputType, 0);
contentGravity = typedArray.getInteger(R.styleable.MyEditText_ed_gravity, 0);
singLeLine = typedArray.getBoolean(R.styleable.MyEditText_ed_singLeLine, false); maxTextMarginLeft = ConvertDpAndPx.Px2Dp(context, typedArray.getDimensionPixelSize(R.styleable.MyEditText_ed_maxLengthMarginLeft, 0));
maxTextMarginRight = ConvertDpAndPx.Px2Dp(context, typedArray.getDimensionPixelSize(R.styleable.MyEditText_ed_maxLengthMarginRight, 0));
maxTextMarginTop = ConvertDpAndPx.Px2Dp(context, typedArray.getDimensionPixelSize(R.styleable.MyEditText_ed_maxLengthMarginTop, 0));
maxTextMarginBottom = ConvertDpAndPx.Px2Dp(context, typedArray.getDimensionPixelSize(R.styleable.MyEditText_ed_maxLengthMarginBottom, 0));
btnGravity = typedArray.getInteger(R.styleable.MyEditText_ed_clear_gravity, 2);
inputType = typedArray.getInteger(R.styleable.MyEditText_inputType, 0); btnMarginTop = ConvertDpAndPx.Px2Dp(context, typedArray.getDimensionPixelSize(R.styleable.MyEditText_ed_btn_marginTop, 0));
btnMarginRight = ConvertDpAndPx.Px2Dp(context, typedArray.getDimensionPixelSize(R.styleable.MyEditText_ed_btn_marginRight, 0));
btnMarginBottom = ConvertDpAndPx.Px2Dp(context, typedArray.getDimensionPixelSize(R.styleable.MyEditText_ed_btn_marginBottom, 0));
btnMarginLeft = ConvertDpAndPx.Px2Dp(context, typedArray.getDimensionPixelSize(R.styleable.MyEditText_ed_btn_marginLeft, 0));
hint = typedArray.getString(R.styleable.MyEditText_ed_hint);
hintColor = typedArray.getColor(R.styleable.MyEditText_ed_hintColor, 0x10);
edTextColor = typedArray.getColor(R.styleable.MyEditText_ed_textColor, 0x10);
edText = typedArray.getString(R.styleable.MyEditText_ed_text);
edTextSize = ConvertDpAndPx.Px2Dp(context, typedArray.getDimensionPixelSize(R.styleable.MyEditText_ed_textSize, 12));
typedArray.recycle(); typedArray.recycle();
initLeght(); initLeght();
if (!isInputIcon) {
mInputFilter.add(new EmojiInputFilter());
}
initEditText(); initEditText();
initClearIcon();
initLookIcon();
} }
private void initEditText() { private void initEditText() {
InputFilter[] inputFilters = new InputFilter[mInputFilter.size()]; if (!isInputIcon) {
if (!TextUtil.isEmptyOrNullOrUndefined(pwdChar)) { mInputFilter.add(new EmojiInputFilter());
this.setInputType(InputType.TYPE_NUMBER_VARIATION_PASSWORD);
this.setTransformationMethod(new AsteriskPasswordTransformationMethod());
} }
editText = new EditText(context);
editText.setText(edText);
editText.setTextColor(edTextColor);
editText.setHint(hint);
editText.setHintTextColor(hintColor);
editText.setTextSize(edTextSize);
editText.setGravity(contentGravity);
InputFilter[] inputFilters = new InputFilter[mInputFilter.size()];
for (int i = 0; i < mInputFilter.size(); i++) { for (int i = 0; i < mInputFilter.size(); i++) {
inputFilters[i] = mInputFilter.get(i); inputFilters[i] = mInputFilter.get(i);
} }
setFilters(inputFilters); editText.setFilters(inputFilters);
setSingleLine(singLeLine); if (!TextUtils.isEmpty(pwdChar)) {
passwordTransformationMethod = new AsteriskPasswordTransformationMethod();
editText.setTransformationMethod(passwordTransformationMethod);//必須在setsingleLine之後才有效
// if (clearIcon != null) { }
// ivClear = new ImageView(context); if(inputType != 0){
// ivClear.setImageDrawable(clearIcon); editText.setInputType(inputType);
// ivClear.setLayoutParams(getImgLayoutParams(clearIconSiZe, clearIconSiZe, clearRightMargin)); }
// this.addView(ivClear);
// ivClear.setOnClickListener(new OnClickListener() { LayoutParams params = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
// @Override editText.setPadding(0, 0, clearIconSiZe + lookIconSiZe + clearRightMargin + lookRightMargin, 0);
// public void onClick(View view) { editText.setBackgroundColor(0);
// editText.setText(""); editText.setLayoutParams(params);
// if (clearOnClickListener != null) { // editText.setSingleLine();這個方法會改變edittext的TransformationMethod,不適用
// clearOnClickListener.onClick(view); if (singleLine) {
// } editText.setMaxLines(1);
// } editText.setHorizontallyScrolling(true);
// }); } else {
// } editText.setMaxLines(Integer.MAX_VALUE);
// //水平滚动设置为False
// editText.setHorizontallyScrolling(false);
// if (lookIcon != null) {
// ivLook = new ImageView(context);
// LayoutParams ivLookParams = getImgLayoutParams(lookIconSiZe, lookIconSiZe, lookRightMargin);
// if (ivClear != null) {
// ivLookParams.rightMargin = clearIconSiZe + lookRightMargin;
// }
// ivLook.setLayoutParams(ivLookParams);
// ivLook.setImageDrawable(lookIcon);
// this.addView(ivLook);
// ivLook.setOnClickListener(new OnClickListener() {
// @Override
// public void onClick(View view) {
// if (lookOnClickListener != null) {
// lookOnClickListener.onClick(view);
// }
// }
// });
// }
} }
editText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void afterTextChanged(Editable editable) {
setMaxLengthText(editable.toString().length());
}
});
this.addView(editText);
}
/**
* 初始化查看密碼按鈕
*/
private void initLookIcon() {
if (lookIcon != null) {
ivLook = new CheckBox(context);
LayoutParams ivLookParams = getImgLayoutParams(lookIconSiZe, lookIconSiZe, lookRightMargin);
ivLook.setButtonDrawable(null);
if (ivClear != null) {
ivLookParams.rightMargin = clearIconSiZe + lookRightMargin + clearRightMargin;
} else {
ivLookParams.rightMargin = lookRightMargin;
}
ivLook.setLayoutParams(ivLookParams);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
ivLook.setBackground(lookIcon);
}
this.addView(ivLook);
ivLook.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
editText.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
} else {
editText.setTransformationMethod(passwordTransformationMethod);//讓密碼顯示為*
}
editText.setSelection(editText.getText().toString().length());
if (lookOnClickListener != null) {
lookOnClickListener.onClick(buttonView);
}
}
});
}
}
/**
* 初始化清空按鈕
*/
private void initClearIcon() {
if (clearIcon != null) {
ivClear = new ImageView(context);
ivClear.setImageDrawable(clearIcon);
ivClear.setLayoutParams(getImgLayoutParams(clearIconSiZe, clearIconSiZe, clearRightMargin));
this.addView(ivClear);
ivClear.setOnClickListener(view -> {
editText.setText("");
if (clearOnClickListener != null) {
clearOnClickListener.onClick(view);
}
});
}
}
public EditText getEditText() {
return editText;
}
public void setEditText(EditText editText) {
this.editText = editText;
}
public Editable getText() {
return editText.getText();
}
private void setMaxLengthText(int currentLenght) {
if (maxLenghtTextView != null)
maxLenghtTextView.setText(currentLenght + "/" + maxLeght);
}
private LayoutParams getImgLayoutParams(int widht, int height, int rightMargin) {
LayoutParams params;
if (widht == 0) {
params = new LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
} else {
params = new LayoutParams(widht, height);
}
params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
switch (btnGravity) {
case 1:
params.addRule(RelativeLayout.ALIGN_PARENT_TOP);
break;
case 2:
params.addRule(RelativeLayout.CENTER_VERTICAL);
break;
case 3:
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
break;
}
params.setMargins(btnMarginLeft, btnMarginTop, btnMarginRight, btnMarginBottom);
params.rightMargin = rightMargin;
return params;
}
/**
* 初始化長度監聽和長度顯示文字
*/
private void initLeght() { private void initLeght() {
if (maxLeght > 0) { if (maxLeght > 0) {
mInputFilter.add(new MaxTextLengthFilter(maxLeght)); mInputFilter.add(new MaxTextLengthFilter(maxLeght));
} }
if (isShowMaxLenght) {
maxLenghtTextView = new TextView(context);
maxLenghtTextView.setTextColor(maxLenghtTextColor);
maxLenghtTextView.setTextSize(maxLenghtTextSize);
LayoutParams textParams = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
textParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
textParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
textParams.setMargins(maxTextMarginLeft, maxTextMarginTop, maxTextMarginRight, maxTextMarginBottom);
maxLenghtTextView.setLayoutParams(textParams);
setMaxLengthText(0);
this.addView(maxLenghtTextView);
}
} }
/** /**
...@@ -226,8 +384,9 @@ public class MyEditText extends AppCompatEditText { ...@@ -226,8 +384,9 @@ public class MyEditText extends AppCompatEditText {
Spanned dest, int dstart, int dend) { Spanned dest, int dstart, int dend) {
int keep = mMaxLength - (dest.length() - (dend - dstart)); int keep = mMaxLength - (dest.length() - (dend - dstart));
if (keep < (end - start)) { if (keep < (end - start)) {
if (!TextUtil.isEmptyOrNullOrUndefined(maxLengthTip)) { if (!TextUtils.isEmpty(maxLengthTip)) {
ToastUtils.show(context, maxLengthTip); // ToastUtils.showShort();
Toast.makeText(context, maxLengthTip, Toast.LENGTH_SHORT).show();
} }
} }
if (keep <= 0) { if (keep <= 0) {
...@@ -246,9 +405,10 @@ public class MyEditText extends AppCompatEditText { ...@@ -246,9 +405,10 @@ public class MyEditText extends AppCompatEditText {
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) { public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
if (containsEmoji(source.toString())) { if (containsEmoji(source.toString())) {
//如果輸入了表情 //如果輸入了表情
if (!TextUtil.isEmptyOrNullOrUndefined(inputIconTipText)) { if (!TextUtils.isEmpty(inputIconTipText)) {
//提示文字不為空,就彈出提示,並移除掉表情 //提示文字不為空,就彈出提示,並移除掉表情
ToastUtils.show(context, inputIconTipText); // ToastUtils.showShort(inputIconTipText);
Toast.makeText(context, inputIconTipText, Toast.LENGTH_SHORT).show();
return ""; return "";
} }
return ""; return "";
...@@ -272,7 +432,7 @@ public class MyEditText extends AppCompatEditText { ...@@ -272,7 +432,7 @@ public class MyEditText extends AppCompatEditText {
} }
public char charAt(int index) { public char charAt(int index) {
return pwdChar.toCharArray()[0]; return pwdChar.charAt(0);
} }
public int length() { public int length() {
...@@ -282,7 +442,6 @@ public class MyEditText extends AppCompatEditText { ...@@ -282,7 +442,6 @@ public class MyEditText extends AppCompatEditText {
public CharSequence subSequence(int start, int end) { public CharSequence subSequence(int start, int end) {
return mSource.subSequence(start, end); return mSource.subSequence(start, end);
} }
} }
} }
......
...@@ -6,7 +6,8 @@ ...@@ -6,7 +6,8 @@
<item name="colorPrimaryDark">@color/theme_color</item> <item name="colorPrimaryDark">@color/theme_color</item>
<item name="colorAccent">@color/theme_color</item> <item name="colorAccent">@color/theme_color</item>
<!--<item name="android:alertDialogTheme">@style/Theme.AppCompat.Light.Dialog.Alert.Self</item>--> <!--<item name="android:alertDialogTheme">@style/Theme.AppCompat.Light.Dialog.Alert.Self</item>-->
<item name="android:windowAnimationStyle">@style/activityAnimation</item><!-- 设置activity切换动画 --> <item name="android:windowAnimationStyle">@style/activityAnimation
</item><!-- 设置activity切换动画 -->
</style> </style>
<!-- animation 样式 --> <!-- animation 样式 -->
...@@ -18,8 +19,6 @@ ...@@ -18,8 +19,6 @@
</style> </style>
<declare-styleable name="MyEditText"> <declare-styleable name="MyEditText">
<!-- 最大長度--> <!-- 最大長度-->
<attr name="ed_MaxLength" format="integer" /> <attr name="ed_MaxLength" format="integer" />
...@@ -36,16 +35,17 @@ ...@@ -36,16 +35,17 @@
<attr name="ed_maxLengthMarginLeft" format="dimension" /> <attr name="ed_maxLengthMarginLeft" format="dimension" />
<attr name="ed_maxLengthMarginRight" format="dimension" /> <attr name="ed_maxLengthMarginRight" format="dimension" />
<attr name="ed_maxLengthMarginBottom" format="dimension" /> <attr name="ed_maxLengthMarginBottom" format="dimension" />
<!-- <attr name="ed_maxLengthLocation" format="enum">--> <attr name="ed_btn_marginTop" format="dimension" />
<!-- <enum name="ALIGN_PARENT_BOTTOM">12</enum>--> <attr name="ed_btn_marginRight" format="dimension" />
<!-- <enum name="ALIGN_PARENT_LEFT">9</enum>--> <attr name="ed_btn_marginBottom" format="dimension" />
<!-- <enum name="ALIGN_PARENT_RIGHT">11</enum>--> <attr name="ed_btn_marginLeft" format="dimension" />
<!-- <enum name="ALIGN_PARENT_TOP">10</enum>-->
<!-- <enum name="ALIGN_RIGHT">7</enum>--> <attr name="ed_hint" format="string" />
<!-- <enum name="ALIGN_TOP">6</enum>--> <attr name="ed_hintColor" format="color" />
<!-- <enum name="ALIGN_LEFT">5</enum>--> <attr name="ed_textColor" format="color" />
<!-- <enum name="ALIGN_BOTTOM">8</enum>--> <attr name="ed_text" format="string" />
<!-- </attr>--> <attr name="ed_textSize" format="dimension" />
<!-- 是否能輸入表情--> <!-- 是否能輸入表情-->
<attr name="ed_isInputIcon" format="boolean" /> <attr name="ed_isInputIcon" format="boolean" />
<!-- 輸入表情時提示的內容--> <!-- 輸入表情時提示的內容-->
...@@ -67,6 +67,48 @@ ...@@ -67,6 +67,48 @@
<attr name="ed_singLeLine" format="boolean" /> <attr name="ed_singLeLine" format="boolean" />
<attr name="ed_clear_gravity">
<flag name="rightTop" value="1" />
<flag name="rightCenter" value="2" />
<flag name="rightBottom" value="3" />
</attr>
<attr name="ed_gravity">
<!-- Push object to the top of its container, not changing its size. -->
<flag name="top" value="0x30" />
<!-- Push object to the bottom of its container, not changing its size. -->
<flag name="bottom" value="0x50" />
<!-- Push object to the left of its container, not changing its size. -->
<flag name="left" value="0x03" />
<!-- Push object to the right of its container, not changing its size. -->
<flag name="right" value="0x05" />
<!-- Place object in the vertical center of its container, not changing its size. -->
<flag name="center_vertical" value="0x10" />
<!-- Grow the vertical size of the object if needed so it completely fills its container. -->
<flag name="fill_vertical" value="0x70" />
<!-- Place object in the horizontal center of its container, not changing its size. -->
<flag name="center_horizontal" value="0x01" />
<!-- Grow the horizontal size of the object if needed so it completely fills its container. -->
<flag name="fill_horizontal" value="0x07" />
<!-- Place the object in the center of its container in both the vertical and horizontal axis, not changing its size. -->
<flag name="center" value="0x11" />
<!-- Grow the horizontal and vertical size of the object if needed so it completely fills its container. -->
<flag name="fill" value="0x77" />
<!-- Additional option that can be set to have the top and/or bottom edges of
the child clipped to its container's bounds.
The clip will be based on the vertical gravity: a top gravity will clip the bottom
edge, a bottom gravity will clip the top edge, and neither will clip both edges. -->
<flag name="clip_vertical" value="0x80" />
<!-- Additional option that can be set to have the left and/or right edges of
the child clipped to its container's bounds.
The clip will be based on the horizontal gravity: a left gravity will clip the right
edge, a right gravity will clip the left edge, and neither will clip both edges. -->
<flag name="clip_horizontal" value="0x08" />
<!-- Push object to the beginning of its container, not changing its size. -->
<flag name="start" value="0x00800003" />
<!-- Push object to the end of its container, not changing its size. -->
<flag name="end" value="0x00800005" />
</attr>
<attr name="inputType"> <attr name="inputType">
<!-- There is no content type. The text is not editable. --> <!-- There is no content type. The text is not editable. -->
......
...@@ -43,7 +43,6 @@ dependencies { ...@@ -43,7 +43,6 @@ dependencies {
implementation rootProject.ext.dependencies["constraintlayout"] implementation rootProject.ext.dependencies["constraintlayout"]
implementation rootProject.ext.dependencies["retrofit-url-manager"] implementation rootProject.ext.dependencies["retrofit-url-manager"]
// annotationProcessor rootProject.ext.dependencies["butterknife-compiler"] //Butterknife 插件, 很多人因为没加这个而报错, 切记!!! // annotationProcessor rootProject.ext.dependencies["butterknife-compiler"] //Butterknife 插件, 很多人因为没加这个而报错, 切记!!!
annotationProcessor rootProject.ext.dependencies["dagger2-compiler"]//依赖插件 annotationProcessor rootProject.ext.dependencies["dagger2-compiler"]//依赖插件
implementation rootProject.ext.dependencies["autosize"] implementation rootProject.ext.dependencies["autosize"]
......
...@@ -8,12 +8,6 @@ ...@@ -8,12 +8,6 @@
<meta-data <meta-data
android:name="network.config.GlobalConfiguration" android:name="network.config.GlobalConfiguration"
android:value="ConfigModule" /> android:value="ConfigModule" />
<meta-data
android:name="design_width_in_dp"
android:value="400" />
<meta-data
android:name="design_height_in_dp"
android:value="705" />
</application> </application>
</manifest> </manifest>
...@@ -16,6 +16,12 @@ ...@@ -16,6 +16,12 @@
</intent-filter> </intent-filter>
</activity> </activity>
<meta-data
android:name="design_width_in_dp"
android:value="360" />
<meta-data
android:name="design_height_in_dp"
android:value="540" />
</application> </application>
</manifest> </manifest>
......
...@@ -2,6 +2,9 @@ package com.gingersoft.gsa.cloud.user.login.mvp.ui.activity; ...@@ -2,6 +2,9 @@ package com.gingersoft.gsa.cloud.user.login.mvp.ui.activity;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import com.gingersoft.gsa.cloud.user.login.R; import com.gingersoft.gsa.cloud.user.login.R;
import com.gingersoft.gsa.cloud.user.login.di.component.DaggerLoginComponent; import com.gingersoft.gsa.cloud.user.login.di.component.DaggerLoginComponent;
...@@ -12,10 +15,14 @@ import com.jess.arms.utils.ArmsUtils; ...@@ -12,10 +15,14 @@ import com.jess.arms.utils.ArmsUtils;
import com.gingersoft.gsa.cloud.user.login.mvp.contract.LoginContract; import com.gingersoft.gsa.cloud.user.login.mvp.contract.LoginContract;
import com.gingersoft.gsa.cloud.user.login.mvp.presenter.LoginPresenter; import com.gingersoft.gsa.cloud.user.login.mvp.presenter.LoginPresenter;
import com.joe.base.widget.view.MyEditText;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import static com.jess.arms.utils.Preconditions.checkNotNull; import static com.jess.arms.utils.Preconditions.checkNotNull;
...@@ -32,7 +39,11 @@ import static com.jess.arms.utils.Preconditions.checkNotNull; ...@@ -32,7 +39,11 @@ import static com.jess.arms.utils.Preconditions.checkNotNull;
* <a href="https://github.com/JessYanCoding/MVPArmsTemplate">模版请保持更新</a> * <a href="https://github.com/JessYanCoding/MVPArmsTemplate">模版请保持更新</a>
* ================================================ * ================================================
*/ */
public class LoginActivity extends BaseActivity<LoginPresenter> implements LoginContract.View { public class LoginActivity extends BaseActivity<LoginPresenter> implements LoginContract.View, View.OnClickListener {
@BindView(R.id.ed_login_user_account)
MyEditText edAccount;
@BindView(R.id.ed_login_user_pwd)
MyEditText edPwd;
@Override @Override
public void setupActivityComponent(@NonNull AppComponent appComponent) { public void setupActivityComponent(@NonNull AppComponent appComponent) {
...@@ -46,11 +57,16 @@ public class LoginActivity extends BaseActivity<LoginPresenter> implements Login ...@@ -46,11 +57,16 @@ public class LoginActivity extends BaseActivity<LoginPresenter> implements Login
@Override @Override
public int initView(@Nullable Bundle savedInstanceState) { public int initView(@Nullable Bundle savedInstanceState) {
return R.layout.user_login_activity_login; //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0 return R.layout.user_login_activity_login; //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0
} }
@Override @Override
public void initData(@Nullable Bundle savedInstanceState) { public void initData(@Nullable Bundle savedInstanceState) {
ButterKnife.bind(this);
findViewById(R.id.tv_gsa_user_login).setOnClickListener(this);
edAccount = findViewById(R.id.ed_login_user_account);
edPwd = findViewById(R.id.ed_login_user_pwd);
} }
...@@ -85,4 +101,17 @@ public class LoginActivity extends BaseActivity<LoginPresenter> implements Login ...@@ -85,4 +101,17 @@ public class LoginActivity extends BaseActivity<LoginPresenter> implements Login
public void loginOut() { public void loginOut() {
} }
@OnClick({R.id.tv_gsa_user_login})
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.tv_gsa_user_login:
//登陸
if (edAccount.getText() != null && edPwd.getText() != null) {
mPresenter.login(edAccount.getText().toString(), edPwd.getText().toString());
}
break;
}
}
} }
...@@ -24,39 +24,78 @@ ...@@ -24,39 +24,78 @@
android:layout_width="40dp" android:layout_width="40dp"
android:layout_height="40dp" android:layout_height="40dp"
android:layout_marginLeft="10dp" android:layout_marginLeft="10dp"
android:layout_marginTop="100dp"
android:background="@color/theme_color" android:background="@color/theme_color"
android:padding="8dp" android:padding="8dp"
android:layout_marginTop="100dp"
android:src="@mipmap/ic_user" android:src="@mipmap/ic_user"
app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@id/login_title"/> app:layout_constraintTop_toBottomOf="@id/login_title" />
<com.joe.base.widget.view.MyEditText
<EditText
android:id="@+id/ed_login_user_account" android:id="@+id/ed_login_user_account"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="0dp" android:layout_height="0dp"
android:hint="請輸入賬戶"
android:padding="10dp" android:padding="10dp"
android:textColorHint="@color/user_login_edit_color" app:ed_MaxLength="11"
app:layout_constraintTop_toTopOf="@id/login_icon" app:ed_clearIconSize="30dp"
app:ed_clearRes="@mipmap/ic_clear_text"
app:ed_hint="請輸入賬戶"
app:ed_hintColor="@color/user_login_edit_color"
app:ed_isInputIcon="false"
app:ed_singLeLine="true"
app:ed_text="admin"
app:ed_textColor="#333"
app:ed_textSize="@dimen/edit_text_size"
app:layout_constraintBottom_toBottomOf="@id/login_icon" app:layout_constraintBottom_toBottomOf="@id/login_icon"
android:textSize="@dimen/edit_text_size"
app:layout_constraintLeft_toRightOf="@id/login_icon" app:layout_constraintLeft_toRightOf="@id/login_icon"
app:layout_constraintRight_toRightOf="parent" /> app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="@id/login_icon" />
<ImageView
android:id="@+id/iv_login_pwd_icon"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:background="@color/theme_color"
android:padding="8dp"
android:src="@mipmap/ic_pwd"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@id/ed_login_user_account" />
<EditText <com.joe.base.widget.view.MyEditText
android:id="@+id/ed_login_user_pwd" android:id="@+id/ed_login_user_pwd"
android:layout_width="match_parent" android:layout_width="0dp"
android:layout_height="50dp" android:layout_height="0dp"
android:background="#00000000" android:background="#00000000"
android:hint="請輸入密碼"
android:padding="10dp" android:padding="10dp"
android:textColor="#333" app:ed_MaxLength="16"
android:textColorHint="@color/user_login_edit_color" app:ed_clearIconSize="30dp"
android:textSize="@dimen/edit_text_size" app:ed_clearRes="@mipmap/ic_clear_text"
app:layout_constraintTop_toBottomOf="@id/ed_login_user_account" /> app:ed_hint="請輸入密碼"
app:ed_hintColor="@color/user_login_edit_color"
app:ed_isInputIcon="false"
app:ed_singLeLine="true"
app:ed_text="123456"
app:ed_textColor="#333"
app:ed_textSize="@dimen/edit_text_size"
app:inputType="numberPassword"
app:layout_constraintBottom_toBottomOf="@id/iv_login_pwd_icon"
app:layout_constraintLeft_toRightOf="@id/iv_login_pwd_icon"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="@id/iv_login_pwd_icon" />
<TextView
android:id="@+id/tv_forget_pwd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="忘記密碼?"
android:textSize="14dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/ed_login_user_pwd" />
<TextView <TextView
android:id="@+id/tv_gsa_user_login" android:id="@+id/tv_gsa_user_login"
...@@ -71,6 +110,6 @@ ...@@ -71,6 +110,6 @@
android:text="登陸" android:text="登陸"
android:textColor="#fff" android:textColor="#fff"
android:textSize="16dp" android:textSize="16dp"
app:layout_constraintTop_toBottomOf="@id/ed_login_user_pwd" /> app:layout_constraintTop_toBottomOf="@id/tv_forget_pwd" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment