Android Open Source - GPSMover Favorites Helper






From Project

Back to project page GPSMover.

License

The source code is released under:

GNU General Public License

If you think the Android project GPSMover 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 org.unlucky.gpsmover.app.db;
/*  ww  w. j av  a 2  s.  com*/
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import java.sql.SQLException;

public class FavoritesHelper {
    public final static String TABLE_NAME = "tb_favorites";
    public final static String[] FIELD_NAME = {"id", "title", "latitude", "longitude", "zoomlevel"};
    public final static String[] FIELD_TYPE = {"integer primary key autoincrement",
            "text", "double", "double", "float"};

    private static FavoritesHelper inst = null;

    private Context context;
    private SQLiteDatabase db;
    private DatabaseOpenHelper openHelper;

    public static FavoritesHelper getInstance(Context context) {
        if (inst == null) {
            inst = new FavoritesHelper(context);
        }
        return inst;
    }

    public FavoritesHelper(Context context) {
        this.context = context;
    }

    public FavoritesHelper open() throws SQLException {
        openHelper = new DatabaseOpenHelper(context);
        db = openHelper.getWritableDatabase();
        return this;
    }

    public void close() {
        openHelper.close();
    }

    public void execSQL(String sql) throws SQLException {
        db.execSQL(sql);
    }

    public Cursor rawQuery(String sql, String [] selectionArgs) {
        return db.rawQuery(sql, selectionArgs);
    }

    public Cursor query(String table, String[] columns, String selection,
                        String[] selectionArgs, String groupBy, String having, String orderBy) {
        return db.query(table, columns, selection, selectionArgs,
                groupBy, having, orderBy);
    }

    public long insert(String table, ContentValues cv) {
        return db.insert(table, null, cv);
    }

    public int delete(String table, String whereClause, String[] whereArgs) {
        return db.delete(table, whereClause, whereArgs);
    }

    public int update(String table, ContentValues cv, String whereClause,
                      String[] whereArgs) {
        return db.update(table, cv, whereClause, whereArgs);
    }

    public Cursor queryAll() {
        return this.query(TABLE_NAME, FIELD_NAME, null, null, null, null, null);
    }

    public long insertFavoriteLocation(FavoriteLocation favorite) {
        ContentValues cv = new ContentValues();
        cv.put("title", favorite.getTitle());
        cv.put("latitude", favorite.getLatitude());
        cv.put("longitude", favorite.getLongitude());
        cv.put("zoomlevel", favorite.getZoomLevel());
        return this.insert(TABLE_NAME, cv);
    }
}




Java Source Code List

org.unlucky.gpsmover.app.AddLocationDialogFragment.java
org.unlucky.gpsmover.app.FavLocationDialogFragment.java
org.unlucky.gpsmover.app.FavLocationListAdapter.java
org.unlucky.gpsmover.app.GPSMoverService.java
org.unlucky.gpsmover.app.GotoLocationDialogFragment.java
org.unlucky.gpsmover.app.MainActivity.java
org.unlucky.gpsmover.app.SettingsActivity.java
org.unlucky.gpsmover.app.db.DatabaseOpenHelper.java
org.unlucky.gpsmover.app.db.FavoriteLocation.java
org.unlucky.gpsmover.app.db.FavoritesHelper.java
org.unlucky.gpsmover.app.util.Common.java