Android Open Source - Bussan Frontpage Activity






From Project

Back to project page Bussan.

License

The source code is released under:

Copyright 2011 Kristian Bendiksen. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: ...

If you think the Android project Bussan 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

package no.kriben.bussan;
/*  www . ja  va 2s  .co m*/
import java.util.ArrayList;
import java.util.List;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.widget.ListView;
import no.kriben.busstopstrondheim.model.BusStop;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem;

public class FrontpageActivity extends BusStopListActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.frontpage);
        super.onCreate(savedInstanceState);

        ListView lv = getListView();
        lv.setTextFilterEnabled(true);

        startDownloadBusStopTask();
    }


    @Override
    public void onResume() {
        super.onResume();
        startDownloadBusStopTask();
    }

    private List<BusStop> filterByCode(List<Integer> codes, List<BusStop> allBusStops) {
        List<BusStop> filteredBusStops = new ArrayList<BusStop>();
        if (allBusStops != null) {
            for (BusStop busStop : allBusStops) {
                if (codes.contains(busStop.getCode()))
                    filteredBusStops.add(busStop);
            }
        }

        return filteredBusStops;
    }

    protected void refreshBusStopListView(List<BusStop> busStops) {
        SharedPreferences settings = getSharedPreferences("BusStopPreferences", MODE_PRIVATE);
        List<Integer> favorites = PreferencesUtil.decodeBusStopString(settings.getString("favorites", getString(R.string.default_busstops)));
        List<BusStop> filteredBusStops = filterByCode(favorites, busStops);
        setListAdapter(new BusStopAdapter(getBaseContext(), R.layout.bus_stop_list_item, R.id.busstop_name, filteredBusStops));
    }

    protected void refreshBusStopListView() {
        startDownloadBusStopTask();
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu){
        MenuInflater inflater = getSupportMenuInflater();
        inflater.inflate(R.menu.frontpagemenu, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case R.id.find_closest:
            startActivity(new Intent(FrontpageActivity.this, FindBusStopByDistanceActivity.class));
            break;
        case R.id.find_by_name:
            startActivity(new Intent(FrontpageActivity.this, FindBusStopByNameActivity.class));
            break;
        }

        return true;
    }
}




Java Source Code List

no.kriben.bussan.AndroidFileStringCache.java
no.kriben.bussan.BusDepartureDetailActivity.java
no.kriben.bussan.BusStopAdapter.java
no.kriben.bussan.BusStopArrayAdapter.java
no.kriben.bussan.BusStopListActivity.java
no.kriben.bussan.BusStopMenuHandler.java
no.kriben.bussan.BusStopNameFormatter.java
no.kriben.bussan.BusStopWithDistance.java
no.kriben.bussan.BussanApplication.java
no.kriben.bussan.BussanAsyncTask.java
no.kriben.bussan.ConnectivityChecker.java
no.kriben.bussan.FindBusStopByDistanceActivity.java
no.kriben.bussan.FindBusStopByNameActivity.java
no.kriben.bussan.FrontpageActivity.java
no.kriben.bussan.PreferencesUtil.java
no.kriben.bussan.RealTimeActivity.java