private void refreshList() { if (GPLog.LOG_HEAVY) GPLog.addLogEntry(this, "refreshing notes list"); // $NON-NLS-1$ try { List<INote> allNotesList = new ArrayList<INote>(); List<Note> notesList = DaoNotes.getNotesList(); allNotesList.addAll(notesList); List<Image> imagesList = DaoImages.getImagesList(); allNotesList.addAll(imagesList); Collections.sort(allNotesList, notesSorter); notesNames = new String[allNotesList.size()]; notesMap.clear(); int index = 0; for (INote note : allNotesList) { String name = note.getName(); notesMap.put(name, note); notesNames[index] = name; index++; } } catch (IOException e) { GPLog.error(this, e.getLocalizedMessage(), e); e.printStackTrace(); } redoAdapter(); }
private void filterList(String filterText) { if (GPLog.LOG_HEAVY) GPLog.addLogEntry(this, "filter notes list"); // $NON-NLS-1$ try { List<INote> allNotesList = new ArrayList<INote>(); List<Note> notesList = DaoNotes.getNotesList(); allNotesList.addAll(notesList); List<Image> imagesList = DaoImages.getImagesList(); allNotesList.addAll(imagesList); Collections.sort(allNotesList, notesSorter); notesMap.clear(); filterText = ".*" + filterText.toLowerCase() + ".*"; // $NON-NLS-1$ //$NON-NLS-2$ List<String> namesList = new ArrayList<String>(); for (INote note : allNotesList) { String name = note.getName(); String nameLower = name.toLowerCase(); if (nameLower.matches(filterText)) { namesList.add(name); notesMap.put(name, note); } } notesNames = namesList.toArray(new String[0]); } catch (IOException e) { GPLog.error(this, e.getLocalizedMessage(), e); e.printStackTrace(); } redoAdapter(); }
protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (mapView == null || mapView.isClickable()) { return; } if (doMeasureMode) { int cWidth = canvas.getWidth(); canvas.drawPath(measurePath, measurePaint); int upper = 70; int delta = 5; measureTextPaint.getTextBounds(distanceString, 0, distanceString.length(), rect); int textWidth = rect.width(); int textHeight = rect.height(); int x = cWidth / 2 - textWidth / 2; canvas.drawText(distanceString, x, upper, measureTextPaint); String distanceText = String.valueOf((int) measuredDistance); // String distanceText = distanceText((int) measuredDistance, imperial, nautical); measureTextPaint.getTextBounds(distanceText, 0, distanceText.length(), rect); textWidth = rect.width(); x = cWidth / 2 - textWidth / 2; canvas.drawText(distanceText, x, upper + delta + textHeight, measureTextPaint); if (GPLog.LOG_HEAVY) GPLog.addLogEntry(this, "Drawing measure path text: " + upper); // $NON-NLS-1$ } else if (doInfoMode) { canvas.drawRect(rect, infoRectPaintFill); canvas.drawRect(rect, infoRectPaintStroke); } }
@Override public void onViewChanged() { EditingView editingView = EditManager.INSTANCE.getEditingView(); try { readData(editingView); } catch (IOException e) { GPLog.error(this, null, e); } }
public void onClick(View v) { if (v == selectAllButton) { Tool currentTool = EditManager.INSTANCE.getActiveTool(); if (currentTool != null && currentTool instanceof InfoTool) { // if the same tool is re-selected, it is disabled EditManager.INSTANCE.setActiveTool(null); } else { // check maps enablement try { final Collection<SpatialVectorTable> spatialTables = SpatialiteSourcesManager.INSTANCE.getSpatialiteMaps2TablesMap().values(); boolean atLeastOneEnabled = false; for (SpatialVectorTable spatialVectorTable : spatialTables) { if (spatialVectorTable.getStyle().enabled == 1) { atLeastOneEnabled = true; break; } } if (!atLeastOneEnabled) { LinearLayout parent = EditManager.INSTANCE.getToolsLayout(); if (parent != null) { Context context = parent.getContext(); GPDialogs.warningDialog( context, context.getString(R.string.no_queriable_layer_is_visible), null); } return; } } catch (Exception e) { GPLog.error(this, null, e); } Tool activeTool = new InfoTool(this, mapView); EditManager.INSTANCE.setActiveTool(activeTool); } } else if (v == selectEditableButton) { Tool currentTool = EditManager.INSTANCE.getActiveTool(); if (currentTool != null && currentTool instanceof SelectionTool) { // if the same tool is re-selected, it is disabled EditManager.INSTANCE.setActiveTool(null); } else { Tool activeTool = new SelectionTool(mapView); EditManager.INSTANCE.setActiveTool(activeTool); } } else if (v == createFeatureButton) { ToolGroup createFeatureToolGroup = new LineCreateFeatureToolGroup(mapView, null); EditManager.INSTANCE.setActiveToolGroup(createFeatureToolGroup); } else if (v == undoButton) { // if (cutExtendProcessedFeature != null) { // EditManager.INSTANCE.setActiveTool(null); // commitButton.setVisibility(View.GONE); // undoButton.setVisibility(View.GONE); // EditManager.INSTANCE.invalidateEditingView(); // } } handleToolIcons(v); }
/** * Check if the app is installed. * * @param context the context to use. * @return <code>true</code> if the app is installed. */ public static boolean appInstalled(final Context context) { if (MARKERS_IS_INTEGRATED) { return true; } if (!hasApp) { List<PackageInfo> installedPackages = new ArrayList<PackageInfo>(); { // try to get the installed packages list. Seems to have troubles over different // versions, so trying them all try { installedPackages = context.getPackageManager().getInstalledPackages(0); } catch (Exception e) { // ignore } if (installedPackages.size() == 0) try { installedPackages = context.getPackageManager().getInstalledPackages(PackageManager.GET_ACTIVITIES); } catch (Exception e) { // ignore } } if (installedPackages.size() > 0) { // if a list is available, check if the status gps is installed for (PackageInfo packageInfo : installedPackages) { String packageName = packageInfo.packageName; if (LOG_HOW) GPLog.addLogEntry("MARKERSUTILITIES", packageName); if (packageName.startsWith(APP_PACKAGE)) { hasApp = true; if (LOG_HOW) GPLog.addLogEntry("MARKERSUTILITIES", "Found package: " + packageName); break; } } } else { /* * if no package list is available, for now try to fire it up anyways. * This has been a problem for a user on droidx with android 2.2.1. */ hasApp = true; } } return hasApp; }
private void filterList(String filterText) { if (GPLog.LOG) GPLog.addLogEntry(this, "filter projects list"); // $NON-NLS-1$ projectListToLoad.clear(); for (Webproject project : projectList) { if (project.matches(filterText)) { projectListToLoad.add(project); } } refreshList(); }
/** * Create the db from scratch. * * @param context the context to use. * @throws IOException if something goes wrong. */ public void create(Context context) throws IOException { db.setLocale(Locale.getDefault()); db.setVersion(DATABASE_VERSION); // CREATE TABLES GPLog.createTables(db); DaoMetadata.createTables(); DaoMetadata.initProjectMetadata(null, null, null, null); DaoNotes.createTables(); DaoGpsLog.createTables(); DaoBookmarks.createTables(); DaoImages.createTables(); }
@Override public void onClick(View view) { try { File sdcardDir = ResourcesManager.getInstance(getContext()).getSdcardDir(); Intent browseIntent = new Intent(getContext(), DirectoryBrowserActivity.class); browseIntent.putExtra( DirectoryBrowserActivity.PUT_PATH_PREFERENCE, PREFS_KEY_CUSTOM_MAPSFOLDER); browseIntent.putExtra(DirectoryBrowserActivity.EXTENSIONS, DirectoryBrowserActivity.FOLDER); browseIntent.putExtra(DirectoryBrowserActivity.STARTFOLDERPATH, sdcardDir.getAbsolutePath()); context.startActivity(browseIntent); } catch (Exception e) { GPLog.error(this, null, e); // $NON-NLS-1$ } }
public void onOkClick(View view) { String color = (String) colorSpinner.getSelectedItem(); spatialTable.getStyle().strokecolor = color; String sizeString = (String) sizeSpinner.getSelectedItem(); float size = Float.parseFloat(sizeString); spatialTable.getStyle().size = size; String widthString = (String) widthSpinner.getSelectedItem(); float width = Float.parseFloat(widthString); spatialTable.getStyle().width = width; String alphaString = (String) alphaSpinner.getSelectedItem(); float alpha100 = Float.parseFloat(alphaString); spatialTable.getStyle().strokealpha = alpha100 / 100f; String fillColor = (String) fillColorSpinner.getSelectedItem(); spatialTable.getStyle().fillcolor = fillColor; String fillAlphaString = (String) fillAlphaSpinner.getSelectedItem(); float fillAlpha100 = Float.parseFloat(fillAlphaString); spatialTable.getStyle().fillalpha = fillAlpha100 / 100f; String shapeColor = (String) shapesSpinner.getSelectedItem(); spatialTable.getStyle().shape = shapeColor; String minZoom = (String) minZoomSpinner.getSelectedItem(); spatialTable.getStyle().minZoom = Integer.parseInt(minZoom); String maxZoom = (String) maxZoomSpinner.getSelectedItem(); spatialTable.getStyle().maxZoom = Integer.parseInt(maxZoom); String dashPatternString = dashPatternText.getText().toString(); spatialTable.getStyle().dashPattern = dashPatternString; try { SpatialDatabasesManager.getInstance().updateStyle(spatialTable); finish(); } catch (Exception e) { GPLog.error(this, null, e); } }
private void refreshList() { if (GPLog.LOG) GPLog.addLogEntry(this, "refreshing projects list"); // $NON-NLS-1$ arrayAdapter = new ArrayAdapter<Webproject>(this, R.layout.webprojectsrow, projectListToLoad) { @Override public View getView(int position, View cView, ViewGroup parent) { LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); final View rowView = inflater.inflate(R.layout.webprojectsrow, null); TextView titleText = (TextView) rowView.findViewById(R.id.titletext); TextView descriptionText = (TextView) rowView.findViewById(R.id.descriptiontext); TextView authorText = (TextView) rowView.findViewById(R.id.authortext); TextView dateText = (TextView) rowView.findViewById(R.id.datetext); // TextView sizeText = (TextView) rowView.findViewById(R.id.sizetext); final Webproject webproject = projectListToLoad.get(position); titleText.setText(webproject.name); descriptionText.setText(webproject.title); authorText.setText(webproject.author); dateText.setText(webproject.date); // int kbSize = (int) (webproject.size / 1024.0); // sizeText.setText(kbSize + "Kb"); ImageView imageText = (ImageView) rowView.findViewById(R.id.downloadproject_image); imageText.setOnClickListener( new View.OnClickListener() { public void onClick(View v) { downloadProject(webproject); } }); return rowView; } }; setListAdapter(arrayAdapter); }
protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (GPLog.LOG_ABSURD) GPLog.addLogEntry(this, "Activity returned"); // $NON-NLS-1$ super.onActivityResult(requestCode, resultCode, data); switch (requestCode) { case (MapsActivity.FORMUPDATE_RETURN_CODE): { if (resultCode == Activity.RESULT_OK) { String[] formArray = data.getStringArrayExtra(LibraryConstants.PREFS_KEY_FORM); if (formArray != null) { try { double lon = Double.parseDouble(formArray[0]); double lat = Double.parseDouble(formArray[1]); String textStr = formArray[4]; String jsonStr = formArray[6]; float n = (float) (lat + 0.00001f); float s = (float) (lat - 0.00001f); float w = (float) (lon - 0.00001f); float e = (float) (lon + 0.00001f); List<Note> notesInWorldBounds = DaoNotes.getNotesInWorldBounds(n, s, w, e); if (notesInWorldBounds.size() > 0) { Note note = notesInWorldBounds.get(0); long id = note.getId(); DaoNotes.updateForm(id, textStr, jsonStr); } } catch (Exception e) { e.printStackTrace(); Utilities.messageDialog(this, eu.geopaparazzi.library.R.string.notenonsaved, null); } } } break; } } }
public void onToolDraw(Canvas canvas) { int cWidth = canvas.getWidth(); int cHeight = canvas.getHeight(); int upper = 70; if (gpsLogInfo == null) return; GpsLogInfo logInfo = gpsLogInfo; int color = Color.BLACK; try { color = Color.parseColor(logInfo.color); } catch (Exception e) { // ignore } linePaint.setAntiAlias(true); linePaint.setColor(color); linePaint.setStrokeWidth(3f); linePaint.setStyle(Paint.Style.STROKE); colorBoxPaint.setAntiAlias(false); colorBoxPaint.setColor(color); colorBoxPaint.setStyle(Paint.Style.FILL); measureTextPaint.setAntiAlias(true); measureTextPaint.setTextSize(pixel); measureTextPaint.setColor(color); measureTextPaint.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD)); String name = logInfo.logName; String ts = " - "; try { ts = TimeUtilities.INSTANCE.TIME_FORMATTER_LOCAL.format(new Date(logInfo.timestamp)); } catch (Exception e) { GPLog.error(this, "Error in timestamp: " + logInfo.timestamp, e); } String time = timeString + ts; Coordinate pointXYZ = logInfo.pointXYZ; if (pointXYZ == null) pointXYZ = new Coordinate(-999, -999); String lon = lonString + coordFormatter.format(pointXYZ.x); String lat = latString + coordFormatter.format(pointXYZ.y); String altim = altimString + elevFormatter.format(pointXYZ.z); String[] texts = {name, time, lon, lat, altim}; int runningY = upper; int textWidth = 0; for (String text : texts) { measureTextPaint.getTextBounds(text, 0, text.length(), rect); int textHeight = rect.height(); runningY += textHeight + 3; } canvas.drawRect(0, 0, cWidth, runningY + 10, whiteBoxPaint); canvas.drawRect(0, runningY, cWidth, runningY + 10, colorBoxPaint); runningY = upper; for (String text : texts) { measureTextPaint.getTextBounds(text, 0, text.length(), rect); textWidth = rect.width(); int textHeight = rect.height(); int x = cWidth / 2 - textWidth / 2; canvas.drawText(text, x, runningY, measureTextPaint); runningY += textHeight + 7; } GeoPoint geoPoint = new GeoPoint(pointXYZ.y, pointXYZ.x); Point point = projection.toPixels(geoPoint, null); canvas.drawLine(point.x, point.y, cWidth / 2, runningY, linePaint); }
public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.data_point_properties); getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); Bundle extras = getIntent().getExtras(); String tableName = extras.getString(SpatialiteLibraryConstants.PREFS_KEY_TEXT); try { spatialTable = SpatialDatabasesManager.getInstance().getVectorTableByName(tableName); } catch (Exception e) { GPLog.error(this, null, e); } shapesSpinner = (Spinner) findViewById(R.id.shape_spinner); String shape = spatialTable.getStyle().shape; int count = shapesSpinner.getCount(); for (int i = 0; i < count; i++) { if (shapesSpinner.getItemAtPosition(i).equals(shape)) { shapesSpinner.setSelection(i); break; } } String size = String.valueOf((int) spatialTable.getStyle().size); sizeSpinner = (Spinner) findViewById(R.id.size_spinner); count = sizeSpinner.getCount(); for (int i = 0; i < count; i++) { if (sizeSpinner.getItemAtPosition(i).equals(size)) { sizeSpinner.setSelection(i); break; } } colorSpinner = (Spinner) findViewById(R.id.color_spinner); String strokecolor = spatialTable.getStyle().strokecolor; count = colorSpinner.getCount(); for (int i = 0; i < count; i++) { if (colorSpinner.getItemAtPosition(i).equals(strokecolor)) { colorSpinner.setSelection(i); break; } } String width = String.valueOf((int) spatialTable.getStyle().width); widthSpinner = (Spinner) findViewById(R.id.width_spinner); count = widthSpinner.getCount(); for (int i = 0; i < count; i++) { if (widthSpinner.getItemAtPosition(i).equals(width)) { widthSpinner.setSelection(i); break; } } String alpha = String.valueOf((int) (spatialTable.getStyle().strokealpha * 100f)); alphaSpinner = (Spinner) findViewById(R.id.alpha_spinner); count = alphaSpinner.getCount(); for (int i = 0; i < count; i++) { if (alphaSpinner.getItemAtPosition(i).equals(alpha)) { alphaSpinner.setSelection(i); break; } } fillColorSpinner = (Spinner) findViewById(R.id.fill_color_spinner); String fillcolor = spatialTable.getStyle().fillcolor; count = fillColorSpinner.getCount(); for (int i = 0; i < count; i++) { if (fillColorSpinner.getItemAtPosition(i).equals(fillcolor)) { fillColorSpinner.setSelection(i); break; } } String fillAlpha = String.valueOf((int) (spatialTable.getStyle().fillalpha * 100f)); fillAlphaSpinner = (Spinner) findViewById(R.id.fill_alpha_spinner); count = fillAlphaSpinner.getCount(); for (int i = 0; i < count; i++) { if (fillAlphaSpinner.getItemAtPosition(i).equals(fillAlpha)) { fillAlphaSpinner.setSelection(i); break; } } int minZoom = spatialTable.getMinZoom(); int tableMinZoom = 0; // spatialTable.getMinZoom(); int tableMaxZoom = 22; // spatialTable.getMaxZoom(); ArrayList<String> minMaxSequence = new ArrayList<String>(); for (int i = tableMinZoom; i <= tableMaxZoom; i++) { minMaxSequence.add(String.valueOf(i)); } minZoomSpinner = (Spinner) findViewById(R.id.minzoom_spinner); ArrayAdapter<String> queryAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, minMaxSequence); queryAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); minZoomSpinner.setAdapter(queryAdapter); count = minZoomSpinner.getCount(); for (int i = 0; i < count; i++) { if (minZoomSpinner.getItemAtPosition(i).equals(String.valueOf(minZoom))) { minZoomSpinner.setSelection(i); break; } } int maxZoom = spatialTable.getMaxZoom(); maxZoomSpinner = (Spinner) findViewById(R.id.maxzoom_spinner); queryAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); maxZoomSpinner.setAdapter(queryAdapter); count = maxZoomSpinner.getCount(); for (int i = 0; i < count; i++) { if (maxZoomSpinner.getItemAtPosition(i).equals(String.valueOf(maxZoom))) { maxZoomSpinner.setSelection(i); break; } } String dashPattern = spatialTable.getStyle().dashPattern; dashPatternText = (EditText) findViewById(R.id.dashpattern_text); dashPatternText.setText(dashPattern); }
@Override public boolean onTouchEvent(MotionEvent event) { if (mapView == null || mapView.isClickable()) { return false; } if (doInfoMode) { Projection pj = sliderDrawProjection; // handle drawing currentX = event.getX(); currentY = event.getY(); int action = event.getAction(); switch (action) { case MotionEvent.ACTION_DOWN: startGeoPoint = pj.fromPixels(round(currentX), round(currentY)); pj.toPixels(startGeoPoint, startP); break; case MotionEvent.ACTION_MOVE: float dx = currentX - lastX; float dy = currentY - lastY; if (abs(dx) < 1 && abs(dy) < 1) { lastX = currentX; lastY = currentY; return true; } GeoPoint currentGeoPoint = pj.fromPixels(round(currentX), round(currentY)); pj.toPixels(currentGeoPoint, tmpP); left = tmpP.x < startP.x ? tmpP.x : startP.x; right = tmpP.x > startP.x ? tmpP.x : startP.x; bottom = tmpP.y < startP.y ? tmpP.y : startP.y; top = tmpP.y > startP.y ? tmpP.y : startP.y; rect.set((int) left, (int) top, (int) right, (int) bottom); invalidate(); break; case MotionEvent.ACTION_UP: GeoPoint ul = pj.fromPixels((int) left, (int) top); GeoPoint lr = pj.fromPixels((int) right, (int) bottom); infoDialog(ul.getLatitude(), ul.getLongitude(), lr.getLatitude(), lr.getLongitude()); if (GPLog.LOG_HEAVY) GPLog.addLogEntry( this, "UNTOUCH: " + tmpP.x + "/" + tmpP.y); // $NON-NLS-1$//$NON-NLS-2$ break; } } if (doMeasureMode) { Projection pj = mapView.getProjection(); // handle drawing currentX = event.getX(); currentY = event.getY(); tmpP.set(round(currentX), round(currentY)); int action = event.getAction(); switch (action) { case MotionEvent.ACTION_DOWN: measuredDistance = 0; measurePath.reset(); GeoPoint firstGeoPoint = pj.fromPixels(round(currentX), round(currentY)); pj.toPixels(firstGeoPoint, tmpP); measurePath.moveTo(tmpP.x, tmpP.y); lastX = currentX; lastY = currentY; if (GPLog.LOG_HEAVY) GPLog.addLogEntry(this, "TOUCH: " + tmpP.x + "/" + tmpP.y); // $NON-NLS-1$//$NON-NLS-2$ break; case MotionEvent.ACTION_MOVE: float dx = currentX - lastX; float dy = currentY - lastY; if (abs(dx) < 1 && abs(dy) < 1) { lastX = currentX; lastY = currentY; return true; } GeoPoint currentGeoPoint = pj.fromPixels(round(currentX), round(currentY)); pj.toPixels(currentGeoPoint, tmpP); measurePath.lineTo(tmpP.x, tmpP.y); if (GPLog.LOG_HEAVY) GPLog.addLogEntry(this, "DRAG: " + tmpP.x + "/" + tmpP.y); // $NON-NLS-1$ //$NON-NLS-2$ // the measurement GeoPoint previousGeoPoint = pj.fromPixels(round(lastX), round(lastY)); Location l1 = new Location("gps"); // $NON-NLS-1$ l1.setLatitude(previousGeoPoint.getLatitude()); l1.setLongitude(previousGeoPoint.getLongitude()); Location l2 = new Location("gps"); // $NON-NLS-1$ l2.setLatitude(currentGeoPoint.getLatitude()); l2.setLongitude(currentGeoPoint.getLongitude()); float distanceTo = l1.distanceTo(l2); lastX = currentX; lastY = currentY; measuredDistance = measuredDistance + distanceTo; invalidate(); break; case MotionEvent.ACTION_UP: if (GPLog.LOG_HEAVY) GPLog.addLogEntry( this, "UNTOUCH: " + tmpP.x + "/" + tmpP.y); // $NON-NLS-1$//$NON-NLS-2$ break; } } return true; }
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { mBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); if (GPLog.LOG) GPLog.addLogEntry(this, "Recreating bitmap"); }