Android Open Source - qshuttle_driver Long Press Popup Overlay






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  2s .  co m
 */
package com.qshuttle.car;

import java.util.ArrayList;
import java.util.List;

import com.amap.mapapi.core.OverlayItem;
import com.amap.mapapi.map.ItemizedOverlay;
import com.amap.mapapi.map.MapView;
import com.amap.mapapi.map.ItemizedOverlay.*;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.location.Address;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import android.view.GestureDetector.OnGestureListener;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.RelativeLayout;
import android.widget.TextView;


/**
 * @author wangpeifeng
 *
 */
public class LongPressPopupOverlay extends ItemizedOverlay implements OnFocusChangeListener{
  
  private static final String TAG = "LongPressPopupOverlay";  
  
  private List<OverlayItem> lstItems = new ArrayList<OverlayItem>();  
  
  private Context context;

  private MapView mapView;
  
  private View popView;
  
  private OverlayItem focusItem;
   
  private Drawable marker;
  
  private OnClickListener listener;
  
      
  
  public LongPressPopupOverlay(Context context, MapView mapView, Drawable marker) {
    
    super(boundCenterBottom(marker));
    // TODO Auto-generated constructor stub
    
    this.context = context;
    
    this.mapView = mapView;
    
    this.marker = marker;
    
    this.listener = listenerButton;
    
      initPopView();
      
      this.setOnFocusChangeListener((OnFocusChangeListener) this);
      
  }
  
  
  public LongPressPopupOverlay(Context context, MapView mapView, Drawable marker, OnClickListener listener) {
    
    super(boundCenterBottom(marker));
    // TODO Auto-generated constructor stub
    
    this.context = context;
    
    this.mapView = mapView;
    
    this.marker = marker;
    
    this.listener = listener;
    
      initPopView();
      
      this.setOnFocusChangeListener((OnFocusChangeListener) this);
      
  }

    private void initPopView(){  
          
     if(null == popView){  

       popView = (((Activity) context).getLayoutInflater().inflate(R.layout.addressbubble, null));  
           
       mapView.addView(popView, new MapView.LayoutParams(  
                      MapView.LayoutParams.WRAP_CONTENT,  
                      MapView.LayoutParams.WRAP_CONTENT, null,  
                      MapView.LayoutParams.BOTTOM_CENTER));  
           
       popView.setVisibility(View.GONE);  

       ((RelativeLayout)(popView.findViewById(R.id.relativeLayoutGo))).setOnClickListener(listener);  
             
     }  
           
      
   }  

   
   public View getPopView(){
  
     return popView;
   
   }
   
   @Override
  
   protected OverlayItem createItem(int index) {
    // TODO Auto-generated method stub
    return lstItems.get(index);
  
   }

  
   @Override
  
   public int size() {
    // TODO Auto-generated method stub
  
     return lstItems.size();
  
   }
  
   
  
   public void addItem(OverlayItem item) {  
  
     lstItems.add(item);  
    
     populate();  
  
   }  
  
  
   public void removeItem(int index) {  
  
     lstItems.remove(index);  
  
   }  

   
   public void onFocusChanged(ItemizedOverlay<?> overlay, OverlayItem newFocus) {
  
     // TODO Auto-generated method stub
     if (null != newFocus) {  
        
       MapView.LayoutParams params = (MapView.LayoutParams) popView.getLayoutParams();  
            
       params.x = marker.getBounds().centerX();// 
            
       params.y =  - marker.getBounds().height();//  
            
       params.point = newFocus.getPoint();  
            
       TextView title_TextView = (TextView) popView.findViewById(R.id.map_bubbleTitle);  
            
       title_TextView.setText(newFocus.getTitle());  
            
       TextView desc_TextView = (TextView) popView.findViewById(R.id.map_bubbleText);  
            
       desc_TextView.setText(newFocus.getSnippet());  
             
       mapView.updateViewLayout(popView, params);  
            
       popView.setVisibility(View.VISIBLE);  
            
       mapView.getController().animateTo(newFocus.getPoint());  
              
       focusItem = newFocus;  
        
     }    
        
  
   }
  
   public void registerListener(OnClickListener listener){
     
     this.listener = listener;
     
   }
  
   public OnClickListener listenerButton = new OnClickListener(){

    public void onClick(View v) {
      // TODO Auto-generated method stub
      
      Log.i("click", "click!");
      
      
      popView.setVisibility(View.GONE);  
      
      Message msg = new Message();
      msg.what = ActivityMain.HANDLER_MSG_WHAT_START_ROUTE;
      
      Bundle bundle = new Bundle();
      bundle.putInt(ActivityMain.BUNDLE_KEY_LATE6, focusItem.getPoint().getLatitudeE6());
      bundle.putInt(ActivityMain.BUNDLE_KEY_LONGE6, focusItem.getPoint().getLongitudeE6());
      msg.setData(bundle);
      
      ActivityMain.handlerRef.sendMessage(msg);

      PrefProxy.Address address = (new PrefProxy()).new Address();
      
      address.address = focusItem.getTitle();
      
      address.late6 = focusItem.getPoint().getLatitudeE6();
      
      address.longe6 = focusItem.getPoint().getLongitudeE6();
      
      PrefProxy.updateRecentAddress(context, address);
    }
     
   };


}




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