Skip to content

Commit a1e733e

Browse files
authored
Merge pull request #325 from moagrius/release/2.2.0
using a single canvas
2 parents 22a5481 + 0bac896 commit a1e733e

25 files changed

+684
-427
lines changed

README.md

+26-18
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
![Release Badge](https://img.shields.io/github/release/moagrius/TileView.svg)
22

3-
_**03/18/16** if you're using a version earlier than 2.1, there were significant performance gains realized with 2.1 so we'd advise you to start using the most recent version (2.1 or later) immediately. The improvements made also make fast-render viable, especially if not fetching tile data from across a network, so we'd also encourage you to try `TileView.setShouldRenderWhilePanning(true);` if you'd like more responsive tile rendering._
3+
#TileView
4+
The TileView widget is a subclass of ViewGroup that provides a mechanism to asynchronously display tile-based images, with additional functionality for 2D dragging, flinging, pinch or double-tap to zoom, adding overlaying Views (markers), built-in Hot Spot support, dynamic path drawing, multiple levels of detail, and support for any relative positioning or coordinate system.
5+
6+
![Demo](https://cloud.githubusercontent.com/assets/701344/17538476/6933099e-5e6b-11e6-9e18-45e924c19c91.gif)
7+
_Properly configured, TileView can render tiles quickly enough to create the illusion of a seamless image_
8+
[](https://cloud.githubusercontent.com/assets/701344/10954033/d20843bc-8310-11e5-83ad-4e062b9b1be0.gif)
9+
10+
_**08/07/16** 2.2 is released, and provides some much-needed improvements in how tiles are rendered - please consider upgrading, but be aware there are some minor potential breaking changes (that should not affect 99% of users)._
11+
12+
_**03/18/16** if you're using a version earlier than 2.1, there were significant performance gains realized with 2.1 so we'd advise you to start using the most recent version (2.1 or later) immediately. The improvements made also make fast-render viable, so we'd also encourage you to try `TileView.setShouldRenderWhilePanning(true);` if you'd like more responsive tile rendering._
413

5-
#Version 2.0
14+
##Version 2.0
615

716
**Version 2.0 released 10.25.15**
817

@@ -20,23 +29,19 @@ Major goals were:
2029
6. General refactoring. There are too many simplifications and optimization to mention, but each class and each method has been revisited.
2130
7. Hooks hooks hooks! While pan and zoom events are broadcast using a familiar listener mechanism, and should be sufficient for most use-cases, public hooks exist for a large number of operations that can be overriden by subclasses for custom functionality.
2231

23-
#Change Log
32+
##Change Log
2433
(Only major and minor changes are tracked here, consult git history for patches)
2534

35+
**2.2** Rewrite of tile rendering strategy, again with the help of @peterLaurence. Peak memory consumption should be reduced, and Tile render performance should be improved.
2636
**2.1** Rewrite of threading strategy, thanks to @peterLaurence and @bnsantos. Tile render performance is substantially improved.
2737

28-
#TileView
29-
The TileView widget is a subclass of ViewGroup that provides a mechanism to asynchronously display tile-based images, with additional functionality for 2D dragging, flinging, pinch or double-tap to zoom, adding overlaying Views (markers), built-in Hot Spot support, dynamic path drawing, multiple levels of detail, and support for any relative positioning or coordinate system.
30-
31-
![Demo](https://cloud.githubusercontent.com/assets/701344/10954033/d20843bc-8310-11e5-83ad-4e062b9b1be0.gif)
32-
3338
###Documentation
3439
Javadocs are [here](http://moagrius.github.io/TileView/index.html?com/qozix/tileview/TileView.html). Wiki is [here](https://github.com/moagrius/TileView/wiki).
3540

3641
###Installation
3742
Gradle:
3843
```
39-
compile 'com.qozix:tileview:2.1.8'
44+
compile 'com.qozix:tileview:2.2.0'
4045
```
4146

4247
The library is hosted on jcenter, and is not currently available from maven.
@@ -56,7 +61,7 @@ A demo application, built in Android Studio, is available in the `demo` folder o
5661
at the 2nd column from left and 3rd row from top.
5762
1. Create a new application with a single activity ('Main').
5863
1. Save the image tiles to your `assets` directory.
59-
1. Add `compile 'com.qozix:tileview:2.1.8'` to your gradle dependencies.
64+
1. Add `compile 'com.qozix:tileview:2.2.0'` to your gradle dependencies.
6065
1. In the Main Activity, use this for `onCreate`:
6166
```
6267
@Override
@@ -76,15 +81,15 @@ That's it. You should have a tiled image that only renders the pieces of the im
7681

7782
![detail-levels](https://cloud.githubusercontent.com/assets/701344/10954031/d2059c3e-8310-11e5-821d-26dd8691d4d3.gif)
7883

79-
A TileView instance can have any number of detail levels, which is a single image made up of many tiles. These tiles are positioned appropriately to show the portion of the image that the device's viewport is displayed - other tiles are recyled (and their memory freed) as they move out of the visible area. Detail levels often showing the same content at different magnifications, but may show different details as well - for example, a detail level showing a larger area will probably label features differently than a detail level showing a smaller area (imagine a TileView representing the United States may show the Rocky Mountains at a very low detail level, while a higher detail level may show individual streets or addresses.
84+
A TileView instance can have any number of detail levels, which is a single image made up of many tiles; each DetailLevel exists in the same space, but are useful to show different levels of details (thus the class name), and to further break down large images into smaller tiles sets. These tiles are positioned appropriately to show the portion of the image that the device's viewport is displayed - other tiles are recycled (and their memory freed) as they move out of the visible area. Detail levels often show the same content at different magnifications, but may show different details as well - for example, a detail level showing a larger area will probably label features differently than a detail level showing a smaller area (imagine a TileView representing the United States may show the Rocky Mountains at a very low detail level, while a higher detail level may show individual streets or addresses.
8085

81-
Each detail level is passed a float value, indicating the scale value that it represents (e.g., a detail level passed 0.5f scale would be displayed when the TileView was zoomed out by 50%). Additionally, each detail level is passed an aribtrary data object that is attached to each tile and can provide instructions on how to generate the tile's bitmap.
86+
Each detail level is passed a float value, indicating the scale value that it represents (e.g., a detail level passed 0.5f scale would be displayed when the TileView was zoomed out by 50%). Additionally, each detail level is passed an arbitrary data object that is attached to each tile and can provide instructions on how to generate the tile's bitmap. That data object is often a String, formatted to provide the path to the bitmap image for that Tile, but can be any kind of Object whatsoever - during the decode process, each tile has access to the data object for the detail level.
8287

8388
####Tiles
8489

85-
A Tile is a class instance that represents a Bitmap which is a portion of the total image. Each Tile provides position information, and methods to manage the Bitmap, and is also passed to the TileView's `BitmapProvider` implementation, which is how individual bitmaps are generated.
90+
A Tile is a class instance that represents a Bitmap - a portion of the total image. Each Tile provides position information, and methods to manage the Bitmap's state and behavior. Each Tile instanced is also passed to the TileView's `BitmapProvider` implementation, which is how individual bitmaps are generated. Tile instances uses an `equals` method that compares only row, column and detail level, and are often passed in `Set` collections, so that Tile instances already in process are simply excluded by the unique nature of the Set if the program or user tries to add a single Tile more than once.
8691

87-
Each TileView uses a `BitmapProvider` implementation to generate tile bitmaps. The interface defines a single method: `public Bitmap getBitmap( Tile tile, Context context );`. This method is called each time a bitmap is required, and has access to the Tile instance for that position and detail level, and a Context object to access system resources. The `BitmapProvider` implementation can generate the bitmap in any way it chooses - assets, resources, http requests, dynamically drawn, SVG, decoded regions, etc. The default implementation, `BitmapProviderAssets`, parses a String (the data object passed to the DetailLevel) and returns a bitmap found by file name in the app's assets directory.
92+
Each TileView instance must reference a `BitmapProvider` implementation to generate tile bitmaps. The interface defines a single method: `public Bitmap getBitmap( Tile tile, Context context );`. This method is called each time a bitmap is required, and has access to the Tile instance for that position and detail level, and a Context object to access system resources. The `BitmapProvider` implementation can generate the bitmap in any way it chooses - assets, resources, http requests, dynamically drawn, SVG, decoded regions, etc. The default implementation, `BitmapProviderAssets`, parses a String (the data object passed to the DetailLevel) and returns a bitmap found by file name in the app's assets directory.
8893

8994
####Markers & Callouts
9095

@@ -145,14 +150,14 @@ tileView.addPath( drawablePath );
145150
####Scaling
146151
The `setScale(1)` method sets the initial scale of the TileView.
147152

148-
`setScaleLimits(0, 1)` sets the minimum and maximum scale which controls how far a TileView can be zoomed in or out. `0` means completely zoomed out, `1` means zoomed in to the most detailled level (with the pixels of the tiles matching the screen dpi). For example by using `setScaleLimits(0, 3)` you allow users to zoom in even further then the most detailled level (stretching the image).
153+
`setScaleLimits(0, 1)` sets the minimum and maximum scale which controls how far a TileView can be zoomed in or out. `0` means completely zoomed out, `1` means zoomed in to the most detailed level (with the pixels of the tiles matching the screen dpi). For example by using `setScaleLimits(0, 3)` you allow users to zoom in even further then the most detailed level (stretching the image).
149154

150155
`setMinimumScaleMode(ZoomPanLayout.MinimumScaleMode.FILL)` controls how far a image can be zoomed out based on the dimensions of the image:
151156
- `FILL`: Limit the minimum scale to no less than what would be required to fill the container
152157
- `FIT`: Limit the minimum scale to no less than what would be required to fit inside the container
153158
- `NONE`: Limit to the minimum scale level set by `setScaleLimits`
154159

155-
_When using `FILL` or `FIT`, the minimum scale level of `setScaleLimits` is ignored_
160+
_When using `FILL` or `FIT`, the minimum scale level of `setScaleLimits` is ignored._
156161

157162
####Hooks and Listeners
158163

@@ -173,7 +178,7 @@ tileView.addZoomPanListener( new ZoomPanListener(){
173178
});
174179
```
175180

176-
Additionally, TileView reports most significant operations to hooks. TileView implements `ZoomPanLayout.ZoomPanListener`, `TileCanvasViewGroup.TileRenderListener`, and `DetailLevelManager.DetailLevelChangeListener`, and it's super class implements `GestureDetector.OnGestureListener`, `GestureDetector.OnDoubleTapListener`,`ScaleGestureDetector.OnScaleGestureListener`, and `TouchUpGestureDetector.OnTouchUpListener`. As such, the following hooks are available to be overriden by subclasses of TileView:
181+
Additionally, TileView reports most significant operations to hooks. TileView implements `ZoomPanLayout.ZoomPanListener`, `TileCanvasViewGroup.TileRenderListener`, and `DetailLevelManager.DetailLevelChangeListener`, and it's super class implements `GestureDetector.OnGestureListener`, `GestureDetector.OnDoubleTapListener`,`ScaleGestureDetector.OnScaleGestureListener`, and `TouchUpGestureDetector.OnTouchUpListener`. As such, the following hooks are available to be overridden by subclasses of TileView:
177182

178183
```
179184
protected void onScrollChanged( int l, int t, int oldl, int oldt );
@@ -214,7 +219,7 @@ See the [wiki entry here](https://github.com/moagrius/TileView/wiki/Creating-Til
214219
####...use relative coordinates (like latitude and longitude)?
215220
The TileView method `defineBounds( double left, double top, double right, double bottom )` establishes a coordinate system for further positioning method calls (e.g., `scrollTo`, `addMarker`, etc). After relative coordinates are established by invoking the `defineBounds` method, any subsequent method invocations that affect position *and* accept `double` parameters will compute the value as relative of the provided bounds, rather than absolute pixels. That's to say that:
216221

217-
1. A TileView instance is intialized with `setSize( 5000, 5000 );`
222+
1. A TileView instance is initialized with `setSize( 5000, 5000 );`
218223
1. That TileView instance calls `defineBounds( 0, 100, 0, 100 );`
219224
1. That TileView instance calls `scrollTo( 25d, 50d );`
220225
1. That TileView will immediately scroll to the pixel at 1250, 2500.
@@ -298,3 +303,6 @@ tileView.addView( downSample, 0 );
298303

299304
###Contributing
300305
See [here](https://github.com/moagrius/TileView/wiki/Contributing).
306+
307+
###Contributors
308+
Several members of the github community have contributed and made `TileView` better, but over the last year or so, @peterLaurence has been as involved as myself and been integral in the last few major updates. Thanks Peter.

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ buildscript {
55
jcenter()
66
}
77
dependencies {
8-
classpath 'com.android.tools.build:gradle:1.3.0'
8+
classpath 'com.android.tools.build:gradle:2.1.2'
99

1010
// NOTE: Do not place your application dependencies here; they belong
1111
// in the individual module build.gradle files
-163 KB
Binary file not shown.
Binary file not shown.
-87.2 KB
Binary file not shown.
-57.9 KB
Binary file not shown.
-163 KB
Binary file not shown.

demo/src/main/java/tileview/demo/BuildingPlansTileViewActivity.java

+6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ public void onCreate( Bundle savedInstanceState ) {
2121
// size of original image at 100% mScale
2222
tileView.setSize( 2736, 2880 );
2323

24+
// small map, let's let it resize to 200%
25+
tileView.setScaleLimits( 0, 2 );
26+
27+
// we're running from assets, should be fairly fast decodes, go ahead and render asap
28+
tileView.setShouldRenderWhilePanning( true );
29+
2430
// detail levels
2531
tileView.addDetailLevel( 1.000f, "tiles/plans/1000/%d_%d.jpg");
2632
tileView.addDetailLevel( 0.500f, "tiles/plans/500/%d_%d.jpg");

demo/src/main/java/tileview/demo/FictionalMapTileViewActivity.java

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ public void onCreate( Bundle savedInstanceState ) {
1717

1818
// size of original image at 100% mScale
1919
tileView.setSize( 4015, 4057 );
20+
21+
// we're running from assets, should be fairly fast decodes, go ahead and render asap
22+
tileView.setShouldRenderWhilePanning( true );
2023

2124
// detail levels
2225
tileView.addDetailLevel( 1.000f, "tiles/fantasy/1000/%d_%d.jpg");

demo/src/main/java/tileview/demo/LargeImageTileViewActivity.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ public void onCreate( Bundle savedInstanceState ) {
1313

1414
// multiple references
1515
TileView tileView = getTileView();
16-
17-
// by disabling transitions, we won't see a flicker of background color when moving between tile sets
18-
tileView.setTransitionsEnabled( false );
16+
17+
// let the image explode
18+
tileView.setScaleLimits( 0, 2 );
1919

2020
// size of original image at 100% mScale
2121
tileView.setSize( 2835, 4289 );

0 commit comments

Comments
 (0)