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; ? ?/*//模擬商家的數(shù)組 ? ?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可以用了^-^。還是中文容易懂。 ? ? ? ? ? ?//可是那個布局的東西現(xiàn)在還是空的摸不著頭腦 ? ? ? ? ? ?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) { ? ? ? ? ? ?//本地獲取存儲的數(shù)據(jù) ? ? ? ? ? ?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 默認使用第三方或系統(tǒng)默認瀏覽器打開網(wǎng)頁的行為,使網(wǎng)頁用 WebView 打開 ? ? ? ? ? ?wbGoodInfoMore.setWebViewClient(new WebViewClient() { ? ? ? ? ? ? ? ?@Override ? ? ? ? ? ? ? ?public boolean shouldOverrideUrlLoading(WebView view, String url) { ? ? ? ? ? ? ? ? ? ?//返回值是 true 的時候控制去 WebView 打開,為 false 調(diào)用 ? ? ? ? ? ? ? ? ? ?//系統(tǒng)瀏覽器或第三方瀏覽器 ? ? ? ? ? ? ? ? ? ?view.loadUrl(url); ? ? ? ? ? ? ? ? ? ?return true; ? ? ? ? ? ? ? ?} ? ? ? ? ? ?}); ? ? ? ? ? ?//啟用支持 javascript ? ? ? ? ? ?WebSettings settings = wbGoodInfoMore.getSettings(); ? ? ? ? ? ?settings.setJavaScriptEnabled(true); ? ? ? ? ? ?settings.setUseWideViewPort(true); ? ? ? ? ? ?//優(yōu)先使用緩存 ? ? ? ? ? ?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); ? ?}}
為什么點了確認按鈕沒反應(yīng)
qq_Linjj藍極光輝_04362138
2017-12-14 10:38:01