Java Android AlertDialogs Show on infowindow OnClick for google maps v2 - java

i would like to ask a question with regards to AlertDialogs which i would like to use in GoogleMaps V2. I read about the custom InfoWindow documentation from the android developers and noticed that they advised not to put any interaction widgets (Buttons, Textbox etc etc) onto an OnClick function. Now, i would like to know if i could use a default alert dialog and put it into an OnClick function for the custom InfoWindow. Is it possible?

Yes that should work fine. The reason why you should not (and cannot, really) put interactive elements in an InfoWindow is because the InfoWinow is statically rendered when shown, making any interactive elements you place in it effectively useless.

Related

Show + Hide / Toggle Soft Keyboard and get what has been typed

I am currently developing a simple library for making games on Android. I am almost done and only want to add a few more features. One feature I would like to add is a method that would show / hide the onscreen-keyboard (soft keyboard). I want to get whatever has been typed and return it using another method.
My codebase consists of an Activity that gets launched and a SurfaceView that does the rendering and touch input (and some other classes for the gameloop, sprites, sound and so on). As this is supposed to be a small library I don't want to mess with the XML.
How would I go on about showing+hiding/toggling the keyboard and receiving it's inputs?
Keyboards work via an InputConnection. I you focus a View in your app, the framework will call getInputConnection on that view. If the view returns non-null, it will send all the data from the keyboard and map it to function calls on the InputConnection. So all you need to do is override that function on your SurfaceView and have it return a custom InputConnection.
InputConnection is a large api, but the most important ones for you to implement are commitText (which sends a string of text from the keyboard to the view) and deleteSurroundingText (used for deletion). The rest of the api should be implemented as well, but those are the main ones.

How to apply the one ripple drawable for multiple buttons dynamically in Java?

I want to apply the same ripple drawable properly on multiple buttons. But it's not happening because, the ripple effect is only getting applied on the last button. I have also used gradient drawable inside the ripple drawable. That works fine on every button. It just the ripple effect is not getting applied on any button except the last button. It is also not working on api level 8. I know that this method doesn't work on apis before api level 21. But I haven't found any tutorial on dynamic button design.
I'm doing everything inside the on-create event. I can't write the codes outside of the on-create event and also can't use any XML for this particular situation I'm in.
Here's the output:
Here's the code:
android.graphics.drawable.GradientDrawable gd_btone = new android.graphics.drawable.GradientDrawable();
gd_btone.setCornerRadius(4);
gd_btone.setStroke(2, Color.parseColor("#ffffff"));
gd_btone.setColor(Color.parseColor("#232323"));
android.graphics.drawable.RippleDrawable ripdr = new android.graphics.drawable.RippleDrawable(new android.content.res.ColorStateList(new int[][]{new int[]{}}, new int[]{ Color.parseColor("#888888")}), gd_btone, null);
button1.setBackground(ripdr);
button2.setBackground(ripdr);
button3.setBackground(ripdr);
button4.setBackground(ripdr);
Also, can anyone help me to make this piece of code back-compatible with api level 8 and how to set margin on this drawable?
I'm not a Android developer so I don't know much about it.
What I see is that the dripple effect is applied to the last button, even when the other buttons are clicked. Because of this, I am thinking that the RippleDrawable class does not support the kind of behavior you are looking for; a single instance can only be bound to one button at a time.
I would suggest simply creating four separate RippleDrawable instances.
Disclaimer: I have not worked with RippleDrawables, but this is purely based on the output you've provided and personal experience with Android development.

How to make a dialog but with the ability to set its content with a custom xml?

In my android app, I want to make a dialog box, the kind of one you get from alertbuilders, where you get access to set positive/neutral/negative button click, but I also want to use the .setcustomview() to load the content with my xml file.
Does android have a way to do this? I want to avoid making those buttons...
Thanks
I don't see a setcustomview() method for the AlertDialog.Builder class, but I do see a setView() method, if that's what you mean. :)
From my experience, using setView() will allow you to set your custom XML layout (though you will still need to inflate it first) without requiring you to recreate / add buttons to your layout. You just need to call the setXxxButton() methods before you build.

Button on android map annotation

After a while of googling I cannot find what I need, I see some libraries which look to do it but I have already implemented the system using androids default methods.
I set the markers like so:
theMap.addMarker(new MarkerOptions()
.position(new LatLng(lat, lon))
.title(title)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.pin_map32))
.snippet(strap));
However I need a 'detail disclosure button' like on iOS (transitioning app from iOS to Android) and I can't seem to add a button to the marker - is it possible using androids system?
This cannot be done.
from the docs
Note: The info window that is drawn is not a live view. The view is rendered as an image (using View.draw(Canvas)) at the time it is returned. This means that any subsequent changes to the view will not be reflected by the info window on the map. To update the info window later (e.g., after an image has loaded), call showInfoWindow(). Furthermore, the info window will not respect any of the interactivity typical for a normal view such as touch or gesture events. However you can listen to a generic click event on the whole info window as described in the section below.
in other words you cannot put a button in the infowindow and be able to use it. You will need to use a dialog of sorts if you want to do something like that
There is always some way.
A nice hack can be found here: https://stackoverflow.com/a/15040761/2183804
I haven't tested it myself, but from the comments there (and the amount of upvotes) we can deduce it works well.
You can track clicks only on Marker. If you want a button on marker - click on marker & show a dialog with buttons.

Google Maps API v2 for Android using FEATURE_ACTION_BAR_OVERLAY

I was viewing a different question Google Maps Android API v2 - Interactive InfoWindow (like in original android google maps) and as you can see he's using the requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY); to make the map v2 use the full screen. I tried this but the my location button is partially covered by the action bar on mine unlike his. Does anyone know how to move it down slightly?
Thanks!
Unfortunately you don't have any control over this button. Obviously, you can search for this button id in android sources and change layout params manually from the code, but I definitely wouldn't do that.
This button is super easy to implement yourself. So I recommend to disable built-in "locate me" button and implement your own which will be positioned right below the action bar.
To disable it use:
googleMap.setMyLocationEnabled(false);
New button onClick method content:
googleMap.animateCamera(CameraUpdateFactory.newLatLng(new LatLng(googleMap.getMyLocation().getLatitude(),
googleMap.getMyLocation().getLongitude())));
You can just get the view by its id and re-set the top margin Apparently the id is always 2, but this isn't documented and your app will break when/if the id ever changes. Like Pavel said, it's safer to make your own location button and wire it up.
Unfortunately, calling ActionBar.getHeight() in your onCreate will always return 0 since layout hasn't finished. The way to get the real heigh is by using a listener on the ViewTreeObserver:
mainLayout.getViewTreeObserver().addOnGlobalLayoutListener(
new ViewTreeObserver.OnGlobalLayoutListener() {
public void onGlobalLayout() {
int actionBarHeight = getActionBar().getHeight();
// TODO: set margin of views dependent on actionbar height
// remove the listener
mainLayout.getViewTreeObserver().removeGlobalOnLayoutListener(this);
}
}
}

Categories