Search in sources :

Example 1 with Bahnhof

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);
}
Also used : MarkerOptions(com.google.android.gms.maps.model.MarkerOptions) Bahnhof(de.bahnhoefe.deutschlands.bahnhofsfotos.model.Bahnhof) LatLng(com.google.android.gms.maps.model.LatLng)

Example 2 with Bahnhof

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();
            }
        }
    });
}
Also used : GridViewAdapter(de.bahnhoefe.deutschlands.bahnhofsfotos.util.GridViewAdapter) Intent(android.content.Intent) GridView(android.widget.GridView) TextView(android.widget.TextView) View(android.view.View) AdapterView(android.widget.AdapterView) FilenameFilter(java.io.FilenameFilter) Bahnhof(de.bahnhoefe.deutschlands.bahnhofsfotos.model.Bahnhof) TextView(android.widget.TextView) AdapterView(android.widget.AdapterView) File(java.io.File)

Example 3 with Bahnhof

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;
}
Also used : Bahnhof(de.bahnhoefe.deutschlands.bahnhofsfotos.model.Bahnhof) Cursor(android.database.Cursor)

Example 4 with Bahnhof

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;
}
Also used : Bahnhof(de.bahnhoefe.deutschlands.bahnhofsfotos.model.Bahnhof) NonNull(android.support.annotation.NonNull)

Example 5 with 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;
}
Also used : Bahnhof(de.bahnhoefe.deutschlands.bahnhofsfotos.model.Bahnhof) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor)

Aggregations

Bahnhof (de.bahnhoefe.deutschlands.bahnhofsfotos.model.Bahnhof)10 Cursor (android.database.Cursor)4 Intent (android.content.Intent)3 ArrayList (java.util.ArrayList)2 ContentValues (android.content.ContentValues)1 NonNull (android.support.annotation.NonNull)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 GridView (android.widget.GridView)1 TextView (android.widget.TextView)1 LatLng (com.google.android.gms.maps.model.LatLng)1 MarkerOptions (com.google.android.gms.maps.model.MarkerOptions)1 GridViewAdapter (de.bahnhoefe.deutschlands.bahnhofsfotos.util.GridViewAdapter)1 File (java.io.File)1 FilenameFilter (java.io.FilenameFilter)1