ShaiXuanPop.java
4.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
package com.shunzhi.parent.popu;
import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.PopupWindow;
import android.widget.TextView;
import com.huxq17.handygridview.HandyGridView;
import com.share.mvpsdk.utils.DisplayUtils;
import com.shunzhi.parent.R;
import com.shunzhi.parent.popu.handygrid.TagView;
import java.util.ArrayList;
import java.util.List;
/**
* Created by ToaHanDong on 2018/3/15.
*/
public class ShaiXuanPop extends PopupWindow {
HandyGridView handyGridView = null;
List<String> stringList = null;
private Context mContext = null;
MyGridAdapter myGridAdapter = null;
TextView tvSubmit;
public ShaiXuanPop(Context context) {
mContext = context;
View view = View.inflate(context, R.layout.popu_shaixuan, null);
handyGridView = view.findViewById(R.id.handyGridView);
tvSubmit=view.findViewById(R.id.tvSubmit);
stringList = new ArrayList<>();
setWidth(WindowManager.LayoutParams.MATCH_PARENT);
setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
setOutsideTouchable(true);
setFocusable(true);
setBackgroundDrawable(new BitmapDrawable());
setContentView(view);
update();
tvSubmit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dismiss();
}
});
}
public void show(View parent) {
showAsDropDown(parent);
}
public void setDatas(List<String> strings) {
if (null != stringList) {
stringList.clear();
stringList.addAll(strings);
}
if (null == myGridAdapter) myGridAdapter = new MyGridAdapter();
if (null == handyGridView.getAdapter()) handyGridView.setAdapter(myGridAdapter);
myGridAdapter.notifyDataSetChanged();
}
private class MyGridAdapter extends BaseAdapter {
private GridView mGridView;
private boolean inEditMode = false;//设置是否可以编辑
public void setInEditMode(boolean inEditMode) {
this.inEditMode = inEditMode;
notifyDataSetChanged();
}
@Override
public int getCount() {
return stringList.size();
}
@Override
public Object getItem(int i) {
return stringList.get(i);
}
@Override
public long getItemId(int i) {
return i;
}
@Override
public View getView(int i, View convertView, ViewGroup viewGroup) {
if (mGridView == null) {
mGridView = (GridView) viewGroup;
}
TagView textView;
if (convertView == null) {
textView = new TagView(mContext);
convertView = textView;
textView.setMaxLines(1);
textView.setHeight(DisplayUtils.dp2px(30));
int id = mContext.getResources().getIdentifier("s_grid_item", "drawable", mContext.getPackageName());
Drawable drawable = mContext.getResources().getDrawable(id);
textView.setBackgroundDrawable(drawable);
textView.setTextColor(mContext.getResources().getColor(R.color.huodong_blue));
textView.setGravity(Gravity.CENTER);
textView.setTag(false);
} else {
textView = (TagView) convertView;
}
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
boolean isSelect = (boolean) view.getTag();
view.setTag(!isSelect);
notifyDataSetChanged();
}
});
boolean isSelect = (boolean) textView.getTag();
if (isSelect) {
textView.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.shape_blue_select));
textView.setTextColor(mContext.getResources().getColor(R.color.white));
} else {
textView.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.shape_blue_normal));
textView.setTextColor(mContext.getResources().getColor(R.color.huodong_blue));
}
textView.showDeleteIcon(false);
textView.setText(getItem(i).toString());
return convertView;
}
}
}