-
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
Make geo classes less linked and implement build without them #130
Open
Feodor0090
wants to merge
8
commits into
main
Choose a base branch
from
abstract-geo-out
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f0f7e5e
Create interface to avoid direct type links
Feodor0090 42fc38f
Move locationapi to standalone class
Feodor0090 6c11518
Create location api via reflection
Feodor0090 8fb005c
Delete location classes from package
Feodor0090 f85bdd6
Make CI upload no_geo jars
Feodor0090 ca8f77e
Forbid `LocationAPI` obfuscation
Feodor0090 72d8423
Fix name conflict
Feodor0090 26089a3
Fix proguard config
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
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 |
---|---|---|
|
@@ -2,12 +2,6 @@ | |
|
||
import java.util.Vector; | ||
|
||
import javax.microedition.location.Coordinates; | ||
import javax.microedition.location.Location; | ||
import javax.microedition.location.LocationListener; | ||
import javax.microedition.location.LocationProvider; | ||
|
||
import mahomaps.MahoMapsApp; | ||
import mahomaps.screens.MapCanvas; | ||
|
||
public class GeoUpdateThread extends Thread { | ||
|
@@ -20,7 +14,7 @@ public class GeoUpdateThread extends Thread { | |
* Состояние получения геопозиции. Одно из state-значений. | ||
*/ | ||
public int state; | ||
private LocationAPI locationAPI; | ||
private ILocationAPI locationAPI; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. А вот это гениально |
||
public boolean loop = true; | ||
public long lastUpdateTime = System.currentTimeMillis(); | ||
public String method = null; | ||
|
@@ -39,7 +33,8 @@ public void run() { | |
try { | ||
Class.forName("javax.microedition.location.LocationProvider"); | ||
try { | ||
locationAPI = new LocationAPI(); | ||
locationAPI = (ILocationAPI) Class.forName("mahomaps.map.LocationAPI").newInstance(); | ||
locationAPI.setThread(this); | ||
} catch (Exception e) { | ||
state = e.toString().indexOf("LocationException") != -1 ? STATE_UNAVAILABLE : STATE_UNSUPPORTED; | ||
e.printStackTrace(); | ||
|
@@ -151,136 +146,4 @@ public boolean DrawPoint() { | |
public final static int STATE_OK = 2; | ||
|
||
public final static int[] states = new int[] { 93, 93, 94, 88, 95, 96 }; | ||
|
||
// для безопасных вызовов | ||
class LocationAPI { | ||
public LocationProvider locationProvider; | ||
|
||
public LocationAPI() throws Exception { | ||
locationProvider = LocationProvider.getInstance(null); | ||
} | ||
|
||
public double[] getLastKnownCoordinates() { | ||
Location location = LocationProvider.getLastKnownLocation(); | ||
if (location == null || !location.isValid()) | ||
return null; | ||
Coordinates coordinates = location.getQualifiedCoordinates(); | ||
if (coordinates == null) | ||
return null; | ||
return new double[] { coordinates.getLatitude(), coordinates.getLongitude() }; | ||
} | ||
|
||
public void setupListener() { | ||
locationProvider.setLocationListener(new LocationAPIListener(), 5, 5, 5); | ||
} | ||
|
||
public void resetProvider() throws Exception { | ||
System.out.println("resetProvider"); | ||
Thread.sleep(5000); | ||
LocationProvider old = locationProvider; | ||
try { | ||
locationProvider = LocationProvider.getInstance(null); | ||
old.setLocationListener(null, 0, 0, 0); | ||
setupListener(); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
class LocationAPIListener implements LocationListener { | ||
|
||
public void locationUpdated(LocationProvider provider, Location location) { | ||
// определение кол-ва спутников | ||
String nmea = location.getExtraInfo("application/X-jsr179-location-nmea"); | ||
if (nmea != null) { | ||
String[] sequence = split(nmea, '$'); | ||
int s1 = -1; | ||
int s2 = -1; | ||
for (int i = sequence.length - 1; i >= 0; i--) { | ||
String[] sentence = split(sequence[i], ','); | ||
if (sentence[0].endsWith("GGA")) { | ||
try { | ||
s1 = Integer.parseInt(sentence[7]); | ||
} catch (Exception e) { | ||
s1 = -1; | ||
} | ||
s2 = Math.max(s2, s1); | ||
} else if (sentence[0].endsWith("GSV")) { | ||
try { | ||
s2 = Math.max(s2, Integer.parseInt(sentence[3])); | ||
} catch (Exception e) { | ||
} | ||
} | ||
} | ||
sattelites = s1; | ||
totalSattelitesInView = s2; | ||
} else { | ||
totalSattelitesInView = sattelites = -1; | ||
} | ||
String s = ""; | ||
int t = location.getLocationMethod(); | ||
if ((t & Location.MTE_SATELLITE) == Location.MTE_SATELLITE) { | ||
s = "GPS"; | ||
} | ||
if ((t & Location.MTE_TIMEDIFFERENCE) == Location.MTE_TIMEDIFFERENCE) { | ||
s += "TD"; | ||
} | ||
if ((t & Location.MTE_TIMEOFARRIVAL) == Location.MTE_TIMEOFARRIVAL) { | ||
s += "TOA"; | ||
} | ||
if ((t & Location.MTE_CELLID) == Location.MTE_CELLID) { | ||
s += "CID"; | ||
} | ||
if ((t & Location.MTE_SHORTRANGE) == Location.MTE_SHORTRANGE) { | ||
s += "SR"; | ||
} | ||
if ((t & Location.MTE_ANGLEOFARRIVAL) == Location.MTE_ANGLEOFARRIVAL) { | ||
s += "AOA"; | ||
} | ||
if ((t & Location.MTA_ASSISTED) == Location.MTA_ASSISTED) { | ||
s = "A" + s; | ||
} else if ((t & Location.MTA_UNASSISTED) == Location.MTA_UNASSISTED) { | ||
s = "U" + s; | ||
} | ||
if ((t & Location.MTY_TERMINALBASED) == Location.MTY_TERMINALBASED) { | ||
s = "TB " + s; | ||
} | ||
if ((t & Location.MTY_NETWORKBASED) == Location.MTY_NETWORKBASED) { | ||
s = "NB " + s; | ||
} | ||
method = s.length() == 0 ? null : s; | ||
if (location.isValid()) { | ||
Coordinates coordinates = location.getQualifiedCoordinates(); | ||
if (coordinates.getLatitude() != 0 && coordinates.getLongitude() != 0) { | ||
if (!vibrated) { | ||
try { | ||
MahoMapsApp.display.vibrate(100); | ||
} catch (Exception e) { | ||
} | ||
vibrated = true; | ||
} | ||
positionPoint.lat = coordinates.getLatitude(); | ||
positionPoint.lon = coordinates.getLongitude(); | ||
positionPoint.color = Geopoint.COLOR_RED; | ||
state = STATE_OK; | ||
lastUpdateTime = System.currentTimeMillis(); | ||
MahoMapsApp.GetCanvas().requestRepaint(); | ||
} else { | ||
state = STATE_UNAVAILABLE; | ||
} | ||
} | ||
updateCount++; | ||
} | ||
|
||
public void providerStateChanged(LocationProvider provider, int newState) { | ||
if (newState != LocationProvider.AVAILABLE) { | ||
state = STATE_OK_PENDING; | ||
} | ||
// на случай если изменился провайдер | ||
if (newState == LocationProvider.OUT_OF_SERVICE) { | ||
restart(); | ||
} | ||
} | ||
} | ||
} | ||
} |
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,12 @@ | ||
package mahomaps.map; | ||
|
||
interface ILocationAPI { | ||
|
||
void setThread(GeoUpdateThread geoUpdateThread); | ||
|
||
void setupListener(); | ||
|
||
double[] getLastKnownCoordinates(); | ||
|
||
void resetProvider() throws Exception; | ||
} |
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,149 @@ | ||
package mahomaps.map; | ||
|
||
import javax.microedition.location.Coordinates; | ||
import javax.microedition.location.Location; | ||
import javax.microedition.location.LocationListener; | ||
import javax.microedition.location.LocationProvider; | ||
|
||
import mahomaps.MahoMapsApp; | ||
|
||
// для безопасных вызовов | ||
class LocationAPI implements ILocationAPI { | ||
|
||
/** | ||
* Geo thread, where this api will work. | ||
*/ | ||
private GeoUpdateThread geoUpdateThread; | ||
public LocationProvider locationProvider; | ||
|
||
public LocationAPI() throws Exception { | ||
locationProvider = LocationProvider.getInstance(null); | ||
} | ||
|
||
public void setThread(GeoUpdateThread geoUpdateThread) { | ||
this.geoUpdateThread = geoUpdateThread; | ||
} | ||
|
||
public double[] getLastKnownCoordinates() { | ||
Location location = LocationProvider.getLastKnownLocation(); | ||
if (location == null || !location.isValid()) | ||
return null; | ||
Coordinates coordinates = location.getQualifiedCoordinates(); | ||
if (coordinates == null) | ||
return null; | ||
return new double[] { coordinates.getLatitude(), coordinates.getLongitude() }; | ||
} | ||
|
||
public void setupListener() { | ||
locationProvider.setLocationListener(new LocationAPIListener(), 5, 5, 5); | ||
} | ||
|
||
public void resetProvider() throws Exception { | ||
System.out.println("resetProvider"); | ||
Thread.sleep(5000); | ||
LocationProvider old = locationProvider; | ||
try { | ||
locationProvider = LocationProvider.getInstance(null); | ||
old.setLocationListener(null, 0, 0, 0); | ||
setupListener(); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
class LocationAPIListener implements LocationListener { | ||
|
||
public void locationUpdated(LocationProvider provider, Location location) { | ||
// определение кол-ва спутников | ||
String nmea = location.getExtraInfo("application/X-jsr179-location-nmea"); | ||
if (nmea != null) { | ||
String[] sequence = GeoUpdateThread.split(nmea, '$'); | ||
int s1 = -1; | ||
int s2 = -1; | ||
for (int i = sequence.length - 1; i >= 0; i--) { | ||
String[] sentence = GeoUpdateThread.split(sequence[i], ','); | ||
if (sentence[0].endsWith("GGA")) { | ||
try { | ||
s1 = Integer.parseInt(sentence[7]); | ||
} catch (Exception e) { | ||
s1 = -1; | ||
} | ||
s2 = Math.max(s2, s1); | ||
} else if (sentence[0].endsWith("GSV")) { | ||
try { | ||
s2 = Math.max(s2, Integer.parseInt(sentence[3])); | ||
} catch (Exception e) { | ||
} | ||
} | ||
} | ||
geoUpdateThread.sattelites = s1; | ||
geoUpdateThread.totalSattelitesInView = s2; | ||
} else { | ||
geoUpdateThread.totalSattelitesInView = geoUpdateThread.sattelites = -1; | ||
} | ||
String s = ""; | ||
int t = location.getLocationMethod(); | ||
if ((t & Location.MTE_SATELLITE) == Location.MTE_SATELLITE) { | ||
s = "GPS"; | ||
} | ||
if ((t & Location.MTE_TIMEDIFFERENCE) == Location.MTE_TIMEDIFFERENCE) { | ||
s += "TD"; | ||
} | ||
if ((t & Location.MTE_TIMEOFARRIVAL) == Location.MTE_TIMEOFARRIVAL) { | ||
s += "TOA"; | ||
} | ||
if ((t & Location.MTE_CELLID) == Location.MTE_CELLID) { | ||
s += "CID"; | ||
} | ||
if ((t & Location.MTE_SHORTRANGE) == Location.MTE_SHORTRANGE) { | ||
s += "SR"; | ||
} | ||
if ((t & Location.MTE_ANGLEOFARRIVAL) == Location.MTE_ANGLEOFARRIVAL) { | ||
s += "AOA"; | ||
} | ||
if ((t & Location.MTA_ASSISTED) == Location.MTA_ASSISTED) { | ||
s = "A" + s; | ||
} else if ((t & Location.MTA_UNASSISTED) == Location.MTA_UNASSISTED) { | ||
s = "U" + s; | ||
} | ||
if ((t & Location.MTY_TERMINALBASED) == Location.MTY_TERMINALBASED) { | ||
s = "TB " + s; | ||
} | ||
if ((t & Location.MTY_NETWORKBASED) == Location.MTY_NETWORKBASED) { | ||
s = "NB " + s; | ||
} | ||
geoUpdateThread.method = s.length() == 0 ? null : s; | ||
if (location.isValid()) { | ||
Coordinates coordinates = location.getQualifiedCoordinates(); | ||
if (coordinates.getLatitude() != 0 && coordinates.getLongitude() != 0) { | ||
if (!geoUpdateThread.vibrated) { | ||
try { | ||
MahoMapsApp.display.vibrate(100); | ||
} catch (Exception e) { | ||
} | ||
geoUpdateThread.vibrated = true; | ||
} | ||
geoUpdateThread.positionPoint.lat = coordinates.getLatitude(); | ||
geoUpdateThread.positionPoint.lon = coordinates.getLongitude(); | ||
geoUpdateThread.positionPoint.color = Geopoint.COLOR_RED; | ||
geoUpdateThread.state = GeoUpdateThread.STATE_OK; | ||
geoUpdateThread.lastUpdateTime = System.currentTimeMillis(); | ||
MahoMapsApp.GetCanvas().requestRepaint(); | ||
} else { | ||
geoUpdateThread.state = GeoUpdateThread.STATE_UNAVAILABLE; | ||
} | ||
} | ||
geoUpdateThread.updateCount++; | ||
} | ||
|
||
public void providerStateChanged(LocationProvider provider, int newState) { | ||
if (newState != LocationProvider.AVAILABLE) { | ||
geoUpdateThread.state = GeoUpdateThread.STATE_OK_PENDING; | ||
} | ||
// на случай если изменился провайдер | ||
if (newState == LocationProvider.OUT_OF_SERVICE) { | ||
geoUpdateThread.restart(); | ||
} | ||
} | ||
} | ||
} |
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.
С этим не согласен
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.
Доправь тогда как надо. По идее, надо только имя запретить трогать.
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.
Перечитал все, понял почему так надо