Android Open Source - qshuttle_driver Activity Offline Map






From Project

Back to project page qshuttle_driver.

License

The source code is released under:

MIT License

If you think the Android project qshuttle_driver listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/**
 * /*from   ww  w.j a  v  a 2 s . c o m*/
 */
package com.qshuttle.car;

import java.util.ArrayList;
import java.util.Iterator;

import com.amap.mapapi.map.MapActivity;
import com.amap.mapapi.offlinemap.City;
import com.amap.mapapi.offlinemap.MOfflineMapStatus;
import com.amap.mapapi.offlinemap.OfflineMapManager;
import com.amap.mapapi.offlinemap.OfflineMapManager.OfflineMapDownloadListener;


import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.Toast;

/**
 * @author wangpeifeng
 *
 */
public class ActivityOfflineMap extends MapActivity implements OfflineMapDownloadListener{
  
  private ArrayList<City> listCity ,listDownloading;
  
  private ArrayList<String> listDownloadingCity;
  
  private ListView listView;
  
  private ListAdapter listAdapter;
  
  public OfflineMapManager mapManager;

  /* (non-Javadoc)
   * @see android.app.Activity#onCreate(android.os.Bundle)
   */
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    
    mapManager = new OfflineMapManager(this,this);
    
    Context context = getApplicationContext();

    listCity = mapManager.getOfflineCityList();
    
    if(listCity != null && listCity.size() > 0){
    
      setContentView(R.layout.citylist);
    
      listView = (ListView)findViewById(R.id.listView);
    
      listDownloadingCity = new ArrayList<String>();

      getDownloadingCity();
    
      listAdapter = new ListAdapter(listCity, listDownloadingCity, this);
    
      listView.setAdapter(listAdapter);
    
      listView.setOnItemClickListener(listener);
    
      ((ImageButton)findViewById(R.id.imageButtonBack)).setOnClickListener(lsrButton);
    
    }
    
    else{

      Toast.makeText(context, R.string.address_list_null, Toast.LENGTH_LONG).show();
      
      finish();
      
    }
  }

  
  /* (non-Javadoc)
   * @see com.amap.mapapi.map.MapActivity#onDestroy()
   */
  @Override
  protected void onDestroy() {
    // TODO Auto-generated method stub
    try{
      
//      mapManager.stop();
      
    }
    catch(Exception e){
      e.printStackTrace();
    }
    super.onDestroy();
  }

  public OnClickListener lsrButton = new OnClickListener(){

    public void onClick(View v) {
      // TODO Auto-generated method stub
      
      finish();
      
    }
    
  };

  public OnItemClickListener listener = new OnItemClickListener(){

    /* (non-Javadoc)
     * @see android.widget.AdapterView.OnItemClickListener#onItemClick(android.widget.AdapterView, android.view.View, int, long)
     */
    public void onItemClick(AdapterView<?> arg0, View view, int position,
        long id) {
      // TODO Auto-generated method stub
      
      mapManager.downloadByCityName(listCity.get(position).getCity());
      
      getDownloadingCity();
      
      listAdapter.notifyDataSetChanged();
           
      listView.invalidate();
      

    }

    
    
  
  };
  
  public void onDownload(int status, int completeCode) {
    // TODO Auto-generated method stub
    switch(status)
    {
    case MOfflineMapStatus.LOADING:
      Toast.makeText(this,
          getApplicationContext().getResources().getString(R.string.map_downloading) + completeCode+"%",
          Toast.LENGTH_SHORT).show();
      break;
    
    case MOfflineMapStatus.ERROR:
      Toast.makeText(this,
          R.string.map_download_error,
          Toast.LENGTH_SHORT).show();
      break;
    
    case MOfflineMapStatus.PAUSE:
      Toast.makeText(this,
          R.string.map_download_pause,
          Toast.LENGTH_SHORT).show();
      break;
    
    case MOfflineMapStatus.STOP:
      Toast.makeText(this,
          R.string.map_download_stop,
          Toast.LENGTH_SHORT).show();
      break;

    case MOfflineMapStatus.SUCCESS:
      
      Toast.makeText(this,
          R.string.map_download_success,
          Toast.LENGTH_SHORT).show();
      
      getDownloadingCity();
      
      listAdapter.notifyDataSetChanged();
           
      listView.invalidate();
    
      break;

    case MOfflineMapStatus.UNZIP:
      Toast.makeText(this,
          R.string.map_download_unzip,
          Toast.LENGTH_SHORT).show();
      break;

    case MOfflineMapStatus.WAITING:
      Toast.makeText(this,
          R.string.map_download_waiting,
          Toast.LENGTH_SHORT).show();
      break;

    }
    
  }
  
  
  private void getDownloadingCity(){
    
    listDownloading = mapManager.getDownloadingCityList();
    
    Iterator<City> i = listDownloading.iterator();
    
    listDownloadingCity.clear();
    
    while(i.hasNext()){
      
      City city = i.next();
      
      listDownloadingCity.add(city.getCity());
      
    }
  }

}




Java Source Code List

com.qshuttle.car.ActivityAddress.java
com.qshuttle.car.ActivityInfoRequest.java
com.qshuttle.car.ActivityMain.java
com.qshuttle.car.ActivityOfflineMap.java
com.qshuttle.car.DataOperator.java
com.qshuttle.car.DataProvider.java
com.qshuttle.car.DatabaseHelper.java
com.qshuttle.car.ExpandableListAdapter.java
com.qshuttle.car.GPSLocationOverlay.java
com.qshuttle.car.HostSettingActivity.java
com.qshuttle.car.ListAdapterAddress.java
com.qshuttle.car.ListAdapter.java
com.qshuttle.car.LongPressPopupOverlay.java
com.qshuttle.car.MapGestureDetectorOverlay.java
com.qshuttle.car.OverlayMapLocation.java
com.qshuttle.car.PassengerScheduleOverlay.java
com.qshuttle.car.PrefProxy.java
com.qshuttle.car.ThreadHttpPost.java
com.qshuttle.car.ThreadTimer.java
com.qshuttle.car.TimerCallBack.java
com.qshuttle.car.Timer.java
com.qshuttle.car.Utilities.java
com.qshuttle.car.WebApi.java