Search in sources :

Example 1 with FavoriteGroup

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

the class FavouritePointMenuBuilder method buildGroupFavouritesView.

private void buildGroupFavouritesView(View view) {
    FavoriteGroup favoriteGroup = app.getFavorites().getGroup(fav);
    List<FavouritePoint> groupFavourites = favoriteGroup.points;
    if (groupFavourites.size() > 0) {
        int color = favoriteGroup.color == 0 || favoriteGroup.color == Color.BLACK ? view.getResources().getColor(R.color.color_favorite) : favoriteGroup.color;
        int disabledColor = light ? R.color.secondary_text_light : R.color.secondary_text_dark;
        color = favoriteGroup.visible ? (color | 0xff000000) : view.getResources().getColor(disabledColor);
        String name = view.getContext().getString(R.string.context_menu_points_of_group);
        buildRow(view, app.getIconsCache().getPaintedIcon(R.drawable.ic_action_folder, color), null, name, 0, null, true, getCollapsableFavouritesView(view.getContext(), true, favoriteGroup, fav), false, 0, false, null, false);
    }
}
Also used : FavouritePoint(net.osmand.data.FavouritePoint) FavoriteGroup(net.osmand.plus.FavouritesDbHelper.FavoriteGroup) FavouritePoint(net.osmand.data.FavouritePoint)

Example 2 with FavoriteGroup

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

the class AddFavouritesGroupBottomSheetDialogFragment method onItemClick.

@Override
protected void onItemClick(int position) {
    FavoriteGroup group = favouritesDbHelper.getFavoriteGroups().get(position - 1);
    if (!group.visible) {
        favouritesDbHelper.editFavouriteGroup(group, group.name, group.color, true);
    }
    addAndSyncGroup(getMyApplication().getMapMarkersHelper().getOrCreateGroup(group));
}
Also used : FavoriteGroup(net.osmand.plus.FavouritesDbHelper.FavoriteGroup)

Example 3 with FavoriteGroup

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

the class WptPtEditorFragment method onCreate.

@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    wpt = editor.getWptPt();
    FavoriteGroup group = getMyApplication().getFavorites().getGroup(wpt.category);
    if (group == null) {
        color = wpt.getColor(0);
    } else {
        color = group.color;
    }
}
Also used : FavoriteGroup(net.osmand.plus.FavouritesDbHelper.FavoriteGroup)

Example 4 with FavoriteGroup

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

the class WptPtEditorFragment method setCategory.

@Override
public void setCategory(String name) {
    FavoriteGroup group = getMyApplication().getFavorites().getGroup(name);
    if (group != null) {
        color = group.color;
    }
    super.setCategory(name);
}
Also used : FavoriteGroup(net.osmand.plus.FavouritesDbHelper.FavoriteGroup)

Example 5 with FavoriteGroup

use of net.osmand.plus.FavouritesDbHelper.FavoriteGroup 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)

Aggregations

FavoriteGroup (net.osmand.plus.FavouritesDbHelper.FavoriteGroup)10 FavouritePoint (net.osmand.data.FavouritePoint)6 Activity (android.app.Activity)1 Dialog (android.app.Dialog)1 DialogInterface (android.content.DialogInterface)1 OnClickListener (android.content.DialogInterface.OnClickListener)1 Intent (android.content.Intent)1 Drawable (android.graphics.drawable.Drawable)1 AsyncTask (android.os.AsyncTask)1 AlertDialog (android.support.v7.app.AlertDialog)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 AutoCompleteTextView (android.widget.AutoCompleteTextView)1 CheckBox (android.widget.CheckBox)1 EditText (android.widget.EditText)1 ListView (android.widget.ListView)1 TextView (android.widget.TextView)1 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1