-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,8 @@ public class ZoomPanLayout extends ViewGroup implements | |
private int mBaseHeight; | ||
private int mScaledWidth; | ||
private int mScaledHeight; | ||
private int mTranslateX = 0; | ||
private int mTranslateY = 0; | ||
|
||
private float mScale = 1; | ||
|
||
|
@@ -118,21 +120,18 @@ protected void onLayout( boolean changed, int l, int t, int r, int b ) { | |
final int width = getWidth(); | ||
final int height = getHeight(); | ||
|
||
int translateX = 0; | ||
int translateY = 0; | ||
|
||
if( mScaledWidth < width ) { | ||
translateX = width / 2 - mScaledWidth / 2; | ||
mTranslateX = width / 2 - mScaledWidth / 2; | ||
} | ||
|
||
if( mScaledHeight < height ) { | ||
translateY = height / 2 - mScaledHeight / 2; | ||
mTranslateY = height / 2 - mScaledHeight / 2; | ||
} | ||
|
||
for( int i = 0; i < getChildCount(); i++ ) { | ||
View child = getChildAt( i ); | ||
if( child.getVisibility() != GONE ) { | ||
child.layout( translateX, translateY, mScaledWidth + translateX, mScaledHeight + translateY ); | ||
child.layout( mTranslateX, mTranslateY, mScaledWidth + mTranslateX, mScaledHeight + mTranslateY ); | ||
} | ||
} | ||
calculateMinimumScaleToFit(); | ||
|
@@ -505,6 +504,7 @@ public boolean canScrollHorizontally( int direction ) { | |
|
||
@Override | ||
public boolean onTouchEvent( MotionEvent event ) { | ||
event.offsetLocation( -mTranslateX, -mTranslateY ); | ||
This comment has been minimized.
Sorry, something went wrong.
moagrius
|
||
boolean gestureIntercept = mGestureDetector.onTouchEvent( event ); | ||
boolean scaleIntercept = mScaleGestureDetector.onTouchEvent( event ); | ||
boolean touchIntercept = mTouchUpGestureDetector.onTouchEvent( event ); | ||
|
28 comments
on commit ff17b91
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for jumping on this peter. let me know if my comments make sense
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok. I realize now this was not a good idea. We need to find another way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about offsetting the events in those specific methods (e.g., MarkeryLayout.processHit, and I forget the other...) by getTop/getLeft?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i tried it. It seems to work. But i did not make a complete check, to see if it doesn't break something else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it'll probably also need to be offset in HotSpotManager. processHit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding :
x -= getLeft();
y -= getTop();
in MarkerLayout.processHit()
works. But HotSpotManager
is not a ViewGroup
so those methods don't exist.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(thumb typing on phone, pls excuse lack of formatting and detail)
a. maybe give the hotspotmanager a reference to the tileview instance, the mTikeView.getX/Y in processHit
b. maybe offset setters in hotspotmanager, updated in tileview onLayout
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As for the HotSpotManager
, i'm not quite sure how it works (no demo uses it, and btw the example in the readme uses an api than doesn't exists : TileView.addHotSpot( HotSpot, HotSpotTapListener )
).
a. maybe give the hotspotmanager a reference to the tileview instance, the mTikeView.getX/Y in processHit
In fact, we need to use the mMarkerLayout offsets, not the mTileView ones.
As the two processHits are only called in TileView.onSingleTapConfirmed
, it could be done like this :
@Override
public boolean onSingleTapConfirmed( MotionEvent event ) {
int x = (int) (getScrollX() + event.getX() - getX() - mMarkerLayout.getLeft() );
int y = (int) (getScrollY() + event.getY() - getY() - mMarkerLayout.getTop() );
mMarkerLayout.processHit( x, y );
mHotSpotManager.processHit( x, y );
return super.onSingleTapConfirmed( event );
}
it works, but not elegant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have to go now, i come back tomorrow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it works, but not elegant
I'm basically +1 on this but will post back later, or tomorrow, with details
I have to go now, i come back tomorrow
no problem, thanks peter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to point out that bug is just the result of another (kind of) bug:
The MarkerLayout
wraps the image, thus cutting of the view of any marker which would be placed at the image's top and reaching into the whitespace. If the MarkerLayout
fills the whole TileView
than one could not just place a marker into the whitespace but this should also solve this bug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with the caveat that i wasn't really involved in this feature, IIUC having MarkerLayout
fill all space would not be a fix. imagine a marker at 10% from top and 10% from left, on a 1000x1000 screen, and the tileview pinched to 100x100 and centered, which means the visible edge is at 950, so the marker should be at 960. if the markerlayout filled the screen, it'd be at 10 dots from top left, not 960.
@peterLaurence does that sound right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Override
public boolean onSingleTapConfirmed( MotionEvent event ) {
int x = (int) (getScrollX() + event.getX() - getX() - mMarkerLayout.getLeft() );
int y = (int) (getScrollY() + event.getY() - getY() - mMarkerLayout.getTop() );
mMarkerLayout.processHit( x, y );
mHotSpotManager.processHit( x, y );
return super.onSingleTapConfirmed( event );
}
Like i said, I'm basically +1 on this. instead of using mMarkerLayout.getLeft/Top()
, i'd probably make the offsets calculated in ZoomPanLayout
protected, and read those here instead.
does that make sense? sound reasonable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with the caveat that i wasn't really involved in this feature, IIUC having MarkerLayout fill all space would not be a fix. imagine a marker at 10% from top and 10% from left, on a 1000x1000 screen, and the tileview pinched to 100x100 and centered, which means the visible edge is at 950, so the marker should be at 960. if the markerlayout filled the screen, it'd be at 10 dots from top left, not 960.
It makes sense, but sadly, i just tested with the fix you're +1 with a map with a marker at 10% from top and 10% from left. The marker's view was cut.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So i am thinking, if the MarkerLayout
fills the TileView
, the logic of marker positioning would be completely changed, taking into account the eventual offsets top and/or left. It's feasible.
Basically, instead of offsetting the MarkerLayout
, marker's positions take into account the offsets.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, i think you're right. i think that's the only way forward, other than deprecating fill mode... i always felt like we got away with that too easily). we need to remember HotSpots too (maybe even paths?) but hopefully we can take whatever happens here and migrate the concept.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
btw, something is unclear to me about HotSpots. As the HotSpotManger
is not a ViewGroup
, when we offsets layouts in the case of FIT mode, the HotSpotManger
is not affected, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's a good point, it just looks at scale... should be fine. I'll double check when markers are done. great catch peter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, thanks confirming me this. I will do some experimentation with markers on FIT mode (try to implement the idea above).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in fact, i just realized there is maybe a very simple solution. The problem is that marker's view are clipped?
By adding setClipChildren( false );
in ZoomPanLayout
constructor, the issue is solved :
From the doc for setClipChildren
:
By default, children are clipped to their bounds before drawing. This allows view groups to override this behavior for animations, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, there is still the HotSpotManager
thing to fix, because that component isn't aware of the eventual offsets. By that i mean that the getMatch
method only looks at the scale.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By adding setClipChildren( false ); in ZoomPanLayout constructor, the issue is solved :
awesome - could we do setClipChildren
in MarkerLayout
instead of ZoomPanLayout
?
So, there is still the HotSpotManager thing to fix, because that component isn't aware of the eventual offsets. By that i mean that the getMatch method only looks at the scale.
yeah - do you want to do the hotspot thing or would you like me to jump in?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
awesome - could we do setClipChildren in MarkerLayout instead of ZoomPanLayout?
Tried it : it doesn't work. I think that in that case the ZoomPanLayout
clips the MarkerLayout
to its bounds, even if the later doesn't clips its children.
yeah - do you want to do the hotspot thing or would you like me to jump in?
Yes i think you're better placed to do it as it's more general api design.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds good, i'll take it from here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
i'd prefer this in another demo - i like the
RealMapTileViewActivity
to show the widget in it's best possible configuration