Commit 58ad4489 by YKai

feat:代码提交

parent e65e3fce
package com.yidianling.listener;
import android.app.Activity;
import android.graphics.Rect;
import android.view.View;
/**
* Created by Ykai on 2020/9/11.
*
* 键盘打开关闭监听类
*/
public class SoftKeyBoardListener {
private View rootView; //activity的根视图
int rootViewVisibleHeight; //纪录根视图的显示高度
private OnSoftKeyBoardChangeListener onSoftKeyBoardChangeListener;
public SoftKeyBoardListener(Activity activity) {
//获取activity的根视图
rootView = activity.getWindow().getDecorView();
//监听视图树中全局布局发生改变或者视图树中的某个视图的可视状态发生改变
rootView.getViewTreeObserver().addOnGlobalLayoutListener(() -> {
//获取当前根视图在屏幕上显示的大小
Rect r = new Rect();
rootView.getWindowVisibleDisplayFrame(r);
int visibleHeight = r.height();
System.out.println("" + visibleHeight);
if (rootViewVisibleHeight == 0) {
rootViewVisibleHeight = visibleHeight;
return;
}
//根视图显示高度没有变化,可以看作软键盘显示/隐藏状态没有改变
if (rootViewVisibleHeight == visibleHeight) {
return;
}
//根视图显示高度变小超过200,可以看作软键盘显示了
if (rootViewVisibleHeight - visibleHeight > 200) {
if (onSoftKeyBoardChangeListener != null) {
onSoftKeyBoardChangeListener.keyBoardShow(rootViewVisibleHeight - visibleHeight);
}
rootViewVisibleHeight = visibleHeight;
return;
}
//根视图显示高度变大超过200,可以看作软键盘隐藏了
if (visibleHeight - rootViewVisibleHeight > 200) {
if (onSoftKeyBoardChangeListener != null) {
onSoftKeyBoardChangeListener.keyBoardHide(visibleHeight - rootViewVisibleHeight);
}
rootViewVisibleHeight = visibleHeight;
}
});
}
private void setOnSoftKeyBoardChangeListener(OnSoftKeyBoardChangeListener onSoftKeyBoardChangeListener) {
this.onSoftKeyBoardChangeListener = onSoftKeyBoardChangeListener;
}
public interface OnSoftKeyBoardChangeListener {
void keyBoardShow(int height);
void keyBoardHide(int height);
}
public static void setListener(Activity activity, OnSoftKeyBoardChangeListener onSoftKeyBoardChangeListener) {
SoftKeyBoardListener softKeyBoardListener = new SoftKeyBoardListener(activity);
softKeyBoardListener.setOnSoftKeyBoardChangeListener(onSoftKeyBoardChangeListener);
}
}
package com.yidianling.uikit.business.session.view package com.yidianling.uikit.business.session.view
import android.app.Activity
import android.content.Context import android.content.Context
import android.graphics.drawable.BitmapDrawable import android.graphics.drawable.BitmapDrawable
import android.os.Build
import android.view.Gravity import android.view.Gravity
import android.view.KeyEvent import android.view.KeyEvent
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.PopupWindow import android.widget.PopupWindow
import androidx.annotation.RequiresApi
import com.yidianling.common.tools.ToastUtil import com.yidianling.common.tools.ToastUtil
import com.yidianling.uikit.custom.http.response.question.QuestionsInfoBean import com.yidianling.uikit.custom.http.response.question.QuestionsInfoBean
...@@ -18,7 +21,7 @@ import com.yidianling.uikit.custom.http.response.question.QuestionsInfoBean ...@@ -18,7 +21,7 @@ import com.yidianling.uikit.custom.http.response.question.QuestionsInfoBean
* @Company 壹点灵 * @Company 壹点灵
* @date 2019/12/10 * @date 2019/12/10
*/ */
class CollectInfoPopupWindow(var mContext: Context, var listener: OnSendMsgListener) : class CollectInfoPopupWindow(var mContext: Activity, var listener: OnSendMsgListener) :
PopupWindow(mContext) { PopupWindow(mContext) {
private var collectUserInformationView: QuestionInformationView private var collectUserInformationView: QuestionInformationView
private var isFromBack = true private var isFromBack = true
...@@ -53,11 +56,8 @@ class CollectInfoPopupWindow(var mContext: Context, var listener: OnSendMsgListe ...@@ -53,11 +56,8 @@ class CollectInfoPopupWindow(var mContext: Context, var listener: OnSendMsgListe
isOutsideTouchable = false isOutsideTouchable = false
} }
@RequiresApi(Build.VERSION_CODES.N)
fun setData(questionInfo: QuestionsInfoBean) { fun setData(questionInfo: QuestionsInfoBean) {
if (questionInfo == null) {
ToastUtil.toastShort("数据异常,请稍后重试")
return
}
collectUserInformationView.setData(questionInfo) collectUserInformationView.setData(questionInfo)
} }
......
package com.yidianling.uikit.business.session.view package com.yidianling.uikit.business.session.view
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.app.Activity
import android.content.Context import android.content.Context
import android.os.Build import android.os.Build
import android.os.Handler
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.view.inputmethod.InputMethodManager import android.view.inputmethod.InputMethodManager
...@@ -13,8 +15,11 @@ import androidx.recyclerview.widget.LinearLayoutManager ...@@ -13,8 +15,11 @@ import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.ydl.ydlcommon.utils.Utils import com.ydl.ydlcommon.utils.Utils
import com.ydl.ydlcommon.view.dialog.CommonDialog import com.ydl.ydlcommon.view.dialog.CommonDialog
import com.yidianling.common.tools.LogUtil
import com.yidianling.common.tools.RxKeyboardTool
import com.yidianling.common.tools.ToastUtil import com.yidianling.common.tools.ToastUtil
import com.yidianling.im.R import com.yidianling.im.R
import com.yidianling.listener.SoftKeyBoardListener
import com.yidianling.uikit.business.session.view.question.QuestionAdapter import com.yidianling.uikit.business.session.view.question.QuestionAdapter
import com.yidianling.uikit.business.session.view.question.QuestionMultiItem import com.yidianling.uikit.business.session.view.question.QuestionMultiItem
import com.yidianling.uikit.business.session.view.question.QuestionOneCheckListener import com.yidianling.uikit.business.session.view.question.QuestionOneCheckListener
...@@ -34,7 +39,7 @@ import kotlin.collections.ArrayList ...@@ -34,7 +39,7 @@ import kotlin.collections.ArrayList
*/ */
@SuppressLint("ViewConstructor") @SuppressLint("ViewConstructor")
class QuestionInformationView( class QuestionInformationView(
var mContext: Context, var mContext: Activity,
var skipEvent: () -> Unit, var skipEvent: () -> Unit,
var backEvent: () -> Unit, var backEvent: () -> Unit,
var sendMsgEvent: (content: String, list: List<QuestionsInfoBean>) -> Unit var sendMsgEvent: (content: String, list: List<QuestionsInfoBean>) -> Unit
...@@ -83,7 +88,7 @@ class QuestionInformationView( ...@@ -83,7 +88,7 @@ class QuestionInformationView(
//使用下一题nextQuestionId 取到题 //使用下一题nextQuestionId 取到题
val questionsBean = mQuestionBean!!.questions[nextQuestionId] val questionsBean = mQuestionBean!!.questions[nextQuestionId]
if (questionsBean!=null){ if (questionsBean != null) {
//还有下一题 //还有下一题
questionMultiItem2.questionsBean = questionsBean questionMultiItem2.questionsBean = questionsBean
if ("radio" == questionsBean?.type) { if ("radio" == questionsBean?.type) {
...@@ -92,7 +97,7 @@ class QuestionInformationView( ...@@ -92,7 +97,7 @@ class QuestionInformationView(
questionMultiItem2.viewType = 4 questionMultiItem2.viewType = 4
} }
mData.add(questionMultiItem2) mData.add(questionMultiItem2)
}else{ } else {
//没有下一题了 //没有下一题了
} }
...@@ -105,12 +110,20 @@ class QuestionInformationView( ...@@ -105,12 +110,20 @@ class QuestionInformationView(
} }
override fun showOtherEdit(list: List<OptionsBean?>?) { override fun showOtherEdit(list: List<OptionsBean?>?) {
// 滚动到底部 //显示输入框
recycle.smoothScrollToPosition(mData.size-1)
//弹出输入框
cl_input.visibility = VISIBLE cl_input.visibility = VISIBLE
tv_problem.visibility = VISIBLE
var problem = "已选:"
list?.forEach {
problem+="# "+it?.name
}
tv_problem.text = problem
// 打开软件盘 // 打开软件盘
showInputMethod(et_input_problem)
// 滚动到底部
Handler().postDelayed({
recycle.scrollToPosition(mData.size - 1)
}, 500L)
} }
}) })
...@@ -142,8 +155,16 @@ class QuestionInformationView( ...@@ -142,8 +155,16 @@ class QuestionInformationView(
} }
} }
// 监听键盘状态
SoftKeyBoardListener.setListener(mContext,
object : SoftKeyBoardListener.OnSoftKeyBoardChangeListener {
override fun keyBoardShow(height: Int) {
recycle.smoothScrollToPosition(mData.size - 1)
}
// mQuestionAdapter.notifyDataSetChanged() override fun keyBoardHide(height: Int) {
}
})
} }
......
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