Android Open Source - smartnavi Icon Style






From Project

Back to project page smartnavi.

License

The source code is released under:

Apache License

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

package org.osmdroid.bonuspack.kml;
/*from   w w w  . ja  v  a2s. c o  m*/
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.PorterDuff.Mode;
import android.graphics.drawable.BitmapDrawable;
import android.os.Parcel;
import android.os.Parcelable;

import org.osmdroid.bonuspack.overlays.Marker;
import org.osmdroid.bonuspack.utils.WebImageCache;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.Writer;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

/**
 * Handling of KML IconStyle
 */
public class IconStyle extends ColorStyle implements Parcelable {

    public static final Parcelable.Creator<IconStyle> CREATOR = new Parcelable.Creator<IconStyle>() {
        @Override
        public IconStyle createFromParcel(Parcel source) {
            return new IconStyle(source);
        }

        @Override
        public IconStyle[] newArray(int size) {
            return new IconStyle[size];
        }
    };
    private static WebImageCache mIconCache;

    static {
        //one common memory cache for all icons:
        mIconCache = new WebImageCache(100);
    }

    public float mScale;
    public float mHeading;
    public String mHref;
    public Bitmap mIcon;
    public float mHotSpotX, mHotSpotY;

    public IconStyle() {
        super();
        mScale = 1.0f;
        mHeading = 0.0f;
        mHotSpotX = 0.5f;
        mHotSpotY = 1.0f;
    }

    public IconStyle(Parcel in) {
        super(in);
        mScale = in.readFloat();
        mHeading = in.readFloat();
        mHref = in.readString();
        mIcon = in.readParcelable(Bitmap.class.getClassLoader());
        mHotSpotX = in.readFloat();
        mHotSpotY = in.readFloat();
    }

    /**
     * Load and set the icon bitmap, from a url or from a local file.
     *
     * @param href              either the full url, or a relative path to a local file.
     * @param containerFullPath full path of the container file.
     * @param kmzContainer      current KMZ file (as a ZipFile) - or null if irrelevant.
     */
    public void setIcon(String href, String containerFullPath, ZipFile kmzContainer) {
        mHref = href;
        if (mHref.startsWith("http://") || mHref.startsWith("https://")) {
            mIcon = mIconCache.get(mHref);
        } else if (kmzContainer == null) {
            File file = new File(containerFullPath);
            String actualFullPath = file.getParent() + '/' + mHref;
            mIcon = BitmapFactory.decodeFile(actualFullPath);
        } else {
            try {
                final ZipEntry fileEntry = kmzContainer.getEntry(href);
                InputStream stream = kmzContainer.getInputStream(fileEntry);
                mIcon = BitmapFactory.decodeStream(stream);
            } catch (Exception e) {
                mIcon = null;
            }
        }
    }

    /**
     * @return the icon, scaled and blended with the icon color, as specified in the IconStyle.
     * Assumes the icon is already loaded.
     */
    public BitmapDrawable getFinalIcon(Context context) {
        if (mIcon == null)
            return null;
        int sizeX = Math.round(mIcon.getWidth() * mScale);
        int sizeY = Math.round(mIcon.getHeight() * mScale);
        Bitmap scaledBitmap = Bitmap.createScaledBitmap(mIcon, sizeX, sizeY, true);
        BitmapDrawable marker = new BitmapDrawable(context.getResources(), scaledBitmap);
        int color = getFinalColor();
        if (color != 0) //there is a real color to blend with:
            marker.setColorFilter(color, Mode.MULTIPLY);
        return marker;
    }

    //Parcelable implementation ------------

    /**
     * apply all IconStyle attributes to the Marker
     */
    public void styleMarker(Marker marker, Context context) {
        BitmapDrawable icon = getFinalIcon(context);
        marker.setIcon(icon);
        marker.setAnchor(mHotSpotX, mHotSpotY);
        marker.setRotation(mHeading);
    }

    public void writeAsKML(Writer writer) {
        try {
            writer.write("<IconStyle>\n");
            super.writeAsKML(writer);
            //write the specifics:
            if (mScale != 1.0f)
                writer.write("<scale>" + mScale + "</scale>\n");
            if (mHeading != 0.0f)
                writer.write("<heading>" + mHeading + "</heading>\n");
            if (mHref != null)
                writer.write("<Icon><href>" + mHref + "</href></Icon>\n");
            writer.write("<hotSpot x=\"" + mHotSpotX + "\" y=\"" + mHotSpotY + "\" xunits=\"fraction\" yunits=\"fraction\"/>\n");
            writer.write("</IconStyle>\n");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel out, int flags) {
        super.writeToParcel(out, flags);
        out.writeFloat(mScale);
        out.writeFloat(mHeading);
        out.writeString(mHref);
        out.writeParcelable(mIcon, flags);
        out.writeFloat(mHotSpotX);
        out.writeFloat(mHotSpotY);
    }

}




Java Source Code List

com.ilm.sandwich.BackgroundService.java
com.ilm.sandwich.BuildConfig.java
com.ilm.sandwich.Config.java
com.ilm.sandwich.GoogleMapActivity.java
com.ilm.sandwich.Info.java
com.ilm.sandwich.MySupportMapFragment.java
com.ilm.sandwich.OsmMapActivity.java
com.ilm.sandwich.Settings.java
com.ilm.sandwich.StartChooser.java
com.ilm.sandwich.TouchableWrapper.java
com.ilm.sandwich.tools.Core.java
com.ilm.sandwich.tools.HttpRequests.java
com.ilm.sandwich.tools.Locationer.java
com.ilm.sandwich.tools.MapDownload.java
com.ilm.sandwich.tools.MyItemizedOverlay.java
com.ilm.sandwich.tools.PlacesAutoComplete.java
com.ilm.sandwich.tools.PlacesTextSearch.java
com.ilm.sandwich.tools.Statistics.java
com.ilm.sandwich.tools.SuggestionsAdapter.java
org.osmdroid.bonuspack.BuildConfig.java
org.osmdroid.bonuspack.BuildConfig.java
org.osmdroid.bonuspack.cachemanager.CacheManager.java
org.osmdroid.bonuspack.clustering.GridMarkerClusterer.java
org.osmdroid.bonuspack.clustering.MarkerClusterer.java
org.osmdroid.bonuspack.clustering.StaticCluster.java
org.osmdroid.bonuspack.kml.ColorStyle.java
org.osmdroid.bonuspack.kml.IconStyle.java
org.osmdroid.bonuspack.kml.KmlDocument.java
org.osmdroid.bonuspack.kml.KmlFeature.java
org.osmdroid.bonuspack.kml.KmlFolder.java
org.osmdroid.bonuspack.kml.KmlGeometry.java
org.osmdroid.bonuspack.kml.KmlGroundOverlay.java
org.osmdroid.bonuspack.kml.KmlLineString.java
org.osmdroid.bonuspack.kml.KmlMultiGeometry.java
org.osmdroid.bonuspack.kml.KmlPlacemark.java
org.osmdroid.bonuspack.kml.KmlPoint.java
org.osmdroid.bonuspack.kml.KmlPolygon.java
org.osmdroid.bonuspack.kml.LineStyle.java
org.osmdroid.bonuspack.kml.Style.java
org.osmdroid.bonuspack.location.FlickrPOIProvider.java
org.osmdroid.bonuspack.location.GeoNamesPOIProvider.java
org.osmdroid.bonuspack.location.GeocoderGisgraphy.java
org.osmdroid.bonuspack.location.GeocoderNominatimOld.java
org.osmdroid.bonuspack.location.GeocoderNominatim.java
org.osmdroid.bonuspack.location.NominatimPOIProvider.java
org.osmdroid.bonuspack.location.POI.java
org.osmdroid.bonuspack.location.PicasaPOIProvider.java
org.osmdroid.bonuspack.mapsforge.GenericMapView.java
org.osmdroid.bonuspack.mapsforge.MapsForgeTileModuleProvider.java
org.osmdroid.bonuspack.mapsforge.MapsForgeTileProvider.java
org.osmdroid.bonuspack.mapsforge.MapsForgeTileSource.java
org.osmdroid.bonuspack.overlays.DefaultInfoWindow.java
org.osmdroid.bonuspack.overlays.ExtendedOverlayItem.java
org.osmdroid.bonuspack.overlays.FolderOverlay.java
org.osmdroid.bonuspack.overlays.GroundOverlay.java
org.osmdroid.bonuspack.overlays.InfoWindow.java
org.osmdroid.bonuspack.overlays.ItemizedOverlayWithBubble.java
org.osmdroid.bonuspack.overlays.MapEventsOverlay.java
org.osmdroid.bonuspack.overlays.MapEventsReceiver.java
org.osmdroid.bonuspack.overlays.MarkerInfoWindow.java
org.osmdroid.bonuspack.overlays.Marker.java
org.osmdroid.bonuspack.overlays.Polygon.java
org.osmdroid.bonuspack.overlays.Polyline.java
org.osmdroid.bonuspack.routing.GoogleRoadManager.java
org.osmdroid.bonuspack.routing.MapQuestRoadManager.java
org.osmdroid.bonuspack.routing.OSRMRoadManager.java
org.osmdroid.bonuspack.routing.RoadLeg.java
org.osmdroid.bonuspack.routing.RoadManager.java
org.osmdroid.bonuspack.routing.RoadNode.java
org.osmdroid.bonuspack.routing.Road.java
org.osmdroid.bonuspack.utils.BonusPackHelper.java
org.osmdroid.bonuspack.utils.DouglasPeuckerReducer.java
org.osmdroid.bonuspack.utils.HttpConnection.java
org.osmdroid.bonuspack.utils.PolylineEncoder.java
org.osmdroid.bonuspack.utils.WebImageCache.java