Search in sources :

Example 1 with OnMultiChoiceClickListener

use of android.content.DialogInterface.OnMultiChoiceClickListener in project Osmand by osmandapp.

the class SettingsNavigationActivity method showBooleanSettings.

public AlertDialog showBooleanSettings(String[] vals, final OsmandPreference<Boolean>[] prefs, final CharSequence title) {
    AlertDialog.Builder bld = new AlertDialog.Builder(this);
    boolean[] checkedItems = new boolean[prefs.length];
    for (int i = 0; i < prefs.length; i++) {
        checkedItems[i] = prefs[i].get();
    }
    final boolean[] tempPrefs = new boolean[prefs.length];
    for (int i = 0; i < prefs.length; i++) {
        tempPrefs[i] = prefs[i].get();
    }
    bld.setMultiChoiceItems(vals, checkedItems, new OnMultiChoiceClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which, boolean isChecked) {
            tempPrefs[which] = isChecked;
        }
    });
    bld.setTitle(title);
    bld.setNegativeButton(R.string.shared_string_cancel, null);
    bld.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int whichButton) {
            for (int i = 0; i < prefs.length; i++) {
                prefs[i].set(tempPrefs[i]);
            }
        }
    });
    return bld.show();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) OnMultiChoiceClickListener(android.content.DialogInterface.OnMultiChoiceClickListener) DialogInterface(android.content.DialogInterface)

Example 2 with OnMultiChoiceClickListener

use of android.content.DialogInterface.OnMultiChoiceClickListener in project Osmand by osmandapp.

the class ConfigureMapMenu method showPreferencesDialog.

protected void showPreferencesDialog(final ContextMenuAdapter adapter, final ArrayAdapter<?> a, final int pos, final MapActivity activity, String category, List<RenderingRuleProperty> ps, final List<CommonPreference<Boolean>> prefs, final boolean useDescription, ListStringPreference defaultSettings, boolean useDefault, final List<RenderingRuleProperty> customRulesIncluded) {
    AlertDialog.Builder bld = new AlertDialog.Builder(activity);
    boolean[] checkedItems = new boolean[prefs.size()];
    final boolean[] tempPrefs = new boolean[prefs.size()];
    for (int i = 0; i < prefs.size(); i++) {
        tempPrefs[i] = checkedItems[i] = defaultSettings != null && useDefault ? defaultSettings.containsValue(prefs.get(i).getId()) : prefs.get(i).get();
    }
    final String[] vals = new String[ps.size()];
    for (int i = 0; i < ps.size(); i++) {
        RenderingRuleProperty p = ps.get(i);
        String propertyName = SettingsActivity.getStringPropertyName(activity, p.getAttrName(), p.getName());
        vals[i] = propertyName;
    }
    bld.setMultiChoiceItems(vals, checkedItems, new OnMultiChoiceClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which, boolean isChecked) {
            tempPrefs[which] = isChecked;
        }
    });
    bld.setTitle(category);
    bld.setNegativeButton(R.string.shared_string_cancel, new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int whichButton) {
            boolean selected = false;
            for (int i = 0; i < prefs.size(); i++) {
                selected |= prefs.get(i).get();
            }
            adapter.getItem(pos).setSelected(selected);
            adapter.getItem(pos).setColorRes(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
            a.notifyDataSetInvalidated();
        }
    });
    bld.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int whichButton) {
            boolean selected = false;
            for (int i = 0; i < prefs.size(); i++) {
                prefs.get(i).set(tempPrefs[i]);
                selected |= tempPrefs[i];
            }
            final List<OsmandSettings.CommonPreference<String>> includedPrefs = new ArrayList<>();
            if (customRulesIncluded != null) {
                for (RenderingRuleProperty p : customRulesIncluded) {
                    if (p.getAttrName().equals(HIKING_ROUTES_OSMC_ATTR)) {
                        final OsmandSettings.CommonPreference<String> pref = activity.getMyApplication().getSettings().getCustomRenderProperty(p.getAttrName());
                        includedPrefs.add(pref);
                        if (hikingRouteOSMCValue == 0) {
                            pref.set("");
                        } else {
                            pref.set(p.getPossibleValues()[hikingRouteOSMCValue - 1]);
                            selected = true;
                        }
                        break;
                    }
                }
            }
            if (adapter != null) {
                if (useDescription) {
                    adapter.getItem(pos).setDescription(getDescription(prefs, includedPrefs));
                } else {
                    adapter.getItem(pos).setSelected(selected);
                }
                adapter.getItem(pos).setColorRes(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
            }
            a.notifyDataSetInvalidated();
            refreshMapComplete(activity);
            activity.getMapLayers().updateLayers(activity.getMapView());
        }
    });
    final AlertDialog dialog = bld.create();
    if (customRulesIncluded != null) {
        for (RenderingRuleProperty p : customRulesIncluded) {
            if (!p.isBoolean()) {
                final OsmandSettings.CommonPreference<String> pref = activity.getMyApplication().getSettings().getCustomRenderProperty(p.getAttrName());
                LayoutInflater inflater = activity.getLayoutInflater();
                View spinnerView = inflater.inflate(R.layout.spinner_rule_layout, null);
                TextView title = (TextView) spinnerView.findViewById(R.id.title);
                final Spinner spinner = (Spinner) spinnerView.findViewById(R.id.spinner);
                TextView description = (TextView) spinnerView.findViewById(R.id.description);
                String propertyName = SettingsActivity.getStringPropertyName(activity, p.getAttrName(), p.getName());
                String propertyDescr = SettingsActivity.getStringPropertyDescription(activity, p.getAttrName(), p.getName());
                title.setText(propertyName);
                description.setText(propertyDescr);
                int i = Arrays.asList(p.getPossibleValues()).indexOf(pref.get());
                if (i >= 0) {
                    i++;
                } else if (Algorithms.isEmpty(pref.get())) {
                    i = 0;
                }
                String[] possibleValuesString = new String[p.getPossibleValues().length + 1];
                possibleValuesString[0] = SettingsActivity.getStringPropertyValue(activity, p.getDefaultValueDescription());
                for (int j = 0; j < p.getPossibleValues().length; j++) {
                    possibleValuesString[j + 1] = SettingsActivity.getStringPropertyValue(activity, p.getPossibleValues()[j]);
                }
                StringSpinnerArrayAdapter arrayAdapter = new StringSpinnerArrayAdapter(activity);
                for (String val : possibleValuesString) {
                    arrayAdapter.add(val);
                }
                spinner.setAdapter(arrayAdapter);
                hikingRouteOSMCValue = i;
                spinner.setSelection(i);
                spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

                    @Override
                    public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                        hikingRouteOSMCValue = position;
                    }

                    @Override
                    public void onNothingSelected(AdapterView<?> parent) {
                    }
                });
                dialog.getListView().addFooterView(spinnerView);
            }
        }
    }
    dialog.show();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) OnMultiChoiceClickListener(android.content.DialogInterface.OnMultiChoiceClickListener) DialogInterface(android.content.DialogInterface) Spinner(android.widget.Spinner) TIntArrayList(gnu.trove.list.array.TIntArrayList) List(java.util.List) ArrayList(java.util.ArrayList) AppCompatCheckedTextView(android.support.v7.widget.AppCompatCheckedTextView) TextView(android.widget.TextView) CommonPreference(net.osmand.plus.OsmandSettings.CommonPreference) RenderingRuleProperty(net.osmand.render.RenderingRuleProperty) AppCompatCheckedTextView(android.support.v7.widget.AppCompatCheckedTextView) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) OsmandSettings(net.osmand.plus.OsmandSettings) LayoutInflater(android.view.LayoutInflater) AdapterView(android.widget.AdapterView)

Example 3 with OnMultiChoiceClickListener

use of android.content.DialogInterface.OnMultiChoiceClickListener in project Osmand by osmandapp.

the class SettingsBaseActivity method showBooleanSettings.

public void showBooleanSettings(String[] vals, final OsmandPreference<Boolean>[] prefs) {
    AlertDialog.Builder bld = new AlertDialog.Builder(this);
    boolean[] checkedItems = new boolean[prefs.length];
    for (int i = 0; i < prefs.length; i++) {
        checkedItems[i] = prefs[i].get();
    }
    bld.setMultiChoiceItems(vals, checkedItems, new OnMultiChoiceClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which, boolean isChecked) {
            prefs[which].set(isChecked);
        }
    });
    bld.show();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) OnMultiChoiceClickListener(android.content.DialogInterface.OnMultiChoiceClickListener) DialogInterface(android.content.DialogInterface)

Example 4 with OnMultiChoiceClickListener

use of android.content.DialogInterface.OnMultiChoiceClickListener in project Osmand by osmandapp.

the class OpeningHoursView method showDaysDialog.

public void showDaysDialog(final BasicOpeningHourRule item, final int positionToAdd) {
    AlertDialog.Builder b = new AlertDialog.Builder(ctx);
    boolean add = positionToAdd > -1;
    Calendar inst = Calendar.getInstance();
    final int first = inst.getFirstDayOfWeek();
    final boolean[] dayToShow = new boolean[7];
    String[] daysToShow = new String[7];
    for (int i = 0; i < 7; i++) {
        int d = (first + i - 1) % 7 + 1;
        inst.set(Calendar.DAY_OF_WEEK, d);
        // $NON-NLS-1$
        daysToShow[i] = DateFormat.format("EEEE", inst).toString();
        final int pos = (d + 5) % 7;
        dayToShow[i] = item.getDays()[pos];
    }
    b.setMultiChoiceItems(daysToShow, dayToShow, new OnMultiChoiceClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which, boolean isChecked) {
            dayToShow[which] = isChecked;
        }
    });
    b.setPositiveButton(add ? ctx.getString(R.string.shared_string_add) : ctx.getString(R.string.shared_string_apply), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            boolean[] days = item.getDays();
            for (int i = 0; i < 7; i++) {
                days[(first + 5 + i) % 7] = dayToShow[i];
            }
            if (positionToAdd != -1) {
                time.insert(item, positionToAdd);
                selectedRule = positionToAdd;
            } else {
                time.notifyDataSetChanged();
            }
            updateTimePickers();
        }
    });
    b.setNegativeButton(ctx.getString(R.string.shared_string_cancel), null);
    b.show();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) OnMultiChoiceClickListener(android.content.DialogInterface.OnMultiChoiceClickListener) DialogInterface(android.content.DialogInterface) Calendar(java.util.Calendar)

Aggregations

DialogInterface (android.content.DialogInterface)4 OnMultiChoiceClickListener (android.content.DialogInterface.OnMultiChoiceClickListener)4 AlertDialog (android.support.v7.app.AlertDialog)4 AppCompatCheckedTextView (android.support.v7.widget.AppCompatCheckedTextView)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 ImageView (android.widget.ImageView)1 ListView (android.widget.ListView)1 Spinner (android.widget.Spinner)1 TextView (android.widget.TextView)1 TIntArrayList (gnu.trove.list.array.TIntArrayList)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 List (java.util.List)1 OsmandSettings (net.osmand.plus.OsmandSettings)1 CommonPreference (net.osmand.plus.OsmandSettings.CommonPreference)1 OsmandMapTileView (net.osmand.plus.views.OsmandMapTileView)1 RenderingRuleProperty (net.osmand.render.RenderingRuleProperty)1