-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add bookmarks system #92
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
387055c
Add basic bookmarks system
Feodor0090 22eceba
Merge branch 'main' into bookmarks
Feodor0090 da187f5
Add method to add bookmark with name asking
Feodor0090 f31d2e0
Allow to add selection and search result
Feodor0090 b59e75e
Allow to select and delete bookmarks
Feodor0090 81382f9
Make bookmarks screen accessible
Feodor0090 59f408c
Do not add items commands if there are no items
Feodor0090 37e1562
Implement route build via bookmarks
Feodor0090 a225f48
Bookmarks fixes
shinovon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
package mahomaps.screens; | ||
|
||
import javax.microedition.lcdui.Choice; | ||
import javax.microedition.lcdui.Command; | ||
import javax.microedition.lcdui.CommandListener; | ||
import javax.microedition.lcdui.Displayable; | ||
import javax.microedition.lcdui.List; | ||
import javax.microedition.lcdui.TextBox; | ||
import javax.microedition.rms.RecordStore; | ||
|
||
import cc.nnproject.json.JSON; | ||
import cc.nnproject.json.JSONArray; | ||
import cc.nnproject.json.JSONObject; | ||
import mahomaps.MahoMapsApp; | ||
import mahomaps.map.Geopoint; | ||
import mahomaps.map.MapState; | ||
import mahomaps.overlays.RouteBuildOverlay; | ||
|
||
public class BookmarksScreen extends List implements CommandListener { | ||
|
||
public final static String RMS_NAME = "mm_v1_bookmarks"; | ||
|
||
private JSONArray list; | ||
|
||
private Command from = new Command("Отсюда", Command.ITEM, 0); | ||
private Command to = new Command("Сюда", Command.ITEM, 1); | ||
private Command del = new Command("Удалить", Command.ITEM, 1); | ||
|
||
public BookmarksScreen() { | ||
super("Закладки", Choice.IMPLICIT); | ||
list = read(); | ||
list.build(); | ||
fillList(); | ||
addCommand(MahoMapsApp.back); | ||
if (list.size() > 0) { | ||
addCommand(from); | ||
addCommand(to); | ||
addCommand(del); | ||
} | ||
setCommandListener(this); | ||
} | ||
|
||
private void fillList() { | ||
for (int i = 0; i < list.size(); i++) { | ||
append(list.getObject(i).getString("name", "Not named"), null); | ||
} | ||
} | ||
|
||
private static JSONArray read() { | ||
try { | ||
RecordStore r = RecordStore.openRecordStore(RMS_NAME, true); | ||
byte[] d = null; | ||
if (r.getNumRecords() > 0) { | ||
d = r.getRecord(1); | ||
} | ||
r.closeRecordStore(); | ||
|
||
if (d == null) | ||
return JSON.getArray("[]"); | ||
|
||
return JSON.getArray(new String(d, "UTF-8")); | ||
} catch (Throwable e) { | ||
return JSON.getArray("[]"); | ||
} | ||
} | ||
|
||
public static void BeginAdd(final Geopoint p, String defaultName) { | ||
final TextBox tb = new TextBox("Название закладки?", defaultName == null ? "" : defaultName, 100, 0); | ||
tb.addCommand(MahoMapsApp.back); | ||
tb.addCommand(MahoMapsApp.ok); | ||
tb.setCommandListener(new CommandListener() { | ||
public void commandAction(Command c, Displayable d) { | ||
if (c == MahoMapsApp.back) | ||
MahoMapsApp.BringMap(); | ||
else if (c == MahoMapsApp.ok) { | ||
String text = tb.getString(); | ||
if (text != null && text.length() > 0) { | ||
Add(p, text); | ||
} | ||
MahoMapsApp.BringMap(); | ||
} | ||
} | ||
}); | ||
MahoMapsApp.BringSubScreen(tb); | ||
} | ||
|
||
public static void Add(Geopoint p, String name) { | ||
JSONArray arr = read(); | ||
JSONObject obj = new JSONObject(); | ||
obj.put("name", name); | ||
obj.put("lat", p.lat); | ||
obj.put("lon", p.lon); | ||
arr.add(obj); | ||
Save(arr); | ||
} | ||
|
||
private static void Save(JSONArray arr) { | ||
try { | ||
byte[] d = arr.toString().getBytes("UTF-8"); | ||
RecordStore r = RecordStore.openRecordStore(RMS_NAME, true); | ||
if (r.getNumRecords() == 0) | ||
r.addRecord(new byte[1], 0, 1); | ||
r.setRecord(1, d, 0, d.length); | ||
r.closeRecordStore(); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
public void commandAction(Command c, Displayable d) { | ||
if (c == MahoMapsApp.back) { | ||
MahoMapsApp.BringMap(); | ||
return; | ||
} | ||
|
||
if (list.size() == 0) | ||
return; | ||
int n = getSelectedIndex(); | ||
if (n == -1) | ||
return; | ||
|
||
if (c == del) { | ||
list.remove(n); | ||
delete(n); | ||
Save(list); | ||
return; | ||
} | ||
JSONObject obj = list.getObject(n); | ||
Geopoint p = new Geopoint(obj.getDouble("lat"), obj.getDouble("lon")); | ||
if (c == SELECT_COMMAND) { | ||
MahoMapsApp.GetCanvas().state = MapState.FocusAt(p); | ||
MahoMapsApp.BringMap(); | ||
} else if (c == from) { | ||
RouteBuildOverlay.Get().SetA(p); | ||
MahoMapsApp.BringMap(); | ||
} else if (c == to) { | ||
RouteBuildOverlay.Get().SetB(p); | ||
MahoMapsApp.BringMap(); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Нет вызова setCurrent, не работает.