private void buildHeader(View view, MenuObject item, MapActivity mapActivity) {

    IconsCache iconsCache = mapActivity.getMyApplication().getIconsCache();
    final View iconLayout = view.findViewById(R.id.context_menu_icon_layout);
    final ImageView iconView = (ImageView) view.findViewById(R.id.context_menu_icon_view);
    Drawable icon = item.getLeftIcon();
    int iconId = item.getLeftIconId();
    if (icon != null) {
      iconView.setImageDrawable(icon);
      iconLayout.setVisibility(View.VISIBLE);
    } else if (iconId != 0) {
      iconView.setImageDrawable(
          iconsCache.getIcon(
              iconId, menu.isLight() ? R.color.osmand_orange : R.color.osmand_orange_dark));
      iconLayout.setVisibility(View.VISIBLE);
    } else {
      iconLayout.setVisibility(View.GONE);
    }

    // Text line 1
    TextView line1 = (TextView) view.findViewById(R.id.context_menu_line1);
    line1.setText(item.getTitleStr());

    // Text line 2
    TextView line2 = (TextView) view.findViewById(R.id.context_menu_line2);
    line2.setText(item.getLocationStr());
    Drawable slIcon = item.getSecondLineIcon();
    line2.setCompoundDrawablesWithIntrinsicBounds(slIcon, null, null, null);
    line2.setCompoundDrawablePadding(dpToPx(5f));
  }
  public void rebuildMenu() {
    IconsCache iconsCache = getMyApplication().getIconsCache();
    boolean light = getMyApplication().getSettings().isLightContent();
    final ImageButton buttonFavorite =
        (ImageButton) view.findViewById(R.id.context_menu_fav_button);
    buttonFavorite.setImageDrawable(
        iconsCache.getIcon(
            menu.getFavActionIconId(),
            light ? R.color.icon_color : R.color.dashboard_subheader_text_dark));

    buildHeader();

    LinearLayout bottomLayout = (LinearLayout) view.findViewById(R.id.context_menu_bottom_view);
    bottomLayout.removeAllViews();
    buildBottomView();

    runLayoutListener();
  }
  private void buildHeader() {
    IconsCache iconsCache = getMyApplication().getIconsCache();
    boolean light = getMyApplication().getSettings().isLightContent();

    final View iconLayout = view.findViewById(R.id.context_menu_icon_layout);
    final ImageView iconView = (ImageView) view.findViewById(R.id.context_menu_icon_view);
    Drawable icon = menu.getLeftIcon();
    int iconId = menu.getLeftIconId();
    if (icon != null) {
      iconView.setImageDrawable(icon);
      iconLayout.setVisibility(View.VISIBLE);
    } else if (iconId != 0) {
      iconView.setImageDrawable(
          iconsCache.getIcon(iconId, light ? R.color.osmand_orange : R.color.osmand_orange_dark));
      iconLayout.setVisibility(View.VISIBLE);
    } else {
      iconLayout.setVisibility(View.GONE);
    }
    setAddressLocation();
  }
Пример #4
0
  private void updateToolbarActions() {
    TextView tv = (TextView) dashboardView.findViewById(R.id.toolbar_text);
    tv.setText("");
    boolean waypointsVisible =
        visibleType == DashboardType.WAYPOINTS || visibleType == DashboardType.WAYPOINTS_FLAT;
    boolean waypointsEdit = visibleType == DashboardType.WAYPOINTS_EDIT;
    if (waypointsVisible || waypointsEdit) {
      tv.setText(R.string.waypoints);
    } else if (visibleType == DashboardType.CONFIGURE_MAP) {
      tv.setText(R.string.configure_map);
    } else if (visibleType == DashboardType.CONFIGURE_SCREEN) {
      tv.setText(R.string.layer_map_appearance);
    }
    ImageView edit = (ImageView) dashboardView.findViewById(R.id.toolbar_edit);
    edit.setVisibility(View.GONE);
    ImageView sort = (ImageView) dashboardView.findViewById(R.id.toolbar_sort);
    sort.setVisibility(View.GONE);
    ImageView ok = (ImageView) dashboardView.findViewById(R.id.toolbar_ok);
    ok.setVisibility(View.GONE);
    ImageView flat = (ImageView) dashboardView.findViewById(R.id.toolbar_flat);
    flat.setVisibility(View.GONE);
    ImageView settingsButton = (ImageView) dashboardView.findViewById(R.id.toolbar_settings);
    settingsButton.setVisibility(View.GONE);
    IconsCache iconsCache = mapActivity.getMyApplication().getIconsCache();
    ImageView lst = (ImageView) dashboardView.findViewById(R.id.toolbar_list);
    lst.setVisibility(View.GONE);
    ImageView back = (ImageView) dashboardView.findViewById(R.id.toolbar_back);
    back.setImageDrawable(
        getMyApplication().getIconsCache().getIcon(R.drawable.abc_ic_ab_back_mtrl_am_alpha));
    back.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            backPressed();
          }
        });

    if (waypointsVisible && getMyApplication().getWaypointHelper().getAllPoints().size() > 0) {
      if (mapActivity.getMyApplication().getTargetPointsHelper().getIntermediatePoints().size()
          > 0) {
        sort.setVisibility(View.VISIBLE);
        sort.setOnClickListener(
            new View.OnClickListener() {

              @Override
              public void onClick(View v) {
                hideDashboard();
                IntermediatePointsDialog.openIntermediatePointsDialog(
                    mapActivity, getMyApplication(), true);
              }
            });
      }
      edit.setVisibility(View.VISIBLE);
      edit.setOnClickListener(
          new View.OnClickListener() {

            @Override
            public void onClick(View v) {
              setDashboardVisibility(true, DashboardType.WAYPOINTS_EDIT);
            }
          });
      if (getMyApplication().getWaypointHelper().isRouteCalculated()) {
        flat.setVisibility(View.VISIBLE);
        final boolean flatNow = visibleType == DashboardType.WAYPOINTS_FLAT;
        flat.setImageDrawable(
            iconsCache.getIcon(
                flatNow ? R.drawable.ic_tree_list_dark : R.drawable.ic_flat_list_dark));
        flat.setOnClickListener(
            new View.OnClickListener() {

              @Override
              public void onClick(View v) {
                setDashboardVisibility(
                    true,
                    flatNow ? DashboardType.WAYPOINTS : DashboardType.WAYPOINTS_FLAT,
                    previousVisibleType,
                    false);
              }
            });
      }
    }
    if (waypointsEdit) {
      ok.setVisibility(View.VISIBLE);
      ok.setOnClickListener(
          new View.OnClickListener() {

            @Override
            public void onClick(View v) {
              mapActivity
                  .getMyApplication()
                  .getWaypointHelper()
                  .removeVisibleLocationPoint(deletedPoints);
              hideDashboard();
            }
          });
    }
    if (visibleType == DashboardType.DASHBOARD || visibleType == DashboardType.LIST_MENU) {
      settingsButton.setVisibility(View.VISIBLE);
      settingsButton.setOnClickListener(
          new View.OnClickListener() {

            @Override
            public void onClick(View v) {
              new DashboardSettingsDialogFragment()
                  .show(mapActivity.getSupportFragmentManager(), "dashboard_settings");
            }
          });
      lst.setVisibility(View.VISIBLE);
      lst.setOnClickListener(
          new View.OnClickListener() {

            @Override
            public void onClick(View v) {
              hideDashboard(false);
              mapActivity.openDrawer();
            }
          });
    }
  }
Пример #5
0
 public Drawable getRowIcon(int iconId) {
   IconsCache iconsCache = app.getIconsCache();
   boolean light = app.getSettings().isLightContent();
   return iconsCache.getIcon(iconId, light ? R.color.icon_color : R.color.icon_color_light);
 }
  @TargetApi(Build.VERSION_CODES.HONEYCOMB)
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    screenHeight = getScreenHeight();
    skipHalfScreenStateLimit = screenHeight * SKIP_HALF_SCREEN_STATE_KOEF;

    viewHeight = screenHeight - getStatusBarHeight();

    fabPaddingTopPx = dpToPx(FAB_PADDING_TOP_DP);
    markerPaddingPx = dpToPx(MARKER_PADDING_DP);
    markerPaddingXPx = dpToPx(MARKER_PADDING_X_DP);

    menu = getMapActivity().getContextMenu();
    leftTitleButtonController = menu.getLeftTitleButtonController();
    rightTitleButtonController = menu.getRightTitleButtonController();
    topRightTitleButtonController = menu.getTopRightTitleButtonController();
    titleProgressController = menu.getTitleProgressController();

    map = getMapActivity().getMapView();
    RotatedTileBox box = map.getCurrentRotatedTileBox().copy();
    customMapCenter = menu.getMapCenter() != null;
    if (!customMapCenter) {
      mapCenter = box.getCenterLatLon();
      menu.setMapCenter(mapCenter);
      double markerLat = menu.getLatLon().getLatitude();
      double markerLon = menu.getLatLon().getLongitude();
      origMarkerX = (int) box.getPixXFromLatLon(markerLat, markerLon);
      origMarkerY = (int) box.getPixYFromLatLon(markerLat, markerLon);
    } else {
      mapCenter = menu.getMapCenter();
      origMarkerX = box.getCenterPixelX();
      origMarkerY = box.getCenterPixelY();
    }

    IconsCache iconsCache = getMyApplication().getIconsCache();
    boolean light = getMyApplication().getSettings().isLightContent();

    view = inflater.inflate(R.layout.map_context_menu_fragment, container, false);
    mainView = view.findViewById(R.id.context_menu_main);

    // Left title button
    final Button leftTitleButton = (Button) view.findViewById(R.id.title_button);
    if (leftTitleButtonController != null) {
      leftTitleButton.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              leftTitleButtonController.buttonPressed();
            }
          });
    }

    // Right title button
    final Button rightTitleButton = (Button) view.findViewById(R.id.title_button_right);
    if (rightTitleButtonController != null) {
      rightTitleButton.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              rightTitleButtonController.buttonPressed();
            }
          });
    }

    // Top Right title button
    final Button topRightTitleButton = (Button) view.findViewById(R.id.title_button_top_right);
    if (topRightTitleButtonController != null) {
      topRightTitleButton.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              topRightTitleButtonController.buttonPressed();
            }
          });
    }

    // Progress bar
    if (titleProgressController != null) {
      final ImageView progressButton = (ImageView) view.findViewById(R.id.progressButton);
      progressButton.setImageDrawable(
          iconsCache.getIcon(
              R.drawable.ic_action_remove_dark,
              light ? R.color.icon_color : R.color.dashboard_subheader_text_dark));
      progressButton.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              titleProgressController.buttonPressed();
            }
          });
    }

    menu.updateData();
    updateButtonsAndProgress();

    if (menu.isLandscapeLayout()) {
      mainView.setLayoutParams(
          new FrameLayout.LayoutParams(
              dpToPx(menu.getLandscapeWidthDp()), ViewGroup.LayoutParams.MATCH_PARENT));
      View fabContainer = view.findViewById(R.id.context_menu_fab_container);
      fabContainer.setLayoutParams(
          new FrameLayout.LayoutParams(
              dpToPx(menu.getLandscapeWidthDp()), ViewGroup.LayoutParams.MATCH_PARENT));
    }

    runLayoutListener();

    final GestureDetector singleTapDetector =
        new GestureDetector(view.getContext(), new SingleTapConfirm());

    final View.OnTouchListener slideTouchListener =
        new View.OnTouchListener() {
          private float dy;
          private float dyMain;
          private VelocityTracker velocity;
          private boolean slidingUp;
          private boolean slidingDown;

          private float velocityY;
          private float maxVelocityY;

          private boolean hasMoved;

          @Override
          public boolean onTouch(View v, MotionEvent event) {

            if (singleTapDetector.onTouchEvent(event)) {
              showOnMap(menu.getLatLon(), true, false);

              if (hasMoved) {
                applyPosY(getViewY(), false, false, 0, 0);
              }
              return true;
            }

            if (menu.isLandscapeLayout()) {
              return true;
            }

            switch (event.getAction()) {
              case MotionEvent.ACTION_DOWN:
                hasMoved = false;
                dy = event.getY();
                dyMain = getViewY();
                velocity = VelocityTracker.obtain();
                velocityY = 0;
                maxVelocityY = 0;
                velocity.addMovement(event);
                break;

              case MotionEvent.ACTION_MOVE:
                hasMoved = true;
                float y = event.getY();
                float newY = getViewY() + (y - dy);
                setViewY((int) newY, false, false);

                menuFullHeight = view.getHeight() - (int) newY + 10;
                if (!oldAndroid()) {
                  ViewGroup.LayoutParams lp = mainView.getLayoutParams();
                  lp.height = Math.max(menuFullHeight, menuTitleHeight);
                  mainView.setLayoutParams(lp);
                  mainView.requestLayout();
                }

                velocity.addMovement(event);
                velocity.computeCurrentVelocity(1000);
                velocityY = Math.abs(velocity.getYVelocity());
                if (velocityY > maxVelocityY) maxVelocityY = velocityY;

                break;

              case MotionEvent.ACTION_UP:
              case MotionEvent.ACTION_CANCEL:
                int currentY = getViewY();

                slidingUp = Math.abs(maxVelocityY) > 500 && (currentY - dyMain) < -50;
                slidingDown = Math.abs(maxVelocityY) > 500 && (currentY - dyMain) > 50;

                velocity.recycle();

                boolean skipHalfScreenState =
                    Math.abs(currentY - dyMain) > skipHalfScreenStateLimit;
                changeMenuState(currentY, skipHalfScreenState, slidingUp, slidingDown);

                break;
            }
            return true;
          }
        };

    View topView = view.findViewById(R.id.context_menu_top_view);
    topView.setOnTouchListener(slideTouchListener);
    View topShadowView = view.findViewById(R.id.context_menu_top_shadow);
    topShadowView.setOnTouchListener(slideTouchListener);
    View topShadowAllView = view.findViewById(R.id.context_menu_top_shadow_all);
    topShadowAllView.setOnTouchListener(
        new View.OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {
            if (event.getY() <= dpToPx(SHADOW_HEIGHT_TOP_DP)
                || event.getAction() != MotionEvent.ACTION_DOWN)
              return slideTouchListener.onTouch(v, event);
            else return false;
          }
        });

    buildHeader();

    // FAB
    fabView = (ImageView) view.findViewById(R.id.context_menu_fab_view);
    if (menu.fabVisible()) {
      fabView.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              menu.fabPressed();
            }
          });
    } else {
      fabView.setVisibility(View.GONE);
    }

    if (!menu.buttonsVisible()) {
      View buttonsTopBorder = view.findViewById(R.id.buttons_top_border);
      View buttons = view.findViewById(R.id.context_menu_buttons);
      buttonsTopBorder.setVisibility(View.GONE);
      buttons.setVisibility(View.GONE);
    }

    // Action buttons
    final ImageButton buttonFavorite =
        (ImageButton) view.findViewById(R.id.context_menu_fav_button);
    buttonFavorite.setImageDrawable(
        iconsCache.getIcon(
            menu.getFavActionIconId(),
            light ? R.color.icon_color : R.color.dashboard_subheader_text_dark));
    buttonFavorite.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            menu.buttonFavoritePressed();
          }
        });

    final ImageButton buttonWaypoint =
        (ImageButton) view.findViewById(R.id.context_menu_route_button);
    buttonWaypoint.setImageDrawable(
        iconsCache.getIcon(
            R.drawable.map_action_flag_dark,
            light ? R.color.icon_color : R.color.dashboard_subheader_text_dark));
    buttonWaypoint.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            menu.buttonWaypointPressed();
          }
        });

    final ImageButton buttonShare = (ImageButton) view.findViewById(R.id.context_menu_share_button);
    buttonShare.setImageDrawable(
        iconsCache.getIcon(
            R.drawable.map_action_gshare_dark,
            light ? R.color.icon_color : R.color.dashboard_subheader_text_dark));
    buttonShare.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            menu.buttonSharePressed();
          }
        });

    final ImageButton buttonMore = (ImageButton) view.findViewById(R.id.context_menu_more_button);
    buttonMore.setImageDrawable(
        iconsCache.getIcon(
            R.drawable.map_overflow_menu_white,
            light ? R.color.icon_color : R.color.dashboard_subheader_text_dark));
    buttonMore.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            menu.buttonMorePressed();
          }
        });

    buildBottomView();

    getMapActivity().getMapLayers().getMapControlsLayer().setControlsClickable(false);

    return view;
  }