use of com.junjunguo.pocketmaps.model.MyMap in project PocketMaps by junjunguo.
the class DownloadMapActivity method unzipBg.
private static void unzipBg(final MyMap myMap, final MyDownloadAdapter dlAdapter) {
log("Unzipping map: " + myMap.getMapName());
myMap.setStatus(MyMap.DlStatus.Unzipping);
refreshMapEntry(myMap, dlAdapter);
new AsyncTask<URL, Integer, MyMap>() {
String errMsg = null;
@Override
protected MyMap doInBackground(URL... params) {
File ghzFile = MyMap.getMapFile(myMap, MyMap.MapFileType.DlMapFile);
if (ghzFile.exists()) {
try {
new MapUnzip().unzip(ghzFile.getPath(), new File(Variable.getVariable().getMapsFolder(), myMap.getMapName() + "-gh").getAbsolutePath());
} catch (IOException e) {
errMsg = "Error unpacking map: " + myMap.getMapName();
}
} else {
errMsg = "Error, missing downloaded file: " + ghzFile.getPath();
}
clearDlFile(myMap);
return myMap;
}
protected void onProgressUpdate(Integer... values) {
super.onProgressUpdate(values);
}
@Override
protected void onPostExecute(MyMap myMaps) {
super.onPostExecute(myMaps);
refreshMapEntry(myMap, dlAdapter);
if (errMsg != null) {
File idFile = MyMap.getMapFile(myMap, MyMap.MapFileType.DlIdFile);
IO.writeToFile("" + MyMap.DlStatus.Error + ": " + errMsg, idFile, false);
myMap.setStatus(MyMap.DlStatus.Error);
return;
}
Variable.getVariable().getRecentDownloadedMaps().add(myMap);
MyMap.setVersionCompatible(myMap.getMapName(), myMap);
myMap.setStatus(MyMap.DlStatus.Complete);
}
}.execute();
}
use of com.junjunguo.pocketmaps.model.MyMap in project PocketMaps by junjunguo.
the class DownloadMapActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_download);
final ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
// return up one level
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
// set status bar
new SetStatusBarColor().setStatusBarColor(findViewById(R.id.statusBarBackgroundDownload), getResources().getColor(R.color.my_primary_dark), this);
List<MyMap> cloudMaps = Variable.getVariable().getCloudMaps();
try {
String[] dlFiles = Variable.getVariable().getDownloadsFolder().list();
if (cloudMaps == null || cloudMaps.isEmpty() || isCloudMapsUpdateRecent()) {
cloudMaps = null;
}
if (cloudMaps != null && dlFiles.length == 0) {
log("Skip downloading existing cloud-map-list");
Collections.sort(cloudMaps);
activateRecyclerView(cloudMaps);
} else {
listDownloadPB = (ProgressBar) findViewById(R.id.my_maps_download_load_list_pb);
listDownloadTV = (TextView) findViewById(R.id.my_maps_download_load_list_tv);
listDownloadTV.bringToFront();
listDownloadPB.setProgress(0);
listDownloadPB.setMax(100);
listDownloadPB.setIndeterminate(false);
listDownloadPB.setVisibility(View.VISIBLE);
listDownloadPB.bringToFront();
activateRecyclerView(new ArrayList<MyMap>());
downloadList(cloudMaps, dlFiles);
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.junjunguo.pocketmaps.model.MyMap in project PocketMaps by junjunguo.
the class MainActivity method refreshList.
/**
* read local files and build a list then add the list to mapAdapter
*/
private void refreshList() {
String[] files = Variable.getVariable().getMapsFolder().list(new FilenameFilter() {
@Override
public boolean accept(File dir, String filename) {
return (filename != null && (filename.endsWith("-gh")));
}
});
if (files == null) {
// Array 'files' was null on a test device.
log("Warning: mapsFolder does not exist!");
files = new String[0];
}
for (String file : files) {
Variable.getVariable().addLocalMap(new MyMap(file));
}
if (!Variable.getVariable().getLocalMaps().isEmpty()) {
mapAdapter.addAll(Variable.getVariable().getLocalMaps());
}
}
use of com.junjunguo.pocketmaps.model.MyMap in project PocketMaps by junjunguo.
the class MainActivity method onClickMap.
@Override
public void onClickMap(View view, int position, TextView tv) {
try {
// load map
// log(mapAdapter.getItem(position).getMapName() + " - " + "chosen");
MyMap myMap = mapAdapter.getItem(position);
if (MyMap.isVersionCompatible(myMap.getMapName())) {
Variable.getVariable().setPrepareInProgress(true);
Variable.getVariable().setCountry(myMap.getMapName());
if (changeMap) {
Variable.getVariable().setLastLocation(null);
// log("last location " + Variable.getVariable().getLastLocation());
MapHandler.reset();
System.gc();
}
startMapActivity();
} else {
logUser("Map is not compatible with this version!\nPlease update map!");
}
myMap.checkUpdateAvailableMsg(this);
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.junjunguo.pocketmaps.model.MyMap in project PocketMaps by junjunguo.
the class MainActivity method addRecentDownloadedFiles.
/**
* add recent downloaded files from Download activity(if any)
*/
private void addRecentDownloadedFiles() {
try {
for (MyMap curMap : Variable.getVariable().getRecentDownloadedMaps()) {
mapAdapter.insert(curMap);
Variable.getVariable().addLocalMap(curMap);
log("add recent downloaded files: " + curMap.getMapName());
}
Variable.getVariable().getRecentDownloadedMaps().clear();
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations