private void init() { userInfo = HallDataManager.getInstance().getUserMe(); ((TextView) findViewById(R.id.tvTitle)).setText(R.string.mix); findViewById(R.id.tvBack).setOnClickListener(this); // 返回 mMix = (Button) findViewById(R.id.btn_mix); btnReduce = (Button) findViewById(R.id.btnReduce); btnIncrease = (Button) findViewById(R.id.btnIncrease); mMix.setOnClickListener(this); btnReduce.setOnClickListener(this); btnIncrease.setOnClickListener(this); mPropName = (TextView) findViewById(R.id.mix_prop_name); mPropDesc = (TextView) findViewById(R.id.mix_prop_desc); mPropImg = (ImageView) findViewById(R.id.mix_prop_img); mMixNum = (TextView) findViewById(R.id.tvMixNum); mMixCost = (TextView) findViewById(R.id.mix_cost); mMixRate = (TextView) findViewById(R.id.mix_precent); mPropName.setText(mixInfo.name); mPropDesc.setText(mixInfo.desc); mMixCost.setText(String.valueOf(mixInfo.beanCost)); if (userInfo.memberOrder > 10) { mMixRate.setText(String.valueOf(mixInfo.vr) + "%"); } else { mMixRate.setText(String.valueOf(mixInfo.or) + "%"); } cousumeItems = (LinearLayout) findViewById(R.id.mix_material_list); // 设置图片 String photoFileName = mixInfo.logo; String photoName = photoFileName.substring(0, photoFileName.indexOf('.')); int drawableId = mContext.getResources().getIdentifier(photoName, "drawable", mContext.getPackageName()); if (drawableId > 0) { // res有图片 mPropImg.setBackgroundResource(drawableId); } else { String iconDir = Util.getIconDir(); File localFile = new File(iconDir, photoFileName); if (localFile.exists()) { Bitmap bitmap = BitmapFactory.decodeFile(localFile.getPath()); if (bitmap != null) { int width = bitmap.getWidth(); int height = bitmap.getHeight(); int disWidth = DensityConst.getWidthPixels(); Bitmap scaleBitmap = Bitmap.createScaledBitmap( bitmap, width * disWidth / 800, height * disWidth / 800, true); mPropImg.setImageBitmap(scaleBitmap); } } } }
private void setImageRes(String photoFileName, ImageView imageView) { if (!Util.isEmptyStr(photoFileName)) { String iconDir = Util.getIconDir(); if (photoFileName.endsWith(".png") || photoFileName.endsWith(".jpg")) { int end = photoFileName.length() - 4; String photoName = photoFileName.substring(0, end); int drawableId = mContext.getResources().getIdentifier(photoName, "drawable", mContext.getPackageName()); if (drawableId > 0) { // res有图片 imageView.setImageResource(drawableId); } else { File file = new File(iconDir, photoFileName); if (file.exists()) { Bitmap bitmap = BitmapFactory.decodeFile(file.getPath()); if (bitmap != null) { int width = bitmap.getWidth(); int height = bitmap.getHeight(); int disWidth = DensityConst.getWidthPixels(); Bitmap scaleBitmap = Bitmap.createScaledBitmap( bitmap, width * disWidth / 800, height * disWidth / 800, true); imageView.setImageBitmap(scaleBitmap); } else { file.delete(); imageView.setImageResource(R.drawable.goods_icon); String url = AppConfig.MIXICON_PATH + "/" + photoFileName; new ImageAsyncTaskDownload(url, photoFileName, imageView).execute(); } } else { imageView.setImageResource(R.drawable.goods_icon); String url = AppConfig.MIXICON_PATH + "/" + photoFileName; new ImageAsyncTaskDownload(url, photoFileName, imageView).execute(); } } } } }