Preview image of text file in Android - android

I would like knowing if it's possible to obtain the preview image (thumbnail) of any text file in Android, like PDF, DOC, TXT, PPT, PPTX, RSS or HTML.
If the response is positive, how do I can make it?
I have the preview images of video and image files, and I want to obtain the same result for text files.
Thanks for your attention, greetings.

This can be quite a problem since you need to handle every file type individually.
TXT, RSS and HTML are simple enough, you can just read them all like a text file and display the text on the screen (first X characters, for instance, either with a TextView or by manually drawing it in the onDraw method. However, if you want to render the HTML, look at this question.
PDF is another story, you need some sort of rendering endine for that, you might want to look at MuPDF.
RSS and HTML Can work the same way as a normal TXT file.
PPT, PPTX and DOC will also need a custom renderer, you might want to look at this question.

Related

Android WebView removing spaces from text

I'm using a WebView to display a formatted HTML text file with color and font size.
My problem is it keeps removing spaces form the text, like it will combine two words together. I think it is because it is trying to fit the text within the screen width. How do I fix this? Or is there a better way to display formatted text like this? (I need size, color, links, and some centered text
This question has been already asked but was not answered.
WebView removing spaces from text
I think you need load formatted local html file, so algorithm:
Parse you unformatted html data.
Format html data as you like, using .replace method
Load formatted data to your webview, like this: Load local html in WebView?

How to drag an image in html file displayed using webview in android?

I have an Android WebView loaded with a html file(actually stored in some folder under sdcard) that is having one/two/three image(s). Is it possible to drag-drop any one of those images?
If its possible, below are my doubts
When i drag an image from (x1,y1) place and drop it in another (x2,y2)place, How can i change the original source file code as the image place is changed ?
When i open the same html file in next time (using default html viewer or my app), i should see the image in (x2, y2) place. Isn't it possible ?
I tried this drag ImageView inside a WebView. But it is just adding an imageview to webview. (So, when i run the same app next time, i don't see the image in the place where i dropped it in first run.) But i need to drag an image presented in source html file. So After every drag-drop, Do i need to render the webview content and create a new html file to see the image in dropped location?
Is it possible to read the android-webview content? (like we read the web page content in java).
Can anyone clear my doubts and suggest me a better way if iam going/thinking wrong?
I don't think it possible (without using some not trivial tricks) to implement the drag and drop as you wish. for the other point's you raised - if the file is on your sd - why not just parse the html file and get the pictures positions and source link and use it to implement the drag and drop on your own? after all- the html file is an xml file which contains attributes which defines positions/links/images/text

Android: how to format a html string to be displayed in a webview?

Here is why I want to do.
I have an html string extracted from a rss feed.
I want it to display nicely in a WebView embedded in my activity.
I can easily do it using the loadData() function, but the display isn't optimized for a small device : in another word I want to resize the html content not to exceed my view width.
So images, frames, tables need to be resized.
How can I do it ?
I thought I could use Google Wireless Transcoder service but it only works with urls
One option would be to use css, but it depends on the feed (each post might have different formatting / apply styles inline)
Use loadDataWithBaseURL(), with "file:///android_asset/" as the base url. Put a css file in your /project/assets folder. Inject the css file into the tag of your html.

The best practice for creating a text file reader on android?

I want to create an app that reads and displays a big text file, so basically, it's a text file reader. There is something specific with the reader is that I would like to show a background image with the text. When the text scrolls, the image moves along with it.
I wondered what is the best practice for this? TextView? WebView? Or using SurficeView to draw the text/animation directly?
Thanks,
I would recommand a WebView. But this would be easier if you already save the large Text as a HTML-Page. You can then use the loadURL()-method to show you'r HTML-File (i guess this is for the help-page?)

Emoji (Emoticons) on Blackberry and Android App. How to support?

I wonder how whatsapp gives support for that. I could use emojis on iPhone because it is natively supported. I'm not developing for bb neither android but I need to help a coder with this stuff.
The bb guy told me that he can add a font as a project resource (ttf), but since emojis are colored graphics, I'm not sure if i can create a ttf. I do not know anything about fonts either.
As you can see, my unknowledge is huge on this. I just need some tips that point me to the right way to research.
Thanks!
On Android you can make a BitMap font with the tutorial i found here. Then you can embed all your Emoji into that font.
For making this on the BlackBerry you can use the FontFamily class. Here is a tutorial that explains how this works.
Have fun! :-)
From my experience most emoticons (emoji) do not use a font, but are rather bitmap graphics (e.g. emoticons in the default Android text editor). There are several downsides to using a font:
Suppose you made the characters a, b, c, d etc into emoticons - the user would then be unable to read/send messages with those characters in without them turning to emoticons.
Fonts are generally quite large as they contain a lot of information for displaying the text at different sizes/styles
Using bitmap graphics will allow you to easily use the same emoticons across a wide range of devices, whilst using standard device fonts the text around the emoticons.
You will have to parse the string that you are displaying, find the emoticons, and replace them with images.
On Android for instance you would accomplish this with:
Search the string for all emoticon occurences (regex can do this easily enough)
Replace all emoticons with the string <img src="emoticon.png" /> (althugh change emoticon.png based on the type of emoticon)
Convert the String to HTML with String myHtmlString = Html.fromHtml(myEmoticonString, myImageGetter, null);
Display the string in a TextView myTextView.setText(myHtmlString)
In step 3 myImageGetter needs to be an instance of Html.ImageGetter which returns a graphic (drawable) based on the src attribute of the images in the string (ie it converts a string file name to an actual graphic)
The steps on other platforms would be different but you should be able to use the same basic method (parse string, replace emoticons with images).
Let me tell what I know, I dont know emoji, but googling it had me thinking it is a set of emoticons, primarily Japanese in origin. If that is true I would like to point out that it is common to create custom fonts using a font file (shown here). And in that font file you should be able to embed these emoticons and use them.
The link I provided above, is for J2ME, but the logic and design should be similar. Hope this helps.

Categories

Resources