listview上拉加载,和显示地图mark

package baoxiu.weixiushang.mydingdan;
 
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
 
import org.json.JSONArray;
import org.json.JSONObject;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
 
public class AlreadyAcc extends Activity implements OnScrollListener{
  
    PopupWindow pop;
    //pop里面的数据
    String pop_name, pop_guzhang, pop_address ;
    
    private BaiduMap mBaiduMap;//百度地图实例
      //定位相关
      LocationClient  mLocationClient;//定位客户端
      MyLocationListener mMyLocationListener;//定位监听器
      private volatile boolean isFristLocation = true; //是否是第一次定位
      private LocationMode mCurrentMode = LocationMode.NORMAL;//当前定位的模式
      private float mCurrentAccracy; //当前精度
      //最新一次的经纬度
      private double mCurrentLantitude;
      private double mCurrentLongitude;
      private int visibleLastIndex = 0;
     private DialogLoading   mPLoading;
    int int_page;
    int count;
    String what="";
     private int y = 0;
    private String u = null;
    private String p = null;
    private String str_server_url=Config.STR_SERVICE_URL;
    public Handler itemHandler;
     private  Common   common;
        private AppContext appContext;
        BitmapDescriptor bitmap;
     List<AlreadyAccData>data_listover=new ArrayList<AlreadyAccData>();
     List<AlreadyAccData>data_list=new ArrayList<AlreadyAccData>();
     AlreadyAccAdapter madapter;
     @ViewInject(R.id.relative_daohang)  private RelativeLayout  relative_daohang;//导航框
     @ViewInject(R.id.tv_mine_add)  private TextView tv_mine_add;//地址
     @ViewInject(R.id.tv_sum_add)  private TextView tv_sum_add;//距离
     @ViewInject(R.id.tv_dao)   private TextView tv_dao;//到这里去
     @ViewInject(R.id.tv_daoh)   private TextView  tv_daoh;//导航
     @ViewInject(R.id.tv_nothing)
     private TextView tv_nothing;
     @ViewInject(R.id.lv_list_md)
     private ListView lv_list_md;
    @ViewInject(R.id.all_list)
    private RadioButton all_list;
    @ViewInject(R.id.all_map)
    private RadioButton all_map;
    @ViewInject(R.id.all_list_item)//全部
    private RadioButton  all_list_item;
    @ViewInject(R.id.all_list_item_m)  private RadioButton all_list_item_m;
    @ViewInject(R.id.success_list_item)//成功
    private RadioButton  success_list_item;
    @ViewInject(R.id.success_list_item_m)  private RadioButton success_list_item_m;
    @ViewInject(R.id.fail_list_item)//失败
    private RadioButton  fail_list_item;
    @ViewInject(R.id.fail_list_item_m)     private RadioButton fail_list_item_m;
    @ViewInject(R.id.delay_list_item)//处理中
    private RadioButton delay_list_item;
    @ViewInject(R.id.btn_uploads)  private Button btn_uploads;//上传订单
    @ViewInject(R.id.delay_list_item_m)  private RadioButton delay_list_item_m;
    @ViewInject(R.id.bmapView) private MapView mMapView;
    @ViewInject(R.id.lin_map_show) private LinearLayout lin_map_show;
    @ViewInject(R.id.lin_list_show)    private LinearLayout lin_list_show;
    
    @OnClick({R.id.all_list,R.id.all_map,R.id.all_list_item,R.id.success_list_item,R.id.all_list_item_m,R.id.success_list_item_m,
        R.id.btn_back_history,R.id.fail_list_item,R.id.delay_list_item,R.id.fail_list_item_m,R.id.delay_list_item_m,R.id.btn_uploads})
    public void oncl(View v){
        if(panduan()==false){
            return;
        }
        switch (v.getId()) {
        case R.id.btn_uploads:
            Intent i=new Intent(this,ChoiceTimeActivity.class);
            startActivity(i);
            finish();
            break;
        case R.id.btn_back_history:
            finish();
            break;
        case R.id.all_list://全部列表
            lin_map_show.setVisibility(View.GONE);
            lin_list_show.setVisibility(View.VISIBLE);
            
            break;
        case R.id.all_map://地图显示
            lin_map_show.setVisibility(View.VISIBLE);
            lin_list_show.setVisibility(View.GONE);
            all_list_item_m.performClick();
            break;
                
        case R.id.all_list_item://全部
            //all_list_item.setTextColor(this.getResources().getColor(R.drawable.word_color));
             initDo();
             what="/type/all";
             bitmap = BitmapDescriptorFactory.fromResource(R.drawable.i46);  
            show_all_list();
             break;
        case R.id.all_list_item_m:
             initDo();
             what="/type/all";
              bitmap = BitmapDescriptorFactory.fromResource(R.drawable.i46);  
            show_all_list();
            break;
        case R.id.success_list_item://成功
            initDo();
            what="/type/success";
            bitmap = BitmapDescriptorFactory.fromResource(R.drawable.i46);
            show_all_list();
            break;
        case R.id.success_list_item_m:
            initDo();
            what="/type/success";
            
            bitmap = BitmapDescriptorFactory.fromResource(R.drawable.i46);
            show_all_list();
            break;
        case R.id.fail_list_item://失败
            initDo();
            what="/type/failed";
            bitmap = BitmapDescriptorFactory.fromResource(R.drawable.i47);
            show_all_list();
            break;
        case R.id.fail_list_item_m:
            initDo();
            what="/type/failed";
            bitmap = BitmapDescriptorFactory.fromResource(R.drawable.i47);
            show_all_list();
            break;
        case R.id.delay_list_item://处理中
            initDo();
            what="/type/processing";
            bitmap = BitmapDescriptorFactory.fromResource(R.drawable.i41);
            show_all_list();
            break;
        case R.id.delay_list_item_m:
            initDo();
            what="/type/processing";
            bitmap = BitmapDescriptorFactory.fromResource(R.drawable.i41);
            show_all_list();
            break;
        default:
            break;
        }
        
    }
      private  void  initDo(){
            int_page=1;
            data_listover.clear();
        }
     private   Boolean   panduan(){  
          if (!appContext.isNetworkConnected()){
                Toast.makeText(AlreadyAcc.this, "加载失败,请检查网络设置", Toast.LENGTH_SHORT).show();
                return     false;
          }
          return  true;
         }
    Handler mHandler = new Handler() {
        public void handleMessage(Message msg) {
            mPLoading.dismiss();
            JSONObject joReturn =  null;
            JSONArray jaInfo       = null;
            JSONObject Info =  null;
            AlreadyAccData  data;
            int status=0;
            String time="0";
            String str="0";
                try {
                    joReturn  = new JSONObject(msg.obj.toString());
                    status = joReturn.getInt("status");
                    mBaiduMap.clear();
                    if(status == 1){
                        lv_list_md.setVisibility(View.VISIBLE);
                         tv_nothing.setVisibility(View.GONE);
                         jaInfo = new JSONArray( joReturn.getString("info"));
                         data_list.clear();
                          
                        count=   jaInfo.length();
                         for( int  i = 0; i<jaInfo.length();i++){
                             Info =  new JSONObject(jaInfo.getString(i)) ;
                              
                             if( Info.getString("status").equals("已完成")){//维修成功
                                 bitmap = BitmapDescriptorFactory.fromResource(R.drawable.i46);  
                             }else if(!Info.getString("is_liubiao").equals("0")){//流标不等于0就是失败
                                 bitmap = BitmapDescriptorFactory.fromResource(R.drawable.i47);  
                             }else {//剩下的是处理中
                                 bitmap = BitmapDescriptorFactory.fromResource(R.drawable.i41);  
                             }
                              
                            //把这个时间处理下再显示,如果时间是0,则返回0,如果是秒数,则转换成时间格式显示
                             if(Info.getString("reserve").equals("0")){
                                 time="0";
                             }else{
                                 long yuyue_time =  Long.parseLong( Info.getString("reserve"))*1000;
                                 SimpleDateFormat times=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                                 time= times.format(yuyue_time);
                                 str=time.substring(0, 16);
                             }
                        
                           data=new AlreadyAccData(
                                   Info.getString("order_id"),//order_id
                                   Info.getString("status"),//状态
                                   Info.getString("id"), //订单编号
                                   Info.getString("add_time"),//报修时间
                                   Info.getString("product_name"), //报修产品
                                   Info.getString("fault_detail"), //故障描述
                                   Info.getString("address"),//地址
                                   Info.getString("special_requests"),//特别提醒
                                   str,//预约时间
                                   Info.getString("real_name"), //报修用户
                                   Info.getString("phone"),//联系电话
                                   Info.getString("is_prepaid"),//预付金额                                           
                                   ""//是否可接
                                  );
                             data_list.add(data );
                             if(!Info.getString("u_lat").equals("")){
                              
                                 Marker marker=null;
                             LatLng point = new LatLng( Info.getDouble("u_lat"),Info.getDouble("u_lng"));    
                              //构建MarkerOption,用于在地图上添加Marker
                                 OverlayOptions option = new MarkerOptions() .position(point)   .icon(bitmap);  
                              //在地图上添加Marker,并显示   
                               
                              marker = (Marker) (mBaiduMap.addOverlay(option));   
                                Bundle bundle = new Bundle();   
                                bundle.putSerializable("product_name", Info.getString("product_name"));   
                                bundle.putSerializable("fault_detail", Info.getString("fault_detail"));
                                bundle.putSerializable("address", Info.getString("address"));
                                bundle.putSerializable("order_id", Info.getString("order_id"));
                                bundle.putSerializable("repair_id", Info.getString("id"));
                                marker.setExtraInfo(bundle);   
                             }else{
                                  
                             }
                
                     }
                         data_listover.addAll(data_list);
                         if(madapter!=null){
                             madapter.notifyDataSetChanged();
                         }
                         if(data_listover.size()==0){
                             Toast.makeText(AlreadyAcc.this, "加载失败,请检查网络设置", Toast.LENGTH_SHORT).show();
                             lv_list_md.setVisibility(View.GONE);
                             tv_nothing.setVisibility(View.VISIBLE);
                             return;
                         }
                        madapter=new AlreadyAccAdapter(AlreadyAcc.this, R.layout.listitem_completed_order,data_listover);
                        lv_list_md.setAdapter(madapter);
                        lv_list_md.setSelection(y);
                    }else{
                        if(data_listover.size()>0){
                            Toast.makeText(AlreadyAcc.this,joReturn.getString("info"), Toast.LENGTH_SHORT).show();
                        }else{
                            lv_list_md.setVisibility(View.GONE);
                            tv_nothing.setVisibility(View.VISIBLE);}
                    }
                } catch (Exception e) {
                    e.printStackTrace();查看错误是什么。。。
                    Toast.makeText(AlreadyAcc.this,"出错啦-_-!", Toast.LENGTH_SHORT).show();
                }
            
        }
        
    };
    private   void    getUserandpass(){
         SharedPreferences MAP_LOGIN = getSharedPreferences(Config.STR_SHARED_TAG, 0);
         u = MAP_LOGIN.getString(Config.STR_SHARED_USER_NAME, "");  
         p    = MAP_LOGIN.getString(Config.STR_SHARED_PASSWORD, "");  
    }
    protected void onStart(){
        super.onStart();  
        // 开启图层定位
        mBaiduMap.setMyLocationEnabled(true);
        if (!mLocationClient.isStarted()){
            mLocationClient.start();
        }
        if(mPLoading==null){
        mPLoading=new DialogLoading(AlreadyAcc.this);}
 
    }
    @Override
    protected void onStop()
    {
        // 关闭图层定位
        mBaiduMap.setMyLocationEnabled(false);
        mLocationClient.stop();
 
        super.onStop();
    }
    @Override   
    protected void onDestroy()   
    {   
        super.onDestroy();   
        // 在activity执行onDestroy时执行mMapView.onDestroy(),实现地图生命周期管理   
        mMapView.onDestroy();   
        mMapView = null;   
    }   
   
    @Override   
    protected void onResume()   
    {   
        super.onResume();   
        // 在activity执行onResume时执行mMapView. onResume (),实现地图生命周期管理   
        mMapView.onResume();   
    }   
   
    @Override   
    protected void onPause()   
    {   
        super.onPause();   
        // 在activity执行onPause时执行mMapView. onPause (),实现地图生命周期管理   
        mMapView.onPause();   
    }   
     
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        SDKInitializer.initialize(getApplication());
        setContentView(R.layout.md_alreadyacc);
        ViewUtils.inject(this);
         getUserandpass();
        appContext = (AppContext)AlreadyAcc.this.getApplication();
        mPLoading=new DialogLoading(AlreadyAcc.this);
        lv_list_md.setOnScrollListener(AlreadyAcc.this);
        all_list.performClick();
        delay_list_item.performClick();
        common=new  Common();
        
        isFristLocation=true;//第一次定位
        //获取地图实例
        mBaiduMap=mMapView.getMap();
        mMapView.removeViewAt(1);
        MapStatusUpdate msu= MapStatusUpdateFactory.zoomTo(11.5f);
        mBaiduMap.setMapStatus(msu);
        //初始化定位
        myLocation();
        
        lv_list_md.setOnItemClickListener(new OnItemClickListener() {
 
            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                    long arg3) {
                
                String repair_id=data_listover.get(Integer.valueOf(arg2)).dd_no;
                String order_id=data_listover.get(Integer.valueOf(arg2)).dd_orderid;
                 Intent intent = new Intent(AlreadyAcc.this,OrderDwActivity.class);
                intent.putExtra("repair_id", repair_id);
                intent.putExtra("user_name", u);
                intent.putExtra("password", p);
                intent.putExtra("order_id", order_id);
                startActivity(intent);
            
            }
        });
        
        mBaiduMap.setOnMarkerClickListener(new OnMarkerClickListener() {
            
            @Override
            public boolean onMarkerClick(Marker oMarker) {
                
                LatLng     pt;
                
                final String pop_order_id,pop_repair_id;
                Bundle mBundle = oMarker.getExtraInfo();
                pop_name=mBundle.getString("product_name");
                pop_guzhang=mBundle.getString("fault_detail");
                pop_address=mBundle.getString("address");
                pop_order_id=mBundle.getString("order_id");
                pop_repair_id=mBundle.getString("repair_id");
        
                   pt = new LatLng(oMarker.getPosition().latitude, oMarker.getPosition().longitude);
                   View view =  LayoutInflater.from(AlreadyAcc.this).inflate(R.layout.map_infowindow, null);
                 
                   TextView tv_name = (TextView) view.findViewById(R.id.tv_info_name);
                TextView tv_guzhang=(TextView) view.findViewById(R.id.tv_info_fail);
                TextView tv_address=(TextView) view.findViewById(R.id.tv_info_address);
                 TextView btn_yes=(TextView) view.findViewById(R.id.tv_info_xiangqing);
                 TextView btn_no=(TextView) view.findViewById(R.id.tv_info_dismiss);
                tv_name.setText("报修产品:"+pop_name);
                tv_guzhang.setText("产品故障:"+pop_guzhang);
                tv_address.setText("报修地址:"+pop_address);
              
            // 创建InfoWindow
            InfoWindow mInfoWindow = new InfoWindow(view, pt, 240);
            mBaiduMap.showInfoWindow(mInfoWindow); //显示气泡
            btn_no.setOnClickListener(new OnClickListener() {
                
                @Override
                public void onClick(View arg0) {
                    mBaiduMap.hideInfoWindow();
                    relative_daohang.setVisibility(View.GONE);
                }
            });
            btn_yes.setOnClickListener(new OnClickListener() {
                
                @Override
                public void onClick(View arg0) {
                    Intent i=new Intent(AlreadyAcc.this,OrderDwActivity.class);
                    i.putExtra("user_name", u);
                    i.putExtra("password", p);
                    i.putExtra("repair_id", pop_repair_id);
                    i.putExtra("order_id", pop_order_id);
                    startActivity(i);
                }
            });
            
            relative_daohang.setVisibility(View.VISIBLE);
            tv_mine_add.setText(pop_address);//地址
            tv_sum_add.setText("230m");//距离
            tv_dao.setOnClickListener(new OnClickListener() {
                
                @Override
                public void onClick(View arg0) {
                    Intent i=new Intent(AlreadyAcc.this,InfoWayActivity.class);
                //    i.putExtra("add_sta", value);
                    i.putExtra("add_end", pop_address);
                    startActivity(i);
                }
            });
            tv_daoh.setOnClickListener(new OnClickListener() {
                
                @Override
                public void onClick(View arg0) {
                    Intent i=new Intent(AlreadyAcc.this,InfoWayActivity.class);
            //        i.putExtra("add_sta", value);
                    i.putExtra("add_end", pop_address);
                    startActivity(i);
                }
            });
    
                return false;
            }
 
        });
        
    }
    
    //定位初始化相关
        private void myLocation() {
            mLocationClient=new LocationClient(this);
            mMyLocationListener=new MyLocationListener();
            mLocationClient.registerLocationListener(mMyLocationListener);
            // 设置定位的相关配置
            LocationClientOption option = new LocationClientOption();
            option.setOpenGps(true);// 打开gps
            option.setCoorType("bd09ll"); // 设置坐标类型
            option.setScanSpan(1000);
            mLocationClient.setLocOption(option);
            
        }
    
        
    //所有的已接单子列表显示
    private void show_all_list(){
        mPLoading.show();
           new Thread(){
               Message msg = new Message();
              public void run() {
                    String t=String.valueOf(System.currentTimeMillis()).substring(0,10);
                    
                    String str_url=str_server_url+"AppApi/"+"getdata/"+"client_type/android"+
                            "/t/"+t+"/u/"+u+"/q/"+common.toSign(u, p, t)+"/p/"+int_page+what;
                    HttpUtils http_get = new HttpUtils();
                    
                    http_get.send(HttpMethod.GET, str_url, new RequestCallBack<String>() {
                        
                         @Override
                            public void onLoading(long total, long current, boolean isUploading) {
                            }
                        @Override
                        public void onFailure(HttpException arg0, String arg1) {
                            mPLoading.dismiss();
                             Toast.makeText(AlreadyAcc.this, "加载失败,请检查网络设置", Toast.LENGTH_SHORT).show();
                        }
                        @SuppressLint("NewApi")
                        @Override
                        public void onSuccess(ResponseInfo<String> arg0) {
                            try {
                                JSONObject jo = Common.toJSONObject(arg0.result);
                                if(jo.getString("status").equals("1")){
                                    msg.obj=jo;
                                }else{
                                    msg.obj=jo;
                                }
                                
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                            mHandler.sendMessage(msg);
                        }
                    });
              };
           }.start();
    
     }
    @Override
    public void onScroll(AbsListView arg0, int arg1, int arg2, int arg3) {
        visibleLastIndex = arg1 + arg2 - 1;
          y = lv_list_md.getFirstVisiblePosition();  
    }
    @Override
    public void onScrollStateChanged(AbsListView view, int scrollState) {
        int itemsLastIndex = madapter.getCount() - 1;  
        if (scrollState == OnScrollListener.SCROLL_STATE_IDLE
                && visibleLastIndex == itemsLastIndex) {
            
            if(all_list_item.isChecked()){
                int_page++;
                what="/type/all";
                show_all_list();    
            }/*else if(all_list_item.isChecked()){
                int_page++;
                what="/type/all";
                show_all_list();
            }*/else if(success_list_item.isChecked()){
                int_page++;
                what="/type/success";
                show_all_list();
            }else if(fail_list_item.isChecked()){
                int_page++;
                what="/type/failed";
                show_all_list();
            }else if(delay_list_item.isChecked()){
                int_page++;
                what="/type/processing";
                show_all_list();
            }
            

        }
    }
    private class MyLocationListener implements BDLocationListener{
        @Override
        public void onReceiveLocation(BDLocation location)
        {
            // map view 销毁后不在处理新接收的位置
            if (location == null || mMapView == null)
                return;
            
            // 构造定位数据
            MyLocationData locData = new MyLocationData.Builder().accuracy(location.getRadius())
                    // 此处设置开发者获取到的方向信息,顺时针0-360
                    .latitude(location.getLatitude())
                    .longitude(location.getLongitude()).build();
            mCurrentAccracy = location.getRadius();
            // 设置定位数据
            mBaiduMap.setMyLocationData(locData);
            mCurrentLantitude = location.getLatitude();
            mCurrentLongitude = location.getLongitude();
            // 设置自定义图标
            BitmapDescriptor mCurrentMarker = BitmapDescriptorFactory
                    .fromResource(R.drawable.ic_launcher);
            MyLocationConfiguration config = new MyLocationConfiguration(
                    mCurrentMode, true, mCurrentMarker);
        //    mBaiduMap.setMyLocationConfigeration(config);
            // 第一次定位时,将地图位置移动到当前位置
            if (isFristLocation)
            {
                isFristLocation = false;
                LatLng ll = new LatLng(location.getLatitude(),
                        location.getLongitude());
                MapStatusUpdate u = MapStatusUpdateFactory.newLatLng(ll);
                mBaiduMap.animateMapStatus(u);
            }
        }
 
    }
 
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值