Search in sources :

Example 1 with MyMap

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();
}
Also used : MyMap(com.junjunguo.pocketmaps.model.MyMap) MapUnzip(com.junjunguo.pocketmaps.downloader.MapUnzip) IOException(java.io.IOException) File(java.io.File) URL(java.net.URL)

Example 2 with MyMap

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();
    }
}
Also used : MyMap(com.junjunguo.pocketmaps.model.MyMap) SetStatusBarColor(com.junjunguo.pocketmaps.util.SetStatusBarColor) ActionBar(android.support.v7.app.ActionBar) JSONException(org.json.JSONException) IOException(java.io.IOException)

Example 3 with MyMap

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());
    }
}
Also used : FilenameFilter(java.io.FilenameFilter) MyMap(com.junjunguo.pocketmaps.model.MyMap) File(java.io.File)

Example 4 with MyMap

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();
    }
}
Also used : MyMap(com.junjunguo.pocketmaps.model.MyMap) ActivityNotFoundException(android.content.ActivityNotFoundException)

Example 5 with MyMap

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();
    }
}
Also used : MyMap(com.junjunguo.pocketmaps.model.MyMap) ActivityNotFoundException(android.content.ActivityNotFoundException)

Aggregations

MyMap (com.junjunguo.pocketmaps.model.MyMap)12 File (java.io.File)5 ActivityNotFoundException (android.content.ActivityNotFoundException)2 SetStatusBarColor (com.junjunguo.pocketmaps.util.SetStatusBarColor)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 JSONException (org.json.JSONException)2 DownloadManager (android.app.DownloadManager)1 Request (android.app.DownloadManager.Request)1 BroadcastReceiver (android.content.BroadcastReceiver)1 IntentFilter (android.content.IntentFilter)1 ActionBar (android.support.v7.app.ActionBar)1 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 OnItemClickListener (android.widget.AdapterView.OnItemClickListener)1 TextView (android.widget.TextView)1 MapUnzip (com.junjunguo.pocketmaps.downloader.MapUnzip)1 FilenameFilter (java.io.FilenameFilter)1 URL (java.net.URL)1