0

I am working on an android application where I have to add a build-in txt reader which can parse and display the content of a txt file for any kind of encoding.

I know there are some opensource solutions like FBReaderJ, CoolReader and etc, however almost all of them are heavy with a lot of features which I do not need. And it is hard to extract the core library. And the FBReaderJ use jni which is unfamiliar to me.

I just need features:

  1. Open a specified txt file in the local storage.
  2. Display the current progress(page and percentage) of the whole book.
  3. Jump to specified progress

That's all I need.

I tried to build it on my own, but I am not sure the general practice for this kind of application, I have some raw ideas:

1 Read the content by part.

For example a whole txt file may contain 10K words, we do not need to load all of them, we only need the content which can fill the screen.

I dot not know how to calculate them.

2 Render the content

I can create a textview and put the content on it or I can create a custom view to draw the cotnent by a canvas. I do not which is preferred.

I hope someone can give me suggestion. Thanks.

hguser
  • 31,173
  • 49
  • 145
  • 269

1 Answers1

0

To 1: You can implement your own "readPage" method using a e.g. BufferedReader. You should dynamically determine the number of lines you can display on a device. A fixed number wouldn't fit on different screen sizes. Then you can load this number of lines as one page.

The number of lines of the txt file can be read like this.

With the total number of lines and the lines per page you can determine the number of pages of your document. You can load them one by one, i also suggest caching the previous and subsequent page in background.

To 2: For the beginning you should be fine with a LinearLayout or RelativeLayout, two TextViews and some navigation elements. The main TextView displays the document, the second holds page number and percentage as header or footer.

For navigation there are just too much options to explain them all: buttons, swiping horizontally, scrolling vertically and so on...

Hope this helps so far.

Community
  • 1
  • 1
Sven Menschner
  • 603
  • 5
  • 12