Example #1
0
  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) {
    Builder bld = new AlertDialog.Builder(activity);
    boolean[] checkedItems = new boolean[prefs.size()];
    for (int i = 0; i < prefs.size(); i++) {
      checkedItems[i] = prefs.get(i).get();
    }

    final boolean[] tempPrefs = new boolean[prefs.size()];
    for (int i = 0; i < prefs.size(); i++) {
      tempPrefs[i] = 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, null);

    bld.setPositiveButton(
        R.string.shared_string_ok,
        new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int whichButton) {
            for (int i = 0; i < prefs.size(); i++) {
              prefs.get(i).set(tempPrefs[i]);
            }
            adapter.setItemDescription(pos, getDescription(prefs));
            a.notifyDataSetInvalidated();
            refreshMapComplete(activity);
            activity.getMapLayers().updateLayers(activity.getMapView());
          }
        });

    bld.show();
  }
Example #2
0
  private void createProperties(
      List<RenderingRuleProperty> customRules,
      final int strId,
      String cat,
      final ContextMenuAdapter adapter,
      final MapActivity activity) {
    final List<RenderingRuleProperty> ps = new ArrayList<RenderingRuleProperty>();
    final List<OsmandSettings.CommonPreference<Boolean>> prefs =
        new ArrayList<OsmandSettings.CommonPreference<Boolean>>();
    Iterator<RenderingRuleProperty> it = customRules.iterator();

    while (it.hasNext()) {
      RenderingRuleProperty p = it.next();
      if (cat.equals(p.getCategory()) && p.isBoolean()) {
        ps.add(p);
        final OsmandSettings.CommonPreference<Boolean> pref =
            activity
                .getMyApplication()
                .getSettings()
                .getCustomRenderBooleanProperty(p.getAttrName());
        prefs.add(pref);
        it.remove();
      }
    }
    if (prefs.size() > 0) {
      final String descr = getDescription(prefs);
      adapter
          .item(strId)
          .description(descr)
          .layout(R.layout.drawer_list_doubleitem)
          .listen(
              new OnContextMenuClick() {

                @Override
                public boolean onContextMenuClick(
                    ArrayAdapter<?> a, int itemId, int pos, boolean isChecked) {
                  showPreferencesDialog(
                      adapter, a, pos, activity, activity.getString(strId), ps, prefs);
                  return false;
                }
              })
          .reg();
      //			createCustomRenderingProperties(adapter, activity, ps);
    }
  }
Example #3
0
  private void createCustomRenderingProperties(
      final ContextMenuAdapter adapter,
      final MapActivity activity,
      List<RenderingRuleProperty> customRules) {
    final OsmandMapTileView view = activity.getMapView();
    for (final RenderingRuleProperty p : customRules) {
      if (p.getAttrName().equals(RenderingRuleStorageProperties.A_APP_MODE)
          || p.getAttrName().equals(RenderingRuleStorageProperties.A_ENGINE_V1)) {
        continue;
      }
      String propertyName =
          SettingsActivity.getStringPropertyName(view.getContext(), p.getAttrName(), p.getName());
      // test old descr as title
      final String propertyDescr =
          SettingsActivity.getStringPropertyDescription(
              view.getContext(), p.getAttrName(), p.getName());
      if (p.isBoolean()) {
        final OsmandSettings.CommonPreference<Boolean> pref =
            view.getApplication().getSettings().getCustomRenderBooleanProperty(p.getAttrName());
        adapter
            .item(propertyName)
            .listen(
                new OnContextMenuClick() {

                  @Override
                  public boolean onContextMenuClick(
                      ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
                    pref.set(!pref.get());
                    refreshMapComplete(activity);
                    return false;
                  }
                })
            .selected(pref.get() ? 1 : 0)
            .reg();
      } else {
        final OsmandSettings.CommonPreference<String> pref =
            view.getApplication().getSettings().getCustomRenderProperty(p.getAttrName());
        String descr;
        if (Algorithms.isEmpty(pref.get())) {
          descr = SettingsActivity.getStringPropertyValue(activity, pref.get());
        } else {
          descr =
              SettingsActivity.getStringPropertyValue(
                  view.getContext(), p.getDefaultValueDescription());
        }
        adapter
            .item(propertyName)
            .listen(
                new OnContextMenuClick() {

                  @Override
                  public boolean onContextMenuClick(
                      final ArrayAdapter<?> ad, int itemId, final int pos, boolean isChecked) {
                    AlertDialog.Builder b = new AlertDialog.Builder(view.getContext());
                    // test old descr as title
                    b.setTitle(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(
                            view.getContext(), p.getDefaultValueDescription());

                    for (int j = 0; j < p.getPossibleValues().length; j++) {
                      possibleValuesString[j + 1] =
                          SettingsActivity.getStringPropertyValue(
                              view.getContext(), p.getPossibleValues()[j]);
                    }

                    b.setSingleChoiceItems(
                        possibleValuesString,
                        i,
                        new DialogInterface.OnClickListener() {
                          @Override
                          public void onClick(DialogInterface dialog, int which) {
                            if (which == 0) {
                              pref.set("");
                            } else {
                              pref.set(p.getPossibleValues()[which - 1]);
                            }
                            refreshMapComplete(activity);
                            adapter.setItemDescription(
                                pos, SettingsActivity.getStringPropertyValue(activity, pref.get()));
                            dialog.dismiss();
                            ad.notifyDataSetInvalidated();
                          }
                        });
                    b.show();
                    return false;
                  }
                })
            .description(descr)
            .layout(R.layout.drawer_list_doubleitem)
            .reg();
      }
    }
  }