Search in sources :

Example 6 with FavouritesDbHelper

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

the class FavoriteAction method drawUI.

@Override
public void drawUI(final ViewGroup parent, final MapActivity activity) {
    FavouritesDbHelper helper = activity.getMyApplication().getFavorites();
    final View root = LayoutInflater.from(parent.getContext()).inflate(R.layout.quick_action_add_favorite, parent, false);
    parent.addView(root);
    AutoCompleteTextViewEx categoryEdit = (AutoCompleteTextViewEx) root.findViewById(R.id.category_edit);
    SwitchCompat showDialog = (SwitchCompat) root.findViewById(R.id.saveButton);
    ImageView categoryImage = (ImageView) root.findViewById(R.id.category_image);
    EditText name = (EditText) root.findViewById(R.id.name_edit);
    if (!getParams().isEmpty()) {
        showDialog.setChecked(Boolean.valueOf(getParams().get(KEY_DIALOG)));
        categoryImage.setColorFilter(Integer.valueOf(getParams().get(KEY_CATEGORY_COLOR)));
        name.setText(getParams().get(KEY_NAME));
        categoryEdit.setText(getParams().get(KEY_CATEGORY_NAME));
        if (getParams().get(KEY_NAME).isEmpty() && Integer.valueOf(getParams().get(KEY_CATEGORY_COLOR)) == 0) {
            categoryEdit.setText(activity.getString(R.string.shared_string_favorites));
            categoryImage.setColorFilter(activity.getResources().getColor(R.color.color_favorite));
        }
    } else if (helper.getFavoriteGroups().size() > 0) {
        FavouritesDbHelper.FavoriteGroup group = helper.getFavoriteGroups().get(0);
        if (group.name.isEmpty() && group.color == 0) {
            group.name = activity.getString(R.string.shared_string_favorites);
            categoryEdit.setText(activity.getString(R.string.shared_string_favorites));
            categoryImage.setColorFilter(activity.getResources().getColor(R.color.color_favorite));
        } else {
            categoryEdit.setText(group.name);
            categoryImage.setColorFilter(group.color);
        }
        getParams().put(KEY_CATEGORY_NAME, group.name);
        getParams().put(KEY_CATEGORY_COLOR, String.valueOf(group.color));
    } else {
        categoryEdit.setText(activity.getString(R.string.shared_string_favorites));
        categoryImage.setColorFilter(activity.getResources().getColor(R.color.color_favorite));
        getParams().put(KEY_CATEGORY_NAME, "");
        getParams().put(KEY_CATEGORY_COLOR, "0");
    }
    categoryEdit.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(final View view) {
            SelectCategoryDialogFragment dialogFragment = SelectCategoryDialogFragment.createInstance("");
            dialogFragment.show(activity.getSupportFragmentManager(), SelectCategoryDialogFragment.TAG);
            dialogFragment.setSelectionListener(new SelectCategoryDialogFragment.CategorySelectionListener() {

                @Override
                public void onCategorySelected(String category, int color) {
                    fillGroupParams(root, category, color);
                }
            });
        }
    });
    SelectCategoryDialogFragment dialogFragment = (SelectCategoryDialogFragment) activity.getSupportFragmentManager().findFragmentByTag(SelectCategoryDialogFragment.TAG);
    if (dialogFragment != null) {
        dialogFragment.setSelectionListener(new SelectCategoryDialogFragment.CategorySelectionListener() {

            @Override
            public void onCategorySelected(String category, int color) {
                fillGroupParams(root, category, color);
            }
        });
    } else {
        EditCategoryDialogFragment dialog = (EditCategoryDialogFragment) activity.getSupportFragmentManager().findFragmentByTag(EditCategoryDialogFragment.TAG);
        if (dialog != null) {
            dialogFragment.setSelectionListener(new SelectCategoryDialogFragment.CategorySelectionListener() {

                @Override
                public void onCategorySelected(String category, int color) {
                    fillGroupParams(root, category, color);
                }
            });
        }
    }
}
Also used : EditText(android.widget.EditText) AutoCompleteTextViewEx(net.osmand.plus.widgets.AutoCompleteTextViewEx) EditCategoryDialogFragment(net.osmand.plus.mapcontextmenu.editors.EditCategoryDialogFragment) FavouritesDbHelper(net.osmand.plus.FavouritesDbHelper) ImageView(android.widget.ImageView) View(android.view.View) SelectCategoryDialogFragment(net.osmand.plus.mapcontextmenu.editors.SelectCategoryDialogFragment) ImageView(android.widget.ImageView) SwitchCompat(android.support.v7.widget.SwitchCompat)

Example 7 with FavouritesDbHelper

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

the class SelectCategoryDialogFragment method onCreateDialog.

@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    if (savedInstanceState != null) {
        restoreState(savedInstanceState);
    } else if (getArguments() != null) {
        restoreState(getArguments());
    }
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle(R.string.favorite_category_select);
    final View v = getActivity().getLayoutInflater().inflate(R.layout.favorite_categories_dialog, null, false);
    LinearLayout ll = (LinearLayout) v.findViewById(R.id.list_container);
    final FavouritesDbHelper helper = ((OsmandApplication) getActivity().getApplication()).getFavorites();
    if (gpxFile != null) {
        Set<String> categories = gpxFile.getWaypointCategories(false);
        for (final String category : categories) {
            addCategory(ll, category, 0);
        }
    } else {
        List<FavouritesDbHelper.FavoriteGroup> gs = helper.getFavoriteGroups();
        for (final FavouritesDbHelper.FavoriteGroup category : gs) {
            addCategory(ll, category.name, category.color);
        }
    }
    View itemView = getActivity().getLayoutInflater().inflate(R.layout.favorite_category_dialog_item, null);
    Button button = (Button) itemView.findViewById(R.id.button);
    button.setCompoundDrawablesWithIntrinsicBounds(getIcon(getActivity(), R.drawable.map_zoom_in), null, null, null);
    button.setCompoundDrawablePadding(dpToPx(15f));
    button.setText(getActivity().getResources().getText(R.string.favorite_category_add_new));
    button.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            dismiss();
            EditCategoryDialogFragment dialogFragment = EditCategoryDialogFragment.createInstance(editorTag);
            dialogFragment.show(getActivity().getSupportFragmentManager(), EditCategoryDialogFragment.TAG);
            dialogFragment.setSelectionListener(selectionListener);
        }
    });
    ll.addView(itemView);
    builder.setView(v);
    builder.setNegativeButton(R.string.shared_string_cancel, null);
    return builder.create();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) OsmandApplication(net.osmand.plus.OsmandApplication) FavouritesDbHelper(net.osmand.plus.FavouritesDbHelper) View(android.view.View) Button(android.widget.Button) LinearLayout(android.widget.LinearLayout) NonNull(android.support.annotation.NonNull)

Example 8 with FavouritesDbHelper

use of net.osmand.plus.FavouritesDbHelper 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 9 with FavouritesDbHelper

use of net.osmand.plus.FavouritesDbHelper 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 10 with FavouritesDbHelper

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

the class DashFavoritesFragment method setupFavorites.

public void setupFavorites() {
    View mainView = getView();
    final FavouritesDbHelper helper = getMyApplication().getFavorites();
    points = new ArrayList<FavouritePoint>(helper.getFavouritePoints());
    if (points.size() == 0) {
        (mainView.findViewById(R.id.main_fav)).setVisibility(View.GONE);
        return;
    } else {
        (mainView.findViewById(R.id.main_fav)).setVisibility(View.VISIBLE);
    }
    final LatLon loc = getDefaultLocation();
    if (loc != null) {
        Collections.sort(points, new Comparator<FavouritePoint>() {

            @Override
            public int compare(FavouritePoint point, FavouritePoint point2) {
                // LatLon lastKnownMapLocation = getMyApplication().getSettings().getLastKnownMapLocation();
                int dist = (int) (MapUtils.getDistance(point.getLatitude(), point.getLongitude(), loc.getLatitude(), loc.getLongitude()));
                int dist2 = (int) (MapUtils.getDistance(point2.getLatitude(), point2.getLongitude(), loc.getLatitude(), loc.getLongitude()));
                return (dist - dist2);
            }
        });
    }
    LinearLayout favorites = (LinearLayout) mainView.findViewById(R.id.items);
    favorites.removeAllViews();
    DashboardOnMap.handleNumberOfRows(points, getMyApplication().getSettings(), ROW_NUMBER_TAG);
    List<DashLocationView> distances = new ArrayList<DashLocationFragment.DashLocationView>();
    for (final FavouritePoint point : points) {
        LayoutInflater inflater = getActivity().getLayoutInflater();
        View view = inflater.inflate(R.layout.favorites_list_item, null, false);
        TextView name = (TextView) view.findViewById(R.id.favourite_label);
        TextView label = (TextView) view.findViewById(R.id.distance);
        ImageView direction = (ImageView) view.findViewById(R.id.direction);
        direction.setVisibility(View.VISIBLE);
        label.setVisibility(View.VISIBLE);
        view.findViewById(R.id.divider).setVisibility(View.VISIBLE);
        ImageView groupImage = (ImageView) view.findViewById(R.id.group_image);
        if (point.getCategory().length() > 0) {
            ((TextView) view.findViewById(R.id.group_name)).setText(point.getCategory());
            groupImage.setImageDrawable(getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_small_group));
        } else {
            groupImage.setVisibility(View.GONE);
        }
        ((ImageView) view.findViewById(R.id.favourite_icon)).setImageDrawable(FavoriteImageDrawable.getOrCreate(getActivity(), point.getColor(), false));
        DashLocationView dv = new DashLocationView(direction, label, new LatLon(point.getLatitude(), point.getLongitude()));
        distances.add(dv);
        name.setText(point.getName());
        name.setTypeface(Typeface.DEFAULT, point.isVisible() ? Typeface.NORMAL : Typeface.ITALIC);
        view.findViewById(R.id.navigate_to).setVisibility(View.VISIBLE);
        ((ImageView) view.findViewById(R.id.navigate_to)).setImageDrawable(getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_action_gdirections_dark));
        view.findViewById(R.id.navigate_to).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                DirectionsDialogs.directionsToDialogAndLaunchMap(getActivity(), point.getLatitude(), point.getLongitude(), new PointDescription(PointDescription.POINT_TYPE_FAVORITE, point.getName()));
            }
        });
        view.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                getMyApplication().getSettings().setMapLocationToShow(point.getLatitude(), point.getLongitude(), 15, new PointDescription(PointDescription.POINT_TYPE_FAVORITE, point.getName()), true, // $NON-NLS-1$
                point);
                MapActivity.launchMapActivityMoveToTop(getActivity());
            }
        });
        favorites.addView(view);
    }
    this.distances = distances;
}
Also used : FavouritePoint(net.osmand.data.FavouritePoint) ArrayList(java.util.ArrayList) FavouritesDbHelper(net.osmand.plus.FavouritesDbHelper) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) LatLon(net.osmand.data.LatLon) LayoutInflater(android.view.LayoutInflater) PointDescription(net.osmand.data.PointDescription) TextView(android.widget.TextView) ImageView(android.widget.ImageView) LinearLayout(android.widget.LinearLayout)

Aggregations

FavouritesDbHelper (net.osmand.plus.FavouritesDbHelper)14 FavouritePoint (net.osmand.data.FavouritePoint)10 AlertDialog (android.support.v7.app.AlertDialog)6 View (android.view.View)6 OsmandApplication (net.osmand.plus.OsmandApplication)5 DialogInterface (android.content.DialogInterface)4 EditText (android.widget.EditText)4 TextView (android.widget.TextView)4 AdapterView (android.widget.AdapterView)3 ImageView (android.widget.ImageView)3 AFavoriteGroup (net.osmand.aidl.favorite.group.AFavoriteGroup)3 AMapPoint (net.osmand.aidl.maplayer.point.AMapPoint)3 Dialog (android.app.Dialog)2 AutoCompleteTextView (android.widget.AutoCompleteTextView)2 LinearLayout (android.widget.LinearLayout)2 ListView (android.widget.ListView)2 ArrayList (java.util.ArrayList)2 LatLon (net.osmand.data.LatLon)2 PointDescription (net.osmand.data.PointDescription)2 MapMarkersHelper (net.osmand.plus.MapMarkersHelper)2