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,7 +708,9 @@ 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);
@ -726,6 +728,7 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
} }
setAddressLocation(); setAddressLocation();
} }
}
private void buildBottomView() { private void buildBottomView() {
View bottomView = view.findViewById(R.id.context_menu_bottom_view); View bottomView = view.findViewById(R.id.context_menu_bottom_view);
@ -785,7 +788,9 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
} }
public void rebuildMenu() { public void rebuildMenu() {
IconsCache iconsCache = getMyApplication().getIconsCache(); OsmandApplication app = getMyApplication();
if (app != null) {
IconsCache iconsCache = app.getIconsCache();
final ImageButton buttonFavorite = (ImageButton) view.findViewById(R.id.context_menu_fav_button); final ImageButton buttonFavorite = (ImageButton) view.findViewById(R.id.context_menu_fav_button);
buttonFavorite.setImageDrawable(iconsCache.getIcon(menu.getFavActionIconId(), buttonFavorite.setImageDrawable(iconsCache.getIcon(menu.getFavActionIconId(),
!nightMode ? R.color.icon_color : R.color.dashboard_subheader_text_dark)); !nightMode ? R.color.icon_color : R.color.dashboard_subheader_text_dark));
@ -799,6 +804,7 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
runLayoutListener(); runLayoutListener();
} }
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void runLayoutListener() { private void runLayoutListener() {
@ -961,8 +967,10 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
} }
private void updateCompassVisibility() { private void updateCompassVisibility() {
OsmandApplication app = getMyApplication();
if (app != null) {
View compassView = view.findViewById(R.id.compass_layout); View compassView = view.findViewById(R.id.compass_layout);
Location ll = getMyApplication().getLocationProvider().getLastKnownLocation(); Location ll = app.getLocationProvider().getLastKnownLocation();
boolean gpsFixed = ll != null && System.currentTimeMillis() - ll.getTime() < 1000 * 60 * 60 * 20; boolean gpsFixed = ll != null && System.currentTimeMillis() - ll.getTime() < 1000 * 60 * 60 * 20;
if (gpsFixed && menu.displayDistanceDirection() && menu.getCurrentMenuState() != MenuState.FULL_SCREEN) { if (gpsFixed && menu.displayDistanceDirection() && menu.getCurrentMenuState() != MenuState.FULL_SCREEN) {
updateDistanceDirection(); updateDistanceDirection();
@ -975,14 +983,18 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
} }
} }
} }
}
private void updateDistanceDirection() { private void updateDistanceDirection() {
OsmandApplication app = getMyApplication();
FragmentActivity activity = getActivity();
if (app != null && activity != null) {
TextView distanceText = (TextView) view.findViewById(R.id.distance); TextView distanceText = (TextView) view.findViewById(R.id.distance);
ImageView direction = (ImageView) view.findViewById(R.id.direction); ImageView direction = (ImageView) view.findViewById(R.id.direction);
float myHeading = menu.getHeading() == null ? 0f : menu.getHeading(); float myHeading = menu.getHeading() == null ? 0f : menu.getHeading();
DashLocationFragment.updateLocationView(false, menu.getMyLocation(), myHeading, direction, distanceText, DashLocationFragment.updateLocationView(false, menu.getMyLocation(), myHeading, direction, distanceText,
menu.getLatLon().getLatitude(), menu.getLatLon().getLongitude(), screenOrientation, getMyApplication(), getActivity()); menu.getLatLon().getLatitude(), menu.getLatLon().getLongitude(), screenOrientation, app, activity);
}
} }
private int getPosY() { private int getPosY() {