From 2ff8ff823074d2a5ac3940b44ed8638a522fc660 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Sun, 4 Aug 2013 13:24:00 +0200 Subject: [PATCH] Fix exceptions --- .../src/net/osmand/data/AmenityType.java | 11 +-- .../src/net/osmand/osm/MapRenderingTypes.java | 4 +- .../activities/search/SearchPOIActivity.java | 2 +- .../SettingsAudioVideoActivity.java | 86 +++++++++---------- 4 files changed, 52 insertions(+), 51 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/data/AmenityType.java b/OsmAnd-java/src/net/osmand/data/AmenityType.java index b865c09358..ca33c78a73 100644 --- a/OsmAnd-java/src/net/osmand/data/AmenityType.java +++ b/OsmAnd-java/src/net/osmand/data/AmenityType.java @@ -43,12 +43,13 @@ public enum AmenityType { this.defaultTag = defaultTag; } - public static AmenityType fromString(String s){ - try { - return AmenityType.valueOf(s.toUpperCase()); - } catch (IllegalArgumentException e) { - return AmenityType.OTHER; + public static AmenityType fromString(String s) { + for (AmenityType t : values()) { + if (t.name().equalsIgnoreCase(s)) { + return t; + } } + return OTHER; } public String getDefaultTag() { diff --git a/OsmAnd-java/src/net/osmand/osm/MapRenderingTypes.java b/OsmAnd-java/src/net/osmand/osm/MapRenderingTypes.java index 73ec2ac6be..655e7069b0 100644 --- a/OsmAnd-java/src/net/osmand/osm/MapRenderingTypes.java +++ b/OsmAnd-java/src/net/osmand/osm/MapRenderingTypes.java @@ -248,7 +248,7 @@ public class MapRenderingTypes { rtype.value = null; } if (poiParentCategory != null) { - rtype.poiCategory = AmenityType.valueOf(poiParentCategory.toUpperCase()); + rtype.poiCategory = AmenityType.fromString(poiParentCategory); rtype.poiSpecified = true; } if (poiParentPrefix != null) { @@ -305,7 +305,7 @@ public class MapRenderingTypes { String tag = parser.getAttributeValue("","poi_tag"); if (tag != null) { AmenityRuleType rtype = new AmenityRuleType(); - rtype.poiCategory = AmenityType.valueOf(poiParentCategory.toUpperCase()); + rtype.poiCategory = AmenityType.fromString(poiParentCategory); rtype.poiSpecified = true; rtype.relation = Boolean.parseBoolean(parser.getAttributeValue("", "relation")); rtype.poiPrefix = poiParentPrefix; diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java index d927b1fe43..245bce36fd 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java @@ -425,7 +425,7 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa if (location == null) { title = R.string.search_poi_location; enabled = false; - } else if (!isNameFinderFilter() && !isSearchByNameFilter()) { + } else if (filter != null && !isNameFinderFilter() && !isSearchByNameFilter()) { title = R.string.search_POI_level_btn; enabled = (taskAlreadyFinished || currentSearchTask.getStatus() != Status.RUNNING) && filter.isSearchFurtherAvailable(); } else if (filter != null) { diff --git a/OsmAnd/src/net/osmand/plus/audionotes/SettingsAudioVideoActivity.java b/OsmAnd/src/net/osmand/plus/audionotes/SettingsAudioVideoActivity.java index 2227b60a2a..931a38d2ad 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/SettingsAudioVideoActivity.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/SettingsAudioVideoActivity.java @@ -47,52 +47,52 @@ public class SettingsAudioVideoActivity extends SettingsBaseActivity { ListPreference defAct = createListPreference(p.AV_DEFAULT_ACTION, entries, intValues, R.string.av_widget_action, R.string.av_widget_action_descr); grp.addPreference(defAct); - - // camera type settings: - grp.addPreference(createCheckBoxPreference(p.AV_EXTERNAL_PHOTO_CAM, R.string.av_use_external_camera, - R.string.av_use_external_camera_descr)); - // focus mode settings: - // show in menu only suppoted modes: final Camera cam = openCamera(); - Parameters parameters = cam.getParameters(); - List sfm = parameters.getSupportedFocusModes(); - List items = new ArrayList(); - List itemsValues = new ArrayList(); - // filtering known types for translate and set index: - for (int index = 0; index < sfm.size(); index++) { - if (sfm.get(index).equals("auto")) { - items.add(getString(R.string.av_camera_focus_auto)); - itemsValues.add(AV_CAMERA_FOCUS_AUTO); - } else if (sfm.get(index).equals("fixed")) { - items.add(getString(R.string.av_camera_focus_hiperfocal)); - itemsValues.add(AV_CAMERA_FOCUS_HIPERFOCAL); - } else if (sfm.get(index).equals("edof")) { - items.add(getString(R.string.av_camera_focus_edof)); - itemsValues.add(AV_CAMERA_FOCUS_EDOF); - } else if (sfm.get(index).equals("infinity")) { - items.add(getString(R.string.av_camera_focus_infinity)); - itemsValues.add(AV_CAMERA_FOCUS_INFINITY); - } else if (sfm.get(index).equals("macro")) { - items.add(getString(R.string.av_camera_focus_macro)); - itemsValues.add(AV_CAMERA_FOCUS_MACRO); - } else if (sfm.get(index).equals("continuous-picture")) { - items.add(getString(R.string.av_camera_focus_continuous)); - itemsValues.add(AV_CAMERA_FOCUS_CONTINUOUS); + if (cam != null) { + // camera type settings: + grp.addPreference(createCheckBoxPreference(p.AV_EXTERNAL_PHOTO_CAM, R.string.av_use_external_camera, + R.string.av_use_external_camera_descr)); + // focus mode settings: + // show in menu only suppoted modes: + + Parameters parameters = cam.getParameters(); + List sfm = parameters.getSupportedFocusModes(); + List items = new ArrayList(); + List itemsValues = new ArrayList(); + // filtering known types for translate and set index: + for (int index = 0; index < sfm.size(); index++) { + if (sfm.get(index).equals("auto")) { + items.add(getString(R.string.av_camera_focus_auto)); + itemsValues.add(AV_CAMERA_FOCUS_AUTO); + } else if (sfm.get(index).equals("fixed")) { + items.add(getString(R.string.av_camera_focus_hiperfocal)); + itemsValues.add(AV_CAMERA_FOCUS_HIPERFOCAL); + } else if (sfm.get(index).equals("edof")) { + items.add(getString(R.string.av_camera_focus_edof)); + itemsValues.add(AV_CAMERA_FOCUS_EDOF); + } else if (sfm.get(index).equals("infinity")) { + items.add(getString(R.string.av_camera_focus_infinity)); + itemsValues.add(AV_CAMERA_FOCUS_INFINITY); + } else if (sfm.get(index).equals("macro")) { + items.add(getString(R.string.av_camera_focus_macro)); + itemsValues.add(AV_CAMERA_FOCUS_MACRO); + } else if (sfm.get(index).equals("continuous-picture")) { + items.add(getString(R.string.av_camera_focus_continuous)); + itemsValues.add(AV_CAMERA_FOCUS_CONTINUOUS); + } } + entries = items.toArray(entries); + intValues = itemsValues.toArray(intValues); + if (entries.length > 0) { + ListPreference camFocus = createListPreference(p.AV_CAMERA_FOCUS_TYPE, entries, intValues, R.string.av_camera_focus, + R.string.av_camera_focus_descr); + grp.addPreference(camFocus); + } + // play sound on success photo: + grp.addPreference(createCheckBoxPreference(p.AV_PHOTO_PLAY_SOUND, R.string.av_photo_play_sound, + R.string.av_photo_play_sound_descr)); + cam.release(); } - entries = items.toArray(entries); - intValues = itemsValues.toArray(intValues); - if (entries.length > 0) { - ListPreference camFocus = createListPreference(p.AV_CAMERA_FOCUS_TYPE, entries, intValues, R.string.av_camera_focus, - R.string.av_camera_focus_descr); - grp.addPreference(camFocus); - } - // play sound on success photo: - grp.addPreference(createCheckBoxPreference(p.AV_PHOTO_PLAY_SOUND, R.string.av_photo_play_sound, - R.string.av_photo_play_sound_descr)); - cam.release(); - - // video settings: grp.addPreference(createCheckBoxPreference(p.AV_EXTERNAL_RECORDER, R.string.av_use_external_recorder, R.string.av_use_external_recorder_descr));