use of de.bahnhoefe.deutschlands.bahnhofsfotos.model.Bahnhof in project RSAndroidApp by RailwayStations.
the class MapsActivity method addMarkers.
private void addMarkers(List<Bahnhof> bahnhofMarker, LatLng myPos) {
for (Bahnhof bahnhof : bahnhofMarker) {
LatLng bahnhofPos = bahnhof.getPosition();
mMap.addMarker(new MarkerOptions().title(bahnhof.getTitle()).position(bahnhofPos).snippet(String.valueOf(bahnhof.getId())).icon(BitmapDescriptorFactory.defaultMarker(343)));
}
// Add a marker and moves the camera
mMap.addMarker(new MarkerOptions().position(myPos).title("Meine aktuelle Position: ").icon(BitmapDescriptorFactory.defaultMarker(55)));
mMap.setInfoWindowAdapter(this);
mMap.setOnInfoWindowClickListener(this);
}
use of de.bahnhoefe.deutschlands.bahnhofsfotos.model.Bahnhof in project RSAndroidApp by RailwayStations.
the class GalleryActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
BaseApplication baseApplication = (BaseApplication) getApplication();
dbAdapter = baseApplication.getDbAdapter();
setContentView(R.layout.activity_gallery);
// Check for SD Card
if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
Toast.makeText(this, "Error! No SDCARD Found!", Toast.LENGTH_LONG).show();
} else {
// Locate the image folder in the SD Card
file = new File(Environment.getExternalStorageDirectory(), "Bahnhofsfotos");
// Creates a new folder if no folder with name Bahnhofsfotos exist
file.mkdirs();
}
if (file.isDirectory()) {
listFile = file.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return !name.startsWith(".");
}
});
// Creates a String array for FilePathStrings
filePathStrings = new String[listFile.length];
// Creates a String array for FileNameStrings
fileNameStrings = new String[listFile.length];
for (int i = 0; i < listFile.length; i++) {
// Get the path of the image file
filePathStrings[i] = listFile[i].getAbsolutePath();
// Get the name image file
fileNameStrings[i] = listFile[i].getName();
//Toast.makeText(this, FileNameStrings[i], Toast.LENGTH_LONG).show();
}
}
int countOfImages = listFile.length;
String strCountOfImagesFormat = getResources().getString(R.string.count_of_images);
String strCountOfImagesMsg = String.format(strCountOfImagesFormat, countOfImages);
TextView tvCountOfImages = (TextView) findViewById(R.id.tvImageCount);
tvCountOfImages.setText(strCountOfImagesMsg);
// Locate the GridView in gridview_main.xml
grid = (GridView) findViewById(R.id.gridview);
// Pass String arrays to LazyAdapter Class
adapter = new GridViewAdapter(this, filePathStrings, fileNameStrings);
// connect LazyAdapter to the GridView
grid.setAdapter(adapter);
// Capture gridview item click
grid.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String fileName = fileNameStrings[position];
String[] nameParts = fileName.split("[-.]");
boolean shown = false;
if (nameParts.length == 3) {
long stationId = Long.valueOf(nameParts[1]);
Bahnhof station = dbAdapter.fetchBahnhofByBahnhofId(stationId);
if (station != null) {
Intent detailIntent = new Intent(GalleryActivity.this, DetailsActivity.class);
detailIntent.putExtra(DetailsActivity.EXTRA_BAHNHOF, station);
startActivity(detailIntent);
shown = true;
}
}
if (!shown) {
Toast.makeText(GalleryActivity.this, "Kann dieses Foto keinem Bahnhof mehr zuordnen", Toast.LENGTH_LONG).show();
}
}
});
}
use of de.bahnhoefe.deutschlands.bahnhofsfotos.model.Bahnhof in project RSAndroidApp by RailwayStations.
the class BahnhofsDbAdapter method fetchBahnhofByBahnhofId.
public Bahnhof fetchBahnhofByBahnhofId(long id) {
Cursor cursor = db.query(DATABASE_TABLE, null, Constants.DB_JSON_CONSTANTS.KEY_ID + "=?", new String[] { id + "" }, null, null, null);
if (cursor != null && cursor.moveToFirst()) {
Bahnhof bahnhof = createBahnhofFromCursor(cursor);
cursor.close();
return bahnhof;
} else
return null;
}
use of de.bahnhoefe.deutschlands.bahnhofsfotos.model.Bahnhof in project RSAndroidApp by RailwayStations.
the class BahnhofsDbAdapter method createBahnhofFromCursor.
@NonNull
private Bahnhof createBahnhofFromCursor(@NonNull Cursor cursor) {
String title = cursor.getString(cursor.getColumnIndexOrThrow(Constants.DB_JSON_CONSTANTS.KEY_TITLE));
int bahnhofsnr = cursor.getInt(cursor.getColumnIndexOrThrow(Constants.DB_JSON_CONSTANTS.KEY_ID));
Double lon = cursor.getDouble(cursor.getColumnIndexOrThrow(Constants.DB_JSON_CONSTANTS.KEY_LON));
Double lat = cursor.getDouble(cursor.getColumnIndexOrThrow(Constants.DB_JSON_CONSTANTS.KEY_LAT));
String photoflag = cursor.getString(cursor.getColumnIndexOrThrow(Constants.DB_JSON_CONSTANTS.KEY_PHOTOFLAG));
Bahnhof bahnhof = new Bahnhof();
bahnhof.setTitle(title);
bahnhof.setId(bahnhofsnr);
bahnhof.setLat(lat);
bahnhof.setLon(lon);
bahnhof.setPhotoflag(photoflag);
return bahnhof;
}
use of de.bahnhoefe.deutschlands.bahnhofsfotos.model.Bahnhof in project RSAndroidApp by RailwayStations.
the class BahnhofsDbAdapter method getBahnhoefeByLatLngRectangle.
// Getting All Bahnhoefe
public List<Bahnhof> getBahnhoefeByLatLngRectangle(LatLng position, boolean withPhoto) {
double lat = position.latitude;
double lng = position.longitude;
List<Bahnhof> bahnhofList = new ArrayList<Bahnhof>();
// Select All Query with rectangle - might be later change with it
String selectQuery = "SELECT " + KEY_ID + ", " + Constants.DB_JSON_CONSTANTS.KEY_TITLE + ", " + Constants.DB_JSON_CONSTANTS.KEY_LAT + ", " + Constants.DB_JSON_CONSTANTS.KEY_LON + ", " + Constants.DB_JSON_CONSTANTS.KEY_PHOTOFLAG + " FROM " + DATABASE_TABLE + " where " + Constants.DB_JSON_CONSTANTS.KEY_LAT + " < " + (lat + 0.5) + " AND " + Constants.DB_JSON_CONSTANTS.KEY_LAT + " > " + (lat - 0.5) + " AND " + Constants.DB_JSON_CONSTANTS.KEY_LON + " < " + (lng + 0.5) + " AND " + Constants.DB_JSON_CONSTANTS.KEY_LON + " > " + (lng - 0.5) + " AND " + Constants.DB_JSON_CONSTANTS.KEY_PHOTOFLAG + " IS " + (withPhoto ? "NOT" : "") + " NULL";
Cursor cursor = db.rawQuery(selectQuery, null);
// looping through all rows and adding to list
if (cursor.moveToFirst()) {
do {
Bahnhof bahnhof = createBahnhofFromCursor(cursor);
// Adding bahnhof to list
bahnhofList.add(bahnhof);
} while (cursor.moveToNext());
}
cursor.close();
// returns bahnhof list
return bahnhofList;
}
Aggregations