diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellManagementActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellManagementActivity.kt index 6635978..6b22a8a 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/WellManagementActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/WellManagementActivity.kt @@ -50,24 +50,18 @@ }) } - private var clickTag = 0 - override fun initEvent() { wellTypeLayout.setOnClickListener { //旋转arrowImageView val rotateAnimation = arrowImageView.animate() rotateAnimation.duration = 200 rotateAnimation.interpolator = LinearInterpolator() - if (clickTag % 2 == 0) { - rotateAnimation.rotation(180f) - } else { - rotateAnimation.rotation(0f) - } - clickTag++ + rotateAnimation.rotation(180f) easyPopupWindow.showAsDropDown(wellTypeLayout) easyPopupWindow.setOnPopupWindowClickListener(object : EasyPopupWindow.OnPopupWindowClickListener { override fun onPopupClick(position: Int) { + rotateAnimation.rotation(0f) wellTypeView.text = items[position].name } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellManagementActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellManagementActivity.kt index 6635978..6b22a8a 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/WellManagementActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/WellManagementActivity.kt @@ -50,24 +50,18 @@ }) } - private var clickTag = 0 - override fun initEvent() { wellTypeLayout.setOnClickListener { //旋转arrowImageView val rotateAnimation = arrowImageView.animate() rotateAnimation.duration = 200 rotateAnimation.interpolator = LinearInterpolator() - if (clickTag % 2 == 0) { - rotateAnimation.rotation(180f) - } else { - rotateAnimation.rotation(0f) - } - clickTag++ + rotateAnimation.rotation(180f) easyPopupWindow.showAsDropDown(wellTypeLayout) easyPopupWindow.setOnPopupWindowClickListener(object : EasyPopupWindow.OnPopupWindowClickListener { override fun onPopupClick(position: Int) { + rotateAnimation.rotation(0f) wellTypeView.text = items[position].name } }) diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/EasyPopupWindow.kt b/app/src/main/java/com/casic/app/smartwell/widgets/EasyPopupWindow.kt index 061b0a7..7774066 100644 --- a/app/src/main/java/com/casic/app/smartwell/widgets/EasyPopupWindow.kt +++ b/app/src/main/java/com/casic/app/smartwell/widgets/EasyPopupWindow.kt @@ -1,88 +1,88 @@ -package com.casic.app.smartwell.widgets - -import android.content.Context -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import android.widget.* -import com.casic.app.smartwell.R -import com.casic.app.smartwell.model.WellTypeModel -import com.pengxh.app.multilib.utils.SizeUtil - -/** - * @description: 顶部下拉菜单 - * @author: Pengxh - * @email: 290677893@qq.com - * @date: 2019/12/28 20:35 - */ -class EasyPopupWindow(private val ctx: Context) : PopupWindow(ctx) { - - private var mClickListener: OnPopupWindowClickListener? = null - private var items: List = ArrayList() - - init { - width = (SizeUtil.getScreenWidth(ctx) * 0.25).toInt() - height = ViewGroup.LayoutParams.WRAP_CONTENT - isOutsideTouchable = true - isFocusable = true - animationStyle = R.style.PopupAnimation - contentView = LayoutInflater.from(ctx).inflate(R.layout.popup_well_type, null, false) - } - - fun setupPopupData(itemList: List) { - this.items = itemList - val popupListView = contentView.findViewById(R.id.popupListView) - setupListView(popupListView) - } - - //给PopupWindow列表绑定数据 - private fun setupListView(popupListView: ListView) { - val adapter = PopupAdapter() - popupListView.adapter = adapter - popupListView.onItemClickListener = - AdapterView.OnItemClickListener { _, _, i, _ -> - if (mClickListener != null) { - mClickListener!!.onPopupClick(i) - } - dismiss() - } - } - - interface OnPopupWindowClickListener { - fun onPopupClick(position: Int) - } - - fun setOnPopupWindowClickListener(windowClickListener: OnPopupWindowClickListener?) { - mClickListener = windowClickListener - } - - inner class PopupAdapter : BaseAdapter() { - - private val inflater: LayoutInflater = LayoutInflater.from(ctx) - - override fun getCount(): Int = items.size - - override fun getItem(position: Int): Any = items[position] - - override fun getItemId(position: Int): Long = position.toLong() - - override fun getView(position: Int, convertView: View?, parent: ViewGroup): View { - val view: View - val holder: ItemViewHolder - if (convertView == null) { - view = inflater.inflate(R.layout.item_popup, null) - holder = ItemViewHolder(view) - view.tag = holder - } else { - view = convertView - holder = view.tag as ItemViewHolder - } - holder.popupTitle.text = items[position].name - return view - } - } - - class ItemViewHolder(itemView: View) { - var popupTitle: TextView = itemView.findViewById(R.id.popupTitle) - } +package com.casic.app.smartwell.widgets + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.* +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.WellTypeModel +import com.pengxh.app.multilib.utils.SizeUtil + +/** + * @description: 顶部下拉菜单 + * @author: Pengxh + * @email: 290677893@qq.com + * @date: 2019/12/28 20:35 + */ +class EasyPopupWindow(private val ctx: Context) : PopupWindow(ctx) { + + private var mClickListener: OnPopupWindowClickListener? = null + private var items: List = ArrayList() + + init { + width = (SizeUtil.getScreenWidth(ctx) * 0.25).toInt() + height = ViewGroup.LayoutParams.WRAP_CONTENT + isOutsideTouchable = false + isFocusable = false + animationStyle = R.style.PopupAnimation + contentView = LayoutInflater.from(ctx).inflate(R.layout.popup_well_type, null, false) + } + + fun setupPopupData(itemList: List) { + this.items = itemList + val popupListView = contentView.findViewById(R.id.popupListView) + setupListView(popupListView) + } + + //给PopupWindow列表绑定数据 + private fun setupListView(popupListView: ListView) { + val adapter = PopupAdapter() + popupListView.adapter = adapter + popupListView.onItemClickListener = + AdapterView.OnItemClickListener { _, _, i, _ -> + if (mClickListener != null) { + mClickListener!!.onPopupClick(i) + } + dismiss() + } + } + + interface OnPopupWindowClickListener { + fun onPopupClick(position: Int) + } + + fun setOnPopupWindowClickListener(windowClickListener: OnPopupWindowClickListener?) { + mClickListener = windowClickListener + } + + inner class PopupAdapter : BaseAdapter() { + + private val inflater: LayoutInflater = LayoutInflater.from(ctx) + + override fun getCount(): Int = items.size + + override fun getItem(position: Int): Any = items[position] + + override fun getItemId(position: Int): Long = position.toLong() + + override fun getView(position: Int, convertView: View?, parent: ViewGroup): View { + val view: View + val holder: ItemViewHolder + if (convertView == null) { + view = inflater.inflate(R.layout.item_popup, null) + holder = ItemViewHolder(view) + view.tag = holder + } else { + view = convertView + holder = view.tag as ItemViewHolder + } + holder.popupTitle.text = items[position].name + return view + } + } + + class ItemViewHolder(itemView: View) { + var popupTitle: TextView = itemView.findViewById(R.id.popupTitle) + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellManagementActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellManagementActivity.kt index 6635978..6b22a8a 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/WellManagementActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/WellManagementActivity.kt @@ -50,24 +50,18 @@ }) } - private var clickTag = 0 - override fun initEvent() { wellTypeLayout.setOnClickListener { //旋转arrowImageView val rotateAnimation = arrowImageView.animate() rotateAnimation.duration = 200 rotateAnimation.interpolator = LinearInterpolator() - if (clickTag % 2 == 0) { - rotateAnimation.rotation(180f) - } else { - rotateAnimation.rotation(0f) - } - clickTag++ + rotateAnimation.rotation(180f) easyPopupWindow.showAsDropDown(wellTypeLayout) easyPopupWindow.setOnPopupWindowClickListener(object : EasyPopupWindow.OnPopupWindowClickListener { override fun onPopupClick(position: Int) { + rotateAnimation.rotation(0f) wellTypeView.text = items[position].name } }) diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/EasyPopupWindow.kt b/app/src/main/java/com/casic/app/smartwell/widgets/EasyPopupWindow.kt index 061b0a7..7774066 100644 --- a/app/src/main/java/com/casic/app/smartwell/widgets/EasyPopupWindow.kt +++ b/app/src/main/java/com/casic/app/smartwell/widgets/EasyPopupWindow.kt @@ -1,88 +1,88 @@ -package com.casic.app.smartwell.widgets - -import android.content.Context -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import android.widget.* -import com.casic.app.smartwell.R -import com.casic.app.smartwell.model.WellTypeModel -import com.pengxh.app.multilib.utils.SizeUtil - -/** - * @description: 顶部下拉菜单 - * @author: Pengxh - * @email: 290677893@qq.com - * @date: 2019/12/28 20:35 - */ -class EasyPopupWindow(private val ctx: Context) : PopupWindow(ctx) { - - private var mClickListener: OnPopupWindowClickListener? = null - private var items: List = ArrayList() - - init { - width = (SizeUtil.getScreenWidth(ctx) * 0.25).toInt() - height = ViewGroup.LayoutParams.WRAP_CONTENT - isOutsideTouchable = true - isFocusable = true - animationStyle = R.style.PopupAnimation - contentView = LayoutInflater.from(ctx).inflate(R.layout.popup_well_type, null, false) - } - - fun setupPopupData(itemList: List) { - this.items = itemList - val popupListView = contentView.findViewById(R.id.popupListView) - setupListView(popupListView) - } - - //给PopupWindow列表绑定数据 - private fun setupListView(popupListView: ListView) { - val adapter = PopupAdapter() - popupListView.adapter = adapter - popupListView.onItemClickListener = - AdapterView.OnItemClickListener { _, _, i, _ -> - if (mClickListener != null) { - mClickListener!!.onPopupClick(i) - } - dismiss() - } - } - - interface OnPopupWindowClickListener { - fun onPopupClick(position: Int) - } - - fun setOnPopupWindowClickListener(windowClickListener: OnPopupWindowClickListener?) { - mClickListener = windowClickListener - } - - inner class PopupAdapter : BaseAdapter() { - - private val inflater: LayoutInflater = LayoutInflater.from(ctx) - - override fun getCount(): Int = items.size - - override fun getItem(position: Int): Any = items[position] - - override fun getItemId(position: Int): Long = position.toLong() - - override fun getView(position: Int, convertView: View?, parent: ViewGroup): View { - val view: View - val holder: ItemViewHolder - if (convertView == null) { - view = inflater.inflate(R.layout.item_popup, null) - holder = ItemViewHolder(view) - view.tag = holder - } else { - view = convertView - holder = view.tag as ItemViewHolder - } - holder.popupTitle.text = items[position].name - return view - } - } - - class ItemViewHolder(itemView: View) { - var popupTitle: TextView = itemView.findViewById(R.id.popupTitle) - } +package com.casic.app.smartwell.widgets + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.* +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.WellTypeModel +import com.pengxh.app.multilib.utils.SizeUtil + +/** + * @description: 顶部下拉菜单 + * @author: Pengxh + * @email: 290677893@qq.com + * @date: 2019/12/28 20:35 + */ +class EasyPopupWindow(private val ctx: Context) : PopupWindow(ctx) { + + private var mClickListener: OnPopupWindowClickListener? = null + private var items: List = ArrayList() + + init { + width = (SizeUtil.getScreenWidth(ctx) * 0.25).toInt() + height = ViewGroup.LayoutParams.WRAP_CONTENT + isOutsideTouchable = false + isFocusable = false + animationStyle = R.style.PopupAnimation + contentView = LayoutInflater.from(ctx).inflate(R.layout.popup_well_type, null, false) + } + + fun setupPopupData(itemList: List) { + this.items = itemList + val popupListView = contentView.findViewById(R.id.popupListView) + setupListView(popupListView) + } + + //给PopupWindow列表绑定数据 + private fun setupListView(popupListView: ListView) { + val adapter = PopupAdapter() + popupListView.adapter = adapter + popupListView.onItemClickListener = + AdapterView.OnItemClickListener { _, _, i, _ -> + if (mClickListener != null) { + mClickListener!!.onPopupClick(i) + } + dismiss() + } + } + + interface OnPopupWindowClickListener { + fun onPopupClick(position: Int) + } + + fun setOnPopupWindowClickListener(windowClickListener: OnPopupWindowClickListener?) { + mClickListener = windowClickListener + } + + inner class PopupAdapter : BaseAdapter() { + + private val inflater: LayoutInflater = LayoutInflater.from(ctx) + + override fun getCount(): Int = items.size + + override fun getItem(position: Int): Any = items[position] + + override fun getItemId(position: Int): Long = position.toLong() + + override fun getView(position: Int, convertView: View?, parent: ViewGroup): View { + val view: View + val holder: ItemViewHolder + if (convertView == null) { + view = inflater.inflate(R.layout.item_popup, null) + holder = ItemViewHolder(view) + view.tag = holder + } else { + view = convertView + holder = view.tag as ItemViewHolder + } + holder.popupTitle.text = items[position].name + return view + } + } + + class ItemViewHolder(itemView: View) { + var popupTitle: TextView = itemView.findViewById(R.id.popupTitle) + } } \ No newline at end of file diff --git a/app/src/main/res/anim/popup_show.xml b/app/src/main/res/anim/popup_show.xml index c43c396..1d281ef 100644 --- a/app/src/main/res/anim/popup_show.xml +++ b/app/src/main/res/anim/popup_show.xml @@ -1,12 +1,12 @@ - - - + + + \ No newline at end of file