@Override protected void onResume() { super.onResume(); Intent intent = getIntent(); LatLon startPoint = null; if (intent != null) { double lat = intent.getDoubleExtra(SEARCH_LAT, 0); double lon = intent.getDoubleExtra(SEARCH_LON, 0); if (lat != 0 || lon != 0) { startPoint = new LatLon(lat, lon); } } if (startPoint == null && getParent() instanceof SearchActivity) { startPoint = ((SearchActivity) getParent()).getSearchPoint(); } if (startPoint == null) { startPoint = settings.getLastKnownMapLocation(); } LatLon pointToNavigate = settings.getPointToNavigate(); if (!Algoritms.objectEquals(pointToNavigate, this.destinationLocation) || !Algoritms.objectEquals(startPoint, this.lastKnownMapLocation)) { destinationLocation = pointToNavigate; selectedDestinationLocation = destinationLocation; lastKnownMapLocation = startPoint; searchTransport(); } }
/** * Set the special phrases to a certain language. This method needs to be used before the * getSpecialPhrase method * * @param lang the language to use * @throws IOException when reading the text file failed */ public static void setLanguage(Context ctx, OsmandSettings settings) throws IOException { String lang = getPreferredLanguage(settings).getLanguage(); m = new HashMap<String, String>(); // The InputStream opens the resourceId and sends it to the buffer InputStream is = null; BufferedReader br = null; try { try { is = ctx.getAssets().open("specialphrases/specialphrases_" + lang + ".txt"); } catch (IOException ex) { // second try: default to English, if this fails, the error is thrown outside is = ctx.getAssets().open("specialphrases/specialphrases_en.txt"); } br = new BufferedReader(new InputStreamReader(is)); String readLine = null; // While the BufferedReader readLine is not null while ((readLine = br.readLine()) != null) { String[] arr = readLine.split(","); if (arr != null && arr.length == 2) { m.put(arr[0], arr[1]); } } } finally { Algoritms.closeStream(is); Algoritms.closeStream(br); } }
public void removeDatabase(File file) { if (DBDialect.H2 == this) { File[] list = file.getParentFile().listFiles(); for (File f : list) { if (f.getName().startsWith(file.getName())) { Algoritms.removeAllFiles(f); } } } else { Algoritms.removeAllFiles(file); } }
@Override public void locationUpdate(LatLon l) { if (!Algoritms.objectEquals(l, this.lastKnownMapLocation)) { lastKnownMapLocation = l; searchTransport(); } }
public static java.util.List<TileSourceTemplate> getUserDefinedTemplates(File tilesDir) { java.util.List<TileSourceTemplate> ts = new ArrayList<TileSourceTemplate>(); if (tilesDir != null) { File[] listFiles = tilesDir.listFiles(); if (listFiles != null) { for (File f : listFiles) { File ch = new File(f, "url"); // $NON-NLS-1$ if (f.isDirectory() && ch.exists()) { try { BufferedReader read = new BufferedReader( new InputStreamReader(new FileInputStream(ch), "UTF-8")); // $NON-NLS-1$ String url = read.readLine(); read.close(); if (!Algoritms.isEmpty(url)) { url = url.replaceAll(Pattern.quote("{$x}"), "{1}"); // $NON-NLS-1$ //$NON-NLS-2$ url = url.replaceAll(Pattern.quote("{$z}"), "{0}"); // $NON-NLS-1$//$NON-NLS-2$ url = url.replaceAll(Pattern.quote("{$y}"), "{2}"); // $NON-NLS-1$ //$NON-NLS-2$ TileSourceTemplate t = new TileSourceTemplate( f.getName(), url, ".jpg", 18, 1, 256, 16, 20000); // $NON-NLS-1$ ts.add(t); } } catch (IOException e) { log.info("Mailformed dir " + f.getName(), e); // $NON-NLS-1$ } } } } } return ts; }
@Override protected String doInBackground(LocalIndexInfo... params) { int count = 0; int total = 0; for (LocalIndexInfo info : params) { if (!isCancelled()) { String warning = null; try { File file = new File(info.getPathToData()); String userName = settings.USER_NAME.get(); String pwd = settings.USER_PASSWORD.get(); String url = URL_TO_UPLOAD_GPX + "?author=" + URLEncoder.encode(userName, "UTF-8") + "&wd=" + URLEncoder.encode(pwd, "UTF-8") + "&file=" + URLEncoder.encode(file.getName(), "UTF-8"); warning = Algoritms.uploadFile(url, file, "filename", true); } catch (UnsupportedEncodingException e) { warning = e.getMessage(); } total++; if (warning == null) { count++; } else { publishProgress(warning); } } } return getString(R.string.local_index_items_uploaded, count, total); }
@Override protected String doInBackground(String... filesToDownload) { try { List<File> filesToReindex = new ArrayList<File>(); boolean forceWifi = downloadFileHelper.isWifiConnected(); for (int i = 0; i < filesToDownload.length; i++) { String filename = filesToDownload[i]; DownloadEntry entry = entriesToDownload.get(filename); if (entry != null) { String indexOfAllFiles = filesToDownload.length <= 1 ? "" : (" [" + (i + 1) + "/" + filesToDownload.length + "]"); boolean result = entry.downloadFile( downloadFileHelper, filename, filesToReindex, progress, indexOfAllFiles, this, forceWifi, getAssets()); if (result) { entriesToDownload.remove(filename); downloads.set(downloads.get() + 1); if (entry.existingBackupFile != null) { Algoritms.removeAllFiles(entry.existingBackupFile); } publishProgress(entry); } } } boolean vectorMapsToReindex = false; for (File f : filesToReindex) { if (f.getName().endsWith(IndexConstants.BINARY_MAP_INDEX_EXT)) { vectorMapsToReindex = true; break; } } // reindex vector maps all at one time ResourceManager manager = getMyApplication().getResourceManager(); manager.indexVoiceFiles(progress); if (vectorMapsToReindex) { List<String> warnings = manager.indexingMaps(progress); if (!warnings.isEmpty()) { return warnings.get(0); } } } catch (InterruptedException e) { // do not dismiss dialog } finally { if (progressFileDlg != null) { removeDialog(DIALOG_PROGRESS_FILE); progressFileDlg = null; } } return null; }
protected void updateBuildingSection() { if (radioBuilding) { ((TextView) findViewById(R.id.BuildingText)).setText(R.string.search_address_building); if (Algoritms.isEmpty(building)) { ((TextView) findViewById(R.id.BuildingButton)).setText(R.string.choose_building); } else { ((TextView) findViewById(R.id.BuildingButton)).setText(building); } } else { ((TextView) findViewById(R.id.BuildingText)).setText(R.string.search_address_street); if (Algoritms.isEmpty(street2)) { ((TextView) findViewById(R.id.BuildingButton)).setText(R.string.choose_intersected_street); } else { ((TextView) findViewById(R.id.BuildingButton)).setText(street2); } } findViewById(R.id.ResetBuilding) .setEnabled(!Algoritms.isEmpty(street2) || !Algoritms.isEmpty(building)); }
public void showOnMap(boolean navigateTo) { if (searchPoint == null) { return; } String historyName = null; String objectName = ""; int zoom = 12; if (!Algoritms.isEmpty(street2) && !Algoritms.isEmpty(street)) { String cityName = !Algoritms.isEmpty(postcode) ? postcode : city; objectName = street; historyName = MessageFormat.format( getString(R.string.search_history_int_streets), street, street2, cityName); zoom = 16; } else if (!Algoritms.isEmpty(building)) { String cityName = !Algoritms.isEmpty(postcode) ? postcode : city; objectName = street + " " + building; historyName = MessageFormat.format( getString(R.string.search_history_building), building, street, cityName); zoom = 16; } else if (!Algoritms.isEmpty(street)) { String cityName = postcode != null ? postcode : city; objectName = street; historyName = MessageFormat.format(getString(R.string.search_history_street), street, cityName); zoom = 15; } else if (!Algoritms.isEmpty(city)) { historyName = MessageFormat.format(getString(R.string.search_history_city), city); objectName = city; zoom = 13; } if (selectAddressMode) { Intent intent = getIntent(); intent.putExtra(SELECT_ADDRESS_POINT_INTENT_KEY, objectName); intent.putExtra(SELECT_ADDRESS_POINT_LAT, searchPoint.getLatitude()); intent.putExtra(SELECT_ADDRESS_POINT_LON, searchPoint.getLongitude()); setResult(SELECT_ADDRESS_POINT_RESULT_OK, intent); finish(); } else { if (navigateTo) { OsmandApplication app = (OsmandApplication) getApplication(); app.getTargetPointsHelper() .navigatePointDialogAndLaunchMap( SearchAddressActivity.this, searchPoint.getLatitude(), searchPoint.getLongitude(), historyName); } else { osmandSettings.setMapLocationToShow( searchPoint.getLatitude(), searchPoint.getLongitude(), zoom, historyName); MapActivity.launchMapActivityMoveToTop(SearchAddressActivity.this); } } }
/** * Use this method to query a special phrase for a certain subtype * * <p>If the language isn't set yet, a nullpointer exception will be thrown * * @param value the subtype to query * @return the special phrase according to the asked key, or "null" if the key isn't found */ public static String getSpecialPhrase(String value) { if (m == null) { // do not throw exception because OsmAndApplication is not always initiliazed before // this call log.warn("The language has not been set for special phrases"); return value; } String specialValue = m.get(value); if (Algoritms.isEmpty(specialValue)) { return value; } return specialValue; }
@Override protected String doInBackground(LocalIndexInfo... params) { int count = 0; int total = 0; for (LocalIndexInfo info : params) { if (!isCancelled()) { boolean successfull = false; if (operation == DELETE_OPERATION) { File f = new File(info.getPathToData()); successfull = Algoritms.removeAllFiles(f); } else if (operation == RESTORE_OPERATION) { successfull = move(new File(info.getPathToData()), getFileToRestore(info)); if (successfull) { info.setBackupedData(false); } } else if (operation == BACKUP_OPERATION) { successfull = move(new File(info.getPathToData()), getFileToBackup(info)); if (successfull) { info.setBackupedData(true); } } total++; if (successfull) { count++; publishProgress(info); } } } if (operation == DELETE_OPERATION) { return getString(R.string.local_index_items_deleted, count, total); } else if (operation == BACKUP_OPERATION) { return getString(R.string.local_index_items_backuped, count, total); } else if (operation == RESTORE_OPERATION) { return getString(R.string.local_index_items_restored, count, total); } return ""; }
public void loadData() { if (!Algoritms.isEmpty(region)) { String postcodeStr = osmandSettings.getLastSearchedPostcode(); if (!Algoritms.isEmpty(postcodeStr)) { postcode = postcodeStr; } else { city = osmandSettings.getLastSearchedCityName(); } if (!Algoritms.isEmpty(postcode) || !Algoritms.isEmpty(city)) { street = osmandSettings.getLastSearchedStreet(); if (!Algoritms.isEmpty(street)) { String str = osmandSettings.getLastSearchedIntersectedStreet(); radioBuilding = Algoritms.isEmpty(str); if (!radioBuilding) { street2 = str; } else { building = osmandSettings.getLastSearchedBuilding(); } } } } }
protected void updateUI() { showOnMap.setEnabled(searchPoint != null); navigateTo.setEnabled(searchPoint != null); if (selectAddressMode) { navigateTo.setText(R.string.search_select_point); showOnMap.setVisibility(View.INVISIBLE); findViewById(R.id.SearchOnline).setVisibility(View.INVISIBLE); } else { navigateTo.setText(R.string.navigate_to); findViewById(R.id.SearchOnline).setVisibility(View.VISIBLE); showOnMap.setVisibility(View.VISIBLE); } findViewById(R.id.ResetCountry).setEnabled(!Algoritms.isEmpty(region)); if (Algoritms.isEmpty(region)) { countryButton.setText(R.string.ChooseCountry); } else { countryButton.setText(region); } findViewById(R.id.ResetCity) .setEnabled(!Algoritms.isEmpty(city) || !Algoritms.isEmpty(postcode)); if (Algoritms.isEmpty(city) && Algoritms.isEmpty(postcode)) { cityButton.setText(R.string.choose_city); } else { if (!Algoritms.isEmpty(postcode)) { cityButton.setText(postcode); } else { cityButton.setText(city); } } cityButton.setEnabled(!Algoritms.isEmpty(region)); findViewById(R.id.ResetStreet).setEnabled(!Algoritms.isEmpty(street)); if (Algoritms.isEmpty(street)) { streetButton.setText(R.string.choose_street); } else { streetButton.setText(street); } streetButton.setEnabled(!Algoritms.isEmpty(city) || !Algoritms.isEmpty(postcode)); buildingButton.setEnabled(!Algoritms.isEmpty(street)); ((RadioGroup) findViewById(R.id.RadioGroup)) .setVisibility(Algoritms.isEmpty(street) ? View.GONE : View.VISIBLE); if (radioBuilding) { ((RadioButton) findViewById(R.id.RadioBuilding)).setChecked(true); } else { ((RadioButton) findViewById(R.id.RadioIntersStreet)).setChecked(true); } updateBuildingSection(); }
private void drawRouteInfo(Canvas canvas) { if (routeLayer != null && routeLayer.getHelper().isRouterEnabled()) { if (routeLayer.getHelper().isFollowingMode()) { int d = routeLayer.getHelper().getDistanceToNextRouteDirection(); if (showMiniMap || d == 0) { if (!routeLayer.getPath().isEmpty()) { canvas.save(); canvas.clipRect(boundsForMiniRoute); canvas.drawRoundRect(boundsForMiniRoute, roundCorner, roundCorner, paintAlphaGray); canvas.drawRoundRect(boundsForMiniRoute, roundCorner, roundCorner, paintBlack); canvas.translate( centerMiniRouteX - view.getCenterPointX(), centerMiniRouteY - view.getCenterPointY()); canvas.scale( scaleMiniRoute, scaleMiniRoute, view.getCenterPointX(), view.getCenterPointY()); canvas.rotate(view.getRotate(), view.getCenterPointX(), view.getCenterPointY()); canvas.drawCircle( view.getCenterPointX(), view.getCenterPointY(), 3 / scaleMiniRoute, fillBlack); canvas.drawPath(routeLayer.getPath(), paintMiniRoute); canvas.restore(); } } else { canvas.drawRoundRect(boundsForMiniRoute, roundCorner, roundCorner, paintAlphaGray); canvas.drawRoundRect(boundsForMiniRoute, roundCorner, roundCorner, paintBlack); RouteDirectionInfo next = routeLayer.getHelper().getNextRouteDirectionInfo(); if (next != null) { if (!Algoritms.objectEquals(cachedTurnType, next.turnType)) { cachedTurnType = next.turnType; calcTurnPath(pathForTurn, cachedTurnType, pathTransform); if (cachedTurnType.getExitOut() > 0) { cachedExitOut = cachedTurnType.getExitOut() + ""; // $NON-NLS-1$ } else { cachedExitOut = null; } } canvas.drawPath(pathForTurn, paintRouteDirection); canvas.drawPath(pathForTurn, paintBlack); if (cachedExitOut != null) { canvas.drawText( cachedExitOut, boundsForMiniRoute.centerX() - 6 * scaleCoefficient, boundsForMiniRoute.centerY() - 9 * scaleCoefficient, paintBlack); } canvas.drawText( OsmAndFormatter.getFormattedDistance(d, map), boundsForMiniRoute.left + 10 * scaleCoefficient, boundsForMiniRoute.bottom - 9 * scaleCoefficient, paintBlack); } } } boolean followingMode = routeLayer.getHelper().isFollowingMode(); int time = routeLayer.getHelper().getLeftTime(); if (time == 0) { cachedLeftTime = 0; cachedLeftTimeString = null; } else { if (followingMode && showArrivalTime) { long toFindTime = time * 1000 + System.currentTimeMillis(); if (Math.abs(toFindTime - cachedLeftTime) > 30000) { cachedLeftTime = toFindTime; if (DateFormat.is24HourFormat(map)) { cachedLeftTimeString = DateFormat.format("kk:mm", toFindTime).toString(); // $NON-NLS-1$ } else { cachedLeftTimeString = DateFormat.format("k:mm aa", toFindTime).toString(); // $NON-NLS-1$ } boundsForLeftTime.left = -paintBlack.measureText(cachedLeftTimeString) - 10 * scaleCoefficient + boundsForLeftTime.right; } } else { if (Math.abs(time - cachedLeftTime) > 30) { cachedLeftTime = time; int hours = time / (60 * 60); int minutes = (time / 60) % 60; cachedLeftTimeString = String.format("%d:%02d", hours, minutes); // $NON-NLS-1$ boundsForLeftTime.left = -paintBlack.measureText(cachedLeftTimeString) - 10 * scaleCoefficient + boundsForLeftTime.right; } } } if (cachedLeftTimeString != null) { int w = (int) (boundsForLeftTime.right - boundsForLeftTime.left); boundsForLeftTime.right = view.getWidth(); boundsForLeftTime.left = view.getWidth() - w; canvas.drawRoundRect(boundsForLeftTime, roundCorner, roundCorner, paintAlphaGray); canvas.drawRoundRect(boundsForLeftTime, roundCorner, roundCorner, paintBlack); canvas.drawText( cachedLeftTimeString, boundsForLeftTime.left + 5 * scaleCoefficient, boundsForLeftTime.bottom - 9 * scaleCoefficient, paintBlack); } } }
private boolean updatePaint( RenderingRuleSearchRequest req, Paint p, int ind, boolean area, RenderingContext rc) { RenderingRuleProperty rColor; RenderingRuleProperty rStrokeW; RenderingRuleProperty rCap; RenderingRuleProperty rPathEff; if (ind == 0) { rColor = req.ALL.R_COLOR; rStrokeW = req.ALL.R_STROKE_WIDTH; rCap = req.ALL.R_CAP; rPathEff = req.ALL.R_PATH_EFFECT; } else if (ind == 1) { rColor = req.ALL.R_COLOR_2; rStrokeW = req.ALL.R_STROKE_WIDTH_2; rCap = req.ALL.R_CAP_2; rPathEff = req.ALL.R_PATH_EFFECT_2; } else if (ind == -1) { rColor = req.ALL.R_COLOR_0; rStrokeW = req.ALL.R_STROKE_WIDTH_0; rCap = req.ALL.R_CAP_0; rPathEff = req.ALL.R_PATH_EFFECT_0; } else if (ind == -2) { rColor = req.ALL.R_COLOR__1; rStrokeW = req.ALL.R_STROKE_WIDTH__1; rCap = req.ALL.R_CAP__1; rPathEff = req.ALL.R_PATH_EFFECT__1; } else { rColor = req.ALL.R_COLOR_3; rStrokeW = req.ALL.R_STROKE_WIDTH_3; rCap = req.ALL.R_CAP_3; rPathEff = req.ALL.R_PATH_EFFECT_3; } if (area) { if (!req.isSpecified(rColor) && !req.isSpecified(req.ALL.R_SHADER)) { return false; } p.setShader(null); p.setColorFilter(null); p.clearShadowLayer(); p.setStyle(Style.FILL_AND_STROKE); p.setStrokeWidth(0); } else { if (!req.isSpecified(rStrokeW)) { return false; } p.setShader(null); p.setColorFilter(null); p.clearShadowLayer(); p.setStyle(Style.STROKE); p.setStrokeWidth(req.getFloatPropertyValue(rStrokeW)); String cap = req.getStringPropertyValue(rCap); if (!Algoritms.isEmpty(cap)) { p.setStrokeCap(Cap.valueOf(cap.toUpperCase())); } else { p.setStrokeCap(Cap.BUTT); } String pathEffect = req.getStringPropertyValue(rPathEff); if (!Algoritms.isEmpty(pathEffect)) { p.setPathEffect(getDashEffect(pathEffect)); } else { p.setPathEffect(null); } } p.setColor(req.getIntPropertyValue(rColor)); if (ind == 0) { String resId = req.getStringPropertyValue(req.ALL.R_SHADER); if (resId != null) { p.setShader(getShader(resId)); } // do not check shadow color here if (rc.shadowRenderingMode == 1) { int shadowColor = req.getIntPropertyValue(req.ALL.R_SHADOW_COLOR); if (shadowColor == 0) { shadowColor = rc.shadowRenderingColor; } int shadowLayer = req.getIntPropertyValue(req.ALL.R_SHADOW_RADIUS); if (shadowColor == 0) { shadowLayer = 0; } p.setShadowLayer(shadowLayer, 0, 0, shadowColor); } } return true; }