Exemplo n.º 1
0
  public ContextMenuAdapter createListAdapter(final MapActivity ma) {
    ContextMenuAdapter adapter = new ContextMenuAdapter(ma, allModes);
    adapter.setDefaultLayoutId(R.layout.drawer_list_item);
    adapter.item(R.string.app_modes_choose).layout(R.layout.mode_toggles).reg();
    adapter.setChangeAppModeListener(
        new OnClickListener() {
          @Override
          public void onClick(boolean result) {
            allModes = true;
            ma.getDashboard().updateListAdapter(createListAdapter(ma));
          }
        });
    createLayersItems(adapter, ma);
    createRenderingAttributeItems(adapter, ma);
    adapter
        .item(R.string.layer_map_appearance)
        .iconColor(R.drawable.ic_configure_screen_dark)
        .listen(
            new OnContextMenuClick() {
              @Override
              public boolean onContextMenuClick(
                  ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
                ma.getDashboard().setDashboardVisibility(true, DashboardType.CONFIGURE_SCREEN);
                return false;
              }
            })
        .reg();

    return adapter;
  }
Exemplo n.º 2
0
  @Override
  public void populateObjectContextMenu(Object o, ContextMenuAdapter adapter) {
    if (o instanceof OpenStreetNote) {
      final OpenStreetNote bug = (OpenStreetNote) o;
      OnContextMenuClick listener =
          new OnContextMenuClick() {

            @Override
            public boolean onContextMenuClick(
                ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
              if (itemId == R.string.osb_comment_menu_item) {
                commentBug(bug);
              } else if (itemId == R.string.osb_close_menu_item) {
                closeBug(bug);
              }
              return true;
            }
          };
      adapter
          .item(R.string.osb_comment_menu_item)
          .iconColor(R.drawable.ic_action_note_dark)
          .listen(listener)
          .reg();
      adapter
          .item(R.string.osb_close_menu_item)
          .iconColor(R.drawable.ic_action_remove_dark)
          .listen(listener)
          .reg();
    }
  }
Exemplo n.º 3
0
  @Override
  public void addMonitorActions(
      final ContextMenuAdapter qa, final MonitoringInfoControl li, final OsmandMapTileView view) {
    boolean o = true;
    try {
      o = mIRemoteService.isActive();
    } catch (Exception e) {
      log.error(e.getMessage(), e);
    }
    final boolean off = !o;
    qa.item(off ? R.string.osmodroid_mode_off : R.string.osmodroid_mode_on)
        .icon(off ? R.drawable.monitoring_rec_inactive : R.drawable.monitoring_rec_big)
        .listen(
            new OnContextMenuClick() {

              @Override
              public void onContextMenuClick(
                  int itemId, int pos, boolean isChecked, DialogInterface dialog) {
                try {
                  if (off) {
                    mIRemoteService.Activate();
                  } else {
                    mIRemoteService.Deactivate();
                  }
                } catch (Exception e) {
                  log.error(e.getMessage(), e);
                }
              }
            })
        .reg();
  }
Exemplo n.º 4
0
  @Override
  public void registerLayerContextMenuActions(
      OsmandMapTileView mapView, ContextMenuAdapter adapter, MapActivity mapActivity) {
    for (OsMoDroidLayer myOsMoDroidLayer : osmoDroidLayerList) {
      adapter.item(myOsMoDroidLayer.layerName).reg();
    }

    super.registerLayerContextMenuActions(mapView, adapter, mapActivity);
  }
Exemplo n.º 5
0
 @Override
 public void populateObjectContextMenu(Object o, ContextMenuAdapter adapter) {
   if (o instanceof Recording) {
     final Recording r = (Recording) o;
     OnContextMenuClick listener =
         new ContextMenuAdapter.OnContextMenuClick() {
           @Override
           public boolean onContextMenuClick(
               ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
             if (itemId == R.string.recording_context_menu_play
                 || itemId == R.string.recording_context_menu_show) {
               plugin.playRecording(view.getContext(), r);
             } else if (itemId == R.string.recording_context_menu_delete) {
               deleteRecording(r);
             }
             return true;
           }
         };
     if (r.isPhoto()) {
       adapter
           .item(R.string.recording_context_menu_show)
           .iconColor(R.drawable.ic_action_view)
           .listen(listener)
           .reg();
     } else {
       adapter
           .item(R.string.recording_context_menu_play)
           .iconColor(R.drawable.ic_action_play_dark)
           .listen(listener)
           .reg();
     }
     adapter
         .item(R.string.recording_context_menu_delete)
         .iconColor(R.drawable.ic_action_delete_dark)
         .listen(listener)
         .reg();
   }
 }
Exemplo n.º 6
0
  private void createLayersItems(ContextMenuAdapter adapter, MapActivity activity) {
    OsmandApplication app = activity.getMyApplication();
    OsmandSettings settings = app.getSettings();
    LayerMenuListener l = new LayerMenuListener(activity, adapter);
    adapter
        .item(R.string.shared_string_show)
        .setCategory(true)
        .layout(R.layout.drawer_list_sub_header)
        .reg();
    // String appMode = " [" + settings.getApplicationMode().toHumanString(view.getApplication())
    // +"] ";
    adapter
        .item(R.string.layer_poi)
        .selected(settings.SELECTED_POI_FILTER_FOR_MAP.get() != null ? 1 : 0)
        .iconColor(R.drawable.ic_action_info_dark)
        .listen(l)
        .reg();
    adapter
        .item(R.string.layer_amenity_label)
        .selected(settings.SHOW_POI_LABEL.get() ? 1 : 0)
        .iconColor(R.drawable.ic_action_text_dark)
        .listen(l)
        .reg();
    adapter
        .item(R.string.shared_string_favorites)
        .selected(settings.SHOW_FAVORITES.get() ? 1 : 0)
        .iconColor(R.drawable.ic_action_fav_dark)
        .listen(l)
        .reg();
    adapter
        .item(R.string.layer_gpx_layer)
        .selected(app.getSelectedGpxHelper().isShowingAnyGpxFiles() ? 1 : 0)
        .iconColor(R.drawable.ic_action_polygom_dark)
        .listen(l)
        .reg();
    adapter.item(R.string.layer_map).iconColor(R.drawable.ic_world_globe_dark).listen(l).reg();
    if (TransportRouteHelper.getInstance().routeIsCalculated()) {
      adapter
          .item(R.string.layer_transport_route)
          .selected(1)
          .iconColor(R.drawable.ic_action_bus_dark)
          .listen(l)
          .reg();
    }

    OsmandPlugin.registerLayerContextMenu(activity.getMapView(), adapter, activity);
    app.getAppCustomization().prepareLayerContextMenu(activity, adapter);
  }
Exemplo n.º 7
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);
    }
  }
Exemplo n.º 8
0
  @Override
  public void populateObjectContextMenu(Object o, ContextMenuAdapter adapter) {
    if (o instanceof FavouritePoint) {
      final FavouritePoint a = (FavouritePoint) o;
      OnContextMenuClick listener =
          new ContextMenuAdapter.OnContextMenuClick() {
            @Override
            public void onContextMenuClick(
                int itemId, int pos, boolean isChecked, DialogInterface dialog) {
              if (itemId == R.string.favourites_context_menu_delete) {
                final Resources resources = view.getContext().getResources();
                Builder builder = new AlertDialog.Builder(view.getContext());
                builder.setMessage(
                    resources.getString(R.string.favourites_remove_dialog_msg, a.getName()));
                builder.setNegativeButton(R.string.default_buttons_no, null);
                builder.setPositiveButton(
                    R.string.default_buttons_yes,
                    new DialogInterface.OnClickListener() {
                      @Override
                      public void onClick(DialogInterface dialog, int which) {
                        favorites.deleteFavourite(a);
                        view.refreshMap();
                      }
                    });
                builder.create().show();
              }
            }
          };

      adapter
          .item(R.string.favourites_context_menu_delete)
          .icons(R.drawable.ic_action_delete_dark, R.drawable.ic_action_delete_light)
          .listen(listener)
          .reg();
    }
  }
Exemplo n.º 9
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();
      }
    }
  }
Exemplo n.º 10
0
  private void createRenderingAttributeItems(
      final ContextMenuAdapter adapter, final MapActivity activity) {
    adapter
        .item(R.string.map_widget_map_rendering)
        .setCategory(true)
        .layout(R.layout.drawer_list_sub_header)
        .reg();
    String descr = getRenderDescr(activity);
    adapter
        .item(R.string.map_widget_renderer)
        .listen(
            new OnContextMenuClick() {
              @Override
              public boolean onContextMenuClick(
                  final ArrayAdapter<?> ad, int itemId, final int pos, boolean isChecked) {
                AlertDialog.Builder bld = new AlertDialog.Builder(activity);
                bld.setTitle(R.string.renderers);
                final OsmandApplication app = activity.getMyApplication();
                Collection<String> rendererNames = app.getRendererRegistry().getRendererNames();
                final String[] items = rendererNames.toArray(new String[rendererNames.size()]);
                final String[] visibleNames = new String[items.length];
                int selected = -1;
                final String selectedName =
                    app.getRendererRegistry().getCurrentSelectedRenderer().getName();
                for (int j = 0; j < items.length; j++) {
                  if (items[j].equals(selectedName)) {
                    selected = j;
                  }
                  visibleNames[j] = items[j].replace('_', ' ').replace('-', ' ');
                }
                bld.setSingleChoiceItems(
                    visibleNames,
                    selected,
                    new DialogInterface.OnClickListener() {

                      @Override
                      public void onClick(DialogInterface dialog, int which) {
                        String renderer = items[which];
                        RenderingRulesStorage loaded =
                            app.getRendererRegistry().getRenderer(renderer);
                        if (loaded != null) {
                          OsmandMapTileView view = activity.getMapView();
                          view.getSettings().RENDERER.set(renderer);
                          app.getRendererRegistry().setCurrentSelectedRender(loaded);
                          refreshMapComplete(activity);
                        } else {
                          AccessibleToast.makeText(
                                  app, R.string.renderer_load_exception, Toast.LENGTH_SHORT)
                              .show();
                        }
                        adapter.setItemDescription(pos, getRenderDescr(activity));
                        activity.getDashboard().refreshContent(true);
                        dialog.dismiss();
                      }
                    });
                bld.show();
                return false;
              }
            })
        .description(descr)
        .layout(R.layout.drawer_list_doubleitem)
        .reg();

    adapter
        .item(R.string.map_widget_day_night)
        .description(getDayNightDescr(activity))
        .listen(
            new OnContextMenuClick() {
              @Override
              public boolean onContextMenuClick(
                  final ArrayAdapter<?> ad, int itemId, final int pos, boolean isChecked) {
                final OsmandMapTileView view = activity.getMapView();
                AlertDialog.Builder bld = new AlertDialog.Builder(view.getContext());
                bld.setTitle(R.string.daynight);
                final String[] items = new String[OsmandSettings.DayNightMode.values().length];
                for (int i = 0; i < items.length; i++) {
                  items[i] =
                      OsmandSettings.DayNightMode.values()[i].toHumanString(
                          activity.getMyApplication());
                }
                int i = view.getSettings().DAYNIGHT_MODE.get().ordinal();
                bld.setSingleChoiceItems(
                    items,
                    i,
                    new DialogInterface.OnClickListener() {
                      @Override
                      public void onClick(DialogInterface dialog, int which) {
                        view.getSettings()
                            .DAYNIGHT_MODE
                            .set(OsmandSettings.DayNightMode.values()[which]);
                        refreshMapComplete(activity);
                        dialog.dismiss();
                        adapter.setItemDescription(pos, getDayNightDescr(activity));
                        ad.notifyDataSetInvalidated();
                      }
                    });
                bld.show();
                return false;
              }
            })
        .layout(R.layout.drawer_list_doubleitem)
        .reg();

    adapter
        .item(R.string.map_magnifier)
        .listen(
            new OnContextMenuClick() {
              @Override
              public boolean onContextMenuClick(
                  final ArrayAdapter<?> ad, int itemId, final int pos, boolean isChecked) {
                final OsmandMapTileView view = activity.getMapView();
                final OsmandSettings.OsmandPreference<Float> mapDensity =
                    view.getSettings().MAP_DENSITY;
                final AlertDialog.Builder bld = new AlertDialog.Builder(view.getContext());
                int p = (int) (mapDensity.get() * 100);
                final TIntArrayList tlist =
                    new TIntArrayList(new int[] {33, 50, 75, 100, 150, 200, 300, 400});
                final List<String> values = new ArrayList<String>();
                int i = -1;
                for (int k = 0; k <= tlist.size(); k++) {
                  final boolean end = k == tlist.size();
                  if (i == -1) {
                    if ((end || p < tlist.get(k))) {
                      values.add(p + " %");
                      i = k;
                    } else if (p == tlist.get(k)) {
                      i = k;
                    }
                  }
                  if (k < tlist.size()) {
                    values.add(tlist.get(k) + " %");
                  }
                }
                if (values.size() != tlist.size()) {
                  tlist.insert(i, p);
                }

                bld.setTitle(R.string.map_magnifier);
                bld.setSingleChoiceItems(
                    values.toArray(new String[values.size()]),
                    i,
                    new DialogInterface.OnClickListener() {
                      @Override
                      public void onClick(DialogInterface dialog, int which) {
                        int p = tlist.get(which);
                        mapDensity.set(p / 100.0f);
                        view.setComplexZoom(view.getZoom(), view.getSettingsMapDensity());
                        MapRendererContext mapContext = NativeCoreContext.getMapRendererContext();
                        if (mapContext != null) {
                          mapContext.updateMapSettings();
                        }
                        adapter.setItemDescription(
                            pos,
                            String.format(
                                    "%.0f",
                                    100f
                                        * activity
                                            .getMyApplication()
                                            .getSettings()
                                            .MAP_DENSITY
                                            .get())
                                + " %");
                        ad.notifyDataSetInvalidated();
                        dialog.dismiss();
                      }
                    });
                bld.show();
                return false;
              }
            })
        .description(
            String.format(
                    "%.0f", 100f * activity.getMyApplication().getSettings().MAP_DENSITY.get())
                + " %")
        .layout(R.layout.drawer_list_doubleitem)
        .reg();

    adapter
        .item(R.string.text_size)
        .listen(
            new OnContextMenuClick() {
              @Override
              public boolean onContextMenuClick(
                  final ArrayAdapter<?> ad, int itemId, final int pos, boolean isChecked) {
                final OsmandMapTileView view = activity.getMapView();
                AlertDialog.Builder b = new AlertDialog.Builder(view.getContext());
                // test old descr as title
                b.setTitle(R.string.text_size);
                final Float[] txtValues = new Float[] {0.75f, 1f, 1.25f, 1.5f, 2f, 3f};
                int selected = -1;
                final String[] txtNames = new String[txtValues.length];
                for (int i = 0; i < txtNames.length; i++) {
                  txtNames[i] = (int) (txtValues[i] * 100) + " %";
                  if (Math.abs(view.getSettings().TEXT_SCALE.get() - txtValues[i]) < 0.1f) {
                    selected = i;
                  }
                }
                b.setSingleChoiceItems(
                    txtNames,
                    selected,
                    new DialogInterface.OnClickListener() {
                      @Override
                      public void onClick(DialogInterface dialog, int which) {
                        view.getSettings().TEXT_SCALE.set(txtValues[which]);
                        refreshMapComplete(activity);
                        adapter.setItemDescription(pos, getScale(activity));
                        ad.notifyDataSetInvalidated();
                        dialog.dismiss();
                      }
                    });
                b.show();
                return false;
              }
            })
        .description(getScale(activity))
        .layout(R.layout.drawer_list_doubleitem)
        .reg();

    adapter
        .item(R.string.map_locale)
        .listen(
            new OnContextMenuClick() {
              @Override
              public boolean onContextMenuClick(
                  final ArrayAdapter<?> ad, int itemId, final int pos, boolean isChecked) {
                final OsmandMapTileView view = activity.getMapView();
                AlertDialog.Builder b = new AlertDialog.Builder(view.getContext());
                // test old descr as title
                b.setTitle(R.string.map_preferred_locale);
                final String[] txtValues = mapNamesIds;
                final String[] txtNames = getMapNamesValues(activity);
                int selected = -1;
                for (int i = 0; i < txtValues.length; i++) {
                  if (view.getSettings().MAP_PREFERRED_LOCALE.get().equals(txtValues[i])) {
                    selected = i;
                    break;
                  }
                }
                b.setSingleChoiceItems(
                    txtNames,
                    selected,
                    new DialogInterface.OnClickListener() {
                      @Override
                      public void onClick(DialogInterface dialog, int which) {
                        view.getSettings().MAP_PREFERRED_LOCALE.set(txtValues[which]);
                        refreshMapComplete(activity);
                        adapter.setItemDescription(pos, txtValues[which]);
                        ad.notifyDataSetInvalidated();
                        dialog.dismiss();
                      }
                    });
                b.show();
                return false;
              }
            })
        .description(activity.getMyApplication().getSettings().MAP_PREFERRED_LOCALE.get())
        .layout(R.layout.drawer_list_doubleitem)
        .reg();

    RenderingRulesStorage renderer =
        activity.getMyApplication().getRendererRegistry().getCurrentSelectedRenderer();
    if (renderer != null) {
      List<RenderingRuleProperty> customRules =
          new ArrayList<RenderingRuleProperty>(renderer.PROPS.getCustomRules());

      createProperties(
          customRules, R.string.rendering_category_transport, "transport", adapter, activity);
      createProperties(
          customRules, R.string.rendering_category_details, "details", adapter, activity);
      createProperties(customRules, R.string.rendering_category_hide, "hide", adapter, activity);
      createProperties(
          customRules, R.string.rendering_category_routes, "routes", adapter, activity);

      if (customRules.size() > 0) {
        adapter
            .item(R.string.rendering_category_others)
            .setCategory(true)
            .layout(R.layout.drawer_list_sub_header)
            .reg();
        createCustomRenderingProperties(adapter, activity, customRules);
      }
    }
  }