Search in sources :

Example 21 with MapActivity

use of net.osmand.plus.activities.MapActivity in project Osmand by osmandapp.

the class PlanRouteFragment method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    final MapActivity mapActivity = getMapActivity();
    markersHelper = mapActivity.getMyApplication().getMapMarkersHelper();
    planRouteContext = markersHelper.getPlanRouteContext();
    planRouteContext.setListener(new MarkersPlanRouteContext.PlanRouteProgressListener() {

        @Override
        public void showProgressBar() {
            PlanRouteFragment.this.showProgressBar();
        }

        @Override
        public void updateProgress(int progress) {
            ((ProgressBar) mainView.findViewById(R.id.snap_to_road_progress_bar)).setProgress(progress);
        }

        @Override
        public void hideProgressBar(boolean canceled) {
            mainView.findViewById(R.id.snap_to_road_progress_bar).setVisibility(View.GONE);
            planRouteContext.setProgressBarVisible(false);
            if (!canceled && portrait && planRouteContext.isMarkersListOpened()) {
                Snackbar.make(mainView, getString(R.string.route_is_calculated) + ":", Snackbar.LENGTH_LONG).setAction(R.string.show_map, new View.OnClickListener() {

                    @Override
                    public void onClick(View view) {
                        showHideMarkersList();
                    }
                }).show();
            }
        }

        @Override
        public void refresh() {
            adapter.notifyDataSetChanged();
            mapActivity.refreshMap();
        }

        @Override
        public void updateText() {
            PlanRouteFragment.this.updateText();
        }

        @Override
        public void showMarkersRouteOnMap(boolean adjustMap) {
            PlanRouteFragment.this.showMarkersRouteOnMap(adjustMap);
        }
    });
    // Handling screen rotation
    FragmentManager fragmentManager = mapActivity.getSupportFragmentManager();
    Fragment snapToRoadFragment = fragmentManager.findFragmentByTag(SnapToRoadBottomSheetDialogFragment.TAG);
    if (snapToRoadFragment != null) {
        ((SnapToRoadBottomSheetDialogFragment) snapToRoadFragment).setListener(createSnapToRoadFragmentListener());
    }
    Fragment optionsFragment = fragmentManager.findFragmentByTag(PlanRouteOptionsBottomSheetDialogFragment.TAG);
    if (optionsFragment != null) {
        ((PlanRouteOptionsBottomSheetDialogFragment) optionsFragment).setListener(createOptionsFragmentListener());
    }
    toolbarHeight = mapActivity.getResources().getDimensionPixelSize(R.dimen.dashboard_map_toolbar);
    nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls();
    final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
    final int backgroundColor = ContextCompat.getColor(mapActivity, nightMode ? R.color.ctx_menu_info_view_bg_dark : R.color.ctx_menu_info_view_bg_light);
    portrait = AndroidUiHelper.isOrientationPortrait(mapActivity);
    fullScreen = portrait && planRouteContext.isMarkersListOpened();
    int layoutRes = fullScreen ? R.layout.fragment_plan_route_full_screen : R.layout.fragment_plan_route_half_screen;
    View view = View.inflate(new ContextThemeWrapper(getContext(), themeRes), layoutRes, null);
    mainView = fullScreen ? view : view.findViewById(R.id.main_view);
    enterPlanRouteMode();
    View markersListContainer = mainView.findViewById(R.id.markers_list_container);
    if (markersListContainer != null) {
        markersListContainer.setBackgroundColor(backgroundColor);
    }
    if (portrait) {
        mainView.findViewById(R.id.toolbar_divider).setBackgroundColor(ContextCompat.getColor(mapActivity, nightMode ? R.color.actionbar_dark_color : R.color.dashboard_divider_light));
        Drawable arrow = getContentIcon(fullScreen ? R.drawable.ic_action_arrow_down : R.drawable.ic_action_arrow_up);
        ((ImageView) mainView.findViewById(R.id.up_down_icon)).setImageDrawable(arrow);
        mainView.findViewById(R.id.up_down_row).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                showHideMarkersList();
            }
        });
        mainView.findViewById(R.id.select_all_button).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                selectAllOnClick();
                updateSelectButton();
            }
        });
        toolbarController = new PlanRouteToolbarController();
        toolbarController.setBackBtnIconIds(R.drawable.ic_action_mode_back, R.drawable.ic_action_mode_back);
        toolbarController.setTitle(getString(R.string.plan_route));
        toolbarController.setOnBackButtonClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                if (quit(false)) {
                    MapMarkersDialogFragment.showInstance(mapActivity);
                }
            }
        });
        toolbarController.setSaveViewTextId(R.string.shared_string_options);
        toolbarController.setOnSaveViewClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                optionsOnClick();
            }
        });
        mapActivity.showTopToolbar(toolbarController);
        if (fullScreen) {
            mapActivity.findViewById(R.id.bottom_controls_container).setVisibility(View.GONE);
            mainView.findViewById(R.id.plan_route_toolbar).setVisibility(View.VISIBLE);
            mainView.findViewById(R.id.toolbar_divider).setVisibility(View.VISIBLE);
        } else {
            final int screenH = AndroidUtils.getScreenHeight(mapActivity);
            final int statusBarH = AndroidUtils.getStatusBarHeight(mapActivity);
            final int navBarH = AndroidUtils.getNavBarHeight(mapActivity);
            final int availableHeight = (screenH - statusBarH - navBarH) / 2;
            mainView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

                @Override
                public void onGlobalLayout() {
                    int upDownRowH = mainView.findViewById(R.id.up_down_row).getHeight();
                    closedListContainerHeight = availableHeight - upDownRowH;
                    View listContainer = mainView.findViewById(R.id.markers_list_container);
                    listContainer.getLayoutParams().height = closedListContainerHeight;
                    listContainer.requestLayout();
                    ViewTreeObserver obs = mainView.getViewTreeObserver();
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                        obs.removeOnGlobalLayoutListener(this);
                    } else {
                        obs.removeGlobalOnLayoutListener(this);
                    }
                }
            });
        }
    }
    Toolbar toolbar = (Toolbar) mainView.findViewById(R.id.plan_route_toolbar);
    toolbar.setNavigationIcon(getContentIcon(R.drawable.ic_arrow_back));
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (quit(false)) {
                MapMarkersDialogFragment.showInstance(mapActivity);
            }
        }
    });
    mainView.findViewById(R.id.options_button).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            optionsOnClick();
        }
    });
    markersRv = mainView.findViewById(R.id.markers_recycler_view);
    adapter = new MapMarkersListAdapter(mapActivity);
    adapter.setHasStableIds(true);
    adapter.setSnappedToRoadPoints(planRouteContext.getSnappedToRoadPoints());
    final ItemTouchHelper touchHelper = new ItemTouchHelper(new MapMarkersItemTouchHelperCallback(adapter));
    touchHelper.attachToRecyclerView(markersRv);
    adapter.setAdapterListener(new MapMarkersListAdapter.MapMarkersListAdapterListener() {

        private int fromPosition;

        private int toPosition;

        @Override
        public void onDisableRoundTripClick() {
            roundTripOnClick();
        }

        @Override
        public void onCheckBoxClick(View view) {
            int pos = markersRv.getChildAdapterPosition(view);
            if (pos == RecyclerView.NO_POSITION) {
                return;
            }
            Object item = adapter.getItem(pos);
            if (item instanceof Location) {
                markersHelper.setStartFromMyLocation(!mapActivity.getMyApplication().getSettings().ROUTE_MAP_MARKERS_START_MY_LOC.get());
            } else if (item instanceof MapMarker) {
                MapMarker marker = (MapMarker) item;
                selectedCount = marker.selected ? selectedCount - 1 : selectedCount + 1;
                marker.selected = !marker.selected;
                markersHelper.updateMapMarker(marker, false);
            }
            adapter.reloadData();
            adapter.notifyDataSetChanged();
            updateSelectButton();
            planRouteContext.recreateSnapTrkSegment(false);
        }

        @Override
        public void onItemClick(View v) {
            int pos = markersRv.getChildAdapterPosition(v);
            if (pos == RecyclerView.NO_POSITION) {
                return;
            }
            Object item = adapter.getItem(pos);
            if (item instanceof Location) {
                Location loc = (Location) item;
                moveMapToPosition(loc.getLatitude(), loc.getLongitude());
            } else if (item instanceof MapMarker) {
                MapMarker marker = (MapMarker) item;
                moveMapToPosition(marker.getLatitude(), marker.getLongitude());
            }
        }

        @Override
        public void onDragStarted(RecyclerView.ViewHolder holder) {
            fromPosition = holder.getAdapterPosition();
            touchHelper.startDrag(holder);
        }

        @Override
        public void onDragEnded(RecyclerView.ViewHolder holder) {
            toPosition = holder.getAdapterPosition();
            if (toPosition >= 0 && fromPosition >= 0) {
                mapActivity.getMyApplication().getMapMarkersHelper().reorderActiveMarkersIfNeeded();
                mapActivity.refreshMap();
                adapter.reloadData();
                try {
                    adapter.notifyDataSetChanged();
                } catch (Exception e) {
                // to avoid crash because of:
                // java.lang.IllegalStateException: Cannot call this method while RecyclerView is computing a layout or scrolling
                }
                planRouteContext.recreateSnapTrkSegment(false);
            }
        }
    });
    markersRv.setPadding(0, (int) mapActivity.getResources().getDimension(R.dimen.map_markers_recycler_view_padding_top), 0, (int) mapActivity.getResources().getDimension(R.dimen.map_markers_recycler_view_padding_bottom));
    markersRv.setClipToPadding(false);
    markersRv.setLayoutManager(new LinearLayoutManager(getContext()));
    markersRv.setAdapter(adapter);
    if (planRouteContext.isProgressBarVisible()) {
        showProgressBar();
    }
    return view;
}
Also used : MapMarker(net.osmand.plus.MapMarkersHelper.MapMarker) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) Fragment(android.support.v4.app.Fragment) SnapToRoadBottomSheetDialogFragment(net.osmand.plus.measurementtool.SnapToRoadBottomSheetDialogFragment) BaseOsmAndFragment(net.osmand.plus.base.BaseOsmAndFragment) ItemTouchHelper(android.support.v7.widget.helper.ItemTouchHelper) MapMarkersItemTouchHelperCallback(net.osmand.plus.mapmarkers.adapters.MapMarkersItemTouchHelperCallback) ImageView(android.widget.ImageView) ViewTreeObserver(android.view.ViewTreeObserver) MapActivity(net.osmand.plus.activities.MapActivity) SnapToRoadBottomSheetDialogFragment(net.osmand.plus.measurementtool.SnapToRoadBottomSheetDialogFragment) Toolbar(android.support.v7.widget.Toolbar) Drawable(android.graphics.drawable.Drawable) MapMarkersListAdapter(net.osmand.plus.mapmarkers.adapters.MapMarkersListAdapter) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) RecyclerView(android.support.v7.widget.RecyclerView) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) FragmentManager(android.support.v4.app.FragmentManager) ContextThemeWrapper(android.view.ContextThemeWrapper) RecyclerView(android.support.v7.widget.RecyclerView) Location(net.osmand.Location) Nullable(android.support.annotation.Nullable)

Example 22 with MapActivity

use of net.osmand.plus.activities.MapActivity in project Osmand by osmandapp.

the class PlanRouteFragment method setupAppModesBtn.

private void setupAppModesBtn() {
    final MapActivity mapActivity = getMapActivity();
    if (mapActivity != null) {
        final ImageButton appModesBtn = (ImageButton) mapActivity.findViewById(R.id.snap_to_road_image_button);
        appModesBtn.setBackgroundResource(nightMode ? R.drawable.btn_circle_night : R.drawable.btn_circle);
        appModesBtn.setImageDrawable(getActiveIcon(planRouteContext.getSnappedMode().getMapIconId()));
        appModesBtn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                SnapToRoadBottomSheetDialogFragment fragment = new SnapToRoadBottomSheetDialogFragment();
                fragment.setListener(createSnapToRoadFragmentListener());
                fragment.setRemoveDefaultMode(false);
                fragment.show(mapActivity.getSupportFragmentManager(), SnapToRoadBottomSheetDialogFragment.TAG);
            }
        });
        if (!portrait) {
            LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) appModesBtn.getLayoutParams();
            params.leftMargin = mapActivity.getResources().getDimensionPixelSize(R.dimen.dashboard_land_width);
            appModesBtn.setLayoutParams(params);
        }
        appModesBtn.setVisibility(View.VISIBLE);
    }
}
Also used : ImageButton(android.widget.ImageButton) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) RecyclerView(android.support.v7.widget.RecyclerView) LinearLayout(android.widget.LinearLayout) MapActivity(net.osmand.plus.activities.MapActivity) SnapToRoadBottomSheetDialogFragment(net.osmand.plus.measurementtool.SnapToRoadBottomSheetDialogFragment)

Example 23 with MapActivity

use of net.osmand.plus.activities.MapActivity in project Osmand by osmandapp.

the class PlanRouteFragment method onPause.

@Override
public void onPause() {
    super.onPause();
    MapActivity mapActivity = getMapActivity();
    if (mapActivity != null) {
        mapActivity.getMyApplication().getLocationProvider().removeLocationListener(this);
    }
}
Also used : MapActivity(net.osmand.plus.activities.MapActivity)

Example 24 with MapActivity

use of net.osmand.plus.activities.MapActivity in project Osmand by osmandapp.

the class PlanRouteFragment method updateLocation.

@Override
public void updateLocation(Location loc) {
    MapActivity mapActivity = getMapActivity();
    if (mapActivity != null) {
        final Location location = mapActivity.getMyApplication().getLocationProvider().getLastStaleKnownLocation();
        boolean newLocation = (this.location == null && location != null) || location == null;
        boolean locationChanged = this.location != null && location != null && this.location.getLatitude() != location.getLatitude() && this.location.getLongitude() != location.getLongitude();
        boolean farEnough = locationChanged && MapUtils.getDistance(this.location.getLatitude(), this.location.getLongitude(), location.getLatitude(), location.getLongitude()) >= MIN_DISTANCE_FOR_RECALCULATE;
        if (newLocation || farEnough) {
            mapActivity.getMyApplication().runInUIThread(new Runnable() {

                @Override
                public void run() {
                    PlanRouteFragment.this.location = location;
                    adapter.reloadData();
                    try {
                        adapter.notifyDataSetChanged();
                    } catch (Exception e) {
                    // to avoid crash because of:
                    // java.lang.IllegalStateException: Cannot call this method while RecyclerView is computing a layout or scrolling
                    }
                }
            });
        }
    }
}
Also used : MapActivity(net.osmand.plus.activities.MapActivity) Location(net.osmand.Location)

Example 25 with MapActivity

use of net.osmand.plus.activities.MapActivity in project Osmand by osmandapp.

the class RenameMarkerBottomSheetDialogFragment method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final MapActivity mapActivity = (MapActivity) getActivity();
    final boolean portrait = AndroidUiHelper.isOrientationPortrait(getActivity());
    final boolean nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls();
    final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
    final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_rename_marker_bottom_sheet_dialog, container);
    LinearLayout contentLayout = (LinearLayout) mainView.findViewById(R.id.content_linear_layout);
    int layoutRes = Build.VERSION.SDK_INT > Build.VERSION_CODES.ICE_CREAM_SANDWICH ? R.layout.markers_track_name_text_field_box : R.layout.markers_track_name_edit_text;
    contentLayout.addView(getLayoutInflater().inflate(layoutRes, contentLayout, false), 1);
    View textBox = mainView.findViewById(R.id.name_text_box);
    if (portrait) {
        AndroidUtils.setBackground(getActivity(), mainView, nightMode, R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark);
    }
    final EditText nameEditText = (EditText) mainView.findViewById(R.id.name_edit_text);
    if (nightMode) {
        nameEditText.setTextColor(ContextCompat.getColor(mapActivity, R.color.color_white));
        if (textBox instanceof TextInputLayout) {
            ((TextInputLayout) textBox).setHintTextAppearance(R.style.TextAppearance_App_DarkTextInputLayout);
        } else if (textBox instanceof OsmandTextFieldBoxes) {
            ((OsmandTextFieldBoxes) textBox).setPrimaryColor(ContextCompat.getColor(mapActivity, R.color.color_dialog_buttons_dark));
        }
    }
    nameEditText.setText(marker.getName(mapActivity));
    nameEditText.requestFocus();
    final InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, InputMethodManager.HIDE_IMPLICIT_ONLY);
    if (textBox instanceof OsmandTextFieldBoxes) {
        ((OsmandTextFieldBoxes) textBox).activate(true);
    }
    mainView.findViewById(R.id.save_button).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            String name = nameEditText.getText().toString();
            if (name.replaceAll("\\s", "").length() > 0) {
                marker.setName(name);
                mapActivity.getMyApplication().getMapMarkersHelper().updateMapMarker(marker, true);
                dismiss();
            } else {
                nameEditText.setError(getString(R.string.wrong_input));
            }
        }
    });
    mainView.findViewById(R.id.close_button).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            dismiss();
        }
    });
    final int screenHeight = AndroidUtils.getScreenHeight(getActivity());
    final int statusBarHeight = AndroidUtils.getStatusBarHeight(getActivity());
    final int navBarHeight = AndroidUtils.getNavBarHeight(getActivity());
    mainView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

        boolean dimensSet;

        @Override
        public void onGlobalLayout() {
            if (!dimensSet) {
                final View scrollView = mainView.findViewById(R.id.rename_marker_scroll_view);
                int scrollViewHeight = scrollView.getHeight();
                int dividerHeight = AndroidUtils.dpToPx(getContext(), 1);
                int cancelButtonHeight = getContext().getResources().getDimensionPixelSize(R.dimen.bottom_sheet_cancel_button_height);
                int spaceForScrollView = screenHeight - statusBarHeight - navBarHeight - dividerHeight - cancelButtonHeight;
                if (scrollViewHeight > spaceForScrollView) {
                    scrollView.getLayoutParams().height = spaceForScrollView;
                    scrollView.requestLayout();
                }
                if (!portrait) {
                    if (screenHeight - statusBarHeight - mainView.getHeight() >= AndroidUtils.dpToPx(getActivity(), 8)) {
                        AndroidUtils.setBackground(getActivity(), mainView, nightMode, R.drawable.bg_bottom_sheet_topsides_landscape_light, R.drawable.bg_bottom_sheet_topsides_landscape_dark);
                    } else {
                        AndroidUtils.setBackground(getActivity(), mainView, nightMode, R.drawable.bg_bottom_sheet_sides_landscape_light, R.drawable.bg_bottom_sheet_sides_landscape_dark);
                    }
                }
                dimensSet = true;
            }
            final Window window = getDialog().getWindow();
            WindowManager.LayoutParams params = window.getAttributes();
            params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
            params.gravity = Gravity.BOTTOM;
            window.setAttributes(params);
        }
    });
    return mainView;
}
Also used : EditText(android.widget.EditText) Window(android.view.Window) InputMethodManager(android.view.inputmethod.InputMethodManager) View(android.view.View) ContextThemeWrapper(android.view.ContextThemeWrapper) OsmandTextFieldBoxes(net.osmand.plus.widgets.OsmandTextFieldBoxes) TextInputLayout(android.support.design.widget.TextInputLayout) ViewTreeObserver(android.view.ViewTreeObserver) LinearLayout(android.widget.LinearLayout) MapActivity(net.osmand.plus.activities.MapActivity) Nullable(android.support.annotation.Nullable)

Aggregations

MapActivity (net.osmand.plus.activities.MapActivity)85 View (android.view.View)39 ImageView (android.widget.ImageView)28 TextView (android.widget.TextView)28 RecyclerView (android.support.v7.widget.RecyclerView)15 OsmandMapTileView (net.osmand.plus.views.OsmandMapTileView)14 AlertDialog (android.support.v7.app.AlertDialog)12 Nullable (android.support.annotation.Nullable)11 DialogInterface (android.content.DialogInterface)10 AdapterView (android.widget.AdapterView)9 LatLon (net.osmand.data.LatLon)9 OsmandApplication (net.osmand.plus.OsmandApplication)9 Bundle (android.os.Bundle)7 Button (android.widget.Button)7 EditText (android.widget.EditText)7 ImageButton (android.widget.ImageButton)7 FavouritePoint (net.osmand.data.FavouritePoint)7 Fragment (android.support.v4.app.Fragment)6 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)6 ViewTreeObserver (android.view.ViewTreeObserver)6