mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 12:53:55 +01:00
Merge remote-tracking branch 'refs/remotes/origin/caching' into device-bugfix
This commit is contained in:
commit
2bc09d16d2
3 changed files with 19 additions and 26 deletions
|
|
@ -147,8 +147,6 @@ public class CommonsApplication extends Application {
|
|||
return bitmapSize / 1024;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
//For caching area -> categories
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ public class CacheController {
|
|||
private double xMinus, xPlus, yMinus, yPlus;
|
||||
|
||||
private static final String TAG = CacheController.class.getName();
|
||||
private static final int EARTH_RADIUS = 6378137;
|
||||
|
||||
public CacheController() {
|
||||
quadTree = new QuadTree(-180, -90, +180, +90);
|
||||
|
|
@ -45,44 +46,37 @@ public class CacheController {
|
|||
//Convert decLatitude and decLongitude to a coordinate offset range
|
||||
convertCoordRange();
|
||||
pointsFound = quadTree.searchWithin(xMinus, yMinus, xPlus, yPlus);
|
||||
List displayCatList = new ArrayList();
|
||||
List<String> displayCatList = new ArrayList<String>();
|
||||
Log.d(TAG, "Points found in quadtree: " + pointsFound);
|
||||
|
||||
List<String> flatCatList = new ArrayList<String>();
|
||||
|
||||
if (pointsFound.length != 0) {
|
||||
Log.d(TAG, "Entering for loop");
|
||||
int index = 0;
|
||||
|
||||
for (Point point : pointsFound) {
|
||||
Log.d(TAG, "Nearby point: " + point.toString());
|
||||
Object cat = point.getValue();
|
||||
Log.d(TAG, "Nearby cat: " + cat);
|
||||
displayCatList.add(index, cat);
|
||||
index++;
|
||||
displayCatList = (List<String>)point.getValue();
|
||||
Log.d(TAG, "Nearby cat: " + point.getValue());
|
||||
}
|
||||
//FIXME: temporary, can't figure out why for loop always only accesses 1 point
|
||||
flatCatList = ((ArrayList<String>)displayCatList.get(0));
|
||||
|
||||
Log.d(TAG, "Categories found in cache: " + flatCatList.toString());
|
||||
Log.d(TAG, "Categories found in cache: " + displayCatList.toString());
|
||||
} else {
|
||||
Log.d(TAG, "No categories found in cache");
|
||||
}
|
||||
return flatCatList;
|
||||
return displayCatList;
|
||||
}
|
||||
|
||||
//Based on algorithm at http://gis.stackexchange.com/questions/2951/algorithm-for-offsetting-a-latitude-longitude-by-some-amount-of-meters
|
||||
public void convertCoordRange() {
|
||||
//Position, decimal degrees
|
||||
double lat = y;
|
||||
double lon = x;
|
||||
|
||||
//Earth’s radius, sphere
|
||||
double radius=6378137;
|
||||
//offsets in meters
|
||||
double offset = 100;
|
||||
|
||||
//Coordinate offsets in radians
|
||||
double dLat = offset/radius;
|
||||
double dLon = offset/(radius*Math.cos(Math.PI*lat/180));
|
||||
double dLat = offset/EARTH_RADIUS;
|
||||
double dLon = offset/(EARTH_RADIUS*Math.cos(Math.PI*lat/180));
|
||||
|
||||
//OffsetPosition, decimal degrees
|
||||
yPlus = lat + dLat * 180/Math.PI;
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ public class ShareActivity
|
|||
|
||||
if (cacheFound == false) {
|
||||
//Has to be called after apiCall.request()
|
||||
cacheObj.cacheData.cacheCategory();
|
||||
app.cacheData.cacheCategory();
|
||||
Log.d(TAG, "Cache the categories found");
|
||||
}
|
||||
|
||||
|
|
@ -221,27 +221,28 @@ public class ShareActivity
|
|||
String filePath = getRealPathFromURI(mediaUri);
|
||||
Log.d(TAG, "Filepath: " + filePath);
|
||||
|
||||
//Using global singleton to get CacheController to last longer than the activity lifecycle
|
||||
cacheObj = ((CommonsApplication)this.getApplication());
|
||||
|
||||
if (filePath != null) {
|
||||
//extract the coordinates of image in decimal degrees
|
||||
Log.d(TAG, "Calling GPSExtractor");
|
||||
GPSExtractor imageObj = new GPSExtractor(filePath);
|
||||
String decimalCoords = imageObj.getCoords();
|
||||
double decLongitude = imageObj.getDecLongitude();
|
||||
double decLatitude = imageObj.getDecLatitude();
|
||||
|
||||
|
||||
if (decimalCoords != null) {
|
||||
double decLongitude = imageObj.getDecLongitude();
|
||||
double decLatitude = imageObj.getDecLatitude();
|
||||
|
||||
Log.d(TAG, "Decimal coords of image: " + decimalCoords);
|
||||
cacheObj.cacheData.setQtPoint(decLongitude, decLatitude);
|
||||
app.cacheData.setQtPoint(decLongitude, decLatitude);
|
||||
|
||||
MwVolleyApi apiCall = new MwVolleyApi(this);
|
||||
|
||||
List displayCatList = cacheObj.cacheData.findCategory();
|
||||
List displayCatList = app.cacheData.findCategory();
|
||||
boolean catListEmpty = displayCatList.isEmpty();
|
||||
|
||||
//if no categories found in cache, call MW API to match image coords with nearby Commons categories
|
||||
if (displayCatList.size() == 0) {
|
||||
if (catListEmpty) {
|
||||
cacheFound = false;
|
||||
apiCall.request(decimalCoords);
|
||||
Log.d(TAG, "displayCatList size 0, calling MWAPI" + displayCatList.toString());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue