package com.weather.com.welcomeactivity.app;
import ...
/**
* 商品信息列表
*/
public class GoodsInfoActivity extends Activity implements View.OnClickListener {
private ImageButton ibGoodInfoBack;
private ImageButton ibGoodInfoMore;
private ImageView ivGoodInfoImage;
private TextView tvGoodInfoName;
private TextView tvGoodInfoDesc;
private TextView tvGoodInfoPrice;
private TextView tvGoodInfoStore;
private TextView tvGoodInfoStyle;
private WebView wbGoodInfoMore;
private LinearLayout llGoodsroot;
private TextView tvGoodInfoCallcenter;
private TextView tvGoodInfoCollection;
private TextView tvGoodInfoCart;
private Button btnGoodInfoAddcart;
private TextView tvMoreShare;
private TextView tvMoreSearch;
private TextView tvMoreHome;
private LinearLayout ll_root;
private Button btn_more;
private CartProvider cartProvider;
//private Boolean isFirst =true;
/*//模拟商家的数组
private String[] sellers =new String[]{"尚硅谷","画影工作室","Wacom"};
private List<GoodsList>goodsLists;
private GoodsList goodsList;
*/
private GoodsBean goods_bean;
private List<GoodsBean> goodsBeans;
private ImageView ivPopImg;
private TextView tvPopInfo;
private NumberAddSubView numberAddSubView;
private Button btnCancel;
private Button btnComfirm;
private TextView tvPopPrice;
private void findViews() {
ibGoodInfoBack = (ImageButton) findViewById(R.id.ib_good_info_back);
ibGoodInfoMore = (ImageButton) findViewById(R.id.ib_good_info_more);
ivGoodInfoImage = (ImageView) findViewById(R.id.iv_good_info_image);
tvGoodInfoName = (TextView) findViewById(R.id.tv_good_info_name);
tvGoodInfoDesc = (TextView) findViewById(R.id.tv_good_info_desc);
tvGoodInfoPrice = (TextView) findViewById(R.id.tv_good_info_price);
tvGoodInfoStore = (TextView) findViewById(R.id.tv_good_info_store);
tvGoodInfoStyle = (TextView) findViewById(R.id.tv_good_info_style);
wbGoodInfoMore = (WebView) findViewById(R.id.wb_good_info_more);
llGoodsroot = (LinearLayout) findViewById(R.id.ll_goods_root);
tvGoodInfoCallcenter = (TextView) findViewById(R.id.tv_good_info_callcenter);
tvGoodInfoCollection = (TextView) findViewById(R.id.tv_good_info_collection);
tvGoodInfoCart = (TextView) findViewById(R.id.tv_good_info_cart);
btnGoodInfoAddcart = (Button) findViewById(R.id.btn_good_info_addcart);
ll_root = (LinearLayout) findViewById(R.id.ll_root);
tvMoreShare = (TextView) findViewById(R.id.tv_more_share);
tvMoreSearch = (TextView) findViewById(R.id.tv_more_search);
tvMoreHome = (TextView) findViewById(R.id.tv_more_home);
btn_more = (Button) findViewById(R.id.btn_more);
btn_more.setOnClickListener(this);
ibGoodInfoBack.setOnClickListener(this);
ibGoodInfoMore.setOnClickListener(this);
tvMoreShare.setOnClickListener(this);
tvMoreSearch.setOnClickListener(this);
tvMoreHome.setOnClickListener(this);
tvGoodInfoCallcenter.setOnClickListener(this);
tvGoodInfoCollection.setOnClickListener(this);
tvGoodInfoCart.setOnClickListener(this);
btnGoodInfoAddcart.setOnClickListener(this);
tvGoodInfoCallcenter.setOnClickListener(this);
}
public void showPopwindow() {
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.popwindow_add_product, null);
final PopupWindow window = new PopupWindow(view, WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
window.setFocusable(true);
window.setTouchable(true);
window.setOutsideTouchable(true);
window.setBackgroundDrawable(new ColorDrawable());
window.showAtLocation(view, Gravity.BOTTOM, 0, 0);
ViewHolder holder = new ViewHolder(view);
holder.setData(goods_bean, window);
btnCancel.setOnClickListener(this);
btnComfirm.setOnClickListener(this);
}
class ViewHolder extends RecyclerView.ViewHolder {
public Context mContext;
public ViewHolder(View view) {
super(view);
ivPopImg = (ImageView) view.findViewById(R.id.iv_pop_img);
tvPopInfo = (TextView) view.findViewById(R.id.tv_pop_info);
numberAddSubView = (NumberAddSubView) view.findViewById(R.id.number_add_sub_view);
btnCancel = (Button) view.findViewById(R.id.btn_cancel);
btnComfirm = (Button) view.findViewById(R.id.btn_comfirm);
tvPopPrice = (TextView) view.findViewById(R.id.tv_pop_price);
//查百度查到的,很开心。mContext可以用了^-^。还是中文容易懂。
//可是那个布局的东西现在还是空的摸不着头脑
mContext = GoodsInfoActivity.this;
}
public void setData(final GoodsBean goodsBean, final PopupWindow window) {
Glide.with(mContext)
.load(Constants.Base_URl_IMAGE + goodsBean.getFigure())
.into(ivPopImg);
tvPopInfo.setText(goodsBean.getName());
tvPopPrice.setText("¥" + goodsBean.getCover_price());
numberAddSubView.setValue(goodsBean.getNumber());
numberAddSubView.setOnNumberChangeListener(new NumberAddSubView.OnNumberChangeListener() {
@Override
public void addNumber(View view, int value) {
goodsBean.setNumber(value);
}
@Override
public void subNumber(View view, int value) {
goodsBean.setNumber(value);
}
});
btnComfirm.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
cartProvider.addData(goodsBean);
window.dismiss();
Toast.makeText(GoodsInfoActivity.this, "加入购物车", Toast.LENGTH_SHORT).show();
}
});
btnCancel.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
cartProvider.addData(goodsBean);
window.dismiss();
Toast.makeText(GoodsInfoActivity.this, "取消加入购物车", Toast.LENGTH_SHORT).show();
}
});
}
}
@Override
public void onClick(View v) {
if (v == ibGoodInfoBack) {
finish();
} else if (v == ibGoodInfoMore) {
if (ll_root.getVisibility() == View.VISIBLE) {
ll_root.setVisibility(View.GONE);
} else {
ll_root.setVisibility(View.VISIBLE);
}
} else if (v == btn_more) {
ll_root.setVisibility(View.GONE);
} else if (v == tvMoreShare) {
Toast.makeText(GoodsInfoActivity.this, "分享", Toast.LENGTH_SHORT).show();
// showShare();
} else if (v == tvMoreSearch) {
Toast.makeText(GoodsInfoActivity.this, "搜索", Toast.LENGTH_SHORT).show();
} else if (v == tvMoreHome) {
Constants.isBackHome = true;
finish();
} else if (v == tvGoodInfoCallcenter) {
Toast.makeText(GoodsInfoActivity.this, "客服", Toast.LENGTH_SHORT).show();
// Intent intent = new Intent(this,CallCenterActivity.class);
// startActivity(intent);
} else if (v == tvGoodInfoCollection) {
Toast.makeText(GoodsInfoActivity.this, "收藏", Toast.LENGTH_SHORT).show();
} else if (v == tvGoodInfoCart) {
Toast.makeText(GoodsInfoActivity.this, "购物车", Toast.LENGTH_SHORT).show();
// Intent intent = new Intent(this, ShoppingCartActivity.class);
// startActivity(intent);
} else if (v == btnGoodInfoAddcart) {
//添加购物车
// cartProvider.addData(goods_bean);
cartProvider = CartProvider.getInstance();
showPopwindow();
// Toast.makeText(GoodsInfoActivity.this, "添加购物车成功", Toast.LENGTH_SHORT).show();
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_goods_info);
findViews();
// cartProvider =CartProvider.getInstance();
//取出 intent
Intent intent = getIntent();
goods_bean = (GoodsBean) intent.getSerializableExtra("goods_bean");
if (goods_bean != null) {
//本地获取存储的数据
setDataFormView(goods_bean);
}
}
private void setWebView(String product_id) {
if (product_id != null) {
//http://192.168.51.104:8080/atguigu/json/GOODSINFO_URL.json2691 //wbGoodInfoMore.loadUrl(Constants.GOODSINFO_URL + product_id);
wbGoodInfoMore.loadUrl("http://www.jd.com");
//覆盖 WebView 默认使用第三方或系统默认浏览器打开网页的行为,使网页用 WebView 打开
wbGoodInfoMore.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
//返回值是 true 的时候控制去 WebView 打开,为 false 调用
//系统浏览器或第三方浏览器
view.loadUrl(url);
return true;
}
});
//启用支持 javascript
WebSettings settings = wbGoodInfoMore.getSettings();
settings.setJavaScriptEnabled(true);
settings.setUseWideViewPort(true);
//优先使用缓存
wbGoodInfoMore.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
}
}
public void setDataFormView(GoodsBean goodsBean) {
String name = goodsBean.getName();
String cover_price = goodsBean.getCover_price();
String figure = goodsBean.getFigure();
String product_id = goodsBean.getProduct_id();
Glide.with(this).load(Constants.Base_URl_IMAGE + figure).into(ivGoodInfoImage);
if (name != null) {
tvGoodInfoName.setText(name);
}
if (cover_price != null) {
tvGoodInfoPrice.setText("¥" + cover_price);
}
setWebView(product_id);
}
}
相关分类