From 5b6880d2e34f4c8a4bfba87b5ce53d3c6727b744 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Mon, 9 Sep 2013 13:16:54 +0200 Subject: Switch from HtmlSpanner to HtmlTextView --- .../keychain/ui/HelpFragmentAbout.java | 30 ++++--------------- .../keychain/ui/HelpFragmentHtml.java | 34 ++++------------------ .../keychain/ui/ShareNfcBeamActivity.java | 29 ++++-------------- 3 files changed, 16 insertions(+), 77 deletions(-) (limited to 'OpenPGP-Keychain/src') diff --git a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/HelpFragmentAbout.java b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/HelpFragmentAbout.java index a2d2290dc..e7a977707 100644 --- a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/HelpFragmentAbout.java +++ b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/HelpFragmentAbout.java @@ -17,22 +17,15 @@ package org.sufficientlysecure.keychain.ui; -import java.io.IOException; -import java.io.InputStream; - -import net.nightwhistler.htmlspanner.HtmlSpanner; -import net.nightwhistler.htmlspanner.JellyBeanSpanFixTextView; - +import org.sufficientlysecure.htmltextview.HtmlTextView; import org.sufficientlysecure.keychain.Constants; -import org.sufficientlysecure.keychain.helper.OtherHelper; -import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.util.Log; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; import android.os.Bundle; -import android.text.method.LinkMovementMethod; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -57,26 +50,13 @@ public class HelpFragmentAbout extends SherlockFragment { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.help_fragment_about, container, false); - // load html from html file from /res/raw - InputStream inputStreamText = getResources().openRawResource(R.raw.help_about); - TextView versionText = (TextView) view.findViewById(R.id.help_about_version); versionText.setText(getString(R.string.help_about_version) + " " + getVersion()); - JellyBeanSpanFixTextView aboutTextView = (JellyBeanSpanFixTextView) view - .findViewById(R.id.help_about_text); - - // load html into textview - 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); - } + HtmlTextView aboutTextView = (HtmlTextView) view.findViewById(R.id.help_about_text); - // make links work - aboutTextView.setMovementMethod(LinkMovementMethod.getInstance()); + // load html from raw resource (Parsing handled by HtmlTextView library) + aboutTextView.setHtmlFromRawResource(getActivity(), R.raw.help_about); // no flickering when clicking textview for Android < 4 aboutTextView.setTextColor(getResources().getColor(android.R.color.black)); diff --git a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/HelpFragmentHtml.java b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/HelpFragmentHtml.java index c4bab5734..ce932fd70 100644 --- a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/HelpFragmentHtml.java +++ b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/HelpFragmentHtml.java @@ -17,20 +17,10 @@ package org.sufficientlysecure.keychain.ui; -import java.io.IOException; -import java.io.InputStream; - -import net.nightwhistler.htmlspanner.HtmlSpanner; -import net.nightwhistler.htmlspanner.JellyBeanSpanFixTextView; - -import org.sufficientlysecure.keychain.Constants; -import org.sufficientlysecure.keychain.helper.OtherHelper; -import org.sufficientlysecure.keychain.util.Log; -import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.htmltextview.HtmlTextView; import android.app.Activity; import android.os.Bundle; -import android.text.method.LinkMovementMethod; import android.util.TypedValue; import android.view.LayoutInflater; import android.view.View; @@ -73,15 +63,12 @@ public class HelpFragmentHtml extends SherlockFragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - htmlFile = getArguments().getInt(ARG_HTML_FILE); - - // load html from html file from /res/raw - InputStream inputStreamText = getResources().openRawResource(htmlFile); - mActivity = getActivity(); + + htmlFile = getArguments().getInt(ARG_HTML_FILE); ScrollView scroller = new ScrollView(mActivity); - JellyBeanSpanFixTextView text = new JellyBeanSpanFixTextView(mActivity); + HtmlTextView text = new HtmlTextView(mActivity); // padding int padding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 16, mActivity @@ -90,17 +77,8 @@ public class HelpFragmentHtml extends SherlockFragment { scroller.addView(text); - // load html into textview - 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()); + // load html from raw resource (Parsing handled by HtmlTextView library) + text.setHtmlFromRawResource(getActivity(), htmlFile); // no flickering when clicking textview for Android < 4 text.setTextColor(getResources().getColor(android.R.color.black)); diff --git a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/ShareNfcBeamActivity.java b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/ShareNfcBeamActivity.java index 10adcc4ab..474e0a9e4 100644 --- a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/ShareNfcBeamActivity.java +++ b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/ShareNfcBeamActivity.java @@ -17,12 +17,7 @@ package org.sufficientlysecure.keychain.ui; -import java.io.IOException; -import java.io.InputStream; - -import net.nightwhistler.htmlspanner.HtmlSpanner; -import net.nightwhistler.htmlspanner.JellyBeanSpanFixTextView; - +import org.sufficientlysecure.htmltextview.HtmlTextView; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.helper.ActionBarHelper; @@ -42,8 +37,6 @@ import android.os.Handler; import android.os.Message; import android.os.Parcelable; import android.provider.Settings; -import android.text.method.LinkMovementMethod; -import android.util.Log; import android.widget.Toast; import com.actionbarsherlock.app.SherlockFragmentActivity; @@ -131,27 +124,15 @@ public class ShareNfcBeamActivity extends SherlockFragmentActivity implements } private void buildView() { - // load html from html file from /res/raw - InputStream inputStreamText = getResources().openRawResource(R.raw.nfc_beam_share); - setContentView(R.layout.share_nfc_beam); - JellyBeanSpanFixTextView text = (JellyBeanSpanFixTextView) findViewById(R.id.nfc_beam_text); - - // load html into textview - 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); - } + HtmlTextView aboutTextView = (HtmlTextView) findViewById(R.id.nfc_beam_text); - // make links work - text.setMovementMethod(LinkMovementMethod.getInstance()); + // load html from raw resource (Parsing handled by HtmlTextView library) + aboutTextView.setHtmlFromRawResource(this, R.raw.nfc_beam_share); // no flickering when clicking textview for Android < 4 - text.setTextColor(getResources().getColor(android.R.color.black)); + aboutTextView.setTextColor(getResources().getColor(android.R.color.black)); // set actionbar without home button if called from another app ActionBarHelper.setBackButton(this); -- cgit v1.2.3