从网络获取图片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();
}
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。