Search in sources :

Example 1 with SelectCategoryDialogFragment

use of net.osmand.plus.mapcontextmenu.editors.SelectCategoryDialogFragment 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 2 with SelectCategoryDialogFragment

use of net.osmand.plus.mapcontextmenu.editors.SelectCategoryDialogFragment in project Osmand by osmandapp.

the class GPXAction method drawUI.

@Override
public void drawUI(final ViewGroup parent, final MapActivity activity) {
    final View root = LayoutInflater.from(parent.getContext()).inflate(R.layout.quick_action_add_gpx, 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("");
            categoryImage.setColorFilter(activity.getResources().getColor(R.color.icon_color));
        }
    } else {
        categoryEdit.setText("");
        categoryImage.setColorFilter(activity.getResources().getColor(R.color.icon_color));
        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) 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)

Aggregations

SwitchCompat (android.support.v7.widget.SwitchCompat)2 View (android.view.View)2 EditText (android.widget.EditText)2 ImageView (android.widget.ImageView)2 EditCategoryDialogFragment (net.osmand.plus.mapcontextmenu.editors.EditCategoryDialogFragment)2 SelectCategoryDialogFragment (net.osmand.plus.mapcontextmenu.editors.SelectCategoryDialogFragment)2 AutoCompleteTextViewEx (net.osmand.plus.widgets.AutoCompleteTextViewEx)2 FavouritesDbHelper (net.osmand.plus.FavouritesDbHelper)1