Android: Button representing "get my position!" - android

I have a EditBox, and on right side of this EditBox I wan't to put a Button representing "Get My Position".
User clicks on this button, and my application get his position and fills EditBox with it.
I found a Compass and added on a ImageButton, but I don't know if this really represent the idea.
Anyone knows a better button to represent "Get My Position"?
Thanks

Your Button looks ok, and will be recognized by most users. If you want to get the System-default (the picture of the Drawalbe may differ on roms from HTC, Samsung Motorola etc) you can get it with
getResources.getDrawable(android.R.drawable.ic_menu_location)
Always check for non-Null here. You can download the standart Android location Button here, (ic_menu_location), as a fallback, if the getDrawable() call fails

I used a 'globe' in my application. If the EditBox is blank until the user requests their location, why not use the put some default text inside it requesting the user to click the button?

Related

How to stop Accessibility from announcing android button as "button"?

I have a button in Android which has text "Next" written on it.
when, I have the accsessibility cursor focus on the button, it reads out "Next button". This is something I don't want. I want whenever, the cursor to have focus on the "Next" button, it must read out as "Next button. Double tap to select". This I can easily do, by setting the
btn.contentDescription("Next button. Double tap to select"),
but then it reads out as
"Next button. Double tap to select button", means it additionally reads out the last button, which seems very odd, with the "button" text getting read twice.
Is there any way, by which I can stop the last button to be announced?
You're trying to do things that are the responsibility of the AT. The AT knows that the object is a button due to its class type. The AT knows that it is clickable, because Clickable is a valid accessibility action.
TalkBack will then share this information, here is the breakdown:
"Next button, (pause) double tap to select"
"Next" -> Content Description/Text. This is the part you control.
"Button" -> Calculated in TalkBack based off of the valid actions and type(class) of the object.
"Double tap to select" -> This announcement is based off of Clickable being a valid accessibility action.
SO, when you set the contentdescription to "Next ....." you end up with an announcement of "next ....... button (pause) double tap to select" and no, there is no way to override this.
IF you are absolutely intent on making your app less accessible, you could create a custom control, write your own gesture recognizers (as in not using "onClick" events, because this would make your element accessibility clickable) to recognize tap gestures. And then write your own content description, that includes name, role, and instructions yourself.
This would be very silly in my opinion! Just let the content-description be "next" and let TalkBack tell users that your element is a button and how to interact with it. While perhaps not the "perfect" wording you/whoever this requirement came from's vision. It will be the way TalkBack users are accustomed to having this type of control announced. Consistency is sometimes more important than having things "just so".
I know I'm way late to the game, but posting an answer here for anyone that may happen to come across this post.
The others are right... we should not be putting the type of widget or how to interact with the widget in the content description. However, all is not lost.
Starting with API 21, there is a way to customize the interaction text through AccessibilityNodeInfo. You can use this class in two different ways:
AccessibilityNodeInfo has a getActionList() method. You can add customize the text that is read out by TalkBack by adding a new item to that list:
info.getActionList().add(new AccessibilityNodeInfo.AccessibilityAction(AccessibilityAction.ACTION_CLICK, "select");
The above code should change "Double-tap to activate" to "Double-tap to select". I say should because I'm just writing that code from memory... I haven't verified it's 100% correct, but it should be something along those lines.
There are two ways to utilize that class, and the one you choose is going to depend on your situation.
Method 1: Subclass your view:
If you create a subclass of the view you are using (in the case of the OP it would be a subclass of Button) then you can override the onInitializeAccessibilityNodeInfo() method and put the code there.
Documentation: https://developer.android.com/reference/android/view/View.html#onInitializeAccessibilityNodeInfo(android.view.accessibility.AccessibilityNodeInfo)
Method 2: Create a view accessibility delegate
This can be a bit more tricky and involved, but it does offer a ton of flexibility because you don't have to subclass the views you are working with.
Every view has a method that allows you to set an accessibility delegate, which acts like a man-in-the-middle and you can tweak things for accessibility purposes before the info goes to TalkBack.
Documentation: https://developer.android.com/reference/android/view/View.html#setAccessibilityDelegate(android.view.View.AccessibilityDelegate)
So basically you create a subclass of View.AccessibilityDelegate and override it's onInitializeAccessibilityNodeInfo() method with the code I posted above.
Documentation: https://developer.android.com/reference/android/view/View.AccessibilityDelegate.html#onInitializeAccessibilityNodeInfo(android.view.View,%20android.view.accessibility.AccessibilityNodeInfo)
Last but not least...
I did come across a way to stop the "Double tap to activate" text from being spoken out by Talkback. This should only be used when it really does make sense to remove it.
I repeat... this is not normally something you want to do.
I did recently come across a case where it made sense. I was using a TabLayout, and I noticed that Talkback would always read out "Double-tap to select" when the focus was on the selected tab (yes, I had used the method described above to change the text). Well... we don't want to tell the user to select a tab that is already selected, especially when the action results in a no-op. So, I used this little trick to get rid of that, but only for the currently selected tab. I left the unselected tabs alone so that Talkback would still give them the interaction text.
In your onInitializeAccessibilityNodeInfo() method, you can put the following code to remove that text:
info.addAction(AccessibilityNodeInfo.ACTION_FOCUS);
Again, I'm writing this code from memory, so I don't know if that's 100% there, but it gives you the gist of what to do.
Try to uncheck the setting in TalkBack -> verbosity -> speak element type -> uncheck. Now talkback will not announce class type of view at end of content description.
What you want to do is employ android:hint to provide information on inputting information (instead of adding it to the label).
Your label would be "Next" (either using labelFor with an onscreen label or android:contentDescription for hidden labeling)
Then your hint would be "Double tap to select" (using android:hint)

Android:: Highlight a non-selected button

I am working on a game project.
I have 4 buttons on my screen. User has to select one of the 4. If user selects the correct one, it works fine. but if user selects incorrect one, I want to highlight the correct answer even though user didnt clicked it.
I have presentation due tomorrow. Can anybody point me to some example source or explain it here, as to how can I accomplish it.
You can set the correct buttons background color or image while clicking other buttons
Whenever user clicks on the incorrect button simply call :
correctButton.setPressed(true)
This will highlight the correct button as per your requirement.
you can do one thing..
Call Button.requestFocus() method to get the focus.
Create a custom selector for you Button's background. there
< item android:state_focused="true" android:drawable="#color/your_color" />

Android map view (dropping a pin and moving it, add a custom label to it)

I wan't to create a map view like in ACL2011 app.
here I list it's details and my progress.
It has several location tags and those containing deferent icons - I can't do it(I can set one tag for all the places but can't put different tags.
it has drop a pin(drop a pin to a specific location - I can do this.
the dropped pin can move( long press on it allow user to move the pin) - cant do it
one user tap on the dropped pin it shows a label with two buttons - can't do this
Please help me...
I tried a lot but I still can't do it. found one with moving pin but I did't able to apply other functions to that.
thanks in advance.
Try this project

Android call search function programmatically

In Google Maps, when you click the search box the real search comes up. The search box is just an imageview illusion with an onclicklistener
similarly, if you press the search button on the mobile device, the search box comes up.
I need to implement similar behavior, when the user clicks an image that is over the map (in a relativelayout), the search box for that mapview comes up.
how would I call the mapview's search feature??? I was thinking of just simulating a search button press but I dont even know what this function's name is.
Thanks for the insight!
The function you are looking for is onSearchRequested(). Just make a call on your onClickListener. Complete guide to search implementation can be found here.
http://developer.android.com/guide/topics/search/index.html

popup windows in android?

Pretty new to android so excuse me if this is a really obvious question.
Say my application has a bunch of TextViews, each one showing the attributes of a certain product (name, price, etc). I have a button next to each of these TextViews labeled "modify".
How do I make it so that when I press the modify button next to a certain attribute, a popup window with a space to enter text into comes up so that the user can enter text into this box and then have the actual attribute listing on the original page change? Actually I just need a push in the right direction with creating this popup text field... not sure if there is already some built in functionality for this or if not, what would be the best way to create this kind of thing.
Thanks.
Why not have the modify button set TextEdit.setEnabled(true); and then change focus with TextEdit.setFocus? Note that both of these are inherited from view
If you really want a dialog you might want to looking into the AlertDialog.Builder. I know you can use it with buttons and radio buttons, but I'm not sure you can get it to work with a TextView.
Use a code like this for the input popup: Android dialog input text
In the positive button handler, set your edittext content programmatically like this:
myEditText.setText(value).
As simple as that. The only difference with a standard GUI framework is that you don't retrieve the value as a result of the popup function. Instead, you must provide an action handler.

Categories

Resources