better help screen

This commit is contained in:
Dominik
2012-10-31 18:58:10 +01:00
parent 586358599e
commit 182524bb96
8 changed files with 117 additions and 73 deletions

View File

@@ -36,30 +36,17 @@ import android.os.Bundle;
public class OtherHelper {
/**
* Reads html files from /res/raw/example.html to output them as string. See
* http://www.monocube.com/2011/02/08/android-tutorial-html-file-in-webview/
* Gets input stream of raw resource
*
* @param context
* current context
* @param resourceID
* of html file to read
* @return content of html file with formatting
* @return input stream of resource
*/
public static String readContentFromResource(Context context, int resourceID) {
public static InputStream getInputStreamFromResource(Context context, int resourceID) {
InputStream raw = context.getResources().openRawResource(resourceID);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
int i;
try {
i = raw.read();
while (i != -1) {
stream.write(i);
i = raw.read();
}
raw.close();
} catch (IOException e) {
e.printStackTrace();
}
return stream.toString();
return raw;
}
/**
@@ -147,7 +134,7 @@ public class OtherHelper {
output[1] = "<" + chunks[1];
}
output[0] = userId;
return output;
}

View File

@@ -16,6 +16,12 @@
package org.thialfihar.android.apg.ui;
import java.io.IOException;
import java.io.InputStream;
import net.nightwhistler.htmlspanner.HtmlSpanner;
import net.nightwhistler.htmlspanner.JellyBeanSpanFixTextView;
import org.thialfihar.android.apg.Constants;
import org.thialfihar.android.apg.R;
import org.thialfihar.android.apg.helper.OtherHelper;
@@ -24,7 +30,6 @@ import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import org.thialfihar.android.apg.util.Log;
import android.view.LayoutInflater;
@@ -52,15 +57,23 @@ public class HelpFragmentAbout extends SherlockFragment {
View view = inflater.inflate(R.layout.help_fragment_about, container, false);
// load html from html file from /res/raw
String aboutText = OtherHelper.readContentFromResource(this.getActivity(), R.raw.help_about);
InputStream inputStreamText = OtherHelper.getInputStreamFromResource(this.getActivity(),
R.raw.help_about);
TextView versionText = (TextView) view.findViewById(R.id.help_about_version);
versionText.setText(getString(R.string.help_about_version) + " " + getVersion());
TextView aboutTextView = (TextView) view.findViewById(R.id.help_about_text);
JellyBeanSpanFixTextView aboutTextView = (JellyBeanSpanFixTextView) view
.findViewById(R.id.help_about_text);
// load html into textview
aboutTextView.setText(Html.fromHtml(aboutText));
HtmlSpanner htmlSpanner = new HtmlSpanner();
htmlSpanner.setStripExtraWhiteSpace(true);
try {
aboutTextView.setText(htmlSpanner.fromHtml(inputStreamText));
} catch (IOException e) {
Log.e(Constants.TAG, "Error while reading raw resources as stream", e);
}
// make links work
aboutTextView.setMovementMethod(LinkMovementMethod.getInstance());

View File

@@ -16,18 +16,24 @@
package org.thialfihar.android.apg.ui;
import java.io.IOException;
import java.io.InputStream;
import net.nightwhistler.htmlspanner.HtmlSpanner;
import net.nightwhistler.htmlspanner.JellyBeanSpanFixTextView;
import org.thialfihar.android.apg.Constants;
import org.thialfihar.android.apg.helper.OtherHelper;
import org.thialfihar.android.apg.util.Log;
import android.app.Activity;
import android.os.Bundle;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ScrollView;
import android.widget.TextView;
import com.actionbarsherlock.app.SherlockFragment;
@@ -68,12 +74,13 @@ public class HelpFragmentHtml extends SherlockFragment {
htmlFile = getArguments().getInt(ARG_HTML_FILE);
// load html from html file from /res/raw
String helpText = OtherHelper.readContentFromResource(this.getActivity(), htmlFile);
InputStream inputStreamText = OtherHelper.getInputStreamFromResource(this.getActivity(),
htmlFile);
mActivity = getActivity();
ScrollView scroller = new ScrollView(mActivity);
TextView text = new TextView(mActivity);
JellyBeanSpanFixTextView text = new JellyBeanSpanFixTextView(mActivity);
// padding
int padding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 16, mActivity
@@ -83,7 +90,13 @@ public class HelpFragmentHtml extends SherlockFragment {
scroller.addView(text);
// load html into textview
text.setText(Html.fromHtml(helpText));
HtmlSpanner htmlSpanner = new HtmlSpanner();
htmlSpanner.setStripExtraWhiteSpace(true);
try {
text.setText(htmlSpanner.fromHtml(inputStreamText));
} catch (IOException e) {
Log.e(Constants.TAG, "Error while reading raw resources as stream", e);
}
// make links work
text.setMovementMethod(LinkMovementMethod.getInstance());