Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
403bd82
added rubber band like scrolling effect
krabo0om Oct 21, 2016
b216b1f
reworked rubber band effect
krabo0om Oct 24, 2016
d628d67
view slides back into place after a drag ended instead of direct scro…
krabo0om Oct 24, 2016
68b16d7
default scroll behavior is limited to standard bounds, only computeSc…
krabo0om Oct 26, 2016
b55acb2
Updating Tile.draw to use intrinsic dimensions
moagrius Oct 27, 2016
6a7b0e0
Merge pull request #361 from moagrius/issue-357
moagrius Oct 27, 2016
3248ecc
Allow arbitrary layout params for Markers in default signature
moagrius Oct 27, 2016
16ca8c0
removing test file
moagrius Oct 27, 2016
2f33616
Merge pull request #362 from moagrius/issue-355
moagrius Oct 27, 2016
63f59cc
bumping version
moagrius Oct 27, 2016
1cf759a
use localized string format to support non-roman languages
moagrius Nov 11, 2016
cf009ce
Merge pull request #370 from moagrius/issue/336
moagrius Nov 11, 2016
4b8248a
bumping version
moagrius Nov 11, 2016
3e453a0
issue-221 dont draw recycled bitmaps
moagrius Nov 11, 2016
9b6050a
Merge pull request #371 from moagrius/issue/221
moagrius Nov 11, 2016
c63b58d
bumping version
moagrius Nov 11, 2016
8ff22db
Remove hardcoded minimum scroll of 0, and expose #getScrollMinX, #get…
MisterRager Dec 3, 2016
8754bfd
Add interface BitmapCleanup to allow for capturing of Bitmap instance…
MisterRager Dec 3, 2016
a147a85
Merge pull request #378 from MisterRager/expose-scroll-limits
p-lr Dec 4, 2016
3a43092
address PR comments
MisterRager Dec 5, 2016
4db028e
fix whitespace, rename argument to something readable and recycled, f…
MisterRager Dec 6, 2016
60500bd
stop being cheeky
MisterRager Dec 6, 2016
85810e1
remove unneccessary space
MisterRager Dec 6, 2016
c0a4561
add necessary space
MisterRager Dec 6, 2016
5a1d284
remove else branch in Tile#reset
MisterRager Dec 6, 2016
d39903c
un-deprecate method
MisterRager Dec 6, 2016
22212a0
Whitespace missing
MisterRager Dec 6, 2016
5091295
Missed a space
MisterRager Dec 6, 2016
ecdb013
Merge pull request #379 from MisterRager/expose-bitmap-recycle
p-lr Dec 6, 2016
43ad9f8
bumping version
p-lr Dec 6, 2016
c783a75
Merge branch 'rubberbandscroll' into rubberband_merge
krabo0om Jan 25, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Javadocs are [here](http://moagrius.github.io/TileView/index.html?com/qozix/tile
###Installation
Gradle:
```
compile 'com.qozix:tileview:'2.2.2'
compile 'com.qozix:tileview:'2.2.6'
```

The library is hosted on jcenter, and is not currently available from maven.
Expand All @@ -64,7 +64,7 @@ A demo application, built in Android Studio, is available in the `demo` folder o
at the 2nd column from left and 3rd row from top.
1. Create a new application with a single activity ('Main').
1. Save the image tiles to your `assets` directory.
1. Add `compile 'com.qozix:tileview:2.2.2'` to your gradle dependencies.
1. Add `compile 'com.qozix:tileview:2.2.6'` to your gradle dependencies.
1. In the Main Activity, use this for `onCreate`:
```
@Override
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
classpath 'com.android.tools.build:gradle:2.2.1'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Sun Aug 07 15:38:33 CDT 2016
#Wed Oct 26 20:44:34 CDT 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
2 changes: 1 addition & 1 deletion tileview/aar-release.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@ generateRelease.dependsOn(zipRelease)

artifacts {
archives androidSourcesJar
archives androidJavadocsJar
//archives androidJavadocsJar
}
4 changes: 2 additions & 2 deletions tileview/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ android {
defaultConfig {
minSdkVersion 11
targetSdkVersion 23
versionCode 33
versionName "2.2.2"
versionCode 37
versionName "2.2.6"
}
buildTypes {
release {
Expand Down
13 changes: 13 additions & 0 deletions tileview/src/main/java/com/qozix/tileview/TileView.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.qozix.tileview.detail.DetailLevelManager;
import com.qozix.tileview.geom.CoordinateTranslater;
import com.qozix.tileview.geom.FloatMathHelper;
import com.qozix.tileview.graphics.BitmapRecycler;
import com.qozix.tileview.graphics.BitmapProvider;
import com.qozix.tileview.hotspots.HotSpot;
import com.qozix.tileview.hotspots.HotSpotManager;
Expand Down Expand Up @@ -287,6 +288,18 @@ public void setBitmapProvider( BitmapProvider bitmapProvider ) {
mTileCanvasViewGroup.setBitmapProvider( bitmapProvider );
}

/**
* Sets a custom class to perform the Bitmap finalization on Tile#reset.
* By default, a BitmapRecycler implementation is provided that calls Bitmap#recycle, but
* alternative implementations could be used that recycle Bitmap instances to prevent garbage
* collection or do other things after the Bitmap is no longer needed for rendering.
*
* @param bitmapRecycler A class instance that implements BitmapRecycler and must define a recycleBitmap method, which accepts a Bitmap after it is no longer being used
*/
public void setBitmapRecycler( BitmapRecycler bitmapRecycler ) {
mTileCanvasViewGroup.setBitmapRecycler( bitmapRecycler );
}

/**
* Defines whether tile bitmaps should be rendered using an AlphaAnimation
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.qozix.tileview.tiles.Tile;

import java.io.InputStream;
import java.util.Locale;

/**
* This is a very simple implementation of BitmapProvider, using a formatted string to find
Expand All @@ -30,7 +31,7 @@ public Bitmap getBitmap( Tile tile, Context context ) {
Object data = tile.getData();
if( data instanceof String ) {
String unformattedFileName = (String) tile.getData();
String formattedFileName = String.format( unformattedFileName, tile.getColumn(), tile.getRow() );
String formattedFileName = String.format( Locale.US, unformattedFileName, tile.getColumn(), tile.getRow() );
AssetManager assetManager = context.getAssets();
try {
InputStream inputStream = assetManager.open( formattedFileName );
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.qozix.tileview.graphics;

import android.graphics.Bitmap;

/**
* This interface represents the final operations applied to a {@link Bitmap} owned by a
* {@link com.qozix.tileview.tiles.Tile} after it is no longer being used. Generally, this only
* entails a call to {@link Bitmap#recycle()}, but it also provides a place to catch {@link Bitmap}
* instances for reuse in a cache or an object pool.
*/
public interface BitmapRecycler {
void recycleBitmap( Bitmap bitmap );
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.qozix.tileview.graphics;

import android.graphics.Bitmap;

public class BitmapRecyclerDefault implements BitmapRecycler {
@Override
public void recycleBitmap( Bitmap bitmap ) {
if( !bitmap.isRecycled() ) {
bitmap.recycle();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,15 @@ public float getScale() {
}

public View addMarker( View view, int x, int y, Float aX, Float aY ) {
LayoutParams layoutParams = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, x, y, aX, aY );
return addMarker( view, layoutParams );
ViewGroup.LayoutParams defaultLayoutParams = view.getLayoutParams();
LayoutParams markerLayoutParams = (defaultLayoutParams != null)
? generateLayoutParams(defaultLayoutParams)
: generateDefaultLayoutParams();
markerLayoutParams.x = x;
markerLayoutParams.y = y;
markerLayoutParams.anchorX = aX;
markerLayoutParams.anchorY = aY;
return addMarker( view, markerLayoutParams );
}

public View addMarker( View view, LayoutParams params ) {
Expand Down Expand Up @@ -149,7 +156,7 @@ protected void onLayout( boolean changed, int l, int t, int r, int b ) {
}

@Override
protected ViewGroup.LayoutParams generateDefaultLayoutParams() {
protected MarkerLayout.LayoutParams generateDefaultLayoutParams() {
return new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 0, 0 );
}

Expand All @@ -159,7 +166,7 @@ protected boolean checkLayoutParams( ViewGroup.LayoutParams layoutParams ) {
}

@Override
protected ViewGroup.LayoutParams generateLayoutParams( ViewGroup.LayoutParams layoutParams ) {
protected MarkerLayout.LayoutParams generateLayoutParams( ViewGroup.LayoutParams layoutParams ) {
return new LayoutParams( layoutParams );
}

Expand Down
43 changes: 31 additions & 12 deletions tileview/src/main/java/com/qozix/tileview/tiles/Tile.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.qozix.tileview.detail.DetailLevel;
import com.qozix.tileview.geom.FloatMathHelper;
import com.qozix.tileview.graphics.BitmapProvider;
import com.qozix.tileview.graphics.BitmapRecycler;

import java.lang.ref.WeakReference;

Expand Down Expand Up @@ -58,6 +59,7 @@ public enum State {
private DetailLevel mDetailLevel;

private WeakReference<TileRenderRunnable> mTileRenderRunnableWeakReference;
private WeakReference<BitmapRecycler> mBitmapRecyclerReference;

public Tile( int column, int row, int width, int height, Object data, DetailLevel detailLevel ) {
mRow = row;
Expand All @@ -71,15 +73,7 @@ public Tile( int column, int row, int width, int height, Object data, DetailLeve
mData = data;
mDetailLevel = detailLevel;
mDetailLevelScale = mDetailLevel.getScale();
mIntrinsicRect.set( 0, 0, mWidth, mHeight );
mBaseRect.set( mLeft, mTop, mRight, mBottom );
mRelativeRect.set(
FloatMathHelper.unscale( mLeft, mDetailLevelScale ),
FloatMathHelper.unscale( mTop, mDetailLevelScale ),
FloatMathHelper.unscale( mRight, mDetailLevelScale ),
FloatMathHelper.unscale( mBottom, mDetailLevelScale )
);
mScaledRect.set( mRelativeRect );
updateRects();
}

public int getWidth() {
Expand Down Expand Up @@ -151,6 +145,18 @@ public Rect getScaledRect( float scale ) {
return mScaledRect;
}

private void updateRects() {
mIntrinsicRect.set( 0, 0, mWidth, mHeight );
mBaseRect.set( mLeft, mTop, mRight, mBottom );
mRelativeRect.set(
FloatMathHelper.unscale( mLeft, mDetailLevelScale ),
FloatMathHelper.unscale( mTop, mDetailLevelScale ),
FloatMathHelper.unscale( mRight, mDetailLevelScale ),
FloatMathHelper.unscale( mBottom, mDetailLevelScale )
);
mScaledRect.set( mRelativeRect );
}

public void setTransitionDuration( int transitionDuration ) {
mTransitionDuration = transitionDuration;
}
Expand All @@ -164,12 +170,17 @@ public void setState( State state ) {
}

public void execute( TileRenderPoolExecutor tileRenderPoolExecutor ) {
execute( tileRenderPoolExecutor, null );
}

public void execute( TileRenderPoolExecutor tileRenderPoolExecutor, BitmapRecycler recycler ) {
if(mState != State.UNASSIGNED){
return;
}
mState = State.PENDING_DECODE;
TileRenderRunnable runnable = new TileRenderRunnable();
mTileRenderRunnableWeakReference = new WeakReference<>( runnable );
mBitmapRecyclerReference = new WeakReference<>( recycler );
runnable.setTile( this );
runnable.setTileRenderPoolExecutor( tileRenderPoolExecutor );
tileRenderPoolExecutor.execute( runnable );
Expand Down Expand Up @@ -223,6 +234,11 @@ void generateBitmap( Context context, BitmapProvider bitmapProvider ) {
return;
}
mBitmap = bitmapProvider.getBitmap( this, context );
mWidth = mBitmap.getWidth();
mHeight = mBitmap.getHeight();
mRight = mLeft + mWidth;
mBottom = mTop + mHeight;
updateRects();
mState = State.DECODED;
}

Expand All @@ -245,8 +261,11 @@ void reset() {
}
mState = State.UNASSIGNED;
mRenderTimeStamp = null;
if( mBitmap != null && !mBitmap.isRecycled() ) {
mBitmap.recycle();
if( mBitmap != null ) {
BitmapRecycler recycler = mBitmapRecyclerReference.get();
if( recycler != null ) {
recycler.recycleBitmap( mBitmap );
}
}
mBitmap = null;
}
Expand All @@ -255,7 +274,7 @@ void reset() {
* @param canvas The canvas the tile's bitmap should be drawn into
*/
public void draw( Canvas canvas ) {
if( mBitmap != null ) {
if( mBitmap != null && !mBitmap.isRecycled() ) {
canvas.drawBitmap( mBitmap, mIntrinsicRect, mRelativeRect, getPaint() );
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import android.view.ViewGroup;

import com.qozix.tileview.detail.DetailLevel;
import com.qozix.tileview.graphics.BitmapRecyclerDefault;
import com.qozix.tileview.graphics.BitmapRecycler;
import com.qozix.tileview.graphics.BitmapProvider;
import com.qozix.tileview.graphics.BitmapProviderAssets;

Expand All @@ -34,6 +36,7 @@ public class TileCanvasViewGroup extends ViewGroup {
private float mScale = 1;

private BitmapProvider mBitmapProvider;
private BitmapRecycler mBitmapRecycler;

private DetailLevel mDetailLevelToRender;
private DetailLevel mLastRenderedDetailLevel;
Expand Down Expand Up @@ -112,10 +115,21 @@ public BitmapProvider getBitmapProvider() {
return mBitmapProvider;
}

public BitmapRecycler getBitmapRecycler() {
if( mBitmapRecycler == null ) {
mBitmapRecycler = new BitmapRecyclerDefault();
}
return mBitmapRecycler;
}

public void setBitmapProvider( BitmapProvider bitmapProvider ) {
mBitmapProvider = bitmapProvider;
}

public void setBitmapRecycler( BitmapRecycler bitmapRecycler ) {
mBitmapRecycler = bitmapRecycler;
}

public void setTileRenderListener( TileRenderListener tileRenderListener ) {
mTileRenderListener = tileRenderListener;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void queue( TileCanvasViewGroup tileCanvasViewGroup, Set<Tile> renderSet
if( isShutdownOrTerminating() ) {
return;
}
tile.execute( this );
tile.execute( this, tileCanvasViewGroup.getBitmapRecycler() );
}
}

Expand Down
Loading