Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 * Copyright 2010, 2011, 2012, 2013 mapsforge.org
 * Copyright  2014 Ludwig M Brinckmann
 * Copyright  2014 devemux86
 *
 * 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/>.
 */

import android.annotation.TargetApi;

import android.content.Context;

import android.graphics.Point;

import android.view.Display;
import android.view.WindowManager;

public class Main {
    /**
     * Compute the minimum cache size for a view. When the cache is created we do not actually
     * know the size of the mapview, so the screenRatio is an approximation of the required size.
     *
     * @param c              the context
     * @param tileSize       the tile size
     * @param overdrawFactor the overdraw factor applied to the mapview
     * @param screenRatio    the part of the screen the view covers
     * @return the minimum cache size for the view
     */
    @SuppressWarnings("deprecation")
    @TargetApi(13)
    public static int getMinimumCacheSize(Context c, int tileSize, double overdrawFactor, float screenRatio) {
        WindowManager wm = (WindowManager) c.getSystemService(Context.WINDOW_SERVICE);
        Display display = wm.getDefaultDisplay();
        int height;
        int width;
        if (android.os.Build.VERSION.SDK_INT >= 13) {
            Point p = new Point();
            display.getSize(p);
            height = p.y;
            width = p.x;
        } else {
            // deprecated since Android 13
            height = display.getHeight();
            width = display.getWidth();
        }

        // height  * overdrawFactor / tileSize calculates the number of tiles that would cover
        // the view port, adding 1 is required since we can have part tiles on either side,
        // adding 2 adds another row/column as spare and ensures that we will generally have
        // a larger number of tiles in the cache than a TileLayer will render for a view.
        // Multiplying by screenRatio adjusts this somewhat inaccurately for MapViews on only part
        // of a screen (the result can be too low if a MapView is very narrow).
        // For any size we need a minimum of 4 (as the intersection of 4 tiles can always be in the
        // middle of a view.
        return (int) Math.max(4, screenRatio * (2 + (height * overdrawFactor / tileSize))
                * (2 + (width * overdrawFactor / tileSize)));
    }

    /**
     * Compute the minimum cache size for a view, using the size of the map view.
     *
     * @param tileSize       the tile size
     * @param overdrawFactor the overdraw factor applied to the mapview
     * @param width          the width of the map view
     * @param height         the height of the map view
     * @return the minimum cache size for the view
     */
    public static int getMinimumCacheSize(int tileSize, double overdrawFactor, int width, int height) {
        // height  * overdrawFactor / tileSize calculates the number of tiles that would cover
        // the view port, adding 1 is required since we can have part tiles on either side,
        // adding 2 adds another row/column as spare and ensures that we will generally have
        // a larger number of tiles in the cache than a TileLayer will render for a view.
        // For any size we need a minimum of 4 (as the intersection of 4 tiles can always be in the
        // middle of a view.
        return (int) Math.max(4,
                (2 + (height * overdrawFactor / tileSize)) * (2 + (width * overdrawFactor / tileSize)));
    }
}