예제 #1
0
        public void ParseMapJsonData(List <MapDownloadResource> maps, Dictionary <String, String> mapsItemsCodes, Dictionary <String, String> regionItemsCodes, InputStream inputStream)
        {
            Console.WriteLine("Catalin ; start parsing !!!");
            long       startTime    = DemoUtils.CurrentTimeMillis();
            JSONObject reader       = new JSONObject(convertJSONFileContentToAString(inputStream));
            JSONArray  regionsArray = reader.GetJSONArray(REGIONS_ID);

            if (regionsArray != null)
            {
                readUSRegionsHierarchy(regionItemsCodes, regionsArray);
            }
            JSONArray packagesArray = reader.GetJSONArray(PACKAGES_ID);

            if (packagesArray != null)
            {
                readMapsPackages(maps, packagesArray);
            }
            JSONObject worldObject = reader.GetJSONObject(WORLD_ID);

            if (worldObject != null)
            {
                JSONArray continentsArray = worldObject.GetJSONArray(CONTINENTS_ID);
                if (continentsArray != null)
                {
                    readWorldHierarchy(mapsItemsCodes, continentsArray);
                }
            }

            /*-for (Map.Entry<String, String> currentEntry : mapsItemsCodes.entrySet()) {
             *  System.out.println("Catalin ; key = " + currentEntry.getKey() + " ; value = " + currentEntry.getValue());
             * }*/
            Console.WriteLine("Catalin ; total loading time = " + (DemoUtils.CurrentTimeMillis() - startTime) + " ; maps size = " + maps.Count);
        }
            public void OnDownloadProgress(SKToolsDownloadItem currentDownloadItem)
            {
                ListItem         affectedListItem;
                DownloadResource resource;
                bool             stateChanged = false;
                long             bytesDownloadedSinceLastUpdate = 0;

                if (_activity.codesMap.TryGetValue(currentDownloadItem.ItemCode, out affectedListItem))
                {
                    stateChanged = currentDownloadItem.DownloadState != affectedListItem.DownloadResource.DownloadState;
                    bytesDownloadedSinceLastUpdate = currentDownloadItem.NoDownloadedBytes - affectedListItem.DownloadResource.NoDownloadedBytes;
                    affectedListItem.DownloadResource.NoDownloadedBytes = (currentDownloadItem.NoDownloadedBytes);
                    affectedListItem.DownloadResource.DownloadState     = (currentDownloadItem.DownloadState);
                    resource = affectedListItem.DownloadResource;
                    _activity.RunOnUiThread((() => NotifyDataSetChanged()));
                }
                else
                {
                    resource = allMapResources[currentDownloadItem.ItemCode];
                    bytesDownloadedSinceLastUpdate = currentDownloadItem.NoDownloadedBytes - resource.NoDownloadedBytes;
                    stateChanged = currentDownloadItem.DownloadState != resource.DownloadState;
                    resource.NoDownloadedBytes = currentDownloadItem.NoDownloadedBytes;
                    resource.DownloadState     = currentDownloadItem.DownloadState;
                }
                if (resource.DownloadState == SKToolsDownloadItem.Downloaded)
                {
                    activeDownloads.Remove(resource);
                    _activity.appContext.AppPrefs.SaveDownloadQueuePreference(activeDownloads);
                }
                else if (resource.DownloadState == SKToolsDownloadItem.Downloading)
                {
                    _activity.downloadChunksMap.Add(DemoUtils.CurrentTimeMillis(), bytesDownloadedSinceLastUpdate);
                    if (stateChanged)
                    {
                        _activity.StartPeriodicUpdates();
                    }
                }
                if (resource.DownloadState != SKToolsDownloadItem.Downloading)
                {
                    _activity.StopPeriodicUpdates();
                }
                if (stateChanged)
                {
                    mapsDAO.updateMapResource((MapDownloadResource)resource);
                }

                _activity.appContext.AppPrefs.SaveDownloadStepPreference(currentDownloadItem.CurrentStepIndex);
            }
예제 #3
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.activity_splash);

            SKLogging.EnableLogs(true);
            bool multipleMapSupport = false;

            try
            {
                ApplicationInfo applicationInfo = PackageManager.GetApplicationInfo(PackageName, PackageInfoFlags.MetaData);
                Bundle          bundle          = applicationInfo.MetaData;
                multipleMapSupport = bundle.GetBoolean("provideMultipleMapSupport");
                _debugKitEnabled   = bundle.GetBoolean(DebugKitConfig.EnableDebugKitKey);
            }
            catch (PackageManager.NameNotFoundException e)
            {
                _debugKitEnabled = false;
                e.PrintStackTrace();
            }
            if (multipleMapSupport)
            {
                SKMapSurfaceView.PreserveGLContext    = false;
                DemoUtils.IsMultipleMapSupportEnabled = true;
            }

            try
            {
                SKLogging.WriteLog(TAG, "Initialize SKMaps", SKLogging.LogDebug);
                _startLibInitTime = DemoUtils.CurrentTimeMillis();
                CheckForSDKUpdate();
                //            SKMapsInitSettings mapsInitSettings = new SKMapsInitSettings();
                //            mapsInitSettings.setMapResourcesPath(getExternalFilesDir(null).toString()+"/SKMaps/");
                //  mapsInitSettings.setConnectivityMode(SKMaps.CONNECTIVITY_MODE_OFFLINE);
                //  mapsInitSettings.setPreinstalledMapsPath(getExternalFilesDir(null).toString()+"/SKMaps/PreinstalledMaps/");
                SKMaps.Instance.InitializeSKMaps(Application, this);
            }
            catch (SKDeveloperKeyException exception)
            {
                exception.PrintStackTrace();
                DemoUtils.ShowApiKeyErrorDialog(this);
            }
        }
            private Tuple <String, String> calculateDownloadEstimates(DownloadResource resource, int referencePeriodInSeconds)
            {
                long referencePeriod      = 1000 * referencePeriodInSeconds;
                long currentTimestamp     = DemoUtils.CurrentTimeMillis();
                long downloadPeriod       = currentTimestamp - referencePeriod < _activity.downloadStartTime ? currentTimestamp - _activity.downloadStartTime : referencePeriod;
                long totalBytesDownloaded = 0;
                var  iterator             = _activity.downloadChunksMap.GetEnumerator();

                do
                {
                    var  entry           = iterator.Current;
                    long timestamp       = entry.Key;
                    long bytesDownloaded = entry.Value;
                    if (currentTimestamp - timestamp > referencePeriod)
                    {
                        //iterator.remove(); remove current item
                    }
                    else
                    {
                        totalBytesDownloaded += bytesDownloaded;
                    }
                } while (iterator.MoveNext());
                float  downloadPeriodSec = downloadPeriod / 1000f;
                long   bytesPerSecond    = (long)Math.Round(totalBytesDownloaded / downloadPeriodSec);
                String formattedTimeLeft = "";

                if (totalBytesDownloaded == 0)
                {
                    formattedTimeLeft = "-";
                }
                else if (resource is MapDownloadResource)
                {
                    MapDownloadResource mapResource = (MapDownloadResource)resource;
                    long remainingBytes             = (mapResource.getSkmAndZipFilesSize() + mapResource.getTXGFileSize()) - mapResource.NoDownloadedBytes;
                    long timeLeft = (downloadPeriod * remainingBytes) / totalBytesDownloaded;
                    formattedTimeLeft = getFormattedTime(timeLeft);
                }

                return(new Tuple <string, string>(convertBytesToStringRepresentation(bytesPerSecond) + "/s", formattedTimeLeft));
            }
예제 #5
0
 public void OnLibraryInitialized(bool isSuccessful)
 {
     SKLogging.WriteLog(TAG, " SKMaps library initialized isSuccessful= " + isSuccessful + " time= " + (DemoUtils.CurrentTimeMillis() - _startLibInitTime), SKLogging.LogDebug);
     if (isSuccessful)
     {
         DemoApplication app = Application as DemoApplication;
         app.MapCreatorFilePath  = SKMaps.Instance.MapInitSettings.MapResourcesPath + "MapCreator/mapcreatorFile.json";
         app.MapResourcesDirPath = SKMaps.Instance.MapInitSettings.MapResourcesPath;
         CopyOtherResources();
         PrepareMapCreatorFile();
         //everything ok. proceed
         SKVersioningManager.Instance.SetMapUpdateListener(this);
         GoToMap();
     }
     else
     {
         //map was not initialized successfully
         Finish();
     }
 }
        ///**
        // * Runnable used to trigger UI updates that refresh the download estimates (for current speed and remaining time)
        // */
        //private Action updater = () =>
        //{
        //    refreshDownloadEstimates = true;
        //    RunOnUiThread(() => adapter.NotifyDataSetChanged());
        //    handler.Interval = 1000;
        //    handler.Elapsed += () => { };
        //    handler.Start();
        //};

        private void StartPeriodicUpdates()
        {
            downloadStartTime = DemoUtils.CurrentTimeMillis();
            //handler.PostDelayed(updater, 3000);
        }