-
Notifications
You must be signed in to change notification settings - Fork 335
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #536 from yashx/master
Added Scaling Marker Plugin #409
- Loading branch information
Showing
3 changed files
with
61 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
tileview/src/main/java/com/moagrius/tileview/plugins/ScalingMarkerPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.moagrius.tileview.plugins; | ||
|
||
import android.content.Context; | ||
import android.support.annotation.NonNull; | ||
import android.view.View; | ||
|
||
public class ScalingMarkerPlugin extends MarkerPlugin { | ||
private float mOriginalAtScale; | ||
|
||
public ScalingMarkerPlugin(@NonNull Context context) { | ||
this(context, 1f); | ||
} | ||
|
||
public ScalingMarkerPlugin(@NonNull Context context, float originalAtScale) { | ||
super(context); | ||
mOriginalAtScale = originalAtScale; | ||
} | ||
|
||
@Override | ||
protected LayoutParams populateLayoutParams(View child) { | ||
MarkerPlugin.LayoutParams layoutParams = (MarkerPlugin.LayoutParams) child.getLayoutParams(); | ||
if (child.getVisibility() != View.GONE) { | ||
// actual sizes of children | ||
int measuredWidth = (int) (child.getMeasuredWidth() / mOriginalAtScale * mScale); | ||
int measuredHeight = (int) (child.getMeasuredHeight() / mOriginalAtScale * mScale); | ||
// calculate combined anchor offsets | ||
float widthOffset = measuredWidth * layoutParams.relativeAnchorX + layoutParams.absoluteAnchorX; | ||
float heightOffset = measuredHeight * layoutParams.relativeAnchorY + layoutParams.absoluteAnchorY; | ||
// get offset position | ||
int scaledX = (int) (layoutParams.x * mScale); | ||
int scaledY = (int) (layoutParams.y * mScale); | ||
// save computed values | ||
layoutParams.mLeft = (int) (scaledX + widthOffset); | ||
layoutParams.mTop = (int) (scaledY + heightOffset); | ||
layoutParams.mRight = layoutParams.mLeft + measuredWidth; | ||
layoutParams.mBottom = layoutParams.mTop + measuredHeight; | ||
} | ||
return layoutParams; | ||
} | ||
|
||
@Override | ||
public void onScaleChanged(float scale, float previous) { | ||
super.onScaleChanged(scale, previous); | ||
requestLayout(); | ||
} | ||
} |