タイムラインのフォント(太字)

This commit is contained in:
tateisu 2017-08-29 15:03:39 +09:00
parent cdb018e135
commit 300a590eba
15 changed files with 170 additions and 57 deletions

View File

@ -9,8 +9,8 @@ android {
applicationId "jp.juggler.subwaytooter"
minSdkVersion 21
targetSdkVersion 26
versionCode 131
versionName "1.3.1"
versionCode 132
versionName "1.3.2"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

View File

@ -10,6 +10,7 @@ import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.ColorInt;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.content.FileProvider;
import android.support.v4.view.ViewCompat;
@ -140,6 +141,8 @@ public class ActAppSetting extends AppCompatActivity
TextView tvTimelineFontUrl;
String timeline_font;
TextView tvTimelineFontBoldUrl;
String timeline_font_bold;
EditText etTimelineFontSize;
EditText etAcctFontSize;
@ -214,7 +217,6 @@ public class ActAppSetting extends AppCompatActivity
swDontUseActionButtonWithQuickTootBar = findViewById( R.id.swDontUseActionButtonWithQuickTootBar );
swDontUseActionButtonWithQuickTootBar.setOnCheckedChangeListener( this );
cbNotificationSound = findViewById( R.id.cbNotificationSound );
cbNotificationVibration = findViewById( R.id.cbNotificationVibration );
cbNotificationLED = findViewById( R.id.cbNotificationLED );
@ -304,6 +306,8 @@ public class ActAppSetting extends AppCompatActivity
findViewById( R.id.btnTimelineFontEdit ).setOnClickListener( this );
findViewById( R.id.btnTimelineFontReset ).setOnClickListener( this );
findViewById( R.id.btnTimelineFontBoldEdit ).setOnClickListener( this );
findViewById( R.id.btnTimelineFontBoldReset ).setOnClickListener( this );
findViewById( R.id.btnSettingExport ).setOnClickListener( this );
findViewById( R.id.btnSettingImport ).setOnClickListener( this );
findViewById( R.id.btnCustomStreamListenerEdit ).setOnClickListener( this );
@ -330,7 +334,7 @@ public class ActAppSetting extends AppCompatActivity
etAutoCWLines = findViewById( R.id.etAutoCWLines );
etAutoCWLines.addTextChangedListener( this );
tvTimelineFontSize = findViewById( R.id.tvTimelineFontSize );
tvAcctFontSize = findViewById( R.id.tvAcctFontSize );
@ -341,6 +345,7 @@ public class ActAppSetting extends AppCompatActivity
etAcctFontSize.addTextChangedListener( new SizeCheckTextWatcher( tvAcctFontSize, etAcctFontSize, default_acct_font_size ) );
tvTimelineFontUrl = findViewById( R.id.tvTimelineFontUrl );
tvTimelineFontBoldUrl = findViewById( R.id.tvTimelineFontBoldUrl );
}
@ -401,11 +406,13 @@ public class ActAppSetting extends AppCompatActivity
etAcctFontSize.setText( formatFontSize( pref.getFloat( Pref.KEY_ACCT_FONT_SIZE, Float.NaN ) ) );
timeline_font = pref.getString( Pref.KEY_TIMELINE_FONT, "" );
timeline_font_bold = pref.getString( Pref.KEY_TIMELINE_FONT_BOLD, "" );
load_busy = false;
showFooterColor();
showTimelineFont();
showTimelineFont( tvTimelineFontUrl,timeline_font);
showTimelineFont( tvTimelineFontBoldUrl,timeline_font_bold);
showFontSize( tvTimelineFontSize, etTimelineFontSize, default_timeline_font_size );
showFontSize( tvAcctFontSize, etAcctFontSize, default_acct_font_size );
@ -434,7 +441,7 @@ public class ActAppSetting extends AppCompatActivity
.putBoolean( Pref.KEY_MENTION_FULL_ACCT, swMentionFullAcct.isChecked() )
.putBoolean( Pref.KEY_RELATIVE_TIMESTAMP, swRelativeTimestamp.isChecked() )
.putBoolean( Pref.KEY_DONT_USE_ACTION_BUTTON, swDontUseActionButtonWithQuickTootBar.isChecked() )
.putBoolean( Pref.KEY_NOTIFICATION_SOUND, cbNotificationSound.isChecked() )
.putBoolean( Pref.KEY_NOTIFICATION_VIBRATION, cbNotificationVibration.isChecked() )
.putBoolean( Pref.KEY_NOTIFICATION_LED, cbNotificationLED.isChecked() )
@ -454,6 +461,7 @@ public class ActAppSetting extends AppCompatActivity
.getIdFromIndex( spDefaultAccount.getSelectedItemPosition() ) )
.putString( Pref.KEY_TIMELINE_FONT, timeline_font )
.putString( Pref.KEY_TIMELINE_FONT_BOLD, timeline_font_bold )
.putString( Pref.KEY_COLUMN_WIDTH, etColumnWidth.getText().toString().trim() )
.putString( Pref.KEY_MEDIA_THUMB_HEIGHT, etMediaThumbHeight.getText().toString().trim() )
.putString( Pref.KEY_CLIENT_NAME, etClientName.getText().toString().trim() )
@ -540,7 +548,7 @@ public class ActAppSetting extends AppCompatActivity
case R.id.btnTimelineFontReset:
timeline_font = "";
saveUIToData();
showTimelineFont();
showTimelineFont( tvTimelineFontUrl,timeline_font);
break;
case R.id.btnTimelineFontEdit:
@ -550,7 +558,24 @@ public class ActAppSetting extends AppCompatActivity
intent.setType( "*/*" );
startActivityForResult( intent, REQUEST_CODE_TIMELINE_FONT );
}catch( Throwable ex ){
Utils.showToast( this, ex, "could not open picker for font/*" );
Utils.showToast( this, ex, "could not open picker for font" );
}
break;
case R.id.btnTimelineFontBoldReset:
timeline_font_bold = "";
saveUIToData();
showTimelineFont( tvTimelineFontBoldUrl,timeline_font_bold);
break;
case R.id.btnTimelineFontBoldEdit:
try{
Intent intent = new Intent( Intent.ACTION_OPEN_DOCUMENT );
intent.addCategory( Intent.CATEGORY_OPENABLE );
intent.setType( "*/*" );
startActivityForResult( intent, REQUEST_CODE_TIMELINE_FONT_BOLD );
}catch( Throwable ex ){
Utils.showToast( this, ex, "could not open picker for font" );
}
break;
@ -582,17 +607,24 @@ public class ActAppSetting extends AppCompatActivity
}
static final int REQUEST_CODE_TIMELINE_FONT = 1;
static final int REQUEST_CODE_APP_DATA_EXPORT = 2;
static final int REQUEST_CODE_APP_DATA_IMPORT = 3;
static final int REQUEST_CODE_TIMELINE_FONT_BOLD = 2;
static final int REQUEST_CODE_APP_DATA_EXPORT = 3;
static final int REQUEST_CODE_APP_DATA_IMPORT = 4;
@Override protected void onActivityResult( int requestCode, int resultCode, Intent data ){
if( resultCode == RESULT_OK && requestCode == REQUEST_CODE_TIMELINE_FONT ){
if( data != null ){
Uri uri = data.getData();
if( uri != null ){
getContentResolver().takePersistableUriPermission( uri, Intent.FLAG_GRANT_READ_URI_PERMISSION );
saveTimelineFont( uri );
}
if( resultCode == RESULT_OK && data != null && requestCode == REQUEST_CODE_TIMELINE_FONT ){
File file = saveTimelineFont( data.getData(), "TimelineFont" );
if( file != null ){
timeline_font = file.getAbsolutePath();
saveUIToData();
showTimelineFont( tvTimelineFontUrl,timeline_font);
}
}else if( resultCode == RESULT_OK && data != null && requestCode == REQUEST_CODE_TIMELINE_FONT_BOLD ){
File file = saveTimelineFont( data.getData(), "TimelineFontBold" );
if( file != null ){
timeline_font_bold = file.getAbsolutePath();
saveUIToData();
showTimelineFont( tvTimelineFontBoldUrl,timeline_font_bold);
}
}else if( resultCode == RESULT_OK && requestCode == REQUEST_CODE_APP_DATA_IMPORT ){
if( data != null ){
@ -774,40 +806,48 @@ public class ActAppSetting extends AppCompatActivity
}
}
private void showTimelineFont(){
private void showTimelineFont(
TextView tvFontUrl
,String font_url
){
try{
if( ! TextUtils.isEmpty( timeline_font ) ){
if( ! TextUtils.isEmpty( font_url ) ){
tvTimelineFontUrl.setTypeface( Typeface.DEFAULT );
Typeface face = Typeface.createFromFile( timeline_font );
tvTimelineFontUrl.setTypeface( face );
tvTimelineFontUrl.setText( timeline_font );
tvFontUrl.setTypeface( Typeface.DEFAULT );
Typeface face = Typeface.createFromFile( font_url );
tvFontUrl.setTypeface( face );
tvFontUrl.setText( font_url );
return;
}
}catch( Throwable ex ){
log.trace( ex );
}
// fallback
tvTimelineFontUrl.setText( getString( R.string.not_selected ) );
tvTimelineFontUrl.setTypeface( Typeface.DEFAULT );
tvFontUrl.setText( getString( R.string.not_selected ) );
tvFontUrl.setTypeface( Typeface.DEFAULT );
}
static final String TIMELINE_FONT_FILE_NAME = "TimelineFont";
private void saveTimelineFont( Uri uri ){
private @Nullable File saveTimelineFont( @Nullable Uri uri, @NonNull String file_name ){
try{
File dir = getFilesDir();
if( uri == null ){
Utils.showToast( this, false, "missing uri.");
return null;
}
getContentResolver().takePersistableUriPermission( uri, Intent.FLAG_GRANT_READ_URI_PERMISSION );
File dir = getFilesDir();
//noinspection ResultOfMethodCallIgnored
dir.mkdir();
File tmp_file = new File( dir, TIMELINE_FONT_FILE_NAME + ".tmp" );
File tmp_file = new File( dir, file_name + ".tmp" );
InputStream is = getContentResolver().openInputStream( uri );
if( is == null ){
Utils.showToast( this, false, "openInputStream returns null." );
return;
Utils.showToast( this, false, "openInputStream returns null. uri=%s", uri );
return null;
}
try{
FileOutputStream os = new FileOutputStream( tmp_file );
try{
@ -815,7 +855,6 @@ public class ActAppSetting extends AppCompatActivity
}finally{
IOUtils.closeQuietly( os );
}
}finally{
IOUtils.closeQuietly( is );
}
@ -823,22 +862,20 @@ public class ActAppSetting extends AppCompatActivity
Typeface face = Typeface.createFromFile( tmp_file );
if( face == null ){
Utils.showToast( this, false, "Typeface.createFromFile() failed." );
return;
return null;
}
File file = new File( dir, TIMELINE_FONT_FILE_NAME );
File file = new File( dir, file_name );
if( ! tmp_file.renameTo( file ) ){
Utils.showToast( this, false, "File operation failed." );
return;
return null;
}
timeline_font = file.getAbsolutePath();
saveUIToData();
showTimelineFont();
return file;
}catch( Throwable ex ){
log.trace( ex );
Utils.showToast( this, ex, "saveTimelineFont failed." );
return null;
}
}

View File

@ -767,6 +767,7 @@ public class ActMain extends AppCompatActivity
static final int COLUMN_WIDTH_MIN_DP = 300;
Typeface timeline_font;
Typeface timeline_font_bold;
boolean dont_crop_media_thumbnail;
@ -778,10 +779,9 @@ public class ActMain extends AppCompatActivity
void initUI(){
setContentView( R.layout.act_main );
String sv = pref.getString( Pref.KEY_TIMELINE_FONT, "" );
dont_crop_media_thumbnail = pref.getBoolean( Pref.KEY_DONT_CROP_MEDIA_THUMBNAIL, false );
String sv = pref.getString( Pref.KEY_TIMELINE_FONT, null );
if( ! TextUtils.isEmpty( sv ) ){
try{
timeline_font = Typeface.createFromFile( sv );
@ -790,6 +790,22 @@ public class ActMain extends AppCompatActivity
}
}
sv = pref.getString( Pref.KEY_TIMELINE_FONT_BOLD, null );
if( ! TextUtils.isEmpty( sv ) ){
try{
timeline_font_bold = Typeface.createFromFile( sv );
}catch( Throwable ex ){
log.trace( ex );
}
}else if( timeline_font != null ){
try{
timeline_font_bold = Typeface.create( timeline_font ,Typeface.BOLD );
}catch( Throwable ex ){
log.trace( ex );
}
}
llEmpty = findViewById( R.id.llEmpty );
// // toolbar

View File

@ -370,6 +370,7 @@ public class AppDataExporter {
// force reset
default:
case Pref.KEY_TIMELINE_FONT:
case Pref.KEY_TIMELINE_FONT_BOLD:
reader.skipValue();
e.remove( k );
break;

View File

@ -91,7 +91,7 @@ class ColumnViewHolder
@Override public void onScanView( View v ){
try{
if( v instanceof Button ){
// ボタンは太字なので触らない
// ボタンは触らない
}else if( v instanceof TextView ){
( (TextView) v ).setTypeface( activity.timeline_font );
}

View File

@ -5,7 +5,6 @@ import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import jp.juggler.subwaytooter.api.entity.TootAccount;
import jp.juggler.subwaytooter.table.SavedAccount;
import jp.juggler.subwaytooter.util.LogCategory;
import jp.juggler.subwaytooter.util.Utils;

View File

@ -54,11 +54,11 @@ class HeaderViewHolderInstance extends HeaderViewHolderBase implements View.OnCl
// tvSearchDesc.setMovementMethod( MyLinkMovementMethod.getInstance() );
// tvSearchDesc.setText( sv );
btnInstance = (TextView) viewRoot.findViewById( R.id.btnInstance );
tvVersion = (TextView) viewRoot.findViewById( R.id.tvVersion );
tvTitle = (TextView) viewRoot.findViewById( R.id.tvTitle );
btnEmail = (TextView) viewRoot.findViewById( R.id.btnEmail );
tvDescription = (TextView) viewRoot.findViewById( R.id.tvDescription );
btnInstance = viewRoot.findViewById( R.id.btnInstance );
tvVersion = viewRoot.findViewById( R.id.tvVersion );
tvTitle = viewRoot.findViewById( R.id.tvTitle );
btnEmail = viewRoot.findViewById( R.id.btnEmail );
tvDescription = viewRoot.findViewById( R.id.tvDescription );
btnInstance.setOnClickListener( this );
btnEmail.setOnClickListener( this );

View File

@ -4,7 +4,6 @@ import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import jp.juggler.subwaytooter.api.entity.TootAccount;
import jp.juggler.subwaytooter.util.HTMLDecoder;
import jp.juggler.subwaytooter.util.LogCategory;
import jp.juggler.subwaytooter.util.Utils;
@ -37,7 +36,7 @@ class HeaderViewHolderSearchDesc extends HeaderViewHolderBase {
CharSequence sv = HTMLDecoder.decodeHTML( activity, access_info, html, false, true, null );
TextView tvSearchDesc = (TextView) viewRoot.findViewById( R.id.tvSearchDesc );
TextView tvSearchDesc = viewRoot.findViewById( R.id.tvSearchDesc );
tvSearchDesc.setVisibility( View.VISIBLE );
tvSearchDesc.setMovementMethod( MyLinkMovementMethod.getInstance() );
tvSearchDesc.setText( sv );

View File

@ -116,14 +116,24 @@ class ItemViewHolder implements View.OnClickListener, View.OnLongClickListener {
this.tvFollowerName = view.findViewById( R.id.tvFollowerName );
this.tvBoosted = view.findViewById( R.id.tvBoosted );
if( activity.timeline_font != null ){
if( activity.timeline_font != null || activity.timeline_font_bold != null ){
Utils.scanView( view, new Utils.ScanViewCallback() {
@Override public void onScanView( View v ){
try{
if( v instanceof Button ){
// ボタンは太字なので触らない
}else if( v instanceof TextView ){
( (TextView) v ).setTypeface( activity.timeline_font );
switch( v.getId() ){
default:
( (TextView) v ).setTypeface( Utils.dor( activity.timeline_font, activity.timeline_font_bold ) );
break;
case R.id.tvName:
case R.id.tvFollowerName:
case R.id.tvBoosted:
( (TextView) v ).setTypeface( Utils.dor( activity.timeline_font_bold, activity.timeline_font ) );
break;
}
}
}catch( Throwable ex ){
log.trace( ex );
@ -444,8 +454,8 @@ class ItemViewHolder implements View.OnClickListener, View.OnLongClickListener {
activity.checkAutoCW( status, content );
TootStatusLike.AutoCW r = status.auto_cw;
tvContent.setMinLines( r != null ? r.originalLineCount : -1 );
tvContent.setMinLines( r != null ? r.originalLineCount : - 1 );
if( ! TextUtils.isEmpty( status.spoiler_text ) ){
// 元データに含まれるContent Warning を使う
llContentWarning.setVisibility( View.VISIBLE );
@ -569,7 +579,7 @@ class ItemViewHolder implements View.OnClickListener, View.OnLongClickListener {
btnContentWarning.setText( shown ? R.string.hide : R.string.show );
if( status != null ){
TootStatusLike.AutoCW r = status.auto_cw;
tvContent.setMinLines( r != null ? r.originalLineCount : -1 );
tvContent.setMinLines( r != null ? r.originalLineCount : - 1 );
if( r != null && r.decoded_spoiler_text != null ){
// 自動CWの場合はContentWarningのテキストを切り替える
tvContentWarning.setText( shown ? activity.getString( R.string.auto_cw_prefix ) : r.decoded_spoiler_text );

View File

@ -47,6 +47,8 @@ public class Pref {
static final String KEY_COLUMN_WIDTH = "ColumnWidth";
static final String KEY_MEDIA_THUMB_HEIGHT = "MediaThumbHeight";
static final String KEY_TIMELINE_FONT = "timeline_font";
static final String KEY_TIMELINE_FONT_BOLD = "timeline_font_bold";
static final String KEY_DONT_CROP_MEDIA_THUMBNAIL = "DontCropMediaThumb";
static final String KEY_STREAM_LISTENER_SECRET = "stream_listener_secret";

View File

@ -1126,4 +1126,14 @@ public class Utils {
}
return null;
}
// defined or
public static <T> T dor(T... args){
if( args != null ){
for( T a : args){
if(a != null ) return a;
}
}
return null;
}
}

View File

@ -940,6 +940,42 @@
<View style="@style/setting_divider"/>
<TextView
style="@style/setting_row_label"
android:text="@string/timeline_font_bold"
/>
<LinearLayout style="@style/setting_row_form">
<TextView
android:id="@+id/tvTimelineFontBoldUrl"
style="@style/setting_horizontal_stretch"
/>
</LinearLayout>
<LinearLayout style="@style/setting_row_form">
<Button
android:id="@+id/btnTimelineFontBoldEdit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/edit"
android:textAllCaps="false"
/>
<Button
android:id="@+id/btnTimelineFontBoldReset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/reset"
android:textAllCaps="false"
/>
</LinearLayout>
<View style="@style/setting_divider"/>
<TextView
android:id="@+id/tvTimelineFontSize"
style="@style/setting_row_label"

View File

@ -318,6 +318,7 @@
<string name="launcher_icon_by">Icone de l\'application créée par フタバ</string>
<string name="ssl_bug_7_0">Android 7.0 ne peut utiliser qu\'elliptic curve \"prime256v1\" pour les connexions sécurisées.\nL\'instance à laquelle vous voulez vous connecter semble ne pas le gérer.\n-Vous pouvez mettre à jour le système d\'exploitation vers Android 7.1.1.\n-Ou, demander au propriétaire de l\'instance de prendre en charge elliptic curve \"prime256v1\".\nPlus de détails ici: https://code.google.com/p/android/issues/detail?id=224438</string>
<string name="timeline_font">Changer la police de caractères de l\'interface\n(redémarrage nécessaire)</string>
<string name="timeline_font_bold">Changer la police de caractères de l\'interface (bold)\n(redémarrage nécessaire)</string>
<string name="account_in_draft_is_lost">Le compte utilisé pour ce brouillon a été supprimé de Subway Tooter. Le lien avec le toot d\'origine ne peut être restauré.</string>
<string name="attachment_in_draft_is_lost">Une ou plusieurs pièces jointes de ce brouillon sont introuvables.</string>
<string name="reply_to_in_draft_is_lost">Le toot auquel ce brouillon fait référence n\'existe plus, vous ne pouvez plus y répondre.</string>

View File

@ -606,6 +606,7 @@
<string name="ssl_bug_7_0">Android 7.0 には利用できる elliptic curve が \"prime256v1\" だけというバグがあります。\nしかし対象のインスタンスはこの elliptic curve に対応していないようです。\n可能ならOSバージョン 7.1.1以降にアップデートするとバグは修正されます。\nもしくは elliptic curve \"prime256v1\" に対応してもらうよう、あなたからインスタンスのオーナーに要望を出すことができます。\n関連情報 https://code.google.com/p/android/issues/detail?id=224438</string>
<string name="timeline_font">タイムラインのフォント(アプリ再起動が必要)</string>
<string name="timeline_font_bold">タイムラインのフォント(太字)(アプリ再起動が必要)</string>
<string name="account_in_draft_is_lost">下書きで使われているアカウント情報がありません。以下の文脈は失われます。in_reply_to, 添付メディア</string>
<string name="attachment_in_draft_is_lost">下書き中の添付メディアのいくつかは失われました</string>
<string name="reply_to_in_draft_is_lost">下書きから参照されている返信元の投稿は失われました。以下の文脈を再現できません。in_reply_to</string>

View File

@ -315,6 +315,7 @@
<string name="launcher_icon_by">Thanks to フタバ for the application icon.</string>
<string name="ssl_bug_7_0">Android 7.0 can only use the elliptic curve \"prime256v1\".\nUnfortunately your instance seems to not support it.\nThis bug has been fixed in Android 7.1.1.\nYou can either upgrade your OS or ask the administrator of your instance to add support to the elliptic curve \"prime256v1\".\nSee also https://code.google.com/p/android/issues/detail?id=224438</string>
<string name="timeline_font">Timeline font (app restart required)</string>
<string name="timeline_font_bold">Timeline font (bold, app restart required)</string>
<string name="restore_draft">Restore from draft</string>
<string name="select_draft">Which draft to restore ?</string>
<string name="account_in_draft_is_lost">The account used for this draft has been removed from app. The following context can not be restored. in_reply_to, media attachment.</string>