Android Open Source - TrafficChecker Traffic Map Itemized Overlay






From Project

Back to project page TrafficChecker.

License

The source code is released under:

GNU General Public License

If you think the Android project TrafficChecker 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

/*
 *  This File is licensed under GPL v3.// w  w w  .  ja v  a  2s  . c om
 *  Copyright (C) 2012 Rene Peinthor.
 *
 *  This file is part of TrafficChecker.
 *
 *  BlueMouse is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  TrafficChecker is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with TrafficChecker.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.oldsch00l.TrafficChecker;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.widget.Toast;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.MapView;
import com.google.android.maps.OverlayItem;

public class TrafficMapItemizedOverlay extends ItemizedOverlay<OverlayItem> {
  private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
  private Context mContext = null;

  public TrafficMapItemizedOverlay(Drawable defaultMarker, Context context) {
      super(boundCenterBottom(defaultMarker));
      mContext = context;
  }
  
  public TrafficMapItemizedOverlay(Drawable defaultMarker) {
    super(boundCenterBottom(defaultMarker));
  }

  public void addOverlay(OverlayItem overlay) {
    if( !hasPoint(overlay.getPoint()) )
      mOverlays.add(overlay);
  }
  
  public boolean hasPoint(GeoPoint point) {
    for (OverlayItem item : mOverlays) {
      if( point.equals(item.getPoint()) )
        return true;
    }
    return false;
  }
  
  public void populateData() {
    populate();
  }
  
  @Override
  public void draw(Canvas canvas, MapView mapView, boolean shadow) {
    if( !shadow )
      super.draw(canvas, mapView, shadow);
  }

  @Override
  protected OverlayItem createItem(int i) {
    return mOverlays.get(i);
  }

  @Override
  public int size() {
    return mOverlays.size();
  }
  
  @Override
  protected boolean onTap(int index) {
    OverlayItem item = mOverlays.get(index);
//    AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
//    dialog.setTitle(item.getTitle());
//    dialog.setMessage(item.getSnippet());
//    dialog.show();
    if( mContext != null)
    {
      StringBuffer sbText = new StringBuffer();
      sbText.append(item.getTitle());
      if( !item.getSnippet().equals(item.getTitle()) )
      {
        sbText.append('\n');
        sbText.append(item.getSnippet());
      }
      Toast.makeText(mContext, sbText.toString(), Toast.LENGTH_LONG).show();
    }
    return true;
  }

}




Java Source Code List

com.oldsch00l.TrafficChecker.AboutDialog.java
com.oldsch00l.TrafficChecker.AndroidSaxFeedParser.java
com.oldsch00l.TrafficChecker.AndroidSaxRSSParser.java
com.oldsch00l.TrafficChecker.BaseFeedParser.java
com.oldsch00l.TrafficChecker.CacheTrafficEntries.java
com.oldsch00l.TrafficChecker.GermanyRegions.java
com.oldsch00l.TrafficChecker.Message.java
com.oldsch00l.TrafficChecker.Preferences.java
com.oldsch00l.TrafficChecker.SelectRegionActivity.java
com.oldsch00l.TrafficChecker.TrafficAdapter.java
com.oldsch00l.TrafficChecker.TrafficChecker.java
com.oldsch00l.TrafficChecker.TrafficMapItemizedOverlay.java
com.oldsch00l.TrafficChecker.TrafficOverlay.java
com.oldsch00l.TrafficChecker.TrafficParser.java
com.oldsch00l.TrafficChecker.TrafficRegion.java