Search in sources :

Example 76 with MapActivity

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

the class FavoriteDialogs method confirmReplace.

private static void confirmReplace(final Activity activity, final Bundle args, final FavouritesDbHelper helper, final FavouritesAdapter favouritesAdapter, final Dialog[] dlgHolder, int position) {
    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    builder.setTitle(R.string.update_existing);
    final FavouritePoint fp = favouritesAdapter.getItem(position);
    builder.setMessage(activity.getString(R.string.replace_favorite_confirmation, fp.getName()));
    builder.setNegativeButton(R.string.shared_string_no, null);
    builder.setPositiveButton(R.string.shared_string_yes, new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (dlgHolder != null && dlgHolder.length > 0 && dlgHolder[0] != null) {
                dlgHolder[0].dismiss();
            }
            FavouritePoint point = (FavouritePoint) args.getSerializable(KEY_FAVORITE);
            if (helper.editFavourite(fp, point.getLatitude(), point.getLongitude())) {
                if (activity instanceof MapActivity) {
                    ((MapActivity) activity).getContextMenu().show(new LatLon(point.getLatitude(), point.getLongitude()), fp.getPointDescription(), fp);
                }
            }
            if (activity instanceof MapActivity) {
                ((MapActivity) activity).getMapView().refreshMap();
            }
        }
    });
    builder.show();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) LatLon(net.osmand.data.LatLon) FavouritePoint(net.osmand.data.FavouritePoint) DialogInterface(android.content.DialogInterface) OnClickListener(android.content.DialogInterface.OnClickListener) FavouritePoint(net.osmand.data.FavouritePoint) MapActivity(net.osmand.plus.activities.MapActivity)

Example 77 with MapActivity

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

the class FavoriteDialogs method createAddFavouriteDialog.

public static Dialog createAddFavouriteDialog(final Activity activity, final Bundle args) {
    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    builder.setTitle(R.string.favourites_context_menu_edit);
    final View v = activity.getLayoutInflater().inflate(R.layout.favorite_edit_dialog, null, false);
    final FavouritesDbHelper helper = ((OsmandApplication) activity.getApplication()).getFavorites();
    builder.setView(v);
    final EditText editText = (EditText) v.findViewById(R.id.Name);
    final EditText description = (EditText) v.findViewById(R.id.description);
    final AutoCompleteTextView cat = (AutoCompleteTextView) v.findViewById(R.id.Category);
    List<FavoriteGroup> gs = helper.getFavoriteGroups();
    final String[] list = new String[gs.size()];
    for (int i = 0; i < list.length; i++) {
        list[i] = gs.get(i).name;
    }
    cat.setAdapter(new ArrayAdapter<String>(activity, R.layout.list_textview, list));
    if (((OsmandApplication) activity.getApplication()).accessibilityEnabled()) {
        final TextView textButton = (TextView) v.findViewById(R.id.TextButton);
        textButton.setClickable(true);
        textButton.setFocusable(true);
        textButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                AlertDialog.Builder b = new AlertDialog.Builder(activity);
                b.setTitle(R.string.access_category_choice);
                b.setItems(list, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        cat.setText(list[which]);
                    }
                });
                b.setNegativeButton(R.string.shared_string_cancel, null);
                b.show();
            }
        });
    }
    builder.setNegativeButton(R.string.shared_string_cancel, null);
    builder.setNeutralButton(R.string.update_existing, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            // Don't use showDialog because it is impossible to refresh favorite items list
            Dialog dlg = createReplaceFavouriteDialog(activity, args);
            if (dlg != null) {
                dlg.show();
            }
        // mapActivity.showDialog(DIALOG_REPLACE_FAVORITE);
        }
    });
    builder.setPositiveButton(R.string.shared_string_add, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            final FavouritePoint point = (FavouritePoint) args.getSerializable(KEY_FAVORITE);
            OsmandApplication app = (OsmandApplication) activity.getApplication();
            String categoryStr = cat.getText().toString().trim();
            final FavouritesDbHelper helper = app.getFavorites();
            app.getSettings().LAST_FAV_CATEGORY_ENTERED.set(categoryStr);
            point.setName(editText.getText().toString().trim());
            point.setDescription(description.getText().toString().trim());
            point.setCategory(categoryStr);
            AlertDialog.Builder bld = FavouritesDbHelper.checkDuplicates(point, helper, activity);
            if (bld != null) {
                bld.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        addFavorite(activity, point, helper);
                    }
                });
                bld.show();
            } else {
                addFavorite(activity, point, helper);
            }
        }

        protected void addFavorite(final Activity activity, FavouritePoint point, final FavouritesDbHelper helper) {
            boolean added = helper.addFavourite(point);
            if (added) {
                Toast.makeText(activity, MessageFormat.format(activity.getString(R.string.add_favorite_dialog_favourite_added_template), point.getName()), Toast.LENGTH_SHORT).show();
            }
            if (activity instanceof MapActivity) {
                ((MapActivity) activity).getMapView().refreshMap(true);
            }
        }
    });
    return builder.create();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) EditText(android.widget.EditText) OsmandApplication(net.osmand.plus.OsmandApplication) FavouritePoint(net.osmand.data.FavouritePoint) DialogInterface(android.content.DialogInterface) FavoriteGroup(net.osmand.plus.FavouritesDbHelper.FavoriteGroup) Activity(android.app.Activity) MapActivity(net.osmand.plus.activities.MapActivity) FavouritesDbHelper(net.osmand.plus.FavouritesDbHelper) View(android.view.View) AdapterView(android.widget.AdapterView) AutoCompleteTextView(android.widget.AutoCompleteTextView) TextView(android.widget.TextView) ListView(android.widget.ListView) FavouritePoint(net.osmand.data.FavouritePoint) OnClickListener(android.content.DialogInterface.OnClickListener) Dialog(android.app.Dialog) AlertDialog(android.support.v7.app.AlertDialog) OnClickListener(android.content.DialogInterface.OnClickListener) AutoCompleteTextView(android.widget.AutoCompleteTextView) TextView(android.widget.TextView) AutoCompleteTextView(android.widget.AutoCompleteTextView) MapActivity(net.osmand.plus.activities.MapActivity)

Example 78 with MapActivity

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

the class FavoriteDialogs method createReplaceFavouriteDialog.

public static Dialog createReplaceFavouriteDialog(final Activity activity, final Bundle args) {
    final FavouritesDbHelper helper = ((OsmandApplication) activity.getApplication()).getFavorites();
    final List<FavouritePoint> points = new ArrayList<FavouritePoint>(helper.getFavouritePoints());
    final FavouritesAdapter favouritesAdapter = new FavouritesAdapter(activity, ((OsmandApplication) activity.getApplication()).getFavorites().getFavouritePoints(), false);
    final Dialog[] dlgHolder = new Dialog[1];
    OnItemClickListener click = new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            confirmReplace(activity, args, helper, favouritesAdapter, dlgHolder, position);
        }
    };
    if (activity instanceof MapActivity) {
        favouritesAdapter.updateLocation(((MapActivity) activity).getMapLocation());
    }
    if (points.size() == 0) {
        Toast.makeText(activity, activity.getString(R.string.fav_points_not_exist), Toast.LENGTH_SHORT).show();
        return null;
    }
    return showFavoritesDialog(activity, favouritesAdapter, click, null, dlgHolder, true);
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) FavouritePoint(net.osmand.data.FavouritePoint) OnItemClickListener(android.widget.AdapterView.OnItemClickListener) FavouritesAdapter(net.osmand.plus.activities.FavoritesListFragment.FavouritesAdapter) Dialog(android.app.Dialog) AlertDialog(android.support.v7.app.AlertDialog) ArrayList(java.util.ArrayList) AdapterView(android.widget.AdapterView) FavouritesDbHelper(net.osmand.plus.FavouritesDbHelper) View(android.view.View) AdapterView(android.widget.AdapterView) AutoCompleteTextView(android.widget.AutoCompleteTextView) TextView(android.widget.TextView) ListView(android.widget.ListView) MapActivity(net.osmand.plus.activities.MapActivity)

Example 79 with MapActivity

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

the class DashNavigationFragment method setupNavigation.

public void setupNavigation() {
    View mainView = getView();
    final RoutingHelper routingHelper = getMyApplication().getRoutingHelper();
    getActivity();
    if (!routingHelper.isRouteCalculated() || (!(getActivity() instanceof MapActivity))) {
        (mainView.findViewById(R.id.main_fav)).setVisibility(View.GONE);
        return;
    } else {
        (mainView.findViewById(R.id.main_fav)).setVisibility(View.VISIBLE);
    }
    final MapActivity map = (MapActivity) getActivity();
    LinearLayout favorites = (LinearLayout) mainView.findViewById(R.id.items);
    favorites.removeAllViews();
    LayoutInflater inflater = getActivity().getLayoutInflater();
    View view = inflater.inflate(R.layout.dash_navigation, null, false);
    TextView name = (TextView) view.findViewById(R.id.name);
    ImageView icon = (ImageView) view.findViewById(R.id.icon);
    ImageView cancel = (ImageView) view.findViewById(R.id.cancel);
    ImageView play = (ImageView) view.findViewById(R.id.play);
    name.setText(routingHelper.getGeneralRouteInformation());
    icon.setImageDrawable(getMyApplication().getIconsCache().getIcon(R.drawable.ic_action_start_navigation, R.color.color_myloc_distance));
    cancel.setImageDrawable(getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_action_remove_dark));
    cancel.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            AlertDialog dlg = map.getMapActions().stopNavigationActionConfirm();
            dlg.setOnDismissListener(new DialogInterface.OnDismissListener() {

                @Override
                public void onDismiss(DialogInterface dialog) {
                    setupNavigation();
                    DashWaypointsFragment f = dashboard.getFragmentByClass(DashWaypointsFragment.class);
                    if (f != null) {
                        f.onOpenDash();
                    }
                }
            });
        }
    });
    int nav;
    if (routingHelper.isFollowingMode()) {
        nav = R.string.cancel_navigation;
    } else {
        nav = R.string.cancel_route;
    }
    cancel.setContentDescription(getString(nav));
    updatePlayButton(routingHelper, map, play);
    favorites.addView(view);
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) RoutingHelper(net.osmand.plus.routing.RoutingHelper) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) LayoutInflater(android.view.LayoutInflater) OnClickListener(android.view.View.OnClickListener) TextView(android.widget.TextView) ImageView(android.widget.ImageView) LinearLayout(android.widget.LinearLayout) MapActivity(net.osmand.plus.activities.MapActivity)

Example 80 with MapActivity

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

the class AudioVideoNoteRecordingMenuFullScreen method setImage.

private void setImage(final byte[] jpeg) {
    MapActivity mapActivity = getMapActivity();
    if (mapActivity != null) {
        Bitmap bmp = BitmapFactory.decodeByteArray(jpeg, 0, jpeg.length);
        DisplayMetrics dm = new DisplayMetrics();
        Display display = mapActivity.getWindowManager().getDefaultDisplay();
        display.getMetrics(dm);
        int imageOrientation = getOrientation(jpeg);
        imageview.setMinimumHeight(dm.heightPixels);
        imageview.setMinimumWidth(dm.widthPixels);
        bmp = rotateBitmap(bmp, imageOrientation, dm.widthPixels, dm.heightPixels);
        imageview.setImageBitmap(bmp);
    }
}
Also used : Bitmap(android.graphics.Bitmap) DisplayMetrics(android.util.DisplayMetrics) MapActivity(net.osmand.plus.activities.MapActivity) Display(android.view.Display)

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