public void updateMapResource(MapDownloadResource mapResource) { ContentValues values = new ContentValues(); values.Put(STATE, mapResource.DownloadState); values.Put(NO_DOWNLOADED_BYTES, mapResource.NoDownloadedBytes); values.Put(SKM_FILE_PATH, mapResource.getSKMFilePath()); values.Put(SKM_FILE_SIZE, mapResource.getSkmFileSize()); values.Put(TXG_FILE_PATH, mapResource.getTXGFilePath()); values.Put(TXG_FILE_SIZE, mapResource.getTXGFileSize()); values.Put(ZIP_FILE_PATH, mapResource.getZipFilePath()); values.Put(SKM_AND_ZIP_FILES_SIZE, mapResource.getSkmAndZipFilesSize()); values.Put(UNZIPPED_FILE_SIZE, mapResource.getUnzippedFileSize()); values.Put(DOWNLOAD_PATH, mapResource.DownloadPath); try { resourcesDAO.getDatabase().BeginTransaction(); resourcesDAO.getDatabase().Update(MAPS_TABLE, values, CODE + "=?", new String[] { mapResource.Code }); resourcesDAO.getDatabase().SetTransactionSuccessful(); } catch (SQLException e) { SKLogging.WriteLog(TAG, "SQL EXCEPTION SAVE MAP DATA " + e.Message, SKLogging.LogError); } finally { resourcesDAO.getDatabase().EndTransaction(); } }
public override void OnCreate(SQLiteDatabase db) { SKLogging.WriteLog(TAG, "On create resources database !!!", SKLogging.LogDebug); string createMapResourcesTable = new StringBuilder("CREATE TABLE IF NOT EXISTS ").Append(MapsDAO.MAPS_TABLE).Append(" (") .Append(MapsDAO.KEY).Append(" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, " + "").Append(MapsDAO.CODE).Append(" TEXT UNIQUE, ").Append(MapsDAO.PARENT_CODE) .Append(" TEXT, ").Append(MapsDAO.REGION).Append(" TEXT, ").Append(MapsDAO.NAMES).Append(" TEXT, " + "").Append(MapsDAO.SKM_FILE_PATH).Append(" TEXT, ").Append(MapsDAO.ZIP_FILE_PATH) .Append(" TEXT, ").Append(MapsDAO.TXG_FILE_PATH).Append(" TEXT, ") .Append(MapsDAO.TXG_FILE_SIZE).Append(" INTEGER, " + "").Append(MapsDAO.SKM_AND_ZIP_FILES_SIZE) .Append(" INTEGER, ").Append(MapsDAO.SKM_FILE_SIZE).Append(" INTEGER, " + "").Append(MapsDAO.UNZIPPED_FILE_SIZE) .Append(" INTEGER, ").Append(MapsDAO.BOUNDING_BOX_LATITUDE_MAX).Append(" DOUBLE, ") .Append(MapsDAO.BOUNDING_BOX_LATITUDE_MIN).Append(" DOUBLE, ") .Append(MapsDAO.BOUNDING_BOX_LONGITUDE_MAX).Append(" DOUBLE, ") .Append(MapsDAO.BOUNDING_BOX_LONGITUDE_MIN).Append(" DOUBLE, " + "").Append(MapsDAO.SUBTYPE) .Append(" TEXT, ").Append(MapsDAO.STATE).Append(" INTEGER, ") .Append(MapsDAO.NO_DOWNLOADED_BYTES).Append(" INTEGER, ").Append(MapsDAO.FLAG_ID) .Append(" INTEGER, ").Append(MapsDAO.DOWNLOAD_PATH).Append(" TEXT)").ToString(); db.BeginTransaction(); db.ExecSQL(createMapResourcesTable); db.SetTransactionSuccessful(); db.EndTransaction(); }
private void readCitiesHierarchy(Dictionary <string, string> mapsItemsCodes, String currentParentCode, JSONArray citiesArray) { for (int i = 0; i < citiesArray.Length(); i++) { try { JSONObject currentCityObject = citiesArray.GetJSONObject(i); if (currentCityObject != null) { try { String currentCityCode = currentCityObject.GetString(CITY_CODE_ID); if ((currentCityCode != null) && (currentParentCode != null)) { mapsItemsCodes.Add(currentCityCode, currentParentCode); } } catch (JSONException ex) { SKLogging.WriteLog(TAG, ex.Message, SKLogging.LogDebug); } } } catch (JSONException ex) { SKLogging.WriteLog(TAG, ex.Message, SKLogging.LogDebug); } } }
private void readCountriesHierarchy(Dictionary <String, String> mapsItemsCodes, string currentContinentCode, JSONArray countriesArray) { for (int i = 0; i < countriesArray.Length(); i++) { try { JSONObject currentCountryObject = countriesArray.GetJSONObject(i); if (currentCountryObject != null) { try { String currentCountryCode = currentCountryObject.GetString(COUNTRY_CODE_ID); if ((currentContinentCode != null) && (currentCountryCode != null)) { mapsItemsCodes.Add(currentCountryCode, currentContinentCode); try { JSONArray citiesArray = currentCountryObject.GetJSONArray(CITY_CODES_ID); if (citiesArray != null) { readCitiesHierarchy(mapsItemsCodes, currentCountryCode, citiesArray); } } catch (JSONException ex) { SKLogging.WriteLog(TAG, ex.Message, SKLogging.LogDebug); } try { JSONArray statesArray = currentCountryObject.GetJSONArray(STATE_CODES_ID); if (statesArray != null) { readStatesHierarchy(mapsItemsCodes, currentCountryCode, statesArray); } } catch (JSONException ex) { SKLogging.WriteLog(TAG, ex.Message, SKLogging.LogDebug); } } } catch (JSONException ex) { SKLogging.WriteLog(TAG, ex.Message, SKLogging.LogDebug); } } } catch (JSONException ex) { SKLogging.WriteLog(TAG, ex.Message, SKLogging.LogDebug); } } }
public void OpenDatabase() { try { if ((sqLiteDatabaseInstance == null) || !sqLiteDatabaseInstance.IsOpen) { sqLiteDatabaseInstance = WritableDatabase; } } catch (SQLException e) { SKLogging.WriteLog(TAG, "Error when opening database: " + e.Message, SKLogging.LogWarning); sqLiteDatabaseInstance = ReadableDatabase; } }
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 void readWorldHierarchy(Dictionary <String, String> mapsItemsCodes, JSONArray continentsArray) { for (int i = 0; i < continentsArray.Length(); i++) { try { JSONObject currentContinentObject = continentsArray.GetJSONObject(i); if (currentContinentObject != null) { try { String currentContinentCode = currentContinentObject.GetString(CONTINENT_CODE_ID); if (currentContinentCode != null) { mapsItemsCodes.Add(currentContinentCode, ""); JSONArray countriesArray = null; try { countriesArray = currentContinentObject.GetJSONArray(COUNTRIES_ID); } catch (JSONException ex) { SKLogging.WriteLog(TAG, ex.Message, SKLogging.LogDebug); } if (countriesArray != null) { readCountriesHierarchy(mapsItemsCodes, currentContinentCode, countriesArray); } } } catch (JSONException ex) { SKLogging.WriteLog(TAG, ex.Message, SKLogging.LogDebug); } } } catch (JSONException ex) { SKLogging.WriteLog(TAG, ex.Message, SKLogging.LogDebug); } } }
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(); } }
public void clearResourcesInDownloadQueue() { ContentValues values = new ContentValues(); values.Put(STATE, SKToolsDownloadItem.NotQueued); values.Put(NO_DOWNLOADED_BYTES, 0); try { resourcesDAO.getDatabase().BeginTransaction(); resourcesDAO.getDatabase().Update(MAPS_TABLE, values, STATE + "=? OR " + STATE + "=? OR " + STATE + "=?", new string[] { SKToolsDownloadItem.Downloading.ToString(), SKToolsDownloadItem.Paused.ToString(), SKToolsDownloadItem.Queued.ToString() }); resourcesDAO.getDatabase().SetTransactionSuccessful(); } catch (SQLException e) { SKLogging.WriteLog(TAG, "SQL EXCEPTION SAVE MAP DATA " + e.Message, SKLogging.LogError); } finally { resourcesDAO.getDatabase().EndTransaction(); } }
public void insertMaps(List <MapDownloadResource> maps, Dictionary <string, string> mapsItemsCodes, Dictionary <string, string> regionItemsCodes, Context applicationContext) { try { if ((maps != null) && (mapsItemsCodes != null) && (regionItemsCodes != null)) { // create a compile statement for inserting the maps using transactions StringBuilder insertCommand = new StringBuilder("INSERT INTO "); insertCommand.Append(MAPS_TABLE).Append(" VALUES (?"); // the number of columns in maps table is 20 for (int i = 0; i < 20; i++) { insertCommand.Append(",?"); } insertCommand.Append(");"); resourcesDAO.getDatabase().BeginTransaction(); SQLiteStatement insertStatement = resourcesDAO.getDatabase().CompileStatement(insertCommand.ToString()); int columnIndex, lineIndex = 0; foreach (MapDownloadResource map in maps) { columnIndex = 1; lineIndex++; insertStatement.ClearBindings(); insertStatement.BindLong(columnIndex++, lineIndex); insertStatement.BindString(columnIndex++, map.Code); insertStatement.BindString(columnIndex++, mapsItemsCodes[map.Code]); if ((map.getSubType() != null) && map.getSubType().Equals(STATE_TYPE)) //ignorecode { insertStatement.BindString(columnIndex++, regionItemsCodes[map.Code]); } else { insertStatement.BindString(columnIndex++, ""); } // compute the string that contains all the name translations StringBuilder nameInAllSpecifiedLanguages = new StringBuilder(); if (map.getNames() != null) { foreach (var currentEntry in map.getNames()) { nameInAllSpecifiedLanguages.Append(currentEntry.Key).Append("=").Append(currentEntry.Value).Append(";"); } } if (nameInAllSpecifiedLanguages.Length > 1) { insertStatement.BindString(columnIndex++, nameInAllSpecifiedLanguages.ToString().Substring(0, nameInAllSpecifiedLanguages.Length - 1)); } else { insertStatement.BindString(columnIndex++, ""); } insertStatement.BindString(columnIndex++, map.getSKMFilePath()); insertStatement.BindString(columnIndex++, map.getZipFilePath()); insertStatement.BindString(columnIndex++, map.getTXGFilePath()); insertStatement.BindLong(columnIndex++, (int)map.getTXGFileSize()); insertStatement.BindLong(columnIndex++, (int)map.getSkmAndZipFilesSize()); insertStatement.BindLong(columnIndex++, (int)map.getSkmFileSize()); insertStatement.BindLong(columnIndex++, (int)map.getUnzippedFileSize()); insertStatement.BindDouble(columnIndex++, map.getBbLatMax()); insertStatement.BindDouble(columnIndex++, map.getBbLatMin()); insertStatement.BindDouble(columnIndex++, map.getBbLongMax()); insertStatement.BindDouble(columnIndex++, map.getBbLongMin()); insertStatement.BindString(columnIndex++, map.getSubType()); insertStatement.BindLong(columnIndex++, map.DownloadState); insertStatement.BindLong(columnIndex++, map.NoDownloadedBytes); insertStatement.BindLong(columnIndex++, 0); insertStatement.BindString(columnIndex, map.DownloadPath); insertStatement.Execute(); } } } finally { if ((maps != null) && (mapsItemsCodes != null)) { SKLogging.WriteLog(TAG, "Maps were inserted into database !!!", SKLogging.LogDebug); // close the GENERAL transaction resourcesDAO.getDatabase().SetTransactionSuccessful(); resourcesDAO.getDatabase().EndTransaction(); } } }
/** * read maps packages list * @param maps a list of maps objects that will be read from JSON file * @param packagesArray packages array */ private void readMapsPackages(List <MapDownloadResource> maps, JSONArray packagesArray) { for (int i = 0; i < packagesArray.Length(); i++) { JSONObject currentPackageObject = null; try { currentPackageObject = packagesArray.GetJSONObject(i); } catch (JSONException ex) { SKLogging.WriteLog(TAG, ex.Message, SKLogging.LogDebug); } if (currentPackageObject != null) { MapDownloadResource currentMap = new MapDownloadResource(); try { currentMap.Code = (currentPackageObject.GetString(PACKAGE_CODE_ID)); } catch (JSONException ex) { SKLogging.WriteLog(TAG, ex.Message, SKLogging.LogDebug); } try { currentMap.setSubType(GetMapType(currentPackageObject.GetInt(TYPE_ID))); } catch (JSONException ex) { SKLogging.WriteLog(TAG, ex.Message, SKLogging.LogDebug); } try { JSONArray currentMapNames = currentPackageObject.GetJSONArray(LANGUAGES_ID); if (currentMapNames != null) { for (int j = 0; j < currentMapNames.Length(); j++) { JSONObject currentMapNameObject = currentMapNames.GetJSONObject(j); if (currentMapNameObject != null) { String currentMapName = currentMapNameObject.GetString(TL_NAME_ID); if (currentMapName != null) { currentMap.setName(currentMapName, currentMapNameObject.GetString(LNG_CODE_ID)); } } } } } catch (JSONException ex) { SKLogging.WriteLog(TAG, ex.Message, SKLogging.LogDebug); } try { JSONObject currentMapBoundingBox = currentPackageObject.GetJSONObject(BBOX_ID); if (currentMapBoundingBox != null) { currentMap.setBbLatMax(currentMapBoundingBox.GetDouble(LAT_MAX_ID)); currentMap.setBbLatMin(currentMapBoundingBox.GetDouble(LAT_MIN_ID)); currentMap.setBbLongMax(currentMapBoundingBox.GetDouble(LONG_MAX_ID)); currentMap.setBbLongMin(currentMapBoundingBox.GetDouble(LONG_MIN_ID)); } } catch (JSONException ex) { SKLogging.WriteLog(TAG, ex.Message, SKLogging.LogDebug); } try { currentMap.setSkmFileSize(currentPackageObject.GetLong(SKM_SIZE_ID)); } catch (JSONException ex) { SKLogging.WriteLog(TAG, ex.Message, SKLogging.LogDebug); } try { currentMap.setSkmFilePath(currentPackageObject.GetString(FILE_ID)); } catch (JSONException ex) { SKLogging.WriteLog(TAG, ex.Message, SKLogging.LogDebug); } try { currentMap.setZipFilePath(currentPackageObject.GetString(NB_ZIP_ID)); } catch (JSONException ex) { SKLogging.WriteLog(TAG, ex.Message, SKLogging.LogDebug); } try { currentMap.setUnzippedFileSize(currentPackageObject.GetLong(UNZIP_SIZE_ID)); } catch (JSONException ex) { SKLogging.WriteLog(TAG, ex.Message, SKLogging.LogDebug); } try { JSONObject currentMapTXGDetails = currentPackageObject.GetJSONObject(TEXTURE_ID); if (currentMapTXGDetails != null) { currentMap.setTXGFilePath(currentMapTXGDetails.GetString(TEXTURES_BIG_FILE_ID)); currentMap.setTXGFileSize(currentMapTXGDetails.GetLong(SIZE_BIG_FILE_ID)); } } catch (JSONException ex) { SKLogging.WriteLog(TAG, ex.Message, SKLogging.LogDebug); } try { currentMap.setSkmAndZipFilesSize(currentPackageObject.GetLong(SIZE_ID)); } catch (JSONException ex) { SKLogging.WriteLog(TAG, ex.Message, SKLogging.LogDebug); } if ((currentMap.Code != null) && (currentMap.getSubType() != null)) { removeNullValuesIfExist(currentMap); maps.Add(currentMap); } } } }