Add left side menu for GPX-points for landscape version of plan route

This commit is contained in:
cepprice 2021-03-03 12:30:19 +05:00
parent a80f463d2b
commit 2f72ddc566
2 changed files with 65 additions and 31 deletions

View file

@ -48,6 +48,11 @@
<include layout="@layout/map_hud_top"
android:id="@+id/MapHudButtonsOverlayTop"/>
<FrameLayout
android:id="@+id/left_side_menu"
android:layout_width="0dp"
android:layout_height="0dp"/>
<include layout="@layout/map_hud_bottom"
android:id="@+id/MapHudButtonsOverlayBottom"/>

View file

@ -11,6 +11,8 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
@ -18,17 +20,6 @@ import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import androidx.activity.OnBackPressedCallback;
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.content.res.AppCompatResources;
import androidx.core.content.ContextCompat;
import androidx.core.widget.TextViewCompat;
import androidx.fragment.app.FragmentManager;
import androidx.recyclerview.widget.ItemTouchHelper;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.snackbar.Snackbar;
import net.osmand.AndroidUtils;
@ -94,6 +85,17 @@ import java.util.Date;
import java.util.List;
import java.util.Locale;
import androidx.activity.OnBackPressedCallback;
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.content.res.AppCompatResources;
import androidx.core.content.ContextCompat;
import androidx.core.widget.TextViewCompat;
import androidx.fragment.app.FragmentManager;
import androidx.recyclerview.widget.ItemTouchHelper;
import androidx.recyclerview.widget.RecyclerView;
import static net.osmand.IndexConstants.GPX_FILE_EXT;
import static net.osmand.IndexConstants.GPX_INDEX_DIR;
import static net.osmand.plus.measurementtool.MeasurementEditingContext.CalculationMode;
@ -126,6 +128,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
private RadioItem pointsBtn;
private RadioItem graphBtn;
private View mainView;
private View bottomMapControls;
private ImageView upDownBtn;
private ImageView undoBtn;
private ImageView redoBtn;
@ -281,8 +284,9 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
mainView = view.findViewById(R.id.main_view);
AndroidUtils.setBackground(mapActivity, mainView, nightMode, R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark);
detailsMenu = new GraphDetailsMenu();
cardsContainer = mainView.findViewById(R.id.cards_container);
if (portrait) {
cardsContainer = mainView.findViewById(R.id.cards_container);
String pointsBtnTitle = getString(R.string.shared_string_gpx_points);
pointsBtn = new RadioItem(pointsBtnTitle);
pointsBtn.setOnClickListener(getInfoTypeBtnListener(InfoType.POINTS));
@ -294,6 +298,15 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
LinearLayout infoButtonsContainer = mainView.findViewById(R.id.custom_radio_buttons);
infoTypeBtn = new MultiStateToggleButton(app, infoButtonsContainer, nightMode);
infoTypeBtn.setItems(pointsBtn, graphBtn);
} else {
cardsContainer = mapActivity.findViewById(R.id.left_side_menu);
bottomMapControls = mapActivity.findViewById(R.id.bottom_controls_container);
mainView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
updateCardContainerSize();
}
});
}
pointsCard = new PointsCard(mapActivity, this);
graphsCard = new GraphsCard(mapActivity, detailsMenu, this);
@ -328,12 +341,10 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
upDownRow.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (portrait) {
if (infoExpanded) {
collapseInfoView();
} else if (setInfoType(InfoType.POINTS)) {
infoTypeBtn.setSelectedItem(pointsBtn);
}
if (infoExpanded) {
collapseInfoView();
} else if (setInfoType(InfoType.POINTS) && portrait) {
infoTypeBtn.setSelectedItem(pointsBtn);
}
}
});
@ -608,14 +619,13 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
}
private void expandInfoView() {
if (portrait) {
infoExpanded = true;
cardsContainer.setVisibility(View.VISIBLE);
setMapPosition(portrait
? OsmandSettings.MIDDLE_TOP_CONSTANT
: OsmandSettings.LANDSCAPE_MIDDLE_RIGHT_CONSTANT);
updateUpDownBtn();
}
infoExpanded = true;
shiftBottomMapControls(false);
cardsContainer.setVisibility(View.VISIBLE);
setMapPosition(portrait
? OsmandSettings.MIDDLE_TOP_CONSTANT
: OsmandSettings.LANDSCAPE_MIDDLE_RIGHT_CONSTANT);
updateUpDownBtn();
}
private void collapseInfoViewIfExpanded() {
@ -625,14 +635,16 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
}
private void collapseInfoView() {
cardsContainer.setVisibility(View.GONE);
if (portrait) {
infoExpanded = false;
currentInfoType = null;
infoTypeBtn.setSelectedItem(null);
cardsContainer.setVisibility(View.GONE);
setDefaultMapPosition();
updateUpDownBtn();
} else {
shiftBottomMapControls(true);
}
infoExpanded = false;
currentInfoType = null;
setDefaultMapPosition();
updateUpDownBtn();
}
private void collapseInfoIfNotEnoughPoints() {
@ -659,6 +671,22 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
}
}
private void updateCardContainerSize() {
View measureModeControls = mainView.findViewById(R.id.measure_mode_controls);
int width = mainView.getWidth() - measureModeControls.getWidth();
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(width, -1);
int bottomMargin = measureModeControls.getHeight();
bottomMargin = progressBarVisible ? bottomMargin + mainView.findViewById(R.id.snap_to_road_progress_bar).getHeight() : bottomMargin;
params.setMargins(0, 0, 0, bottomMargin);
cardsContainer.setLayoutParams(params);
}
private void shiftBottomMapControls(boolean toInitialPosition) {
int leftMargin = toInitialPosition ? 0 : cardsContainer.getWidth();
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) bottomMapControls.getLayoutParams();
params.setMargins(leftMargin, 0, 0, 0);
}
public boolean isInEditMode() {
return !isPlanRouteMode() && !editingCtx.isNewData() && !isDirectionMode() && !isFollowTrackMode();
}
@ -780,6 +808,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
progressBar.setMinimumHeight(0);
progressBar.setProgress(0);
progressBarVisible = true;
updateCardContainerSize();
}
public boolean isProgressBarVisible() {