updated styles for search and split action bar
This commit is contained in:
parent
309161ceb2
commit
9705642d7e
5 changed files with 118 additions and 84 deletions
|
@ -3,7 +3,7 @@
|
|||
<color name="actionbar_dark_color">#39464d</color>
|
||||
<color name="tool_bar_dark_color">#CC080B0D</color>
|
||||
<color name="actionbar_light_color">#ff8f00</color>
|
||||
<color name="tool_bar_light_color">#CC080B0D</color>
|
||||
<color name="tool_bar_light_color">#b4ff8f00</color>
|
||||
|
||||
<color name="dashboard_descr_colol">#727272</color>
|
||||
<color name="dashboard_background">#eaeaea</color>
|
||||
|
|
|
@ -5,6 +5,7 @@ import java.text.DecimalFormatSymbols;
|
|||
import java.util.Locale;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.support.v4.view.MenuItemCompat;
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.data.LatLon;
|
||||
|
@ -15,6 +16,7 @@ import net.osmand.plus.activities.search.SearchActivity;
|
|||
import net.osmand.plus.activities.search.SearchActivity.SearchActivityChild;
|
||||
import net.osmand.plus.dialogs.DirectionsDialogs;
|
||||
import net.osmand.plus.dialogs.FavoriteDialogs;
|
||||
import net.osmand.plus.helpers.ScreenOrientationHelper;
|
||||
import net.osmand.util.MapUtils;
|
||||
import android.app.Dialog;
|
||||
import android.content.Intent;
|
||||
|
@ -111,13 +113,21 @@ public class NavigatePointFragment extends Fragment implements SearchActivityChi
|
|||
@Override
|
||||
public void onCreateOptionsMenu(Menu onCreate, MenuInflater inflater) {
|
||||
OsmandApplication app = (OsmandApplication) getActivity().getApplication();
|
||||
int orientation = ScreenOrientationHelper.getScreenOrientation(getActivity());
|
||||
boolean portrait = orientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT ||
|
||||
orientation == ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
|
||||
boolean light = app.getSettings().isLightActionBar();
|
||||
Menu menu = onCreate;
|
||||
if(getActivity() instanceof SearchActivity) {
|
||||
menu = ((SearchActivity) getActivity()).getClearToolbar(true).getMenu();
|
||||
if (portrait) {
|
||||
menu = ((SearchActivity) getActivity()).getClearToolbar(true).getMenu();
|
||||
} else {
|
||||
((SearchActivity) getActivity()).getClearToolbar(false);
|
||||
}
|
||||
light = false;
|
||||
}
|
||||
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);
|
||||
MenuItemCompat.setShowAsAction(menuItem, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
|
||||
menuItem = menuItem.setIcon(light ? R.drawable.ic_action_gdirections_light : R.drawable.ic_action_gdirections_dark);
|
||||
menuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
|
||||
|
||||
|
@ -130,12 +140,12 @@ 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);
|
||||
MenuItemCompat.setShowAsAction(menuItem, MenuItemCompat.SHOW_AS_ACTION_ALWAYS | MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT);
|
||||
MenuItemCompat.setShowAsAction(menuItem, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
|
||||
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);
|
||||
MenuItemCompat.setShowAsAction(menuItem, MenuItemCompat.SHOW_AS_ACTION_ALWAYS | MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT);
|
||||
MenuItemCompat.setShowAsAction(menuItem, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
|
||||
menuItem = menuItem.setIcon(light ? R.drawable.ic_action_flag_light
|
||||
: R.drawable.ic_action_flag_dark);
|
||||
}
|
||||
|
@ -148,7 +158,7 @@ public class NavigatePointFragment extends Fragment implements SearchActivityChi
|
|||
});
|
||||
//}
|
||||
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);
|
||||
MenuItemCompat.setShowAsAction(menuItem, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
|
||||
menuItem = menuItem.setIcon(light ? R.drawable.ic_action_marker_light : R.drawable.ic_action_marker_dark);
|
||||
|
||||
menuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
|
||||
|
@ -160,7 +170,7 @@ public class NavigatePointFragment extends Fragment implements SearchActivityChi
|
|||
});
|
||||
|
||||
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);
|
||||
MenuItemCompat.setShowAsAction(menuItem, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
|
||||
menuItem = menuItem.setIcon(light ? R.drawable.ic_action_fav_light : R.drawable.ic_action_fav_dark);
|
||||
|
||||
menuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
package net.osmand.plus.activities.search;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.view.MenuItemCompat;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
|
@ -20,6 +18,7 @@ import net.osmand.plus.TargetPointsHelper;
|
|||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.dialogs.DirectionsDialogs;
|
||||
import net.osmand.plus.dialogs.FavoriteDialogs;
|
||||
import net.osmand.plus.helpers.ScreenOrientationHelper;
|
||||
import net.osmand.plus.resources.RegionAddressRepository;
|
||||
import net.osmand.util.Algorithms;
|
||||
import android.app.Dialog;
|
||||
|
@ -72,7 +71,7 @@ public class SearchAddressFragment extends Fragment {
|
|||
cityButton = (Button) findViewById(R.id.CityButton);
|
||||
countryButton = (Button) findViewById(R.id.CountryButton);
|
||||
buildingButton = (Button) findViewById(R.id.BuildingButton);
|
||||
osmandSettings = ((OsmandApplication) getApplication()).getSettings();
|
||||
osmandSettings = getApplication().getSettings();
|
||||
attachListeners();
|
||||
setHasOptionsMenu(true);
|
||||
return view;
|
||||
|
@ -82,10 +81,18 @@ public class SearchAddressFragment extends Fragment {
|
|||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu onCreate, MenuInflater inflater) {
|
||||
boolean light = ((OsmandApplication) getApplication()).getSettings().isLightActionBar();
|
||||
boolean light = getApplication().getSettings().isLightActionBar();
|
||||
Menu menu = onCreate;
|
||||
int orientation = ScreenOrientationHelper.getScreenOrientation(getActivity());
|
||||
boolean portrait = orientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT ||
|
||||
orientation == ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
|
||||
if(getActivity() instanceof SearchActivity) {
|
||||
menu = ((SearchActivity) getActivity()).getClearToolbar(true).getMenu();
|
||||
if (portrait) {
|
||||
menu = ((SearchActivity) getActivity()).getClearToolbar(true).getMenu();
|
||||
} else {
|
||||
((SearchActivity) getActivity()).getClearToolbar(false);
|
||||
}
|
||||
light = false;
|
||||
}
|
||||
if(getActivity() instanceof SearchAddressActivity) {
|
||||
MenuItem menuItem = menu.add(0, SELECT_POINT, 0, "");
|
||||
|
@ -100,7 +107,7 @@ public class SearchAddressFragment extends Fragment {
|
|||
});
|
||||
} else {
|
||||
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);
|
||||
MenuItemCompat.setShowAsAction(menuItem, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
|
||||
menuItem = menuItem.setIcon(light ? R.drawable.ic_action_gdirections_light : R.drawable.ic_action_gdirections_dark);
|
||||
menuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
|
||||
@Override
|
||||
|
@ -109,14 +116,14 @@ public class SearchAddressFragment extends Fragment {
|
|||
return true;
|
||||
}
|
||||
});
|
||||
TargetPointsHelper targets = ((OsmandApplication) getApplication()).getTargetPointsHelper();
|
||||
TargetPointsHelper targets = getApplication().getTargetPointsHelper();
|
||||
if (targets.getPointToNavigate() != null) {
|
||||
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);
|
||||
MenuItemCompat.setShowAsAction(menuItem, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
|
||||
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);
|
||||
MenuItemCompat.setShowAsAction(menuItem, MenuItemCompat.SHOW_AS_ACTION_ALWAYS | MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT);
|
||||
MenuItemCompat.setShowAsAction(menuItem, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
|
||||
menuItem = menuItem.setIcon(light ? R.drawable.ic_action_flag_light : R.drawable.ic_action_flag_dark);
|
||||
}
|
||||
menuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
|
||||
|
@ -127,7 +134,7 @@ public class SearchAddressFragment extends Fragment {
|
|||
}
|
||||
});
|
||||
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);
|
||||
MenuItemCompat.setShowAsAction(menuItem, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
|
||||
menuItem = menuItem.setIcon(light ? R.drawable.ic_action_marker_light : R.drawable.ic_action_marker_dark);
|
||||
|
||||
menuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
|
||||
|
@ -139,8 +146,8 @@ public class SearchAddressFragment extends Fragment {
|
|||
});
|
||||
|
||||
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);
|
||||
MenuItemCompat.setShowAsAction(menuItem, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
|
||||
menuItem = menuItem.setIcon(R.drawable.ic_action_fav_dark);
|
||||
|
||||
menuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
|
||||
@Override
|
||||
|
@ -150,7 +157,7 @@ public class SearchAddressFragment extends Fragment {
|
|||
}
|
||||
});
|
||||
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);
|
||||
MenuItemCompat.setShowAsAction(menuItem, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
|
||||
menuItem = menuItem.setIcon(light ? R.drawable.ic_action_gnext_light : R.drawable.ic_action_gnext_dark);
|
||||
menuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
|
||||
@Override
|
||||
|
@ -473,7 +480,7 @@ public class SearchAddressFragment extends Fragment {
|
|||
street = null;
|
||||
building = null;
|
||||
region = osmandSettings.getLastSearchedRegion();
|
||||
RegionAddressRepository reg = ((OsmandApplication)getApplication()).getResourceManager().getRegionRepository(region);
|
||||
RegionAddressRepository reg = getApplication().getResourceManager().getRegionRepository(region);
|
||||
if(reg != null && reg.useEnglishNames() != osmandSettings.usingEnglishNames()){
|
||||
reg.setUseEnglishNames(osmandSettings.usingEnglishNames());
|
||||
}
|
||||
|
|
|
@ -0,0 +1,77 @@
|
|||
package net.osmand.plus.helpers;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
import android.view.Surface;
|
||||
import net.osmand.PlatformUtil;
|
||||
|
||||
/**
|
||||
* Created by dummy on 28.01.15.
|
||||
*/
|
||||
public class ScreenOrientationHelper {
|
||||
|
||||
public static int getScreenOrientation(Activity activity) {
|
||||
int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
|
||||
DisplayMetrics dm = new DisplayMetrics();
|
||||
activity.getWindowManager().getDefaultDisplay().getMetrics(dm);
|
||||
int width = dm.widthPixels;
|
||||
int height = dm.heightPixels;
|
||||
int orientation;
|
||||
// if the device's natural orientation is portrait:
|
||||
if ((rotation == Surface.ROTATION_0
|
||||
|| rotation == Surface.ROTATION_180) && height > width ||
|
||||
(rotation == Surface.ROTATION_90
|
||||
|| rotation == Surface.ROTATION_270) && width > height) {
|
||||
switch(rotation) {
|
||||
case Surface.ROTATION_0:
|
||||
orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
|
||||
break;
|
||||
case Surface.ROTATION_90:
|
||||
orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
|
||||
break;
|
||||
case Surface.ROTATION_180:
|
||||
orientation =
|
||||
ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
|
||||
break;
|
||||
case Surface.ROTATION_270:
|
||||
orientation =
|
||||
ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
|
||||
break;
|
||||
default:
|
||||
Log.e(PlatformUtil.TAG, "Unknown screen orientation. Defaulting to " +
|
||||
"portrait.");
|
||||
orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// if the device's natural orientation is landscape or if the device
|
||||
// is square:
|
||||
else {
|
||||
switch(rotation) {
|
||||
case Surface.ROTATION_0:
|
||||
orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
|
||||
break;
|
||||
case Surface.ROTATION_90:
|
||||
orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
|
||||
break;
|
||||
case Surface.ROTATION_180:
|
||||
orientation =
|
||||
ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
|
||||
break;
|
||||
case Surface.ROTATION_270:
|
||||
orientation =
|
||||
ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
|
||||
break;
|
||||
default:
|
||||
Log.e(PlatformUtil.TAG, "Unknown screen orientation. Defaulting to " +
|
||||
"landscape.");
|
||||
orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return orientation;
|
||||
}
|
||||
}
|
|
@ -13,6 +13,7 @@ import net.osmand.plus.OsmandSettings;
|
|||
import net.osmand.plus.OsmandSettings.CommonPreference;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.helpers.ScreenOrientationHelper;
|
||||
import net.osmand.plus.routing.RoutingHelper;
|
||||
import net.osmand.plus.helpers.WaypointDialogHelper;
|
||||
import net.osmand.plus.views.controls.MapRoutePlanControl;
|
||||
|
@ -91,7 +92,7 @@ public class MapControlsLayer extends OsmandMapLayer {
|
|||
// default buttons
|
||||
zoomControls = init(new MapZoomControls(mapActivity, showUIHandler, scaleCoefficient), parent,
|
||||
rightGravity);
|
||||
if (getScreenOrientation() == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT){
|
||||
if (ScreenOrientationHelper.getScreenOrientation(mapActivity) == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT){
|
||||
zoomSideControls = init(new MapZoomControls(mapActivity, showUIHandler, scaleCoefficient), parent,
|
||||
rightCenterGravity);
|
||||
} else {
|
||||
|
@ -335,66 +336,5 @@ public class MapControlsLayer extends OsmandMapLayer {
|
|||
mapInfoNavigationControl.setShowDialog();
|
||||
}
|
||||
|
||||
private int getScreenOrientation() {
|
||||
int rotation = mapActivity.getWindowManager().getDefaultDisplay().getRotation();
|
||||
DisplayMetrics dm = new DisplayMetrics();
|
||||
mapActivity.getWindowManager().getDefaultDisplay().getMetrics(dm);
|
||||
int width = dm.widthPixels;
|
||||
int height = dm.heightPixels;
|
||||
int orientation;
|
||||
// if the device's natural orientation is portrait:
|
||||
if ((rotation == Surface.ROTATION_0
|
||||
|| rotation == Surface.ROTATION_180) && height > width ||
|
||||
(rotation == Surface.ROTATION_90
|
||||
|| rotation == Surface.ROTATION_270) && width > height) {
|
||||
switch(rotation) {
|
||||
case Surface.ROTATION_0:
|
||||
orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
|
||||
break;
|
||||
case Surface.ROTATION_90:
|
||||
orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
|
||||
break;
|
||||
case Surface.ROTATION_180:
|
||||
orientation =
|
||||
ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
|
||||
break;
|
||||
case Surface.ROTATION_270:
|
||||
orientation =
|
||||
ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
|
||||
break;
|
||||
default:
|
||||
Log.e(PlatformUtil.TAG, "Unknown screen orientation. Defaulting to " +
|
||||
"portrait.");
|
||||
orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// if the device's natural orientation is landscape or if the device
|
||||
// is square:
|
||||
else {
|
||||
switch(rotation) {
|
||||
case Surface.ROTATION_0:
|
||||
orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
|
||||
break;
|
||||
case Surface.ROTATION_90:
|
||||
orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
|
||||
break;
|
||||
case Surface.ROTATION_180:
|
||||
orientation =
|
||||
ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
|
||||
break;
|
||||
case Surface.ROTATION_270:
|
||||
orientation =
|
||||
ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
|
||||
break;
|
||||
default:
|
||||
Log.e(PlatformUtil.TAG, "Unknown screen orientation. Defaulting to " +
|
||||
"landscape.");
|
||||
orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return orientation;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue