Merge remote-tracking branch 'refs/remotes/origin/caching' into device-bugfix

This commit is contained in:
misaochan 2016-01-11 19:12:02 +13:00
commit 2bc09d16d2
3 changed files with 19 additions and 26 deletions

View file

@ -147,8 +147,6 @@ public class CommonsApplication extends Application {
return bitmapSize / 1024;
}
};
}
//For caching area -> categories

View file

@ -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;
//Earths 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;

View file

@ -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());