Fixed bottom toolbar not spread items equally

This commit is contained in:
Denis 2015-01-20 11:36:49 +02:00
parent 21940dee97
commit b7b075f2f2
6 changed files with 73 additions and 31 deletions

View file

@ -1,10 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_marginTop="?attr/actionBarSize"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_marginTop="?attr/actionBarSize"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout android:id="@+id/layout"
android:orientation="vertical"
@ -13,8 +13,9 @@
android:layout_weight="1"/>
<android.support.v7.widget.Toolbar android:orientation="horizontal"
android:id="@+id/bottomControls"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<net.osmand.plus.activities.search.toolbar.SplitToolbar
android:orientation="horizontal"
android:id="@+id/bottomControls"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>

View file

@ -17,7 +17,7 @@
android:layout_height="0dp"
android:layout_weight="1" />
<android.support.v7.widget.Toolbar
<net.osmand.plus.activities.search.toolbar.SplitToolbar
android:id="@+id/bottomControls"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />

View file

@ -5,6 +5,7 @@ import java.text.DecimalFormatSymbols;
import java.util.Locale;
import java.util.StringTokenizer;
import android.support.v4.view.MenuItemCompat;
import net.osmand.PlatformUtil;
import net.osmand.data.LatLon;
import net.osmand.plus.OsmandApplication;
@ -115,8 +116,8 @@ public class NavigatePointFragment extends Fragment implements SearchActivityChi
if(getActivity() instanceof SearchActivity) {
menu = ((SearchActivity) getActivity()).getClearToolbar(true).getMenu();
}
MenuItem menuItem = menu.add(0, NAVIGATE_TO, 0, R.string.context_menu_item_directions_to).setShowAsActionFlags(
MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
MenuItem menuItem = menu.add(0, NAVIGATE_TO, 0, R.string.context_menu_item_directions_to);
MenuItemCompat.setShowAsAction(menuItem, MenuItemCompat.SHOW_AS_ACTION_ALWAYS | MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT);
menuItem = menuItem.setIcon(light ? R.drawable.ic_action_gdirections_light : R.drawable.ic_action_gdirections_dark);
menuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
@ -128,13 +129,13 @@ public class NavigatePointFragment extends Fragment implements SearchActivityChi
});
TargetPointsHelper targets = app.getTargetPointsHelper();
if (targets.getPointToNavigate() != null) {
menuItem = menu.add(0, ADD_WAYPOINT, 0, R.string.context_menu_item_intermediate_point).setShowAsActionFlags(
MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
menuItem = menu.add(0, ADD_WAYPOINT, 0, R.string.context_menu_item_intermediate_point);
MenuItemCompat.setShowAsAction(menuItem, MenuItemCompat.SHOW_AS_ACTION_ALWAYS | MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT);
menuItem = menuItem.setIcon(light ? R.drawable.ic_action_flage_light
: R.drawable.ic_action_flage_dark);
} else {
menuItem = menu.add(0, ADD_WAYPOINT, 0, R.string.context_menu_item_destination_point).setShowAsActionFlags(
MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
menuItem = menu.add(0, ADD_WAYPOINT, 0, R.string.context_menu_item_destination_point);
MenuItemCompat.setShowAsAction(menuItem, MenuItemCompat.SHOW_AS_ACTION_ALWAYS | MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT);
menuItem = menuItem.setIcon(light ? R.drawable.ic_action_flag_light
: R.drawable.ic_action_flag_dark);
}
@ -146,7 +147,8 @@ public class NavigatePointFragment extends Fragment implements SearchActivityChi
}
});
//}
menuItem = menu.add(0, SHOW_ON_MAP, 0, R.string.search_shown_on_map).setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
menuItem = menu.add(0, SHOW_ON_MAP, 0, R.string.search_shown_on_map);
MenuItemCompat.setShowAsAction(menuItem, MenuItemCompat.SHOW_AS_ACTION_ALWAYS | MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT);
menuItem = menuItem.setIcon(light ? R.drawable.ic_action_marker_light : R.drawable.ic_action_marker_dark);
menuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
@ -157,7 +159,8 @@ public class NavigatePointFragment extends Fragment implements SearchActivityChi
}
});
menuItem = menu.add(0, ADD_TO_FAVORITE, 0, R.string.add_to_favourite).setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
menuItem = menu.add(0, ADD_TO_FAVORITE, 0, R.string.add_to_favourite);
MenuItemCompat.setShowAsAction(menuItem, MenuItemCompat.SHOW_AS_ACTION_ALWAYS | MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT);
menuItem = menuItem.setIcon(light ? R.drawable.ic_action_fav_light : R.drawable.ic_action_fav_dark);
menuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {

View file

@ -88,8 +88,8 @@ public class SearchAddressFragment extends Fragment {
menu = ((SearchActivity) getActivity()).getClearToolbar(true).getMenu();
}
if(getActivity() instanceof SearchAddressActivity) {
MenuItem menuItem = menu.add(0, SELECT_POINT, 0, "").setShowAsActionFlags(
MenuItem.SHOW_AS_ACTION_ALWAYS );
MenuItem menuItem = menu.add(0, SELECT_POINT, 0, "");
MenuItemCompat.setShowAsAction(menuItem, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
menuItem = menuItem.setIcon(light ? R.drawable.ic_action_ok_light : R.drawable.ic_action_ok_dark);
menuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
@ -99,8 +99,8 @@ public class SearchAddressFragment extends Fragment {
}
});
} else {
MenuItem menuItem = menu.add(0, NAVIGATE_TO, 0, R.string.context_menu_item_directions_to).setShowAsActionFlags(
MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
MenuItem menuItem = menu.add(0, NAVIGATE_TO, 0, R.string.context_menu_item_directions_to);
MenuItemCompat.setShowAsAction(menuItem, MenuItemCompat.SHOW_AS_ACTION_ALWAYS | MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT);
menuItem = menuItem.setIcon(light ? R.drawable.ic_action_gdirections_light : R.drawable.ic_action_gdirections_dark);
menuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
@ -111,12 +111,12 @@ public class SearchAddressFragment extends Fragment {
});
TargetPointsHelper targets = ((OsmandApplication) getApplication()).getTargetPointsHelper();
if (targets.getPointToNavigate() != null) {
menuItem = menu.add(0, ADD_WAYPOINT, 0, R.string.context_menu_item_intermediate_point).setShowAsActionFlags(
MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
menuItem = menu.add(0, ADD_WAYPOINT, 0, R.string.context_menu_item_intermediate_point);
MenuItemCompat.setShowAsAction(menuItem, MenuItemCompat.SHOW_AS_ACTION_ALWAYS | MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT);
menuItem = menuItem.setIcon(light ? R.drawable.ic_action_flage_light : R.drawable.ic_action_flage_dark);
} else {
menuItem = menu.add(0, ADD_WAYPOINT, 0, R.string.context_menu_item_destination_point).setShowAsActionFlags(
MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
menuItem = menu.add(0, ADD_WAYPOINT, 0, R.string.context_menu_item_destination_point);
MenuItemCompat.setShowAsAction(menuItem, MenuItemCompat.SHOW_AS_ACTION_ALWAYS | MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT);
menuItem = menuItem.setIcon(light ? R.drawable.ic_action_flag_light : R.drawable.ic_action_flag_dark);
}
menuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
@ -126,7 +126,8 @@ public class SearchAddressFragment extends Fragment {
return true;
}
});
menuItem = menu.add(0, SHOW_ON_MAP, 0, R.string.search_shown_on_map).setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
menuItem = menu.add(0, SHOW_ON_MAP, 0, R.string.search_shown_on_map);
MenuItemCompat.setShowAsAction(menuItem, MenuItemCompat.SHOW_AS_ACTION_ALWAYS | MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT);
menuItem = menuItem.setIcon(light ? R.drawable.ic_action_marker_light : R.drawable.ic_action_marker_dark);
menuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
@ -137,7 +138,8 @@ public class SearchAddressFragment extends Fragment {
}
});
menuItem = menu.add(0, ADD_TO_FAVORITE, 0, R.string.add_to_favourite).setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
menuItem = menu.add(0, ADD_TO_FAVORITE, 0, R.string.add_to_favourite);
MenuItemCompat.setShowAsAction(menuItem, MenuItemCompat.SHOW_AS_ACTION_ALWAYS | MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT);
menuItem = menuItem.setIcon(light ? R.drawable.ic_action_fav_light : R.drawable.ic_action_fav_dark);
menuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
@ -147,7 +149,8 @@ public class SearchAddressFragment extends Fragment {
return true;
}
});
menuItem = menu.add(0, ONLINE_SEARCH, 0, R.string.search_online_address).setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
menuItem = menu.add(0, ONLINE_SEARCH, 0, R.string.search_online_address);
MenuItemCompat.setShowAsAction(menuItem, MenuItemCompat.SHOW_AS_ACTION_ALWAYS | MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT);
menuItem = menuItem.setIcon(light ? R.drawable.ic_action_gnext_light : R.drawable.ic_action_gnext_dark);
menuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override

View file

@ -64,7 +64,8 @@ public class SearchAddressOnlineFragment extends Fragment implements SearchActiv
if(getActivity() instanceof SearchActivity) {
menu = ((SearchActivity) getActivity()).getClearToolbar(true).getMenu();
}
MenuItem menuItem = menu.add(0, 1, 0, R.string.search_offline_clear_search).setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT );
MenuItem menuItem = menu.add(0, 1, 0, R.string.search_offline_clear_search);
MenuItemCompat.setShowAsAction(menuItem, MenuItemCompat.SHOW_AS_ACTION_ALWAYS | MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT);
menuItem = menuItem.setIcon(light ? R.drawable.ic_action_gremove_light : R.drawable.ic_action_gremove_dark);
menuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
@ -76,8 +77,8 @@ public class SearchAddressOnlineFragment extends Fragment implements SearchActiv
}
});
if (getActivity() instanceof SearchActivity) {
menuItem = menu.add(0, 0, 0, R.string.search_offline_address).setShowAsActionFlags(
MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
menuItem = menu.add(0, 0, 0, R.string.search_offline_address);
MenuItemCompat.setShowAsAction(menuItem, MenuItemCompat.SHOW_AS_ACTION_ALWAYS | MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT);
menuItem = menuItem.setIcon(light ? R.drawable.ic_action_gnext_light : R.drawable.ic_action_gnext_dark);
menuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override

View file

@ -0,0 +1,34 @@
package net.osmand.plus.activities.search.toolbar;
import android.content.Context;
import android.support.v7.widget.ActionMenuView;
import android.support.v7.widget.Toolbar;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
/**
* Created by Denis
* on 20.01.2015.
*/
public class SplitToolbar extends Toolbar {
public SplitToolbar(Context context) {
super(context);
}
public SplitToolbar(Context context, AttributeSet attrs) {
super(context, attrs);
}
public SplitToolbar(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
public void addView(View child, ViewGroup.LayoutParams params) {
if (child instanceof ActionMenuView) {
params.width = LayoutParams.MATCH_PARENT;
}
super.addView(child, params);
}
}