add option for condensed fonts
This commit is contained in:
parent
86daa8ee53
commit
d75dc81c0d
@ -1,8 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="org.fox.ttrss"
|
||||
android:versionCode="234"
|
||||
android:versionName="1.37" >
|
||||
android:versionCode="235"
|
||||
android:versionName="1.38" >
|
||||
|
||||
<uses-sdk
|
||||
android:minSdkVersion="8"
|
||||
|
@ -103,6 +103,12 @@
|
||||
android:summary="@string/pref_headlines_mark_read_scroll_long"
|
||||
android:title="@string/pref_headlines_mark_read_scroll" />
|
||||
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="false"
|
||||
android:key="enable_condensed_fonts"
|
||||
android:summary="Use condensed fonts for headline titles and a few other UI elements."
|
||||
android:title="Enable condensed fonts" />
|
||||
|
||||
<org.fox.ttrss.util.FontSizeDialogPreference
|
||||
android:defaultValue="13"
|
||||
android:key="headlines_font_size_sp"
|
||||
|
@ -9,6 +9,7 @@ import java.util.Date;
|
||||
|
||||
import org.fox.ttrss.types.Article;
|
||||
import org.fox.ttrss.types.Attachment;
|
||||
import org.fox.ttrss.util.TypefaceCache;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
@ -19,6 +20,7 @@ import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Typeface;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
@ -101,6 +103,18 @@ public class ArticleFragment extends Fragment {
|
||||
|
||||
if (title != null) {
|
||||
|
||||
if (m_prefs.getBoolean("enable_condensed_fonts", false)) {
|
||||
Typeface tf = TypefaceCache.get(m_activity, "sans-serif-condensed", Typeface.NORMAL);
|
||||
|
||||
if (tf != null && !tf.equals(title.getTypeface())) {
|
||||
title.setTypeface(tf);
|
||||
}
|
||||
|
||||
title.setTextSize(TypedValue.COMPLEX_UNIT_SP, Math.min(21, articleFontSize + 5));
|
||||
} else {
|
||||
title.setTextSize(TypedValue.COMPLEX_UNIT_SP, Math.min(21, articleFontSize + 3));
|
||||
}
|
||||
|
||||
String titleStr;
|
||||
|
||||
if (m_article.title.length() > 200)
|
||||
@ -108,7 +122,6 @@ public class ArticleFragment extends Fragment {
|
||||
else
|
||||
titleStr = m_article.title;
|
||||
|
||||
title.setTextSize(TypedValue.COMPLEX_UNIT_SP, Math.min(21, articleFontSize + 3));
|
||||
title.setText(Html.fromHtml(titleStr));
|
||||
//title.setPaintFlags(title.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
|
||||
title.setOnClickListener(new OnClickListener() {
|
||||
|
@ -11,6 +11,7 @@ import org.fox.ttrss.types.Article;
|
||||
import org.fox.ttrss.types.ArticleList;
|
||||
import org.fox.ttrss.types.Feed;
|
||||
import org.fox.ttrss.util.HeadlinesRequest;
|
||||
import org.fox.ttrss.util.TypefaceCache;
|
||||
import org.jsoup.Jsoup;
|
||||
|
||||
import uk.co.senab.actionbarpulltorefresh.library.PullToRefreshAttacher.OnRefreshListener;
|
||||
@ -21,6 +22,7 @@ import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Resources.Theme;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Typeface;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
@ -688,9 +690,21 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
|
||||
|
||||
TextView tt = (TextView)v.findViewById(R.id.title);
|
||||
|
||||
if (tt != null) {
|
||||
tt.setTextSize(TypedValue.COMPLEX_UNIT_SP, Math.min(21, headlineFontSize + 3));
|
||||
if (tt != null) {
|
||||
tt.setText(Html.fromHtml(article.title));
|
||||
|
||||
if (m_prefs.getBoolean("enable_condensed_fonts", false)) {
|
||||
Typeface tf = TypefaceCache.get(m_activity, "sans-serif-condensed", article.unread ? Typeface.BOLD : Typeface.NORMAL);
|
||||
|
||||
if (tf != null && !tf.equals(tt.getTypeface())) {
|
||||
tt.setTypeface(tf);
|
||||
}
|
||||
|
||||
tt.setTextSize(TypedValue.COMPLEX_UNIT_SP, Math.min(21, headlineFontSize + 5));
|
||||
} else {
|
||||
tt.setTextSize(TypedValue.COMPLEX_UNIT_SP, Math.min(21, headlineFontSize + 3));
|
||||
}
|
||||
|
||||
adjustTitleTextView(article.score, tt, position);
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,11 @@ public class PreferencesActivity extends PreferenceActivity {
|
||||
|
||||
if (compatMode) {
|
||||
findPreference("dim_status_bar").setEnabled(false);
|
||||
findPreference("webview_hardware_accel").setEnabled(false);
|
||||
findPreference("webview_hardware_accel").setEnabled(false);
|
||||
}
|
||||
|
||||
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) {
|
||||
findPreference("enable_condensed_fonts").setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,7 @@ import java.util.Date;
|
||||
|
||||
import org.fox.ttrss.R;
|
||||
import org.fox.ttrss.util.ImageCacheService;
|
||||
import org.fox.ttrss.util.TypefaceCache;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
@ -20,6 +21,7 @@ import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.database.Cursor;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Typeface;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
@ -140,14 +142,25 @@ public class OfflineArticleFragment extends Fragment {
|
||||
|
||||
if (title != null) {
|
||||
|
||||
if (m_prefs.getBoolean("enable_condensed_fonts", false)) {
|
||||
Typeface tf = TypefaceCache.get(m_activity, "sans-serif-condensed", Typeface.NORMAL);
|
||||
|
||||
if (tf != null && !tf.equals(title.getTypeface())) {
|
||||
title.setTypeface(tf);
|
||||
}
|
||||
|
||||
title.setTextSize(TypedValue.COMPLEX_UNIT_SP, Math.min(21, articleFontSize + 5));
|
||||
} else {
|
||||
title.setTextSize(TypedValue.COMPLEX_UNIT_SP, Math.min(21, articleFontSize + 3));
|
||||
}
|
||||
|
||||
String titleStr;
|
||||
|
||||
if (m_cursor.getString(m_cursor.getColumnIndex("title")).length() > 200)
|
||||
titleStr = m_cursor.getString(m_cursor.getColumnIndex("title")).substring(0, 200) + "...";
|
||||
else
|
||||
titleStr = m_cursor.getString(m_cursor.getColumnIndex("title"));
|
||||
|
||||
title.setTextSize(TypedValue.COMPLEX_UNIT_SP, Math.min(21, articleFontSize + 3));
|
||||
|
||||
title.setText(titleStr);
|
||||
//title.setPaintFlags(title.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
|
||||
title.setOnClickListener(new OnClickListener() {
|
||||
|
@ -8,6 +8,7 @@ import java.util.TimeZone;
|
||||
import org.fox.ttrss.CommonActivity;
|
||||
import org.fox.ttrss.GlobalState;
|
||||
import org.fox.ttrss.R;
|
||||
import org.fox.ttrss.util.TypefaceCache;
|
||||
import org.jsoup.Jsoup;
|
||||
|
||||
import android.app.Activity;
|
||||
@ -17,6 +18,7 @@ import android.content.res.Resources.Theme;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteStatement;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Typeface;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
@ -493,9 +495,21 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis
|
||||
TextView tt = (TextView)v.findViewById(R.id.title);
|
||||
|
||||
if (tt != null) {
|
||||
tt.setTextSize(TypedValue.COMPLEX_UNIT_SP, Math.min(21, headlineFontSize + 3));
|
||||
|
||||
tt.setText(Html.fromHtml(article.getString(article.getColumnIndex("title"))));
|
||||
|
||||
if (m_prefs.getBoolean("enable_condensed_fonts", false)) {
|
||||
Typeface tf = TypefaceCache.get(m_activity, "sans-serif-condensed", article.getInt(article.getColumnIndex("unread")) == 1 ? Typeface.BOLD : Typeface.NORMAL);
|
||||
|
||||
if (tf != null && !tf.equals(tt.getTypeface())) {
|
||||
tt.setTypeface(tf);
|
||||
}
|
||||
|
||||
tt.setTextSize(TypedValue.COMPLEX_UNIT_SP, Math.min(21, headlineFontSize + 5));
|
||||
} else {
|
||||
tt.setTextSize(TypedValue.COMPLEX_UNIT_SP, Math.min(21, headlineFontSize + 3));
|
||||
}
|
||||
|
||||
int scoreIndex = article.getColumnIndex("score");
|
||||
if (scoreIndex >= 0)
|
||||
adjustTitleTextView(article.getInt(scoreIndex), tt, position);
|
||||
|
29
src/org/fox/ttrss/util/TypefaceCache.java
Normal file
29
src/org/fox/ttrss/util/TypefaceCache.java
Normal file
@ -0,0 +1,29 @@
|
||||
package org.fox.ttrss.util;
|
||||
|
||||
import java.util.Hashtable;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Typeface;
|
||||
import android.util.Log;
|
||||
|
||||
public class TypefaceCache {
|
||||
private static final String TAG = "TypefaceCache";
|
||||
private static final Hashtable<String, Typeface> cache = new Hashtable<String, Typeface>();
|
||||
|
||||
public static Typeface get(Context c, String typefaceName, int style) {
|
||||
synchronized (cache) {
|
||||
String key = typefaceName + ":" + style;
|
||||
|
||||
if (!cache.containsKey(key)) {
|
||||
try {
|
||||
Typeface t = Typeface.create(typefaceName, style);
|
||||
cache.put(key, t);
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Could not get typeface '" + typefaceName + "' because " + e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return cache.get(key);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user