Keep Size Image with Ground Overlay in Google Map - java

I'm new in Android and I'm building an app. My problem is that when I want to put my own image in google map app using Ground Overlay.
But When I put my images, I can't keep the size, it very small and when I zoom it is the real size. What I would like to have it's when I zoom it keep the same size.
For example in Booking App, The "H" image is always at the same size (Airbnb had the same also).
Here is my code:
#Override
public void onMapReady(GoogleMap map) {
// Register a listener to respond to clicks on GroundOverlays.
map.setOnGroundOverlayClickListener(this);
map.moveCamera(CameraUpdateFactory.newLatLngZoom(NEWARK, 11));
mImages.clear();
mImages.add(BitmapDescriptorFactory.fromResource(R.drawable.newark_nj_1922));
mImages.add(BitmapDescriptorFactory.fromResource(R.drawable.newark_prudential_sunny));
mImages.add(BitmapDescriptorFactory.fromResource(R.drawable.logo_franprix));
//Resources res = getResources();
//Drawable drawable = res.getDrawable(R.drawable.ic_logo_franprix);
// Add a small, rotated overlay that is clickable by default
// (set by the initial state of the checkbox.)
mGroundOverlayRotated = map.addGroundOverlay(new GroundOverlayOptions().image(mImages.get(2)).anchor(0, 1)
.position(new LatLng(48.886517, 2.37105), 300f,300f));
I hope that you could help me, thank you very much.

Related

Android Google Maps v2: customized marker with large click area

Related: Customizing clickable area on a Marker in Google Maps v2 for Android
I have a number of icons inside an ArrayList, which are all custom icons with a drawable. The problem I have is that the clickable area is that of the default marker. I need to customize this clickable area to the same size of the default marker.
Here is my code to generate a set of markers on the map:
MarkerOptions options = new MarkerOptions();
for (Icon iconItem: icons) {
//Scale icon
int markerSize = 90;
Bitmap iconBitmap = BitmapFactory.decodeResource(getResources(), iconItem.resourceInt);
Bitmap scaledIconBitmap = Bitmap.createScaledBitmap(iconBitmap, markerSize, markerSize, false);
options.position(iconItem.location).title(iconItem.type);
Marker newMarker = gMap.addMarker(options);
newMarker.setIcon(BitmapDescriptorFactory.fromBitmap(scaledIconBitmap));
}

Android ImageView scale and zoom replace image

I'm trying to build an simple image-zoom-replace functionality based on the Image-Zoom-Library "PhotoView":
https://github.com/chrisbanes/PhotoView
I just want to load a small image into a imageView and zoom/scale it. This code works perfectly:
ImageView galleryPictureNew = (ImageView)findViewById(R.id.galleryImage);
PhotoViewAttacher mAttacher = new PhotoViewAttacher(view);
mAttacher.update();
The problem is, i want to replace the small image with a large (hd-image) if i zoom in.
There is function called "setOnScaleChangeListener" like this:
mAttacher.setOnScaleChangeListener(new PhotoViewAttacher.OnScaleChangeListener() {
#Override
public void onScaleChange(float scaleFactor, float focusX, float focusY) {
//REPLACE IMAGE
}
});
This code above works, too BUT i want to "jump" to the last "position" and "zooming-level"?!
Does anyone has a solution for it?
Or maybe someone has an alternative library for this problem?
Do i have to save the last "position-state"?

LayoutTransition animation on ExpandableListview does not work properly

I want to apply a simple rotationX animation when a group expands/collapses on an ExpandableListView. The code below works in first two expands but after two/three/five times does not play the defined animation. The strange thing is that the first time that I expand /collapse it works perfect!
ExpandableListview exp = new ExpandableListview(context);
// set adapter code
LayoutTransition transition = new LayoutTransition();
Animator appearAnim = ObjectAnimator.ofFloat(null, "rotationX", 90f,0f).setDuration(transition.getDuration(LayoutTransition.APPEARING));
transition.setAnimator(LayoutTransition.APPEARING, appearAnim); // I also tried first argument equals DISSAPEARING, CHANGING, etc
exp.setLayoutTransition(transition);
Any idea?? Is this approach totally wrong???
I have to notice at this point that this is not a duplicate! I am looking for a solution that will be approached with LayoutTransition class / methods.
Here is some awesome sample which may help you to do animation on expands/collapses on an ExpandableListView, In the android-flip library that uses OpenGL for rendering animation ,if the minimum supported Android version for the app was 4.0 we can use standard Android SDK methods instead of OpenGL: View.setRotationX(), View.setScaleX(), etc. When hardware acceleration is enabled (and it is enabled by default if your target API level is >=14), these methods work quite efficiently using the device GPU.
You can use this FoldableLayout to implement folding animation for expands/collapses on an ExpandableListView.
Layout implementation in FoldableLayout:
The first element to design was a layout that can fold in half. Our
approach was rather bold: the main layout (FoldableItemLayout) simply
contains a specialized layout (BaseLayout). During the animation, the
BaseLayout writes its contents to cache which is a specially created
Bitmap object based on the size of the original layout. view plaincopy
to clipboardprint?
class FoldableItemLayout extends FrameLayout {
#Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
Bitmap cacheBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
mBaseLayout.setCacheCanvas(new Canvas(cacheBitmap));
}
}
class BaseLayout extends FrameLayout {
private Canvas mCacheCanvas;
private void setCacheCanvas(Canvas cacheCanvas) {
mCacheCanvas = cacheCanvas;
}
#Override
public void draw(Canvas canvas) {
mCacheCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
super.draw(mCacheCanvas);
}
}
In addition, we needed to use two extra Views (PartView) – for the
upper and lower image halves – which would display the corresponding
data in cache that represents the upper and lower halves of the image
(Bitmap). Both Views encompass the entire area of the main layout, but
display only the required parts. To achieve this effect, we calculated
the Bitmap limits – and in the onDraw() method we made Canvas draw the
required part via the drawBitmap (Bitmap bitmap, Rect src, RectF dst,
Paint paint) method.
Then we managed to rotate these extra Views by setting the
setRotationX() method to the corresponding angle, achieving
independent rotation of the lower and upper parts of the images. To
pull this off, we add a new parameter for the FoldableItemLayout –
with the name FoldRotation.
Source: How to Make a Paper Folding Animation in Android?

IllegalArgumentException: width and height must be > 0 while loading Bitmap from View

I'm trying to draw on an ImageViewTouch, a library which enables pinch zooming. I'm able to draw over the image using Canvas, but when I zoom the image, the drawing disappears.
For this, I'm trying to convert the view to a bitmap and set theImageBitmap for this same view. Here's the code:
mImage.setDrawPath(true);
mImage.setImageBitmap(loadBitmapFromView(mImage));
public static Bitmap loadBitmapFromView(View v) {
Bitmap b = Bitmap.createBitmap( v.getWidth(), v.getHeight(), Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(b);
v.layout(0, 0, v.getWidth(), v.getHeight());
v.draw(c);
return b;
}
When I do this, I get the following log error:
07-11 21:13:41.567: E/AndroidRuntime(20056): java.lang.IllegalArgumentException: width and height must be > 0
07-11 21:13:41.567: E/AndroidRuntime(20056): at android.graphics.Bitmap.createBitmap(Bitmap.java:638)
07-11 21:13:41.567: E/AndroidRuntime(20056): at android.graphics.Bitmap.createBitmap(Bitmap.java:620)
If I remove the loadBitmapFromView call the drawing normally appears over the image. When I try to do any interaction with the image (like zooming in or out), the drawing disappears, remaing only the background image, which is a picture.
--- EDIT ---
Here's some more code placed after the loadBitmapFromView call. The case is: I have a radio group listenner and when I check some radio button, I have to load the image and draw some possibles drawings over it.. then I'm trying to convert everything (the image and the drawings) into only one bitmap.
Here's the ohter part of the code:
bitmap = BitmapUtils.decodeSampledBitmapFromResource(root + DefinesAndroid.CAMINHO_SHOPPINGS_SDCARD + nomeImagemAtual, size.x, size.y);
mImage.setImageBitmap(bitmap);
After that, I draw everything I have to draw and try to convert the view to bitmap using the loadImageBitmap method I have shown.
the decodeSampledBitmapFromResource method I got from this link on android developers http://developer.android.com/training/displaying-bitmaps/load-bitmap.html
I finally figured out a solution for my problem.
I'm using the post method of the View, which will be executed only after the view measuring and layouting, this way getWidth() and getHeight() returns the actual width and height.
Here's the code sample:
mImage.post(new Runnable() {
#Override
public void run() {
mImage.setImageBitmap(loadBitmapFromView(mImage));
}
});
Hope it also helps someone else :)
If everything else is correct you are executing your code too early.
The view's layout has not yet been measured by Android. Try executing in OnResume just to see if this is your problem.
Cheers!
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
loadBitmapFromView(mImage);
}
}, 1000);
java.lang.IllegalArgumentException: width and height must be > 0 is because in your Bitmap.createBitmap() call v.getLayoutParams().width or v.getLayoutParams().height is 0. Probably the LayoutParams are wrongly set in mImage.
Update: setLayoutParams() for the mImage before using createBitmap(). Something like this:
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(30, 30);
mImage.setLayoutParams(layoutParams);
In my case, I forgot to set orientation to vertical for parent LinearLayout and the default value of horizontal has been set, so I set it and my problem gone...
android:orientation="vertical"
I'm not sure if it relates to this specific question , but I had the same error and I solved it with getting a image source , in the layout xml file , from drawable instead of from mipmap (of course I had to put the image there before).

Set size for checkbox image in libgdx UI

I can't figure out how to manage checkbox images size. Of course, it is possible to create different size of image in my Texture atlas and take appropriate one, but I don't want to do that.
Here is my code:
AtlasRegion checkboxOn = AssetsHelper.textures.findRegion("checked");
AtlasRegion checkboxOff = AssetsHelper.textures.findRegion("unchecked");
CheckBoxStyle checkBoxStyle = new CheckBoxStyle();
checkBoxStyle.font = AssetsHelper.font66yellow;
checkBoxStyle.checkboxOff = checkboxOff;
checkBoxStyle.checkboxOn = checkboxOn;
CheckBox cbSound = new CheckBox(" Sound", checkBoxStyle);
cbSound object doesn't have such methods to rezise image of checkbox, but there is method getImage(), but seems it doesn't work too.
This is not working:
cbSound.getImage().width = 120;
cbSound.getImage().height = 120;
FYI: for example, when I wanted to draw image I did like that:
batch.draw(textureRegion, 0, 0, widthIwant, heightIwant);
But in CheckBox class there is overrided only this (without setting width and height):
public void draw (SpriteBatch batch, float parentAlpha) {
image.setRegion(isChecked ? style.checkboxOn : style.checkboxOff);
super.draw(batch, parentAlpha);
}
Question: how can I change width and height of checkbox image?
Thanks in advance.
The libgdx widgets are using drawables for drawing images. A drawable gets automatically scaled to fit the cell it is in. So in order to change the image size, change the cell size:
cbSound.getCells().get(0).size(widht, height);
For better results, you should use a nine patch for the drawable.
You need to set the image scaling type. Also method getImageCell is more correct than method getCells().get(0). Default is none.
CheckBox soundCB = new CheckBox("Sound", uiskin);
soundCB.getImage().setScaling(Scaling.fill);
soundCB.getImageCell().size(GameConfig.WIDTH/6);
soundCB.left().pad(PAD);
soundCB.getLabelCell().pad(PAD);
//...
content.add(soundCB).width(GameConfig.WIDTH/1.5f).row(); //add to table

Categories