• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

A simple editor with rich text in Android

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How to implement a editor with font styles, sizes and colors in android. And how save the note and open it after creating the note with all these styles.

Regards,
Bhavani.G
 
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bhavani,

I'm unfamiliar with Android, so I'm not sure if it supports the full standard API, but if it does, you might want to take a look at javax.swing.JTextPane.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, Android has neither AWT nor Swing. But an EditText view can display text in various styles. Check out the android.text package, particularly Spannable, SpannableString and SpannableStringBuilder, and the related android.text.style package and the android.graphics.Typeface class. That's what I use in the Styled WikiNotes app (see my signature). Also check out the original WikiNotes app on which it is based. While that does not deal with styles, it shows how to edit, display and store text.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to our Android forum.
 
vani golakoti
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, Android does not supports awt and swings. Already I gone through Spannables but once applying the styles how to save the content with styles and retrieve it. Can you please post any proper example to apply styles with spannables and saving.(Every thing should be dynamic)
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The easiest would probably be to keep track of styles in memory in a triple format of (style, index of first character, index of last character) and to store that along with the actual text. Maybe in Properties format.

You still have to decide between various ways of storing data: http://developer.android.com/guide/topics/data/data-storage.html. Shared Preferences is certainly a bad approach, but the other four might be viable, depending on your requirements.
 
vani golakoti
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ulf Dittmer,

"The easiest would probably be to keep track of styles in memory in a triple format of (style, index of first character, index of last character) and to store that along with the actual text. Maybe in Properties format" . I did not under stand what exactly it is saying. I mean dynamically we have to get the selected text and high light it with styles and once the bold is enabled whatever we are typing it should be bold like that. So other than spannables what is the exact way to do this. Once applying the styles is finished then I can go for saving part. And one more thing is we have so many commercial apps with rich text, how they are achieving this, are they using any libraries?

Thank you.
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ulf Dittmer,

The easiest would probably be to keep track of styles in memory in a triple format of (style, index of first character, index of last character) and to store that along with the actual text. Maybe in Properties format.

We can store styles start and end index. In the case of Bold, JETTI , for this I store 2 is the start index and 4 is the last index.
And later he changed that to JETTI , TI as Normal text.. Again we have to store the indexes.. It may work but takes more complicated to look into this approach.. Or else is there any other Idea from your side?

 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

So other than spannables what is the exact way to do this.


Spannables *are* the way to do this; what else are you looking for?
 
vani golakoti
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is it the only way to do this. It is some what difficult while removing the applied style because removespan() method has no parameters for selected text, so it removes the total applied style and further and is difficult to get all the properties.And somebody suggested HTML I don't know what exactly what is the way with HTML's. Let me know if you have any idea, and any libraries for that.

Thank you.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

It is some what difficult while removing the applied style because removespan() method has no parameters for selected text, so it removes the total applied style and further and is difficult to get all the properties.


The way to remove styles is probably to start over with the unstyled text, and then to successively apply all the styles that you have stored (after removing the now-obsolete style from the list, obviously).
 
vani golakoti
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could you please simplify your explanation for me.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There isn't much to simplify - you were asking about how to remove a style. So, you start out with a list of, say, 17 styles that are used in the text, each of them in the shape of a triple as I described earlier. Now you remove one style from the list. To display the other styles, you start with the original unstyled text, and apply all remaining 16 styles to it. Done!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic