DescriptionFragment now works correctly with different themes

This commit is contained in:
daniel oeh 2012-11-23 19:50:18 +01:00
parent 49974c776a
commit 349b5970f2
1 changed files with 20 additions and 11 deletions

View File

@ -2,7 +2,6 @@ package de.danoeh.antennapod.fragment;
import org.apache.commons.lang3.StringEscapeUtils; import org.apache.commons.lang3.StringEscapeUtils;
import android.R;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.Activity; import android.app.Activity;
import android.content.res.TypedArray; import android.content.res.TypedArray;
@ -19,6 +18,8 @@ import android.webkit.WebView;
import com.actionbarsherlock.app.SherlockFragment; import com.actionbarsherlock.app.SherlockFragment;
import de.danoeh.antennapod.AppConfig; import de.danoeh.antennapod.AppConfig;
import de.danoeh.antennapod.PodcastApp;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.feed.Feed; import de.danoeh.antennapod.feed.Feed;
import de.danoeh.antennapod.feed.FeedItem; import de.danoeh.antennapod.feed.FeedItem;
import de.danoeh.antennapod.feed.FeedManager; import de.danoeh.antennapod.feed.FeedManager;
@ -53,7 +54,9 @@ public class ItemDescriptionFragment extends SherlockFragment {
if (AppConfig.DEBUG) if (AppConfig.DEBUG)
Log.d(TAG, "Creating view"); Log.d(TAG, "Creating view");
webvDescription = new WebView(getActivity()); webvDescription = new WebView(getActivity());
if (PodcastApp.getThemeResourceId() == R.style.Theme_AntennaPod_Dark) {
webvDescription.setBackgroundColor(0); webvDescription.setBackgroundColor(0);
}
webvDescription.getSettings().setUseWideViewPort(false); webvDescription.getSettings().setUseWideViewPort(false);
return webvDescription; return webvDescription;
} }
@ -154,8 +157,12 @@ public class ItemDescriptionFragment extends SherlockFragment {
} }
} }
/** Return the CSS style of the Webview. /**
* @param textColor the default color to use for the text in the webview. This value is inserted directly into the CSS String. * Return the CSS style of the Webview.
*
* @param textColor
* the default color to use for the text in the webview. This
* value is inserted directly into the CSS String.
* */ * */
private String getWebViewStyle(String textColor) { private String getWebViewStyle(String textColor) {
final String WEBVIEW_STYLE = "<head><style type=\"text/css\"> * { color: %s; font-family: Helvetica; line-height: 1.5em; font-size: 12pt; } a { font-style: normal; text-decoration: none; font-weight: normal; color: #00A8DF; }</style></head>"; final String WEBVIEW_STYLE = "<head><style type=\"text/css\"> * { color: %s; font-family: Helvetica; line-height: 1.5em; font-size: 12pt; } a { font-style: normal; text-decoration: none; font-weight: normal; color: #00A8DF; }</style></head>";
@ -205,16 +212,18 @@ public class ItemDescriptionFragment extends SherlockFragment {
if (AppConfig.DEBUG) if (AppConfig.DEBUG)
Log.d(TAG, "Loading Webview"); Log.d(TAG, "Loading Webview");
data = ""; data = "";
if (contentEncodedRef == null if (contentEncodedRef == null && descriptionRef != null) {
&& descriptionRef != null) {
data = descriptionRef; data = descriptionRef;
} else { } else {
data = StringEscapeUtils.unescapeHtml4(contentEncodedRef); data = StringEscapeUtils.unescapeHtml4(contentEncodedRef);
} }
TypedArray res = getActivity().getTheme().obtainStyledAttributes(new int[] {android.R.attr.textColorPrimary}); TypedArray res = getActivity().getTheme()
.obtainStyledAttributes(
new int[] { android.R.attr.textColorPrimary });
int colorResource = res.getColor(0, 0); int colorResource = res.getColor(0, 0);
String colorString = String.format("#%06X", 0xFFFFFF & colorResource); String colorString = String.format("#%06X",
0xFFFFFF & colorResource);
Log.i(TAG, "text color: " + colorString); Log.i(TAG, "text color: " + colorString);
res.recycle(); res.recycle();
data = getWebViewStyle(colorString) + data; data = getWebViewStyle(colorString) + data;