Codestyle: add braces in "if" and "for" statements, remove trailing whitespace

This commit is contained in:
Roman Inflianskas 2016-04-23 16:26:21 +03:00
parent 2390c95a1b
commit 6944f76748
8 changed files with 65 additions and 44 deletions

View file

@ -217,10 +217,10 @@ public class AppInitializer implements IProgress {
private void checkMapUpdates() { private void checkMapUpdates() {
long diff = System.currentTimeMillis() - app.getSettings().LAST_CHECKED_UPDATES.get(); long diff = System.currentTimeMillis() - app.getSettings().LAST_CHECKED_UPDATES.get();
if(diff >= 2 * 24 * 60 * 60l && new Random().nextInt(5) == 0 && if (diff >= 2 * 24 * 60 * 60l && new Random().nextInt(5) == 0 &&
app.getSettings().isInternetConnectionAvailable()) { app.getSettings().isInternetConnectionAvailable()) {
app.getDownloadThread().runReloadIndexFiles(); app.getDownloadThread().runReloadIndexFiles();
} else if(Version.isDeveloperVersion(app)) { } else if (Version.isDeveloperVersion(app)) {
// app.getDownloadThread().runReloadIndexFiles(); // app.getDownloadThread().runReloadIndexFiles();
} }
} }

View file

@ -2328,8 +2328,9 @@ public class OsmandSettings {
public Set<String> getSelectedPoiFilters() { public Set<String> getSelectedPoiFilters() {
Set<String> result = new LinkedHashSet<>(); Set<String> result = new LinkedHashSet<>();
String filtersId = SELECTED_POI_FILTER_FOR_MAP.get(); String filtersId = SELECTED_POI_FILTER_FOR_MAP.get();
if (filtersId != null) if (filtersId != null) {
Collections.addAll(result, filtersId.split(",")); Collections.addAll(result, filtersId.split(","));
}
return result; return result;
} }

View file

@ -307,10 +307,11 @@ public class MapActivityLayers {
builder.setListener(new ContextMenuAdapter.ItemClickListener() { builder.setListener(new ContextMenuAdapter.ItemClickListener() {
@Override @Override
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int position, boolean isChecked) { public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int position, boolean isChecked) {
if (isChecked) if (isChecked) {
getApplication().getPoiFilters().addSelectedPoiFilter(f); getApplication().getPoiFilters().addSelectedPoiFilter(f);
else } else {
getApplication().getPoiFilters().removeSelectedPoiFilter(f); getApplication().getPoiFilters().removeSelectedPoiFilter(f);
}
return true; return true;
} }
}); });

View file

@ -828,8 +828,9 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa
List<String> attributes = new ArrayList<String>(); List<String> attributes = new ArrayList<String>();
NavigationInfo navigationInfo = app.getLocationProvider().getNavigationInfo(); NavigationInfo navigationInfo = app.getLocationProvider().getNavigationInfo();
String direction = navigationInfo.getDirectionString(amenity.getLocation(), heading); String direction = navigationInfo.getDirectionString(amenity.getLocation(), heading);
if (direction != null) if (direction != null) {
attributes.add(direction); attributes.add(direction);
}
String[] as = OsmAndFormatter.getAmenityDescriptionContent(getMyApplication(), amenity, false).split("\n"); String[] as = OsmAndFormatter.getAmenityDescriptionContent(getMyApplication(), amenity, false).split("\n");
for (String s : as) { for (String s : as) {
attributes.add(s.replace(':', ' ')); attributes.add(s.replace(':', ' '));

View file

@ -542,8 +542,9 @@ public class WaypointHelper {
if (app.getPoiFilters().isShowingAnyPoi()) { if (app.getPoiFilters().isShowingAnyPoi()) {
final List<Location> locs = route.getImmutableAllLocations(); final List<Location> locs = route.getImmutableAllLocations();
List<Amenity> amenities = new ArrayList<>(); List<Amenity> amenities = new ArrayList<>();
for (PoiUIFilter pf : app.getPoiFilters().getSelectedPoiFilters()) for (PoiUIFilter pf : app.getPoiFilters().getSelectedPoiFilters()) {
amenities.addAll(pf.searchAmenitiesOnThePath(locs, poiSearchDeviationRadius)); amenities.addAll(pf.searchAmenitiesOnThePath(locs, poiSearchDeviationRadius));
}
for (Amenity a : amenities) { for (Amenity a : amenities) {
AmenityRoutePoint rp = a.getRoutePoint(); AmenityRoutePoint rp = a.getRoutePoint();
int i = locs.indexOf(rp.pointA); int i = locs.indexOf(rp.pointA);
@ -760,18 +761,23 @@ public class WaypointHelper {
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (this == obj) if (this == obj) {
return true; return true;
if (obj == null) }
if (obj == null) {
return false; return false;
if (getClass() != obj.getClass()) }
if (getClass() != obj.getClass()) {
return false; return false;
}
LocationPointWrapper other = (LocationPointWrapper) obj; LocationPointWrapper other = (LocationPointWrapper) obj;
if (point == null) { if (point == null) {
if (other.point != null) if (other.point != null) {
return false; return false;
} else if (!point.equals(other.point)) }
} else if (!point.equals(other.point)) {
return false; return false;
}
return true; return true;
} }

View file

@ -100,7 +100,7 @@ public class PoiFiltersHelper {
if (localWikiPoiFilter == null){ if (localWikiPoiFilter == null){
PoiType place = application.getPoiTypes().getPoiTypeByKey("wiki_place"); PoiType place = application.getPoiTypes().getPoiTypeByKey("wiki_place");
if (place != null && !Algorithms.isEmpty(application.getLanguage())) { if (place != null && !Algorithms.isEmpty(application.getLanguage())) {
PoiUIFilter filter = new PoiUIFilter(place, application, " " + PoiUIFilter filter = new PoiUIFilter(place, application, " " +
application.getLangTranslation(application.getLanguage())); //$NON-NLS-1$ application.getLangTranslation(application.getLanguage())); //$NON-NLS-1$
filter.setSavedFilterByName("wiki:lang:"+application.getLanguage()); filter.setSavedFilterByName("wiki:lang:"+application.getLanguage());
filter.setStandardFilter(true); filter.setStandardFilter(true);
@ -189,9 +189,11 @@ public class PoiFiltersHelper {
List<PoiUIFilter> result = new ArrayList<>(); List<PoiUIFilter> result = new ArrayList<>();
List<PoiUIFilter> filters = Arrays.asList(getCustomPOIFilter(), // getShowAllPOIFilter(), List<PoiUIFilter> filters = Arrays.asList(getCustomPOIFilter(), // getShowAllPOIFilter(),
getSearchByNamePOIFilter(), getNominatimPOIFilter(), getNominatimAddressFilter()); getSearchByNamePOIFilter(), getNominatimPOIFilter(), getNominatimAddressFilter());
for (PoiUIFilter f : filters) for (PoiUIFilter f : filters) {
if (f != null && !f.isEmpty()) if (f != null && !f.isEmpty()) {
result.add(f); result.add(f);
}
}
return result; return result;
} }
@ -222,21 +224,21 @@ public class PoiFiltersHelper {
if(!application.getPoiTypes().isInit()) { if(!application.getPoiTypes().isInit()) {
return null; return null;
} }
return new PoiFilterDbHelper(application.getPoiTypes(), application); return new PoiFilterDbHelper(application.getPoiTypes(), application);
} }
public boolean removePoiFilter(PoiUIFilter filter){ public boolean removePoiFilter(PoiUIFilter filter){
if(filter.getFilterId().equals(PoiUIFilter.CUSTOM_FILTER_ID) || if (filter.getFilterId().equals(PoiUIFilter.CUSTOM_FILTER_ID) ||
filter.getFilterId().equals(PoiUIFilter.BY_NAME_FILTER_ID) || filter.getFilterId().equals(PoiUIFilter.BY_NAME_FILTER_ID) ||
filter.getFilterId().startsWith(PoiUIFilter.STD_PREFIX)){ filter.getFilterId().startsWith(PoiUIFilter.STD_PREFIX)) {
return false; return false;
} }
PoiFilterDbHelper helper = openDbHelper(); PoiFilterDbHelper helper = openDbHelper();
if(helper == null){ if (helper == null) {
return false; return false;
} }
boolean res = helper.deleteFilter(helper.getWritableDatabase(), filter); boolean res = helper.deleteFilter(helper.getWritableDatabase(), filter);
if(res){ if (res) {
ArrayList<PoiUIFilter> copy = new ArrayList<>(cacheTopStandardFilters); ArrayList<PoiUIFilter> copy = new ArrayList<>(cacheTopStandardFilters);
copy.remove(filter); copy.remove(filter);
cacheTopStandardFilters = copy; cacheTopStandardFilters = copy;
@ -269,7 +271,7 @@ public class PoiFiltersHelper {
} }
public boolean editPoiFilter(PoiUIFilter filter) { public boolean editPoiFilter(PoiUIFilter filter) {
if (filter.getFilterId().equals(PoiUIFilter.CUSTOM_FILTER_ID) || if (filter.getFilterId().equals(PoiUIFilter.CUSTOM_FILTER_ID) ||
filter.getFilterId().equals(PoiUIFilter.BY_NAME_FILTER_ID) || filter.getFilterId().startsWith(PoiUIFilter.STD_PREFIX)) { filter.getFilterId().equals(PoiUIFilter.BY_NAME_FILTER_ID) || filter.getFilterId().startsWith(PoiUIFilter.STD_PREFIX)) {
return false; return false;
} }
@ -309,11 +311,11 @@ public class PoiFiltersHelper {
public String getFiltersName(Set<PoiUIFilter> filters) { public String getFiltersName(Set<PoiUIFilter> filters) {
if (filters.isEmpty()) { if (filters.isEmpty()) {
return application.getResources().getString(R.string.shared_string_none); return application.getResources().getString(R.string.shared_string_none);
} } else {
else {
List<String> names = new ArrayList<>(); List<String> names = new ArrayList<>();
for (PoiUIFilter filter : filters) for (PoiUIFilter filter : filters) {
names.add(filter.getName()); names.add(filter.getName());
}
return android.text.TextUtils.join(", ", names); return android.text.TextUtils.join(", ", names);
} }
} }
@ -327,22 +329,26 @@ public class PoiFiltersHelper {
} }
public boolean isPoiFilterSelected(String filterId) { public boolean isPoiFilterSelected(String filterId) {
for (PoiUIFilter filter: selectedPoiFilters) for (PoiUIFilter filter: selectedPoiFilters) {
if (filter.filterId.equals(filterId)) if (filter.filterId.equals(filterId)) {
return true; return true;
}
}
return false; return false;
} }
public void loadSelectedPoiFilters() { public void loadSelectedPoiFilters() {
Set<String> filters = application.getSettings().getSelectedPoiFilters(); Set<String> filters = application.getSettings().getSelectedPoiFilters();
for (String f: filters) for (String f: filters) {
selectedPoiFilters.add(getFilterById(f)); selectedPoiFilters.add(getFilterById(f));
}
} }
public void saveSelectedPoiFilters() { public void saveSelectedPoiFilters() {
Set<String> filters = new HashSet<>(); Set<String> filters = new HashSet<>();
for (PoiUIFilter f: selectedPoiFilters) for (PoiUIFilter f: selectedPoiFilters) {
filters.add(f.filterId); filters.add(f.filterId);
}
application.getSettings().setSelectedPoiFilters(filters); application.getSettings().setSelectedPoiFilters(filters);
} }
@ -356,8 +362,8 @@ public class PoiFiltersHelper {
private static final String FILTER_COL_FILTERBYNAME = "filterbyname"; //$NON-NLS-1$ private static final String FILTER_COL_FILTERBYNAME = "filterbyname"; //$NON-NLS-1$
private static final String FILTER_TABLE_CREATE = "CREATE TABLE " + FILTER_NAME + " (" + //$NON-NLS-1$ //$NON-NLS-2$ private static final String FILTER_TABLE_CREATE = "CREATE TABLE " + FILTER_NAME + " (" + //$NON-NLS-1$ //$NON-NLS-2$
FILTER_COL_NAME + ", " + FILTER_COL_ID + ", " + FILTER_COL_FILTERBYNAME + ");"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ FILTER_COL_NAME + ", " + FILTER_COL_ID + ", " + FILTER_COL_FILTERBYNAME + ");"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
private static final String CATEGORIES_NAME = "categories"; //$NON-NLS-1$ private static final String CATEGORIES_NAME = "categories"; //$NON-NLS-1$
private static final String CATEGORIES_FILTER_ID = "filter_id"; //$NON-NLS-1$ private static final String CATEGORIES_FILTER_ID = "filter_id"; //$NON-NLS-1$
private static final String CATEGORIES_COL_CATEGORY = "category"; //$NON-NLS-1$ private static final String CATEGORIES_COL_CATEGORY = "category"; //$NON-NLS-1$
@ -372,7 +378,7 @@ public class PoiFiltersHelper {
this.mapPoiTypes = mapPoiTypes; this.mapPoiTypes = mapPoiTypes;
this.context = context; this.context = context;
} }
public SQLiteConnection getWritableDatabase() { public SQLiteConnection getWritableDatabase() {
return openConnection(false); return openConnection(false);
} }
@ -418,7 +424,7 @@ public class PoiFiltersHelper {
} }
conn.setVersion(newVersion); conn.setVersion(newVersion);
} }
private void deleteOldFilters(SQLiteConnection conn) { private void deleteOldFilters(SQLiteConnection conn) {
for (String toDel : DEL) { for (String toDel : DEL) {
deleteFilter(conn, "user_" + toDel); deleteFilter(conn, "user_" + toDel);
@ -452,7 +458,7 @@ public class PoiFiltersHelper {
} }
return false; return false;
} }
protected List<PoiUIFilter> getFilters(SQLiteConnection conn){ protected List<PoiUIFilter> getFilters(SQLiteConnection conn){
ArrayList<PoiUIFilter> list = new ArrayList<PoiUIFilter>(); ArrayList<PoiUIFilter> list = new ArrayList<PoiUIFilter>();
if(conn != null){ if(conn != null){
@ -497,7 +503,7 @@ public class PoiFiltersHelper {
} }
return list; return list;
} }
protected boolean editFilter(SQLiteConnection conn, PoiUIFilter filter) { protected boolean editFilter(SQLiteConnection conn, PoiUIFilter filter) {
if (conn != null) { if (conn != null) {
conn.execSQL("DELETE FROM " + CATEGORIES_NAME + " WHERE " + CATEGORIES_FILTER_ID + " = ?", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ conn.execSQL("DELETE FROM " + CATEGORIES_NAME + " WHERE " + CATEGORIES_FILTER_ID + " = ?", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
@ -513,7 +519,7 @@ public class PoiFiltersHelper {
db.execSQL("UPDATE " + FILTER_NAME + " SET " + FILTER_COL_FILTERBYNAME + " = ?, " + FILTER_COL_NAME + " = ? " + " WHERE " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ db.execSQL("UPDATE " + FILTER_NAME + " SET " + FILTER_COL_FILTERBYNAME + " = ?, " + FILTER_COL_NAME + " = ? " + " WHERE " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
+ FILTER_COL_ID + "= ?", new Object[] { filter.getFilterByName(), filter.getName(), filter.getFilterId() }); //$NON-NLS-1$ + FILTER_COL_ID + "= ?", new Object[] { filter.getFilterByName(), filter.getName(), filter.getFilterId() }); //$NON-NLS-1$
} }
protected boolean deleteFilter(SQLiteConnection db, PoiUIFilter p){ protected boolean deleteFilter(SQLiteConnection db, PoiUIFilter p){
String key = p.getFilterId(); String key = p.getFilterId();
return deleteFilter(db, key); return deleteFilter(db, key);
@ -528,7 +534,7 @@ public class PoiFiltersHelper {
} }
return false; return false;
} }
} }

View file

@ -496,14 +496,17 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable<PoiUIFilter>
public static void combineStandardPoiFilters(Set<PoiUIFilter> filters, OsmandApplication app) { public static void combineStandardPoiFilters(Set<PoiUIFilter> filters, OsmandApplication app) {
Set<PoiUIFilter> standardFilters = new TreeSet<>(); Set<PoiUIFilter> standardFilters = new TreeSet<>();
for (PoiUIFilter filter : filters) for (PoiUIFilter filter : filters) {
if (filter.isStandardFilter() && filter.filterId.startsWith(PoiUIFilter.STD_PREFIX)) if (filter.isStandardFilter() && filter.filterId.startsWith(PoiUIFilter.STD_PREFIX)) {
standardFilters.add(filter); standardFilters.add(filter);
}
}
if (!standardFilters.isEmpty()) { if (!standardFilters.isEmpty()) {
PoiUIFilter standardFiltersCombined = new PoiUIFilter( PoiUIFilter standardFiltersCombined = new PoiUIFilter(
null, app, app.getPoiFilters().getFiltersName(standardFilters)); null, app, app.getPoiFilters().getFiltersName(standardFilters));
for (PoiUIFilter f : standardFilters) for (PoiUIFilter f : standardFilters) {
standardFiltersCombined.combineWithPoiFilter(f); standardFiltersCombined.combineWithPoiFilter(f);
}
filters.removeAll(standardFilters); filters.removeAll(standardFilters);
filters.add(standardFiltersCombined); filters.add(standardFiltersCombined);
} }
@ -587,10 +590,11 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable<PoiUIFilter>
@Override @Override
public int compareTo(@NonNull PoiUIFilter another) { public int compareTo(@NonNull PoiUIFilter another) {
if (another.filterId.equals(this.filterId)) if (another.filterId.equals(this.filterId)) {
return 0; return 0;
else } else {
return this.name.compareTo(another.name); return this.name.compareTo(another.name);
}
} }
public interface AmenityNameFilter { public interface AmenityNameFilter {
@ -598,4 +602,4 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable<PoiUIFilter>
public boolean accept(Amenity a) ; public boolean accept(Amenity a) ;
} }
} }

View file

@ -123,7 +123,7 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
List<Amenity> res = new ArrayList<>(); List<Amenity> res = new ArrayList<>();
PoiUIFilter.combineStandardPoiFilters(filters, app); PoiUIFilter.combineStandardPoiFilters(filters, app);
for (PoiUIFilter filter : filters) for (PoiUIFilter filter : filters) {
res.addAll(filter.searchAmenities(latLonBounds.top, latLonBounds.left, res.addAll(filter.searchAmenities(latLonBounds.top, latLonBounds.left,
latLonBounds.bottom, latLonBounds.right, z, new ResultMatcher<Amenity>() { latLonBounds.bottom, latLonBounds.right, z, new ResultMatcher<Amenity>() {
@ -137,6 +137,7 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
return isInterrupted(); return isInterrupted();
} }
})); }));
}
Collections.sort(res, new Comparator<Amenity>() { Collections.sort(res, new Comparator<Amenity>() {
@Override @Override
@ -309,8 +310,9 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
} }
static int getResIdFromAttribute(final Context ctx, final int attr) { static int getResIdFromAttribute(final Context ctx, final int attr) {
if (attr == 0) if (attr == 0) {
return 0; return 0;
}
final TypedValue typedvalueattr = new TypedValue(); final TypedValue typedvalueattr = new TypedValue();
ctx.getTheme().resolveAttribute(attr, typedvalueattr, true); ctx.getTheme().resolveAttribute(attr, typedvalueattr, true);
return typedvalueattr.resourceId; return typedvalueattr.resourceId;