android volley
实战 QQ demo源码(本例中有该应用)
服务器端下载:http://download.csdn.net/download/knight_black_bob/9822551
android eclipse 版:http://download.csdn.net/download/knight_black_bob/9822553
android stdio 版本:http://download.csdn.net/download/knight_black_bob/9822556
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 ; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); testView = (ImageView) this.findViewById(R.id.testView); /* IResquest req = new IResquest() { @Override public 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 block e.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>() { @Override public 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() { @Override public 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>() { @Override public void onResponse(QueryResultJson response) { JsonElement obj = response.retdata; if (obj != null) { /*{id=1.40115571E9, name=baoy, nickName=呵呵, password=15155150208, [email protected], 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() { @Override public 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); //get String url2 = "http://localhost:8080/RepositoryPic/WebService/rest/friendShip/friendShips/1401155710"; GsonRequest<QueryResultJson> gsonRequest2 = new GsonRequest<QueryResultJson>(url, QueryResultJson.class, new Response.Listener<QueryResultJson>() { @Override public void onResponse(QueryResultJson response) { System.out.println("baoyou" + response.toString()); Log.i("baoyou",response.toString()); Log.e("baoyou",response.retdata.toString()); } }, new Response.ErrorListener() { @Override public 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); } }
相关推荐
lolafon 2015-04-18
狂草 2015-12-31
俊光 2018-08-10
scuzoutao 2015-04-02
Garment 2019-06-21
OliverLau 2019-06-21
SnailDream 2019-06-21
newtrekWang 2019-06-20
scuzoutao 2019-06-20
狂草 2019-06-20
doomvsjing 2019-06-11
hh000 2017-04-10
scuzoutao 2017-03-30
狂草 2016-09-12
JewelCCL 2016-08-10
Garment 2016-08-10
magic00 2016-08-10
SnailDream 2016-03-21
SnailDream 2016-03-08