Search in sources :

Example 66 with MapActivity

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

the class SaveAsTrackBottomSheetDialogFragment method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    MapActivity mapActivity = (MapActivity) getActivity();
    portrait = AndroidUiHelper.isOrientationPortrait(getActivity());
    final boolean nightMode = !getMyApplication().getSettings().isLightContent();
    final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
    final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_marker_save_as_track_bottom_sheet_dialog, container);
    LinearLayout contentLayout = (LinearLayout) mainView.findViewById(R.id.content_linear_layout);
    int layoutRes;
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        layoutRes = R.layout.markers_track_name_text_field_box;
    } else {
        layoutRes = R.layout.markers_track_name_edit_text;
    }
    contentLayout.addView(getLayoutInflater().inflate(layoutRes, contentLayout, false), 2);
    if (portrait) {
        AndroidUtils.setBackground(getActivity(), mainView, nightMode, R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark);
    }
    View textBox = mainView.findViewById(R.id.name_text_box);
    if (nightMode) {
        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));
        }
    }
    final File dir = mapActivity.getMyApplication().getAppPath(IndexConstants.GPX_INDEX_DIR + "/map markers");
    if (!dir.exists()) {
        dir.mkdirs();
    }
    Date date = new Date();
    final String suggestedName = mapActivity.getString(R.string.markers) + "_" + DateFormat.format("yyyy-MM-dd", date).toString();
    String displayedName = suggestedName;
    File fout = new File(dir, suggestedName + GPX_SUFFIX);
    int ind = 1;
    while (fout.exists()) {
        displayedName = suggestedName + "_" + (++ind);
        fout = new File(dir, displayedName + GPX_SUFFIX);
    }
    final EditText nameEditText = (EditText) mainView.findViewById(R.id.name_edit_text);
    nameEditText.setText(displayedName);
    if (textBox instanceof OsmandTextFieldBoxes) {
        ((OsmandTextFieldBoxes) textBox).activate(true);
    }
    mainView.findViewById(R.id.save_button).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (listener != null) {
                listener.saveGpx(nameEditText.getText().toString());
            }
            dismiss();
        }
    });
    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.marker_save_as_track_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() >= getResources().getDimension(R.dimen.bottom_sheet_content_padding_small)) {
                        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) View(android.view.View) Date(java.util.Date) ContextThemeWrapper(android.view.ContextThemeWrapper) OsmandTextFieldBoxes(net.osmand.plus.widgets.OsmandTextFieldBoxes) TextInputLayout(android.support.design.widget.TextInputLayout) File(java.io.File) ViewTreeObserver(android.view.ViewTreeObserver) LinearLayout(android.widget.LinearLayout) MapActivity(net.osmand.plus.activities.MapActivity) Nullable(android.support.annotation.Nullable)

Example 67 with MapActivity

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

the class MapMultiSelectionMenuFragment method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    menu = ((MapActivity) getActivity()).getContextMenu().getMultiSelectionMenu();
    view = inflater.inflate(R.layout.menu_obj_selection_fragment, container, false);
    if (menu.isLandscapeLayout()) {
        AndroidUtils.setBackground(view.getContext(), view, !menu.isLight(), R.drawable.multi_selection_menu_bg_light_land, R.drawable.multi_selection_menu_bg_dark_land);
    } else {
        AndroidUtils.setBackground(view.getContext(), view.findViewById(R.id.cancel_row), !menu.isLight(), R.color.ctx_menu_bg_light, R.color.ctx_menu_bg_dark);
    }
    final ListView listView = (ListView) view.findViewById(R.id.list);
    if (menu.isLandscapeLayout() && Build.VERSION.SDK_INT >= 21) {
        AndroidUtils.addStatusBarPadding21v(getActivity(), listView);
    }
    listAdapter = createAdapter();
    listAdapter.setListener(this);
    if (!menu.isLandscapeLayout()) {
        final Context context = getContext();
        FrameLayout paddingView = new FrameLayout(context);
        paddingView.setLayoutParams(new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT, getPaddingViewHeight()));
        paddingView.setClickable(true);
        paddingView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                dismissMenu();
            }
        });
        FrameLayout shadowContainer = new FrameLayout(context);
        shadowContainer.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT, Gravity.BOTTOM));
        ImageView shadow = new ImageView(context);
        shadow.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.bg_shadow_onmap));
        shadow.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT, Gravity.BOTTOM));
        shadow.setScaleType(ImageView.ScaleType.FIT_XY);
        shadowContainer.addView(shadow);
        paddingView.addView(shadowContainer);
        listView.addHeaderView(paddingView);
        view.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

            @Override
            public void onGlobalLayout() {
                float titleHeight = getResources().getDimension(R.dimen.multi_selection_header_height);
                int maxHeight = (int) (titleHeight);
                for (int i = 0; i < 3 && i < listAdapter.getCount(); i++) {
                    View childView = listAdapter.getView(0, null, (ListView) view.findViewById(R.id.list));
                    childView.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
                    maxHeight += childView.getMeasuredHeight();
                }
                listView.setSelectionFromTop(0, -maxHeight);
                ViewTreeObserver obs = view.getViewTreeObserver();
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                    obs.removeOnGlobalLayoutListener(this);
                } else {
                    obs.removeGlobalOnLayoutListener(this);
                }
            }
        });
        ((ObservableListView) listView).setScrollViewCallbacks(new ObservableScrollViewCallbacks() {

            boolean initialScroll = true;

            int minHeight = getResources().getDimensionPixelSize(R.dimen.multi_selection_header_height) + getResources().getDimensionPixelSize(R.dimen.list_item_height);

            @Override
            public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) {
                if (scrollY <= minHeight && !initialScroll) {
                    dismissMenu();
                }
            }

            @Override
            public void onDownMotionEvent() {
                initialScroll = false;
            }

            @Override
            public void onUpOrCancelMotionEvent(ScrollState scrollState) {
            }
        });
    }
    listView.setAdapter(listAdapter);
    View headerView = inflater.inflate(R.layout.menu_obj_selection_header, listView, false);
    if (!menu.isLandscapeLayout()) {
        AndroidUtils.setBackground(getContext(), headerView, !menu.isLight(), R.color.ctx_menu_bg_light, R.color.ctx_menu_bg_dark);
    }
    headerView.setOnClickListener(null);
    listView.addHeaderView(headerView);
    view.findViewById(R.id.divider).setBackgroundColor(ContextCompat.getColor(getContext(), menu.isLight() ? R.color.multi_selection_menu_divider_light : R.color.multi_selection_menu_divider_dark));
    ((TextView) view.findViewById(R.id.cancel_row_text)).setTextColor(ContextCompat.getColor(getContext(), menu.isLight() ? R.color.multi_selection_menu_close_btn_light : R.color.multi_selection_menu_close_btn_dark));
    view.findViewById(R.id.cancel_row).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            dismissMenu();
        }
    });
    return view;
}
Also used : Context(android.content.Context) AbsListView(android.widget.AbsListView) ObservableScrollViewCallbacks(com.github.ksoichiro.android.observablescrollview.ObservableScrollViewCallbacks) ImageView(android.widget.ImageView) View(android.view.View) AbsListView(android.widget.AbsListView) TextView(android.widget.TextView) ListView(android.widget.ListView) ObservableListView(com.github.ksoichiro.android.observablescrollview.ObservableListView) ObservableListView(com.github.ksoichiro.android.observablescrollview.ObservableListView) AbsListView(android.widget.AbsListView) ListView(android.widget.ListView) ObservableListView(com.github.ksoichiro.android.observablescrollview.ObservableListView) FrameLayout(android.widget.FrameLayout) ScrollState(com.github.ksoichiro.android.observablescrollview.ScrollState) TextView(android.widget.TextView) ImageView(android.widget.ImageView) ViewTreeObserver(android.view.ViewTreeObserver) MapActivity(net.osmand.plus.activities.MapActivity) Nullable(android.support.annotation.Nullable)

Example 68 with MapActivity

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

the class MapMarkerSelectionFragment method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Bundle bundle = null;
    if (getArguments() != null) {
        bundle = getArguments();
    } else if (savedInstanceState != null) {
        bundle = savedInstanceState;
    }
    if (bundle != null) {
        target = bundle.getBoolean(TARGET_KEY);
        intermediate = bundle.getBoolean(INTERMEDIATE_KEY);
    }
    MapActivity mapActivity = getMapActivity();
    OsmandApplication app = getMyApplication();
    if (mapActivity != null) {
        MapRouteInfoMenu routeInfoMenu = mapActivity.getMapLayers().getMapControlsLayer().getMapRouteInfoMenu();
        onClickListener = routeInfoMenu.getOnMarkerSelectListener();
        screenOrientation = DashLocationFragment.getScreenOrientation(mapActivity);
        MapViewTrackingUtilities trackingUtils = mapActivity.getMapViewTrackingUtilities();
        if (trackingUtils != null) {
            Float head = trackingUtils.getHeading();
            float mapRotation = mapActivity.getMapRotate();
            LatLon mw = mapActivity.getMapLocation();
            Location l = trackingUtils.getMyLocation();
            boolean mapLinked = trackingUtils.isMapLinkedToLocation() && l != null;
            LatLon myLoc = l == null ? null : new LatLon(l.getLatitude(), l.getLongitude());
            useCenter = !mapLinked;
            loc = (useCenter ? mw : myLoc);
            if (useCenter) {
                heading = -mapRotation;
            } else {
                heading = head;
            }
        }
    }
    nightMode = !app.getSettings().isLightContent();
    View view = inflater.inflate(R.layout.map_marker_selection_fragment, container, false);
    ImageButton closeButton = (ImageButton) view.findViewById(R.id.closeButton);
    closeButton.setImageDrawable(getMyApplication().getIconsCache().getIcon(R.drawable.ic_action_mode_back));
    closeButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            dismiss();
        }
    });
    ListView listView = (ListView) view.findViewById(android.R.id.list);
    final ArrayAdapter<MapMarker> adapter = new MapMarkersListAdapter();
    List<MapMarker> markers = getMyApplication().getMapMarkersHelper().getMapMarkers();
    if (markers.size() > 0) {
        for (MapMarker marker : markers) {
            adapter.add(marker);
        }
    }
    listView.setAdapter(adapter);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (onClickListener != null) {
                onClickListener.onSelect(position, target, intermediate);
            }
            dismiss();
        }
    });
    return view;
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) MapMarker(net.osmand.plus.MapMarkersHelper.MapMarker) Bundle(android.os.Bundle) MapViewTrackingUtilities(net.osmand.plus.base.MapViewTrackingUtilities) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) LatLon(net.osmand.data.LatLon) ImageButton(android.widget.ImageButton) MapRouteInfoMenu(net.osmand.plus.mapcontextmenu.other.MapRouteInfoMenu) ListView(android.widget.ListView) AdapterView(android.widget.AdapterView) MapActivity(net.osmand.plus.activities.MapActivity) Location(net.osmand.Location) Nullable(android.support.annotation.Nullable)

Example 69 with MapActivity

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

the class MapMarkersDialogFragment method createSaveAsTrackFragmentListener.

private MarkerSaveAsTrackFragmentListener createSaveAsTrackFragmentListener() {
    return new MarkerSaveAsTrackFragmentListener() {

        final MapActivity mapActivity = getMapActivity();

        @Override
        public void saveGpx(final String fileName) {
            final String gpxPath = mapActivity.getMyApplication().getMapMarkersHelper().generateGpx(fileName);
            snackbar = Snackbar.make(viewPager, fileName + " " + getString(R.string.is_saved) + ".", Snackbar.LENGTH_LONG).setAction(R.string.shared_string_show, new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    Intent intent = new Intent(mapActivity, getMyApplication().getAppCustomization().getTrackActivity());
                    intent.putExtra(TrackActivity.TRACK_FILE_NAME, gpxPath);
                    intent.putExtra(TrackActivity.OPEN_POINTS_TAB, true);
                    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(intent);
                }
            });
            AndroidUtils.setSnackbarTextColor(snackbar, R.color.color_dialog_buttons_dark);
            snackbar.show();
        }
    };
}
Also used : MarkerSaveAsTrackFragmentListener(net.osmand.plus.mapmarkers.SaveAsTrackBottomSheetDialogFragment.MarkerSaveAsTrackFragmentListener) Intent(android.content.Intent) View(android.view.View) BottomNavigationView(android.support.design.widget.BottomNavigationView) MapActivity(net.osmand.plus.activities.MapActivity)

Example 70 with MapActivity

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

the class MapMarkersHistoryFragment method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    final boolean night = !app.getSettings().isLightContent();
    final MapActivity mapActivity = (MapActivity) getActivity();
    backgroundPaint.setColor(ContextCompat.getColor(getActivity(), night ? R.color.dashboard_divider_dark : R.color.dashboard_divider_light));
    backgroundPaint.setStyle(Paint.Style.FILL_AND_STROKE);
    backgroundPaint.setAntiAlias(true);
    iconPaint.setAntiAlias(true);
    iconPaint.setFilterBitmap(true);
    iconPaint.setDither(true);
    textPaint.setTextSize(getResources().getDimension(R.dimen.default_desc_text_size));
    textPaint.setFakeBoldText(true);
    textPaint.setAntiAlias(true);
    final String delStr = getString(R.string.shared_string_delete).toUpperCase();
    final String activateStr = getString(R.string.local_index_mi_restore).toUpperCase();
    Rect bounds = new Rect();
    textPaint.getTextBounds(activateStr, 0, activateStr.length(), bounds);
    final int activateStrWidth = bounds.width();
    final int textHeight = bounds.height();
    Fragment historyMarkerMenuFragment = mapActivity.getSupportFragmentManager().findFragmentByTag(HistoryMarkerMenuBottomSheetDialogFragment.TAG);
    if (historyMarkerMenuFragment != null) {
        ((HistoryMarkerMenuBottomSheetDialogFragment) historyMarkerMenuFragment).setListener(createHistoryMarkerMenuListener());
    }
    final View mainView = inflater.inflate(R.layout.fragment_map_markers_history, container, false);
    final EmptyStateRecyclerView recyclerView = (EmptyStateRecyclerView) mainView.findViewById(R.id.list);
    recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
    ItemTouchHelper.SimpleCallback simpleItemTouchCallback = new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) {

        private float marginSides = getResources().getDimension(R.dimen.list_content_padding);

        private Bitmap deleteBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_action_delete_dark);

        private Bitmap resetBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_action_reset_to_default_dark);

        private boolean iconHidden;

        @Override
        public int getSwipeDirs(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
            if (viewHolder instanceof MapMarkerHeaderViewHolder) {
                return 0;
            }
            return super.getSwipeDirs(recyclerView, viewHolder);
        }

        @Override
        public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
            return false;
        }

        @Override
        public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
            if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE && viewHolder instanceof MapMarkerItemViewHolder) {
                if (!iconHidden && isCurrentlyActive) {
                    ((MapMarkerItemViewHolder) viewHolder).optionsBtn.setVisibility(View.GONE);
                    iconHidden = true;
                }
                View itemView = viewHolder.itemView;
                int colorIcon;
                int colorText;
                if (Math.abs(dX) > itemView.getWidth() / 2) {
                    colorIcon = R.color.map_widget_blue;
                    colorText = R.color.map_widget_blue;
                } else {
                    colorIcon = night ? 0 : R.color.icon_color;
                    colorText = R.color.dashboard_subheader_text_light;
                }
                if (colorIcon != 0) {
                    iconPaint.setColorFilter(new PorterDuffColorFilter(ContextCompat.getColor(getActivity(), colorIcon), PorterDuff.Mode.SRC_IN));
                }
                textPaint.setColor(ContextCompat.getColor(getActivity(), colorText));
                float textMarginTop = ((float) itemView.getHeight() - (float) textHeight) / 2;
                if (dX > 0) {
                    c.drawRect(itemView.getLeft(), itemView.getTop(), dX, itemView.getBottom(), backgroundPaint);
                    float iconMarginTop = ((float) itemView.getHeight() - (float) deleteBitmap.getHeight()) / 2;
                    c.drawBitmap(deleteBitmap, itemView.getLeft() + marginSides, itemView.getTop() + iconMarginTop, iconPaint);
                    c.drawText(delStr, itemView.getLeft() + 2 * marginSides + deleteBitmap.getWidth(), itemView.getTop() + textMarginTop + textHeight, textPaint);
                } else {
                    c.drawRect(itemView.getRight() + dX, itemView.getTop(), itemView.getRight(), itemView.getBottom(), backgroundPaint);
                    float iconMarginTop = ((float) itemView.getHeight() - (float) resetBitmap.getHeight()) / 2;
                    c.drawBitmap(resetBitmap, itemView.getRight() - resetBitmap.getWidth() - marginSides, itemView.getTop() + iconMarginTop, iconPaint);
                    c.drawText(activateStr, itemView.getRight() - resetBitmap.getWidth() - 2 * marginSides - activateStrWidth, itemView.getTop() + textMarginTop + textHeight, textPaint);
                }
            }
            super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
        }

        @Override
        public void clearView(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
            if (viewHolder instanceof MapMarkerItemViewHolder) {
                ((MapMarkerItemViewHolder) viewHolder).optionsBtn.setVisibility(View.VISIBLE);
                iconHidden = false;
            }
            super.clearView(recyclerView, viewHolder);
        }

        @Override
        public void onSwiped(RecyclerView.ViewHolder viewHolder, final int direction) {
            final int pos = viewHolder.getAdapterPosition();
            Object item = adapter.getItem(pos);
            if (item instanceof MapMarker) {
                final MapMarker marker = (MapMarker) item;
                int snackbarStringRes;
                if (direction == ItemTouchHelper.LEFT) {
                    app.getMapMarkersHelper().restoreMarkerFromHistory((MapMarker) item, 0);
                    snackbarStringRes = R.string.marker_moved_to_active;
                } else {
                    app.getMapMarkersHelper().removeMarker((MapMarker) item);
                    snackbarStringRes = R.string.item_removed;
                }
                snackbar = Snackbar.make(viewHolder.itemView, snackbarStringRes, Snackbar.LENGTH_LONG).setAction(R.string.shared_string_undo, new View.OnClickListener() {

                    @Override
                    public void onClick(View view) {
                        if (direction == ItemTouchHelper.LEFT) {
                            app.getMapMarkersHelper().moveMapMarkerToHistory(marker);
                        } else {
                            app.getMapMarkersHelper().addMarker(marker);
                        }
                    }
                });
                AndroidUtils.setSnackbarTextColor(snackbar, R.color.color_dialog_buttons_dark);
                snackbar.show();
            }
        }
    };
    ItemTouchHelper itemTouchHelper = new ItemTouchHelper(simpleItemTouchCallback);
    itemTouchHelper.attachToRecyclerView(recyclerView);
    adapter = new MapMarkersHistoryAdapter(mapActivity.getMyApplication());
    adapter.setAdapterListener(new MapMarkersHistoryAdapter.MapMarkersHistoryAdapterListener() {

        @Override
        public void onItemClick(View view) {
            int pos = recyclerView.getChildAdapterPosition(view);
            if (pos == RecyclerView.NO_POSITION) {
                return;
            }
            Object item = adapter.getItem(pos);
            if (item instanceof MapMarker) {
                MapMarker marker = (MapMarker) item;
                HistoryMarkerMenuBottomSheetDialogFragment fragment = new HistoryMarkerMenuBottomSheetDialogFragment();
                fragment.setUsedOnMap(false);
                Bundle arguments = new Bundle();
                arguments.putInt(HistoryMarkerMenuBottomSheetDialogFragment.MARKER_POSITION, pos);
                arguments.putString(HistoryMarkerMenuBottomSheetDialogFragment.MARKER_NAME, marker.getName(mapActivity));
                arguments.putInt(HistoryMarkerMenuBottomSheetDialogFragment.MARKER_COLOR_INDEX, marker.colorIndex);
                arguments.putLong(HistoryMarkerMenuBottomSheetDialogFragment.MARKER_VISITED_DATE, marker.visitedDate);
                fragment.setArguments(arguments);
                fragment.setListener(createHistoryMarkerMenuListener());
                fragment.show(mapActivity.getSupportFragmentManager(), HistoryMarkerMenuBottomSheetDialogFragment.TAG);
            }
        }
    });
    final View emptyView = mainView.findViewById(R.id.empty_view);
    ImageView emptyImageView = (ImageView) emptyView.findViewById(R.id.empty_state_image_view);
    if (Build.VERSION.SDK_INT >= 18) {
        emptyImageView.setImageResource(night ? R.drawable.ic_empty_state_marker_history_night : R.drawable.ic_empty_state_marker_history_day);
    } else {
        emptyImageView.setVisibility(View.INVISIBLE);
    }
    recyclerView.setEmptyView(emptyView);
    recyclerView.setAdapter(adapter);
    app.getMapMarkersHelper().addListener(this);
    return mainView;
}
Also used : MapMarker(net.osmand.plus.MapMarkersHelper.MapMarker) EmptyStateRecyclerView(net.osmand.plus.widgets.EmptyStateRecyclerView) MapMarkerItemViewHolder(net.osmand.plus.mapmarkers.adapters.MapMarkerItemViewHolder) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) Fragment(android.support.v4.app.Fragment) ItemTouchHelper(android.support.v7.widget.helper.ItemTouchHelper) Bitmap(android.graphics.Bitmap) MapMarkerItemViewHolder(net.osmand.plus.mapmarkers.adapters.MapMarkerItemViewHolder) MapMarkerHeaderViewHolder(net.osmand.plus.mapmarkers.adapters.MapMarkerHeaderViewHolder) ImageView(android.widget.ImageView) MapActivity(net.osmand.plus.activities.MapActivity) Rect(android.graphics.Rect) Bundle(android.os.Bundle) Canvas(android.graphics.Canvas) MapMarkerHeaderViewHolder(net.osmand.plus.mapmarkers.adapters.MapMarkerHeaderViewHolder) EmptyStateRecyclerView(net.osmand.plus.widgets.EmptyStateRecyclerView) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) Paint(android.graphics.Paint) MapMarkersHistoryAdapter(net.osmand.plus.mapmarkers.adapters.MapMarkersHistoryAdapter) EmptyStateRecyclerView(net.osmand.plus.widgets.EmptyStateRecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) 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