团队冲刺阶段二(9)

  对已完成的代码检查并进行优化。

已经完成了大部分的工作,现在要做的就是对代码的检查和修改,发现其中的问题。

工作中的部分代码如下:

public class firstFragment extends Fragment {

private ProgressDialog progressDialog;
private String mContentText;
ImageView img;
TextView text;
String str;
Bitmap bitmap;
Handler handler=new Handler(){
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
byte[] bye=(byte[])msg.obj;
bitmap = ((BitmapDrawable) img.getDrawable()).getBitmap();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);
String str1="";
for(int i=0;i<30;i++){
str1=str1+baos.toByteArray()[i]+"A"+i+"a";
}
text.setText(str1);
bye=baos.toByteArray();
//progressDialog = MaskUtil.firshowProgressDialog("拼命加载中",firstFragment.this);
bitmap=BitmapFactory.decodeByteArray(bye, 0, bye.length);
//text.setText(baos.toByteArray()[0]+"a"+baos.toByteArray()[1]+"b");
img.setImageBitmap(bitmap);
//bitmap=BitmapFactory.decodeResource(getResources(),R.mipmap.dibu);
//contentTv.setText("size:"+L.size());
//img.setImageBitmap(bitmap);
// progressDialog.dismiss();
}
};
public firstFragment(){

}


//联网方法
public void netmethod(){
progressDialog = MaskUtil.firshowProgressDialog("拼命加载中",firstFragment.this);

String path = "";
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url(path)
.get()
.build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
Looper.prepare();
progressDialog.dismiss();
AlertDialog alertDialog = new AlertDialog.Builder(getActivity()).create();
alertDialog.setMessage("网络或服务器原因连接失败");
alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "我知道了", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {

}
});
alertDialog.show();
Looper.loop();
}
@Override
public void onResponse(Call call, Response response) throws IOException {
//progressDialog.dismiss();
//Looper.prepare();
//String result = response.body().string();
byte[] piby=response.body().bytes();

Message mes=handler.obtainMessage();
mes.obj=piby;
handler.sendMessage(mes);
progressDialog.dismiss();
}
});
}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

//getinformation();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View rootView = inflater.inflate(R.layout.activity_first_fragment, container, false);
img=(ImageView)rootView.findViewById(R.id.firimg);
text=rootView.findViewById(R.id.textView2);
//byte[] bytt=
//Bitmap bip=BitmapFactory.decodeByteArray(list.get(0).getTupian(), 0, list.get(0).getTupian().length);


netmethod();

//contentTv.setText("信息:"+L.size());
return rootView;
}
}
原文地址:https://www.cnblogs.com/ruangongwangxiansheng/p/14914725.html