Back to project page tb-android-3.
The source code is released under:
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE Version 2, December 2004 Copyright (C) 2004 Sam Hocevar <sam@hocevar.net> Everyone is permitted to copy and distribute verba...
If you think the Android project tb-android-3 listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package org.gordon.tb3.manager; //from w w w .j a va2 s . c o m import java.util.ArrayList; import java.util.List; import org.gordon.tb3.Gordon; import org.gordon.tb3.provider.impl.GordonProvider; import org.gordon.tb3.provider.table.GordonTable; import android.content.ContentResolver; import android.content.ContentValues; import android.database.Cursor; public class GordonManager { /** * Rcuprer un cursor contenant tous les lments. * * @param contentResolver * @return un cursor */ public Cursor getCursor(ContentResolver contentResolver) { return contentResolver.query(GordonProvider.CONTENT_URI, null, null, null, null); } /** * Rcuprer tous les lments, sans filtre possible. * * @param contentResolver * @return la liste de tous les lments de la table */ public List<Gordon> getAll(ContentResolver contentResolver) { final Cursor c = contentResolver.query(GordonProvider.CONTENT_URI, null, null, null, null); return getFromCursor(c); } /** * Rcuprer un Gordon par son id. * * @param contentResolver * @param id * L'id du Gordon dsir. * @return Le Gordon dsir. */ public Gordon getById(ContentResolver contentResolver, long id) { final Cursor c = contentResolver.query(GordonProvider.CONTENT_URI, null, GordonTable._ID + "=?", new String[] { String.valueOf(id) }, null); return getFirstFromCursor(c); } /** * Ajouter un Gordon. * * @param contentResolver * @param item * Le Gordon ajouter. */ public void add(final ContentResolver contentResolver, final Gordon item) { final ContentValues values = getContentValues(item); contentResolver.insert(GordonProvider.CONTENT_URI, values); } /** * Supprimer un lment. * * @param contentResolver * @param id * L'id du Gordon radiquer. */ public void delete(final ContentResolver contentResolver, long id) { contentResolver.delete(GordonProvider.CONTENT_URI, GordonTable._ID + " = ?", new String[] { String.valueOf(id) }); } /** * Mettre jour un lment. * * @param contentResolver * @param item * Le Gordon modifier. */ public void update(final ContentResolver contentResolver, final Gordon item) { final ContentValues values = getContentValues(item); contentResolver.update(GordonProvider.CONTENT_URI, values, GordonTable._ID + " = ?", new String[] { String.valueOf(item._id) }); } /** * Prparer Gordon pour son entre en base. * * @param item * Le Gordon. * @return a ContentValue filled with ArretItem values, for a FavoriTable * structure */ private ContentValues getContentValues(Gordon item) { final ContentValues values = new ContentValues(); values.put(GordonTable.NAME, item.name); return values; } /** * Transformer un curseur en liste d'lments * * @param c * un Curseur * @return une liste d'lments */ private List<Gordon> getFromCursor(Cursor c) { List<Gordon> items = new ArrayList<Gordon>(); if (c.getCount() > 0) { c.moveToFirst(); while (!c.isAfterLast()) { items.add(getSingleFromCursor(c)); c.moveToNext(); } } c.close(); return items; } /** * Retourner le premier lment d'un curseur * * @param c * @return le premier lment du curseur */ private Gordon getFirstFromCursor(Cursor c) { Gordon result = null; if (c.getCount() > 0) { c.moveToFirst(); result = getSingleFromCursor(c); } c.close(); return result; } /** * Transformer la position courante d'un curseur en lment * * @param c * le curseur * @return un lment */ private Gordon getSingleFromCursor(Cursor c) { final Gordon item = new Gordon(); item._id = c.getInt(c.getColumnIndex(GordonTable._ID)); item.name = c.getString(c.getColumnIndex(GordonTable.NAME)); return item; } }