Fix MapContextMenuFragment crash
This commit is contained in:
parent
fb0712853b
commit
8a5d207a10
1 changed files with 231 additions and 218 deletions
|
@ -582,134 +582,136 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateButtonsAndProgress() {
|
private void updateButtonsAndProgress() {
|
||||||
// Title buttons
|
if (view != null) {
|
||||||
boolean showTitleButtonsContainer = (leftTitleButtonController != null || rightTitleButtonController != null);
|
// Title buttons
|
||||||
final View titleButtonsContainer = view.findViewById(R.id.title_button_container);
|
boolean showTitleButtonsContainer = (leftTitleButtonController != null || rightTitleButtonController != null);
|
||||||
titleButtonsContainer.setVisibility(showTitleButtonsContainer ? View.VISIBLE : View.GONE);
|
final View titleButtonsContainer = view.findViewById(R.id.title_button_container);
|
||||||
|
titleButtonsContainer.setVisibility(showTitleButtonsContainer ? View.VISIBLE : View.GONE);
|
||||||
|
|
||||||
// Left title button
|
// Left title button
|
||||||
final Button leftTitleButton = (Button) view.findViewById(R.id.title_button);
|
final Button leftTitleButton = (Button) view.findViewById(R.id.title_button);
|
||||||
final TextView titleButtonRightText = (TextView) view.findViewById(R.id.title_button_right_text);
|
final TextView titleButtonRightText = (TextView) view.findViewById(R.id.title_button_right_text);
|
||||||
if (leftTitleButtonController != null) {
|
if (leftTitleButtonController != null) {
|
||||||
leftTitleButton.setText(leftTitleButtonController.caption);
|
leftTitleButton.setText(leftTitleButtonController.caption);
|
||||||
leftTitleButton.setVisibility(leftTitleButtonController.visible ? View.VISIBLE : View.GONE);
|
leftTitleButton.setVisibility(leftTitleButtonController.visible ? View.VISIBLE : View.GONE);
|
||||||
|
|
||||||
Drawable leftIcon = leftTitleButtonController.getLeftIcon();
|
Drawable leftIcon = leftTitleButtonController.getLeftIcon();
|
||||||
if (leftIcon != null) {
|
if (leftIcon != null) {
|
||||||
leftTitleButton.setCompoundDrawablesWithIntrinsicBounds(leftIcon, null, null, null);
|
leftTitleButton.setCompoundDrawablesWithIntrinsicBounds(leftIcon, null, null, null);
|
||||||
leftTitleButton.setCompoundDrawablePadding(dpToPx(4f));
|
leftTitleButton.setCompoundDrawablePadding(dpToPx(4f));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (leftTitleButtonController.needRightText) {
|
if (leftTitleButtonController.needRightText) {
|
||||||
titleButtonRightText.setText(leftTitleButtonController.rightTextCaption);
|
titleButtonRightText.setText(leftTitleButtonController.rightTextCaption);
|
||||||
titleButtonRightText.setVisibility(View.VISIBLE);
|
titleButtonRightText.setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
titleButtonRightText.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
|
leftTitleButton.setVisibility(View.GONE);
|
||||||
titleButtonRightText.setVisibility(View.GONE);
|
titleButtonRightText.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
leftTitleButton.setVisibility(View.GONE);
|
|
||||||
titleButtonRightText.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Right title button
|
// Right title button
|
||||||
final Button rightTitleButton = (Button) view.findViewById(R.id.title_button_right);
|
final Button rightTitleButton = (Button) view.findViewById(R.id.title_button_right);
|
||||||
if (rightTitleButtonController != null) {
|
if (rightTitleButtonController != null) {
|
||||||
rightTitleButton.setText(rightTitleButtonController.caption);
|
rightTitleButton.setText(rightTitleButtonController.caption);
|
||||||
rightTitleButton.setVisibility(rightTitleButtonController.visible ? View.VISIBLE : View.GONE);
|
rightTitleButton.setVisibility(rightTitleButtonController.visible ? View.VISIBLE : View.GONE);
|
||||||
|
|
||||||
Drawable leftIcon = rightTitleButtonController.getLeftIcon();
|
Drawable leftIcon = rightTitleButtonController.getLeftIcon();
|
||||||
rightTitleButton.setCompoundDrawablesWithIntrinsicBounds(leftIcon, null, null, null);
|
rightTitleButton.setCompoundDrawablesWithIntrinsicBounds(leftIcon, null, null, null);
|
||||||
rightTitleButton.setCompoundDrawablePadding(dpToPx(4f));
|
rightTitleButton.setCompoundDrawablePadding(dpToPx(4f));
|
||||||
} else {
|
} else {
|
||||||
rightTitleButton.setVisibility(View.GONE);
|
rightTitleButton.setVisibility(View.GONE);
|
||||||
}
|
|
||||||
|
|
||||||
// Top Right title button
|
|
||||||
final Button topRightTitleButton = (Button) view.findViewById(R.id.title_button_top_right);
|
|
||||||
if (topRightTitleButtonController != null) {
|
|
||||||
topRightTitleButton.setText(topRightTitleButtonController.caption);
|
|
||||||
topRightTitleButton.setVisibility(topRightTitleButtonController.visible ? View.VISIBLE : View.INVISIBLE);
|
|
||||||
|
|
||||||
Drawable leftIcon = topRightTitleButtonController.getLeftIcon();
|
|
||||||
topRightTitleButton.setCompoundDrawablesWithIntrinsicBounds(leftIcon, null, null, null);
|
|
||||||
topRightTitleButton.setCompoundDrawablePadding(dpToPx(4f));
|
|
||||||
} else {
|
|
||||||
topRightTitleButton.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Download buttons
|
|
||||||
boolean showDownloadButtonsContainer =
|
|
||||||
((leftDownloadButtonController != null && leftDownloadButtonController.visible)
|
|
||||||
|| (rightDownloadButtonController != null && rightDownloadButtonController.visible))
|
|
||||||
&& (titleProgressController == null || !titleProgressController.visible);
|
|
||||||
final View downloadButtonsContainer = view.findViewById(R.id.download_buttons_container);
|
|
||||||
downloadButtonsContainer.setVisibility(showDownloadButtonsContainer ? View.VISIBLE : View.GONE);
|
|
||||||
|
|
||||||
if (showDownloadButtonsContainer) {
|
|
||||||
view.findViewById(R.id.download_buttons_top_border).setVisibility(showTitleButtonsContainer ? View.VISIBLE : View.INVISIBLE);
|
|
||||||
if (showTitleButtonsContainer) {
|
|
||||||
LinearLayout.LayoutParams ll = (LinearLayout.LayoutParams) downloadButtonsContainer.getLayoutParams();
|
|
||||||
if (ll.topMargin != 0) {
|
|
||||||
ll.setMargins(0, 0, 0, 0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Left download button
|
// Top Right title button
|
||||||
final Button leftDownloadButton = (Button) view.findViewById(R.id.download_button_left);
|
final Button topRightTitleButton = (Button) view.findViewById(R.id.title_button_top_right);
|
||||||
if (leftDownloadButtonController != null) {
|
if (topRightTitleButtonController != null) {
|
||||||
leftDownloadButton.setText(leftDownloadButtonController.caption);
|
topRightTitleButton.setText(topRightTitleButtonController.caption);
|
||||||
leftDownloadButton.setVisibility(leftDownloadButtonController.visible ? View.VISIBLE : View.GONE);
|
topRightTitleButton.setVisibility(topRightTitleButtonController.visible ? View.VISIBLE : View.INVISIBLE);
|
||||||
|
|
||||||
Drawable leftIcon = leftDownloadButtonController.getLeftIcon();
|
Drawable leftIcon = topRightTitleButtonController.getLeftIcon();
|
||||||
if (leftIcon != null) {
|
topRightTitleButton.setCompoundDrawablesWithIntrinsicBounds(leftIcon, null, null, null);
|
||||||
leftDownloadButton.setCompoundDrawablesWithIntrinsicBounds(leftIcon, null, null, null);
|
topRightTitleButton.setCompoundDrawablePadding(dpToPx(4f));
|
||||||
leftDownloadButton.setCompoundDrawablePadding(dpToPx(4f));
|
} else {
|
||||||
|
topRightTitleButton.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
leftDownloadButton.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Right download button
|
// Download buttons
|
||||||
final Button rightDownloadButton = (Button) view.findViewById(R.id.download_button_right);
|
boolean showDownloadButtonsContainer =
|
||||||
if (rightDownloadButtonController != null) {
|
((leftDownloadButtonController != null && leftDownloadButtonController.visible)
|
||||||
rightDownloadButton.setText(rightDownloadButtonController.caption);
|
|| (rightDownloadButtonController != null && rightDownloadButtonController.visible))
|
||||||
rightDownloadButton.setVisibility(rightDownloadButtonController.visible ? View.VISIBLE : View.GONE);
|
&& (titleProgressController == null || !titleProgressController.visible);
|
||||||
|
final View downloadButtonsContainer = view.findViewById(R.id.download_buttons_container);
|
||||||
|
downloadButtonsContainer.setVisibility(showDownloadButtonsContainer ? View.VISIBLE : View.GONE);
|
||||||
|
|
||||||
Drawable leftIcon = rightDownloadButtonController.getLeftIcon();
|
if (showDownloadButtonsContainer) {
|
||||||
rightDownloadButton.setCompoundDrawablesWithIntrinsicBounds(leftIcon, null, null, null);
|
view.findViewById(R.id.download_buttons_top_border).setVisibility(showTitleButtonsContainer ? View.VISIBLE : View.INVISIBLE);
|
||||||
rightDownloadButton.setCompoundDrawablePadding(dpToPx(4f));
|
if (showTitleButtonsContainer) {
|
||||||
} else {
|
LinearLayout.LayoutParams ll = (LinearLayout.LayoutParams) downloadButtonsContainer.getLayoutParams();
|
||||||
rightDownloadButton.setVisibility(View.GONE);
|
if (ll.topMargin != 0) {
|
||||||
}
|
ll.setMargins(0, 0, 0, 0);
|
||||||
|
}
|
||||||
// Progress bar
|
|
||||||
final View titleProgressContainer = view.findViewById(R.id.title_progress_container);
|
|
||||||
if (titleProgressController != null) {
|
|
||||||
titleProgressContainer.setVisibility(titleProgressController.visible ? View.VISIBLE : View.GONE);
|
|
||||||
if (titleProgressController.visible && showTitleButtonsContainer) {
|
|
||||||
LinearLayout.LayoutParams ll = (LinearLayout.LayoutParams) titleProgressContainer.getLayoutParams();
|
|
||||||
if (ll.topMargin != 0) {
|
|
||||||
ll.setMargins(0, 0, 0, 0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final ProgressBar progressBar = (ProgressBar) view.findViewById(R.id.progressBar);
|
// Left download button
|
||||||
final TextView progressTitle = (TextView) view.findViewById(R.id.progressTitle);
|
final Button leftDownloadButton = (Button) view.findViewById(R.id.download_button_left);
|
||||||
progressTitle.setText(titleProgressController.caption);
|
if (leftDownloadButtonController != null) {
|
||||||
progressBar.setIndeterminate(titleProgressController.indeterminate);
|
leftDownloadButton.setText(leftDownloadButtonController.caption);
|
||||||
progressBar.setProgress(titleProgressController.progress);
|
leftDownloadButton.setVisibility(leftDownloadButtonController.visible ? View.VISIBLE : View.GONE);
|
||||||
|
|
||||||
final ImageView progressButton = (ImageView) view.findViewById(R.id.progressButton);
|
Drawable leftIcon = leftDownloadButtonController.getLeftIcon();
|
||||||
progressButton.setVisibility(titleProgressController.buttonVisible ? View.VISIBLE : View.GONE);
|
if (leftIcon != null) {
|
||||||
} else {
|
leftDownloadButton.setCompoundDrawablesWithIntrinsicBounds(leftIcon, null, null, null);
|
||||||
titleProgressContainer.setVisibility(View.GONE);
|
leftDownloadButton.setCompoundDrawablePadding(dpToPx(4f));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
leftDownloadButton.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Right download button
|
||||||
|
final Button rightDownloadButton = (Button) view.findViewById(R.id.download_button_right);
|
||||||
|
if (rightDownloadButtonController != null) {
|
||||||
|
rightDownloadButton.setText(rightDownloadButtonController.caption);
|
||||||
|
rightDownloadButton.setVisibility(rightDownloadButtonController.visible ? View.VISIBLE : View.GONE);
|
||||||
|
|
||||||
|
Drawable leftIcon = rightDownloadButtonController.getLeftIcon();
|
||||||
|
rightDownloadButton.setCompoundDrawablesWithIntrinsicBounds(leftIcon, null, null, null);
|
||||||
|
rightDownloadButton.setCompoundDrawablePadding(dpToPx(4f));
|
||||||
|
} else {
|
||||||
|
rightDownloadButton.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Progress bar
|
||||||
|
final View titleProgressContainer = view.findViewById(R.id.title_progress_container);
|
||||||
|
if (titleProgressController != null) {
|
||||||
|
titleProgressContainer.setVisibility(titleProgressController.visible ? View.VISIBLE : View.GONE);
|
||||||
|
if (titleProgressController.visible && showTitleButtonsContainer) {
|
||||||
|
LinearLayout.LayoutParams ll = (LinearLayout.LayoutParams) titleProgressContainer.getLayoutParams();
|
||||||
|
if (ll.topMargin != 0) {
|
||||||
|
ll.setMargins(0, 0, 0, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final ProgressBar progressBar = (ProgressBar) view.findViewById(R.id.progressBar);
|
||||||
|
final TextView progressTitle = (TextView) view.findViewById(R.id.progressTitle);
|
||||||
|
progressTitle.setText(titleProgressController.caption);
|
||||||
|
progressBar.setIndeterminate(titleProgressController.indeterminate);
|
||||||
|
progressBar.setProgress(titleProgressController.progress);
|
||||||
|
|
||||||
|
final ImageView progressButton = (ImageView) view.findViewById(R.id.progressButton);
|
||||||
|
progressButton.setVisibility(titleProgressController.buttonVisible ? View.VISIBLE : View.GONE);
|
||||||
|
} else {
|
||||||
|
titleProgressContainer.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buildHeader() {
|
private void buildHeader() {
|
||||||
OsmandApplication app = getMyApplication();
|
OsmandApplication app = getMyApplication();
|
||||||
if (app != null) {
|
if (app != null && view != null) {
|
||||||
IconsCache iconsCache = app.getIconsCache();
|
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);
|
||||||
|
@ -731,15 +733,17 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buildBottomView() {
|
private void buildBottomView() {
|
||||||
View bottomView = view.findViewById(R.id.context_menu_bottom_view);
|
if (view != null) {
|
||||||
if (menu.isExtended()) {
|
View bottomView = view.findViewById(R.id.context_menu_bottom_view);
|
||||||
bottomView.setOnTouchListener(new View.OnTouchListener() {
|
if (menu.isExtended()) {
|
||||||
@Override
|
bottomView.setOnTouchListener(new View.OnTouchListener() {
|
||||||
public boolean onTouch(View v, MotionEvent event) {
|
@Override
|
||||||
return true;
|
public boolean onTouch(View v, MotionEvent event) {
|
||||||
}
|
return true;
|
||||||
});
|
}
|
||||||
menu.build(bottomView);
|
});
|
||||||
|
menu.build(bottomView);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -789,7 +793,7 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
|
||||||
|
|
||||||
public void rebuildMenu() {
|
public void rebuildMenu() {
|
||||||
OsmandApplication app = getMyApplication();
|
OsmandApplication app = getMyApplication();
|
||||||
if (app != null) {
|
if (app != null && view != null) {
|
||||||
IconsCache iconsCache = app.getIconsCache();
|
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(),
|
||||||
|
@ -808,75 +812,79 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
|
||||||
|
|
||||||
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
|
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
|
||||||
private void runLayoutListener() {
|
private void runLayoutListener() {
|
||||||
ViewTreeObserver vto = view.getViewTreeObserver();
|
if (view != null) {
|
||||||
vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
ViewTreeObserver vto = view.getViewTreeObserver();
|
||||||
|
vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onGlobalLayout() {
|
public void onGlobalLayout() {
|
||||||
|
|
||||||
ViewTreeObserver obs = view.getViewTreeObserver();
|
if (view != null) {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
ViewTreeObserver obs = view.getViewTreeObserver();
|
||||||
obs.removeOnGlobalLayoutListener(this);
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||||
} else {
|
obs.removeOnGlobalLayoutListener(this);
|
||||||
obs.removeGlobalOnLayoutListener(this);
|
} else {
|
||||||
}
|
obs.removeGlobalOnLayoutListener(this);
|
||||||
|
|
||||||
if (getActivity() == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int newMenuTopViewHeight = view.findViewById(R.id.context_menu_top_view).getHeight();
|
|
||||||
menuTopShadowHeight = view.findViewById(R.id.context_menu_top_shadow).getHeight();
|
|
||||||
int newMenuTopShadowAllHeight = view.findViewById(R.id.context_menu_top_shadow_all).getHeight();
|
|
||||||
menuFullHeight = view.findViewById(R.id.context_menu_main).getHeight();
|
|
||||||
|
|
||||||
int dy = 0;
|
|
||||||
if (!menu.isLandscapeLayout()) {
|
|
||||||
TextView line1 = (TextView) view.findViewById(R.id.context_menu_line1);
|
|
||||||
TextView line2 = (TextView) view.findViewById(R.id.context_menu_line2);
|
|
||||||
int line2LineCount = 0;
|
|
||||||
int line2LineHeight = 0;
|
|
||||||
int line2MeasuredHeight = 0;
|
|
||||||
if (line2 != null) {
|
|
||||||
line2LineCount = line2.getLineCount();
|
|
||||||
line2LineHeight = line2.getLineHeight();
|
|
||||||
line2MeasuredHeight = line2.getMeasuredHeight();
|
|
||||||
}
|
|
||||||
if (menuTopViewHeight != 0) {
|
|
||||||
int titleHeight = line1.getLineCount() * line1.getLineHeight() + line2LineCount * line2LineHeight + menuTitleTopBottomPadding;
|
|
||||||
if (titleHeight < line1.getMeasuredHeight() + line2MeasuredHeight) {
|
|
||||||
titleHeight = line1.getMeasuredHeight() + line2MeasuredHeight;
|
|
||||||
}
|
}
|
||||||
newMenuTopViewHeight = menuTopViewHeightExcludingTitle + titleHeight;
|
|
||||||
dy = Math.max(0, newMenuTopViewHeight - menuTopViewHeight - (newMenuTopShadowAllHeight - menuTopShadowAllHeight));
|
if (getActivity() == null) {
|
||||||
} else {
|
return;
|
||||||
menuTopViewHeightExcludingTitle = newMenuTopViewHeight - line1.getMeasuredHeight() - line2MeasuredHeight;
|
}
|
||||||
menuTitleTopBottomPadding = (line1.getMeasuredHeight() - line1.getLineCount() * line1.getLineHeight())
|
|
||||||
+ (line2MeasuredHeight - line2LineCount * line2LineHeight);
|
int newMenuTopViewHeight = view.findViewById(R.id.context_menu_top_view).getHeight();
|
||||||
|
menuTopShadowHeight = view.findViewById(R.id.context_menu_top_shadow).getHeight();
|
||||||
|
int newMenuTopShadowAllHeight = view.findViewById(R.id.context_menu_top_shadow_all).getHeight();
|
||||||
|
menuFullHeight = view.findViewById(R.id.context_menu_main).getHeight();
|
||||||
|
|
||||||
|
int dy = 0;
|
||||||
|
if (!menu.isLandscapeLayout()) {
|
||||||
|
TextView line1 = (TextView) view.findViewById(R.id.context_menu_line1);
|
||||||
|
TextView line2 = (TextView) view.findViewById(R.id.context_menu_line2);
|
||||||
|
int line2LineCount = 0;
|
||||||
|
int line2LineHeight = 0;
|
||||||
|
int line2MeasuredHeight = 0;
|
||||||
|
if (line2 != null) {
|
||||||
|
line2LineCount = line2.getLineCount();
|
||||||
|
line2LineHeight = line2.getLineHeight();
|
||||||
|
line2MeasuredHeight = line2.getMeasuredHeight();
|
||||||
|
}
|
||||||
|
if (menuTopViewHeight != 0) {
|
||||||
|
int titleHeight = line1.getLineCount() * line1.getLineHeight() + line2LineCount * line2LineHeight + menuTitleTopBottomPadding;
|
||||||
|
if (titleHeight < line1.getMeasuredHeight() + line2MeasuredHeight) {
|
||||||
|
titleHeight = line1.getMeasuredHeight() + line2MeasuredHeight;
|
||||||
|
}
|
||||||
|
newMenuTopViewHeight = menuTopViewHeightExcludingTitle + titleHeight;
|
||||||
|
dy = Math.max(0, newMenuTopViewHeight - menuTopViewHeight - (newMenuTopShadowAllHeight - menuTopShadowAllHeight));
|
||||||
|
} else {
|
||||||
|
menuTopViewHeightExcludingTitle = newMenuTopViewHeight - line1.getMeasuredHeight() - line2MeasuredHeight;
|
||||||
|
menuTitleTopBottomPadding = (line1.getMeasuredHeight() - line1.getLineCount() * line1.getLineHeight())
|
||||||
|
+ (line2MeasuredHeight - line2LineCount * line2LineHeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
menuTopViewHeight = newMenuTopViewHeight;
|
||||||
|
menuTopShadowAllHeight = newMenuTopShadowAllHeight;
|
||||||
|
menuTitleHeight = menuTopShadowHeight + menuTopShadowAllHeight + dy;
|
||||||
|
menuBottomViewHeight = view.findViewById(R.id.context_menu_bottom_view).getHeight();
|
||||||
|
|
||||||
|
menuFullHeightMax = menuTitleHeight + menuBottomViewHeight;
|
||||||
|
|
||||||
|
if (origMarkerX == 0 && origMarkerY == 0) {
|
||||||
|
origMarkerX = view.getWidth() / 2;
|
||||||
|
origMarkerY = view.getHeight() / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (initLayout && centered) {
|
||||||
|
centerMarkerLocation();
|
||||||
|
}
|
||||||
|
if (!moving) {
|
||||||
|
doLayoutMenu();
|
||||||
|
}
|
||||||
|
initLayout = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
menuTopViewHeight = newMenuTopViewHeight;
|
|
||||||
menuTopShadowAllHeight = newMenuTopShadowAllHeight;
|
|
||||||
menuTitleHeight = menuTopShadowHeight + menuTopShadowAllHeight + dy;
|
|
||||||
menuBottomViewHeight = view.findViewById(R.id.context_menu_bottom_view).getHeight();
|
|
||||||
|
|
||||||
menuFullHeightMax = menuTitleHeight + menuBottomViewHeight;
|
});
|
||||||
|
}
|
||||||
if (origMarkerX == 0 && origMarkerY == 0) {
|
|
||||||
origMarkerX = view.getWidth() / 2;
|
|
||||||
origMarkerY = view.getHeight() / 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (initLayout && centered) {
|
|
||||||
centerMarkerLocation();
|
|
||||||
}
|
|
||||||
if (!moving) {
|
|
||||||
doLayoutMenu();
|
|
||||||
}
|
|
||||||
initLayout = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void centerMarkerLocation() {
|
public void centerMarkerLocation() {
|
||||||
|
@ -934,41 +942,42 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setAddressLocation() {
|
private void setAddressLocation() {
|
||||||
// Text line 1
|
if (view != null) {
|
||||||
TextView line1 = (TextView) view.findViewById(R.id.context_menu_line1);
|
// Text line 1
|
||||||
line1.setText(menu.getTitleStr());
|
TextView line1 = (TextView) view.findViewById(R.id.context_menu_line1);
|
||||||
|
line1.setText(menu.getTitleStr());
|
||||||
|
|
||||||
// Text line 2
|
// Text line 2
|
||||||
LinearLayout line2layout = (LinearLayout) view.findViewById(R.id.context_menu_line2_layout);
|
LinearLayout line2layout = (LinearLayout) view.findViewById(R.id.context_menu_line2_layout);
|
||||||
TextView line2 = (TextView) view.findViewById(R.id.context_menu_line2);
|
TextView line2 = (TextView) view.findViewById(R.id.context_menu_line2);
|
||||||
if (menu.hasCustomAddressLine()) {
|
if (menu.hasCustomAddressLine()) {
|
||||||
line2layout.removeAllViews();
|
line2layout.removeAllViews();
|
||||||
menu.buildCustomAddressLine(line2layout);
|
menu.buildCustomAddressLine(line2layout);
|
||||||
} else {
|
} else {
|
||||||
String typeStr = menu.getTypeStr();
|
String typeStr = menu.getTypeStr();
|
||||||
String streetStr = menu.getStreetStr();
|
String streetStr = menu.getStreetStr();
|
||||||
StringBuilder line2Str = new StringBuilder();
|
StringBuilder line2Str = new StringBuilder();
|
||||||
if (!Algorithms.isEmpty(typeStr)) {
|
if (!Algorithms.isEmpty(typeStr)) {
|
||||||
line2Str.append(typeStr);
|
line2Str.append(typeStr);
|
||||||
Drawable icon = menu.getTypeIcon();
|
Drawable icon = menu.getTypeIcon();
|
||||||
line2.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null);
|
line2.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null);
|
||||||
line2.setCompoundDrawablePadding(dpToPx(5f));
|
line2.setCompoundDrawablePadding(dpToPx(5f));
|
||||||
}
|
|
||||||
if (!Algorithms.isEmpty(streetStr) && !menu.displayStreetNameInTitle()) {
|
|
||||||
if (line2Str.length() > 0) {
|
|
||||||
line2Str.append(": ");
|
|
||||||
}
|
}
|
||||||
line2Str.append(streetStr);
|
if (!Algorithms.isEmpty(streetStr) && !menu.displayStreetNameInTitle()) {
|
||||||
|
if (line2Str.length() > 0) {
|
||||||
|
line2Str.append(": ");
|
||||||
|
}
|
||||||
|
line2Str.append(streetStr);
|
||||||
|
}
|
||||||
|
line2.setText(line2Str.toString());
|
||||||
}
|
}
|
||||||
line2.setText(line2Str.toString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
updateCompassVisibility();
|
updateCompassVisibility();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateCompassVisibility() {
|
private void updateCompassVisibility() {
|
||||||
OsmandApplication app = getMyApplication();
|
OsmandApplication app = getMyApplication();
|
||||||
if (app != null) {
|
if (app != null && view != null) {
|
||||||
View compassView = view.findViewById(R.id.compass_layout);
|
View compassView = view.findViewById(R.id.compass_layout);
|
||||||
Location ll = app.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;
|
||||||
|
@ -988,7 +997,7 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
|
||||||
private void updateDistanceDirection() {
|
private void updateDistanceDirection() {
|
||||||
OsmandApplication app = getMyApplication();
|
OsmandApplication app = getMyApplication();
|
||||||
FragmentActivity activity = getActivity();
|
FragmentActivity activity = getActivity();
|
||||||
if (app != null && activity != null) {
|
if (app != null && activity != null && view != 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();
|
||||||
|
@ -1035,12 +1044,14 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateMainViewLayout(int posY) {
|
private void updateMainViewLayout(int posY) {
|
||||||
menuFullHeight = view.getHeight() - posY;
|
if (view != null) {
|
||||||
if (!oldAndroid()) {
|
menuFullHeight = view.getHeight() - posY;
|
||||||
ViewGroup.LayoutParams lp = mainView.getLayoutParams();
|
if (!oldAndroid()) {
|
||||||
lp.height = Math.max(menuFullHeight, menuTitleHeight);
|
ViewGroup.LayoutParams lp = mainView.getLayoutParams();
|
||||||
mainView.setLayoutParams(lp);
|
lp.height = Math.max(menuFullHeight, menuTitleHeight);
|
||||||
mainView.requestLayout();
|
mainView.setLayoutParams(lp);
|
||||||
|
mainView.requestLayout();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1176,14 +1187,16 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFragmentVisibility(boolean visible) {
|
public void setFragmentVisibility(boolean visible) {
|
||||||
if (visible) {
|
if (view != null) {
|
||||||
view.setVisibility(View.VISIBLE);
|
if (visible) {
|
||||||
if (mapCenter != null) {
|
view.setVisibility(View.VISIBLE);
|
||||||
map.setLatLon(mapCenter.getLatitude(), mapCenter.getLongitude());
|
if (mapCenter != null) {
|
||||||
|
map.setLatLon(mapCenter.getLatitude(), mapCenter.getLongitude());
|
||||||
|
}
|
||||||
|
adjustMapPosition(getPosY(), true, false);
|
||||||
|
} else {
|
||||||
|
view.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
adjustMapPosition(getPosY(), true, false);
|
|
||||||
} else {
|
|
||||||
view.setVisibility(View.GONE);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue