Substitue button with expandable layout
This commit is contained in:
parent
91e89169c5
commit
e10ff36add
4 changed files with 61 additions and 17 deletions
|
@ -1,9 +1,11 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" >
|
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:custom="http://schemas.android.com/apk/res/net.osmand.plus"
|
||||||
|
android:layout_width="fill_parent" android:layout_height="fill_parent" >
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="fill_parent" android:orientation="vertical">
|
android:layout_height="fill_parent" android:orientation="vertical" android:gravity="center_horizontal">
|
||||||
|
<net.osmand.view.ExpandableLinearLayout custom:maxVisibleWidth="800dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" >
|
||||||
<TextView android:id="@+id/TextView" android:textSize="16sp" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center" android:layout_marginTop="4dp" android:layout_marginBottom="4dp" android:text="@string/navigate_point_top_text"></TextView>
|
<TextView android:id="@+id/TextView" android:textSize="16sp" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center" android:layout_marginTop="4dp" android:layout_marginBottom="4dp" android:text="@string/navigate_point_top_text"></TextView>
|
||||||
|
|
||||||
<TableLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:stretchColumns="1">
|
<TableLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:stretchColumns="1">
|
||||||
|
@ -26,6 +28,6 @@
|
||||||
<Button android:layout_width="125dp" android:layout_height="wrap_content" android:id="@+id/ShowOnMap" android:text="@string/search_shown_on_map"></Button>
|
<Button android:layout_width="125dp" android:layout_height="wrap_content" android:id="@+id/ShowOnMap" android:text="@string/search_shown_on_map"></Button>
|
||||||
<Button android:layout_width="125dp" android:layout_height="wrap_content" android:id="@+id/Cancel" android:text="@string/navigate_point_cancel" > </Button>
|
<Button android:layout_width="125dp" android:layout_height="wrap_content" android:id="@+id/Cancel" android:text="@string/navigate_point_cancel" > </Button>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
</net.osmand.view.ExpandableLinearLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</ScrollView>
|
</ScrollView>
|
|
@ -1,49 +1,47 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:custom="http://schemas.android.com/apk/res/net.osmand.plus"
|
xmlns:custom="http://schemas.android.com/apk/res/net.osmand.plus"
|
||||||
xmlns:custom2="http://schemas.android.com/apk/res/net.osmand.views"
|
|
||||||
android:layout_width="fill_parent" android:layout_height="fill_parent">
|
android:layout_width="fill_parent" android:layout_height="fill_parent">
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="fill_parent" android:orientation="vertical">
|
android:layout_height="wrap_content" android:orientation="vertical" android:gravity="center_horizontal">
|
||||||
|
|
||||||
|
|
||||||
<TextView android:id="@+id/TopTextView" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center_horizontal"
|
<TextView android:id="@+id/TopTextView" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center_horizontal"
|
||||||
android:layout_marginTop = "5dp" android:text="@string/search_address_top_text">
|
android:layout_marginTop = "5dp" android:text="@string/search_address_top_text">
|
||||||
</TextView>
|
</TextView>
|
||||||
|
<net.osmand.view.ExpandableLinearLayout custom:maxVisibleWidth="800dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" >
|
||||||
|
|
||||||
<LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center_horizontal">
|
<TableLayout android:id="@+id/TableLayout" android:layout_width="fill_parent" android:stretchColumns="1" android:layout_height="wrap_content" >
|
||||||
<TableLayout android:id="@+id/TableLayout" android:layout_width="fill_parent" android:stretchColumns="1" android:layout_height="wrap_content" android:gravity="center_horizontal">
|
|
||||||
<TableRow android:id="@+id/TableRow" android:layout_marginLeft = "5dp">
|
<TableRow android:id="@+id/TableRow" android:layout_marginLeft = "5dp">
|
||||||
<TextView android:id="@+id/TextView" android:text="@string/search_address_region">
|
<TextView android:id="@+id/TextView" android:text="@string/search_address_region">
|
||||||
</TextView>
|
</TextView>
|
||||||
<net.osmand.view.ExpandableButton android:id="@+id/CountryButton" android:text="@string/ChooseCountry" custom:maxVisibleWidth="500dp"/>
|
<Button android:id="@+id/CountryButton" android:text="@string/ChooseCountry" />
|
||||||
<ImageButton android:id="@+id/ResetCountry" android:layout_marginRight = "5dp" android:background="@drawable/reset" android:contentDescription="@string/default_buttons_reset">
|
<ImageButton android:id="@+id/ResetCountry" android:layout_marginRight = "5dp" android:background="@drawable/reset" android:contentDescription="@string/default_buttons_reset">
|
||||||
</ImageButton>
|
</ImageButton>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
<TableRow android:id="@+id/TableRow" android:layout_marginLeft = "5dp" >
|
<TableRow android:id="@+id/TableRow" android:layout_marginLeft = "5dp" >
|
||||||
<TextView android:id="@+id/TextView" android:text="@string/search_address_city">
|
<TextView android:id="@+id/TextView" android:text="@string/search_address_city">
|
||||||
</TextView>
|
</TextView>
|
||||||
<net.osmand.view.ExpandableButton android:id="@+id/CityButton" android:text="@string/choose_city" custom:maxVisibleWidth="500dp" />
|
<Button android:id="@+id/CityButton" android:text="@string/choose_city" />
|
||||||
<ImageButton android:id="@+id/ResetCity" android:layout_marginRight = "5dp" android:background="@drawable/reset" android:contentDescription="@string/default_buttons_reset">
|
<ImageButton android:id="@+id/ResetCity" android:layout_marginRight = "5dp" android:background="@drawable/reset" android:contentDescription="@string/default_buttons_reset">
|
||||||
</ImageButton>
|
</ImageButton>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
<TableRow android:id="@+id/TableRow" android:layout_marginLeft = "5dp">
|
<TableRow android:id="@+id/TableRow" android:layout_marginLeft = "5dp">
|
||||||
<TextView android:id="@+id/TextView" android:text="@string/search_address_street">
|
<TextView android:id="@+id/TextView" android:text="@string/search_address_street">
|
||||||
</TextView>
|
</TextView>
|
||||||
<net.osmand.view.ExpandableButton android:id="@+id/StreetButton" android:text="@string/choose_street" custom:maxVisibleWidth="500dp"/>
|
<Button android:id="@+id/StreetButton" android:text="@string/choose_street" />
|
||||||
<ImageButton android:id="@+id/ResetStreet" android:layout_marginRight = "5dp" android:background="@drawable/reset" android:contentDescription="@string/default_buttons_reset">
|
<ImageButton android:id="@+id/ResetStreet" android:layout_marginRight = "5dp" android:background="@drawable/reset" android:contentDescription="@string/default_buttons_reset">
|
||||||
</ImageButton>
|
</ImageButton>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
<TableRow android:id="@+id/TableRow" android:layout_marginLeft = "5dp">
|
<TableRow android:id="@+id/TableRow" android:layout_marginLeft = "5dp">
|
||||||
<TextView android:id="@+id/BuildingText" android:text="@string/search_address_building">
|
<TextView android:id="@+id/BuildingText" android:text="@string/search_address_building">
|
||||||
</TextView>
|
</TextView>
|
||||||
<net.osmand.view.ExpandableButton android:id="@+id/BuildingButton" android:text="@string/choose_building" custom:maxVisibleWidth="500dp"/>
|
<Button android:id="@+id/BuildingButton" android:text="@string/choose_building" />
|
||||||
<ImageButton android:id="@+id/ResetBuilding" android:layout_marginRight = "5dp" android:background="@drawable/reset" android:contentDescription="@string/default_buttons_reset">
|
<ImageButton android:id="@+id/ResetBuilding" android:layout_marginRight = "5dp" android:background="@drawable/reset" android:contentDescription="@string/default_buttons_reset">
|
||||||
</ImageButton>
|
</ImageButton>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</TableLayout>
|
</TableLayout>
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<RadioGroup android:orientation="horizontal" android:layout_span="3" android:id="@+id/RadioGroup" android:layout_marginLeft="5dp" android:layout_width="fill_parent" android:layout_height="wrap_content">
|
<RadioGroup android:orientation="horizontal" android:layout_span="3" android:id="@+id/RadioGroup" android:layout_marginLeft="5dp" android:layout_width="fill_parent" android:layout_height="wrap_content">
|
||||||
<RadioButton android:id="@+id/RadioBuilding" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/search_address_building_option"></RadioButton>
|
<RadioButton android:id="@+id/RadioBuilding" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/search_address_building_option"></RadioButton>
|
||||||
|
@ -69,5 +67,7 @@
|
||||||
</Button>
|
</Button>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
</net.osmand.view.ExpandableLinearLayout >
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</ScrollView>
|
</ScrollView>
|
|
@ -33,6 +33,7 @@ public class ExpandableButton extends Button {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||||
|
if(maxWidth >0){
|
||||||
if(MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.UNSPECIFIED) {
|
if(MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.UNSPECIFIED) {
|
||||||
widthMeasureSpec = MeasureSpec.makeMeasureSpec((int) maxWidth, MeasureSpec.AT_MOST);
|
widthMeasureSpec = MeasureSpec.makeMeasureSpec((int) maxWidth, MeasureSpec.AT_MOST);
|
||||||
} else if(MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.AT_MOST && (MeasureSpec.getSize(widthMeasureSpec)) > maxWidth){
|
} else if(MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.AT_MOST && (MeasureSpec.getSize(widthMeasureSpec)) > maxWidth){
|
||||||
|
@ -40,10 +41,8 @@ public class ExpandableButton extends Button {
|
||||||
} else if(MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.EXACTLY && (MeasureSpec.getSize(widthMeasureSpec)) > maxWidth){
|
} else if(MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.EXACTLY && (MeasureSpec.getSize(widthMeasureSpec)) > maxWidth){
|
||||||
widthMeasureSpec = MeasureSpec.makeMeasureSpec((int) maxWidth, MeasureSpec.EXACTLY);
|
widthMeasureSpec = MeasureSpec.makeMeasureSpec((int) maxWidth, MeasureSpec.EXACTLY);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||||
// if(maxWidth != 0 && getMeasuredWidth() > maxWidth) {
|
|
||||||
// setMeasuredDimension((int) maxWidth, getMeasuredHeight());
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
43
OsmAnd/src/net/osmand/view/ExpandableLinearLayout.java
Normal file
43
OsmAnd/src/net/osmand/view/ExpandableLinearLayout.java
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
package net.osmand.view;
|
||||||
|
|
||||||
|
import net.osmand.plus.R;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.res.TypedArray;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
|
||||||
|
public class ExpandableLinearLayout extends LinearLayout {
|
||||||
|
|
||||||
|
private float maxWidth;
|
||||||
|
|
||||||
|
public ExpandableLinearLayout(Context context, AttributeSet attrs) {
|
||||||
|
super(context, attrs);
|
||||||
|
if(attrs != null) {
|
||||||
|
TypedArray ar = context.obtainStyledAttributes(attrs, R.styleable.ExpandableView);
|
||||||
|
maxWidth = ar.getDimension(R.styleable.ExpandableView_maxVisibleWidth, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ExpandableLinearLayout(Context context) {
|
||||||
|
this(context, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||||
|
if (maxWidth > 0) {
|
||||||
|
if (MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.UNSPECIFIED) {
|
||||||
|
widthMeasureSpec = MeasureSpec.makeMeasureSpec((int) maxWidth, MeasureSpec.AT_MOST);
|
||||||
|
} else if (MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.AT_MOST && (MeasureSpec.getSize(widthMeasureSpec)) > maxWidth) {
|
||||||
|
widthMeasureSpec = MeasureSpec.makeMeasureSpec((int) maxWidth, MeasureSpec.AT_MOST);
|
||||||
|
} else if (MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.EXACTLY && (MeasureSpec.getSize(widthMeasureSpec)) > maxWidth) {
|
||||||
|
widthMeasureSpec = MeasureSpec.makeMeasureSpec((int) maxWidth, MeasureSpec.EXACTLY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||||
|
// if(maxWidth != 0 && getMeasuredWidth() > maxWidth) {
|
||||||
|
// setMeasuredDimension((int) maxWidth, getMeasuredHeight());
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue