package com.bdyjy.fragment; import java.util.ArrayList; import com.alibaba.fastjson.JSON; import com.bdyjy.R; import com.bdyjy.activity.LocationActivity; import com.bdyjy.activity.MainActivity; import com.bdyjy.constants.HandlerOrder; import com.bdyjy.custom.view.ImageCycleView; import com.bdyjy.custom.view.ImageCycleView.ImageCycleViewListener; import com.bdyjy.entity.campusguide.CampusGuides; import com.bdyjy.entity.campusguide.CampusGuidesContentQueryResultBean; import com.bdyjy.entity.complaint.ComplaintContentQueryResultBean; import com.bdyjy.entity.complaint.Complaints; import com.bdyjy.util.OkHttpUtils; import com.bdyjy.util.SPUtils; import android.R.integer; import android.app.Fragment; import android.content.Intent; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.TextView; import android.widget.Toast; /** * * @author holy У԰ָ�� * */ public class CampusGuideFragment extends Fragment { private TextView tv_back; private MainActivity ctx; private Handler handler; private String toastMsg; private void initHandler() { handler = new Handler() { @Override public void handleMessage(Message msg) { switch (msg.what) { case HandlerOrder.TOAST: // TODO Toast.makeText(ctx, toastMsg, Toast.LENGTH_LONG).show(); break; case HandlerOrder.UPDATE_LISTVIEW: // listView1.onLoad(); // loadData(); break; case HandlerOrder.PROCESSBAR_SHOW: ctx.showRoundProcessDialog(); break; case HandlerOrder.PROCESSBAR_HIDE: ctx.hideRoundProcessDialog(); break; } } }; } public CampusGuideFragment(MainActivity ctx) { this.ctx = ctx; initHandler(); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.campusguide_fragment, null); tv_back = (TextView) view.findViewById(R.id.tv_back); tv_back.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ctx.jumpToLakesideFragment(); } }); //�����а�ť���ü��� OnClickListener clickListener=new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub int type =0; switch (v.getId()) { case R.id.btn_guide1: type=4; Intent intent=new Intent(ctx,LocationActivity.class); startActivity(intent); break; case R.id.btn_guide2: type=2; break; case R.id.btn_guide3: type=1; break; case R.id.btn_guide4: type=5; break; case R.id.btn_guide5: type=6; break; case R.id.btn_guide6: type=3; break; case R.id.btn_guide7: type=7; break; default: break; } if (type!=4) { getContent(type); } //ctx.jumpToCampusGuideContentFragment(); } }; //У������ Button btn_map=(Button)view.findViewById(R.id.btn_guide1); btn_map.setOnClickListener(clickListener); //ס����Ϣ Button btn_recommadation=(Button)view.findViewById(R.id.btn_guide2); btn_recommadation.setOnClickListener(clickListener); //�������� Button btn_catering=(Button)view.findViewById(R.id.btn_guide3); btn_catering.setOnClickListener(clickListener); //��ݷ��� Button btn_express=(Button)view.findViewById(R.id.btn_guide4); btn_express.setOnClickListener(clickListener); //�������� Button btn_exercise=(Button)view.findViewById(R.id.btn_guide5); btn_exercise.setOnClickListener(clickListener); //ҽ�Ʒ��� Button btn_medical=(Button)view.findViewById(R.id.btn_guide6); btn_medical.setOnClickListener(clickListener); //��ͨ��Ϣ Button btn_traffic=(Button)view.findViewById(R.id.btn_guide7); btn_traffic.setOnClickListener(clickListener); initCycleView(view); return view; } // �������װ�Ӻ�̨һ����ȡ���ݵķ��� private void getContent(final int type) { new Thread() { @Override public void run() { // ����get���� String res = null; // ��sharePreference��ȡ��֮ǰ�洢�IJ��� String token = (String) SPUtils.get(ctx, "token", ""); String singnature = (String) SPUtils.get(ctx, "singnature", ""); String st = (String) SPUtils.get(ctx, "st", ""); try { handler.sendEmptyMessage(HandlerOrder.PROCESSBAR_SHOW); res = OkHttpUtils.getInstance().doGet( ctx, "/admin/lifeguide/findByType.do?type="+type + "&token="+ token + "&singnature=" + singnature + "&st=" + st); handler.sendEmptyMessage(HandlerOrder.PROCESSBAR_HIDE); } catch (Exception e) { e.printStackTrace(); toastMsg = "��ȡ����ʧ��"; handler.sendEmptyMessage(HandlerOrder.TOAST); return; } System.out.println(type+"����У԰����ָ�����ݷ��صĽ���ǣ�" + res.trim()); CampusGuidesContentQueryResultBean bean = JSON.parseObject(res, CampusGuidesContentQueryResultBean.class); // System.out.println("xxxx:" + bean.getApp_result_key()); // ����ֵ������JSON��ʽ�����ݣ���Ҫ��������� if (res.trim().length() == 0) { toastMsg = "��ȡ����ʧ��"; handler.sendEmptyMessage(HandlerOrder.TOAST); return; } String app_result_key = bean.getApp_result_key(); if ("0".equals(app_result_key))// ���������������ŵ�����, // ��ô��Ҫ������ȡ�����ŵı��⣬���ݣ���ʾ�ڽ����� { CampusGuides b = bean.getEntity(); MainActivity.campusGuides= b; System.out.println("news:" + b); } ctx.jumpToCampusGuideContentFragment(); } }.start(); } // �ֲ�ͼ��� private ImageCycleView mAdView; private ArrayList<String> mImageUrl = null; private ArrayList<String> mImageTitle = null; private String imageUrl1 = "http://pic.baike.soso.com/p/20131115/20131115144549-353378746.jpg"; private String imageUrl2 = "http://ww1.sinaimg.cn/large/832a46c7jw1dz6cgksg52j.jpg"; private String imageUrl3 = "https://ss1.baidu.com/9vo3dSag_xI4khGko9WTAnF6hhy/news/q=100/sign=32bf684cf203918fd1d139ca613c264b/3b87e950352ac65c41a059dffef2b21192138af0.jpg"; private String imageTitle1 = "����"; private String imageTitle2 = "����"; private String imageTitle3 = "����"; public int stype = 1; /** * ��ʼ���ֲ�ͼ * * @param view */ private void initCycleView(View view) { mImageUrl = new ArrayList<String>(); mImageUrl.add(imageUrl1); mImageUrl.add(imageUrl2); mImageUrl.add(imageUrl3); mImageTitle = new ArrayList<String>(); mImageTitle.add(imageTitle1); mImageTitle.add(imageTitle2); mImageTitle.add(imageTitle3); mAdView = (ImageCycleView) view.findViewById(R.id.ad_view); mAdView.setImageResources(mImageUrl, mImageTitle, mAdCycleViewListener, stype); } private ImageCycleViewListener mAdCycleViewListener = new ImageCycleViewListener() { @Override public void onImageClick(int position, View imageView) { // Toast.makeText(ctx, mImageUrl.get(position) + position, 1).show(); } }; }