Best way to load ~500 paragraphs plus options - android

I'm just getting started and trying to make a simple app after going through some of the Google Codelabs. I wrote a Choose your own Adventure type of game. It consists of 500 paragraphs, and at the end of each paragraph is usually a choice of the next action to take (ie paragraph to load) and possibly some game logic. For now I am concentrating on the text only.
It seems simpler to make 500 text files and load up whatever file number is necessary, however it makes more sense to load ALL the paragraphs as the entire text takes up roughly 300Kb as a text file.
How would I even attempt this? I know I would need a text array and I file reader. I think it would be more work to format the paragraphs with a delineator to separate them, as it may be simpler to just create 500 files and write a While loop feeding my array.
That should fulfill my current objective, but when I want to add the choices at the end of the paragraphs, it seems as if a JSON or XML file that includes the text and choices would be better. I could not figure out how to even attempt this.
Example Paragraph: "You hear a horseman galloping and spin towards the sound. Do you have the skill of Forest Stealth? If you do, turn to 95. If you do not, turn to 234."

Related

How to change image display duration in VLC lists for Android?

I have set this duration for lists on Windows over the setting 'demuxer', however the android version does not contain this option.
I'm actually creating the list dynamically over a php file in a server, so it looks like this:
#EXTM3U
#EXTINF:-1,
image1.png
#EXTINF:-1,
video1.m4v
So I wonder if there is an option in android to make images (not videos) display over a minute and if there is no such option, maybe I can add something to the list to make images display longer?
I have seen a tutorial for the list to use 1000 but it is a tag based language (html?), which seems not to be the case of my list. (link to tutorial: http://chris-reilly.org/blog/vlc-slideshow-duration/)
It is worth mentioning that in the Android version there is a small input for VLClib, but I was unable to find anything related to what I'm looking for.
Any help will be appreciated.
The answer is #EXTVLCOPT:image-duration=100 after each image file. (change 100 for the number of seconds.
Found in https://forum.videolan.org/viewtopic.php?t=148945

Apptimize - Modifiable Text / Images in app

Within our application, our product designer would like the in app text and images be changeable via Apptimize.
We have a tutorial with 5 screens, each with a description and image.
Currently, for the text, I have an Array of 5 Strings, and use Apptimize's AppTimizeVar to get a value.
// Either use the already existing string, of the one from Apptimize.
description[i] = ApptimizeVar.createString( "tutorial_description_" + i, description[i]).value();
And for the images, I was going to create an Array of 5 Strings that may or may not contain URLs to an Image to replace that image.
This solution may work, but I'm wondering. Is there a better way to accomplish this goal?
Also, I wanted to get someone's opinion on if this is the right path to follow. Trying to make things changeable down the road via a third party library like Apptimize.
Thanks for your time.

Android ~ Listview with images that have been uploaded by user?

I know how to setup a listview to have an image and some text on each rows.
I know how to have the user open up a dialogue to pick an image from the file system or live.
I almost know how to downsample it in case its huge. (too many ways, no expert to recommend one).
I really need to know how the user can create db entries (notes) that contain text and an image that is user selected. In essence, the user is entering text and selecting/uploading an image that makes a 'note' and the notes get displayed in a listview.
I don't want the full code, but rather a general direction. I did some research and for me its a big forest. If you can give general directions how thats done, I'll do the rest.
Thank you,

Possible TextView imeplementation to handle very large data

I have been looking for a while but haven't been able to find an answer. I have a text view in my APK that needs to potentially handle large amounts of text being appended to it a little at a time. So it could grow over time as stuff streams to it. So far I haven't seen any issues and I have let the underlying Android implementation take care of the data. Does anyone know if Android caches these all in memory or that if it passes a watermark level it could then write to file for the TextView? What if it gets too huge, would the APK run out of memory and get killed by Dalvik? If that is the case I am open for any suggestion as how to mitigate this possiblity. One solution in my mind is that have a custom textview that does exactly what I explained and caches data to file if it passes a water mark. However, I am not sure how tricky it would get to detect where the user is navigating within the TextView to pull the data back and forth from the underlying data file and populate the actual TextView object.
Thanks
While I was unable to find the actual threshold, it has been discussed and suggested that extremely long text be displayed in smaller chunks. You can also write to a file which you can then read back in as necessary for your project.
Edit: regarding the TextView bookmark (for lack of a better term), you could always programmatically check to see where the user is in the TextView (checking for a certain character or string at the end of the TextView) and reading the next few lines of text into the TextView. You would have to match the getText().toString() value of the TextView against the readable text in your file.
I'm wondering now too if you would be able to do that in either direction. To save space, you could write your text to file as the user needs it, and update the TextView to only display 5 or 6 lines (arbitrary number). You could trim the TextView in either direction to save memory. You could ellipsize both sides of your text, scroll enable it, and trim/read those points as necessary.

Traverse a XML file in Android

I'm developing an app in Android and I need to traverse a xml file.
I need to traverse a xml - backwards and forward from a given position. It means i start to parse the file, but at each instant i can stop and go backwards or continue.
I was thinking in using DOM, with its for cycle i could control it and do what i wanted. But the xml file that i want to parse has at least 8 Mb and since DOM is very memory intensive, don't seem to be a good solution.
A solution to this problem was not to load the whole document for parsing. Like to split the document in several parts and only load one part to memory and parse. When i come to the end of this part, i load another. The same when i want to rewind.
My question is, how can i achieve to split the file in several pieces. Since it is a xml file and the childs don't have all the same size ?
For example:
<root>
<child time="A">
<sub1>1</sub1>
<sub2>2</sub2>
</child>
<child time="B">
<sub1>3</sub1>
</child>
<child time="C">
<sub2>4</sub2>
</child>
</root>
As you can see, their childs have different sizes and i don't know how I can split a file like this in an efficient way in several parts.
Can anyone give me a clue ?
Best regards.
With XML you typically have to make a choice. DOM is memory intensive, SAX cannot go backward, and hand made parsers are tedious to create and maintain.
If you can afford consuming tens of MB of memory, go simply with DOM.
The decision between SAX and manual parsing depends on how often you actually need to go backward and whether you can afford a delay at this point.
If you cannot, you will have to implement a hand made parser with precomputation. Precomputation can be done, for example, using SAX, used in conjunction with CountingInputStream, or also manually. You would precompute starting and ending offsets of each n-th child element and store that as an array of intervals like these:
public class Interval {
public int startOffset;
public int endOffset;
}
Interval[] precomputedOffsets;
The value of n, the page size, could be something like 20. Balance that to control the tradeoff between memory consumption and performance of going back.
Now, if you know that you need to go to item i at runtime, you will call reset and skip(precomputedOffsets[i / n]) on the input stream, and hand parse of i % n remaining child elements from there.

Categories

Resources