package com.luxji.auction.app;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Matrix;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.PaintDrawable;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.DisplayMetrics;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.HorizontalScrollView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.RadioButton;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.google.gson.Gson;
import com.luxji.auction.R;
import com.luxji.auction.adapter.GoodsListAdapter;
import com.luxji.auction.base.BaseActivity;
import com.luxji.auction.base.BaseApplication;
import com.luxji.auction.model.GoodsInfo;
import com.luxji.auction.model.GoodsSearchResult;
import com.luxji.auction.model.MaintenanceResult;
import com.luxji.auction.util.Constant;
import com.luxji.auction.util.SharedPreferencesUtil;
import com.luxji.auction.widget.LoadFailView;
import com.luxji.auction.widget.MyListView;
import com.luxji.auction.widget.NetWorkView;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
/**
* Created by Clare on 2016/6/28.
* Emali [email protected]
*/
public class GoodsSearchActivity extends BaseActivity {
public static String CATID = "id";
public static String CATNAME = "cat_name";
//筛选条件菜单
// private SlidingMenu mSlidingMenu;
//搜索按钮
private TextView searchTextView;
//返回按钮
private LinearLayout backLayout;
//搜索文本框
private EditText searchEditText;
private ImageView deleteImageview;
//品牌
private TextView brandTextView;
private ListView brandListView;
private ListView serialListView;
private int screenHeight=0;
private int screenWidth=0;
private LinkedList brands;
private LinkedList serials;
private ArrayAdapter brandAdapter;
private ArrayAdapter serialAdapter;
// private SupperLayout brandSupperLayout;
// private SupperLayout serialSupperLayout;
private View.OnClickListener mOnClickListener;
private View.OnClickListener mSerialOnClickListener;
private View.OnClickListener mFilterCityOnClickListener;
private View.OnClickListener mFilterSexOnClickListener;
private View.OnClickListener mFilterPriceOnClickListener;
// private SupperLayout mCitySupperLayout;
private FlowRadioGroup mSexRadioGroup;
private FlowRadioGroup mPriceRadioGroup;
// private SupperLayout mSexSupperLayout;
// private SupperLayout mPriceSupperLayout;
//价格
private LinearLayout priceLayout;
private Boolean isUp = false;
//帅选
private TextView filterTextView;
//商品列表adapter
private GoodsListAdapter goodsListAdapter;
//商品数据list
private LinkedList goodsInfos;
//商品列表控件listview
private ListView goodsListView;
private int skip = 0;
//每次刷新时把最后一行或最上面一行的商品编号传递过去
private String goodsId;
private LayoutInflater inflater;
private View footView;
private LinearLayout loading;
private TextView moreTextView;
//保存筛选条件
private LinkedList selectedList;
private LinkedList selectedSexList;
private LinkedList selectedPriceList;
private LinkedList tempSelectedList = new LinkedList();
private LinkedList tempSelectedSexList = new LinkedList();
private LinkedList tempSelectedPriceList = new LinkedList();
private Drawable checkedDrawable;
private TextView sureTextview;
private TextView cancelTextview;
//查询条件
private String condition = "" ;
//分类id
private String mCatId = "";
private String mCatName = "";
//价格排序
private String mPriceSort = "up" ;
//查询关键字
private String mKeywords = "" ;
//男女或中性
private String mCrowd = "" ;
//价格区间
private String mPrice = "" ;
//地区
private String mArea = "";
//弹出窗口
private PopupWindow popupWindow;
//热词
private HorizontalScrollView horizontalScrollView;
private ArrayList hotWordList;
//搜索历史列表
private ListView hisListview;
//历史数据列表
private ArrayList hisList;
//
private LinearLayout conditionLayout;
private String his;
//搜索历史页
private ScrollView searchHisScrollView;
//热词点击事件
private View.OnClickListener hotWordOnClickListener;
//清除历史按钮
private TextView clearTextView;
//历史查询记录adapter
private ArrayAdapter mArrayAdapter;
// //性别数组
// private String[] sexArr = {"女性√","男性√","中性√"};
// //价格数组
// private String[] priceArr = {"0-5000√","5001-10000√",
// "10001-20000√","20001-30000√","30000以上√"};
// //城市
// private String[] cityArr = {"北京√","香港√","上海√","成都√","西安√"};
//popupwindow
private View filterContentView;
private View brandContentView;
private MyListView hotWordListView;
private ArrayAdapter hotwordAdapter;
private ImageView priceImageview;
private Matrix matrix;
private Bitmap bitmap;
// private NetWorkView noNetworkView;
// private LoadFailView loadFailView;
// private NoDataView noDataView;
private View noDataView;// 无数据时状态
private NetWorkView noNetworkView;// 无网络时状态
private View view;
private TextView saveBrandTextView;
//新
String externalKeyword;//外部传过来的关键字
int page=1;//分页第几页
int pagesize=10;//每页个数
private LinkedList mDataInfo = new LinkedList<>();; //商品数据list
private RecyclerView recyclerView;
private MaintenanceAdatper adapter;
public static void oepn(Context context,String value){
Intent intent=new Intent(context,GoodsSearchActivity.class);
intent.putExtra("externalKeyword",value);
context.startActivity(intent);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_search);
noNetworkView();
loadFailView();
//控件初始化
initWidget();
initSearchHis();
initScreenWidth();
doInitLoad();
GoodsItemClick();
intBundle();
// initFilterPopupWindow();
// initBrandPopupwindow();
}
private void intBundle(){
//得到外部传进来的搜索关键字
Bundle bunlde = getIntent().getExtras();
if(bunlde != null){
externalKeyword = bunlde.getString("externalKeyword");
if(!TextUtils.isEmpty(externalKeyword)){
if (searchEditText!=null){
searchEditText.setText(externalKeyword);
}
search(getText());
}
}
}
//初始化控件并且设置控件事件
private void initWidget(){
// checkedDrawable = getResources().getDrawable(R.drawable.check_box_true);
searchTextView = (TextView)this.findViewById(R.id.search_textview);
deleteImageview = (ImageView)this.findViewById(R.id.my_delete);
backLayout = (LinearLayout)this.findViewById(R.id.title_back_layout);
searchEditText = (EditText)this.findViewById(R.id.search_myedittext);
//加载提示控件初始化
inflater = LayoutInflater.from(this);
footView = inflater.inflate(R.layout.layout_loading_footer, null);
loading = (LinearLayout) footView.findViewById(R.id.loading_layout);
moreTextView = (TextView) footView.findViewById(R.id.more_texview);
moreTextView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
autoRefresh();
}
});
loading.setVisibility(View.GONE);
moreTextView.setVisibility(View.GONE);
goodsListView = (ListView)this.findViewById(R.id.goods_listview);
goodsListView.addFooterView(footView);
goodsInfos = new LinkedList();
goodsListAdapter = new GoodsListAdapter(this,goodsInfos,R.color.common_ff0000);
goodsListView.setAdapter(goodsListAdapter);
//设置监听,如果滑动到最后一行则进行数据加载
goodsListView.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView absListView, int i) {
if (i == AbsListView.OnScrollListener.SCROLL_STATE_IDLE) {
if (absListView.getLastVisiblePosition() == absListView.getCount() - 1) {
autoRefresh();
}
}
}
@Override
public void onScroll(AbsListView absListView, int i, int i2, int i3) {
}
});
popupWindow = new PopupWindow(GoodsSearchActivity.this);
//搜索历史页显示
searchHisScrollView = (ScrollView)this.findViewById(R.id.search_his_popupwindow);
//遮罩层
view = (View)this.findViewById(R.id.shade_view);
// //检索按钮
// searchTextView.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View view) {
// search(getText());
// mArrayAdapter.notifyDataSetChanged();
// }
// });
//删除键监听,点击删除输入框内容
deleteImageview.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
searchEditText.setText("");
deleteImageview.setVisibility(View.GONE);
}
});
//输入框内容监听,内容为空,隐藏删除键;反之,显示删除键
searchEditText.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void afterTextChanged(Editable s) {
if (s != null && !"".equals(s.toString().trim())) {
deleteImageview.setVisibility(View.VISIBLE);
searchHisScrollView.setVisibility(View.VISIBLE);
view.setVisibility(View.VISIBLE);
} else {
deleteImageview.setVisibility(View.GONE);
searchHisScrollView.setVisibility(View.GONE);
view.setVisibility(View.GONE);
}
}
});
//搜索
searchEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
if (i == EditorInfo.IME_ACTION_SEARCH) {
search(getText());
mArrayAdapter.notifyDataSetChanged();
}
return false;
}
});
//返回按钮
backLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
finish();
}
});
// //品牌选项
// brandTextView.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View view) {
// brandTextView.setTextColor(getResources().getColor(R.color.common_ff0000));
// showBrandPopupWindow(brandTextView);
// }
// });
// //价格选项
// matrix = new Matrix();
// bitmap = ((BitmapDrawable) getResources().getDrawable(R.drawable.default_1)).getBitmap();
// priceLayout.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View view) {
// if(isUp){
// mPriceSort = "down";
// isUp = false;
// rotateImg(180);
// }else{
// mPriceSort = "up";
// isUp = true;
// rotateImg(180);
// }
// skip = 0;
// doInitLoad();
// }
// });
//过滤选项
// filterTextView.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View view) {
// //改变字颜色
// filterTextView.setTextColor(getResources().getColor(R.color.common_ff0000));
// showFilterPopupWindow(filterTextView);
// }
// });
//清除
clearTextView = (TextView)this.findViewById(R.id.his_clear_textview);
clearTextView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//取得搜索历史数据
SharedPreferencesUtil.savePrivateInfoToSharedPreferences(GoodsSearchActivity.this, "searchwordhis","");
hisList.clear();
mArrayAdapter.notifyDataSetChanged();
}
});
}
//选装图片
private void rotateImg(int rotate){
// 设置旋转角度
matrix.setRotate(rotate);
// 重新绘制Bitmap
bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(),bitmap.getHeight(), matrix, true);
priceImageview.setImageBitmap(bitmap);
}
//搜索处理
private void search(String keyword){
his = SharedPreferencesUtil.getPrivateInfoFromSharedPreferences(this,"searchwordhis");
mKeywords = keyword;
//先转成数组然后再进行比较是否已经保存过,这样比较相对来说准确一些
if(TextUtils.isEmpty(his)){
if(!TextUtils.isEmpty(mKeywords)){
SharedPreferencesUtil.savePrivateInfoToSharedPreferences(GoodsSearchActivity.this, "searchwordhis", mKeywords);
hisList.add(mKeywords);
}
}else{
String[] array;
if(!hisList.contains(mKeywords)){
if(!TextUtils.isEmpty(mKeywords)){
String saveStr = "";
if(!TextUtils.isEmpty(his))
saveStr = mKeywords + "," + his;
else
saveStr = mKeywords;
SharedPreferencesUtil.savePrivateInfoToSharedPreferences(GoodsSearchActivity.this, "searchwordhis", saveStr);
//因为排序问题所以需要重新再加入list
array = saveStr.split(",");
hisList.clear();
hisList.addAll(Arrays.asList(array));
}
}
}
searchHisScrollView.setVisibility(View.GONE);
view.setVisibility(View.GONE);
//搜索
skip = 0;
doInitLoad();
}
//获得屏幕尺寸
private void initScreenWidth() {
DisplayMetrics dm = new DisplayMetrics();
dm = getResources().getDisplayMetrics();
screenHeight = dm.heightPixels;
screenWidth = dm.widthPixels;
}
//获取输入框内容
public String getText() {
if (searchEditText == null) {
return null;
}
String text = searchEditText.getText().toString();
return text;
// if (!TextUtils.isEmpty(text)){
// if (!"".equals(externalKeyword)&&null!=externalKeyword){
// return externalKeyword;
// }
// }
}
//显示搜索历史和热词搜索popupwindow
public void initSearchHis() {
//得到历史数据
his = SharedPreferencesUtil.getPrivateInfoFromSharedPreferences(this,"searchwordhis");
//搜索历史
hisListview = (ListView)this.findViewById(R.id.his_listview);
hisList = new ArrayList();
if (!TextUtils.isEmpty(his)){
String[] hisArray = his.split(",");
hisList.addAll(Arrays.asList(hisArray));
}
mArrayAdapter = new ArrayAdapter(this,R.layout.search_his_item,hisList);
hisListview.setAdapter(mArrayAdapter);
//热词横向滚动
/*horizontalScrollView = (HorizontalScrollView)this.findViewById(R.id.hotword_horizontalscrollview);
conditionLayout = (LinearLayout)this.findViewById(R.id.condition_layout);*/
/* hotWordOnClickListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
if (TextView.class.isInstance(view)) {
//得到品牌对应的系列数据
String keyword = ((TextView) view).getText().toString();
search(keyword);
mArrayAdapter.notifyDataSetChanged();
}
}
};*/
hisListview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView> adapterView, View view, int i, long l) {
if (TextView.class.isInstance(view)) {
//得到品牌对应的系列数据
String keyword = ((TextView) view).getText().toString();
search(keyword);
}
}
});
hotWordList = new ArrayList();
hotWordListView = (MyListView)this.findViewById(R.id.hotword_listview);
hotwordAdapter =
new ArrayAdapter(this,R.layout.search_his_item,hotWordList);
hotWordListView.setAdapter(hotwordAdapter);
hotWordListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView> adapterView, View view, int i, long l) {
if (TextView.class.isInstance(view)) {
//得到品牌对应的系列数据
String keyword = ((TextView) view).getText().toString();
search(keyword);
}
}
});
// doSearchHotWord();
}
// //查询热词
// private void doSearchHotWord() {
// //检索数据前首先检查网络是否可用
// if(!BaseApplication.getInstance().isNetworkAvailable(this)){
// Toast.makeText(this, getString(R.string.no_network_toast), Toast.LENGTH_SHORT).show();
// return;
// }
// getStatusTip().showProgress();
// StringRequest postRequest = new StringRequest(Request.Method.POST, Constant.hotWordUrl,
// new Response.Listener(){
// @Override
// public void onResponse(String response) {
// //处理返回结果
// parseWordJson(response);
// getStatusTip().hideProgress();
// }
// },
// new Response.ErrorListener() {
// @Override
// public void onErrorResponse(VolleyError error) {
// Toast.makeText(GoodsSearchActivity.this,getString(R.string.reload_txt), Toast.LENGTH_SHORT).show();
// getStatusTip().hideProgress();
// }
// });
// BaseApplication.mRequestQueue.add(postRequest);
// }
// //解析json数据
// private void parseWordJson(String json){
// Gson gson = new Gson();
// HotWordResult hotWordResult = gson.fromJson(json, HotWordResult.class);
// //有错误信息返回
// if(hotWordResult != null
// && "0".equals(hotWordResult.status.succeed)){
// Toast.makeText(GoodsSearchActivity.this,hotWordResult.status.error_desc, Toast.LENGTH_SHORT).show();
// return;
// }else{
// if(hotWordResult.data != null&& hotWordResult.data.size() > 0 ){
// hotWordList.addAll(hotWordResult.data);
// hotwordAdapter.notifyDataSetChanged();
// /* //成功返回品牌list
// int i = 0;
// for(String hotword:hotWordList){
// TextView tv = makeHotWordTextView(hotword,i, 16,3,
// hotWordOnClickListener);
// conditionLayout.addView(tv);
// i++;
// }*/
// }
// }
// }
//
// //显示品牌popupwindow
// public void showBrandPopupWindow(View anchor) {
// popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
// @Override
// public void onDismiss() {
// //改变字颜色
// brandTextView.setTextColor(getResources().getColor(R.color.common_666666));
// view.setVisibility(View.GONE);
// }
// });
// popupWindow.setWidth(screenWidth);
// popupWindow.setHeight(screenHeight*2/3);
// popupWindow.setContentView(brandContentView);
// popupWindow.setFocusable(true);
// popupWindow.setOutsideTouchable(true);
// popupWindow.setBackgroundDrawable(new PaintDrawable(getResources().getColor(R.color.homepage_bg)));
// popupWindow.showAsDropDown(anchor);
// view.setVisibility(View.VISIBLE);
// }
// private void initBrandPopupwindow(){
// brandContentView = LayoutInflater.from(GoodsSearchActivity.this).inflate(R.layout.brand_popupwindow, null);
// brandSupperLayout = (SupperLayout) brandContentView.findViewById(R.id.brand_superlayout);
// mOnClickListener = new View.OnClickListener() {
// @Override
// public void onClick(View v) {
// if (TextView.class.isInstance(v)) {
// //得到品牌对应的系列数据
// getSerial(((TextView) v).getId());
// if(saveBrandTextView != null) saveBrandTextView.setTextColor(getResources().getColor(R.color.item_light_gray));
// ((TextView) v).setTextColor(getResources().getColor(R.color.common_ff0000));
// saveBrandTextView = ((TextView) v);
// }
// }
// };
// //系列
// serialListView = (ListView)brandContentView.findViewById(R.id.serial_listview);
// mSerialList = new LinkedList();
// mSerialArrayAdapter = new SerialListAdapter(this,mSerialList);
// serialListView.setAdapter(mSerialArrayAdapter);
// serialListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
// @Override
// public void onItemClick(AdapterView> adapterView, View view, int i, long l) {
// mCatId = mSerialList.get(i).cat_id;
// //进行搜索
// skip = 0;
// doInitLoad();
// popupWindow.dismiss();
// }
// });
// /* mSerialOnClickListener = new View.OnClickListener() {
// @Override
// public void onClick(View v) {
// if (TextView.class.isInstance(v)) {
// mCatId = String.valueOf(((TextView)v).getId());
// //进行搜索
// skip = 0;
// doInitLoad();
// popupWindow.dismiss();
// }
// }
// };*/
// doSearchBrand();
// }
//显示筛选popupwindow
public void showFilterPopupWindow(View anchor) {
// mSexRadioGroup = (FlowRadioGroup)contentView.findViewById(R.id.sex_radiogroup);
// mPriceRadioGroup = (FlowRadioGroup)contentView.findViewById(R.id.price_radiogroup);
// mSexRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
// @Override
// public void onCheckedChanged(RadioGroup radioGroup, int i) {
// RadioButton rb = (RadioButton)radioGroup.getChildAt(i);
// mCrowd = rb.getText().toString();
// }
// });
// mPriceRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
// @Override
// public void onCheckedChanged(RadioGroup radioGroup, int i) {
// RadioButton rb = (RadioButton)radioGroup.getChildAt(i);
// mPrice = rb.getText().toString();
// }
// });
popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
@Override
public void onDismiss() {
//改变字颜色
// filterTextView.setTextColor(getResources().getColor(R.color.common_666666));//第一个报错的控件,原因是没有找到--------------------------------
view.setVisibility(View.GONE);
}
});
popupWindow.setWidth(screenWidth);
popupWindow.setHeight(screenHeight*2/3);
popupWindow.setContentView(filterContentView);
popupWindow.setFocusable(true);
popupWindow.setOutsideTouchable(true);
popupWindow.setBackgroundDrawable(new PaintDrawable(getResources().getColor(R.color.common_f5f5f5)));
popupWindow.showAsDropDown(anchor);
view.setVisibility(View.VISIBLE);
//保留状态
saveFilterState();
//getFilterState();
}
//初始化状态list
// private void initFilterPopupWindow(){
// selectedSexList = new LinkedList();
// selectedList = new LinkedList();
// selectedPriceList = new LinkedList();
// filterContentView = LayoutInflater.from(GoodsSearchActivity.this).inflate(
// R.layout.filter_popupwindow, null);
// mSexSupperLayout = (SupperLayout) filterContentView.findViewById(
// R.id.right_menu_sex_superlayout);
// mFilterSexOnClickListener = new View.OnClickListener() {
// @Override
// public void onClick(View v) {
// if (TextView.class.isInstance(v)) {
// if(selectedSexList.contains(v)){
// ((TextView) v).setTextColor(getResources().getColor(R.color.item_light_gray));
// selectedSexList.remove(v);
// }else {
// if(selectedSexList.size() > 0){
// for (TextView textview:selectedSexList){
// textview.setTextColor(getResources().getColor(R.color.item_light_gray));
// }
// selectedSexList.clear();
// }
// ((TextView) v).setTextColor(getResources().getColor(R.color.common_ff0000));
// selectedSexList.add(((TextView) v));
// }
// }
// }
// };
// getSex();
// //价格
// mPriceSupperLayout = (SupperLayout) filterContentView.findViewById(
// R.id.right_menu_price_superlayout);
// mFilterPriceOnClickListener = new View.OnClickListener() {
// @Override
// public void onClick(View v) {
// if (TextView.class.isInstance(v)) {
// if(selectedPriceList.contains(v)){
// ((TextView) v).setTextColor(getResources().getColor(R.color.item_light_gray));
// selectedPriceList.remove(v);
// }else {
// if(selectedPriceList.size() > 0){
// for (TextView textview:selectedPriceList){
// textview.setTextColor(getResources().getColor(R.color.item_light_gray));
// }
// selectedPriceList.clear();
// }
// ((TextView) v).setTextColor(getResources().getColor(R.color.common_ff0000));
// selectedPriceList.add(((TextView) v));
// }
// }
// }
// };
// getPrice();
// //城市
// mCitySupperLayout = (SupperLayout) filterContentView.findViewById(
// R.id.right_menu_city_superlayout);
// mFilterCityOnClickListener = new View.OnClickListener() {
// @Override
// public void onClick(View v) {
// if (TextView.class.isInstance(v)) {
// if(selectedList.contains(v)){
// ((TextView) v).setTextColor(getResources().getColor(R.color.item_light_gray));
// selectedList.remove(v);
// }else {
// ((TextView) v).setTextColor(getResources().getColor(R.color.common_ff0000));
// selectedList.add(((TextView) v));
// }
// }
// }
// };
// getCity();
// //确认
// sureTextview = (TextView) filterContentView.findViewById(
// R.id.filter_sure_textview);
// sureTextview.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View view) {
// //根据选择的条件去搜索
// if(selectedList.size() > 0){
// StringBuffer buffer = new StringBuffer();
// for(TextView seleted:selectedList){
// buffer.append(seleted.getText().toString()).append(",");
// }
// buffer.deleteCharAt(buffer.length()-1);
// mArea = buffer.toString();
// mArea = mArea.replace("√","");
// }else {
// mArea = "";
// }
// if(selectedSexList.size() > 0){
// mCrowd = selectedSexList.get(0).getText().toString();
// mCrowd = mCrowd.replace("√","");
// }else {
// mCrowd = "";
// }
// if(selectedPriceList.size() > 0){
// mPrice = selectedPriceList.get(0).getText().toString();
// mPrice = mPrice.replace("√","");
// }else {
// mPrice = "";
// }
// //进行搜索
// skip = 0;
// doInitLoad();
// popupWindow.dismiss();
// }
// });
// //取消
// cancelTextview = (TextView) filterContentView.findViewById(
// R.id.filter_cancel_textview);
// cancelTextview.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View view) {
// recoverFilterState();
// popupWindow.dismiss();
// }
// });
// }
//保留筛选窗口状态
private void saveFilterState(){
tempSelectedList = (LinkedList)selectedList.clone();
tempSelectedSexList = (LinkedList)selectedSexList.clone();
tempSelectedPriceList = (LinkedList)selectedPriceList.clone();
}
private void recoverFilterState(){
selectedList = tempSelectedList;
selectedSexList = tempSelectedSexList;
selectedPriceList = tempSelectedPriceList;
}
// //得到筛选窗口前的状态
// private void getFilterState(){
// //恢复初始状态
// for(int i = 0;i < cityArr.length; i++){
// ((TextView)mCitySupperLayout.getChildAt(i)).setTextColor(getResources().getColor(R.color.item_light_gray));
// }
// for(int i = 0;i < sexArr.length; i++){
// ((TextView)mSexSupperLayout.getChildAt(i)).setTextColor(getResources().getColor(R.color.item_light_gray));
// }
// for(int i = 0;i < priceArr.length; i++){
// ((TextView)mPriceSupperLayout.getChildAt(i)).setTextColor(getResources().getColor(R.color.item_light_gray));
// }
// if(selectedList.size() > 0){
// for(TextView textView:selectedList){
// textView.setTextColor(getResources().getColor(R.color.common_ff0000));
// }
// }
// if(selectedSexList.size() > 0){
// for(TextView textView:selectedSexList){
// textView.setTextColor(getResources().getColor(R.color.common_ff0000));
// }
// }
// if(selectedPriceList.size() > 0){
// for(TextView textView:selectedPriceList){
// textView.setTextColor(getResources().getColor(R.color.common_ff0000));
// }
// }
// }
//动态生成textview 并把它添加到popupwindow中
private TextView makeTextView(String name, int index, float textSize, int col,
View.OnClickListener onClick) {
TextView tv = new TextView(this);
tv.setText(name);
tv.setId(index);
ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
tv.setLayoutParams(params);
tv.setWidth(screenWidth / col - 40);
tv.setPadding(0, 15, 0, 15);
tv.setTextSize(textSize);
tv.setTextColor(getResources().getColor(R.color.common_666666));
tv.setOnClickListener(onClick);
return tv;
}
private TextView makeHotWordTextView(String name, int index, int textSize, int col,
View.OnClickListener onClick) {
TextView tv = new TextView(this);
tv.setText(name);
tv.setId(index);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
lp.setMargins(10, 10, 10, 10);
tv.setLayoutParams(lp);
tv.setPadding(30, 15, 30, 15);
tv.setTextSize(textSize);
tv.setBackgroundResource(R.drawable.bg_edittext_focused);
tv.setOnClickListener(onClick);
return tv;
}
private RadioButton makeRadioButton(String name, int textSize, int col,
View.OnClickListener onClick, int id) {
RadioButton tv = new RadioButton(this);
tv.setId(id);
tv.setText(name);
ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
tv.setLayoutParams(params);
tv.setWidth(screenWidth / col - 30);
tv.setPadding(0, 15, 0, 15);
tv.setTextSize(textSize);
tv.setClickable(true);
tv.setBackgroundResource(R.drawable.bg_edittext_focused);
tv.setVisibility(View.VISIBLE);
// tv.setTextColor(R.drawable.texview_selected_color);
// tv.setOnClickListener(onClick);
return tv;
}
// //城市
// private void getCity() {
// for (int i = 0; i < cityArr.length; i++) {
// TextView tv = makeTextView(cityArr[i], 0,(float)(12.6),3,
// mFilterCityOnClickListener);
// mCitySupperLayout.addView(tv);
// }
// }
// //性别
// private void getSex() {
// for (int i = 0; i < sexArr.length; i++) {
// TextView tv = makeTextView(sexArr[i], i, (float)(12.6), 3,
// mFilterSexOnClickListener);
mSexRadioGroup.addView(tv);
// mSexSupperLayout.addView(tv);
// }
// }
// //价格区间
// private void getPrice() {
// for (int i = 0; i < priceArr.length; i++) {
// TextView tv = makeTextView(priceArr[i], i, (float)(12.6), 3,
// mFilterPriceOnClickListener);
mPriceRadioGroup.addView(tv);
// mPriceSupperLayout.addView(tv);
// }
// }
// //系列
// private void getSerial(int index){
// //得到list的下标索引
// CategoryInfo categoryInfo = categoryInfos.get(index);
// mSerialList.clear();
// CategoryInfo categoryInfo1 = (CategoryInfo)categoryInfo.clone();
// categoryInfo1.cat_name = "全部";
// categoryInfo1.cat_id = categoryInfo.cat_id;
// mSerialList.add(categoryInfo1);
// mSerialList.addAll(categoryInfo.cat_children);
// mSerialArrayAdapter.notifyDataSetChanged();
// /*
// if(catchildrens != null && catchildrens.size() > 0 ) {
// //每个系统前面加一个全部
// TextView tv = makeTextView("全部",category_main_id ,(float)10.8,2,
// mSerialOnClickListener);
// tv.setPadding(0,5,10,0);
// tv.setTextColor(getResources().getColor(R.color.common_666666));
// serialSupperLayout.addView(tv);
// for(CategoryInfo cat:catchildrens){
// int catid = 0;
// if(!TextUtils.isEmpty(cat.cat_id))
// catid = Integer.valueOf(cat.cat_id);
// else catid = 0;
// tv = makeTextView(CommonUtil.replaceBlank(cat.cat_name), catid,(float)10.8,2,
// mSerialOnClickListener);
// tv.setPadding(5,10,15,10);
// tv.setLines(2);
// tv.setEllipsize(TextUtils.TruncateAt.END);
// tv.setMaxWidth(screenWidth / 3 - 40);
// tv.setTextColor(getResources().getColor(R.color.item_light_gray));
// tv.setBackgroundResource(R.drawable.click_background);
// serialSupperLayout.addView(tv);
// }
// }*/
// }
// //查询品牌
// private void doSearchBrand() {
// //检索数据前首先检查网络是否可用
// if(!BaseApplication.getInstance().isNetworkAvailable(this)){
// Toast.makeText(this, getString(R.string.no_network_toast), Toast.LENGTH_SHORT).show();
// return;
// }
// getStatusTip().showProgress();
// StringRequest postRequest = new StringRequest(com.android.volley.Request.Method.POST, Constant.categoryUrl,
// new com.android.volley.Response.Listener(){
// @Override
// public void onResponse(String response) {
// //处理返回结果
// parseBrandCategoryJson(response);
// getStatusTip().hideProgress();
// }
// },
// new com.android.volley.Response.ErrorListener() {
// @Override
// public void onErrorResponse(VolleyError error) {
// Toast.makeText(GoodsSearchActivity.this,getString(R.string.reload_txt), Toast.LENGTH_SHORT).show();
// getStatusTip().hideProgress();
// }
// });
// BaseApplication.mRequestQueue.add(postRequest);
// }
//解析json数据
// private void parseBrandCategoryJson(String json){
// Gson gson = new Gson();
// CategoryResult categorys = gson.fromJson(json, CategoryResult.class);
// //有错误信息返回
// if(categorys != null
// && "0".equals(categorys.status.succeed)){
// Toast.makeText(GoodsSearchActivity.this,categorys.status.error_desc, Toast.LENGTH_SHORT).show();
// return;
// }else{
// if(categorys.data != null&& categorys.data.size() > 0 ){
// categoryInfos = categorys.data;
// //成功返回品牌list
// int i = 0;
// for(CategoryInfo categoryInfo:categorys.data){
// TextView tv = makeTextView(categoryInfo.cat_name,i, (float)14.4,3,
// mOnClickListener);
// if(TextUtils.isEmpty(mCatName)){
// tv.setTextColor(getResources().getColor(R.color.item_light_gray));
// }else{
// if(mCatName.equals(categoryInfo.cat_name)){
// tv.setTextColor(getResources().getColor(R.color.common_ff0000));
// //得到系列数据
// getSerial(i);
// }else {
// tv.setTextColor(getResources().getColor(R.color.item_light_gray));
// }
// }
// brandSupperLayout.addView(tv);
// i++;
// }
// }
// }
// }
//处理刷新
private void autoRefresh(){
loading.setVisibility(View.VISIBLE);
moreTextView.setVisibility(View.GONE);
skip = goodsInfos.size();
//doRefresh();
}
//初始化加载
private void doInitLoad() {
//检索数据前首先检查网络是否可用
BaseApplication application = new BaseApplication();
if(!application.isNetworkAvailable(this)){
Toast.makeText(GoodsSearchActivity.this,getString(R.string.no_network_toast), Toast.LENGTH_SHORT).show();
return;
}
getStatusTip().showProgress();
StringRequest postRequest = new StringRequest(Request.Method.POST, Constant.getSearchWord,
new Response.Listener(){
@Override
public void onResponse(String response) {
//处理返回结果
parseInitJson(response);
getStatusTip().hideProgress();
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
getStatusTip().showProgress();
loadFailView.setViewsVisible(0);
}
})
{
@Override
protected Map, String> getParams(){//传入后台的参数
Map, String> params = new HashMap, String>();
params.put("data", "{" +
"\"searchWord\":"+getText()+"," +
"\"page\":"+page+"," +
"\"pagesize\":"+pagesize+"," +
"\"version\":\""+BaseApplication.verName+"\"," +
"\"versionCode\":\""+BaseApplication.verCode+"\"," +
"\"system\":\""+BaseApplication.SYSTEMFLG+"\"" +
"}");//搜索条件
return params;
}
};
BaseApplication.mRequestQueue.add(postRequest);
}
// //检索处理
// private void doRefresh() {
// //检索数据前首先检查网络是否可用
// BaseApplication application = new BaseApplication();
// if(!application.isNetworkAvailable(this)){
// loading.setVisibility(View.GONE);
// moreTextView.setVisibility(View.VISIBLE);
// Toast.makeText(GoodsSearchActivity.this,getString(R.string.no_network_toast), Toast.LENGTH_SHORT).show();
// return;
// }
// StringRequest postRequest = new StringRequest(Request.Method.POST, Constant.getSearchWord,
// new Response.Listener(){
// @Override
// public void onResponse(String response) {
// //处理返回结果
// parseJson(response);
// loading.setVisibility(View.GONE);
// moreTextView.setVisibility(View.VISIBLE);
// }
// },
// new Response.ErrorListener() {
// @Override
// public void onErrorResponse(VolleyError error) {
// Toast.makeText(GoodsSearchActivity.this,error.getMessage(), Toast.LENGTH_SHORT).show();
// loading.setVisibility(View.GONE);
// moreTextView.setVisibility(View.VISIBLE);
// }
// })
// {
// @Override
// protected Map getParams(){//传入后台的参数
// Map params = new HashMap();
// if("30000以上".equals(mPrice)){
// mPrice = mPrice.replace("30000以上","30001-100000000");
// }
//
// params.put("data", "{" +
// "\"searchWord\":"+"1"+"," +
// "\"version\":\""+BaseApplication.verName+"\"," +
// "\"versionCode\":\""+BaseApplication.verCode+"\"," +
// "\"system\":\""+BaseApplication.SYSTEMFLG+"\"" +
// "}");//搜索条件
// return params;
// }
// };
// BaseApplication.mRequestQueue.add(postRequest);
// }
//解析json数据
private void parseJson(String json){
Gson gson = new Gson();
// GoodsList goodsList = gson.fromJson(json, GoodsList.class);
// //有错误信息返回
// if(goodsList == null || (goodsList != null
// && "0".equals(goodsList.status.succeed))){
// Toast.makeText(this,goodsList.status.error_desc, Toast.LENGTH_SHORT).show();
// return;
// }else{
// if(goodsList.data != null
// && goodsList.data.size() > 0
// ){
// //成功返回商品list
// goodsListAdapter.addAll(goodsList.data);
// }else{
// moreTextView.setText("已加载全部数据");
// }
// }
}
//解析json数据
private void parseInitJson(String json){
Gson gson = new Gson();
GoodsSearchResult homePageResult = gson.fromJson(json, GoodsSearchResult.class);
//有错误信息返回
if (homePageResult != null
&& 200==(homePageResult.getCode())) {
//服务器当前时间
if(homePageResult.getData() != null){
if (homePageResult.getData() != null
&& homePageResult.getData().size() > 0){
//养护
mDataInfo=homePageResult.getData();
adapter.getList().clear();
adapter.appendToList(mDataInfo);
}
//loadFailView.setViewsVisible(View.GONE);
}
} else {
Toast.makeText(GoodsSearchActivity.this, homePageResult != null ? homePageResult.getMessage() : "", Toast.LENGTH_SHORT).show();
}
}
//商品数据点击事件处理
private void GoodsItemClick(){
goodsListView.setOnItemClickListener(new AdapterView.OnItemClickListener(){
@Override
public void onItemClick(AdapterView> parent, View view, int position, long id) {
// Intent intent = new Intent();
// intent.setClass(GoodsSearchActivity.this, GoodsDetailActivity.class);
// Bundle dataBun = new Bundle();
// dataBun.putString(
// GoodsDetailActivity.GOODSID,
// ((GoodsInfo) goodsInfos.get(position)).goods_id);
// dataBun.putString(
// GoodsDetailActivity.GOODSNAME,
// ((GoodsInfo) goodsInfos.get(position)).goods_name);
// intent.putExtras(dataBun);
// startActivity(intent);
}
});
}
@Override
public void finish(View view) {
}
@Override
protected void doReload() {
}
}
XML:
xml version="1.0" encoding="utf-8"?>
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/base_backgroud_color">
android:id="@+id/search_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
>
android:id="@+id/title_back_layout"
android:layout_width="wrap_content"
android:layout_height="49.2dp"
android:paddingLeft="@dimen/common_space"
>
android:id="@+id/title_back_imageview"
android:layout_width="9dp"
android:layout_height="18dp"
android:layout_centerVertical="true"
android:clickable="true"
android:background="@drawable/title_back_imageview"
android:layout_gravity="center_vertical"
/>
android:id="@+id/search_edittext_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/margin_10dp"
android:layout_marginLeft="@dimen/common_space"
android:layout_marginRight="50dp"
android:layout_marginTop="@dimen/margin_10dp"
android:layout_toRightOf="@+id/title_back_layout"
android:background="@drawable/bg_edittext_focused">
android:id="@+id/search_myedittext"
android:layout_width="match_parent"
android:layout_height="29.2dp"
android:background="@null"
android:hint="@string/search_edt_hint"
android:imeOptions="actionSearch"
android:paddingLeft="@dimen/margin_15dp"
android:lines="1"
android:textSize="@dimen/small_text_size_12" />
android:id="@+id/my_delete"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:paddingRight="@dimen/margin_10dp"
android:src="@drawable/delete_text_icon"
android:visibility="gone" />
android:id="@+id/search_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="@dimen/common_space"
android:clickable="true"
android:gravity="center"
android:text="搜索"
android:textColor="@color/color_333333"
android:textSize="@dimen/small_text_size_12" />
android:id="@+id/content_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/search_layout">
android:id="@+id/goods_listview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:cacheColorHint="#00000000"
android:fadingEdge="none"
android:fastScrollEnabled="false"
android:footerDividersEnabled="false"
android:headerDividersEnabled="false"
android:paddingLeft="@dimen/common_space"
android:smoothScrollbar="true" />
android:id="@+id/shade_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#70000000"
android:visibility="gone"
/>
android:id="@+id/search_his_popupwindow"
layout="@layout/search_his_popupwindow"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@id/search_layout"
android:visibility="gone"
android:background="@color/white"
/>
android:id="@+id/no_network_view"
android:layout_width="match_parent"
android:visibility="gone"
android:layout_height="match_parent"
/>
android:id="@+id/load_fail_view"
android:layout_width="match_parent"
android:visibility="gone"
android:layout_height="match_parent" />