It could get complicated. For example, since the Japanese Language Proficiency test (JLPT) has 5 levels, that makes 10 apps. And if I add an all-levels version, that could makes 12. Add the IOS version, and that makes 24. Owch. Of course, I'll have the same code base for each version, and vary the code only with configuration information. Otherwise, it will become unmanageable.
There's sooo much to getting this app out. There's debugging. There's adding the link to the pay version. There's adding the credits. There's testing. There's fixing the known errors in the data files. There's adding a feedback link. There are all the other changes I'll need to make to manage separate apps for the 5 levels.
I wonder if I can avoid that by just selling one app?
I don't think so. For JLPT, if I'm taking the test, I want the materials for my level. I don't want to really see the other levels - for the most part.
Ok. As the first foray into managing separate free/pay version, we'll add a link to the pay version on the first page which only displays if it's the free version. We'll first add an entry in strings.xml which says
android:layout_gravity="bottom|center" android:paddingTop="0dp"
android:textSize="16dp" />
Ok. We already have code for this, so it's just a question of modifying it. Actually, I should add the pro/full version first. This is so that when I upload the free version, it will have a url to reference. Hmmmm...what if I make a verson for other markets?
One thing at a time. First, add the code. How about something like this:
String fullLink = "Get full version at www.temp.com" + "/" + "jlpt" + "/";
TextView textViewFullLink = (TextView) findViewById(R.id.full_link);
// String text = "Data courtesy of www.mxpkl.com";
textViewFullLink.setText(fullLink);
// pattern we want to match and turn into a clickable link
Pattern fullPattern = Pattern.compile(fullLink);
// prefix our pattern with http://
Linkify.addLinks(textViewFullLink, fullPattern, "http://");
Add the flag to strings.xml:
Now, add the code to check the string...
String str = getResources().getString(R.string.free);
boolean isFree = Boolean.getBoolean(str);
// add reference to full link
if (isFree) {
// and fill in the code above.
Ok, let's see if this works.
Hmmm. No. Why? Let's debug to just after it reads the boolean, to make sure that's executing ok.
Hmm, it's just stalling waiting for the debugger port. I'll be lazy in throw in a couple of toasts:
Toast.makeText(this, str, Toast.LENGTH_LONG);
// add reference to full link
if (isFree) {
Toast.makeText(this, "isFree is true", Toast.LENGTH_LONG);
Now I get the message as if the debugger was running already, asking to terminate the current session or not. Terminate.
Arggh. I can't get it to re-install. I think I need to change some code. Throw in a log statement.
I don't get why the toast isn't working. Ok, let's just use log.
Still nothing. Shall I use the infamous clean, with its incessant risk of drawing me into a R not fund annoyance? Ok, let's try.
Ok, the clean and compile worked - let's run it.
Still nothing. Ok. let's put a debug statement in the first line of code.
Yup, there it is. Dash it all, I should have checked right away that I was using the Boolean.getBoolean properly. I thought of it, but got waylayed by the slow-to-startup up debugger. Sometimes, picking through adb output, you miss things. Maybe I should try back in Eclipse instead of command line.
Anyway, here's what getBoolean does:
"Returns true if and only if the system property named by the argument exists and is equal to the string "true"."
I'm not using a system property, just a string. Boolean.parseBoolean is what I should've used, which oddly looks to be an Android, not Java method. Anyway:
Boolean isFree = Boolean.parseBoolean(str);
Ok, it's working. That's a wrap.
No comments:
Post a Comment