From 96a71caa26f4d28230c4454a63297d6703a21350 Mon Sep 17 00:00:00 2001 From: Pavol Zibrita Date: Thu, 23 Aug 2012 23:36:31 +0200 Subject: [PATCH] Improving FontFitTextView and using it in the layers/settings list --- .../res/layout/layers_list_activity_item.xml | 2 +- .../activities/DownloadIndexActivity.java | 2 - .../plus/activities/FontFitTextView.java | 45 ++++++------------- .../net/osmand/plus/views/MapInfoLayer.java | 6 --- 4 files changed, 15 insertions(+), 40 deletions(-) diff --git a/OsmAnd/res/layout/layers_list_activity_item.xml b/OsmAnd/res/layout/layers_list_activity_item.xml index eadd0a5467..5cbfca79dc 100644 --- a/OsmAnd/res/layout/layers_list_activity_item.xml +++ b/OsmAnd/res/layout/layers_list_activity_item.xml @@ -9,7 +9,7 @@ android:layout_marginRight="5dip" android:weightSum="1" > - MAX_TEXT_SIZE) - setTextSize(MAX_TEXT_SIZE); + setSingleLine(); + setEllipsize(TruncateAt.MARQUEE); } // Default constructor override public FontFitTextView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); - - float size = this.getTextSize(); - if (size > MAX_TEXT_SIZE) - setTextSize(MAX_TEXT_SIZE); + setSingleLine(); + setEllipsize(TruncateAt.MARQUEE); } private void refitText(String text, int textWidth) { if (textWidth > 0) { + Drawable left = getCompoundDrawables()[0]; + Drawable right = getCompoundDrawables()[2]; float availableWidth = textWidth - this.getPaddingLeft() - - this.getPaddingRight(); + - this.getPaddingRight() - this.getCompoundDrawablePadding() + - (left != null ? left.getMinimumWidth() : 0) + - (right != null ? right.getMinimumWidth() : 0); + setTextScaleX(1f); TextPaint tp = getPaint(); - Rect rect = new Rect(); - tp.getTextBounds(text, 0, text.length(), rect); - float size = rect.width(); + float size = tp.measureText(text); if (size > availableWidth) setTextScaleX(availableWidth / size); @@ -51,11 +49,9 @@ public class FontFitTextView extends TextView { @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - super.onMeasure(widthMeasureSpec, heightMeasureSpec); int parentWidth = MeasureSpec.getSize(widthMeasureSpec); - int parentHeight = MeasureSpec.getSize(heightMeasureSpec); refitText(this.getText().toString(), parentWidth); - this.setMeasuredDimension(parentWidth, parentHeight); + super.onMeasure(widthMeasureSpec, heightMeasureSpec); } @Override @@ -70,18 +66,5 @@ public class FontFitTextView extends TextView { refitText(this.getText().toString(), w); } } - -// /** -// * Resize text after measuring -// */ -// @Override -// protected void onLayout(boolean changed, int left, int top, int right, int bottom) { -// if(changed) { // || mNeedsResize) { -// int widthLimit = (right - left) - getCompoundPaddingLeft() - getCompoundPaddingRight(); -// int heightLimit = (bottom - top) - getCompoundPaddingBottom() - getCompoundPaddingTop(); -// resizeText(widthLimit, heightLimit); -// } -// super.onLayout(changed, left, top, right, bottom); -// } } diff --git a/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java b/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java index ca64dde3c4..a93766377a 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java @@ -26,7 +26,6 @@ import net.osmand.render.RenderingRuleProperty; import net.osmand.render.RenderingRulesStorage; import android.app.AlertDialog; import android.app.AlertDialog.Builder; -import android.app.Dialog; import android.content.Context; import android.content.DialogInterface; import android.content.DialogInterface.OnClickListener; @@ -45,11 +44,7 @@ import android.view.Gravity; import android.view.View; import android.view.View.MeasureSpec; import android.view.ViewGroup; -import android.view.Window; import android.view.WindowManager; -import android.widget.AdapterView; -import android.widget.AdapterView.OnItemClickListener; -import android.widget.AdapterView.OnItemSelectedListener; import android.widget.ArrayAdapter; import android.widget.CheckBox; import android.widget.CompoundButton; @@ -59,7 +54,6 @@ import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.LinearLayout.LayoutParams; import android.widget.ListAdapter; -import android.widget.ListView; import android.widget.TextView; import android.widget.Toast;