use of com.junjunguo.pocketmaps.model.MyMap in project PocketMaps by junjunguo.
the class DownloadMapActivity method getMapsFromJSsources.
/**
* Read all maps data from server.
* @param mapNameFilter MapName or null for all.
* @return list of MyMap
*/
public static List<MyMap> getMapsFromJSsources(String mapNameFilter, OnProgressListener task) {
ArrayList<MyMap> maps = new ArrayList<>();
try {
String jsonDirUrl = Variable.getVariable().getMapUrlJSON();
String jsonFileUrl = jsonDirUrl + "/map_url_json";
String jsonContent = DownloadFiles.getDownloader().downloadTextfile(jsonFileUrl);
task.onProgress(50);
JSONObject jsonObj = new JSONObject(jsonContent);
if (jsonObj.has("maps-" + MyMap.MAP_VERSION) && jsonObj.has("maps-" + MyMap.MAP_VERSION + "-path")) {
String mapsPath = jsonObj.getString("maps-" + MyMap.MAP_VERSION + "-path");
JSONArray jsonList = jsonObj.getJSONArray("maps-" + MyMap.MAP_VERSION);
for (int i = 0; i < jsonList.length(); i++) {
JSONObject o = jsonList.getJSONObject(i);
String name = o.getString("name");
if (mapNameFilter != null && !mapNameFilter.equals(name)) {
continue;
}
String size = o.getString("size");
String time = o.getString("time");
MyMap curMap = new MyMap(name, size, time, jsonDirUrl + "/" + mapsPath + "/" + time + "/");
maps.add(curMap);
float progress = i;
progress = i / jsonList.length();
progress = progress * 50.0f;
task.onProgress(50 + (int) progress);
}
}
} catch (JSONException e) {
e.printStackTrace();
}
return maps;
}
use of com.junjunguo.pocketmaps.model.MyMap in project PocketMaps by junjunguo.
the class DownloadMapActivity method onClickMapNow.
/**
* download map
*
* @param view View
* @param position item position
*/
private void onClickMapNow(View view, int position, TextView tv) {
MyMap myMap = myDownloadAdapter.getItem(position);
if (myMap.getStatus() == MyMap.DlStatus.Downloading || myMap.getStatus() == MyMap.DlStatus.Unzipping) {
logUser("Already downloading!");
return;
} else if (myMap.getStatus() == MyMap.DlStatus.Complete) {
logUser("Already downloaded!");
return;
}
tv.setText("downloading...");
refreshMapEntry(myMap, myDownloadAdapter);
myMap.setStatus(MyMap.DlStatus.Downloading);
DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
Request request = new Request(Uri.parse(myMap.getUrl()));
File destFile = MyMap.getMapFile(myMap, MyMap.MapFileType.DlMapFile);
request.setDestinationUri(Uri.fromFile(destFile));
long enqueueId = dm.enqueue(request);
File idFile = MyMap.getMapFile(myMap, MyMap.MapFileType.DlIdFile);
IO.writeToFile("" + enqueueId, idFile, false);
BroadcastReceiver br = createBroadcastReceiver(myDownloadAdapter, myMap, enqueueId);
registerReceiver(br, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
receiverList.add(br);
}
use of com.junjunguo.pocketmaps.model.MyMap in project PocketMaps by junjunguo.
the class MainActivity method continueActivity.
boolean continueActivity() {
if (activityLoaded) {
return true;
}
String sPermission = android.Manifest.permission.WRITE_EXTERNAL_STORAGE;
if (!Permission.checkPermission(sPermission, this)) {
String sPermission2 = android.Manifest.permission.ACCESS_FINE_LOCATION;
Permission.startRequest(new String[] { sPermission, sPermission2 }, true, this);
return false;
}
Variable.getVariable().setContext(getApplicationContext());
// set status bar
new SetStatusBarColor().setStatusBarColor(findViewById(R.id.statusBarBackgroundMain), getResources().getColor(R.color.my_primary_dark), this);
File defMapsDir = getDefaultBaseDirectory(this);
if (defMapsDir == null) {
return false;
}
Variable.getVariable().setBaseFolder(defMapsDir.getPath());
if (!Variable.getVariable().getMapsFolder().exists()) {
Variable.getVariable().getMapsFolder().mkdirs();
}
boolean loadSuccess = Variable.getVariable().loadVariables();
activateAddBtn();
activateRecyclerView(new ArrayList<MyMap>());
generateList();
// vh = null;
changeMap = getIntent().getBooleanExtra("com.junjunguo.pocketmaps.activities.MapActivity.SELECTNEWMAP", true);
// start map activity if load succeed
if (loadSuccess && !changeMap) {
startMapActivity();
}
activityLoaded = true;
return true;
}
use of com.junjunguo.pocketmaps.model.MyMap in project PocketMaps by junjunguo.
the class MainActivity method deleteItemHandler.
/**
* swipe to right or left to delete item & AlertDialog to confirm
*/
private void deleteItemHandler() {
OnItemClickListener l = new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
MyMap mm = mapAdapter.remove(position);
Variable.getVariable().removeLocalMap(mm);
File mapsFolder = MyMap.getMapFile(mm, MyMap.MapFileType.MapFolder);
recursiveDelete(mapsFolder);
mm.setStatus(MyMap.DlStatus.On_server);
log("RecursiveDelete: " + mm.getMapName());
}
};
addDeleteItemHandler(this, mapsRV, l);
}
use of com.junjunguo.pocketmaps.model.MyMap in project PocketMaps by junjunguo.
the class MyDownloadAdapter method remove.
/**
* remove item at the given position
*
* @param position index
*/
public MyMap remove(int position) {
MyMap mm = null;
if (position >= 0 && position < getItemCount()) {
mm = myMaps.remove(position);
notifyItemRemoved(position);
}
return mm;
}
Aggregations