Android Open Source - taxitwin-app Taxi Twin List Fragment






From Project

Back to project page taxitwin-app.

License

The source code is released under:

GNU General Public License

If you think the Android project taxitwin-app 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 kimle.michal.android.taxitwin.fragment;
//from   ww w  .j a va2  s .  c o m
import android.app.ListFragment;
import android.app.LoaderManager;
import android.content.CursorLoader;
import android.content.Intent;
import android.content.Loader;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import kimle.michal.android.taxitwin.R;
import kimle.michal.android.taxitwin.activity.MainActivity;
import kimle.michal.android.taxitwin.activity.OfferDetailActivity;
import kimle.michal.android.taxitwin.contentprovider.TaxiTwinContentProvider;
import kimle.michal.android.taxitwin.db.DbContract;

public class TaxiTwinListFragment extends ListFragment implements LoaderManager.LoaderCallbacks<Cursor> {

    private SimpleCursorAdapter adapter;

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        setupAdapter();
    }

    private void setupAdapter() {
        String[] columns = new String[]{
            DbContract.DbEntry.TAXITWIN_NAME_COLUMN,
            DbContract.DbEntry.AS_START_POINT_TEXTUAL_COLUMN,
            DbContract.DbEntry.AS_END_POINT_TEXTUAL_COLUMN};

        int[] to = new int[]{
            R.id.name_text,
            R.id.from_text,
            R.id.to_text};

        getLoaderManager().initLoader(0, null, this);

        adapter = new SimpleCursorAdapter(
                getActivity(), R.layout.offer,
                null,
                columns,
                to,
                0);

        setListAdapter(adapter);
    }

    public Loader<Cursor> onCreateLoader(int id, Bundle args) {
        String[] projection = {
            DbContract.DbEntry.OFFER_ID_COLUMN,
            DbContract.DbEntry.TAXITWIN_NAME_COLUMN,
            DbContract.DbEntry.POINT_START_TABLE + "." + DbContract.DbEntry.POINT_TEXTUAL_COLUMN + " as " + DbContract.DbEntry.AS_START_POINT_TEXTUAL_COLUMN,
            DbContract.DbEntry.POINT_END_TABLE + "." + DbContract.DbEntry.POINT_TEXTUAL_COLUMN + " as " + DbContract.DbEntry.AS_END_POINT_TEXTUAL_COLUMN};

        Uri uri = TaxiTwinContentProvider.OFFERS_URI;

        CursorLoader cursorLoader = new CursorLoader(getActivity(), uri, projection, null, null, null);
        return cursorLoader;
    }

    public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
        adapter.swapCursor(data);
    }

    public void onLoaderReset(Loader<Cursor> loader) {
        adapter.swapCursor(null);
    }

    public void updateView() {
        getLoaderManager().restartLoader(0, null, this);
        adapter.notifyDataSetChanged();
    }

    @Override
    public void onListItemClick(ListView l, View v, int position, long id) {
        super.onListItemClick(l, v, position, id);
        Intent i = new Intent(getActivity(), OfferDetailActivity.class);
        Uri taskUri = Uri.parse(TaxiTwinContentProvider.OFFERS_URI + "/" + id);
        i.putExtra(TaxiTwinContentProvider.OFFER_CONTENT_ITEM_TYPE, taskUri);

        getActivity().startActivityForResult(i, MainActivity.OFFER_DETAIL);
    }
}




Java Source Code List

kimle.michal.android.taxitwin.activity.LauncherActivity.java
kimle.michal.android.taxitwin.activity.MainActivity.java
kimle.michal.android.taxitwin.activity.MyTaxiTwinActivity.java
kimle.michal.android.taxitwin.activity.OfferDetailActivity.java
kimle.michal.android.taxitwin.activity.ResponseDetailActivity.java
kimle.michal.android.taxitwin.activity.ResponsesActivity.java
kimle.michal.android.taxitwin.adapter.TaxiTwinPlacesAutoCompleteAdapter.java
kimle.michal.android.taxitwin.application.TaxiTwinApplication.java
kimle.michal.android.taxitwin.contentprovider.TaxiTwinContentProvider.java
kimle.michal.android.taxitwin.db.DbContract.java
kimle.michal.android.taxitwin.db.DbHelper.java
kimle.michal.android.taxitwin.dialog.alert.AddressAlertDialogFragment.java
kimle.michal.android.taxitwin.dialog.alert.GPSAlertDialogFragment.java
kimle.michal.android.taxitwin.dialog.alert.GooglePlayServicesAlertDialogFragment.java
kimle.michal.android.taxitwin.dialog.alert.InternetAlertDialogFragment.java
kimle.michal.android.taxitwin.dialog.alert.LeaveTaxiTwinAlertDialogFragment.java
kimle.michal.android.taxitwin.dialog.alert.ServicesAlertDialogFragment.java
kimle.michal.android.taxitwin.dialog.alert.TaxiTwinAlertDialogFragment.java
kimle.michal.android.taxitwin.dialog.alert.TaxiTwinNoLongerAlertDialogFragment.java
kimle.michal.android.taxitwin.dialog.error.GooglePlayServicesErrorDialogFragment.java
kimle.michal.android.taxitwin.dialog.error.OfferErrorDialogFragment.java
kimle.michal.android.taxitwin.dialog.error.PlaceErrorDialogFragment.java
kimle.michal.android.taxitwin.dialog.error.ResponseErrorDialogFragment.java
kimle.michal.android.taxitwin.entity.Place.java
kimle.michal.android.taxitwin.enumerate.UserState.java
kimle.michal.android.taxitwin.fragment.TaxiTwinListFragment.java
kimle.michal.android.taxitwin.fragment.TaxiTwinMapFragment.java
kimle.michal.android.taxitwin.gcm.GcmBroadcastReceiver.java
kimle.michal.android.taxitwin.gcm.GcmConnector.java
kimle.michal.android.taxitwin.gcm.GcmHandler.java
kimle.michal.android.taxitwin.gcm.GcmIntentService.java
kimle.michal.android.taxitwin.popup.SettingsPopup.java
kimle.michal.android.taxitwin.services.ServicesManagement.java
kimle.michal.android.taxitwin.view.TaxiTwinAutoCompleteTextView.java