Android Open Source - BusFollower Route Chooser Activity






From Project

Back to project page BusFollower.

License

The source code is released under:

GNU General Public License

If you think the Android project BusFollower listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Copyright 2012 Clayton Smith/*from  ww  w. j a  v  a  2s  .c  o m*/
 *
 * This file is part of Ottawa Bus Follower.
 *
 * Ottawa Bus Follower is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 3, or (at
 * your option) any later version.
 *
 * Ottawa Bus Follower is distributed in the hope that it will be
 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Ottawa Bus Follower; see the file COPYING.  If not, see
 * <http://www.gnu.org/licenses/>.
 */

package net.argilo.busfollower;

import java.util.ArrayList;

import net.argilo.busfollower.ocdata.GetRouteSummaryForStopResult;
import net.argilo.busfollower.ocdata.Route;
import net.argilo.busfollower.ocdata.Stop;

import android.app.ListActivity;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class RouteChooserActivity extends ListActivity {
    private SQLiteDatabase db = null;
    private static FetchTripsTask task = null;

    private Stop stop;
    private ArrayList<Route> routes;
        
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.routechooser);

        db = ((BusFollowerApplication) getApplication()).getDatabase();

        Util.setDisplayHomeAsUpEnabled(this, true);

        stop = (Stop) getIntent().getSerializableExtra("stop");
        GetRouteSummaryForStopResult result = (GetRouteSummaryForStopResult) getIntent().getSerializableExtra("result");
        routes = result.getRoutes();
        
        setListAdapter(new ArrayAdapter<Route>(this, android.R.layout.simple_list_item_1, routes));
        setTitle(getString(R.string.stop_number) + " " + stop.getNumber() +
                (stop.getName() != null ? " " + stop.getName() : ""));
        
        if (savedInstanceState != null) {
            if (task != null) {
                // Let the AsyncTask know we're back.
                task.setActivityContext(this);
            }
        }
    }
    
    @Override
    public void onListItemClick(ListView parent, View v, int position, long id) {
        // Here we just use RecentQuery as a convenience, since it can hold a stop and route.
        task = new FetchTripsTask(this, db);
        task.execute(new RecentQuery(stop, routes.get(position)));
    }
    
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                // app icon in action bar clicked; go home
                Intent intent = new Intent(this, StopChooserActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(intent);
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }
    
    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        
        if (task != null) {
            // Let the AsyncTask know we're gone.
            task.setActivityContext(null);
        }
    }
}




Java Source Code List

net.argilo.busfollower.BusFollowerActivity.java
net.argilo.busfollower.BusFollowerApplication.java
net.argilo.busfollower.BusFollowerItemizedOverlay.java
net.argilo.busfollower.BusOverlayItem.java
net.argilo.busfollower.DoubleTapZoomMapView.java
net.argilo.busfollower.FetchRoutesTask.java
net.argilo.busfollower.FetchTripsTask.java
net.argilo.busfollower.MapChooserActivity.java
net.argilo.busfollower.RecentQueryList.java
net.argilo.busfollower.RecentQuery.java
net.argilo.busfollower.RouteChooserActivity.java
net.argilo.busfollower.StopChooserActivity.java
net.argilo.busfollower.StopOverlayItem.java
net.argilo.busfollower.StopsMapView.java
net.argilo.busfollower.Util.java
net.argilo.busfollower.ocdata.BusType.java
net.argilo.busfollower.ocdata.DatabaseHelper.java
net.argilo.busfollower.ocdata.GetNextTripsForStopResult.java
net.argilo.busfollower.ocdata.GetRouteSummaryForStopResult.java
net.argilo.busfollower.ocdata.OCTranspoDataFetcher.java
net.argilo.busfollower.ocdata.RouteDirection.java
net.argilo.busfollower.ocdata.Route.java
net.argilo.busfollower.ocdata.Stop.java
net.argilo.busfollower.ocdata.Trip.java
net.argilo.busfollower.ocdata.Util.java