Custom Onlayout not working - android

Can anybody tell me how to change data dynamically in onLayout().i want to display first 8 values and after rotation complete another 8 values until it display array limit.here is my code-
if (position < conversion.length) {
if (!childRotate) {
child.setAngle(angle);
child.setPosition(i);
position = i;
child.setImageResource(conversion[position]);
Float an = angle;
Log.i("prj,=angle", an.toString() + ",i=" + i.toString()
+ ",onlayout,position=" + position.toString());
position++;
} else {
child.setAngle(angle);
child.setPosition(i);
child.setImageResource(conversion[position]);
Float an = angle;
Log.i("prj,angle=", an.toString() + ",i=" + i.toString()
+ ",onlayout,position=" + position.toString());
position++;
// childRotate = false;
}
}
left = Math
.round((float) (((layoutWidth / 2) - childWidth / 2) + radius
* Math.cos(Math.toRadians(angle))));
top = Math
.round((float) (((layoutHeight / 2) - childHeight / 2) + radius
* Math.sin(Math.toRadians(angle))));
child.layout(left, top, left + childWidth, top + childHeight);
angle += angleDelay;

Related

Crop YUV byte[] based on a rectangle without any convertion

I have tried to use the logic and pictorial representation from this SO. I am though confused with the images since one of them follow 4:1:1 whereas the later one does 4:2:2 nomenclature for YUV image (NV21).
Right now the issue is that i get an image (converted to Bitmap/PNG) with YUV component all over, essentially an unusable image.
Any recommendation to fix this?
private byte[] cropImage(byte[] data, Rect cropRect) {
int dataHeight = 480;
int dataWidth = 640;
int totalWH = dataWidth * dataHeight;
// make rect points even, currently the width & height is even number
// adjust x coordinates to make them
if (cropRect.left % 2 != 0 || cropRect.right % 2 != 0) {
cropRect.left -= 1;
cropRect.right -= 1;
}
// adjust y coordinates to make them even
if (cropRect.top % 2 != 0 || cropRect.bottom % 2 != 0) {
cropRect.top -= 1;
cropRect.bottom -= 1;
}
int area = cropRect.width() * cropRect.height() * 3/2;
Logger.getLogger().d("Size of byte array " + data.length + " Size of alloc area " + area);
byte[] pixels = new byte[area];//the size of the array is the dimensions of the sub-photo
// size.total = size.width * size.height;
// y = yuv[position.y * size.width + position.x];
// u = yuv[(position.y / 2) * (size.width / 2) + (position.x / 2) + size.total];
// v = yuv[(position.y / 2) * (size.width / 2) + (position.x / 2) + size.total + (size.total / 4)];
try {
// copy Y plane first
int srcOffset = cropRect.top * dataWidth;
int destOffset = 0;
int lengthToCopy = cropRect.width();
int y = 0;
for (; y < cropRect.height(); y++, srcOffset += dataWidth, destOffset += cropRect.width()) {
// Logger.getLogger().d("IO " + srcOffset + cropRect.left + " oO " + destOffset + " LTC " + lengthToCopy);
System.arraycopy(data, srcOffset + cropRect.left, pixels, destOffset, lengthToCopy);
}
Logger.getLogger().d("Completed Y copy");
// U and V components are not-interleaved, hence their size is just 1/4th the original size
// copy U plane
int nonYPlanerHeight = dataHeight / 4;
int nonYPlanerWidth = dataWidth / 4;
srcOffset = totalWH + (cropRect.top / 4 * nonYPlanerWidth);
for (y = 0; y < cropRect.height();
y++, srcOffset += nonYPlanerWidth, destOffset += cropRect.width() / 4) {
System.arraycopy(data, srcOffset + cropRect.left / 4, pixels, destOffset, cropRect.width() / 4);
}
Logger.getLogger().d("Completed U copy " + y + " destOffset=" + destOffset);
// copy V plane
srcOffset = totalWH + totalWH / 4 + (cropRect.top / 4 * nonYPlanerWidth);
for (y = 0; y < cropRect.height();
y++, srcOffset += nonYPlanerWidth, destOffset += cropRect.width() / 4) {
System.arraycopy(data, srcOffset + cropRect.left / 4, pixels, destOffset, cropRect.width() / 4);
}
Logger.getLogger().d("Completed V copy " + y + " destOffset=" + destOffset);
} catch (ArrayIndexOutOfBoundsException ae) {
// do nothing
Logger.getLogger().e("Exception " + ae.getLocalizedMessage());
}
return pixels;
}

MuPDF Android Library Vertical Scroll

I am using MuPdf Android Library, I want vertical Scroll instead of horizontal page Scrolling, tried everything but failed, googled the problem and found an answer on Stackoverflow and someone answered his question which worked for the Questions Author but I am not getting this solution, putted these methods in ReaderView but by this way I found errors which were related to other activities, kindly help me to where put these methods etc. someone worked on mupdf vertical scrolling?
As Arunjyothis said :
You can do by changing the horizontal values to vertical ( change all width related calculations to height )
Check the answer HERE.
I created new binding library for Mupdf with method swipeHorizontal(boolean isHorizontal) so you can easy change between vertical and horizontal scroll
https://github.com/minaairsupport/MuPDF_Xamarin
Just download the library and reference it in your project
You can do by changing the horizontal values to vertical ( change all width related calculations to height ). Change onLayout() & onFling() as below: (Reference)
#Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
// "Edit mode" means when the View is being displayed in the Android GUI editor. (this class
// is instantiated in the IDE, so we need to be a bit careful what we do).
if (isInEditMode())
return;
View cv = mChildViews.get(mCurrent);
Point cvOffset;
if (!mResetLayout) {
// Move to next or previous if current is sufficiently off center
if (cv != null) {
cvOffset = subScreenSizeOffset(cv);
// cv.getRight() may be out of date with the current scale
// so add left to the measured width for the correct position
//if (cv.getLeft() + cv.getMeasuredWidth() + cvOffset.x + GAP/2 + mXScroll < getWidth()/2 && mCurrent + 1 < mAdapter.getCount()) {
if (cv.getTop() + cv.getMeasuredHeight() + cvOffset.y + GAP / 2 + mYScroll < getHeight() / 2 && mCurrent + 1 < mAdapter.getCount()) {
postUnsettle(cv);
// post to invoke test for end of animation
// where we must set hq area for the new current view
mStepper.prod();
onMoveOffChild(mCurrent);
mCurrent++;
onMoveToChild(mCurrent);
}
//if (cv.getLeft() - cvOffset.x - GAP/2 + mXScroll >= getWidth()/2 && mCurrent > 0) {
if (cv.getTop() - cvOffset.y - GAP / 2 + mYScroll >= getHeight() / 2 && mCurrent > 0) {
postUnsettle(cv);
// post to invoke test for end of animation
// where we must set hq area for the new current view
mStepper.prod();
onMoveOffChild(mCurrent);
mCurrent--;
onMoveToChild(mCurrent);
}
}
// Remove not needed children and hold them for reuse
int numChildren = mChildViews.size();
int childIndices[] = new int[numChildren];
for (int i = 0; i < numChildren; i++)
childIndices[i] = mChildViews.keyAt(i);
for (int i = 0; i < numChildren; i++) {
int ai = childIndices[i];
if (ai < mCurrent - 1 || ai > mCurrent + 1) {
View v = mChildViews.get(ai);
onNotInUse(v);
mViewCache.add(v);
removeViewInLayout(v);
mChildViews.remove(ai);
}
}
} else {
mResetLayout = false;
mXScroll = mYScroll = 0;
// Remove all children and hold them for reuse
int numChildren = mChildViews.size();
for (int i = 0; i < numChildren; i++) {
View v = mChildViews.valueAt(i);
onNotInUse(v);
mViewCache.add(v);
removeViewInLayout(v);
}
mChildViews.clear();
// Don't reuse cached views if the adapter has changed
if (mReflowChanged) {
mReflowChanged = false;
mViewCache.clear();
}
// post to ensure generation of hq area
mStepper.prod();
}
// Ensure current view is present
int cvLeft, cvRight, cvTop, cvBottom;
boolean notPresent = (mChildViews.get(mCurrent) == null);
cv = getOrCreateChild(mCurrent);
// When the view is sub-screen-size in either dimension we
// offset it to center within the screen area, and to keep
// the views spaced out
cvOffset = subScreenSizeOffset(cv);
if (notPresent) {
//Main item not already present. Just place it top left
cvLeft = cvOffset.x;
cvTop = cvOffset.y;
} else {
// Main item already present. Adjust by scroll offsets
cvLeft = cv.getLeft() + mXScroll;
cvTop = cv.getTop() + mYScroll;
}
// Scroll values have been accounted for
mXScroll = mYScroll = 0;
cvRight = cvLeft + cv.getMeasuredWidth();
cvBottom = cvTop + cv.getMeasuredHeight();
if (!mUserInteracting && mScroller.isFinished()) {
Point corr = getCorrection(getScrollBounds(cvLeft, cvTop, cvRight, cvBottom));
cvRight += corr.x;
cvLeft += corr.x;
cvTop += corr.y;
cvBottom += corr.y;
} else if (cv.getMeasuredWidth() <= getWidth()) {
// // When the current view is as small as the screen in height, clamp
// // it vertically
// Point corr = getCorrection(getScrollBounds(cvLeft, cvTop, cvRight, cvBottom));
// cvTop += corr.y;
// cvBottom += corr.y;
// When the current view is as small as the screen in width, clamp
// it horizontally
Point corr = getCorrection(getScrollBounds(cvLeft, cvTop, cvRight, cvBottom));
cvRight += corr.x;
cvLeft += corr.x;
}
cv.layout(cvLeft, cvTop, cvRight, cvBottom);
if (mCurrent > 0) {
View lv = getOrCreateChild(mCurrent - 1);
Point leftOffset = subScreenSizeOffset(lv);
/*int gap = leftOffset.x + GAP + cvOffset.x;
lv.layout(cvLeft - lv.getMeasuredWidth() - gap,
(cvBottom + cvTop - lv.getMeasuredHeight())/2,
cvLeft - gap,
(cvBottom + cvTop + lv.getMeasuredHeight())/2);*/
int gap = leftOffset.y + GAP + cvOffset.y;
lv.layout((cvRight + cvLeft - lv.getMeasuredWidth())/2,
cvTop - lv.getMeasuredHeight() - gap,
(cvRight + cvLeft + lv.getMeasuredWidth())/2,
cvTop - gap);
}
if (mCurrent + 1 < mAdapter.getCount()) {
View rv = getOrCreateChild(mCurrent + 1);
Point rightOffset = subScreenSizeOffset(rv);
/*int gap = cvOffset.x + GAP + rightOffset.x;
rv.layout(cvRight + gap,
(cvBottom + cvTop - rv.getMeasuredHeight())/2,
cvRight + rv.getMeasuredWidth() + gap,
(cvBottom + cvTop + rv.getMeasuredHeight())/2);*/
int gap = cvOffset.y + GAP + rightOffset.y;
rv.layout((cvRight + cvLeft - rv.getMeasuredWidth())/2,
cvBottom + gap,
(cvRight + cvLeft + rv.getMeasuredWidth())/2,
cvBottom + rv.getMeasuredHeight() + gap);
}
invalidate();
}
Also add the below lines:
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
if (mScaling)
return true;
View v = mChildViews.get(mCurrent);
if (v != null) {
Rect bounds = getScrollBounds(v);
switch (directionOfTravel(velocityX, velocityY)) {
case MOVING_UP:
if (bounds.top >= 0) {
// Fling off to the left bring next view onto screen
View vl = mChildViews.get(mCurrent + 1);
if (vl != null) {
slideViewOntoScreen(vl);
return true;
}
}
break;
case MOVING_DOWN:
if (bounds.bottom <= 0) {
// Fling off to the right bring previous view onto screen
View vr = mChildViews.get(mCurrent - 1);
if (vr != null) {
slideViewOntoScreen(vr);
return true;
}
}
break;
}
mScrollerLastX = mScrollerLastY = 0;
// If the page has been dragged out of bounds then we want to spring back
// nicely. fling jumps back into bounds instantly, so we don't want to use
// fling in that case. On the other hand, we don't want to forgo a fling
// just because of a slightly off-angle drag taking us out of bounds other
// than in the direction of the drag, so we test for out of bounds only
// in the direction of travel.
//
// Also don't fling if out of bounds in any direction by more than fling
// margin
Rect expandedBounds = new Rect(bounds);
expandedBounds.inset(-FLING_MARGIN, -FLING_MARGIN);
if (withinBoundsInDirectionOfTravel(bounds, velocityX, velocityY)
&& expandedBounds.contains(0, 0)) {
mScroller.fling(0, 0, (int) velocityX, (int) velocityY, bounds.left, bounds.right, bounds.top, bounds.bottom);
mStepper.prod();
}
}
return true;
}

Android OpenGL 2.0 : Object Picking (seeing if you hit a object with a ray)

So I am trying to get object picking working in OpenGL 2, in OpenGK 1 I used the glpixelColor which was pretty straight forward.
I have the following code to give me the start and end point of my ray??
Log.i("My POSITION", "x:" + mRenderer.eye.x + " y:" + mRenderer.eye.y + " z:" + mRenderer.eye.z);
float xyzw[] = unproject(x, mRenderer.screenHeight - y, -1.0f);
Log.i("Start of ray", "x:" + xyzw[0] + " y:" + xyzw[1] + " z:" + xyzw[2]);
xyzw = unproject(x, mRenderer.screenHeight - y, 1.0f);
Log.i("End of Ray", "x:" + xyzw[0] + " y:" + xyzw[1] + " z:" + xyzw[2]);
I use the following function
public float[] unproject(float rx, float ry, float rz) {
float[] xyzw = {0, 0, 0, 0};
int[] viewport = { 0, 0, mRenderer.screenWidth, mRenderer.screenHeight};
android.opengl.GLU.gluUnProject(rx, ry, rz, mRenderer.mViewMatrix, 0, mRenderer.mProjectionMatrix, 0, viewport, 0, xyzw, 0);
xyzw[0] /= xyzw[3];
xyzw[1] /= xyzw[3];
xyzw[2] /= xyzw[3];
xyzw[3] = 1;
return xyzw;
}
I get the following output
My POSITION: x:-1.857801 y:0.0 z:-8.655011
04-21
Start of ray: x:-1.8198236 y:-0.005848203 z:-8.688532
04-21
End of Ray: x:758.43915 y:-117.07846 z:-679.7136
Question
How do I work out if I have tapped on a cube at a position? Say the cube is at 1,1,1
I have tried this and it kinda works
float xDif = (xyzw2[0] - xyzw[0]) / 1000;
float yDif = (xyzw2[1] - xyzw[1]) / 1000;
float zDif = (xyzw2[2] - xyzw[2]) / 1000;
for (int i = 0; i < 1000; i ++)
{
if ((xyzw[0] + (xDif * i)) > mRenderer.cube.position.x - 1.0 && (xyzw[0] + (xDif * i)) < mRenderer.cube.position.x + 1.0 &&
(xyzw[1] + (yDif * i)) > mRenderer.cube.position.y - 1.0 && (xyzw[1] + (yDif * i)) < mRenderer.cube.position.y + 1.0 &&
(xyzw[2] + (zDif * i)) > mRenderer.cube.position.z - 1.0 && (xyzw[2] + (zDif * i)) < mRenderer.cube.position.z + 1.0)
{
Log.i("Hit cube", "HIT");
break;
}
}

Setting image view absolute position

I'm trying to manually set the image-view position within my app, the code is currently working but all the facebook images display at the top right and side on top of each other.
I do not have access to any adaptors, this is within the Facebook SDK, can anyone spot any problems with the following code:
My XML:
DisplayPhotos.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/DisplayPhotosLayout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</RelativeLayout>
This is set by the following:
fbManager = new FBLoginManager(this, R.layout.displayphotos, "-------", permissions);
Then I use the following to display images (working but all in same position)
int Row = 0;
int RowCount = 0;
int imageWidth = (int)getWindowManager().getDefaultDisplay().getWidth() / 3;
for(int _i = 0; _i < _noOfPhotos; _i++)
{
ImageView imageView = new ImageView(getApplicationContext());
imageView.setImageResource(R.drawable.no_image);
RelativeLayout.LayoutParams rl = new RelativeLayout.LayoutParams(imageWidth, imageWidth);
rl.setMargins(imageWidth * _i, imageWidth * Row, 0,0);
RowCount = RowCount + 1;
if(RowCount == 3){Row = Row + 1;RowCount = 0;}
UrlImageViewHelper.setUrlDrawable(imageView, _userGallery.get(_i).getPicture());
addContentView(imageView, rl);
System.out.println(imageWidth * _i + " top: " + imageWidth * Row);
_imageViewArray.add(imageView);
}
I think you need a table layout, http://developer.android.com/guide/topics/ui/layout/grid.html
i've found a trick to place an imageview at absolute position xy inside a relative layout. the following code place the CENTER of a imageview at x,y, even outside the relativelayout boundaries.
/*
* relativelayout allow out-of-boudaries only along the alignment side.
* if aligned to left then you can have a negative x and overlap the
* left side, if aligned to right you can overlap the right
*
* let's put the image CENTERED on x,y
*
* If we are on the left side of the container
* | (x<dx/2) |<---imgDx-->|
* | |____________|
* |
* | x
* |<----------------> |
* |<----------> x-imgDx/2 |
* |____________________________________|
*
* if we goes past the half of the container
* <---imgDx--> |
* | |____________| |
* | x |
* |<---------------------> |
* | <----->| dx-(x+imgDx/2)
* |____________________________________|
*/
public void setBitmapPosition(ImageView iv, int x, int y) {
String log = "";
RelativeLayout rl = (RelativeLayout) iv.getParent();
// get bitmap size
int imgDx = iv.getLayoutParams().width;
int imgDy = iv.getLayoutParams().height;
// get container size
int dx = rl.getWidth();
int dy = rl.getHeight();
log = log + " XY:" + new Integer(x).toString() + ","
+ new Integer(y).toString();
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
imgDx, imgDy);
iv.setLayoutParams(lp);
log = log + " imgXY:" + new Integer(imgDx).toString() + ","
+ new Integer(imgDy).toString();
log = log + " winXY:" + new Integer(dx).toString() + ","
+ new Integer(dy).toString();
if (x <= (dx / 2)) {
// i'm on the left side of the view so let's align to left
lp.addRule(RelativeLayout.ALIGN_PARENT_LEFT,
RelativeLayout.TRUE);
lp.leftMargin = x - imgDx / 2;
log = log + " LEFT:" + new Integer(lp.leftMargin).toString();
} else {
// align to right. we are past the middle
lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT,
RelativeLayout.TRUE);
lp.rightMargin = dx - (x + imgDx / 2);
log = log + " RIGHT:" + new Integer(lp.rightMargin).toString();
}
if (y <= (dy / 2)) {
// align to top
lp.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);
lp.topMargin = y - imgDy / 2;
log = log + " TOP:" + new Integer(lp.topMargin).toString();
} else {
// align to bottom
lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM,
RelativeLayout.TRUE);
lp.bottomMargin = dy - (y + imgDy / 2);
log = log + " BOTTOM:"
+ new Integer(lp.bottomMargin).toString();
}
iv.setLayoutParams(lp);
Log.i("PARAM", log);
}

Limit Scrolling on offline maps, in Android

I got these piece of codes or patches from osmdroid, and I decided to ask for your help guys because i don't have the enough knowledge to combine these codes to come up with on a solution on my problem, Scrolling limit on an offline map. I searched across the web, and modified tutorials. Honestly I tried to modify these codes but i have not found any progress. Basically I have an offline map from mapnik, and a few overlays. I don't know where to properly place these set of codes. Your ideas and modification will be a great help and also helps me keep going with my project and I guess your answers will definitely help others with the same problem as mine in the future. I know this is to much. Thank you sirs for your time, and God Bless.
public void onCreate(Bundle savedInstanceState) {
...
...
m_mapView = (MapView) findViewById(R.id.mapview);
m_mapView.setTileSource(TileSourceFactory.MAPNIK);
}
First: BoundingBox
BoundingBoxE6 bbox = new BoundingBoxE6(9.37398, 123.33761, 9.23948, 123.25035);
this.setScrollableAreaLimit(bbox);
Second: LimitScrollToGeographicArea.patch
Index: MapView.java
===================================================================
--- MapView.java (revision 944)
+++ MapView.java (working copy)
## -103,6 +103,8 ##
protected MapListener mListener;
+ protected Rect mScrollableAreaLimit;
+
// for speed (avoiding allocations)
private final Matrix mMatrix = new Matrix();
private final MapTileProviderBase mTileProvider;
## -505,6 +507,36 ##
mMapOverlay.setUseDataConnection(aMode);
}
+ /**
+ * Set the map to limit it's scrollable view to the specified BoundingBoxE6. Note that, like
+ * North/South bounds limiting, this allows an overscroll of half the screen size. This means
+ * each border can be scrolled to the center of the screen.
+ *
+ * #param boundingBox
+ * A lat/long bounding box to limit scrolling to, or null to remove any scrolling
+ * limitations
+ */
+ public void setScrollableAreaLimit(BoundingBoxE6 boundingBox) {
+ final int worldSize_2 = TileSystem.MapSize(MapViewConstants.MAXIMUM_ZOOMLEVEL) / 2;
+
+ // Clear scrollable area limit if null passed.
+ if (boundingBox == null) {
+ mScrollableAreaLimit = null;
+ return;
+ }
+
+ // Get NW/upper-left
+ final Point upperLeft = TileSystem.LatLongToPixelXY(boundingBox.getLatNorthE6() / 1E6,
+ boundingBox.getLonWestE6() / 1E6, MapViewConstants.MAXIMUM_ZOOMLEVEL, null);
+ upperLeft.offset(-worldSize_2, -worldSize_2);
+
+ // Get SE/lower-right
+ final Point lowerRight = TileSystem.LatLongToPixelXY(boundingBox.getLatSouthE6() / 1E6,
+ boundingBox.getLonEastE6() / 1E6, MapViewConstants.MAXIMUM_ZOOMLEVEL, null);
+ lowerRight.offset(-worldSize_2, -worldSize_2);
+ mScrollableAreaLimit = new Rect(upperLeft.x, upperLeft.y, lowerRight.x, lowerRight.y);
+ }
+
// ===========================================================
// Methods from SuperClass/Interfaces
// ===========================================================
## -772,10 +804,26 ##
//I am confused with these codes below, where should I declare it? Int x, y in the onCreate method?
x += (worldSize_2 * 2);
while (x > worldSize_2)
x -= (worldSize_2 * 2);
- while (y < -worldSize_2)
- y += (worldSize_2 * 2);
- while (y > worldSize_2)
- y -= (worldSize_2 * 2);
+ if (y < -worldSize_2)
+ y = -worldSize_2;
+ if (y > worldSize_2)
+ y = worldSize_2;
+
+ if (mScrollableAreaLimit != null) {
+ final int zoomDiff = MapViewConstants.MAXIMUM_ZOOMLEVEL - getZoomLevel();
+ final int minX = mScrollableAreaLimit.left >> zoomDiff;
+ final int minY = mScrollableAreaLimit.top >> zoomDiff;
+ final int maxX = mScrollableAreaLimit.right >> zoomDiff;
+ final int maxY = mScrollableAreaLimit.bottom >> zoomDiff;
+ if (x < minX)
+ x = minX;
+ else if (x > maxX)
+ x = maxX;
+ if (y < minY)
+ y = minY;
+ else if (y > maxY)
+ y = maxY;
+ }
super.scrollTo(x, y);
// do callback on listener
Another one:
scrollToMethod
public void scrollTo(int x, int y) {
int curZoomLevel = mZoomLevel;
final int worldSize_2 = TileSystem.MapSize(curZoomLevel) / 2;
Log.v("HELP", "Scrolling to X=" + x + " Y=" + y + " ZL=" + curZoomLevel + " - WW="+worldSize_2);
while (x < -worldSize_2)
x += (worldSize_2 * 2);
while (x > worldSize_2)
x -= (worldSize_2 * 2);
if (y < -worldSize_2)
y = -worldSize_2;
if (y > worldSize_2)
y = worldSize_2;
if (mScrollableAreaLimit != null) {
int targetZoomLevel = getZoomLevel();
final int zoomDiff = MapViewConstants.MAXIMUM_ZOOMLEVEL - targetZoomLevel;
//final int zoomDiff = MapViewConstants.MAXIMUM_ZOOMLEVEL - mZoomLevel;
final int minX = mScrollableAreaLimit.left >> zoomDiff;
final int minY = mScrollableAreaLimit.top >> zoomDiff;
final int maxX = mScrollableAreaLimit.right >> zoomDiff;
final int maxY = mScrollableAreaLimit.bottom >> zoomDiff;
Log.v("HELP", "Limit: minX=" + minX + " maxX=" + maxX + " minY=" + minY + " maxY=" + maxY + " ZL=" + curZoomLevel + " ZLTarget="+ targetZoomLevel + " ZD="+zoomDiff);
if (x < minX) {
Log.v("HELP", "!!! X=" + x + " minX=" + minX + " CORRECTION:" + (minX-x));
x = minX;
} else if (x > maxX) {
Log.v("HELP", "!!! X=" + x + " maxX=" + maxX + " CORRECTION:" + (maxX-x));
x = maxX;
}
if (y < minY) {
Log.v("HELP", "!!! Y=" + y + " minY=" + minY + " CORRECTION:" + (minY-y));
y = minY;
} else if (y > maxY) {
Log.v("HELP", "!!! Y=" + y + " maxY=" + maxY + " CORRECTION:" + (maxY-y));
y = maxY;
}
}
super.scrollTo(x, y);
// do callback on listener
if (mListener != null) {
final ScrollEvent event = new ScrollEvent(this, x, y);
mListener.onScroll(event);
}
}
First of all use this command on your terminal:
svn checkout http://osmdroid.googlecode.com/svn/branches/release_3_0_5
It will download a stable version
Then follow this to import contents of the folder you downloaded:
In Eclipse, right-click on the Package area, and select the following:
click on Import...
select General -> Existing Projects into Workspace
click Next
click Browse...
select the checked out projects' directories
osmdroid-android (import as a java project)
OSMMapTilePackager (import as a java project)
OpenStreetMapViewer (mport as an android project)
click OK
click Finish
Now open this java file-->
osmdroid-android/src/org/osmdroid/view/MapView.java
Now as stated in this patch file, modify MapView.java ( add
code wherever + , remove code wherever -)
Also modify computeScroll() in MapView.java as stated here
Now, to use this modified .java file, you need to create a new jar
file that you can include in your project
Here is a step by step process to create jar
Add this newly created jar file to your project's build path and you
are ready to use your modified jar
Now use this in your activity class:
BoundingBoxE6 bbox = new BoundingBoxE6(limit north, limit east, limit south, limit west);
mapView.setScrollableAreaLimit(bbox);

Categories

Resources