Quellcode durchsuchen

设置支付密码的页面与逻辑

liukai vor 2 Jahren
Ursprung
Commit
115c524cca

+ 2 - 0
cpt_ewallet/src/main/AndroidManifest.xml

@@ -16,6 +16,8 @@
 
         <activity android:name=".ui.AppointmentEnquiryDetailActivity"/>
 
+        <activity android:name=".ui.PaymentPsdActivity"/>
+
     </application>
 
 </manifest>

+ 42 - 0
cpt_ewallet/src/main/java/com/hongyegroup/cpt_ewallet/mvvm/PaymentPsdViewModel.kt

@@ -0,0 +1,42 @@
+package com.hongyegroup.cpt_ewallet.mvvm
+
+import androidx.lifecycle.LiveData
+import androidx.lifecycle.SavedStateHandle
+import androidx.lifecycle.liveData
+import com.guadou.lib_baselib.base.vm.BaseViewModel
+import dagger.hilt.android.lifecycle.HiltViewModel
+import kotlinx.coroutines.delay
+import javax.inject.Inject
+
+@HiltViewModel
+class PaymentPsdViewModel @Inject constructor(
+    private val savedStateHandle: SavedStateHandle
+) : BaseViewModel() {
+
+    var mFirstPassword: String = ""
+
+    //设置支付密码
+    fun setPaymentPassword(code: String): LiveData<Boolean> {
+
+        return liveData {
+            loadStartProgress()
+            delay(1000)
+            loadHideProgress()
+            emit(true)
+        }
+
+    }
+
+    //验证支付密码
+    fun validPaymentPassword(code: String): LiveData<Boolean> {
+
+        return liveData {
+            loadStartProgress()
+            delay(1000)
+            loadHideProgress()
+            emit(true)
+        }
+
+    }
+
+}

+ 1 - 1
cpt_ewallet/src/main/java/com/hongyegroup/cpt_ewallet/ui/EWalletMainFragment.kt

@@ -116,7 +116,7 @@ class EWalletMainFragment(private val needBackLayout: Boolean) : YYBaseVDBFragme
 
         //去设置密码页面
         fun gotoSetPsdPage() {
-            toast("去设置密码页面")
+            PaymentPsdActivity.startInstance(0)
         }
 
         //去提现页面

+ 230 - 0
cpt_ewallet/src/main/java/com/hongyegroup/cpt_ewallet/ui/PaymentPsdActivity.kt

@@ -0,0 +1,230 @@
+package com.hongyegroup.cpt_ewallet.ui
+
+import android.content.Intent
+import android.os.Bundle
+import android.view.View
+import android.widget.TextView
+import com.guadou.cs_cptservices.base.activity.YYBaseVDBActivity
+import com.guadou.lib_baselib.bean.DataBindingConfig
+import com.guadou.lib_baselib.engine.toast
+import com.guadou.lib_baselib.ext.commContext
+import com.guadou.lib_baselib.ext.gotoActivity
+import com.guadou.lib_baselib.utils.CommUtils
+import com.guadou.lib_baselib.utils.KeyboardUtils
+import com.hongyegroup.cpt_ewallet.BR
+import com.hongyegroup.cpt_ewallet.R
+import com.hongyegroup.cpt_ewallet.databinding.ActivityPaymentPsdBinding
+import com.hongyegroup.cpt_ewallet.mvvm.PaymentPsdViewModel
+import kotlinx.coroutines.flow.MutableStateFlow
+
+/**
+ * 支付密码的设置/修改页面
+ *
+ * 0为设置密码页面  1为重置密码页面 2.设置新密码 3确认密码页面
+ */
+class PaymentPsdActivity : YYBaseVDBActivity<PaymentPsdViewModel, ActivityPaymentPsdBinding>() {
+
+    private val mClickProxy by lazy { ClickProxy() }
+    private var mStatus = 0   //当前的页面状态
+
+    companion object {
+        fun startInstance(status: Int) {
+            commContext().gotoActivity<PaymentPsdActivity>(bundle = arrayOf(Pair("status", status)))
+        }
+    }
+
+    override fun getDataFromIntent(intent: Intent) {
+        mStatus = intent.getIntExtra("status", 0)
+    }
+
+    override fun getDataBindingConfig(): DataBindingConfig {
+        return DataBindingConfig(R.layout.activity_payment_psd, BR.viewModel, mViewModel)
+            .addBindingParams(BR.click, mClickProxy)
+    }
+
+    override fun startObserve() {
+
+    }
+
+    override fun init(savedInstanceState: Bundle?) {
+        setStatusBarBlackText()
+
+        setupTextWithStatus()
+    }
+
+    //根据状态更改文本样式
+    private fun setupTextWithStatus() {
+
+        //默认设置第一个选择的背景和对话框
+        CommUtils.getHandler().postDelayed({
+            KeyboardUtils.showSoftInput(mActivity, mBinding.editTextHidden)
+        }, 250)
+        mClickProxy.curSelectedIndex.value = 0
+
+        when (mStatus) {
+            0 -> {
+                mBinding.tvSetPsd.text = "设置支付密码"
+                mBinding.easyTitleBar.setTitle("设置支付密码")
+                mBinding.tvForgetPsd.visibility = View.VISIBLE
+            }
+            1 -> {
+                mBinding.tvSetPsd.text = "修改支付密码"
+                mBinding.easyTitleBar.setTitle("修改支付密码")
+                mBinding.tvForgetPsd.visibility = View.VISIBLE
+            }
+            2 -> {
+                mBinding.tvSetPsd.text = "设置新密码"
+                mBinding.easyTitleBar.setTitle("设置新密码")
+                mBinding.tvForgetPsd.visibility = View.GONE
+            }
+            3 -> {
+                mBinding.tvSetPsd.text = "确认新密码"
+                mBinding.easyTitleBar.setTitle("确认新密码")
+                mBinding.tvForgetPsd.visibility = View.GONE
+            }
+
+        }
+    }
+
+    //根据状态处理6位数验证码
+    private fun handleCodebyStatus(code: String) {
+        when (mStatus) {
+            0 -> {
+                //设置密码-调用接口设置支付密码
+                mViewModel.setPaymentPassword(code).observe(this) {
+                    toast("设置支付密码成功")
+                    finish()
+                }
+            }
+            1 -> {
+                //修改密码-调用接口验证支付密码
+                mViewModel.validPaymentPassword(code).observe(this) {
+                    //验证成功去设置新密码
+                    mClickProxy.resetETs()
+                    mStatus = if (it) 2 else 1
+                    setupTextWithStatus()
+                }
+            }
+            2 -> {
+                //设置新密码-记录第一次的密码
+                mViewModel.mFirstPassword = code
+                mClickProxy.resetETs()
+                mStatus = 3
+                setupTextWithStatus()
+            }
+            3 -> {
+                //确认新密码-判断密码是否一样
+                if (code == mViewModel.mFirstPassword) {
+                    mViewModel.setPaymentPassword(code).observe(this) {
+                        finish()
+                    }
+                } else {
+                    toast("确认密码失败")
+                }
+            }
+
+        }
+    }
+
+
+    /**
+     * DataBinding事件处理
+     */
+    inner class ClickProxy {
+
+        var curSelectedIndex = MutableStateFlow(0)  //当前输入的框框索引
+        var et1Code = MutableStateFlow("")
+        var et2Code = MutableStateFlow("")
+        var et3Code = MutableStateFlow("")
+        var et4Code = MutableStateFlow("")
+        var et5Code = MutableStateFlow("")
+        var et6Code = MutableStateFlow("")
+
+        val onHidenChanged: (String) -> Unit = { hiden ->
+            when (hiden.length) {
+                0 -> {
+                    curSelectedIndex.value = 0
+                    et1Code.value = ""
+                    et2Code.value = ""
+                    et3Code.value = ""
+                    et4Code.value = ""
+                    et5Code.value = ""
+                    et6Code.value = ""
+                }
+                1 -> {
+                    curSelectedIndex.value = 1
+                    et1Code.value = hiden[0].toString()
+                }
+                2 -> {
+                    curSelectedIndex.value = 2
+                    et2Code.value = hiden[1].toString()
+                }
+                3 -> {
+                    curSelectedIndex.value = 3
+                    et3Code.value = hiden[2].toString()
+                }
+                4 -> {
+                    curSelectedIndex.value = 4
+                    et4Code.value = hiden[3].toString()
+                }
+                5 -> {
+                    curSelectedIndex.value = 5
+                    et5Code.value = hiden[4].toString()
+                }
+                6 -> {
+                    curSelectedIndex.value = 6
+                    et6Code.value = hiden[5].toString()
+                    KeyboardUtils.hideSoftInput(mBinding.editTextSixthCode)
+
+                    //根据状态处理Code
+                    handleCodebyStatus(hiden)
+                }
+            }
+
+        }
+
+        //上面6个输入框的焦点获取
+        val onCodeETFocusGet: TextView.() -> Unit = {
+            setHidenFocus()
+            KeyboardUtils.showSoftkeyboard(mActivity)
+        }
+
+        //当按键Del触发的事件
+        val onKeyDelEvent: () -> Unit = {
+            val curCode = mBinding.editTextHidden.text.toString()
+            when (curCode.length) {
+                6 -> et6Code.value = ""
+                5 -> et5Code.value = ""
+                4 -> et4Code.value = ""
+                3 -> et3Code.value = ""
+                2 -> et2Code.value = ""
+                1 -> et1Code.value = ""
+            }
+            if (curCode.isNotEmpty()) {
+                mBinding.editTextHidden.setText(curCode.subSequence(0, curCode.length - 1))
+                mBinding.editTextHidden.setSelection(mBinding.editTextHidden.text.length)
+            }
+
+        }
+
+        //设置隐藏的Code框焦点
+        private fun setHidenFocus() {
+            mBinding.editTextHidden.isFocusable = true
+            mBinding.editTextHidden.isFocusableInTouchMode = true
+            mBinding.editTextHidden.requestFocus()
+            mBinding.editTextHidden.setSelection(mBinding.editTextHidden.text.length)
+        }
+
+        fun resetETs() {
+            curSelectedIndex.value = 0
+            et1Code.value = ""
+            et2Code.value = ""
+            et3Code.value = ""
+            et4Code.value = ""
+            et5Code.value = ""
+            et6Code.value = ""
+            mBinding.editTextHidden.setText("")
+        }
+    }
+
+}

+ 270 - 0
cpt_ewallet/src/main/res/layout/activity_payment_psd.xml

@@ -0,0 +1,270 @@
+<?xml version="1.0" encoding="utf-8"?>
+<layout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    xmlns:binding="http://schemas.android.com/apk/res-auto"
+    xmlns:tools="http://schemas.android.com/tools"
+    tools:ignore="RtlHardcoded">
+
+    <data>
+
+        <variable
+            name="viewModel"
+            type="com.hongyegroup.cpt_ewallet.mvvm.PaymentPsdViewModel" />
+
+        <variable
+            name="click"
+            type="com.hongyegroup.cpt_ewallet.ui.PaymentPsdActivity.ClickProxy" />
+
+        <import type="android.text.TextUtils" />
+
+    </data>
+
+    <LinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:background="@color/white"
+        android:orientation="vertical">
+
+        <com.guadou.lib_baselib.view.titlebar.EasyTitleBar
+            android:id="@+id/easy_title_bar"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            app:Easy_title="设置支付密码" />
+
+        <LinearLayout
+            android:layout_width="match_parent"
+            android:layout_height="match_parent"
+            android:background="@color/white"
+            android:orientation="vertical">
+
+            <com.guadou.lib_baselib.font_text_view.TextViewMedium
+                android:id="@+id/tv_set_psd"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_marginLeft="@dimen/d_24dp"
+                android:layout_marginTop="@dimen/d_35dp"
+                android:text="设置支付密码"
+                android:textColor="@color/black"
+                android:textSize="@dimen/d_22sp" />
+
+            <ImageView
+                android:layout_width="match_parent"
+                android:layout_height="@dimen/d_0.7dp"
+                android:layout_marginLeft="@dimen/d_20dp"
+                android:layout_marginTop="@dimen/d_18dp"
+                android:layout_marginRight="@dimen/d_20dp"
+                android:background="@color/divider_color" />
+
+            <com.guadou.lib_baselib.font_text_view.TextViewRegular
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_marginLeft="@dimen/d_25dp"
+                android:layout_marginTop="@dimen/d_20dp"
+                android:text="输入支付密码"
+                android:textColor="#767676"
+                android:textSize="@dimen/d_15sp" />
+
+            <LinearLayout
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:layout_marginLeft="@dimen/d_25dp"
+                android:layout_marginTop="@dimen/d_6dp"
+                android:baselineAligned="false"
+                android:orientation="horizontal">
+
+                <FrameLayout
+                    android:id="@+id/frame_first_code"
+                    android:layout_width="@dimen/d_40dp"
+                    android:layout_height="@dimen/d_40dp"
+                    android:layout_marginTop="@dimen/d_10dp"
+                    android:background="@{click.curSelectedIndex>=0?@drawable/white_input_finish:@drawable/white_input_field}"
+                    tools:background="@drawable/white_input_field">
+
+                    <EditText
+                        android:id="@+id/edit_text_first_code"
+                        android:layout_width="match_parent"
+                        android:layout_height="match_parent"
+                        android:background="@android:color/transparent"
+                        android:cursorVisible="false"
+                        android:gravity="center"
+                        android:inputType="number"
+                        android:maxLength="1"
+                        android:minEms="2"
+                        android:text="@{click.et1Code}"
+                        android:textColor="@color/profile_red"
+                        android:textSize="@dimen/d_23sp"
+                        binding:onFocusGet="@{click.onCodeETFocusGet}"
+                        binding:typefaceMedium="@{true}" />
+
+                </FrameLayout>
+
+                <FrameLayout
+                    android:id="@+id/frame_second_code"
+                    android:layout_width="@dimen/d_40dp"
+                    android:layout_height="@dimen/d_40dp"
+                    android:layout_marginLeft="@dimen/d_6dp"
+                    android:layout_marginTop="@dimen/d_10dp"
+                    android:background="@{click.curSelectedIndex>=1?@drawable/white_input_finish:@drawable/white_input_field}"
+                    tools:background="@drawable/white_input_field">
+
+                    <EditText
+                        android:id="@+id/edit_text_second_code"
+                        android:layout_width="match_parent"
+                        android:layout_height="match_parent"
+                        android:background="@android:color/transparent"
+                        android:cursorVisible="false"
+                        android:gravity="center"
+                        android:inputType="number"
+                        android:maxLength="1"
+                        android:minEms="2"
+                        android:text="@{click.et2Code}"
+                        android:textColor="@color/profile_red"
+                        android:textSize="@dimen/d_23sp"
+                        binding:onFocusGet="@{click.onCodeETFocusGet}"
+                        binding:typefaceMedium="@{true}" />
+
+                </FrameLayout>
+
+                <FrameLayout
+                    android:id="@+id/frame_third_code"
+                    android:layout_width="@dimen/d_40dp"
+                    android:layout_height="@dimen/d_40dp"
+                    android:layout_marginLeft="@dimen/d_6dp"
+                    android:layout_marginTop="@dimen/d_10dp"
+                    android:background="@{click.curSelectedIndex>=2?@drawable/white_input_finish:@drawable/white_input_field}"
+                    tools:background="@drawable/white_input_field">
+
+                    <EditText
+                        android:id="@+id/edit_text_third_code"
+                        android:layout_width="match_parent"
+                        android:layout_height="match_parent"
+                        android:background="@android:color/transparent"
+                        android:cursorVisible="false"
+                        android:gravity="center"
+                        android:inputType="number"
+                        android:maxLength="1"
+                        android:minEms="2"
+                        android:text="@{click.et3Code}"
+                        android:textColor="@color/profile_red"
+                        android:textSize="@dimen/d_23sp"
+                        binding:onFocusGet="@{click.onCodeETFocusGet}"
+                        binding:typefaceMedium="@{true}" />
+
+                </FrameLayout>
+
+                <FrameLayout
+                    android:id="@+id/frame_fourth_code"
+                    android:layout_width="@dimen/d_40dp"
+                    android:layout_height="@dimen/d_40dp"
+                    android:layout_marginLeft="@dimen/d_6dp"
+                    android:layout_marginTop="@dimen/d_10dp"
+                    android:background="@{click.curSelectedIndex>=3?@drawable/white_input_finish:@drawable/white_input_field}"
+                    tools:background="@drawable/white_input_field">
+
+                    <EditText
+                        android:id="@+id/edit_text_fourth_code"
+                        android:layout_width="match_parent"
+                        android:layout_height="match_parent"
+                        android:background="@android:color/transparent"
+                        android:cursorVisible="false"
+                        android:gravity="center"
+                        android:inputType="number"
+                        android:maxLength="1"
+                        android:minEms="2"
+                        android:text="@{click.et4Code}"
+                        android:textColor="@color/profile_red"
+                        android:textSize="@dimen/d_23sp"
+                        binding:onFocusGet="@{click.onCodeETFocusGet}"
+                        binding:typefaceMedium="@{true}" />
+
+                </FrameLayout>
+
+                <FrameLayout
+                    android:id="@+id/frame_fifth_code"
+                    android:layout_width="@dimen/d_40dp"
+                    android:layout_height="@dimen/d_40dp"
+                    android:layout_marginLeft="@dimen/d_6dp"
+                    android:layout_marginTop="@dimen/d_10dp"
+                    android:layout_marginBottom="@dimen/d_10dp"
+                    android:background="@{click.curSelectedIndex>=4?@drawable/white_input_finish:@drawable/white_input_field}"
+                    tools:background="@drawable/white_input_field">
+
+                    <EditText
+                        android:id="@+id/edit_text_fifth_code"
+                        android:layout_width="match_parent"
+                        android:layout_height="match_parent"
+                        android:background="@android:color/transparent"
+                        android:cursorVisible="false"
+                        android:gravity="center"
+                        android:inputType="number"
+                        android:maxLength="1"
+                        android:minEms="2"
+                        android:text="@{click.et5Code}"
+                        android:textColor="@color/profile_red"
+                        android:textSize="@dimen/d_23sp"
+                        binding:onFocusGet="@{click.onCodeETFocusGet}"
+                        binding:typefaceMedium="@{true}" />
+
+                </FrameLayout>
+
+                <FrameLayout
+                    android:id="@+id/frame_sixth_code"
+                    android:layout_width="@dimen/d_40dp"
+                    android:layout_height="@dimen/d_40dp"
+                    android:layout_marginLeft="@dimen/d_6dp"
+                    android:layout_marginTop="@dimen/d_10dp"
+                    android:layout_marginBottom="@dimen/d_10dp"
+                    android:background="@{click.curSelectedIndex>=5?@drawable/white_input_finish:@drawable/white_input_field}"
+                    tools:background="@drawable/white_input_field">
+
+                    <EditText
+                        android:id="@+id/edit_text_sixth_code"
+                        android:layout_width="match_parent"
+                        android:layout_height="match_parent"
+                        android:background="@android:color/transparent"
+                        android:cursorVisible="false"
+                        android:gravity="center"
+                        android:inputType="number"
+                        android:maxLength="1"
+                        android:minEms="2"
+                        android:text="@{click.et6Code}"
+                        android:textColor="@color/profile_red"
+                        android:textSize="@dimen/d_23sp"
+                        binding:onFocusGet="@{click.onCodeETFocusGet}"
+                        binding:typefaceMedium="@{true}" />
+
+                </FrameLayout>
+
+            </LinearLayout>
+
+            <EditText
+                android:id="@+id/edit_text_hidden"
+                android:layout_width="@dimen/d_1dp"
+                android:layout_height="@dimen/d_1dp"
+                android:layout_gravity="center_horizontal"
+                android:background="@null"
+                android:cursorVisible="false"
+                android:gravity="center_horizontal"
+                android:inputType="number"
+                android:maxLength="6"
+                android:textColor="@color/transparent"
+                binding:onKeyDel="@{click.onKeyDelEvent}"
+                binding:onTextChanged="@{click.onHidenChanged}" />
+
+
+            <com.guadou.lib_baselib.font_text_view.TextViewMedium
+                android:id="@+id/tv_forget_psd"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_marginLeft="@dimen/d_25dp"
+                android:layout_marginTop="@dimen/d_28dp"
+                android:text="忘记支付密码?"
+                android:textColor="@color/notify_dark_blue"
+                android:textSize="@dimen/d_13sp" />
+
+
+        </LinearLayout>
+
+    </LinearLayout>
+
+</layout>

+ 135 - 139
cs_baselib/src/main/java/com/guadou/lib_baselib/utils/KeyboardUtils.java

@@ -13,144 +13,140 @@ import android.widget.EditText;
  */
 public class KeyboardUtils {
 
-	/**
-	 * 为给定的编辑器开启软键盘
-	 * @param context 
-	 * @param editText 给定的编辑器
-	 */
-	public static void openSoftKeyboard(Context context, EditText editText){
-		editText.requestFocus();
-		 InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
-	        imm.showSoftInput(editText, InputMethodManager.RESULT_SHOWN);
-	        imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,
-	                InputMethodManager.HIDE_IMPLICIT_ONLY);
-	}
-
-	/**
-	 * 关闭软键盘
-	  */
-	public static void closeSoftKeyboard(View view){
-		InputMethodManager imm = (InputMethodManager) view.getContext()
-				.getSystemService(Context.INPUT_METHOD_SERVICE);
-		if (imm != null) {
-			imm.hideSoftInputFromWindow(view.getWindowToken(),0);
-		}
-	}
-
-
-	/**
-	 * 动态隐藏软键盘--√yyjobs
-	 */
-	public static void hideSoftInput(Activity activity) {
-		View view = activity.getCurrentFocus();
-		if (view == null) view = new View(activity);
-		InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
-		if (imm == null) return;
-		imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
-	}
-
-	/*
-	 * 显示键盘
-	 * */
-	public static void showKeyboard(Context context) {
-		InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
-		imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, 0);
-	}
-
-
-	/**
-	 * 切换软键盘状态 如果是弹出就隐藏
-	 *
-	 * @param activity
-	 */
-	public static void toggleSoftkeyboard(Activity activity) {
-		InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
-		imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
-	}
-
-
-	/**
-	 * 判断当前输入法是否打开
-	 *
-	 * @param activity
-	 * @return
-	 */
-	public static boolean getInputOpen(Activity activity) {
-		InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
-		return imm.isActive();//isOpen若返回true,则表示输入法打开
-	}
-
-
-	/**
-	 * 显示软键盘
-	 *
-	 * @param activity
-	 */
-	public static void showSoftkeyboard(Activity activity) {
-		try {
-			InputMethodManager inputManager =
-					(InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
-			inputManager.showSoftInput(activity.getCurrentFocus(), 0);
-		} catch (NullPointerException e) {
-
-		}
-	}
-
-	/**
-	 * 隐藏软键盘
-	 *
-	 * @param activity
-	 */
-	public static void hideSoftkeyboard(Activity activity) {
-		try {
-			((InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE))
-					.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(),
-							InputMethodManager.HIDE_NOT_ALWAYS);
-		} catch (NullPointerException e) {
-		}
-	}
-
-	// =======================  软键盘监听 begin ↓ =========================
-
-	/**
-	 * 监听输入键盘的谈起和收起
-	 *
-	 * @param activity
-	 * @param onSoftkeyboardChangeListener
-	 */
-	public static void setOnSoftkeyboardChangeListener(Activity activity, final OnSoftKeyBoardChangeListener onSoftkeyboardChangeListener) {
-
-		final View decorView = activity.getWindow().getDecorView();
-		decorView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
-
-			//当键盘弹出隐藏的时候会 调用此方法。
-			@Override
-			public void onGlobalLayout() {
-				final Rect rect = new Rect();
-				decorView.getWindowVisibleDisplayFrame(rect);
-				final int screenHeight = decorView.getRootView().getHeight();
-				final int heightDifference = screenHeight - rect.bottom;
-				boolean visible = heightDifference > screenHeight / 3;
-				onSoftkeyboardChangeListener.onSoftKeyBoardChange(visible, heightDifference);
-			}
-		});
-	}
-
-
-	/**
-	 * 监听软键盘的弹起和收起的回调
-	 */
-	public interface OnSoftKeyBoardChangeListener {
-
-		/**
-		 * 第一个参数是否显示
-		 * 第二个参数是软键盘高度
-		 *
-		 * @param isShow
-		 * @param keyboadHeight
-		 */
-		void onSoftKeyBoardChange(boolean isShow, int keyboadHeight);
-
-	}
+    /**
+     * 为给定的编辑器开启软键盘
+     *
+     */
+    public static void showSoftInput(Context context, EditText editText) {
+        editText.requestFocus();
+        InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
+        imm.showSoftInput(editText, InputMethodManager.RESULT_SHOWN);
+        imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
+    }
+
+    /**
+     * 关闭View的软键盘
+     */
+    public static void hideSoftInput(View view) {
+        InputMethodManager imm = (InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
+        if (imm != null) {
+            imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
+        }
+    }
+
+    /**
+     * 动态隐藏软键盘
+     */
+    public static void hideSoftInput(Activity activity) {
+        View view = activity.getCurrentFocus();
+        if (view == null) view = new View(activity);
+        InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
+        if (imm == null) return;
+        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
+    }
+
+    /*
+     * 显示键盘
+     * */
+    public static void showKeyboard(Context context) {
+        InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
+        imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, 0);
+    }
+
+
+    /**
+     * 切换软键盘状态 如果是弹出就隐藏
+     *
+     * @param activity
+     */
+    public static void toggleSoftkeyboard(Activity activity) {
+        InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
+        imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
+    }
+
+
+    /**
+     * 判断当前输入法是否打开
+     *
+     * @param activity
+     * @return
+     */
+    public static boolean getInputOpen(Activity activity) {
+        InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
+        return imm.isActive();//isOpen若返回true,则表示输入法打开
+    }
+
+
+    /**
+     * 显示软键盘
+     *
+     * @param activity
+     */
+    public static void showSoftkeyboard(Activity activity) {
+        try {
+            InputMethodManager inputManager =
+                    (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
+            inputManager.showSoftInput(activity.getCurrentFocus(), 0);
+        } catch (NullPointerException e) {
+
+        }
+    }
+
+    /**
+     * 隐藏软键盘
+     *
+     * @param activity
+     */
+    public static void hideSoftkeyboard(Activity activity) {
+        try {
+            ((InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE))
+                    .hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(),
+                            InputMethodManager.HIDE_NOT_ALWAYS);
+        } catch (NullPointerException e) {
+        }
+    }
+
+    // =======================  软键盘监听 begin ↓ =========================
+
+    /**
+     * 监听输入键盘的谈起和收起
+     *
+     * @param activity
+     * @param onSoftkeyboardChangeListener
+     */
+    public static void setOnSoftkeyboardChangeListener(Activity activity, final OnSoftKeyBoardChangeListener onSoftkeyboardChangeListener) {
+
+        final View decorView = activity.getWindow().getDecorView();
+        decorView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
+
+            //当键盘弹出隐藏的时候会 调用此方法。
+            @Override
+            public void onGlobalLayout() {
+                final Rect rect = new Rect();
+                decorView.getWindowVisibleDisplayFrame(rect);
+                final int screenHeight = decorView.getRootView().getHeight();
+                final int heightDifference = screenHeight - rect.bottom;
+                boolean visible = heightDifference > screenHeight / 3;
+                onSoftkeyboardChangeListener.onSoftKeyBoardChange(visible, heightDifference);
+            }
+        });
+    }
+
+
+    /**
+     * 监听软键盘的弹起和收起的回调
+     */
+    public interface OnSoftKeyBoardChangeListener {
+
+        /**
+         * 第一个参数是否显示
+         * 第二个参数是软键盘高度
+         *
+         * @param isShow
+         * @param keyboadHeight
+         */
+        void onSoftKeyBoardChange(boolean isShow, int keyboadHeight);
+
+    }
 
 }

+ 19 - 5
cs_cptServices/src/main/java/com/guadou/cs_cptservices/binding/BindingEditText.kt

@@ -38,7 +38,7 @@ var _clickRunnable = Runnable { _viewClickFlag = false }
 fun EditText.onKeyEnter(action: () -> Unit) {
     setOnKeyListener { _, keyCode, _ ->
         if (keyCode == KeyEvent.KEYCODE_ENTER) {
-            KeyboardUtils.closeSoftKeyboard(this)
+            KeyboardUtils.hideSoftInput(this)
 
             if (!_viewClickFlag) {
                 _viewClickFlag = true
@@ -52,13 +52,27 @@ fun EditText.onKeyEnter(action: () -> Unit) {
 }
 
 /**
+ * Edit的删除按键事件
+ */
+@BindingAdapter("onKeyDel")
+fun EditText.onKeyDel(action: () -> Unit) {
+    setOnKeyListener { _, keyCode, event ->
+        if (event.action == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_DEL) {
+            action()
+            return@setOnKeyListener true
+        }
+        return@setOnKeyListener false
+    }
+}
+
+/**
  * Edit的失去焦点监听
  */
 @BindingAdapter("onFocusLose")
-fun EditText.onFocusLose(action: (textView: TextView) -> Unit) {
+fun EditText.onFocusLose(action: TextView.() -> Unit) {
     setOnFocusChangeListener { _, hasFocus ->
         if (!hasFocus) {
-            action(this)
+            action()
         }
     }
 }
@@ -67,10 +81,10 @@ fun EditText.onFocusLose(action: (textView: TextView) -> Unit) {
  * Edit的得到焦点监听
  */
 @BindingAdapter("onFocusGet")
-fun EditText.onFocusGet(action: (textView: TextView) -> Unit) {
+fun EditText.onFocusGet(action: TextView.() -> Unit) {
     setOnFocusChangeListener { _, hasFocus ->
         if (hasFocus) {
-            action(this)
+            action()
         }
     }
 }

+ 11 - 0
cs_cptServices/src/main/res/drawable/white_input_field.xml

@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="utf-8"?>
+<shape xmlns:android="http://schemas.android.com/apk/res/android">
+    <solid android:color="@color/white" />
+
+    <stroke android:color="@color/main_divide"
+        android:width="0.5dp" />
+
+
+    <corners android:radius="2dp"/>
+
+</shape>

+ 11 - 0
cs_cptServices/src/main/res/drawable/white_input_finish.xml

@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="utf-8"?>
+<shape xmlns:android="http://schemas.android.com/apk/res/android">
+    <solid android:color="@color/white" />
+
+    <stroke android:color="@color/profile_red"
+        android:width="0.5dp" />
+
+
+    <corners android:radius="2dp" />
+
+</shape>

+ 0 - 25
cs_cptServices/src/main/res/values/styles.xml

@@ -1,31 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <resources>
 
-    <!--  点击波纹- 无边界  -->
-    <style name="SelectableItemBackgroundLess">
-        <item name="android:background">?attr/selectableItemBackgroundBorderless</item>
-    </style>
-
-    <!--  点击波纹- 有边界  -->
-    <style name="SelectableItemBackground">
-        <item name="android:background">?attr/selectableItemBackground</item>
-    </style>
-
-    <!--  Spinner下拉箭头颜色   -->
-    <style name="SpnStyle">
-        <item name="android:colorControlNormal">@color/app_blue</item>
-    </style>
-
-    <!--   自定义Switch样式 -->
-    <style name="scstyle" parent="Theme.AppCompat.Light">
-
-        <item name="colorControlActivated">#00000000</item>
-
-        <item name="colorSwitchThumbNormal">#00000000</item>
-
-        <item name="android:colorForeground">#00000000</item>
-    </style>
-
     <!--Image 圆角-->
     <declare-styleable name="custom_round_image">