Search in sources :

Example 11 with OsmandApplication

use of net.osmand.plus.OsmandApplication in project Osmand by osmandapp.

the class MenuBottomSheetDialogFragment method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
    createMenuItems(savedInstanceState);
    OsmandApplication app = getMyApplication();
    final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
    View mainView = View.inflate(new ContextThemeWrapper(app, themeRes), R.layout.bottom_sheet_menu_base, null);
    if (useScrollableItemsContainer()) {
        itemsContainer = (LinearLayout) mainView.findViewById(R.id.scrollable_items_container);
    } else {
        mainView.findViewById(R.id.scroll_view).setVisibility(View.GONE);
        itemsContainer = (LinearLayout) mainView.findViewById(R.id.non_scrollable_items_container);
        itemsContainer.setVisibility(View.VISIBLE);
    }
    for (BaseBottomSheetItem item : items) {
        item.inflate(app, itemsContainer, nightMode);
    }
    int bottomDividerColorId = getBottomDividerColorId();
    if (bottomDividerColorId != DEFAULT_VALUE) {
        mainView.findViewById(R.id.bottom_row_divider).setBackgroundColor(getResolvedColor(bottomDividerColorId));
    }
    mainView.findViewById(R.id.dismiss_button).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            onDismissButtonClickAction();
            dismiss();
        }
    });
    ((TextView) mainView.findViewById(R.id.dismiss_button_text)).setText(getDismissButtonTextId());
    int rightBottomButtonTextId = getRightBottomButtonTextId();
    if (rightBottomButtonTextId != DEFAULT_VALUE) {
        View buttonsDivider = mainView.findViewById(R.id.bottom_buttons_divider);
        buttonsDivider.setVisibility(View.VISIBLE);
        if (bottomDividerColorId != DEFAULT_VALUE) {
            buttonsDivider.setBackgroundColor(getResolvedColor(bottomDividerColorId));
        }
        View rightButton = mainView.findViewById(R.id.right_bottom_button);
        rightButton.setVisibility(View.VISIBLE);
        rightButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                onRightBottomButtonClick();
            }
        });
        ((TextView) rightButton.findViewById(R.id.right_bottom_button_text)).setText(rightBottomButtonTextId);
    }
    setupHeightAndBackground(mainView);
    return mainView;
}
Also used : BaseBottomSheetItem(net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem) OsmandApplication(net.osmand.plus.OsmandApplication) ContextThemeWrapper(android.view.ContextThemeWrapper) TextView(android.widget.TextView) View(android.view.View) TextView(android.widget.TextView) Nullable(android.support.annotation.Nullable)

Example 12 with OsmandApplication

use of net.osmand.plus.OsmandApplication in project Osmand by osmandapp.

the class FailSafeFuntions method enterRoutingMode.

public static void enterRoutingMode(MapActivity ma, GPXRouteParamsBuilder gpxRoute) {
    OsmandApplication app = ma.getMyApplication();
    ma.getMapViewTrackingUtilities().backToLocationImpl();
    RoutingHelper routingHelper = app.getRoutingHelper();
    if (gpxRoute == null) {
        app.getSettings().FOLLOW_THE_GPX_ROUTE.set(null);
    }
    routingHelper.setGpxParams(gpxRoute);
    if (app.getTargetPointsHelper().getPointToStart() == null) {
        app.getTargetPointsHelper().setStartPoint(null, false, null);
    }
    app.getSettings().FOLLOW_THE_ROUTE.set(true);
    routingHelper.setFollowingMode(true);
    app.getTargetPointsHelper().updateRouteAndRefresh(true);
    app.initVoiceCommandPlayer(ma, routingHelper.getAppMode(), true, null, false, false);
    if (ma.getDashboard().isVisible()) {
        ma.getDashboard().hideDashboard();
    }
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) RoutingHelper(net.osmand.plus.routing.RoutingHelper)

Example 13 with OsmandApplication

use of net.osmand.plus.OsmandApplication in project Osmand by osmandapp.

the class FailSafeFuntions method restoreRoutingMode.

public static void restoreRoutingMode(final MapActivity ma) {
    final OsmandApplication app = ma.getMyApplication();
    final OsmandSettings settings = app.getSettings();
    final Handler uiHandler = new Handler();
    final String gpxPath = settings.FOLLOW_THE_GPX_ROUTE.get();
    final TargetPointsHelper targetPoints = app.getTargetPointsHelper();
    final TargetPoint pointToNavigate = targetPoints.getPointToNavigate();
    if (pointToNavigate == null && gpxPath == null) {
        notRestoreRoutingMode(ma, app);
    } else {
        quitRouteRestoreDialog = false;
        Runnable encapsulate = new Runnable() {

            int delay = 7;

            Runnable delayDisplay = null;

            @Override
            public void run() {
                AlertDialog.Builder builder = new AlertDialog.Builder(ma);
                final TextView tv = new TextView(ma);
                tv.setText(ma.getString(R.string.continue_follow_previous_route_auto, delay + ""));
                tv.setPadding(7, 5, 7, 5);
                builder.setView(tv);
                builder.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        quitRouteRestoreDialog = true;
                        restoreRoutingModeInner();
                    }
                });
                builder.setNegativeButton(R.string.shared_string_no, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        quitRouteRestoreDialog = true;
                        notRestoreRoutingMode(ma, app);
                    }
                });
                final AlertDialog dlg = builder.show();
                dlg.setOnDismissListener(new OnDismissListener() {

                    @Override
                    public void onDismiss(DialogInterface dialog) {
                        quitRouteRestoreDialog = true;
                    }
                });
                dlg.setOnCancelListener(new OnCancelListener() {

                    @Override
                    public void onCancel(DialogInterface dialog) {
                        quitRouteRestoreDialog = true;
                    }
                });
                delayDisplay = new Runnable() {

                    @Override
                    public void run() {
                        if (!quitRouteRestoreDialog) {
                            delay--;
                            tv.setText(ma.getString(R.string.continue_follow_previous_route_auto, delay + ""));
                            if (delay <= 0) {
                                try {
                                    if (dlg.isShowing() && !quitRouteRestoreDialog) {
                                        dlg.dismiss();
                                    }
                                    quitRouteRestoreDialog = true;
                                    restoreRoutingModeInner();
                                } catch (Exception e) {
                                    // swalow view not attached exception
                                    log.error(e.getMessage() + "", e);
                                }
                            } else {
                                uiHandler.postDelayed(delayDisplay, 1000);
                            }
                        }
                    }
                };
                delayDisplay.run();
            }

            private void restoreRoutingModeInner() {
                AsyncTask<String, Void, GPXFile> task = new AsyncTask<String, Void, GPXFile>() {

                    @Override
                    protected GPXFile doInBackground(String... params) {
                        if (gpxPath != null) {
                            // Reverse also should be stored ?
                            GPXFile f = GPXUtilities.loadGPXFile(app, new File(gpxPath));
                            if (f.warning != null) {
                                return null;
                            }
                            return f;
                        } else {
                            return null;
                        }
                    }

                    @Override
                    protected void onPostExecute(GPXFile result) {
                        final GPXRouteParamsBuilder gpxRoute;
                        if (result != null) {
                            gpxRoute = new GPXRouteParamsBuilder(result, settings);
                            if (settings.GPX_ROUTE_CALC_OSMAND_PARTS.get()) {
                                gpxRoute.setCalculateOsmAndRouteParts(true);
                            }
                            if (settings.GPX_CALCULATE_RTEPT.get()) {
                                gpxRoute.setUseIntermediatePointsRTE(true);
                            }
                            if (settings.GPX_ROUTE_CALC.get()) {
                                gpxRoute.setCalculateOsmAndRoute(true);
                            }
                        } else {
                            gpxRoute = null;
                        }
                        TargetPoint endPoint = pointToNavigate;
                        if (endPoint == null) {
                            notRestoreRoutingMode(ma, app);
                        } else {
                            enterRoutingMode(ma, gpxRoute);
                        }
                    }
                };
                task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, gpxPath);
            }
        };
        encapsulate.run();
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) OsmandApplication(net.osmand.plus.OsmandApplication) DialogInterface(android.content.DialogInterface) GPXRouteParamsBuilder(net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder) GPXRouteParamsBuilder(net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder) OnDismissListener(android.content.DialogInterface.OnDismissListener) AsyncTask(android.os.AsyncTask) Handler(android.os.Handler) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) OsmandSettings(net.osmand.plus.OsmandSettings) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) TextView(android.widget.TextView) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) TargetPointsHelper(net.osmand.plus.TargetPointsHelper) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) File(java.io.File) OnCancelListener(android.content.DialogInterface.OnCancelListener)

Example 14 with OsmandApplication

use of net.osmand.plus.OsmandApplication in project Osmand by osmandapp.

the class QuickSearchCoordinatesFragment method onCreateView.

@Override
@SuppressLint("PrivateResource")
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final OsmandApplication app = getMyApplication();
    view = inflater.inflate(R.layout.search_advanced_coords, container, false);
    Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar);
    toolbar.setNavigationIcon(app.getIconsCache().getIcon(R.drawable.ic_arrow_back));
    toolbar.setNavigationContentDescription(R.string.access_shared_string_navigate_up);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            dismiss();
        }
    });
    screenOrientation = DashLocationFragment.getScreenOrientation(getActivity());
    myLocation = app.getLocationProvider().getLastKnownLocation();
    currentFormat = app.getSettings().COORDINATES_FORMAT.get();
    latEdit = ((EditText) view.findViewById(R.id.latitudeEditText));
    lonEdit = ((EditText) view.findViewById(R.id.longitudeEditText));
    northingEdit = ((EditText) view.findViewById(R.id.northingEditText));
    eastingEdit = ((EditText) view.findViewById(R.id.eastingEditText));
    zoneEdit = ((EditText) view.findViewById(R.id.zoneEditText));
    olcEdit = ((EditText) view.findViewById(R.id.olcEditText));
    olcInfo = ((TextView) view.findViewById(R.id.olcInfoTextView));
    formatEdit = ((EditText) view.findViewById(R.id.formatEditText));
    String defaultLat = "";
    String defaultZone = "";
    String defaultOlc = "";
    boolean coordinatesApplied = false;
    if (getArguments() != null) {
        String text = getArguments().getString(QUICK_SEARCH_COORDS_TEXT_KEY);
        if (!Algorithms.isEmpty(text)) {
            if (currentFormat == PointDescription.UTM_FORMAT) {
                defaultZone = text.trim();
            } else if (currentFormat == PointDescription.OLC_FORMAT) {
                defaultOlc = text.trim();
            } else {
                defaultLat = text.trim();
            }
        } else {
            double latitude = getArguments().getDouble(QUICK_SEARCH_COORDS_LATITUDE_KEY, Double.NaN);
            double longitude = getArguments().getDouble(QUICK_SEARCH_COORDS_LONGITUDE_KEY, Double.NaN);
            if (!Double.isNaN(latitude) && !Double.isNaN(longitude)) {
                currentLatLon = new LatLon(latitude, longitude);
                applyFormat(currentFormat, true);
                coordinatesApplied = true;
            }
        }
    }
    String latStr = getStringValue(savedInstanceState, QUICK_SEARCH_COORDS_LAT_KEY, defaultLat);
    String lonStr = getStringValue(savedInstanceState, QUICK_SEARCH_COORDS_LON_KEY, "");
    String northingStr = getStringValue(savedInstanceState, QUICK_SEARCH_COORDS_NORTH_KEY, "");
    String eastingStr = getStringValue(savedInstanceState, QUICK_SEARCH_COORDS_EAST_KEY, "");
    String zoneStr = getStringValue(savedInstanceState, QUICK_SEARCH_COORDS_ZONE_KEY, defaultZone);
    String olcStr = getStringValue(savedInstanceState, QUICK_SEARCH_COORDS_OLC_KEY, defaultOlc);
    String olcInfoStr = getStringValue(savedInstanceState, QUICK_SEARCH_COORDS_OLC_INFO_KEY, defaultOlc);
    if (savedInstanceState != null)
        currentFormat = savedInstanceState.getInt(QUICK_SEARCH_COORDS_FORMAT_KEY, -1);
    if (currentFormat == -1)
        currentFormat = getArguments().getInt(QUICK_SEARCH_COORDS_FORMAT_KEY, -1);
    if (currentFormat == -1)
        currentFormat = app.getSettings().COORDINATES_FORMAT.get();
    if (savedInstanceState != null && savedInstanceState.containsKey(QUICK_SEARCH_COORDS_USE_MAP_CENTER_KEY))
        useMapCenter = savedInstanceState.getBoolean(QUICK_SEARCH_COORDS_USE_MAP_CENTER_KEY);
    else if (getArguments().containsKey(QUICK_SEARCH_COORDS_USE_MAP_CENTER_KEY))
        useMapCenter = getArguments().getBoolean(QUICK_SEARCH_COORDS_USE_MAP_CENTER_KEY);
    if (!coordinatesApplied) {
        latEdit.setText(latStr);
        latEdit.setSelection(latStr.length());
        lonEdit.setText(lonStr);
        lonEdit.setSelection(lonStr.length());
        northingEdit.setText(northingStr);
        northingEdit.setSelection(northingStr.length());
        eastingEdit.setText(eastingStr);
        eastingEdit.setSelection(eastingStr.length());
        zoneEdit.setText(zoneStr);
        zoneEdit.setSelection(zoneStr.length());
        olcEdit.setText(olcStr);
        olcEdit.setSelection(olcStr.length());
        olcInfo.setText(olcInfoStr);
    }
    formatEdit.setText(PointDescription.formatToHumanString(app, currentFormat));
    formatEdit.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            new ChooseCoordsFormatDialogFragment().show(getChildFragmentManager(), "ChooseCoordinatesFormatFragment");
        }
    });
    TextWatcher textWatcher = new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            parseLocation();
        }
    };
    latEdit.addTextChangedListener(textWatcher);
    lonEdit.addTextChangedListener(textWatcher);
    northingEdit.addTextChangedListener(textWatcher);
    eastingEdit.addTextChangedListener(textWatcher);
    zoneEdit.addTextChangedListener(textWatcher);
    olcEdit.addTextChangedListener(textWatcher);
    OnEditorActionListener doneListener = new OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                showOnMap();
                return true;
            } else {
                return false;
            }
        }
    };
    lonEdit.setOnEditorActionListener(doneListener);
    zoneEdit.setOnEditorActionListener(doneListener);
    olcEdit.setOnEditorActionListener(doneListener);
    IconsCache ic = app.getIconsCache();
    ((ImageView) view.findViewById(R.id.latitudeImage)).setImageDrawable(ic.getThemedIcon(R.drawable.ic_action_coordinates_latitude));
    ((ImageView) view.findViewById(R.id.longitudeImage)).setImageDrawable(ic.getThemedIcon(R.drawable.ic_action_coordinates_longitude));
    ((ImageView) view.findViewById(R.id.northingImage)).setImageDrawable(ic.getThemedIcon(R.drawable.ic_action_coordinates_latitude));
    ((ImageView) view.findViewById(R.id.eastingImage)).setImageDrawable(ic.getThemedIcon(R.drawable.ic_action_coordinates_longitude));
    ImageButton latitudeClearButton = (ImageButton) view.findViewById(R.id.latitudeClearButton);
    latitudeClearButton.setImageDrawable(ic.getThemedIcon(R.drawable.ic_action_remove_dark));
    latitudeClearButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            latEdit.setText("");
        }
    });
    ImageButton longitudeClearButton = (ImageButton) view.findViewById(R.id.longitudeClearButton);
    longitudeClearButton.setImageDrawable(ic.getThemedIcon(R.drawable.ic_action_remove_dark));
    longitudeClearButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            lonEdit.setText("");
        }
    });
    ImageButton northingClearButton = (ImageButton) view.findViewById(R.id.northingClearButton);
    northingClearButton.setImageDrawable(ic.getThemedIcon(R.drawable.ic_action_remove_dark));
    northingClearButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            northingEdit.setText("");
        }
    });
    ImageButton eastingClearButton = (ImageButton) view.findViewById(R.id.eastingClearButton);
    eastingClearButton.setImageDrawable(ic.getThemedIcon(R.drawable.ic_action_remove_dark));
    eastingClearButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            eastingEdit.setText("");
        }
    });
    ImageButton zoneClearButton = (ImageButton) view.findViewById(R.id.zoneClearButton);
    zoneClearButton.setImageDrawable(ic.getThemedIcon(R.drawable.ic_action_remove_dark));
    zoneClearButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            olcEdit.setText("");
        }
    });
    ImageButton olcClearButton = (ImageButton) view.findViewById(R.id.olcClearButton);
    olcClearButton.setImageDrawable(ic.getThemedIcon(R.drawable.ic_action_remove_dark));
    olcClearButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            olcEdit.setText("");
        }
    });
    ImageButton formatSelectButton = (ImageButton) view.findViewById(R.id.formatSelectButton);
    formatSelectButton.setImageDrawable(ic.getThemedIcon(R.drawable.ic_action_arrow_drop_down));
    formatSelectButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            new ChooseCoordsFormatDialogFragment().show(getChildFragmentManager(), "ChooseCoordinatesFormatFragment");
        }
    });
    coordsView = view.findViewById(R.id.searchListItemLayout);
    view.findViewById(R.id.divider).setVisibility(View.GONE);
    TypedValue outValue = new TypedValue();
    app.getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
    coordsView.setBackgroundResource(outValue.resourceId);
    coordsView.setClickable(true);
    coordsView.findViewById(R.id.toggle_item).setVisibility(View.GONE);
    coordsView.findViewById(R.id.time_icon).setVisibility(View.GONE);
    coordsView.findViewById(R.id.time).setVisibility(View.GONE);
    coordsView.findViewById(R.id.type_name_icon).setVisibility(View.GONE);
    ((ImageView) coordsView.findViewById(R.id.imageView)).setImageDrawable(ic.getIcon(R.drawable.ic_action_world_globe, app.getSettings().isLightContent() ? R.color.osmand_orange : R.color.osmand_orange_dark));
    coordsView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            showOnMap();
        }
    });
    errorView = view.findViewById(R.id.error_item);
    parseLocation();
    updateControlsVisibility();
    return view;
}
Also used : EditText(android.widget.EditText) OsmandApplication(net.osmand.plus.OsmandApplication) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) KeyEvent(android.view.KeyEvent) LatLon(net.osmand.data.LatLon) ImageButton(android.widget.ImageButton) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) TextView(android.widget.TextView) OnEditorActionListener(android.widget.TextView.OnEditorActionListener) IconsCache(net.osmand.plus.IconsCache) ImageView(android.widget.ImageView) Toolbar(android.support.v7.widget.Toolbar) TypedValue(android.util.TypedValue) SuppressLint(android.annotation.SuppressLint)

Example 15 with OsmandApplication

use of net.osmand.plus.OsmandApplication in project Osmand by osmandapp.

the class QuickSearchCoordinatesFragment method startLocationUpdate.

private void startLocationUpdate() {
    OsmandApplication app = getMyApplication();
    app.getLocationProvider().removeCompassListener(app.getLocationProvider().getNavigationInfo());
    app.getLocationProvider().addCompassListener(this);
    app.getLocationProvider().addLocationListener(this);
    myLocation = app.getLocationProvider().getLastKnownLocation();
    updateLocation(myLocation);
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication)

Aggregations

OsmandApplication (net.osmand.plus.OsmandApplication)181 View (android.view.View)46 TextView (android.widget.TextView)39 ArrayList (java.util.ArrayList)33 AlertDialog (android.support.v7.app.AlertDialog)32 ImageView (android.widget.ImageView)31 DialogInterface (android.content.DialogInterface)27 OsmandSettings (net.osmand.plus.OsmandSettings)27 LatLon (net.osmand.data.LatLon)25 Intent (android.content.Intent)21 AdapterView (android.widget.AdapterView)19 File (java.io.File)17 OsmandMapTileView (net.osmand.plus.views.OsmandMapTileView)15 Location (net.osmand.Location)13 EditText (android.widget.EditText)12 ContextMenuAdapter (net.osmand.plus.ContextMenuAdapter)12 ArrayAdapter (android.widget.ArrayAdapter)11 ListView (android.widget.ListView)11 ContextMenuItem (net.osmand.plus.ContextMenuItem)11 SelectedGpxFile (net.osmand.plus.GpxSelectionHelper.SelectedGpxFile)11