Fix context menu crash

This commit is contained in:
Alexey Kulish 2017-04-25 11:16:14 +03:00
parent 8043cfdad9
commit c5dea0bc13

View file

@ -708,23 +708,26 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
} }
private void buildHeader() { private void buildHeader() {
IconsCache iconsCache = getMyApplication().getIconsCache(); OsmandApplication app = getMyApplication();
if (app != null) {
IconsCache iconsCache = app.getIconsCache();
final View iconLayout = view.findViewById(R.id.context_menu_icon_layout); final View iconLayout = view.findViewById(R.id.context_menu_icon_layout);
final ImageView iconView = (ImageView) view.findViewById(R.id.context_menu_icon_view); final ImageView iconView = (ImageView) view.findViewById(R.id.context_menu_icon_view);
Drawable icon = menu.getLeftIcon(); Drawable icon = menu.getLeftIcon();
int iconId = menu.getLeftIconId(); int iconId = menu.getLeftIconId();
if (icon != null) { if (icon != null) {
iconView.setImageDrawable(icon); iconView.setImageDrawable(icon);
iconLayout.setVisibility(View.VISIBLE); iconLayout.setVisibility(View.VISIBLE);
} else if (iconId != 0) { } else if (iconId != 0) {
iconView.setImageDrawable(iconsCache.getIcon(iconId, iconView.setImageDrawable(iconsCache.getIcon(iconId,
!nightMode ? R.color.osmand_orange : R.color.osmand_orange_dark)); !nightMode ? R.color.osmand_orange : R.color.osmand_orange_dark));
iconLayout.setVisibility(View.VISIBLE); iconLayout.setVisibility(View.VISIBLE);
} else { } else {
iconLayout.setVisibility(View.GONE); iconLayout.setVisibility(View.GONE);
}
setAddressLocation();
} }
setAddressLocation();
} }
private void buildBottomView() { private void buildBottomView() {
@ -785,19 +788,22 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
} }
public void rebuildMenu() { public void rebuildMenu() {
IconsCache iconsCache = getMyApplication().getIconsCache(); OsmandApplication app = getMyApplication();
final ImageButton buttonFavorite = (ImageButton) view.findViewById(R.id.context_menu_fav_button); if (app != null) {
buttonFavorite.setImageDrawable(iconsCache.getIcon(menu.getFavActionIconId(), IconsCache iconsCache = app.getIconsCache();
!nightMode ? R.color.icon_color : R.color.dashboard_subheader_text_dark)); final ImageButton buttonFavorite = (ImageButton) view.findViewById(R.id.context_menu_fav_button);
buttonFavorite.setContentDescription(getString(menu.getFavActionStringId())); buttonFavorite.setImageDrawable(iconsCache.getIcon(menu.getFavActionIconId(),
!nightMode ? R.color.icon_color : R.color.dashboard_subheader_text_dark));
buttonFavorite.setContentDescription(getString(menu.getFavActionStringId()));
buildHeader(); buildHeader();
LinearLayout bottomLayout = (LinearLayout) view.findViewById(R.id.context_menu_bottom_view); LinearLayout bottomLayout = (LinearLayout) view.findViewById(R.id.context_menu_bottom_view);
bottomLayout.removeAllViews(); bottomLayout.removeAllViews();
buildBottomView(); buildBottomView();
runLayoutListener(); runLayoutListener();
}
} }
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@ -961,28 +967,34 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
} }
private void updateCompassVisibility() { private void updateCompassVisibility() {
View compassView = view.findViewById(R.id.compass_layout); OsmandApplication app = getMyApplication();
Location ll = getMyApplication().getLocationProvider().getLastKnownLocation(); if (app != null) {
boolean gpsFixed = ll != null && System.currentTimeMillis() - ll.getTime() < 1000 * 60 * 60 * 20; View compassView = view.findViewById(R.id.compass_layout);
if (gpsFixed && menu.displayDistanceDirection() && menu.getCurrentMenuState() != MenuState.FULL_SCREEN) { Location ll = app.getLocationProvider().getLastKnownLocation();
updateDistanceDirection(); boolean gpsFixed = ll != null && System.currentTimeMillis() - ll.getTime() < 1000 * 60 * 60 * 20;
compassView.setVisibility(View.VISIBLE); if (gpsFixed && menu.displayDistanceDirection() && menu.getCurrentMenuState() != MenuState.FULL_SCREEN) {
} else { updateDistanceDirection();
if (!menu.displayDistanceDirection()) { compassView.setVisibility(View.VISIBLE);
compassView.setVisibility(View.GONE);
} else { } else {
compassView.setVisibility(View.INVISIBLE); if (!menu.displayDistanceDirection()) {
compassView.setVisibility(View.GONE);
} else {
compassView.setVisibility(View.INVISIBLE);
}
} }
} }
} }
private void updateDistanceDirection() { private void updateDistanceDirection() {
TextView distanceText = (TextView) view.findViewById(R.id.distance); OsmandApplication app = getMyApplication();
ImageView direction = (ImageView) view.findViewById(R.id.direction); FragmentActivity activity = getActivity();
if (app != null && activity != null) {
float myHeading = menu.getHeading() == null ? 0f : menu.getHeading(); TextView distanceText = (TextView) view.findViewById(R.id.distance);
DashLocationFragment.updateLocationView(false, menu.getMyLocation(), myHeading, direction, distanceText, ImageView direction = (ImageView) view.findViewById(R.id.direction);
menu.getLatLon().getLatitude(), menu.getLatLon().getLongitude(), screenOrientation, getMyApplication(), getActivity()); float myHeading = menu.getHeading() == null ? 0f : menu.getHeading();
DashLocationFragment.updateLocationView(false, menu.getMyLocation(), myHeading, direction, distanceText,
menu.getLatLon().getLatitude(), menu.getLatLon().getLongitude(), screenOrientation, app, activity);
}
} }
private int getPosY() { private int getPosY() {