Remove unnecessary method

This commit is contained in:
Vitaliy 2020-08-01 15:53:41 +03:00
parent df0dc024f8
commit c334cfa62e
4 changed files with 40 additions and 83 deletions

View file

@ -320,10 +320,8 @@ public class Algorithms {
* exception. Supported formats are:
* #RRGGBB
* #AARRGGBB
* 'red', 'blue', 'green', 'black', 'white', 'gray', 'cyan', 'magenta',
* 'yellow', 'lightgray', 'darkgray'
*/
public static int parseColor(String colorString) {
public static int parseColor(String colorString) throws IllegalArgumentException {
if (colorString.charAt(0) == '#') {
// Use a long to avoid rollovers on #ffXXXXXX
if (colorString.length() == 4) {

View file

@ -520,12 +520,12 @@ public class GpxSelectionHelper {
}
GPXFile gpx = GPXUtilities.loadGPXFile(fl);
if (obj.has(COLOR)) {
int clr = Algorithms.parseColor(obj.getString(COLOR));
int clr = parseColor(obj.getString(COLOR));
gpx.setColor(clr);
}
for (GradientScaleType scaleType : GradientScaleType.values()) {
if (obj.has(scaleType.getColorTypeName())) {
int clr = Algorithms.parseColor(obj.getString(scaleType.getColorTypeName()));
int clr = parseColor(obj.getString(scaleType.getColorTypeName()));
gpx.setGradientScaleColor(scaleType.getColorTypeName(), clr);
}
}
@ -567,6 +567,14 @@ public class GpxSelectionHelper {
}
}
private int parseColor(String color) {
try {
return Algorithms.isEmpty(color) ? 0 : Algorithms.parseColor(color);
} catch (IllegalArgumentException e) {
return 0;
}
}
private void saveCurrentSelections() {
JSONArray ar = new JSONArray();
for (SelectedGpxFile s : selectedGPXFiles) {

View file

@ -26,6 +26,7 @@ import net.osmand.plus.base.MenuBottomSheetDialogFragment;
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log;
@ -103,7 +104,13 @@ public class CustomColorBottomSheet extends MenuBottomSheetDialogFragment implem
@Override
public void afterTextChanged(Editable s) {
if (hexEditText.isFocused()) {
int color = parseColorString(s.toString());
int color = colorPicker.getColor();
try {
color = Algorithms.parseColor("#" + s.toString());
} catch (IllegalArgumentException e) {
hexEditText.setError(getString(R.string.wrong_input));
log.error(e);
}
if (color != colorPicker.getColor()) {
fromEditText = true;
colorPicker.setColor(color, true);
@ -166,60 +173,6 @@ public class CustomColorBottomSheet extends MenuBottomSheetDialogFragment implem
}
}
private static int parseColorString(String colorString) throws NumberFormatException {
int a, r, g, b = 0;
if (colorString.startsWith("#")) {
colorString = colorString.substring(1);
}
if (colorString.length() == 0) {
r = 0;
a = 255;
g = 0;
} else if (colorString.length() <= 2) {
a = 255;
r = 0;
b = Integer.parseInt(colorString, 16);
g = 0;
} else if (colorString.length() == 3) {
a = 255;
r = Integer.parseInt(colorString.substring(0, 1), 16);
g = Integer.parseInt(colorString.substring(1, 2), 16);
b = Integer.parseInt(colorString.substring(2, 3), 16);
} else if (colorString.length() == 4) {
a = 255;
r = Integer.parseInt(colorString.substring(0, 2), 16);
g = r;
r = 0;
b = Integer.parseInt(colorString.substring(2, 4), 16);
} else if (colorString.length() == 5) {
a = 255;
r = Integer.parseInt(colorString.substring(0, 1), 16);
g = Integer.parseInt(colorString.substring(1, 3), 16);
b = Integer.parseInt(colorString.substring(3, 5), 16);
} else if (colorString.length() == 6) {
a = 255;
r = Integer.parseInt(colorString.substring(0, 2), 16);
g = Integer.parseInt(colorString.substring(2, 4), 16);
b = Integer.parseInt(colorString.substring(4, 6), 16);
} else if (colorString.length() == 7) {
a = Integer.parseInt(colorString.substring(0, 1), 16);
r = Integer.parseInt(colorString.substring(1, 3), 16);
g = Integer.parseInt(colorString.substring(3, 5), 16);
b = Integer.parseInt(colorString.substring(5, 7), 16);
} else if (colorString.length() == 8) {
a = Integer.parseInt(colorString.substring(0, 2), 16);
r = Integer.parseInt(colorString.substring(2, 4), 16);
g = Integer.parseInt(colorString.substring(4, 6), 16);
b = Integer.parseInt(colorString.substring(6, 8), 16);
} else {
b = -1;
g = -1;
r = -1;
a = -1;
}
return Color.argb(a, r, g, b);
}
public interface ColorPickerListener {
void onColorSelected(@ColorInt int prevColor, @ColorInt int newColor);

View file

@ -379,7 +379,8 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
for (int k = 0; k < items.size(); k++) {
GpxDisplayItem i = items.get(k);
WptPt point = i.locationEnd;
if (point != null) {
if (point != null && point.lat >= latLonBounds.bottom && point.lat <= latLonBounds.top
&& point.lon >= latLonBounds.left && point.lon <= latLonBounds.right) {
float x = tileBox.getPixXFromLatLon(point.lat, point.lon);
float y = tileBox.getPixYFromLatLon(point.lat, point.lon);
if (px != -1 || py != -1) {
@ -389,8 +390,6 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
}
px = x;
py = y;
if (point.lat >= latLonBounds.bottom && point.lat <= latLonBounds.top
&& point.lon >= latLonBounds.left && point.lon <= latLonBounds.right) {
String name = i.splitName;
if (name != null) {
int ind = name.indexOf(' ');
@ -415,7 +414,6 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
}
}
}
}
private void drawDirectionArrows(Canvas canvas, RotatedTileBox tileBox, List<SelectedGpxFile> selectedGPXFiles) {
if (!tileBox.isZoomAnimated()) {