Skip to content

Commit

Permalink
adding new methods
Browse files Browse the repository at this point in the history
added moveMarker, moveToMarker, and framePoints convenience methods
  • Loading branch information
moagrius committed Feb 22, 2014
1 parent 0d6ddfd commit f624ade
Showing 1 changed file with 94 additions and 1 deletion.
95 changes: 94 additions & 1 deletion src/com/qozix/tileview/TileView.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import android.graphics.Region;
import android.view.View;

import com.qozix.layouts.AnchorLayout;
import com.qozix.layouts.TranslationLayout;
import com.qozix.layouts.ZoomPanLayout;
import com.qozix.tileview.detail.DetailLevelEventListener;
import com.qozix.tileview.detail.DetailLevelPatternParser;
Expand Down Expand Up @@ -436,6 +438,47 @@ public void slideToAndCenter( double x, double y ) {
slideToAndCenter( point );
}

/**
* Scales and moves TileView so that each of the passed points is visible.
* @param points (List<double[]>) List of 2-element double arrays to be translated to Points (pixel values). The first double should represent the relative x value, the second is y
*/
public void framePoints( List<double[]> points ) {

double topMost = -Integer.MAX_VALUE;
double bottomMost = Integer.MAX_VALUE;
double leftMost = Integer.MAX_VALUE;
double rightMost = -Integer.MAX_VALUE;

for( double[] coordinate : points ) {
double x = coordinate[0];
double y = coordinate[1];
if(positionManager.contains( x, y )){
topMost = Math.max( topMost, x );
bottomMost = Math.min( bottomMost, x );
leftMost = Math.min( leftMost, y );
rightMost = Math.max( rightMost, y );
}
}

Point topRight = translate( topMost, rightMost );
Point bottomLeft = translate( bottomMost, leftMost );

int width = bottomLeft.x - topRight.x;
int height = bottomLeft.y - topRight.y;

double scaleX = Math.abs( getWidth() / (double) width );
double scaleY = Math.abs( getHeight() / (double) height );

double destinationScale = Math.min( scaleX, scaleY );

double middleX = ( rightMost + leftMost ) * 0.5f;
double middleY = ( topMost + bottomMost ) * 0.5f;

moveToAndCenter( middleY, middleX );
setScaleFromCenter( destinationScale );

}


//------------------------------------------------------------------------------------
// Marker, Callout and HotSpot API
Expand Down Expand Up @@ -484,12 +527,62 @@ public View addMarker( View view, double x, double y, float anchorX, float ancho

/**
* Removes a marker View from the TileView's view tree.
* @param view The marker View to be removed.
* @param view (View) The marker View to be removed.
*/
public void removeMarker( View view ) {
markerManager.removeMarker( view );
}

/**
* Moves an existing marker to another position.
* @param view The marker View to be repositioned.
* @param x (double) relative x position the View instance should be positioned at
* @param y (double) relative y position the View instance should be positioned at
*/
public void moveMarker( View view, double x, double y ){
if( markerManager.indexOfChild( view ) > -1 ){
Point point = positionManager.translate( x, y );
LayoutParams params = view.getLayoutParams();
if( params instanceof AnchorLayout.LayoutParams ) {
AnchorLayout.LayoutParams anchorLayoutParams = (AnchorLayout.LayoutParams) params;
anchorLayoutParams.x = point.x;
anchorLayoutParams.y = point.y;
view.setLayoutParams( anchorLayoutParams );
markerManager.requestLayout();
}
}
}

/**
* Scroll the TileView so that the View passed is centered in the viewport
* @param view (View) the View marker that the TileView should center on.
* @params animate (boolean) should the movement use a transition effectg
*/
public void moveToMarker( View view, boolean animate ) {
if( markerManager.indexOfChild( view ) > -1 ){
LayoutParams params = view.getLayoutParams();
if( params instanceof AnchorLayout.LayoutParams ) {
AnchorLayout.LayoutParams anchorLayoutParams = (AnchorLayout.LayoutParams) params;
int scaledX = (int) ( anchorLayoutParams.x * getScale() );
int scaledY = (int) ( anchorLayoutParams.y * getScale() );
Point point = new Point( scaledX, scaledY );
if( animate ) {
slideToAndCenter( point );
} else {
scrollToAndCenter( point );
}
}
}
}

/**
* Scroll the TileView so that the View passed is centered in the viewport
* @param view (View) the View marker that the TileView should center on.
*/
public void moveToMarker( View view ) {
moveToMarker( view, false );
}

/**
* Register a MarkerEventListener. Unlike standard touch events attached to marker View's (e.g., View.OnClickListener),
* MarkerEventListeners do not consume the touch event, so will not interfere with scrolling. While the event is
Expand Down

0 comments on commit f624ade

Please sign in to comment.