Android Open Source - TileView Detail Level






From Project

Back to project page TileView.

License

The source code is released under:

MIT License

If you think the Android project TileView 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 com.qozix.tileview.detail;
/*from   www .  j a v  a  2 s.c  om*/
import java.util.LinkedList;

import android.graphics.Rect;
import android.util.Log;

import com.qozix.tileview.tiles.Tile;

public class DetailLevel implements Comparable<DetailLevel> {

  private static final int DEFAULT_TILE_SIZE = 256;

  private double scale;
  
  private int tileWidth = DEFAULT_TILE_SIZE;
  private int tileHeight = DEFAULT_TILE_SIZE;

  private String pattern;
  private String downsample;

  private DetailManager detailManager;
  private Rect viewport = new Rect();

  public DetailLevel( DetailManager zm, float s, String p, String d, int tw, int th ) {
    detailManager = zm;
    scale = s;
    pattern = p;
    downsample = d;
    tileWidth = tw;
    tileHeight = th;
  }
  
  public DetailLevel( DetailManager zm, float s, String p, String d ) {
    this( zm, s, p, d, DEFAULT_TILE_SIZE, DEFAULT_TILE_SIZE );
  }

  public LinkedList<Tile> getIntersections() {
    
    double relativeScale = getRelativeScale();
    
    int drawableWidth = (int) ( detailManager.getWidth() * getScale() * relativeScale );
    int drawableHeight = (int) ( detailManager.getHeight() * getScale() * relativeScale );
    double offsetWidth = ( tileWidth * relativeScale );
    double offsetHeight = ( tileHeight * relativeScale );
    
    LinkedList<Tile> intersections = new LinkedList<Tile>();
    
    viewport.set( detailManager.getComputedViewport() );
    
    // TODO test if mins are right
    viewport.top = Math.max( viewport.top, 0 );
    viewport.left = Math.max( viewport.left, 0 );
    viewport.right = Math.min( viewport.right, drawableWidth );
    viewport.bottom = Math.min( viewport.bottom, drawableHeight );
    
    
    int startingRow = (int) Math.floor( viewport.top / offsetHeight );
    int endingRow = (int) Math.ceil( viewport.bottom / offsetHeight );
    int startingColumn = (int) Math.floor( viewport.left / offsetWidth );
    int endingColumn = (int) Math.ceil( viewport.right / offsetWidth );
    
    DetailLevelPatternParser parser = detailManager.getDetailLevelPatternParser();
    
    for ( int iterationRow = startingRow; iterationRow < endingRow; iterationRow++ ) {
      for ( int iterationColumn = startingColumn; iterationColumn < endingColumn; iterationColumn++ ) {
        String fileName = parser.parse( pattern, iterationRow, iterationColumn );
        int left = iterationColumn * tileWidth;
        int top = iterationRow * tileHeight;
        Tile tile = new Tile( left, top, tileWidth, tileHeight, fileName );
        intersections.add( tile );
      }
    }
    
    
    return intersections;
    
  }

  public double getScale(){
    return scale;
  }
  
  public double getRelativeScale(){
    return detailManager.getScale() / scale;
  }
  
  public int getTileWidth() {
    return tileWidth;
  }

  public int getTileHeight() {
    return tileHeight;
  }

  public String getPattern() {
    return pattern;
  }

  public String getDownsample() {
    return downsample;
  }

  @Override
  public int compareTo( DetailLevel o ) {
    return (int) Math.signum( getScale() - o.getScale() );
  }

  @Override
  public boolean equals( Object o ) {
    if ( o instanceof DetailLevel ) {
      DetailLevel zl = (DetailLevel) o;
      return ( zl.getScale() == getScale() );
    }
    return false;
  }

  @Override
  public int hashCode() {
    long bits = ( Double.doubleToLongBits( getScale() ) * 43 );
    return ( ( (int) bits ) ^ ( (int) ( bits >> 32 ) ) );
  }

  
}




Java Source Code List

com.qozix.animation.AnimationListener.java
com.qozix.animation.Animator.java
com.qozix.animation.TweenHandler.java
com.qozix.animation.TweenListener.java
com.qozix.animation.Tween.java
com.qozix.animation.easing.EasingEquation.java
com.qozix.animation.easing.Linear.java
com.qozix.animation.easing.Strong.java
com.qozix.layouts.AnchorLayout.java
com.qozix.layouts.FixedLayout.java
com.qozix.layouts.ScalingLayout.java
com.qozix.layouts.StaticLayout.java
com.qozix.layouts.TranslationLayout.java
com.qozix.layouts.ZoomPanLayout.java
com.qozix.os.AsyncTask.java
com.qozix.tileview.TileView.java
com.qozix.tileview.detail.DetailLevelEventListener.java
com.qozix.tileview.detail.DetailLevelPatternParserDefault.java
com.qozix.tileview.detail.DetailLevelPatternParser.java
com.qozix.tileview.detail.DetailLevelSet.java
com.qozix.tileview.detail.DetailLevelSetupListener.java
com.qozix.tileview.detail.DetailLevel.java
com.qozix.tileview.detail.DetailManager.java
com.qozix.tileview.geom.PositionManager.java
com.qozix.tileview.graphics.BitmapDecoderAssets.java
com.qozix.tileview.graphics.BitmapDecoderHttp.java
com.qozix.tileview.graphics.BitmapDecoder.java
com.qozix.tileview.hotspots.HotSpotEventListener.java
com.qozix.tileview.hotspots.HotSpotManager.java
com.qozix.tileview.hotspots.HotSpot.java
com.qozix.tileview.markers.CalloutManager.java
com.qozix.tileview.markers.MarkerEventListener.java
com.qozix.tileview.markers.MarkerManager.java
com.qozix.tileview.paths.DrawablePath.java
com.qozix.tileview.paths.PathHelper.java
com.qozix.tileview.paths.PathManager.java
com.qozix.tileview.samples.SampleManager.java
com.qozix.tileview.tiles.TileCache.java
com.qozix.tileview.tiles.TileManager.java
com.qozix.tileview.tiles.TileRenderHandler.java
com.qozix.tileview.tiles.TileRenderListener.java
com.qozix.tileview.tiles.TileRenderTask.java
com.qozix.tileview.tiles.TileTransitionListener.java
com.qozix.tileview.tiles.Tile.java
com.qozix.tileview.tiles.selector.TileSetSelectorByRange.java
com.qozix.tileview.tiles.selector.TileSetSelectorClosest.java
com.qozix.tileview.tiles.selector.TileSetSelectorMinimalUpScale.java
com.qozix.tileview.tiles.selector.TileSetSelector.java
com.qozix.utils.ViewCurator.java
com.qozix.widgets.Scroller.java