大二下学期团队项目(app端电影显示)

今日修复了分类查询无法显示图片的bug,但是有图片显示慢,导致手机卡死的情况,可以使用多线程解决,但是子线程不能修改视图,所以无法显示图片,以后将尝试用子线程解决。修复了显示页面无法滑动的bug。完成了手机端的电影详情页面的展示。

package com.example.cloudlibrary.Fragment;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.example.cloudlibrary.Adapter.CloudPagerAdapter;
import com.example.cloudlibrary.Data.ListData;
import com.example.cloudlibrary.MoviePagerActivity;
import com.example.cloudlibrary.R;
import com.example.cloudlibrary.tools.FlowRadioGroup;
import com.example.cloudlibrary.tools.xUtils3TestActivity;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.xutils.common.Callback;
import org.xutils.http.RequestParams;
import org.xutils.x;

import java.util.ArrayList;
import java.util.List;

public class CloudPageFragment extends Fragment implements RadioGroup.OnCheckedChangeListener{
    FlowRadioGroup type_group;
    FlowRadioGroup date_group;
    FlowRadioGroup area_group;
    RadioGroup first_group;
    Button more_show;
    Button less_show;
    TextView test;
    int num=0;
    String[] str_s={"","","","","0"};
    View view;
    ListView class_show;
    CloudPagerAdapter cloudPagerAdapter;

    xUtils3TestActivity xutils=new xUtils3TestActivity();
    List<ListData> list_data=new ArrayList<>();
    ListData listData;

    public CloudPageFragment(){
    }
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.activity_cloud_page, container, false);
        //控件声明
        type_group=(FlowRadioGroup)view.findViewById(R.id.type_group);
        date_group=(FlowRadioGroup)view.findViewById(R.id.date_group);
        area_group=(FlowRadioGroup)view.findViewById(R.id.area_group);
        first_group=(RadioGroup)view.findViewById(R.id.first_group);
        more_show=(Button)view.findViewById(R.id.more_show);
        less_show=(Button)view.findViewById(R.id.less_show);
        class_show=(ListView)view.findViewById(R.id.class_show);
        //分类排序监听
        type_group.setOnCheckedChangeListener(this);
        date_group.setOnCheckedChangeListener(this);
        area_group.setOnCheckedChangeListener(this);
        first_group.setOnCheckedChangeListener(this);
        //上一页下一页点击事件
        more_show.setOnClickListener(new View.OnClickListener(){

            @Override
            public void onClick(View v) {
                num = num + 20;
                str_s[4] = "" + num;
                RequestParams params = new RequestParams("http://10.98.16.79:5000/query_tag");
                //params.setMultipart(true);
                params.addBodyParameter("type", str_s[0]);
                params.addBodyParameter("date", str_s[1]);
                params.addBodyParameter("area", str_s[2]);
                params.addBodyParameter("first", str_s[3]);
                params.addBodyParameter("num", str_s[4]);
                //params.addBodyParameter("File",new File(Environment.getExternalStorageDirectory()+"/test_download/YLY.jpg"),null,"YLY.jpg");
                x.http().get(params, new Callback.CacheCallback<String>() {
                    List<ListData> list_data_flag = new ArrayList<>();

                    @Override
                    public boolean onCache(String result) {
                        return false;
                    }

                    @Override
                    public void onSuccess(String result) {
                        try {
                            JSONObject object = new JSONObject(result);
                            JSONArray array = object.optJSONArray("data");
                            for (int i = 0; i < array.length(); i++) {
//                        map=new HashMap<>();
                                String title = array.getString(i);
                                String[] Str_s;
                                Str_s = title.split(",");
                                String str = "";
                                for (int k = 0; k < Str_s.length; k++) {
                                    if (k == 0) {
                                        Str_s[k] = Str_s[k].substring(2, Str_s[k].length() - 1);
                                    }
                                    if (k == Str_s.length - 1) {
                                        Str_s[k] = Str_s[k].substring(1, Str_s[k].length() - 2);
                                    }
                                    if (k != 7 && k != 0 && k != Str_s.length - 1) {
                                        Str_s[k] = Str_s[k].substring(1, Str_s[k].length() - 1);
                                    }
                                }
                                listData = new ListData(Str_s[0], Str_s[1], Str_s[2], Str_s[6], Str_s[5], Str_s[4], "", Str_s[3]
                                        , "", Str_s[8], Str_s[7], "");
                                list_data_flag.add(listData);
                            }
                            list_data = list_data_flag;
                            cloudPagerAdapter = new CloudPagerAdapter(getContext(), list_data);
                            class_show.setAdapter(cloudPagerAdapter);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }

                    @Override
                    public void onError(Throwable ex, boolean isOnCallback) {
                        Log.e("TAG", "onError==" + ex.toString());
                    }

                    @Override
                    public void onCancelled(CancelledException cex) {
                        Log.e("TAG", "onCancelled==" + cex.toString());
                    }

                    @Override
                    public void onFinished() {
                        Log.e("TAG", "onFinished");
                    }
                });
            }
        });
        less_show.setOnClickListener(new View.OnClickListener(){

            @Override
            public void onClick(View v) {
                num = num - 20;
                if(num<0){
                    num=0;
                }
                str_s[4] = "" + num;
                RequestParams params = new RequestParams("http://10.98.16.79:5000/query_tag");
                //params.setMultipart(true);
                params.addBodyParameter("type", str_s[0]);
                params.addBodyParameter("date", str_s[1]);
                params.addBodyParameter("area", str_s[2]);
                params.addBodyParameter("first", str_s[3]);
                params.addBodyParameter("num", str_s[4]);
                //params.addBodyParameter("File",new File(Environment.getExternalStorageDirectory()+"/test_download/YLY.jpg"),null,"YLY.jpg");
                x.http().get(params, new Callback.CacheCallback<String>() {
                    List<ListData> list_data_flag = new ArrayList<>();

                    @Override
                    public boolean onCache(String result) {
                        return false;
                    }

                    @Override
                    public void onSuccess(String result) {
                        try {
                            JSONObject object = new JSONObject(result);
                            JSONArray array = object.optJSONArray("data");
                            for (int i = 0; i < array.length(); i++) {
//                        map=new HashMap<>();
                                String title = array.getString(i);
                                String[] Str_s;
                                Str_s = title.split(",");
                                String str = "";
                                for (int k = 0; k < Str_s.length; k++) {
                                    if (k == 0) {
                                        Str_s[k] = Str_s[k].substring(2, Str_s[k].length() - 1);
                                    }
                                    if (k == Str_s.length - 1) {
                                        Str_s[k] = Str_s[k].substring(1, Str_s[k].length() - 2);
                                    }
                                    if (k != 7 && k != 0 && k != Str_s.length - 1) {
                                        Str_s[k] = Str_s[k].substring(1, Str_s[k].length() - 1);
                                    }
                                }
                                listData = new ListData(Str_s[0], Str_s[1], Str_s[2], Str_s[6], Str_s[5], Str_s[4], "", Str_s[3]
                                        , "", Str_s[8], Str_s[7], "");
                                list_data_flag.add(listData);
                            }
                            list_data = list_data_flag;
                            cloudPagerAdapter = new CloudPagerAdapter(getContext(), list_data);
                            class_show.setAdapter(cloudPagerAdapter);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }

                    @Override
                    public void onError(Throwable ex, boolean isOnCallback) {
                        Log.e("TAG", "onError==" + ex.toString());
                    }

                    @Override
                    public void onCancelled(CancelledException cex) {
                        Log.e("TAG", "onCancelled==" + cex.toString());
                    }

                    @Override
                    public void onFinished() {
                        Log.e("TAG", "onFinished");
                    }
                });
            }
        });
        //listview嵌套问题解决
        class_show.setOnTouchListener((v, event) -> {
            if (event.getAction() == MotionEvent.ACTION_UP) {
                class_show.requestDisallowInterceptTouchEvent(false);
            } else {
                class_show.requestDisallowInterceptTouchEvent(true);
            }
            return false;
        });
        //listview点击事件
        class_show.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                ListData listData_flag = list_data.get(i);
                Intent intent=new Intent();
                intent.putExtra("title",listData_flag.getTitle());
                intent.putExtra("scorenum",listData_flag.getScorenum());
                intent.setClass(view.getContext(), MoviePagerActivity.class);
                startActivity(intent);
                Toast.makeText(view.getContext(),listData_flag.getTitle()+listData_flag.getScorenum(),Toast.LENGTH_LONG).show();
            }
        });
        return view;
    }
    //分类排序搜索
    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        if(group==type_group){
            RadioButton type_button=(RadioButton)view.findViewById(checkedId);
            str_s[0]=type_button.getText().toString();
        }
        if(group==date_group){
            RadioButton type_button=(RadioButton)view.findViewById(checkedId);
            str_s[1]=type_button.getText().toString();
        }
        if(group==area_group){
            RadioButton type_button=(RadioButton)view.findViewById(checkedId);
            str_s[2]=type_button.getText().toString();
        }
        if(group==first_group){
            RadioButton type_button=(RadioButton)view.findViewById(checkedId);
            str_s[3]=type_button.getText().toString();
        }
        num=0;
        str_s[4]=""+num;
        RequestParams params = new RequestParams("http://10.98.16.79:5000/query_tag");
        //params.setMultipart(true);
        params.addBodyParameter("type",str_s[0]);
        params.addBodyParameter("date",str_s[1]);
        params.addBodyParameter("area",str_s[2]);
        params.addBodyParameter("first",str_s[3]);
        params.addBodyParameter("num",str_s[4]);
        //params.addBodyParameter("File",new File(Environment.getExternalStorageDirectory()+"/test_download/YLY.jpg"),null,"YLY.jpg");
        x.http().get(params, new Callback.CacheCallback<String>() {
            List<ListData> list_data_flag=new ArrayList<>();
            @Override
            public boolean onCache(String result) {
                return false;
            }

            @Override
            public void onSuccess(String result) {
                try {
                    JSONObject object=new JSONObject(result);
                    JSONArray array=object.optJSONArray("data");
                    for(int i=0;i<array.length();i++){
//                        map=new HashMap<>();
                        String title=array.getString(i);
                        String[] Str_s;
                        Str_s=title.split(",");
                        String str="";
                        for(int k=0;k<Str_s.length;k++){
                            if(k==0){
                                Str_s[k]=Str_s[k].substring(2,Str_s[k].length()-1);
                            }
                            if(k== Str_s.length-1){
                                Str_s[k]=Str_s[k].substring(1,Str_s[k].length()-2);
                            }
                            if(k!=7&&k!=0&&k!=Str_s.length-1){
                                Str_s[k]=Str_s[k].substring(1,Str_s[k].length()-1);
                            }
                        }
                        listData=new ListData(Str_s[0],Str_s[1],Str_s[2],Str_s[6],Str_s[5],Str_s[4],"",Str_s[3]
                                ,"",Str_s[8],Str_s[7],"");
                        list_data_flag.add(listData);
                    }
                    list_data=list_data_flag;
                    cloudPagerAdapter=new CloudPagerAdapter(getContext(),list_data);
                    class_show.setAdapter(cloudPagerAdapter);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                Log.e("TAG","onError=="+ex.toString());
            }

            @Override
            public void onCancelled(CancelledException cex) {
                Log.e("TAG","onCancelled=="+cex.toString());
            }

            @Override
            public void onFinished() {
                Log.e("TAG","onFinished");
            }
        });
    }
}
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MoviePagerActivity"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <ImageView android:id="@+id/movie_img"
                android:layout_width="150dp"
                android:layout_height="180dp"
                android:src="@mipmap/head3">
            </ImageView>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <TextView android:id="@+id/movie_title"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="百变小樱"
                    android:textSize="20dp"
                    android:textColor="#EEAAFF">
                </TextView>

                <TextView
                    android:id="@+id/movie_score"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="9.9分"
                    android:textColor="#EEAAFF"
                    android:textSize="20dp"></TextView>

                <TextView android:id="@+id/movie_scorenum"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="评价人数:101245"
                    android:textSize="18dp"
                    android:layout_marginTop="5dp"></TextView>


                <TextView android:id="@+id/movie_type"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="类型:喜剧 爱情"
                    android:textSize="18dp"
                    android:layout_marginTop="5dp"></TextView>

                <TextView android:id="@+id/movie_area"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="国家地区:中国大陆"
                    android:textSize="18dp"
                    android:layout_marginTop="5dp"></TextView>

                <TextView android:id="@+id/movie_date"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="上映时间:2021-01-01"
                    android:textSize="18dp"
                    android:layout_marginTop="5dp"></TextView>

                <TextView android:id="@+id/movie_language"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="语言:日语"
                    android:textSize="18dp"
                    android:layout_marginTop="5dp"></TextView>

                <TextView android:id="@+id/movie_timelen"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="时长:126分钟"
                    android:textSize="18dp"
                    android:layout_marginTop="5dp"></TextView>

            </LinearLayout>

        </LinearLayout>

        <TextView android:id="@+id/movie_director"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="导演:大道世知世"
            android:textSize="20dp">
        </TextView>

        <TextView android:id="@+id/movie_star"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="主演:木之本樱 雪兔 小可 小狼 梅玲"
            android:textSize="20dp">
        </TextView>

        <View
            android:id="@+id/div_tab_bar"
            android:layout_width="match_parent"
            android:layout_height="2px"
            android:layout_above="@id/main_group"
            android:background="#EEAAFF" />

        <TextView android:id="@+id/movie_summary"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="简介:
   孙悟空(周星驰)护送唐三藏(罗家英)去西天取经路上,与牛魔王合谋欲杀害唐三藏,并偷走了月光宝盒,此举使观音萌生将其铲除心思,经唐三藏请求,孙悟空被判五百年后重新投胎做人赎其罪孽。

   五百年后孙悟空化身强盗头头至尊宝。当遇见预谋吃唐僧肉的妖怪姐妹蜘蛛精春三十娘(蓝洁瑛)和白骨精白晶晶(莫文蔚)时,因为五百年前孙悟空曾与白晶晶有过一段恋情,至尊宝与她一见钟情,但因菩提老祖将二人妖怪身份相告,至尊宝仍带领众强盗开始与二妖展开周旋,过程中,白晶晶为救至尊宝打伤春三十娘,自己也中毒受伤,为了救白晶晶,至尊宝去找春三十娘,遭白晶晶误会,绝望自杀,至尊宝开始用月光宝盒以期使时光倒流。
 "
            android:textSize="18dp"
            android:layout_marginTop="10dp">
        </TextView>

    </LinearLayout>

</ScrollView>
package com.example.cloudlibrary;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Log;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.cloudlibrary.Adapter.CloudPagerAdapter;
import com.example.cloudlibrary.Data.ListData;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.xutils.common.Callback;
import org.xutils.db.table.TableEntity;
import org.xutils.http.RequestParams;
import org.xutils.x;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

public class MoviePagerActivity extends AppCompatActivity {
    TextView movie_title;
    TextView movie_star;
    TextView movie_director;
    TextView movie_type;
    TextView movie_area;
    TextView movie_date;
    TextView movie_summary;
    TextView movie_score;
    TextView movie_language;
    ImageView movie_img;
    TextView movie_scorenum;
    TextView movie_timelen;

    ListData listData;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_movie_pager);
        movie_title=(TextView)findViewById(R.id.movie_title);
        movie_star=(TextView)findViewById(R.id.movie_star);
        movie_director=(TextView)findViewById(R.id.movie_director);
        movie_type=(TextView)findViewById(R.id.movie_type);
        movie_area=(TextView)findViewById(R.id.movie_area);
        movie_date=(TextView)findViewById(R.id.movie_date);
        movie_summary=(TextView)findViewById(R.id.movie_summary);
        movie_score=(TextView)findViewById(R.id.movie_score);
        movie_language=(TextView)findViewById(R.id.movie_language);
        movie_img=(ImageView)findViewById(R.id.movie_img);
        movie_scorenum=(TextView)findViewById(R.id.movie_scorenum);
        movie_timelen=(TextView)findViewById(R.id.movie_timelen);
        Intent intent=getIntent();
        String movie_title_str=intent.getStringExtra("title");
        String movie_scorenum_str=intent.getStringExtra("scorenum");
        set_movie(movie_title_str,movie_scorenum_str);
    }
    public void set_movie(String title,String scorenum){
        RequestParams params = new RequestParams("http://10.98.16.79:5000/android_query");
        //params.setMultipart(true);
        params.addBodyParameter("title",title);
        params.addBodyParameter("scorenum",scorenum);
        //params.addBodyParameter("File",new File(Environment.getExternalStorageDirectory()+"/test_download/YLY.jpg"),null,"YLY.jpg");
        x.http().get(params, new Callback.CacheCallback<String>() {
            @Override
            public boolean onCache(String result) {
                return false;
            }

            @Override
            public void onSuccess(String result) {
                try {
                    JSONObject object=new JSONObject(result);
                    JSONArray array=object.optJSONArray("data");
                    movie_title.setText(array.getString(0));
                    movie_star.setText("主演:"+array.getString(1));
                    movie_director.setText("导演:"+array.getString(2));
                    movie_type.setText("类型:"+array.getString(3));
                    movie_area.setText("地区:"+array.getString(4));
                    movie_date.setText("上映时间:"+array.getString(5));
                    movie_summary.setText("简介:"+array.getString(6));
                    movie_score.setText(array.getString(7)+"分");
                    movie_language.setText("语言:"+array.getString(8));
                    movie_scorenum.setText("评价人数:"+array.getString(10));
                    movie_timelen.setText("时长:"+array.getString(11));
                    String url=array.getString(9);
                    Bitmap bitmap = getHttpBitmap(url);
                    movie_img.setImageBitmap(bitmap);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                Log.e("TAG","onError=="+ex.toString());
            }

            @Override
            public void onCancelled(CancelledException cex) {
                Log.e("TAG","onCancelled=="+cex.toString());
            }

            @Override
            public void onFinished() {
                Log.e("TAG","onFinished");
            }
        });
    }
    public static Bitmap getHttpBitmap(String url){
        URL myFileURL;
        Bitmap bitmap=null;
        try{
            myFileURL = new URL(url);
            //获得连接
            HttpURLConnection conn=(HttpURLConnection)myFileURL.openConnection();
            Log.e("TAG",conn.toString());
            //设置超时时间为6000毫秒,conn.setConnectionTiem(0);表示没有时间限制
            conn.setConnectTimeout(6000);
            //连接设置获得数据流
            conn.setDoInput(true);
            //设置请求方式
            conn.setRequestMethod("GET");
            //不使用缓存
            conn.setUseCaches(false);
            //响应的状态码
            int code = conn.getResponseCode();
            //这句可有可无,没有影响
            //conn.connect();
            //得到数据流
            InputStream is = conn.getInputStream();
            //解析得到图片
            bitmap = BitmapFactory.decodeStream(is);
            //关闭数据流
            is.close();
        }catch(IOException e){
            e.printStackTrace();
        }
        return bitmap;
    }
}


package com.example.cloudlibrary.Adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.cloudlibrary.Data.ListData;
import com.example.cloudlibrary.R;

import org.w3c.dom.Text;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

public class CloudPagerAdapter extends BaseAdapter {
    private List<ListData> list_data=new ArrayList<>();
    private Context context;
    public CloudPagerAdapter(Context context, List<ListData> list_data){
        this.context=context;
        this.list_data=list_data;
    }
    @Override
    public int getCount() {
        return list_data.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if(convertView==null)
        {
            convertView= LayoutInflater.from(context).inflate(R.layout.first_pager_list,null);
        }
        ImageView first_img=(ImageView)convertView.findViewById(R.id.first_img);
        TextView first_name=(TextView)convertView.findViewById(R.id.first_name);
        TextView first_score=(TextView)convertView.findViewById(R.id.first_score);
        TextView first_star=(TextView)convertView.findViewById(R.id.first_satr);
        TextView first_scorenum=(TextView)convertView.findViewById(R.id.first_scorenum);
        TextView first_director=(TextView)convertView.findViewById(R.id.first_director);
        ListData listData=list_data.get(position);
        first_name.setText(listData.getTitle());
        first_score.setText(listData.getScore()+"分");
        first_director.setText("导演:"+and_so_on(listData.getDirector()));
        first_scorenum.setText(listData.getScorenum()+"人评价");
        first_star.setText("主演:"+and_so_on(listData.getStar()));
        String url=listData.getImg();
        Bitmap bitmap = getHttpBitmap(url);
        first_img.setImageBitmap(bitmap);
        return convertView;
    }

    public static Bitmap getHttpBitmap(String url){
        URL myFileURL;
        Bitmap bitmap=null;
        try{
            myFileURL = new URL(url);
            //获得连接
            HttpURLConnection conn=(HttpURLConnection)myFileURL.openConnection();
            Log.e("TAG",conn.toString());
            //设置超时时间为6000毫秒,conn.setConnectionTiem(0);表示没有时间限制
            conn.setConnectTimeout(6000);
            //连接设置获得数据流
            conn.setDoInput(true);
            //设置请求方式
            conn.setRequestMethod("GET");
            //不使用缓存
            conn.setUseCaches(false);
            //响应的状态码
            int code = conn.getResponseCode();
            //这句可有可无,没有影响
            //conn.connect();
            //得到数据流
            InputStream is = conn.getInputStream();
            //解析得到图片
            bitmap = BitmapFactory.decodeStream(is);
            //关闭数据流
            is.close();
        }catch(IOException e){
            e.printStackTrace();
        }
        return bitmap;
    }
    public String and_so_on(String str){
        if(str.length()>=12){
            str=str.substring(0,11)+"...";
        }
        return str;
    }
}

 

posted @ 2021-05-12 22:03  风吹过半夏  阅读(58)  评论(0)    收藏  举报