Android Open Source - morpho Buses S Q Lite






From Project

Back to project page morpho.

License

The source code is released under:

Apache License

If you think the Android project morpho 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 com.morpho.android.ws.impl.sqlite;
/* ww  w  .  j a va 2 s  . c  om*/
import android.content.Context;
import android.os.AsyncTask;

import com.morpho.android.R;
import com.morpho.android.ws.AsyncTaskAdapter;
import com.morpho.android.ws.Buses;

import java.util.List;

public class BusesSQLite implements Buses {

    private final Context context;

    public BusesSQLite(Context context) {
        this.context = context.getApplicationContext();
    }

    @Override
    public FetchSQLiteRequest fetch() {
        return new FetchSQLiteRequest(context);
    }

    private static class FetchSQLiteRequest implements Buses.FetchRequest {

        private final Context context;
        
        private String query;
        private int limit;

        private FetchSQLiteRequest(Context context) {
            this.context = context;
        }

        @Override
        public FetchRequest allBusNames() {
            query = context.getString(R.string.all_bus_names_query);
            return this;
        }

        @Override
        public FetchRequest limitTo(int limit) {
            if (limit > 0) {
                this.limit = limit;
                query += context.getString(R.string.limit_query_fragment);
            }
            return this;
        }

        @Override
        public void loadBusNames(final AsyncTaskAdapter<List<String>> adapter) {
            new BusNamesLoader(context) {
                @Override
                protected void onPreExecute() {
                    super.onPreExecute();
                    if (adapter != null) adapter.onPreExecute();
                }
                
                @Override
                protected void onPostExecute(List<String> result) {
                    super.onPostExecute(result);
                    if (adapter != null) adapter.onPostExecute(result);
                }
            }.execute(query, limit);
        }
        
        private static class BusNamesLoader  extends AsyncTask<Object, Void, List<String>> {

            private final Context context;

            private SQLiteTemplate sqliteTemplate;
            
            private BusNamesLoader(Context context) {
                this.context = context.getApplicationContext();
            }

            @Override
            protected void onPreExecute() {
                sqliteTemplate = new SQLiteTemplate(new MorphoSQLiteOpenHelper(context));
            }

            @Override
            protected List<String> doInBackground(Object... params) {
                String query = (String) params[0];
                String[] queryParams = new String[params.length-1];
                for (int i = 1; i < params.length; i++) queryParams[i-1] = params[i].toString();
                return sqliteTemplate.queryForList(
                        query, 
                        queryParams, 
                        new SQLiteTemplate.SingleColumnRowMapper());
            }
            
        }
    }
}




Java Source Code List

com.morpho.android.activity.MainActivity.java
com.morpho.android.data.GeoArea.java
com.morpho.android.data.GeoPoint.java
com.morpho.android.data.JSONable.java
com.morpho.android.data.Route.java
com.morpho.android.data.Schedule.java
com.morpho.android.data.Station.java
com.morpho.android.intent.ReceiveTransitionsIntentService.java
com.morpho.android.receiver.VoiceReplyReceiver.java
com.morpho.android.util.Strings.java
com.morpho.android.ws.AsyncTaskAdapter.java
com.morpho.android.ws.Buses.java
com.morpho.android.ws.MorphoRequest.java
com.morpho.android.ws.Schedules.java
com.morpho.android.ws.Stations.java
com.morpho.android.ws.impl.MorphoClientFactory.java
com.morpho.android.ws.impl.sqlite.BusesSQLite.java
com.morpho.android.ws.impl.sqlite.MorphoSQLiteOpenHelper.java
com.morpho.android.ws.impl.sqlite.SQLFileParser.java
com.morpho.android.ws.impl.sqlite.SQLiteTemplate.java
com.morpho.android.ws.impl.sqlite.SQLiteUtils.java
com.morpho.android.ws.impl.sqlite.SchedulesSQLite.java
com.morpho.android.ws.impl.sqlite.StationsSQLite.java