android volley_第1张图片

package com.example.demonetworkandimagecache; import java.util.HashMap;import java.util.Map;import org.json.JSONObject;import android.app.Activity;import android.content.res.Resources;import android.graphics.Bitmap;import android.graphics.BitmapFactory;import android.os.Bundle;import android.util.Log;import android.widget.ImageView;import com.android.volley.Request.Method;import com.android.volley.Response;import com.android.volley.VolleyError;import com.android.volley.toolbox.Volley; import com.example.demonetworkandimagecache.util.GsonRequest;import com.example.demonetworkandimagecache.util.ImageCacheManager;import com.google.gson.JsonElement;public class MainActivity extends Activity {ImageView testView ;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);testView = (ImageView) this.findViewById(R.id.testView);/* IResquest req = new IResquest() {@Overridepublic void handler(String result) {try {JSONObject json = new JSONObject(result);String img =  (String) json.get("link");ImageCacheManager.loadImage(img, testView, getBitmapFromRes(R.drawable.ic_launcher), getBitmapFromRes(R.drawable.ic_launcher));} catch (JSONException e) {// TODO Auto-generated catch blocke.printStackTrace();} }};new RequestManager(req).stringRequestWithGet(url,new HashMap<String, String>()); *///String url = "http://10.2.6.60:8080/RepositoryPic/WebService/rest/user/login";/*GsonRequest<PicRepository> gsonRequest = new GsonRequest<PicRepository>(url, PicRepository.class,new Response.Listener<PicRepository>() {@Overridepublic void onResponse(PicRepository response) {System.out.println("baoyou" + response.toString());Log.i("baoyou",response.toString());String img = response.getLink();ImageCacheManager.loadImage(img, testView, getBitmapFromRes(R.drawable.ic_launcher), getBitmapFromRes(R.drawable.ic_launcher));}}, new Response.ErrorListener() {@Overridepublic void onErrorResponse(VolleyError error) {Log.e("baoyou",error.getMessage());}});Volley.newRequestQueue(MyApplication.newInstance()).add(gsonRequest); *///post String url = "http://10.2.6.60:8080/RepositoryPic/WebService/rest/user/login"; HashMap<String, String> map = new HashMap<String, String>();map.put("userId", "1401155710");map.put("userPassword", "15155150208");  JSONObject jsonObject = new JSONObject(map);GsonRequest<QueryResultJson> gsonRequest = new GsonRequest<QueryResultJson>(Method.POST ,url, QueryResultJson.class, jsonObject.toString(),new Response.Listener<QueryResultJson>() {@Overridepublic void onResponse(QueryResultJson response) {JsonElement  obj =response.retdata;  if (obj != null) {    /*{id=1.40115571E9, name=baoy,  nickName=呵呵, password=15155150208, mail=15155150208@163.com,  telphone=15155150208,  photo=http://10.2.6.60/users/1401155710/pics/1.png,     insertTime=2016-04-18, lastUpdateTime=2016-04-15}*/  Log.e("baoyou", obj.toString());UserEntity  user = JsonParser.parseDateJson( obj.toString() , UserEntity.class);Log.e("baoyou", user.toString()); } }}, new Response.ErrorListener() {@Overridepublic void onErrorResponse(VolleyError error) {Log.e("baoyou", error.getMessage());}}) /*{protected Map<String, String> getParams() {HashMap<String, String> map = new HashMap<String, String>();map.put("userName", "baoy");map.put("userPassword", "15155150208");return map;}}*/;Volley.newRequestQueue(MyApplication.newInstance()).add(gsonRequest); //getString url2 = "http://localhost:8080/RepositoryPic/WebService/rest/friendShip/friendShips/1401155710";GsonRequest<QueryResultJson> gsonRequest2 = new GsonRequest<QueryResultJson>(url, QueryResultJson.class,new Response.Listener<QueryResultJson>() {@Overridepublic void onResponse(QueryResultJson response) {System.out.println("baoyou" + response.toString());Log.i("baoyou",response.toString());Log.e("baoyou",response.retdata.toString()); }}, new Response.ErrorListener() {@Overridepublic void onErrorResponse(VolleyError error) {Log.e("baoyou",error.getMessage());}});Volley.newRequestQueue(MyApplication.newInstance()).add(gsonRequest);} public Bitmap getBitmapFromRes(int resId) {          Resources res = this.getResources();         return BitmapFactory.decodeResource(res, resId);       } }

更多相关文章

  1. android 图片背景使用这种方式很爽
  2. android获得圆角图片
  3. Android在Button按钮上同时显示文字和图片
  4. android ViewFlipper实现图片轮播
  5. Android如何使用XML创建一个环形渐变颜色图片
  6. Android 旋转图片
  7. Android 获取网络图片
  8. Android 图片加载缓存
  9. Android 系统图片

随机推荐

  1. 将项目从Eclipse转到Android Studio
  2. Android消息机制(Handler原理)
  3. Android消息推送(二)--基于MQTT协议实现
  4. android的手势识别例子
  5. App-Launcher-Cordova-Plugin运行已经安
  6. Android 学习笔记4---签名Android的执行
  7. android:限制文本长度加省略号用ellipsize
  8. Android用户界面开发(9):日期和时间
  9. Android - This Handler class should be
  10. Android入门篇四:使用剪切板在Activity之