How to pinch zoom an edittext in android? - java

Please suggest a way to zoom all the contents of the edittext when a pinch gesture is detected. Want to zoom like typical text editor apps like KingSoft and quickoffice.

It's going to be nasty, but you can subclass EditText.
In your subclass, override onTouch and pass its values to a ScaleGestureDetector. Store the detected scale as a member variable.
Override onDraw, and call canvas.scale() with your scale value prior to calling through to super.onDraw.
This is likely to wreak havoc with the caret and edit controls.

I wrote a simple library to do just that, back when I need the functionality in an app. You can find it on GitHub

To add tad's answer, you probably can use children of MetricAffectingSpan or CharacterStyle:
http://developer.android.com/reference/android/text/style/MetricAffectingSpan.html
You will have to handle copy/paste (with spans!), and it will be tedious.
Note that you can derive your own spans from the existing classes, but I cannot say what will happen with them when you copy & paste the text into another application.
OTOH, if you decide from the very beginning that your text is just plain text and there is only one span used for zooming, it may be not so tedious.

Related

Inline Clickable List Layout in Android

I want to create a sort of inline list of clickable text blocks in Android Studio. Below is the closest image I could find to the effect I would like. How would I achieve such an effect?
The information shown will be just a string, however clicking on this will take the user to another activity. It would be good if the text blocks also had a background, by the looks of it this app uses an image as the background, which should be fairly easy to set if the list is made from text views. I just don't know how to make a list with variable length inline objects.
See here: https://github.com/google/flexbox-layout
What I was looking for was specifically a horiztonal, wrapping, inline list.

How to prevent text from turning to ellipsis on small buttons in JavaFX?

If I make button relatively small, it's caption turns to ellipsis.
How to turn off this feature?
Don't let the button go below it's preferred size, then it will never need to elide the text of the button label:
button.setMinSize(Button.USE_PREF_SIZE, Button.USE_PREF_SIZE);
I want to make very small button
You can use any of the below either separately or in combination:
Apply CSS to use a very small font in the button.
Make the label text for the button very short.
Use brian's answer which proposes explicitly setting the ellipse string to empty.
Use a small graphic icon instead of text.
You can use setMinSize as documented above in all cases (if you wish the button not to go below a preferred size truncating or eliding content).
In all cases, if you wish, you can also apply CSS to minimize the padding between the label and button the border.
From your previous comment (I want to use simple captions like "<" and ">"), I think option 2 (Make the label text for the button very short) is what you want.
You may also be interested in Joel's Designing for People Who Have Better Things To Do With Their Lives which would indicate, usability-wise that very small buttons are usually a pretty bad idea.
in your label/button you can use the textOverrun property to turn off ellipsis.
textOverrun.set(OverrunStyle.CLIP);
this is probably a bit late for you, so i am putting it here for lone wanderers digging up this question.
It puts ... because there's no room for the text. You can use bigger buttons or a smaller font but if you really want the dots gone use button.setEllipsisString(""); , but then you just get truncated text.

SMS Balloons / Long Chat Boxes

I want to be able to add a text-messaging balloon every time the user revives data from a HttpGet, I want it so that it looks nearly identical to the default Android text messaging UI. I'm fine with all the code, I just need a way to create the UI and create another text balloon every time data comes back from a HttpGet request.
Thanks ever so much, for the answering this questions and I'm sure there's an easy way to do it, yet I've found no way by using the 'ole Google.
I am doing something similar for my app am doing the following to achieve it:
You will need a 9-Patch-Image (a stretchable PNG, see here) that represents the bubble. You want to make the part stretchable that does not include the corners of the bubble. You can create the bubbles using an image editor of your choice (I'd recommend a vector graphics editor like Inkscape). Then use the 9-Patch editor included in the Android Developer Tools to transform the PNG image into a 9-Patch PNG.
Create a custom layout file for one bubble. Create a textview inside it, and add your bubble as a background resource. (android:background)
Use an arraylist with a custom adapter to inflate and fill your items.
So far, this will give you identical bubbles as background for all messages.
If you want to get fancy, you can create different bubbles for participants, and use the setBackgroundResource method in your Adapter to set the correct background.
Further, if you wish to align them left or right, like in the message app, you will need to add spacers to the left and right of your TextView in the layout file. I used FrameLayouts with a fixed width. Make sure to set their visibility to GONE.
As with swapping the different bubble colors, just set the visibility of the left/right spacer.

Listfield focus issue in blackberry

I am using list-field in a BlackBerry application. In each list-field item, I have a bitmap-field at the left, text at center and again a bitmap-field at the right.
Can I determine whether the fields are focusable inside the list-field rows for keypad versions of BlackBerry Devices for e.g BlackBery Tour?
No in list field no control except whole row is focusable explicitly. If you want to perform any click events you can use touchEvent() but the calculation will be too complex and not so reliable.
If you want to have separate clickable items in one row you must use HorizontalFieldManager each time.
Update: : I have come across this scenario twice, and if I were in place of you I will consider what exactly the feature is about, If you are concerned about UI and there is not any heavy functionality behind focusing you can try touchEvent or navigationClick but using both will be cumbersome. Too much logic, too much thinking, hard to test.
If there is any functionality, you have an option to add them on menu, It will be more convenient way than using horizontal field manager or the above mentioned methods.

EditText background color

I have an Activity that consists only of a huge EditText, full screen.
To match with my app's colours, i changed the background color of the EditText. But although it occupies the whole screen, it only changes the first line. Everytime i press enter i go to a new line and that line gets the background i want.
What propertie can i set in order to do this? I just can't see it!
I would wrap the EditText with a View and set the background color on the View.
In order to change the background of those Views that come with a background already, its better to provide your own image, and then use patch9 for proper resizing
I hope that helps
#everyone:
While searching for a solution for this same kind of problem i found this page. While reading the solutions i thought to myself: "There must be a better way to do this, instead of making your own styles and widgetborders, etcetera, etcetera, ....
Therefore, i present to you: the 1 LINE OF CODE SOLUTION!!! No trolling.
<your-widget-component-that-has-a-background-color>.getBackground().setColorFilter(Color.<your-desired-color>, PorterDuff.Mode.MULTIPLY);).
It works like this:
"getBackground()" fetches the background from the component
"setColorFilter" will call a filtering on the background image itself
"Color." determines what color you want to pass onto the filter
"PorterDuff.Mode." sets the kind of manipulation you would like to do with the given color and the fetched background image. People with knowledge of image editing software (GIMP, Photoshop, ...) might recognise these modes. Basically, each mode has a certain effect on how the color is applied to the background image. to simply "override" the color of the image, while preservind it's gradients, borders and such, use "MULTIPLY"
I haven't profoundly read the PorterDuff class documentation, but honestly, ain't it a powerful bit of code?
With kind regards,
How to set the background color of an EditText widget:
editText.setBackgroundColor(Color.RED);

Categories

Resources