Create a textfield which only supports copy-option - android

Is there a way to make a textfield (EditText, TextView) on Android which displays copyable text (no edit options)? Something like Swing's JTextField().setEditable(false) on Windows?
Edit: It seems that my question was a little bit unclear, so I'm going to give it some real-world context. I am working on a checksum calculator which lets you pick a file and prints the results of the calculation into 4 different textfields. I want the user to be able to copy those hashes from the textfield, but to disable all edit options.

I believe what you are asking is very straightforward and simple, if I am reading your question wrong, please correct me!
Are the four text fields that hold the results required to be EditText 's?
otherwise - >
Question:
How to make TextView only copyable, not editable
Answer:
Well using a TextView solves the not editable part
and if you take a look
at my android studio. I have a simple TextView with an attribute of
textIsSelectable="true"
allowing users to copy and paste!
Hope this helped!
-Stephen

Related

Autocomplete/Autofill Edit Text Android

I am looking to achieve the functionality of an AutocompleteTextView but slightly different. Instead of getting a drop-down list with suggestions i want it to complete the sentence for me.
For example: i type abc and i get completed, with the rest of the text in grey: abc1#etc.etc and then click a button to keep this text or keep writing to filter this even further.
Do you think is is achievable somehow?
I have looked my problem up so far but all the answers i found involved a drop-down list, perhaps i haven't looked deep enough.
Why don't you try to implement a custom view?
Basically, you need to the same things that the AutoCompleteTextView does but instead of displaying N elements into the drop down list you have to add the first option to your EditText.
Have a look at:
TextWatcher in order to see how detect the user input and progress
You can then play with indexes and spannables in order to keep track of the data input by the user and the data that you are suggesting.
One thing that I don't like about this idea is the fact that if you have got:
Germans
Germany
...
You need to type a lot of letters without the possibility to choose something different from the solution that you are providing.
use below example ... i think help you...
http://teamandroid4u.blogspot.in/2012/06/autocompletetextview-example.html

How to create a rich text editor in Android [duplicate]

I am wondering if there are any good options to implement a rich text editor in Android. Please note I am talking about a rich text editor that can be used in an Android application, not the one embedded in a web page using HTML and Javascript.
My requirements are:
Basic formatting (color, fonts, highlight, bold, italic, underline, etc.)
Hyperlinks
Inline images
Bullet lists and numbered lists
Inline table (only the contents inside a cell is editable, not the table structure)
As you can see, this is pretty much something quite similar to a typical RichEdit control on Windows.
Here are some efforts (investigation & prototyping) I have made so far:
Using WebView
I have tried using a WebView control to load an HTML fragment with one . The content becomes editable and as it is HTML, I suppose it can meet most of my requirements. But it has several issues:
(deadly) No text caret. The user will have no idea where his/her typed characters will be inserted.
The on-screen soft keyboard is not visible by default. There is a trick that the user has to long-press the Menu button to bring up the keyboard. But I think this is a very bad user experience. Besides, the screen layout is not properly rearranged and the text inserting point sometimes will be covered by the keyboard.
Using EditText
I have tried using the EditText control. It seems to support some level of rich text editing (color, fonts, bold, italic, underline, inline images, bullet lists). But I still cannot figure out how I can implement the following requirements:
Control the appereance of the bullet symbol (dot, circle, dash, arrow, star, etc.)
Numbered list (1., 2., 3., etc.)
Table
BTW, I have seen there are several *Span classes out there but I am not sure if they can be any help... And the http://developer.android.com does not provide much useful information about them.
So, how on earth can I implement a rich text editor on Android?
Can I extends the EditText and add my new functionalities? Or should I do something from scratch - extends the View and implement everything by myself? For later option (extending View), I actually even don't know how to show a text caret and blink it, not mentionging moving the caret with user typing.
I am desperate now... Any hints?
Thanks!
-Tony
(EDIT)
After some further investigation, it looks like extending EditText would be my best bet. I somehow figured out how to use those Span classes and guess I should be able to do most of the tricks by using (extending) them.
For example, extending the BulletSpan and overriding drawLeadingMargin should give me the control of the bullet appereances. Extending the LeadingMarginSpan should help me on the numbered list.
As to the table, my initial plan is to extend the LineBackgroundSpan and draw all the table borders in the drawBackground override. However, I still need to figure out how to layout all the text in the table cells and properly handle the caret movement and selection. Suggestions?
I just published my rich text editor component under the Apache 2.0 license:
https://github.com/1gravity/Android-RTEditor
You can make use of any of the following libraries:-
https://github.com/commonsguy/cwac-richedit
https://github.com/chinalwb/Android-Rich-text-Editor
https://github.com/wasabeef/richeditor-android
https://github.com/irshuLx/Android-WYSIWYG-Editor
I would probably extend both EditText and TableLayout or at least end up using most of their source if there were big enough changes I needed to make.
Can you do the following:
Manually hold the contents in the EditText as your own model (ie by seperating and maintaing the content document and the view attributes as seperate entities).
Override the render (or draw method) to do custom layout on parts of the content document (part of your model) that handle non text characters (say bullets with particular attribute).
To me seems like if you have to muck about with the layout, are you better off writing it from scratch on your own. From what I remember the Edit text (and the richt text editor) is great for anything where you the data is pure text.
There is an open source EditText rich text editor called android-richtexteditor but the code was inexplicably deleted in r5. The code is still there in r4; just use svn to check out r4 or earlier to access it. The code appears to support italics, underline, color picker, text size, and more.
Also answered in these questions: 1, 2
Extend from EditText is a best choice for you, it support CharacterSpan and
ParagraphSpan.
See my App on the Google Play:
https://play.google.com/store/apps/details?id=com.hly.notes
Check this open source Wordpress mobile application for android.It has very promising Richtexteditor based on Edittext.
You can download the source from here
Thanks

How to make a custom EditText tool bar?

I am currently trying to make a Writing program. I would like the functionality of an Edit tool bar that contains things such as BOLD, ITALIC, UNDERLINE, etc. I see that it is under Typeface but I'm struggling to figure out how to make it function on just selected text or just for formatting text. I already have the GUI and button listeners in place. Thanks.
There is nothing really built into Android for this, except at a fairly low level. I have the beginnings of a RichEditText custom widget, as a drop-in EditText replacement, but it needs a fair bit of work, which I will get to later in June (I hope I hope I hope).
In a nutshell, you will need to get a Spannable object from your EditText via getText(), then call methods like setSpan() on it to apply your formatting.
Two words my friend, "creative commons". In my experience, mundane pieces of code like date/time pickers, RTF text boxes, etc.. they've all been coded and thought through more thoroughly than you'll ever have the time for. For something like this, don't reinvent the wheel, check out someone else's code, build on it, and check it back in.

Is there an industry standard to have the text of a button in capital or small letters for Android?

This may be a mundane question but I wanted to confirm if displaying the text of a button in capitals (like 'OK' or 'REGISTER') is acceptable or should it be in regular text (like 'Ok' or 'Register').
Thanks in advance.
P.S
I don't want to be seeminlgly shout at people using caps in buttons :)
In the Android Design site, you can see some examples of text under Writing Style which have just the first letter capitalized. "OK" is a bit of a special case though as it's an abbreviation of sorts, so I'd leave that with both letters capitalized.
The Android design guide details that and a lot more in the writing style page. Do not use all caps...
There's no standard, at least for buttons and labels it seems to be more of a "design choice". In ICS some of the text (e.g. preference and tab labels) are shown all in CAPS. Interestingly enough, there's a setting for textviews to accomplish that: android:textAllCaps. See this. If it's a block of text of course, don't do it.
Sure. You can use the Java String function toUpperCase() or toLowerCase()

Line Numbers, Code Highlighting in TextView

I'm working on an 'IDE' for Android - it could be useful for editing short scripts / making quick adjustments to files. At the moment I'm just using a simple EditText, but I am wanting to add several features, for example Line Numbering down the left hand side of the EditText and Code Highlighting.
Does anyone have any suggestions about how to approach this? For the code highlighting, I'm guessing I'll need to write my own subclass of EditText. For the line numbering, could I have a thin vertical TextView that has the same text size as the EditText??
Yes, I'm aware editing code on a mobile sized screen is painful.
Thanks!
The stock Email application uses an html view (android.webkit.WebView) to wrap even text emails in html. Perhaps rendering the code into html and displaying in a WebView would be a good way to get syntax highlighting.
For line numbering, the thin TextView beside the EditText seems reasonable. You might want to encapsulate it into your own View class that handles both subviews - and allows line numbers to be turned on and off (and perhaps does other good things like keep text size of both equal)
I think an ide for Android is a good idea. Would be nice to be able to code on an airplane without having to get the tray table involved =)

Categories

Resources