use of net.osmand.plus.widgets.multistatetoggle.TextToggleButton in project Osmand by osmandapp.
the class SplitIntervalBottomSheet method setupTypeRadioGroup.
private void setupTypeRadioGroup(LinearLayout buttonsContainer) {
TextRadioItem none = createRadioButton(GpxSplitType.NO_SPLIT, R.string.shared_string_none);
TextRadioItem time = createRadioButton(GpxSplitType.TIME, R.string.shared_string_time);
TextRadioItem distance = createRadioButton(GpxSplitType.DISTANCE, R.string.distance);
GPXTrackAnalysis analysis = selectedGpxFile.getTrackAnalysisToDisplay(app);
time.setEnabled(analysis.timeSpan > 0);
TextToggleButton radioGroup = new TextToggleButton(app, buttonsContainer, nightMode);
radioGroup.setItems(none, time, distance);
if (selectedSplitType == GpxSplitType.NO_SPLIT) {
radioGroup.setSelectedItem(none);
} else {
radioGroup.setSelectedItem(selectedSplitType == GpxSplitType.TIME ? time : distance);
}
}
use of net.osmand.plus.widgets.multistatetoggle.TextToggleButton in project Osmand by osmandapp.
the class MeasurementToolFragment method onCreateView.
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
MapActivity mapActivity = (MapActivity) getActivity();
if (mapActivity == null) {
return null;
}
final MeasurementToolLayer measurementLayer = mapActivity.getMapLayers().getMeasurementToolLayer();
final OsmandApplication app = mapActivity.getMyApplication();
app.setMeasurementEditingContext(editingCtx);
editingCtx.setProgressListener(new SnapToRoadProgressListener() {
@Override
public void showProgressBar() {
MeasurementToolFragment.this.showProgressBar();
updateInfoView();
updateInfoViewAppearance();
}
@Override
public void updateProgress(int progress) {
((ProgressBar) mainView.findViewById(R.id.snap_to_road_progress_bar)).setProgress(progress);
}
@Override
public void hideProgressBar() {
((ProgressBar) mainView.findViewById(R.id.snap_to_road_progress_bar)).setVisibility(View.INVISIBLE);
progressBarVisible = false;
updateInfoView();
updateInfoViewAppearance();
}
@Override
public void refresh() {
measurementLayer.refreshMap();
updateDistancePointsText();
}
});
editingCtx.setupRouteSettingsListener();
measurementLayer.setEditingCtx(editingCtx);
nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls();
portrait = AndroidUiHelper.isOrientationPortrait(mapActivity);
int btnWidth = getResources().getDimensionPixelOffset(R.dimen.gpx_group_button_width);
pointsSt = getString(R.string.shared_string_gpx_points).toLowerCase();
View view = UiUtilities.getInflater(getContext(), nightMode).inflate(R.layout.fragment_measurement_tool, container, false);
mainView = view.findViewById(R.id.main_view);
detailsMenu = new GraphDetailsMenu();
LinearLayout infoButtonsContainer = mainView.findViewById(R.id.custom_radio_buttons);
if (portrait) {
cardsContainer = mainView.findViewById(R.id.cards_container);
infoTypeBtn = new TextToggleButton(app, infoButtonsContainer, nightMode);
String pointsBtnTitle = getString(R.string.shared_string_gpx_points);
pointsBtn = new TextRadioItem(pointsBtnTitle);
String graphBtnTitle = getString(R.string.shared_string_graph);
graphBtn = new TextRadioItem(graphBtnTitle);
} else {
cardsContainer = mapActivity.findViewById(R.id.left_side_menu);
bottomMapControls = mapActivity.findViewById(R.id.bottom_controls_container);
topMapControls = mapActivity.findViewById(R.id.top_controls_container);
infoTypeBtn = new IconToggleButton(app, infoButtonsContainer, nightMode);
pointsBtn = new IconRadioItem(R.drawable.ic_action_plan_route_point_colored, true);
graphBtn = new IconRadioItem(R.drawable.ic_action_analyze_intervals);
ScrollUtils.addOnGlobalLayoutListener(mainView, new Runnable() {
@Override
public void run() {
updateInfoViewAppearance();
}
});
}
pointsBtn.setOnClickListener(getInfoTypeBtnListener(InfoType.POINTS));
graphBtn.setOnClickListener(getInfoTypeBtnListener(InfoType.GRAPH));
infoTypeBtn.setItems(pointsBtn, graphBtn);
pointsCard = new PointsCard(mapActivity, this);
chartsCard = new ChartsCard(mapActivity, detailsMenu, this);
if (progressBarVisible) {
showProgressBar();
}
distanceTv = (TextView) mainView.findViewById(R.id.measurement_distance_text_view);
pointsTv = (TextView) mainView.findViewById(R.id.measurement_points_text_view);
distanceToCenterTv = (TextView) mainView.findViewById(R.id.distance_to_center_text_view);
mainIcon = (ImageView) mainView.findViewById(R.id.main_icon);
upDownBtn = (ImageView) mainView.findViewById(R.id.up_down_button);
updateUpDownBtn();
mainView.findViewById(R.id.cancel_move_point_button).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
cancelMovePointMode();
}
});
mainView.findViewById(R.id.cancel_point_before_after_button).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
cancelAddPointBeforeOrAfterMode();
}
});
View upDownRow = mainView.findViewById(R.id.up_down_row);
upDownRow.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (infoExpanded) {
collapseInfoView();
} else if (setInfoType(InfoType.POINTS)) {
infoTypeBtn.setSelectedItem(pointsBtn);
}
}
});
View applyMovePointButton = mainView.findViewById(R.id.apply_move_point_button);
UiUtilities.setupDialogButton(nightMode, applyMovePointButton, UiUtilities.DialogButtonType.PRIMARY, R.string.shared_string_apply);
applyMovePointButton.setMinimumWidth(btnWidth);
applyMovePointButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
applyMovePointMode();
}
});
View applyPointBeforeAfterButton = mainView.findViewById(R.id.apply_point_before_after_point_button);
UiUtilities.setupDialogButton(nightMode, applyPointBeforeAfterButton, UiUtilities.DialogButtonType.PRIMARY, R.string.shared_string_apply);
applyPointBeforeAfterButton.setMinimumWidth(btnWidth);
applyPointBeforeAfterButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
applyAddPointBeforeAfterMode();
}
});
View addPointBeforeAfterButton = mainView.findViewById(R.id.add_point_before_after_button);
UiUtilities.setupDialogButton(nightMode, addPointBeforeAfterButton, UiUtilities.DialogButtonType.PRIMARY, R.string.shared_string_add);
addPointBeforeAfterButton.setMinimumWidth(btnWidth);
addPointBeforeAfterButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
addPointBeforeAfter();
}
});
mainView.findViewById(R.id.options_button).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
boolean trackSnappedToRoad = !editingCtx.isApproximationNeeded();
boolean addNewSegmentAllowed = editingCtx.isAddNewSegmentAllowed();
boolean plainTrack = editingCtx.getPointsCount() > 0 && !editingCtx.hasRoutePoints() && !editingCtx.hasRoute();
OptionsBottomSheetDialogFragment.showInstance(mapActivity.getSupportFragmentManager(), MeasurementToolFragment.this, trackSnappedToRoad, addNewSegmentAllowed, editingCtx.getAppMode().getStringKey(), plainTrack);
}
}
});
undoBtn = ((ImageButton) mainView.findViewById(R.id.undo_point_button));
redoBtn = ((ImageButton) mainView.findViewById(R.id.redo_point_button));
Drawable undoDrawable = getActiveIcon(R.drawable.ic_action_undo_dark);
undoBtn.setImageDrawable(AndroidUtils.getDrawableForDirection(mapActivity, undoDrawable));
undoBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
editingCtx.getCommandManager().undo();
updateUndoRedoButton(editingCtx.getCommandManager().canUndo(), undoBtn);
updateUndoRedoButton(true, redoBtn);
updateUndoRedoCommonStuff();
}
});
Drawable redoDrawable = getActiveIcon(R.drawable.ic_action_redo_dark);
redoBtn.setImageDrawable(AndroidUtils.getDrawableForDirection(mapActivity, redoDrawable));
redoBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
editingCtx.getCommandManager().redo();
updateUndoRedoButton(editingCtx.getCommandManager().canRedo(), redoBtn);
updateUndoRedoButton(true, undoBtn);
updateUndoRedoCommonStuff();
}
});
View addPointButton = mainView.findViewById(R.id.add_point_button);
UiUtilities.setupDialogButton(nightMode, addPointButton, UiUtilities.DialogButtonType.PRIMARY, R.string.shared_string_add);
addPointButton.setMinimumWidth(btnWidth);
addPointButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
addCenterPoint();
}
});
measurementLayer.setOnSingleTapListener(new MeasurementToolLayer.OnSingleTapListener() {
@Override
public void onAddPoint() {
addPoint();
}
@Override
public void onSelectPoint(int selectedPointPos) {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null && selectedPointPos != -1) {
openSelectedPointMenu(mapActivity);
}
}
@Override
public void onSelectProfileIcon(int startPointPos) {
if (startPointPos != -1) {
onChangeRouteTypeAfter();
}
}
});
measurementLayer.setOnMeasureDistanceToCenterListener(new MeasurementToolLayer.OnMeasureDistanceToCenter() {
@Override
public void onMeasure(float distance, float bearing) {
String distStr = OsmAndFormatter.getFormattedDistance(distance, app);
String azimuthStr = OsmAndFormatter.getFormattedAzimuth(bearing, app);
distanceToCenterTv.setText(String.format("%1$s • %2$s", distStr, azimuthStr));
TextViewCompat.setAutoSizeTextTypeUniformWithConfiguration(distanceToCenterTv, 14, 18, 2, TypedValue.COMPLEX_UNIT_SP);
}
});
measurementLayer.setOnEnterMovePointModeListener(new MeasurementToolLayer.OnEnterMovePointModeListener() {
@Override
public void onEnterMovePointMode() {
collapseInfoViewIfExpanded();
switchMovePointMode(true);
}
});
if (!editingCtx.getCommandManager().canUndo()) {
updateUndoRedoButton(false, undoBtn);
}
if (!editingCtx.getCommandManager().canRedo()) {
updateUndoRedoButton(false, redoBtn);
}
if (editingCtx.getPointsCount() < 1) {
disable(upDownBtn);
}
toolBarController = new MeasurementToolBarController();
if (editingCtx.getSelectedPointPosition() != -1) {
int navigationIconResId = AndroidUtils.getNavigationIconResId(mapActivity);
toolBarController.setBackBtnIconIds(navigationIconResId, navigationIconResId);
} else {
toolBarController.setBackBtnIconIds(R.drawable.ic_action_remove_dark, R.drawable.ic_action_remove_dark);
}
toolBarController.setOnBackButtonClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
GpxApproximationFragment gpxApproximationFragment = mapActivity.getGpxApproximationFragment();
SnapTrackWarningFragment snapTrackWarningFragment = mapActivity.getSnapTrackWarningBottomSheet();
if (gpxApproximationFragment != null) {
gpxApproximationFragment.dismissImmediate();
} else if (snapTrackWarningFragment != null) {
snapTrackWarningFragment.dismissImmediate();
} else {
quit(false);
}
}
}
});
toolBarController.setOnSaveViewClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (isFollowTrackMode()) {
startTrackNavigation();
} else if (editingCtx.isNewData() || editingCtx.hasChanges()) {
saveChanges(FinalSaveAction.SHOW_SNACK_BAR_AND_CLOSE, false);
} else {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
dismiss(mapActivity, false);
}
}
}
});
updateToolbar();
ImageButton snapToRoadBtn = mapActivity.findViewById(R.id.snap_to_road_image_button);
snapToRoadBtn.setBackgroundResource(nightMode ? R.drawable.btn_circle_night : R.drawable.btn_circle);
snapToRoadBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
startSnapToRoad(false);
}
});
snapToRoadBtn.setVisibility(View.VISIBLE);
LinearLayout profileWithConfig = mapActivity.findViewById(R.id.profile_with_config_btn);
View background = profileWithConfig.findViewById(R.id.btn_background);
AndroidUtils.setBackground(background, AppCompatResources.getDrawable(view.getContext(), AndroidUtils.resolveAttribute(view.getContext(), R.attr.bg_round_btn)));
View divider = profileWithConfig.findViewById(R.id.divider);
divider.setBackgroundResource(AndroidUtils.resolveAttribute(view.getContext(), R.attr.divider_color));
ImageButton profileBtn = profileWithConfig.findViewById(R.id.profile);
profileBtn.setBackgroundResource(nightMode ? R.drawable.btn_circle_night_no_shadow : R.drawable.btn_circle_no_shadow);
profileBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
startSnapToRoad(false);
}
});
ImageButton configBtn = profileWithConfig.findViewById(R.id.profile_config);
configBtn.setBackgroundResource(nightMode ? R.drawable.btn_circle_night_no_shadow : R.drawable.btn_circle_no_shadow);
configBtn.setImageDrawable(getContentIcon(R.drawable.ic_action_settings));
configBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
RouteOptionsBottomSheet.showInstance(mapActivity, MeasurementToolFragment.this, DialogMode.PLAN_ROUTE, editingCtx.getAppMode().getStringKey());
}
}
});
GpxData gpxData = editingCtx.getGpxData();
initMeasurementMode(gpxData, savedInstanceState == null);
if (savedInstanceState == null) {
if (fileName != null) {
addNewGpxData(getGpxFile(fileName));
} else if (editingCtx.isApproximationNeeded() && isFollowTrackMode() && isShowSnapWarning()) {
enterApproximationMode(mapActivity);
}
} else {
measurementLayer.setTapsDisabled(savedInstanceState.getBoolean(TAPS_DISABLED_KEY));
if (initialPoint == null && savedInstanceState.containsKey(INITIAL_POINT_KEY)) {
initialPoint = (LatLon) savedInstanceState.getSerializable(INITIAL_POINT_KEY);
}
modes = savedInstanceState.getInt(MODES_KEY);
showSnapWarning = savedInstanceState.getBoolean(SHOW_SNAP_WARNING_KEY);
}
return view;
}
Aggregations