Search in sources :

Example 1 with Station

use of be.brunoparmentier.openbikesharing.app.models.Station in project OpenBikeSharing by bparmentier.

the class MapActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_map);
    getActionBar().setDisplayHomeAsUpEnabled(true);
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
    stationsDataSource = new StationsDataSource(this);
    ArrayList<Station> stations = stationsDataSource.getStations();
    map = (MapView) findViewById(R.id.mapView);
    stationMarkerInfoWindow = new StationMarkerInfoWindow(R.layout.bonuspack_bubble, map);
    /* handling map events */
    MapEventsOverlay mapEventsOverlay = new MapEventsOverlay(this, this);
    map.getOverlays().add(0, mapEventsOverlay);
    /* markers list */
    GridMarkerClusterer stationsMarkers = new GridMarkerClusterer();
    Drawable clusterIconD = getResources().getDrawable(R.drawable.marker_cluster);
    Bitmap clusterIcon = ((BitmapDrawable) clusterIconD).getBitmap();
    map.getOverlays().add(stationsMarkers);
    stationsMarkers.setIcon(clusterIcon);
    stationsMarkers.setGridSize(100);
    for (final Station station : stations) {
        stationsMarkers.add(createStationMarker(station));
    }
    map.invalidate();
    map.setMultiTouchControls(true);
    map.setBuiltInZoomControls(true);
    map.setMinZoomLevel(3);
    /* map tile source */
    String mapLayer = settings.getString(PREF_KEY_MAP_LAYER, "");
    switch(mapLayer) {
        case MAP_LAYER_MAPNIK:
            map.setTileSource(TileSourceFactory.MAPNIK);
            break;
        case MAP_LAYER_CYCLEMAP:
            map.setTileSource(TileSourceFactory.CYCLEMAP);
            break;
        case MAP_LAYER_OSMPUBLICTRANSPORT:
            map.setTileSource(TileSourceFactory.PUBLIC_TRANSPORT);
            break;
        default:
            map.setTileSource(TileSourceFactory.DEFAULT_TILE_SOURCE);
            break;
    }
    GpsMyLocationProvider imlp = new GpsMyLocationProvider(this.getBaseContext());
    imlp.setLocationUpdateMinDistance(1000);
    imlp.setLocationUpdateMinTime(60000);
    map.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
        }
    });
    myLocationOverlay = new MyLocationNewOverlay(imlp, this.map);
    myLocationOverlay.enableMyLocation();
    map.getOverlays().add(this.myLocationOverlay);
    mapController = map.getController();
    if (savedInstanceState != null) {
        mapController.setZoom(savedInstanceState.getInt(MAP_CURRENT_ZOOM_KEY));
        mapController.setCenter(new GeoPoint(savedInstanceState.getDouble(MAP_CENTER_LAT_KEY), savedInstanceState.getDouble(MAP_CENTER_LON_KEY)));
    } else {
        LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
        Location userLocation = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
        if (userLocation != null) {
            mapController.setZoom(16);
            mapController.animateTo(new GeoPoint(userLocation));
        } else {
            double bikeNetworkLatitude = Double.longBitsToDouble(settings.getLong(PREF_KEY_NETWORK_LATITUDE, 0));
            double bikeNetworkLongitude = Double.longBitsToDouble(settings.getLong(PREF_KEY_NETWORK_LONGITUDE, 0));
            mapController.setZoom(13);
            mapController.setCenter(new GeoPoint(bikeNetworkLatitude, bikeNetworkLongitude));
            Toast.makeText(this, R.string.location_not_found, Toast.LENGTH_LONG).show();
        }
    }
}
Also used : LocationManager(android.location.LocationManager) SharedPreferences(android.content.SharedPreferences) MapEventsOverlay(org.osmdroid.views.overlay.MapEventsOverlay) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) GpsMyLocationProvider(org.osmdroid.views.overlay.mylocation.GpsMyLocationProvider) MyLocationNewOverlay(org.osmdroid.views.overlay.mylocation.MyLocationNewOverlay) BitmapDrawable(android.graphics.drawable.BitmapDrawable) ImageView(android.widget.ImageView) View(android.view.View) MapView(org.osmdroid.views.MapView) Station(be.brunoparmentier.openbikesharing.app.models.Station) GeoPoint(org.osmdroid.util.GeoPoint) Bitmap(android.graphics.Bitmap) GridMarkerClusterer(org.osmdroid.bonuspack.clustering.GridMarkerClusterer) StationsDataSource(be.brunoparmentier.openbikesharing.app.db.StationsDataSource) Location(android.location.Location)

Example 2 with Station

use of be.brunoparmentier.openbikesharing.app.models.Station in project OpenBikeSharing by bparmentier.

the class StationsListActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_stations_list);
    refreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_container);
    refreshLayout.setColorSchemeResources(R.color.bike_red, R.color.parking_blue_dark);
    refreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            executeDownloadTask();
        }
    });
    viewPager = (ViewPager) findViewById(R.id.viewPager);
    viewPager.setOffscreenPageLimit(2);
    viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        }

        @Override
        public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);
        }

        @Override
        public void onPageScrollStateChanged(int state) {
            /* as explained on
                http://stackoverflow.com/questions/25978462/swiperefreshlayout-viewpager-limit-horizontal-scroll-only
                 */
            refreshLayout.setEnabled(state == ViewPager.SCROLL_STATE_IDLE);
        }
    });
    stationsDataSource = new StationsDataSource(this);
    stations = stationsDataSource.getStations();
    favStations = stationsDataSource.getFavoriteStations();
    nearbyStations = new ArrayList<>();
    tabsPagerAdapter = new TabsPagerAdapter(getSupportFragmentManager());
    viewPager.setAdapter(tabsPagerAdapter);
    settings = PreferenceManager.getDefaultSharedPreferences(this);
    actionBar = getActionBar();
    int defaultTabIndex = Integer.valueOf(settings.getString(PREF_KEY_DEFAULT_TAB, "0"));
    for (int i = 0; i < 3; i++) {
        ActionBar.Tab tab = actionBar.newTab();
        tab.setTabListener(this);
        tab.setText(tabsPagerAdapter.getPageTitle(i));
        actionBar.addTab(tab, (defaultTabIndex == i));
    }
    actionBar.setHomeButtonEnabled(false);
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    boolean firstRun = settings.getString(PREF_KEY_NETWORK_ID, "").isEmpty();
    setDBLastUpdateText();
    if (firstRun) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(R.string.welcome_dialog_message);
        builder.setTitle(R.string.welcome_dialog_title);
        builder.setPositiveButton(R.string.welcome_dialog_ok, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                Intent intent = new Intent(StationsListActivity.this, BikeNetworksListActivity.class);
                startActivityForResult(intent, PICK_NETWORK_REQUEST);
            }
        });
        builder.setNegativeButton(R.string.welcome_dialog_cancel, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                finish();
            }
        });
        AlertDialog dialog = builder.create();
        dialog.show();
    } else {
        if (savedInstanceState != null) {
            bikeNetwork = (BikeNetwork) savedInstanceState.getSerializable(KEY_BIKE_NETWORK);
            stations = (ArrayList<Station>) savedInstanceState.getSerializable(KEY_STATIONS);
            favStations = (ArrayList<Station>) savedInstanceState.getSerializable(KEY_FAV_STATIONS);
            nearbyStations = (ArrayList<Station>) savedInstanceState.getSerializable(KEY_NEARBY_STATIONS);
        } else {
            String networkId = settings.getString(PREF_KEY_NETWORK_ID, "");
            String stationUrl = settings.getString(PREF_KEY_API_URL, DEFAULT_API_URL) + "networks/" + networkId;
            jsonDownloadTask = new JSONDownloadTask();
            jsonDownloadTask.execute(stationUrl);
        }
    }
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) Intent(android.content.Intent) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) ViewPager(android.support.v4.view.ViewPager) Station(be.brunoparmentier.openbikesharing.app.models.Station) StationsDataSource(be.brunoparmentier.openbikesharing.app.db.StationsDataSource) ActionBar(android.app.ActionBar)

Example 3 with Station

use of be.brunoparmentier.openbikesharing.app.models.Station in project OpenBikeSharing by bparmentier.

the class StationsListActivity method loadData.

private void loadData(String query) {
    ArrayList<Station> queryStations = new ArrayList<>();
    String[] columns = new String[] { "_id", "text" };
    Object[] temp = new Object[] { 0, "default" };
    MatrixCursor cursor = new MatrixCursor(columns);
    if (stations != null) {
        for (int i = 0; i < stations.size(); i++) {
            Station station = stations.get(i);
            if (station.getName().toLowerCase().contains(query.toLowerCase())) {
                temp[0] = i;
                temp[1] = station.getName();
                cursor.addRow(temp);
                queryStations.add(station);
            }
        }
    }
    searchView.setSuggestionsAdapter(new SearchStationAdapter(this, cursor, queryStations));
}
Also used : Station(be.brunoparmentier.openbikesharing.app.models.Station) SearchStationAdapter(be.brunoparmentier.openbikesharing.app.adapters.SearchStationAdapter) ArrayList(java.util.ArrayList) MatrixCursor(android.database.MatrixCursor)

Example 4 with Station

use of be.brunoparmentier.openbikesharing.app.models.Station in project OpenBikeSharing by bparmentier.

the class StationsListAdapter method getView.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View v = convertView;
    if (v == null) {
        LayoutInflater vi;
        vi = LayoutInflater.from(getContext());
        v = vi.inflate(R.layout.station_list_item, parent, false);
    }
    final Station station = getItem(position);
    if (station != null) {
        TextView stationNameTitle = (TextView) v.findViewById(R.id.stationNameTitle);
        TextView freeBikesValue = (TextView) v.findViewById(R.id.freeBikesValue);
        TextView emptySlotsValue = (TextView) v.findViewById(R.id.emptySlotsValue);
        StationStatus stationStatus = station.getStatus();
        if (stationNameTitle != null) {
            stationNameTitle.setText(station.getName());
            if (stationStatus == StationStatus.CLOSED) {
                stationNameTitle.setPaintFlags(stationNameTitle.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
            } else {
                stationNameTitle.setPaintFlags(stationNameTitle.getPaintFlags() & (~Paint.STRIKE_THRU_TEXT_FLAG));
            }
        }
        if (freeBikesValue != null) {
            int bikes = station.getFreeBikes();
            freeBikesValue.setText(String.valueOf(bikes));
        }
        if (emptySlotsValue != null) {
            int emptySlots = station.getEmptySlots();
            ImageView emptySlotsLogo = (ImageView) v.findViewById(R.id.emptySlotsLogo);
            if (emptySlots == -1) {
                emptySlotsLogo.setVisibility(View.GONE);
                emptySlotsValue.setVisibility(View.GONE);
            } else {
                emptySlotsLogo.setVisibility(View.VISIBLE);
                emptySlotsValue.setVisibility(View.VISIBLE);
                emptySlotsValue.setText(String.valueOf(emptySlots));
            }
        }
    }
    return v;
}
Also used : Station(be.brunoparmentier.openbikesharing.app.models.Station) LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) StationStatus(be.brunoparmentier.openbikesharing.app.models.StationStatus) ImageView(android.widget.ImageView) ImageView(android.widget.ImageView) AbsListView(android.widget.AbsListView) TextView(android.widget.TextView) View(android.view.View) Paint(android.graphics.Paint)

Example 5 with Station

use of be.brunoparmentier.openbikesharing.app.models.Station in project OpenBikeSharing by bparmentier.

the class StationsDataSource method getFavoriteStations.

public ArrayList<Station> getFavoriteStations() {
    SQLiteDatabase db = dbHelper.getReadableDatabase();
    ArrayList<Station> favStations = new ArrayList<>();
    Cursor cursor = db.rawQuery("SELECT sta.id as _id, name, last_update, latitude, longitude, " + "free_bikes, empty_slots, address, banking, bonus, status " + "FROM " + DatabaseHelper.FAV_STATIONS_TABLE_NAME + " sta " + "INNER JOIN " + DatabaseHelper.STATIONS_TABLE_NAME + " fav " + "ON sta.id = fav.id", null);
    try {
        if (cursor.moveToFirst()) {
            while (!cursor.isAfterLast()) {
                Station station = toStation(cursor);
                favStations.add(station);
                cursor.moveToNext();
            }
        }
        Collections.sort(favStations);
        return favStations;
    } finally {
        cursor.close();
    }
}
Also used : Station(be.brunoparmentier.openbikesharing.app.models.Station) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor)

Aggregations

Station (be.brunoparmentier.openbikesharing.app.models.Station)9 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)3 ArrayList (java.util.ArrayList)3 Cursor (android.database.Cursor)2 Location (android.location.Location)2 LocationManager (android.location.LocationManager)2 View (android.view.View)2 ImageView (android.widget.ImageView)2 StationsDataSource (be.brunoparmentier.openbikesharing.app.db.StationsDataSource)2 ActionBar (android.app.ActionBar)1 AlertDialog (android.app.AlertDialog)1 ContentValues (android.content.ContentValues)1 DialogInterface (android.content.DialogInterface)1 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 MatrixCursor (android.database.MatrixCursor)1 Bitmap (android.graphics.Bitmap)1 Paint (android.graphics.Paint)1 BitmapDrawable (android.graphics.drawable.BitmapDrawable)1 Drawable (android.graphics.drawable.Drawable)1