Formatting.

This commit is contained in:
GaidamakUA 2016-04-15 13:02:56 +03:00
parent 989cf70bb3
commit 8eab6893a2
2 changed files with 60 additions and 63 deletions

View file

@ -70,7 +70,7 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider
private OsmBugsLocalUtil local; private OsmBugsLocalUtil local;
private MapLayerData<List<OpenStreetNote>> data; private MapLayerData<List<OpenStreetNote>> data;
public OsmBugsLayer(MapActivity activity, OsmEditingPlugin plugin){ public OsmBugsLayer(MapActivity activity, OsmEditingPlugin plugin) {
this.activity = activity; this.activity = activity;
this.plugin = plugin; this.plugin = plugin;
local = plugin.getOsmNotesLocalUtil(); local = plugin.getOsmNotesLocalUtil();
@ -166,6 +166,7 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider
} }
} }
} }
@Override @Override
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) { public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
@ -191,13 +192,12 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider
} }
@Override @Override
public boolean onLongPressEvent(PointF point, RotatedTileBox tileBox) { public boolean onLongPressEvent(PointF point, RotatedTileBox tileBox) {
return false; return false;
} }
public void getBugFromPoint(RotatedTileBox tb, PointF point, List<? super OpenStreetNote> res){ public void getBugFromPoint(RotatedTileBox tb, PointF point, List<? super OpenStreetNote> res) {
List<OpenStreetNote> objects = data.getResults(); List<OpenStreetNote> objects = data.getResults();
if (objects != null && view != null) { if (objects != null && view != null) {
int ex = (int) point.x; int ex = (int) point.x;
@ -222,7 +222,7 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider
} }
public void clearCache() { public void clearCache() {
if(data != null) { if (data != null) {
data.clearCache(); data.clearCache();
} }
} }
@ -231,9 +231,9 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider
int tok; int tok;
String text = ""; String text = "";
while ((tok = parser.next()) != XmlPullParser.END_DOCUMENT) { while ((tok = parser.next()) != XmlPullParser.END_DOCUMENT) {
if(tok == XmlPullParser.END_TAG && parser.getName().equals(key)){ if (tok == XmlPullParser.END_TAG && parser.getName().equals(key)) {
break; break;
} else if(tok == XmlPullParser.TEXT){ } else if (tok == XmlPullParser.TEXT) {
text += parser.getText(); text += parser.getText();
} }
@ -242,15 +242,14 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider
} }
protected List<OpenStreetNote> loadingBugs(double topLatitude, double leftLongitude, double bottomLatitude,double rightLongitude){ protected List<OpenStreetNote> loadingBugs(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude) {
final int deviceApiVersion = android.os.Build.VERSION.SDK_INT; final int deviceApiVersion = android.os.Build.VERSION.SDK_INT;
String SITE_API; String SITE_API;
if (deviceApiVersion >= android.os.Build.VERSION_CODES.GINGERBREAD) { if (deviceApiVersion >= android.os.Build.VERSION_CODES.GINGERBREAD) {
SITE_API = "https://api.openstreetmap.org/"; SITE_API = "https://api.openstreetmap.org/";
} } else {
else {
SITE_API = "http://api.openstreetmap.org/"; SITE_API = "http://api.openstreetmap.org/";
} }
@ -284,17 +283,17 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider
} else if (parser.getName().equals("id") && current != null) { } else if (parser.getName().equals("id") && current != null) {
current.id = Long.parseLong(readText(parser, "id")); current.id = Long.parseLong(readText(parser, "id"));
} else if (parser.getName().equals("comment")) { } else if (parser.getName().equals("comment")) {
commentIndex ++; commentIndex++;
} else if (parser.getName().equals("user") && current != null) { } else if (parser.getName().equals("user") && current != null) {
if(commentIndex == current.users.size()) { if (commentIndex == current.users.size()) {
current.users.add(readText(parser, "user")); current.users.add(readText(parser, "user"));
} }
} else if (parser.getName().equals("date") && current != null) { } else if (parser.getName().equals("date") && current != null) {
if(commentIndex == current.dates.size()) { if (commentIndex == current.dates.size()) {
current.dates.add(readText(parser, "date")); current.dates.add(readText(parser, "date"));
} }
} else if (parser.getName().equals("text") && current != null) { } else if (parser.getName().equals("text") && current != null) {
if(commentIndex == current.comments.size()) { if (commentIndex == current.comments.size()) {
current.comments.add(readText(parser, "text")); current.comments.add(readText(parser, "text"));
} }
} }
@ -311,11 +310,10 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider
} }
private void asyncActionTask(final OpenStreetNote bug, final String text, final Action action) { private void asyncActionTask(final OpenStreetNote bug, final String text, final Action action) {
AsyncTask<Void, Void, OsmBugResult> task = new AsyncTask<Void, Void, OsmBugResult>() { AsyncTask<Void, Void, OsmBugResult> task = new AsyncTask<Void, Void, OsmBugResult>() {
private OsmBugsUtil osmbugsUtil; private OsmBugsUtil osmbugsUtil;
@Override @Override
protected OsmBugResult doInBackground(Void... params) { protected OsmBugResult doInBackground(Void... params) {
osmbugsUtil = getOsmbugsUtil(bug); osmbugsUtil = getOsmbugsUtil(bug);
@ -325,22 +323,23 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider
pnt.setLongitude(bug.getLongitude()); pnt.setLongitude(bug.getLongitude());
return osmbugsUtil.commit(pnt, text, action); return osmbugsUtil.commit(pnt, text, action);
} }
protected void onPostExecute(OsmBugResult obj) { protected void onPostExecute(OsmBugResult obj) {
if (obj != null && obj.warning == null) { if (obj != null && obj.warning == null) {
if(local == osmbugsUtil) { if (local == osmbugsUtil) {
Toast.makeText(activity, R.string.osm_changes_added_to_local_edits, Toast.LENGTH_LONG).show(); Toast.makeText(activity, R.string.osm_changes_added_to_local_edits, Toast.LENGTH_LONG).show();
if(obj.local != null) { if (obj.local != null) {
PointDescription pd = new PointDescription(PointDescription.POINT_TYPE_OSM_BUG, obj.local.getText()); PointDescription pd = new PointDescription(PointDescription.POINT_TYPE_OSM_BUG, obj.local.getText());
activity.getContextMenu().show(new LatLon(obj.local.getLatitude(), obj.local.getLongitude()), pd, obj.local); activity.getContextMenu().show(new LatLon(obj.local.getLatitude(), obj.local.getLongitude()), pd, obj.local);
} }
} else { } else {
if(action == Action.REOPEN) { if (action == Action.REOPEN) {
Toast.makeText(activity, R.string.osn_add_dialog_success, Toast.LENGTH_LONG).show(); Toast.makeText(activity, R.string.osn_add_dialog_success, Toast.LENGTH_LONG).show();
} else if(action == Action.MODIFY) { } else if (action == Action.MODIFY) {
Toast.makeText(activity, R.string.osb_comment_dialog_success, Toast.LENGTH_LONG).show(); Toast.makeText(activity, R.string.osb_comment_dialog_success, Toast.LENGTH_LONG).show();
} else if(action == Action.DELETE) { } else if (action == Action.DELETE) {
Toast.makeText(activity, R.string.osn_close_dialog_success, Toast.LENGTH_LONG).show(); Toast.makeText(activity, R.string.osn_close_dialog_success, Toast.LENGTH_LONG).show();
} else if(action == Action.CREATE) { } else if (action == Action.CREATE) {
Toast.makeText(activity, R.string.osn_add_dialog_success, Toast.LENGTH_LONG).show(); Toast.makeText(activity, R.string.osn_add_dialog_success, Toast.LENGTH_LONG).show();
} }
@ -348,13 +347,13 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider
clearCache(); clearCache();
} else { } else {
int r = R.string.osb_comment_dialog_error; int r = R.string.osb_comment_dialog_error;
if(action == Action.REOPEN) { if (action == Action.REOPEN) {
r = R.string.osn_add_dialog_error; r = R.string.osn_add_dialog_error;
reopenBug(bug, text); reopenBug(bug, text);
} else if(action == Action.DELETE) { } else if (action == Action.DELETE) {
r = R.string.osn_close_dialog_error; r = R.string.osn_close_dialog_error;
closeBug(bug, text); closeBug(bug, text);
} else if(action == Action.CREATE) { } else if (action == Action.CREATE) {
r = R.string.osn_add_dialog_error; r = R.string.osn_add_dialog_error;
openBug(bug.getLatitude(), bug.getLongitude(), text); openBug(bug.getLatitude(), bug.getLongitude(), text);
} else { } else {
@ -368,52 +367,52 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider
} }
public void openBug(final double latitude, final double longitude, String message){ public void openBug(final double latitude, final double longitude, String message) {
OpenStreetNote bug = new OpenStreetNote(); OpenStreetNote bug = new OpenStreetNote();
bug.setLatitude(latitude); bug.setLatitude(latitude);
bug.setLongitude(longitude); bug.setLongitude(longitude);
showBugDialog(bug, Action.CREATE, message); showBugDialog(bug, Action.CREATE, message);
} }
public void closeBug(final OpenStreetNote bug, String txt){ public void closeBug(final OpenStreetNote bug, String txt) {
showBugDialog(bug, Action.DELETE, txt); showBugDialog(bug, Action.DELETE, txt);
} }
public void reopenBug(final OpenStreetNote bug, String txt){ public void reopenBug(final OpenStreetNote bug, String txt) {
showBugDialog(bug, Action.REOPEN, txt); showBugDialog(bug, Action.REOPEN, txt);
} }
public void commentBug(final OpenStreetNote bug, String txt){ public void commentBug(final OpenStreetNote bug, String txt) {
showBugDialog(bug, Action.MODIFY, txt); showBugDialog(bug, Action.MODIFY, txt);
} }
private void showBugDialog(final OpenStreetNote bug, final Action action, String text) { private void showBugDialog(final OpenStreetNote bug, final Action action, String text) {
int title ; int title;
if(action == Action.DELETE) { if (action == Action.DELETE) {
title = R.string.osn_close_dialog_title; title = R.string.osn_close_dialog_title;
} else if(action == Action.MODIFY) { } else if (action == Action.MODIFY) {
title = R.string.osn_comment_dialog_title; title = R.string.osn_comment_dialog_title;
} else if(action == Action.REOPEN) { } else if (action == Action.REOPEN) {
title = R.string.osn_reopen_dialog_title; title = R.string.osn_reopen_dialog_title;
} else { } else {
title = R.string.osn_add_dialog_title; title = R.string.osn_add_dialog_title;
} }
OsmBugsUtil util = getOsmbugsUtil(bug); OsmBugsUtil util = getOsmbugsUtil(bug);
final boolean offline = util instanceof OsmBugsLocalUtil; final boolean offline = util instanceof OsmBugsLocalUtil;
final View view = LayoutInflater.from(activity).inflate(R.layout.open_bug, null); final View view = LayoutInflater.from(activity).inflate(R.layout.open_bug, null);
if(offline) { if (offline) {
view.findViewById(R.id.user_name_field).setVisibility(View.GONE); view.findViewById(R.id.user_name_field).setVisibility(View.GONE);
view.findViewById(R.id.userNameEditTextLabel).setVisibility(View.GONE); view.findViewById(R.id.userNameEditTextLabel).setVisibility(View.GONE);
view.findViewById(R.id.password_field).setVisibility(View.GONE); view.findViewById(R.id.password_field).setVisibility(View.GONE);
view.findViewById(R.id.passwordEditTextLabel).setVisibility(View.GONE); view.findViewById(R.id.passwordEditTextLabel).setVisibility(View.GONE);
} else { } else {
((EditText)view.findViewById(R.id.user_name_field)).setText(getUserName()); ((EditText) view.findViewById(R.id.user_name_field)).setText(getUserName());
((EditText)view.findViewById(R.id.password_field)).setText(((OsmandApplication) activity.getApplication()).getSettings().USER_PASSWORD.get()); ((EditText) view.findViewById(R.id.password_field)).setText(((OsmandApplication) activity.getApplication()).getSettings().USER_PASSWORD.get());
} }
if(!Algorithms.isEmpty(text)) { if (!Algorithms.isEmpty(text)) {
((EditText)view.findViewById(R.id.message_field)).setText(text); ((EditText) view.findViewById(R.id.message_field)).setText(text);
} }
AndroidUtils.softKeyboardDelayed(view.findViewById(R.id.message_field)); AndroidUtils.softKeyboardDelayed(view.findViewById(R.id.message_field));
@ -440,37 +439,35 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider
private String getTextAndUpdateUserPwd(final View view) { private String getTextAndUpdateUserPwd(final View view) {
String text = getMessageText(view); String text = getMessageText(view);
String author = ((EditText)view.findViewById(R.id.user_name_field)).getText().toString(); String author = ((EditText) view.findViewById(R.id.user_name_field)).getText().toString();
String pwd = ((EditText)view.findViewById(R.id.password_field)).getText().toString(); String pwd = ((EditText) view.findViewById(R.id.password_field)).getText().toString();
((OsmandApplication) OsmBugsLayer.this.activity.getApplication()).getSettings().USER_NAME.set(author); ((OsmandApplication) OsmBugsLayer.this.activity.getApplication()).getSettings().USER_NAME.set(author);
((OsmandApplication) OsmBugsLayer.this.activity.getApplication()).getSettings().USER_PASSWORD.set(pwd); ((OsmandApplication) OsmBugsLayer.this.activity.getApplication()).getSettings().USER_PASSWORD.set(pwd);
return text; return text;
} }
private String getMessageText(final View view) { private String getMessageText(final View view) {
return ((EditText)view.findViewById(R.id.message_field)).getText().toString(); return ((EditText) view.findViewById(R.id.message_field)).getText().toString();
} }
public void refreshMap(){ public void refreshMap() {
if (view != null && view.getLayers().contains(OsmBugsLayer.this)) { if (view != null && view.getLayers().contains(OsmBugsLayer.this)) {
view.refreshMap(); view.refreshMap();
} }
} }
@Override @Override
public String getObjectDescription(Object o) { public String getObjectDescription(Object o) {
if(o instanceof OpenStreetNote){ if (o instanceof OpenStreetNote) {
return activity.getString(R.string.osn_bug_name) + ": " + ((OpenStreetNote)o).getCommentDescription(); //$NON-NLS-1$ return activity.getString(R.string.osn_bug_name) + ": " + ((OpenStreetNote) o).getCommentDescription(); //$NON-NLS-1$
} }
return null; return null;
} }
@Override @Override
public PointDescription getObjectName(Object o) { public PointDescription getObjectName(Object o) {
if(o instanceof OpenStreetNote){ if (o instanceof OpenStreetNote) {
OpenStreetNote bug = (OpenStreetNote) o; OpenStreetNote bug = (OpenStreetNote) o;
String name = bug.description != null ? bug.description : ""; String name = bug.description != null ? bug.description : "";
String typeName = bug.typeName != null ? bug.typeName : activity.getString(R.string.osn_bug_name); String typeName = bug.typeName != null ? bug.typeName : activity.getString(R.string.osn_bug_name);
@ -503,8 +500,8 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider
@Override @Override
public LatLon getObjectLocation(Object o) { public LatLon getObjectLocation(Object o) {
if(o instanceof OpenStreetNote){ if (o instanceof OpenStreetNote) {
return new LatLon(((OpenStreetNote)o).getLatitude(), ((OpenStreetNote)o).getLongitude()); return new LatLon(((OpenStreetNote) o).getLatitude(), ((OpenStreetNote) o).getLongitude());
} }
return null; return null;
} }
@ -607,12 +604,15 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider
public long getId() { public long getId() {
return id; return id;
} }
public void setId(long id) { public void setId(long id) {
this.id = id; this.id = id;
} }
public boolean isOpened() { public boolean isOpened() {
return opened; return opened;
} }
public void setOpened(boolean opened) { public void setOpened(boolean opened) {
this.opened = opened; this.opened = opened;
} }

View file

@ -53,7 +53,7 @@ public class OsmEditingPlugin extends OsmandPlugin {
private OpenstreetmapRemoteUtil remoteUtil; private OpenstreetmapRemoteUtil remoteUtil;
private OsmBugsRemoteUtil remoteNotesUtil; private OsmBugsRemoteUtil remoteNotesUtil;
private OsmBugsLocalUtil localNotesUtil; private OsmBugsLocalUtil localNotesUtil;
public OsmEditingPlugin(OsmandApplication app) { public OsmEditingPlugin(OsmandApplication app) {
this.app = app; this.app = app;
settings = app.getSettings(); settings = app.getSettings();
@ -70,37 +70,35 @@ public class OsmEditingPlugin extends OsmandPlugin {
} }
return dbpoi; return dbpoi;
} }
public OpenstreetmapLocalUtil getPoiModificationLocalUtil() { public OpenstreetmapLocalUtil getPoiModificationLocalUtil() {
if(localUtil == null) { if (localUtil == null) {
localUtil = new OpenstreetmapLocalUtil(this); localUtil = new OpenstreetmapLocalUtil(this);
} }
return localUtil; return localUtil;
} }
public OpenstreetmapRemoteUtil getPoiModificationRemoteUtil() { public OpenstreetmapRemoteUtil getPoiModificationRemoteUtil() {
if(remoteUtil == null) { if (remoteUtil == null) {
remoteUtil = new OpenstreetmapRemoteUtil(app); remoteUtil = new OpenstreetmapRemoteUtil(app);
} }
return remoteUtil; return remoteUtil;
} }
public OsmBugsRemoteUtil getOsmNotesRemoteUtil() { public OsmBugsRemoteUtil getOsmNotesRemoteUtil() {
if(remoteNotesUtil == null) { if (remoteNotesUtil == null) {
remoteNotesUtil = new OsmBugsRemoteUtil(app); remoteNotesUtil = new OsmBugsRemoteUtil(app);
} }
return remoteNotesUtil; return remoteNotesUtil;
} }
public OsmBugsLocalUtil getOsmNotesLocalUtil() { public OsmBugsLocalUtil getOsmNotesLocalUtil() {
if(localNotesUtil == null) { if (localNotesUtil == null) {
localNotesUtil = new OsmBugsLocalUtil(app, getDBBug()); localNotesUtil = new OsmBugsLocalUtil(app, getDBBug());
} }
return localNotesUtil; return localNotesUtil;
} }
public OsmBugsDbHelper getDBBug() { public OsmBugsDbHelper getDBBug() {
if (dbbug == null) { if (dbbug == null) {
@ -109,7 +107,6 @@ public class OsmEditingPlugin extends OsmandPlugin {
return dbbug; return dbbug;
} }
private OsmBugsLayer osmBugsLayer; private OsmBugsLayer osmBugsLayer;
private OsmEditsLayer osmEditsLayer; private OsmEditsLayer osmEditsLayer;
@ -415,7 +412,7 @@ public class OsmEditingPlugin extends OsmandPlugin {
} }
return prefix + subtype + ((OpenstreetmapPoint) point).getName(); return prefix + subtype + ((OpenstreetmapPoint) point).getName();
} else if (point.getGroup() == OsmPoint.Group.BUG) { } else if (point.getGroup() == OsmPoint.Group.BUG) {
return prefix + ((OsmNotesPoint) point).getText(); return prefix + ((OsmNotesPoint) point).getText();
} else { } else {
return prefix; return prefix;
} }