ContextMenu with footer view (to add checkbox for 'make default' option) - android

Is there a standard way to add a footer to a context menu, in which I can add a checkbox to make the selected option the default one?
Similar to the context menu that comes up when choosing the default home screen for example.
From the Api docs for ContextMenu I see that you can set a header view, but not a footer view. Also the setCheckable / setGroupCheckable methods don't seem to help much here.
Does this need to be done via a custom (alert) dialog? I would be wondering if nobody has yet developed such a component yet in case it's not possible through the standard SDK api. Any standalone open source component out there (beside the Android source itself)?

The best I've come up with is using an AlertDialog
alert.getListView().addFooterView(...); and overriding it's onItemSelected method.

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.

Context Menu for user setup on first use?

I'm trying to set up a menu that appears when the user starts the app for the 1st time, so they can set it up by choosing from 1 of 6 items. It needs to start automatically dependent on a boolean value taken from sharedPreferences.
I have been trying to create a context menu, but its not working and I'm not sure if its the right way to go about it.
Has anyone done this and is context menu the right way to go? If not, please could you point me in the right direction.
Many thanks
You shouldn't be using a ContextMenu for this kind of design. You should be using a Custom Dialog for the configuring of your app. Using perhaps a ViewSlider to allow multiple configuration screens or just one View with all the configuration options in a ScrollView.

Editing the EditText context menu in Android

Is there a way to add a custom case to the existing context menu in Android? We all have a context menu that is called on the active EditText view, the one with "Input Type" and other. What I need is to add another case to this menu, say "Options". I honestly searched for info on Android Developers, but no luck over there. They only write about creating your own menu from scratch. I don't need to change it systemwide as this guy does. My only concern is to change it in one activity of my app, one instance of EditTextto be precise.
See https://stackoverflow.com/a/7383161/1351347
It is NOT possible to override the system-wide contextMenu. You could (as you already know) push another contextMenu on a longClick on this single EditText.

Show affordance/hover/tooltip on a long-clicked View

I would like to show a tooltip, i.e. additional non-essential information about a View when the user long-clicks on it.
The two options I see in front of me are using an OnLongClickListener to construct a custom tooltip in front of the clicked View; or abusing an OnCreateContextMenuListener to create a context menu that isn't.
Neither seems like the best way to go about things, and I'm not sure whether either will work. I've scoured the web and haven't found any hints. Any alternatives, or should I be wet-fish-slapped for trying to do this? Thanks!
Android Oreo has introduced the android:tooltipText attribute in order to display a simple Toast-like tooltip when user long-presses on a View:
<Button
// ...
android:tooltipText="#string/share_button_tooltip"/>
Although it has been introduced in API 26, you can still use it through the Support Library's TooltipCompat helper class:
TooltipCompat.setTooltipText(shareButton, getString(R.string.share_button_tooltip))
My suggestion is to set android:contentDescription and then use it as the tooltip text to kill 2 stones with 1 bird:
<Button
// ...
android:contentDescription="#string/share_button_tooltip"/>
TooltipCompat.setTooltipText(shareButton, shareButton.getContentDescription())

How can I write my own context menu for copy & paste?

I'm writing an application with EditText driven widget. and I'd like to create my own copy & paste menu. To replace android default menu on EditText, what should I do?
Just overriding long click? or is there another way to implement?
Thanks in advance.
EditText should already have a context menu enabled. If it were not, then you would have to enable it by calling registerForContextMenu. Once you have the context menu enabled, you have to add items to it. This is done in onCreateContextMenu by using one of the Menu.add methods.
The hard part is writing the code for onContextItemSelected after the user has selected an option. Saving text to the clipboard is simply a matter of calling ((ClipboardManager) getSystemService(CLIPBOARD_SERVICE)).setText("myText");. However, first we need to find what text to copy. I haven't figured this last part out yet, but I am hopeful that I will soon.
Related Questions
Show context menu when link is long pressed in TextView
It is considered to be somewhat of a standard exercise to implement copy/paste the hard way by overwriting the menu system, creating the menu items yourself, and your own internal buffer.
However, that is not how it should be done if a better way is available on the platform. Reimplementing platform functions is good for learning but bad for maintenance.
Community Wiki as this is not a real answer and I should not get rep for this.

Categories

Resources