Fix MapContextMenuFragment crash
This commit is contained in:
parent
fb0712853b
commit
8a5d207a10
1 changed files with 231 additions and 218 deletions
|
@ -582,6 +582,7 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
|
|||
}
|
||||
|
||||
private void updateButtonsAndProgress() {
|
||||
if (view != null) {
|
||||
// Title buttons
|
||||
boolean showTitleButtonsContainer = (leftTitleButtonController != null || rightTitleButtonController != null);
|
||||
final View titleButtonsContainer = view.findViewById(R.id.title_button_container);
|
||||
|
@ -706,10 +707,11 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
|
|||
titleProgressContainer.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void buildHeader() {
|
||||
OsmandApplication app = getMyApplication();
|
||||
if (app != null) {
|
||||
if (app != null && view != null) {
|
||||
IconsCache iconsCache = app.getIconsCache();
|
||||
|
||||
final View iconLayout = view.findViewById(R.id.context_menu_icon_layout);
|
||||
|
@ -731,6 +733,7 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
|
|||
}
|
||||
|
||||
private void buildBottomView() {
|
||||
if (view != null) {
|
||||
View bottomView = view.findViewById(R.id.context_menu_bottom_view);
|
||||
if (menu.isExtended()) {
|
||||
bottomView.setOnTouchListener(new View.OnTouchListener() {
|
||||
|
@ -742,6 +745,7 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
|
|||
menu.build(bottomView);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
|
@ -789,7 +793,7 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
|
|||
|
||||
public void rebuildMenu() {
|
||||
OsmandApplication app = getMyApplication();
|
||||
if (app != null) {
|
||||
if (app != null && view != null) {
|
||||
IconsCache iconsCache = app.getIconsCache();
|
||||
final ImageButton buttonFavorite = (ImageButton) view.findViewById(R.id.context_menu_fav_button);
|
||||
buttonFavorite.setImageDrawable(iconsCache.getIcon(menu.getFavActionIconId(),
|
||||
|
@ -808,12 +812,14 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
|
|||
|
||||
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
|
||||
private void runLayoutListener() {
|
||||
if (view != null) {
|
||||
ViewTreeObserver vto = view.getViewTreeObserver();
|
||||
vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||
|
||||
@Override
|
||||
public void onGlobalLayout() {
|
||||
|
||||
if (view != null) {
|
||||
ViewTreeObserver obs = view.getViewTreeObserver();
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||
obs.removeOnGlobalLayoutListener(this);
|
||||
|
@ -875,9 +881,11 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
|
|||
}
|
||||
initLayout = false;
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void centerMarkerLocation() {
|
||||
centered = true;
|
||||
|
@ -934,6 +942,7 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
|
|||
}
|
||||
|
||||
private void setAddressLocation() {
|
||||
if (view != null) {
|
||||
// Text line 1
|
||||
TextView line1 = (TextView) view.findViewById(R.id.context_menu_line1);
|
||||
line1.setText(menu.getTitleStr());
|
||||
|
@ -962,13 +971,13 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
|
|||
}
|
||||
line2.setText(line2Str.toString());
|
||||
}
|
||||
|
||||
}
|
||||
updateCompassVisibility();
|
||||
}
|
||||
|
||||
private void updateCompassVisibility() {
|
||||
OsmandApplication app = getMyApplication();
|
||||
if (app != null) {
|
||||
if (app != null && view != null) {
|
||||
View compassView = view.findViewById(R.id.compass_layout);
|
||||
Location ll = app.getLocationProvider().getLastKnownLocation();
|
||||
boolean gpsFixed = ll != null && System.currentTimeMillis() - ll.getTime() < 1000 * 60 * 60 * 20;
|
||||
|
@ -988,7 +997,7 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
|
|||
private void updateDistanceDirection() {
|
||||
OsmandApplication app = getMyApplication();
|
||||
FragmentActivity activity = getActivity();
|
||||
if (app != null && activity != null) {
|
||||
if (app != null && activity != null && view != null) {
|
||||
TextView distanceText = (TextView) view.findViewById(R.id.distance);
|
||||
ImageView direction = (ImageView) view.findViewById(R.id.direction);
|
||||
float myHeading = menu.getHeading() == null ? 0f : menu.getHeading();
|
||||
|
@ -1035,6 +1044,7 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
|
|||
}
|
||||
|
||||
private void updateMainViewLayout(int posY) {
|
||||
if (view != null) {
|
||||
menuFullHeight = view.getHeight() - posY;
|
||||
if (!oldAndroid()) {
|
||||
ViewGroup.LayoutParams lp = mainView.getLayoutParams();
|
||||
|
@ -1043,6 +1053,7 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
|
|||
mainView.requestLayout();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int getViewY() {
|
||||
if (!oldAndroid()) {
|
||||
|
@ -1176,6 +1187,7 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
|
|||
}
|
||||
|
||||
public void setFragmentVisibility(boolean visible) {
|
||||
if (view != null) {
|
||||
if (visible) {
|
||||
view.setVisibility(View.VISIBLE);
|
||||
if (mapCenter != null) {
|
||||
|
@ -1186,6 +1198,7 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
|
|||
view.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public OsmandApplication getMyApplication() {
|
||||
if (getActivity() == null) {
|
||||
|
|
Loading…
Reference in a new issue