Android Open Source - Mero-Bhada-Meter Utils






From Project

Back to project page Mero-Bhada-Meter.

License

The source code is released under:

GNU General Public License

If you think the Android project Mero-Bhada-Meter 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

/*
 * Copyright 2013-2014 Ludwig M Brinckmann
 *//from   w  w  w . j av a2s.co m
 * This program is free software: you can redistribute it and/or modify it under the
 * terms of the GNU Lesser General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later version.
 *
 * This program 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 Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 */
package com.nirab.merobhadameter;

import java.io.File;

import org.mapsforge.core.graphics.Bitmap;
import org.mapsforge.core.graphics.Paint;
import org.mapsforge.core.graphics.Style;
import org.mapsforge.core.model.LatLong;
import org.mapsforge.core.model.Point;
import org.mapsforge.map.android.graphics.AndroidGraphicFactory;
import org.mapsforge.map.layer.cache.TileCache;
import org.mapsforge.map.layer.overlay.Marker;
import org.mapsforge.map.layer.renderer.TileRendererLayer;
import org.mapsforge.map.model.MapViewPosition;
import org.mapsforge.map.rendertheme.XmlRenderTheme;

import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.util.Log;
import android.view.View;
import android.view.View.MeasureSpec;

/**
 * Utility functions that can be used across different mapsforge based
 * activities.
 */
public final class Utils {
  /**
   * Compatibility method.
   * 
   * @param a
   *            the current activity
   */
  @TargetApi(11)
  public static void enableHome(Activity a) {
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
      // Show the Up button in the action bar.
      a.getActionBar().setDisplayHomeAsUpEnabled(true);
    }
  }

  /**
   * Compatibility method.
   * 
   * @param view
   *            the view to set the background on
   * @param background
   *            the background
   */
  @TargetApi(16)
  public static void setBackground(View view, Drawable background) {
    if (android.os.Build.VERSION.SDK_INT >= 16) {
      view.setBackground(background);
    } else {
      view.setBackgroundDrawable(background);
    }
  }

  static Marker createMarker(Context c, int resourceIdentifier,
      LatLong latLong) {
    Drawable drawable = c.getResources().getDrawable(resourceIdentifier);
    Bitmap bitmap = AndroidGraphicFactory.convertToBitmap(drawable);
    return new Marker(latLong, bitmap, 0, -bitmap.getHeight() / 2);
  }

  static Paint createPaint(int color, int strokeWidth, Style style) {
    Paint paint = AndroidGraphicFactory.INSTANCE.createPaint();
    paint.setColor(color);
    paint.setStrokeWidth(strokeWidth);
    paint.setStyle(style);
    return paint;
  }

  static Marker createTappableMarker(Context c, int resourceIdentifier,
      LatLong latLong) {
    Drawable drawable = c.getResources().getDrawable(resourceIdentifier);
    Bitmap bitmap = AndroidGraphicFactory.convertToBitmap(drawable);
    return new Marker(latLong, bitmap, 0, -bitmap.getHeight() / 2) {
      @Override
      public boolean onTap(LatLong geoPoint, Point viewPosition,
          Point tapPoint) {
        if (contains(viewPosition, tapPoint)) {
          Log.w("Tapp", "The Marker was touched with onTap: "
              + this.getLatLong().toString());
          return true;
        }
        return false;
      }
    };
  }

  /*
   * @param tileCache the cache
   * 
   * @param mapViewPosition the position
   * 
   * @param layerManager the layer manager
   * 
   * @param mapFile the map file
   * 
   * @param renderTheme the render theme to use
   * 
   * @return the layer
   */
  static TileRendererLayer createTileRendererLayer(TileCache tileCache,
      MapViewPosition mapViewPosition, File mapFile,
      XmlRenderTheme renderTheme, boolean hasAlpha) {
    TileRendererLayer tileRendererLayer = new TileRendererLayer(tileCache,
        mapViewPosition, hasAlpha, AndroidGraphicFactory.INSTANCE);
    tileRendererLayer.setMapFile(mapFile);
    tileRendererLayer.setXmlRenderTheme(renderTheme);
    tileRendererLayer.setTextScale(1.5f);
    return tileRendererLayer;
  }

  static Bitmap viewToBitmap(Context c, View view) {
    view.measure(MeasureSpec.getSize(view.getMeasuredWidth()),
        MeasureSpec.getSize(view.getMeasuredHeight()));
    view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
    view.setDrawingCacheEnabled(true);
    Drawable drawable = new BitmapDrawable(c.getResources(),
        android.graphics.Bitmap.createBitmap(view.getDrawingCache()));
    view.setDrawingCacheEnabled(false);
    return AndroidGraphicFactory.convertToBitmap(drawable);
  }

  private Utils() {
    throw new IllegalStateException();
  }

}




Java Source Code List

com.nirab.merobhadameter.AsyncTaskCompleteListener.java
com.nirab.merobhadameter.DownloadOfflineData.java
com.nirab.merobhadameter.Fare.java
com.nirab.merobhadameter.MainActivity.java
com.nirab.merobhadameter.MapActivity.java
com.nirab.merobhadameter.MenuActivity.java
com.nirab.merobhadameter.MyPreferencesActivity.java
com.nirab.merobhadameter.OfflineMapActivity.java
com.nirab.merobhadameter.OfflineRoute.java
com.nirab.merobhadameter.SamplesApplication.java
com.nirab.merobhadameter.Utils.java
com.nirab.merobhadameter.ViaPointInfoWindow.java