parent
7ccc56a382
commit
c131d790d3
@ -0,0 +1,133 @@
|
|||||||
|
package edu.hzuapps.viewproducts;
|
||||||
|
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.BitmapFactory;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.Message;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
import edu.hzuapps.viewproducts.bean.Itembean;
|
||||||
|
|
||||||
|
public class Information_Activity extends AppCompatActivity{
|
||||||
|
private TextView mTvTitle;
|
||||||
|
private TextView mTvContent;
|
||||||
|
private ImageView mIvImage;
|
||||||
|
private Itembean mNewsBean;
|
||||||
|
private Button back_btn;
|
||||||
|
protected static final int CHANGE_UI = 1;
|
||||||
|
protected static final int ERROR = 2;
|
||||||
|
private ImageView ivPic;
|
||||||
|
|
||||||
|
private Handler handler = new Handler(){//主线程创建消息处理器
|
||||||
|
public void handleMessage(android.os.Message msg){
|
||||||
|
if (msg.what == CHANGE_UI){
|
||||||
|
Bitmap bitmap = (Bitmap) msg.obj;
|
||||||
|
ivPic.setImageBitmap(bitmap);
|
||||||
|
}else if(msg.what == ERROR){
|
||||||
|
Toast.makeText(Information_Activity.this,"图片显示失败",Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_information);
|
||||||
|
|
||||||
|
initView();
|
||||||
|
initData();
|
||||||
|
initEvent();
|
||||||
|
|
||||||
|
back_btn.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
Intent intent = new Intent(Information_Activity.this,ListViewActivity.class);
|
||||||
|
startActivity(intent);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void click(View view){
|
||||||
|
new Thread(){
|
||||||
|
private HttpURLConnection conn;
|
||||||
|
private Bitmap bitmap;
|
||||||
|
public void run(){
|
||||||
|
try {
|
||||||
|
String title = mNewsBean.getTitle();
|
||||||
|
URL url = null;
|
||||||
|
if ("态极闪现1代".equals(title)) {
|
||||||
|
url = new URL("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fam.zdmimg.com%2F202105%2F30%2F60b2f4768cd7f6124.png_e680.jpg&refer=http%3A%2F%2Fam.zdmimg.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1627325338&t=62a178742590ddf8803bd92a1a0197f7");
|
||||||
|
}else if ("李宁音速7".equals(title)){
|
||||||
|
url = new URL("https://img1.baidu.com/it/u=1873542307,3620652532&fm=26&fmt=auto&gp=0.jpg");
|
||||||
|
}else if ("vans Old skool".equals(title)){
|
||||||
|
url = new URL("https://img0.baidu.com/it/u=1585008502,4137901845&fm=26&fmt=auto&gp=0.jpg");
|
||||||
|
}else if ("M2K tekno".equals(title)){
|
||||||
|
url = new URL("https://gimg2.baidu.com/image_search/src=http%3A%2F%2F5b0988e595225.cdn.sohucs.com%2Fimages%2F20181222%2F97ff160ee8c24d0cad640a3330f1ab37.jpeg&refer=http%3A%2F%2F5b0988e595225.cdn.sohucs.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1627328091&t=6decbda5cb66c15cb48ef1e62969774b");
|
||||||
|
}else if ("converse 1970s".equals(title)){
|
||||||
|
url = new URL("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic1.58cdn.com.cn%2Fzhuanzh%2Fn_v22b0b9abc301f4ac5ad19d0b85db512c2.jpg%3Fw%3D750%26h%3D0&refer=http%3A%2F%2Fpic1.58cdn.com.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1627328151&t=564f51357387e4ff9ea16a637f263cf5");
|
||||||
|
}else if ("韦德之道全城9".equals(title)){
|
||||||
|
url = new URL("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.alicdn.com%2Fbao%2Fuploaded%2Fi4%2F2931649245%2FO1CN01osV7P52IAGCokVjCt_%21%212931649245.jpg&refer=http%3A%2F%2Fimg.alicdn.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1627328189&t=43b40fa1b28be1dee22e368dc5505178");
|
||||||
|
}
|
||||||
|
conn = (HttpURLConnection) url.openConnection();
|
||||||
|
conn.setRequestMethod("GET");
|
||||||
|
conn.setConnectTimeout(5000);
|
||||||
|
int code = conn.getResponseCode();
|
||||||
|
if(code==200){
|
||||||
|
InputStream is = conn.getInputStream();
|
||||||
|
bitmap = BitmapFactory.decodeStream(is);
|
||||||
|
Message msg = new Message();
|
||||||
|
msg.what = CHANGE_UI;
|
||||||
|
msg.obj = bitmap;
|
||||||
|
handler.sendMessage(msg);
|
||||||
|
}else {
|
||||||
|
Message msg = new Message();
|
||||||
|
msg.what = ERROR;
|
||||||
|
handler.sendMessage(msg);
|
||||||
|
}
|
||||||
|
}catch (Exception e){
|
||||||
|
e.printStackTrace();
|
||||||
|
Message msg = new Message();
|
||||||
|
msg.what = ERROR;
|
||||||
|
handler.sendMessage(msg);
|
||||||
|
}
|
||||||
|
conn.disconnect();
|
||||||
|
}
|
||||||
|
}.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initView() {
|
||||||
|
back_btn = findViewById(R.id.back);
|
||||||
|
mIvImage = findViewById(R.id.iv_img);
|
||||||
|
mTvContent = findViewById(R.id.tv_content);
|
||||||
|
mTvTitle = findViewById(R.id.tv_title);
|
||||||
|
ivPic = (ImageView) findViewById(R.id.iv_img);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initData() {
|
||||||
|
|
||||||
|
Intent intent = getIntent();
|
||||||
|
mNewsBean = (Itembean) intent.getSerializableExtra("item");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initEvent() {
|
||||||
|
if (mNewsBean != null) {
|
||||||
|
mTvTitle.setText(mNewsBean.getTitle());
|
||||||
|
mTvContent.setText(mNewsBean.getContent());
|
||||||
|
mIvImage.setImageResource(mNewsBean.getImgResId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue