How does the GMail app implement its selection summary in ActionBar? - android

When an email is selected for deletion in the GMail app, the ActionBar looks like so:
There is a check mark and selection count displayed, with a subtle entry and exit animation. It appears it's an overlay that's on top of the ActionBar or replaces it.
Since I don't know the name of this widget I have trouble finding info about it.
Is it part of the API? Google Calendar has a similar overlay when creating an event, which makes me think it's possibly part of the API.
If it is, what is it called?
How is the ActionBar updated with the row selection count? (No need for code, just a brief explanation would be helpful on how to write content to the the ActionBar overlay shown in the image).

Providing a partial answer to my own question. Hope this helps someone.
It's part of the API since Level 11 and is called contextual ActionMode. The idea is to enable the user to perform some specific action without leaving the Activity or Fragment. The references docs describe it like so:
Represents a contextual mode of the user interface. Action modes can be used to provide alternative interaction modes and replace parts of the normal UI until finished.
Android Developers have a section on it, saying:
The contextual action mode is available on Android 3.0 (API level 11) and higher and is the preferred technique for displaying contextual actions when available
There is a tutorial by Lars Vogella with a screen shot showing it's the same kind of overlay as seen in the GMail app.
Here is a screen shot from Android Developers (screen shot is licensed under Apache 2.0):

First it is not the part of the API and to update the count in action bar just add a listener for check box upon check increment the count and upon un-check decrements the count so simple :)
Update
alternately you can use this custom action bar

Related

Is it possible to create a custom floating text selection menu in Android versions pre Marshmallow?

I'm looking to create a custom menu for text selection. I know it's possible to edit the behaviour of the action bar with setCustomSelectionActionModeCallback, but in my case I don't want that action bar to show at all, I want my own floating custom menu which I have already achieved.
Only thing is that there is no way to not show the action bar menu after selecting the text in the TextView.
The behaviour I need is not the standard cut/copy/paste, the actions I have implemented are for highlighting and saving the highlighted section of text to a database.
I have done some tinkering and the best I could do was a messy reflection idea whereby I returned false in onCreateActionMode and got references to the text selection handles through reflection. It half worked and it's just as well because any form of reflection in this case is very bad practice.
My hope was that the last support library would have included the floating text menu in 6.0, and I though I could implement my own custom view in that menu, but that's wishful thinking.
If anyone has any ideas or libraries that might be of use then I'm all ears.
As you already noticed, using reflection is one of the ways. I'm pretty sure that it's the only one. If you're interested in what I did with that menu, check out Carbon. Its EditText does pretty much what you need, but with reflection as well.
The code snippet is way too long to paste it here, but here are the links:
https://github.com/ZieIony/Carbon/blob/master/carbon/src/main/java/carbon/widget/EditText.java
https://plus.google.com/109054799904873578131/posts/BH6r9J5gnw6
Basically I'm hiding the fancy Samsung's menu, disable the standard Action Mode and show my own popup window with options connected to standard copy/paste click handlers.

Buttons in the action bar vs on screen

I have a question that is more about the user experience than a technical issue. As such, it may not belong here (let me know if it doesn't) but it's something that's bothering me.
I'm building an application to help with learning English which has a quiz section with multiple choice questions. Most of the applications like that (including my old applications developed for Android 2.x) have a layout of the screen that goes like:
Answer 1
Answer 2
Answer 3
Button "Check"
Button "Skip"
The user selects an answer and clicks the button to check it and go to the next question. If they don't want to answer the question, they press Skip. That layout is quite intuitive and easy to grasp.
Now, I would like to use the action bar for all the actions the user may take. My problem is that while having Next action is ok (with the icon of arrow pointing right), adding another action of Skip makes the action bar unclear. Is just my inability to come up with the right icon for skipping? Or is it a problem with the icons in the action bar not necessarily being easy to understand and use?
What do you think?
The ActionBar is not the place for such actions.
UI-wise, the hierarchy of of an app such as your should be (imo):
ActionBar with general actions (for example settings , share question...)
Question
Answers
Check and Skip
From top to bottom
I usually prefer to put buttons belonging to the content (such as the question) WITH the content. Then I find buttons that interact with the app as a whole to belong to the action bar. It can also be used if it interacts with multiple content items on single screen (more common on tablets
For example putting a login button in a login screen in the action bar would be kinda awkward..
Im no UI expert by any means though
Action Bar would be better for your situation.. try drawing your idea about the UI in a piece of paper, that really helps a lot about UI decisions

Number of menu button that is guaranteed to be shown in ActionBar

I did quite a lot of research, but couldn't find an answer for this one. The main quote I am starting from, is from the official android developer site:
"If you believe that more than four of your menu items can be justified as action items[...]"
This indicates me, I can safely use 4 menu buttons. At the moment, I am using 3 menu buttons on my main screen, but by popular demand, I am refactoring the mentioned main screen, which causes the need of exactly 4 menu item buttons.
My question is: are 4 standard size, only image buttons are guaranteed to be shown at ALL times, on EVERY device? So the top of the screen would look something like this in ALL cases:
_____________________________
|[I] ASD [1] [2] [3] [4]|
-----------------------------
Where [I] is the App icon, "ASD" is the label of the Activity(which is exactly 3 letters), [1], [2], [3], [4] are the menubuttons, each of them is a simple image.
Thanks in advance, cheers.
This indicates me, I can safely use 4 menu buttons
I think you are reading too much into that sentence, wherever you got it from.
are 4 standard size, only image buttons are guaranteed to be shown at ALL times, on EVERY device?
No.
First, device manufacturers can tinker with Android and may affect the behavior of the action bar on their devices. Now, the odds are that they will leave this alone, but "odds are" != "guaranteed". Even if the number of action bar items were mandated as part of compatibility testing (and AFAIK it is not), there are device manufacturers exempt from such testing because they do not license the Play Store or other Google commercial apps.
Second, on a -small screen device, four buttons might well be too many. Two might be too many, in portrait at least. I have not experimented with either ActionBarSherlock or the native API Level 11+ action bar on a -small device recently and so do not know how many action bar items it supports.
Moreover, any action bar items that do not fit into the action bar will go into the overflow (triggered via the MENU button on devices that have them or a "..." affordance in the action bar for those that don't), so the user can still access those things even if the icons are not visible for one reason or another.

Custom options menu in Android

I want to create a custom OptionsMenu in my application. The default OptionsMenu display only three items in one row. Now i want to display five to six items having only icons. Also i want to change the background color of the OptionsMenu but not getting the appropriate way of doing this. If it is possible then please let me know about it.
Short answer
As an user it bothers me when the application changes my android's widgets. I wouldn't recommend changing that and android doesn't provide a way to do it.
Long answer
Even though Android doesn't provide a way to customize that you can always handle the key event and show a view from your own. Similar discussion in stackoverflow.

horizontal bar slider

I am looking for a class that implement a horizontal slider bar like the one on the "lock" screen. In other words, user must slide the bar from left to right to run an activity. Thank you so much for your time.
Internally, Android uses a class called SlidingTab for this (the main lockscreen is in a file called LockScreen.java. As with all Android core code, it's Apache licensed. At the risk of sounding like a broken record here on SO, download the AOSP and read through the code whenever you have a "how did the Google folks do x?" type of question (or even when you don't; there's some good stuff in there).
Maybe a Seek Bar might help you towards a solution to your problem. If this works for you let me know, because i am interested in a solution to that as well. Thanks
The link is the developer document for that feature.
Here is an example that extends a horizontal ProgressBar so that the user can set the "progress" by sliding left/right. It's actually quite straight forward, it just overrides the onTouchEvent() method, does some minor mathematics and sets the progress value depending on the TouchEvent's X coordinate.

Categories

Resources