Commit afd7573ccdd09b599dbb134916c4900459a9b97d
1 parent
c14df5e9
1 修复pop控件item点击没有反应的问题
Showing
5 changed files
with
85 additions
and
43 deletions
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/frame/view/AllDeviceFragmentView.java
| 1 | package com.cnlive.strike.xiaojiaspeaker.frame.view; | 1 | package com.cnlive.strike.xiaojiaspeaker.frame.view; |
| 2 | 2 | ||
| 3 | import android.app.Activity; | 3 | import android.app.Activity; |
| 4 | +import android.graphics.Color; | ||
| 4 | import android.support.v7.widget.LinearLayoutManager; | 5 | import android.support.v7.widget.LinearLayoutManager; |
| 6 | +import android.util.Log; | ||
| 7 | +import android.view.View; | ||
| 5 | 8 | ||
| 9 | +import com.cnlive.strike.xiaojiaspeaker.R; | ||
| 6 | import com.cnlive.strike.xiaojiaspeaker.model.AllDeviceInfo; | 10 | import com.cnlive.strike.xiaojiaspeaker.model.AllDeviceInfo; |
| 7 | import com.cnlive.strike.xiaojiaspeaker.ui.activity.BlueToothStep1Activity; | 11 | import com.cnlive.strike.xiaojiaspeaker.ui.activity.BlueToothStep1Activity; |
| 12 | +import com.cnlive.strike.xiaojiaspeaker.ui.activity.DeviceManagerActivity; | ||
| 8 | import com.cnlive.strike.xiaojiaspeaker.ui.adapter.AllDeviceAdapter; | 13 | import com.cnlive.strike.xiaojiaspeaker.ui.adapter.AllDeviceAdapter; |
| 9 | import com.cnlive.strike.xiaojiaspeaker.ui.fragment.AllDeviceFragment; | 14 | import com.cnlive.strike.xiaojiaspeaker.ui.fragment.AllDeviceFragment; |
| 15 | +import com.cnlive.strike.xiaojiaspeaker.ui.widget.popmenu.PopMenu; | ||
| 16 | +import com.cnlive.strike.xiaojiaspeaker.ui.widget.popmenu.PopMenuInfo; | ||
| 10 | import com.hannesdorfmann.mosby3.mvp.MvpView; | 17 | import com.hannesdorfmann.mosby3.mvp.MvpView; |
| 18 | +import com.qmuiteam.qmui.alpha.QMUIAlphaImageButton; | ||
| 11 | 19 | ||
| 12 | import java.util.ArrayList; | 20 | import java.util.ArrayList; |
| 13 | import java.util.List; | 21 | import java.util.List; |
| @@ -16,6 +24,9 @@ public class AllDeviceFragmentView implements MvpView { | @@ -16,6 +24,9 @@ public class AllDeviceFragmentView implements MvpView { | ||
| 16 | private AllDeviceFragment fragment; | 24 | private AllDeviceFragment fragment; |
| 17 | private AllDeviceAdapter adapter; | 25 | private AllDeviceAdapter adapter; |
| 18 | private List<AllDeviceInfo> allDeviceInfoList; | 26 | private List<AllDeviceInfo> allDeviceInfoList; |
| 27 | + private List<PopMenuInfo> popMenuInfoList = null; | ||
| 28 | + private PopMenu mPopMenu; | ||
| 29 | + private String TAG = "AllDeviceFragmentView"; | ||
| 19 | 30 | ||
| 20 | public AllDeviceFragmentView(AllDeviceFragment fragment) { | 31 | public AllDeviceFragmentView(AllDeviceFragment fragment) { |
| 21 | this.fragment = fragment; | 32 | this.fragment = fragment; |
| @@ -26,6 +37,7 @@ public class AllDeviceFragmentView implements MvpView { | @@ -26,6 +37,7 @@ public class AllDeviceFragmentView implements MvpView { | ||
| 26 | } | 37 | } |
| 27 | 38 | ||
| 28 | public void initView() { | 39 | public void initView() { |
| 40 | + initPopView(); | ||
| 29 | AllDeviceInfo allDeviceInfo = new AllDeviceInfo(); | 41 | AllDeviceInfo allDeviceInfo = new AllDeviceInfo(); |
| 30 | allDeviceInfoList = new ArrayList<>(); | 42 | allDeviceInfoList = new ArrayList<>(); |
| 31 | allDeviceInfoList.add(allDeviceInfo); | 43 | allDeviceInfoList.add(allDeviceInfo); |
| @@ -38,5 +50,58 @@ public class AllDeviceFragmentView implements MvpView { | @@ -38,5 +50,58 @@ public class AllDeviceFragmentView implements MvpView { | ||
| 38 | BlueToothStep1Activity.startActivity(fragment.getActivity()); | 50 | BlueToothStep1Activity.startActivity(fragment.getActivity()); |
| 39 | } | 51 | } |
| 40 | }); | 52 | }); |
| 53 | + adapter.setOnItemClickListener(new AllDeviceAdapter.OnItemClickListener() { | ||
| 54 | + @Override | ||
| 55 | + public void onItemClick(int position, AllDeviceInfo AllDeviceInfo) { | ||
| 56 | + DeviceManagerActivity.startActivity(fragment.getActivity()); | ||
| 57 | + } | ||
| 58 | + }); | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + public void initPopView() { | ||
| 62 | + popMenuInfoList = new ArrayList<>(); | ||
| 63 | + PopMenuInfo popMenuInfo = new PopMenuInfo(); | ||
| 64 | + popMenuInfo.setTitle("使用者管理"); | ||
| 65 | + popMenuInfo.setNetImag("zsdfs"); | ||
| 66 | + popMenuInfoList.add(popMenuInfo); | ||
| 67 | + popMenuInfo = new PopMenuInfo(); | ||
| 68 | + popMenuInfo.setTitle("添加设备"); | ||
| 69 | + popMenuInfo.setNetImag("zsdfs"); | ||
| 70 | + popMenuInfoList.add(popMenuInfo); | ||
| 71 | +// popMenuInfo = new PopMenuInfo(); | ||
| 72 | +// popMenuInfo.setTitle("设备管理"); | ||
| 73 | +//// popMenuInfo.setNetImag("zsdfs"); | ||
| 74 | +// popMenuInfoList.add(popMenuInfo); | ||
| 75 | + | ||
| 76 | + if (null == mPopMenu) { | ||
| 77 | + mPopMenu = new PopMenu.Builder(fragment.getActivity()) | ||
| 78 | + .addData(popMenuInfoList) | ||
| 79 | + .setBackgroundColorArray(new int[]{Color.parseColor("#363636"), Color.parseColor("#BF000000"), Color.parseColor("#BF000000")}) | ||
| 80 | + .setLeftAndRightMargin(20) | ||
| 81 | + .setTopMargin(20) | ||
| 82 | + .setLineColor(R.color.white_50) | ||
| 83 | + .setTextColor(R.color.white) | ||
| 84 | + .setLineVisible(View.VISIBLE) | ||
| 85 | +// .setArrowHeight(30f) | ||
| 86 | +// .setArrowHeight(30f) | ||
| 87 | + //.setCancelable(false) | ||
| 88 | + .setCornerRadius(10f) | ||
| 89 | + .build(); | ||
| 90 | + } | ||
| 91 | + | ||
| 92 | + mPopMenu.setmItemClickListener(new PopMenu.OnItemClickListener() { | ||
| 93 | + @Override | ||
| 94 | + public void onClick(int position, PopMenuInfo popMenuInfo) { | ||
| 95 | + if (position == 1) { | ||
| 96 | + BlueToothStep1Activity.startActivity(fragment.getActivity()); | ||
| 97 | + } | ||
| 98 | + } | ||
| 99 | + }); | ||
| 100 | + } | ||
| 101 | + | ||
| 102 | + public void showPop(View view) { | ||
| 103 | + if (null != getContext() && null != mPopMenu) { | ||
| 104 | + mPopMenu.show(view); | ||
| 105 | + } | ||
| 41 | } | 106 | } |
| 42 | } | 107 | } |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/ui/activity/DeviceManagerActivity.java
| 1 | package com.cnlive.strike.xiaojiaspeaker.ui.activity; | 1 | package com.cnlive.strike.xiaojiaspeaker.ui.activity; |
| 2 | 2 | ||
| 3 | +import android.app.Activity; | ||
| 4 | +import android.content.Intent; | ||
| 3 | import android.databinding.DataBindingUtil; | 5 | import android.databinding.DataBindingUtil; |
| 4 | import android.support.v7.app.AppCompatActivity; | 6 | import android.support.v7.app.AppCompatActivity; |
| 5 | import android.os.Bundle; | 7 | import android.os.Bundle; |
| @@ -23,4 +25,8 @@ public class DeviceManagerActivity extends AppCompatActivity { | @@ -23,4 +25,8 @@ public class DeviceManagerActivity extends AppCompatActivity { | ||
| 23 | getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, DeviceManagerFragment.newInstance()).commitAllowingStateLoss(); | 25 | getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, DeviceManagerFragment.newInstance()).commitAllowingStateLoss(); |
| 24 | 26 | ||
| 25 | } | 27 | } |
| 28 | + | ||
| 29 | + public static void startActivity(Activity activity) { | ||
| 30 | + activity.startActivity(new Intent(activity, DeviceManagerActivity.class)); | ||
| 31 | + } | ||
| 26 | } | 32 | } |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/ui/fragment/AllDeviceFragment.java
| @@ -23,6 +23,8 @@ import java.util.List; | @@ -23,6 +23,8 @@ import java.util.List; | ||
| 23 | 23 | ||
| 24 | public class AllDeviceFragment extends MvpBindingFragment<AllDeviceFragmentView, AllDeviceFragmentPresenter, Object, FragmentAllDeviceBinding> { | 24 | public class AllDeviceFragment extends MvpBindingFragment<AllDeviceFragmentView, AllDeviceFragmentPresenter, Object, FragmentAllDeviceBinding> { |
| 25 | private UIPopup qmuiPopup; | 25 | private UIPopup qmuiPopup; |
| 26 | + private QMUIAlphaImageButton addButton; | ||
| 27 | + ; | ||
| 26 | 28 | ||
| 27 | public static AllDeviceFragment newInstance() { | 29 | public static AllDeviceFragment newInstance() { |
| 28 | AllDeviceFragment fragment = new AllDeviceFragment(); | 30 | AllDeviceFragment fragment = new AllDeviceFragment(); |
| @@ -39,8 +41,6 @@ public class AllDeviceFragment extends MvpBindingFragment<AllDeviceFragmentView, | @@ -39,8 +41,6 @@ public class AllDeviceFragment extends MvpBindingFragment<AllDeviceFragmentView, | ||
| 39 | super.onActivityCreated(savedInstanceState); | 41 | super.onActivityCreated(savedInstanceState); |
| 40 | } | 42 | } |
| 41 | 43 | ||
| 42 | - QMUIAlphaImageButton button; | ||
| 43 | - QMUIAlphaImageButton button1; | ||
| 44 | 44 | ||
| 45 | @Override | 45 | @Override |
| 46 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { | 46 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { |
| @@ -57,52 +57,23 @@ public class AllDeviceFragment extends MvpBindingFragment<AllDeviceFragmentView, | @@ -57,52 +57,23 @@ public class AllDeviceFragment extends MvpBindingFragment<AllDeviceFragmentView, | ||
| 57 | if (null != binding) { | 57 | if (null != binding) { |
| 58 | binding.topbar.setTitle("所有设备"); | 58 | binding.topbar.setTitle("所有设备"); |
| 59 | //设置返回按钮 | 59 | //设置返回按钮 |
| 60 | - button1 = binding.topbar.addLeftImageButton(R.drawable.icon_back, R.id.left_back); | ||
| 61 | - button1.setOnClickListener(new View.OnClickListener() { | 60 | + binding.topbar.addLeftImageButton(R.drawable.icon_back, R.id.left_back).setOnClickListener(new View.OnClickListener() { |
| 62 | @Override | 61 | @Override |
| 63 | public void onClick(View view) { | 62 | public void onClick(View view) { |
| 64 | } | 63 | } |
| 65 | }); | 64 | }); |
| 66 | //添加设备按钮 | 65 | //添加设备按钮 |
| 67 | - button = binding.topbar.addRightImageButton(R.drawable.icon_item_add, R.id.right_add); | ||
| 68 | - button.setOnClickListener(new View.OnClickListener() { | 66 | + addButton = binding.topbar.addRightImageButton(R.drawable.icon_item_add, R.id.right_add); |
| 67 | + addButton.setOnClickListener(new View.OnClickListener() { | ||
| 69 | @Override | 68 | @Override |
| 70 | public void onClick(View view) { | 69 | public void onClick(View view) { |
| 71 | -// BlueToothStep1Activity.startActivity(getActivity()); | ||
| 72 | - AddClick(); | 70 | + if (null!=getMvpView()){ |
| 71 | + getMvpView().showPop(addButton); | ||
| 72 | + } | ||
| 73 | } | 73 | } |
| 74 | }); | 74 | }); |
| 75 | + | ||
| 75 | } | 76 | } |
| 76 | } | 77 | } |
| 77 | 78 | ||
| 78 | - private void AddClick() { | ||
| 79 | - List<PopMenuInfo> popMenuInfoList = new ArrayList<>(); | ||
| 80 | - PopMenuInfo popMenuInfo = new PopMenuInfo(); | ||
| 81 | - popMenuInfo.setTitle("下载中"); | ||
| 82 | -// popMenuInfo.setNetImag("zsdfs"); | ||
| 83 | - popMenuInfoList.add(popMenuInfo); | ||
| 84 | - popMenuInfo = new PopMenuInfo(); | ||
| 85 | - popMenuInfo.setTitle("历史记录"); | ||
| 86 | -// popMenuInfo.setNetImag("zsdfs"); | ||
| 87 | - popMenuInfoList.add(popMenuInfo); | ||
| 88 | - popMenuInfo = new PopMenuInfo(); | ||
| 89 | - popMenuInfo.setTitle("设备管理"); | ||
| 90 | -// popMenuInfo.setNetImag("zsdfs"); | ||
| 91 | - popMenuInfoList.add(popMenuInfo); | ||
| 92 | - | ||
| 93 | - PopMenu mPopMenu = new PopMenu.Builder(getActivity()) | ||
| 94 | - .addData(popMenuInfoList) | ||
| 95 | - .setBackgroundColorArray(new int[]{Color.parseColor("#363636"), Color.parseColor("#BF000000"), Color.parseColor("#BF000000")}) | ||
| 96 | - .setLeftAndRightMargin(20) | ||
| 97 | - .setTopMargin(20) | ||
| 98 | - .setLineColor(R.color.white_50) | ||
| 99 | - .setTextColor(R.color.white) | ||
| 100 | - .setLineVisible(View.VISIBLE) | ||
| 101 | -// .setArrowHeight(30f) | ||
| 102 | -// .setArrowHeight(30f) | ||
| 103 | - //.setCancelable(false) | ||
| 104 | - .setCornerRadius(10f) | ||
| 105 | - .build(); | ||
| 106 | - mPopMenu.show(button); | ||
| 107 | - } | ||
| 108 | } | 79 | } |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/ui/widget/popmenu/PopMenu.java
| @@ -15,6 +15,7 @@ import android.support.annotation.NonNull; | @@ -15,6 +15,7 @@ import android.support.annotation.NonNull; | ||
| 15 | import android.support.v7.widget.LinearLayoutManager; | 15 | import android.support.v7.widget.LinearLayoutManager; |
| 16 | import android.support.v7.widget.RecyclerView; | 16 | import android.support.v7.widget.RecyclerView; |
| 17 | import android.util.DisplayMetrics; | 17 | import android.util.DisplayMetrics; |
| 18 | +import android.util.Log; | ||
| 18 | import android.view.Gravity; | 19 | import android.view.Gravity; |
| 19 | import android.view.View; | 20 | import android.view.View; |
| 20 | import android.view.ViewGroup; | 21 | import android.view.ViewGroup; |
| @@ -51,12 +52,11 @@ public final class PopMenu { | @@ -51,12 +52,11 @@ public final class PopMenu { | ||
| 51 | private int mBackgroundColor; | 52 | private int mBackgroundColor; |
| 52 | private RecyclerView mRecyclerView; | 53 | private RecyclerView mRecyclerView; |
| 53 | 54 | ||
| 54 | - private PopMenu.OnItemClickListener mItemClickListener; | 55 | + private OnItemClickListener mItemClickListener; |
| 55 | private PopMenuAdapter mAdapter; | 56 | private PopMenuAdapter mAdapter; |
| 56 | private List<PopMenuInfo> mData = new ArrayList<>(); | 57 | private List<PopMenuInfo> mData = new ArrayList<>(); |
| 57 | private String TAG = "PopMenu"; | 58 | private String TAG = "PopMenu"; |
| 58 | private Builder builder; | 59 | private Builder builder; |
| 59 | - private OnItemClickListener onItemClickListener; | ||
| 60 | 60 | ||
| 61 | public void setmItemClickListener(OnItemClickListener mItemClickListener) { | 61 | public void setmItemClickListener(OnItemClickListener mItemClickListener) { |
| 62 | this.mItemClickListener = mItemClickListener; | 62 | this.mItemClickListener = mItemClickListener; |
| @@ -130,8 +130,8 @@ public final class PopMenu { | @@ -130,8 +130,8 @@ public final class PopMenu { | ||
| 130 | mAdapter.setOnItemClickListener(new PopMenuAdapter.OnItemClickListener() { | 130 | mAdapter.setOnItemClickListener(new PopMenuAdapter.OnItemClickListener() { |
| 131 | @Override | 131 | @Override |
| 132 | public void onClick(int position, PopMenuInfo popMenuInfo) { | 132 | public void onClick(int position, PopMenuInfo popMenuInfo) { |
| 133 | - if (null != onItemClickListener) { | ||
| 134 | - onItemClickListener.onClick(position, popMenuInfo); | 133 | + if (null != mItemClickListener) { |
| 134 | + mItemClickListener.onClick(position, popMenuInfo); | ||
| 135 | } | 135 | } |
| 136 | dismiss(); | 136 | dismiss(); |
| 137 | } | 137 | } |
module_xiaojiaSoundBox/src/main/res/layout/pop_item_menu.xml
| @@ -3,7 +3,7 @@ | @@ -3,7 +3,7 @@ | ||
| 3 | 3 | ||
| 4 | <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | 4 | <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
| 5 | android:id="@+id/ll_root" | 5 | android:id="@+id/ll_root" |
| 6 | - android:layout_width="wrap_content" | 6 | + android:layout_width="match_parent" |
| 7 | android:layout_height="wrap_content" | 7 | android:layout_height="wrap_content" |
| 8 | android:background="@drawable/selectable_pop_item_background" | 8 | android:background="@drawable/selectable_pop_item_background" |
| 9 | android:clickable="true" | 9 | android:clickable="true" |