Fixing the local index activity title and description text.

This commit is contained in:
Pavol Zibrita 2012-03-15 22:28:28 +01:00
parent c41d534a49
commit 2b054dc780
5 changed files with 178 additions and 42 deletions

View file

@ -5,13 +5,13 @@
android:layout_height="fill_parent" android:orientation="vertical">
<TextView android:id="@+id/DescriptionTextTop" android:layout_width="fill_parent" android:layout_height="wrap_content"
android:text="" android:layout_marginLeft = "3dp" android:layout_marginRight = "3dp"
android:text="" android:layout_marginLeft = "10dp" android:layout_marginRight = "10dp"
android:visibility="gone"/>
<LinearLayout android:id="@+id/LoadingPanel" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="3dp">
<!-- Button android:id="@+id/DownloadButton" android:layout_width="wrap_content" android:layout_gravity="right" android:layout_height="wrap_content" android:text="@string/local_index_download"
android:layout_marginLeft = "3dp" android:layout_marginTop ="3dp" android:layout_marginRight = "3dp"/-->
<TextView android:id="@+id/DescriptionText" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:layout_margin="3dp"
android:text="@string/local_index_description"/>
<TextView android:id="@+id/DescriptionText" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:layout_marginLeft="10dp"
android:layout_marginRight="10dp" android:text="@string/local_index_description"/>
<LinearLayout android:id="@+id/FillLayoutStart" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:visibility="gone"/>
<Button android:id="@+id/ActionButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/local_index_download"
android:layout_marginLeft = "3dp" android:layout_marginTop ="3dp" android:layout_marginRight = "3dp" android:visibility="gone"/>

View file

@ -1,33 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:background="@drawable/tab_title_headline_background" >
android:id="@+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/tab_title_headline_background"
android:orientation="horizontal" >
<Button
android:id="@+id/back_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_gravity="top"
android:background="@drawable/tab_back_button"
android:text="" />
<Button
android:id="@+id/back_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_gravity="top"
android:background="@drawable/tab_back_button"
android:text="" />
<ImageView
android:id="@+id/title_image"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="27dp"
android:layout_marginTop="0dp"
android:layout_marginBottom="3dp"
android:src="@drawable/tab_favorites_screen_icon" />
<!-- Button
<!--
Button
android:id="@+id/extra_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@ -36,16 +26,30 @@
android:layout_gravity="top"
android:background="@drawable/tab_back_button"
android:visibility="gone"
android:text="" /-->
<TextView
android:id="@+id/title_text"
style="@style/WhiteTitleText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="29dp"
android:layout_toRightOf="@+id/back_button"
android:text="@string/favourites_activity" />
android:text="" /
-->
<net.osmand.plus.activities.FontFitTextView
android:id="@+id/title_text"
style="@style/WhiteTitleText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:layout_centerVertical="true"
android:layout_marginLeft="22dp"
android:layout_marginRight="22dp"
android:layout_toLeftOf="@+id/title_image"
android:layout_toRightOf="@+id/back_button"
android:text="@string/favourites_activity" />
<ImageView
android:id="@+id/title_image"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="20dp"
android:layout_gravity="top"
android:src="@drawable/tab_favorites_screen_icon" />
</RelativeLayout>

View file

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/tab_title_headline_background"
android:orientation="horizontal" >
<Button
android:id="@+id/back_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_gravity="top"
android:background="@drawable/tab_back_button"
android:text="" />
<net.osmand.plus.activities.FontFitTextView
android:id="@+id/title_text"
style="@style/WhiteTitleText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:layout_centerVertical="true"
android:layout_marginLeft="22dp"
android:layout_marginRight="22dp"
android:layout_toLeftOf="@+id/title_image"
android:layout_toRightOf="@+id/back_button"
android:text="@string/favourites_activity" />
<ImageView
android:id="@+id/title_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_gravity="top"
android:background="@drawable/tab_back_button_background" />
</RelativeLayout>

View file

@ -17,7 +17,7 @@ public class CustomTitleBarWithExtraButton extends CustomTitleBar {
@Override
protected int getTitleBarLayout() {
return R.layout.titlebar;
return R.layout.titlebar_extrabutton;
}
@Override
@ -27,8 +27,12 @@ public class CustomTitleBarWithExtraButton extends CustomTitleBar {
titleImg.setImageResource(getTitleImageRes());
// titleImg.setVisibility(View.GONE);
titleImg.setBackgroundResource(R.drawable.tab_back_button_background);
// titleImg.setPadding(0, 0, 2, 0);
// titleImg.getLayoutParams().height = LayoutParams.WRAP_CONTENT;
// titleImg.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
// titleImg.setBackgroundResource(R.drawable.tab_back_button_background);
titleImg.setOnClickListener(listener);
// titleImg.invalidate();
//
// Button extraButton = (Button)getActivity().findViewById(R.id.extra_button);
// extraButton.setVisibility(View.VISIBLE);

View file

@ -0,0 +1,87 @@
package net.osmand.plus.activities;
import android.content.Context;
import android.graphics.Rect;
import android.text.TextPaint;
import android.util.AttributeSet;
import android.widget.TextView;
/* Based on
* from http://stackoverflow.com/questions/2617266/how-to-adjust-text-font-size-to-fit-textview
*/
public class FontFitTextView extends TextView {
private static float MAX_TEXT_SIZE = 20;
public FontFitTextView(Context context) {
this(context, null);
}
public FontFitTextView(Context context, AttributeSet attrs) {
super(context, attrs);
float size = this.getTextSize();
if (size > MAX_TEXT_SIZE)
setTextSize(MAX_TEXT_SIZE);
}
// 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);
}
private void refitText(String text, int textWidth) {
if (textWidth > 0) {
float availableWidth = textWidth - this.getPaddingLeft()
- this.getPaddingRight();
TextPaint tp = getPaint();
Rect rect = new Rect();
tp.getTextBounds(text, 0, text.length(), rect);
float size = rect.width();
if (size > availableWidth)
setTextScaleX(availableWidth / size);
}
}
@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);
}
@Override
protected void onTextChanged(final CharSequence text, final int start,
final int before, final int after) {
refitText(text.toString(), this.getWidth());
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
if (w != oldw) {
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);
// }
}