码迷,mamicode.com
首页 > Web开发 > 详细

从网络获取图片JSON链接本地轮流播放

时间:2014-09-05 14:34:02      阅读:274      评论:0      收藏:0      [点我收藏+]

标签:服务器   图片   json   轮流播放   

private List<Map<String, String>> mlist;

private FinalBitmap fb;


初始化,准备请求服务器

public void initttq() {

mlist = new ArrayList<Map<String, String>>();

StringBuffer urlSb = new StringBuffer();

urlSb.append(getResources().getString(R.string.str_bcpservice_ip))

.append(":")

.append(getResources().getString(R.string.str_bcpservice_port))

.append("/mobileInterface/forum/note/home");

executeRequest(new JsonObjectRequest(Method.POST, urlSb.toString(),

getttqinfo(), ttqHomeResponseListener(), errorListener()));

}


提交请求数据

public JSONObject getttqinfo() {

JSONObject jsonObject = new JSONObject();

try {

jsonObject.put("smallCommunityCode", smallcommunitycode);

jsonObject.put("mobile", regeditmobile);

jsonObject.put("token", token);

jsonObject.put("recordNum", "3");

return jsonObject;

} catch (Exception ex) {

ex.printStackTrace();

}

return null;

}


监听服务器响应

private Response.Listener<JSONObject> ttqHomeResponseListener() {

return new Response.Listener<JSONObject>() {

@Override

public void onResponse(JSONObject jsonobject) {

try {

System.out.println(jsonobject.toString());

JSONArray jsonarr = jsonobject.getJSONArray("list");

for (int i = 0; i < jsonarr.length(); i++) {

JSONObject jsonObj = jsonarr.getJSONObject(i);

final Map<String, String> map = new HashMap<String, String>();

Iterator it = jsonObj.keys();

while (it.hasNext()) {

String key = it.next();

String value = jsonObj.getString(key);

map.put(key, value);

}

mlist.add(map);

fb = FinalBitmap.create(getActivity());

fb.configLoadingImage(R.drawable.ic_launcher);

fb.configBitmapLoadThreadSize(5);

final ViewFlipper viewFlipper = (ViewFlipper) view

.findViewById(R.id.viewflipper);

try {

for (int j = 0; j < jsonObj.length(); j++) {

ImageView img = new ImageView(getActivity());

fb.display(img, mlist.get(j).get("titlePicPath").toString());

viewFlipper.addView(img);

initadvertising(viewFlipper);

}

} catch (Exception ex) {

ex.printStackTrace();

}

}

initTtqViewFlliper();

} catch (Exception ex) {

ex.printStackTrace();

}

}

};

}


执行自动播放

private void initadvertising(final ViewFlipper viewFlipper) {

viewFlipper.setAutoStart(true); // 设置自动播放功能(点击事件,前自动播放)

viewFlipper.setFlipInterval(2000);

if (viewFlipper.isAutoStart() && !viewFlipper.isFlipping()) {

viewFlipper.startFlipping();

Animation lInAnim = AnimationUtils.loadAnimation(getActivity(),

R.anim.push_left_in); // 向左滑动左侧进入的渐变效果(alpha 0.1 -> 1.0)

Animation lOutAnim = AnimationUtils.loadAnimation(getActivity(),

R.anim.push_left_out); // 向左滑动右侧滑出的渐变效果(alpha 1.0 -> 0.1)


viewFlipper.setInAnimation(lInAnim);

viewFlipper.setOutAnimation(lOutAnim);

viewFlipper.setDisplayedChild(3);

viewFlipper.showNext();

}


从网络获取图片JSON链接本地轮流播放

标签:服务器   图片   json   轮流播放   

原文地址:http://4384137.blog.51cto.com/4374137/1549033

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!