├── res └── .gitignore ├── lint.xml ├── example ├── lint.xml ├── res │ ├── drawable-hdpi │ │ └── ic_launcher.png │ ├── drawable-ldpi │ │ └── ic_launcher.png │ ├── drawable-mdpi │ │ └── ic_launcher.png │ ├── drawable-xhdpi │ │ └── ic_launcher.png │ ├── xml │ │ └── searchable.xml │ ├── menu │ │ ├── item_context.xml │ │ ├── main.xml │ │ └── item_edit.xml │ ├── layout │ │ ├── detail.xml │ │ ├── dialog_filter.xml │ │ ├── main.xml │ │ └── edit.xml │ └── values │ │ └── strings.xml ├── .classpath ├── project.properties ├── proguard.cfg ├── src │ └── edu │ │ └── mit │ │ └── mobile │ │ └── android │ │ └── content │ │ └── example │ │ ├── Message.java │ │ ├── SampleProvider.java │ │ └── MessageDetail.java └── AndroidManifest.xml ├── .gitignore ├── test ├── res │ ├── drawable-hdpi │ │ └── icon.png │ ├── drawable-ldpi │ │ └── icon.png │ ├── drawable-mdpi │ │ └── icon.png │ └── values │ │ └── strings.xml ├── project.properties ├── src │ └── edu │ │ └── mit │ │ └── mobile │ │ └── android │ │ └── content │ │ └── test │ │ ├── sample5 │ │ ├── Tag.java │ │ ├── IdenticalTagFinder.java │ │ ├── SampleProvider5.java │ │ ├── Bookmark.java │ │ └── SampleProvider5Test.java │ │ ├── SampleProvider4.java │ │ ├── sample3 │ │ ├── Person.java │ │ └── Project.java │ │ ├── SampleProvider1.java │ │ ├── sample1 │ │ └── Message.java │ │ ├── sample4 │ │ └── Person.java │ │ ├── sample2 │ │ ├── Comment.java │ │ └── BlogPost.java │ │ ├── SampleProvider3.java │ │ ├── ContentResolverTestUtils.java │ │ ├── SampleProvider2.java │ │ ├── query │ │ ├── QueryBuilderTest.java │ │ └── ParserTest.java │ │ ├── SampleProvider1Test.java │ │ ├── SampleProvider3Test.java │ │ └── SampleProvider4Test.java └── AndroidManifest.xml ├── Makefile ├── src └── edu │ └── mit │ └── mobile │ └── android │ └── content │ ├── package.html │ ├── m2m │ ├── M2MColumns.java │ ├── IdenticalChildFinder.java │ ├── M2MManager.java │ └── M2MReverseHelper.java │ ├── column │ ├── BlobColumn.java │ ├── TextColumn.java │ ├── FloatColumn.java │ ├── DoubleColumn.java │ ├── IntegerColumn.java │ ├── BooleanColumn.java │ ├── TimestampColumn.java │ ├── DBForeignKeyColumn.java │ ├── DatetimeColumn.java │ ├── DBColumnType.java │ └── DBColumn.java │ ├── SQLGenerationException.java │ ├── ContentItem.java │ ├── DBTable.java │ ├── ContentItemRegisterable.java │ ├── DBSortOrder.java │ ├── UriPath.java │ ├── OnSaveListener.java │ ├── Manager.java │ ├── AndroidVersions.java │ ├── dbhelper │ └── ContentItemDBHelper.java │ ├── DBHelper.java │ ├── SQLGenUtils.java │ ├── ForeignKeyManager.java │ ├── GenericDBHelper.java │ ├── ForeignKeyDBHelper.java │ ├── query │ └── QuerystringParser.y │ ├── ProviderUtils.java │ └── DBHelperMapper.java ├── AndroidManifest.xml ├── project.properties ├── .classpath └── README.md /res/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /lint.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /example/lint.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | bin/ 2 | gen/ 3 | doc/ 4 | .project 5 | test/.project 6 | test/.classpath 7 | local.properties 8 | build.xml 9 | -------------------------------------------------------------------------------- /test/res/drawable-hdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mitmel/SimpleContentProvider/HEAD/test/res/drawable-hdpi/icon.png -------------------------------------------------------------------------------- /test/res/drawable-ldpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mitmel/SimpleContentProvider/HEAD/test/res/drawable-ldpi/icon.png -------------------------------------------------------------------------------- /test/res/drawable-mdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mitmel/SimpleContentProvider/HEAD/test/res/drawable-mdpi/icon.png -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | yacc=bison 2 | 3 | all: src/edu/mit/mobile/android/content/query/QuerystringParser.java 4 | %.java: %.y 5 | $(yacc) -o $@ $< 6 | -------------------------------------------------------------------------------- /example/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mitmel/SimpleContentProvider/HEAD/example/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/res/drawable-ldpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mitmel/SimpleContentProvider/HEAD/example/res/drawable-ldpi/ic_launcher.png -------------------------------------------------------------------------------- /example/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mitmel/SimpleContentProvider/HEAD/example/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mitmel/SimpleContentProvider/HEAD/example/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /test/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | SimpleContentProvider Test 4 | 5 | -------------------------------------------------------------------------------- /src/edu/mit/mobile/android/content/package.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |

Simple ContentProvider

5 | 6 |

See {@link edu.mit.mobile.android.content.SimpleContentProvider} for an example of how to use this package.

7 | 8 | 9 | -------------------------------------------------------------------------------- /example/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system use, 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | 10 | android.library=true 11 | # Project target. 12 | target=android-17 13 | -------------------------------------------------------------------------------- /test/project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system use, 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | 10 | android.library.reference.1=.. 11 | # Project target. 12 | target=android-17 13 | -------------------------------------------------------------------------------- /example/project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system use, 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | 10 | # Project target. 11 | target=android-16 12 | android.library.reference.1=.. 13 | -------------------------------------------------------------------------------- /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /example/res/xml/searchable.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | -------------------------------------------------------------------------------- /example/res/menu/item_context.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 10 | 13 | 14 | -------------------------------------------------------------------------------- /test/src/edu/mit/mobile/android/content/test/sample5/Tag.java: -------------------------------------------------------------------------------- 1 | package edu.mit.mobile.android.content.test.sample5; 2 | 3 | import edu.mit.mobile.android.content.ContentItem; 4 | import edu.mit.mobile.android.content.UriPath; 5 | import edu.mit.mobile.android.content.column.DBColumn; 6 | import edu.mit.mobile.android.content.column.TextColumn; 7 | import edu.mit.mobile.android.content.m2m.M2MManager; 8 | 9 | @UriPath(Tag.PATH) 10 | public class Tag implements ContentItem { 11 | 12 | @DBColumn(type = TextColumn.class, unique = true) 13 | public static final String NAME = "name"; 14 | public static final String PATH = "tag"; 15 | 16 | public static M2MManager BOOKMARKS = new M2MManager(Bookmark.class); 17 | 18 | } 19 | -------------------------------------------------------------------------------- /example/res/layout/detail.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 15 | 19 | 20 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /example/res/menu/main.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /example/res/menu/item_edit.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 17 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /example/res/layout/dialog_filter.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 13 | 14 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /src/edu/mit/mobile/android/content/m2m/M2MColumns.java: -------------------------------------------------------------------------------- 1 | package edu.mit.mobile.android.content.m2m; 2 | /* 3 | * Copyright (C) 2011-2013 MIT Mobile Experience Lab 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License version 2.1 as published by the Free Software Foundation. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, visit 16 | * http://www.gnu.org/licenses/lgpl.html 17 | */ 18 | 19 | import android.provider.BaseColumns; 20 | 21 | public class M2MColumns implements BaseColumns { 22 | 23 | public static final String TO_ID = "to_id"; 24 | public static final String FROM_ID = "from_id"; 25 | } 26 | -------------------------------------------------------------------------------- /test/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 10 | 11 | 14 | 15 | 18 | 19 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /test/src/edu/mit/mobile/android/content/test/SampleProvider4.java: -------------------------------------------------------------------------------- 1 | package edu.mit.mobile.android.content.test; 2 | 3 | import edu.mit.mobile.android.content.ForeignKeyDBHelper; 4 | import edu.mit.mobile.android.content.GenericDBHelper; 5 | import edu.mit.mobile.android.content.SimpleContentProvider; 6 | import edu.mit.mobile.android.content.test.sample4.Person; 7 | 8 | public class SampleProvider4 extends SimpleContentProvider { 9 | 10 | public static final int DB_VER = 1; 11 | public static final String AUTHORITY = "edu.mit.mobile.android.content.test.sampleprovider4"; 12 | 13 | public SampleProvider4() { 14 | super(AUTHORITY, DB_VER); 15 | 16 | final GenericDBHelper personHelper = new GenericDBHelper(Person.class); 17 | 18 | final ForeignKeyDBHelper subordinateHelper = new ForeignKeyDBHelper(Person.class, 19 | Person.class, Person.SUPERVISOR); 20 | 21 | // 22 | // define the interface. 23 | // 24 | 25 | // /person/ 26 | addDirAndItemUri(personHelper, Person.PATH); 27 | 28 | // /person/1/subordinates/ 29 | addChildDirAndItemUri(subordinateHelper, Person.PATH, Person.SUBORDINATE_PATH); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/edu/mit/mobile/android/content/column/BlobColumn.java: -------------------------------------------------------------------------------- 1 | package edu.mit.mobile.android.content.column; 2 | /* 3 | * Copyright (C) 2011-2013 MIT Mobile Experience Lab 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License version 2.1 as published by the Free Software Foundation. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, visit 16 | * http://www.gnu.org/licenses/lgpl.html 17 | */ 18 | 19 | import android.database.Cursor; 20 | 21 | public class BlobColumn extends DBColumnType { 22 | 23 | @Override 24 | public String toCreateColumn(String colName) { 25 | return toColumnDef(colName, "BLOB"); 26 | } 27 | 28 | @Override 29 | public byte[] get(Cursor c, int colNumber) { 30 | 31 | return c.getBlob(colNumber); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/edu/mit/mobile/android/content/column/TextColumn.java: -------------------------------------------------------------------------------- 1 | package edu.mit.mobile.android.content.column; 2 | /* 3 | * Copyright (C) 2011-2013 MIT Mobile Experience Lab 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License version 2.1 as published by the Free Software Foundation. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, visit 16 | * http://www.gnu.org/licenses/lgpl.html 17 | */ 18 | 19 | import android.database.Cursor; 20 | 21 | public class TextColumn extends DBColumnType { 22 | 23 | @Override 24 | public String toCreateColumn(String colName) { 25 | return toColumnDef(colName, "TEXT"); 26 | } 27 | 28 | @Override 29 | public String get(Cursor c, int colNumber) { 30 | return c.getString(colNumber); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /test/src/edu/mit/mobile/android/content/test/sample3/Person.java: -------------------------------------------------------------------------------- 1 | package edu.mit.mobile.android.content.test.sample3; 2 | 3 | import android.content.ContentValues; 4 | import android.net.Uri; 5 | import edu.mit.mobile.android.content.ContentItem; 6 | import edu.mit.mobile.android.content.ProviderUtils; 7 | import edu.mit.mobile.android.content.UriPath; 8 | import edu.mit.mobile.android.content.column.DBColumn; 9 | import edu.mit.mobile.android.content.column.TextColumn; 10 | import edu.mit.mobile.android.content.m2m.M2MManager; 11 | import edu.mit.mobile.android.content.test.SampleProvider3; 12 | 13 | @UriPath(Person.PATH) 14 | public class Person implements ContentItem { 15 | 16 | @DBColumn(type = TextColumn.class) 17 | public static final String NAME = "name"; 18 | 19 | public static final M2MManager PROJECTS = new M2MManager(Project.class); 20 | 21 | public static final String PATH = "person"; 22 | 23 | public static final Uri CONTENT_URI = ProviderUtils.toContentUri(SampleProvider3.AUTHORITY, 24 | PATH); 25 | 26 | public static ContentValues toCv(String name) { 27 | final ContentValues cv = new ContentValues(); 28 | 29 | cv.put(NAME, name); 30 | 31 | return cv; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /test/src/edu/mit/mobile/android/content/test/sample5/IdenticalTagFinder.java: -------------------------------------------------------------------------------- 1 | package edu.mit.mobile.android.content.test.sample5; 2 | 3 | import android.content.ContentUris; 4 | import android.content.ContentValues; 5 | import android.database.Cursor; 6 | import android.database.sqlite.SQLiteDatabase; 7 | import android.net.Uri; 8 | import edu.mit.mobile.android.content.DBHelper; 9 | import edu.mit.mobile.android.content.m2m.IdenticalChildFinder; 10 | 11 | public class IdenticalTagFinder implements IdenticalChildFinder { 12 | protected static final String[] COLS = new String[] { Tag._ID }; 13 | 14 | @Override 15 | public Uri getIdenticalChild(DBHelper m2m, Uri parentChildDir, SQLiteDatabase db, 16 | String childTable, ContentValues values) { 17 | final Cursor c = db.query(childTable, COLS, Tag.NAME + "=?", 18 | new String[] { values.getAsString(Tag.NAME) }, null, null, null); 19 | try { 20 | if (c.moveToFirst()) { 21 | final long id = c.getLong(c.getColumnIndex(Tag._ID)); 22 | return ContentUris.withAppendedId(parentChildDir, id); 23 | } 24 | } finally { 25 | c.close(); 26 | } 27 | return null; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/edu/mit/mobile/android/content/column/FloatColumn.java: -------------------------------------------------------------------------------- 1 | package edu.mit.mobile.android.content.column; 2 | /* 3 | * Copyright (C) 2011-2013 MIT Mobile Experience Lab 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License version 2.1 as published by the Free Software Foundation. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, visit 16 | * http://www.gnu.org/licenses/lgpl.html 17 | */ 18 | 19 | import android.database.Cursor; 20 | 21 | public class FloatColumn extends DBColumnType { 22 | 23 | @Override 24 | public String toCreateColumn(String colName) { 25 | return toColumnDef(colName, "FLOAT"); 26 | } 27 | 28 | @Override 29 | public java.lang.Float get(Cursor c, int colNumber) { 30 | 31 | return java.lang.Float.valueOf(c.getFloat(colNumber)); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/edu/mit/mobile/android/content/column/DoubleColumn.java: -------------------------------------------------------------------------------- 1 | package edu.mit.mobile.android.content.column; 2 | /* 3 | * Copyright (C) 2011-2013 MIT Mobile Experience Lab 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License version 2.1 as published by the Free Software Foundation. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, visit 16 | * http://www.gnu.org/licenses/lgpl.html 17 | */ 18 | 19 | import android.database.Cursor; 20 | 21 | public class DoubleColumn extends DBColumnType { 22 | 23 | @Override 24 | public String toCreateColumn(String colName) { 25 | return toColumnDef(colName, "DOUBLE"); 26 | } 27 | 28 | @Override 29 | public java.lang.Double get(Cursor c, int colNumber) { 30 | 31 | return java.lang.Double.valueOf(c.getDouble(colNumber)); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/edu/mit/mobile/android/content/column/IntegerColumn.java: -------------------------------------------------------------------------------- 1 | package edu.mit.mobile.android.content.column; 2 | /* 3 | * Copyright (C) 2011-2013 MIT Mobile Experience Lab 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License version 2.1 as published by the Free Software Foundation. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, visit 16 | * http://www.gnu.org/licenses/lgpl.html 17 | */ 18 | 19 | import android.database.Cursor; 20 | 21 | public class IntegerColumn extends DBColumnType { 22 | 23 | @Override 24 | public String toCreateColumn(String colName) { 25 | return toColumnDef(colName, "INTEGER"); 26 | } 27 | 28 | @Override 29 | public java.lang.Integer get(Cursor c, int colNumber) { 30 | 31 | return java.lang.Integer.valueOf(c.getInt(colNumber)); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/edu/mit/mobile/android/content/SQLGenerationException.java: -------------------------------------------------------------------------------- 1 | package edu.mit.mobile.android.content; 2 | /* 3 | * Copyright (C) 2011-2013 MIT Mobile Experience Lab 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License version 2.1 as published by the Free Software Foundation. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, visit 16 | * http://www.gnu.org/licenses/lgpl.html 17 | */ 18 | 19 | public class SQLGenerationException extends RuntimeException { 20 | /** 21 | * 22 | */ 23 | private static final long serialVersionUID = 1987806236697877222L; 24 | 25 | public SQLGenerationException() { 26 | super(); 27 | } 28 | 29 | public SQLGenerationException(String message) { 30 | super(message); 31 | } 32 | 33 | public SQLGenerationException(String message, Throwable initCause) { 34 | super(message); 35 | initCause(initCause); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/edu/mit/mobile/android/content/column/BooleanColumn.java: -------------------------------------------------------------------------------- 1 | package edu.mit.mobile.android.content.column; 2 | /* 3 | * Copyright (C) 2011-2013 MIT Mobile Experience Lab 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License version 2.1 as published by the Free Software Foundation. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, visit 16 | * http://www.gnu.org/licenses/lgpl.html 17 | */ 18 | 19 | import android.database.Cursor; 20 | 21 | /** 22 | * A simple boolean value. Internally, this is stored as an integer where 0 is false and 1 is true. 23 | * 24 | */ 25 | public class BooleanColumn extends DBColumnType { 26 | 27 | @Override 28 | public String toCreateColumn(String colName) { 29 | return toColumnDef(colName, "BOOLEAN"); 30 | } 31 | 32 | @Override 33 | public Boolean get(Cursor c, int colNumber) { 34 | 35 | return c.getInt(colNumber) != 0; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/edu/mit/mobile/android/content/ContentItem.java: -------------------------------------------------------------------------------- 1 | package edu.mit.mobile.android.content; 2 | /* 3 | * Copyright (C) 2011-2013 MIT Mobile Experience Lab 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License version 2.1 as published by the Free Software Foundation. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, visit 16 | * http://www.gnu.org/licenses/lgpl.html 17 | */ 18 | 19 | import android.provider.BaseColumns; 20 | import edu.mit.mobile.android.content.column.DBColumn; 21 | import edu.mit.mobile.android.content.column.IntegerColumn; 22 | 23 | /** 24 | * A simple extension of {@link BaseColumns} that tags {@link #_ID} as an integer primary key. 25 | * 26 | * @author Steve Pomeroy 27 | * 28 | */ 29 | public interface ContentItem extends BaseColumns { 30 | 31 | @DBColumn(type = IntegerColumn.class, primaryKey = true, autoIncrement = true) 32 | public static final String _ID = BaseColumns._ID; 33 | 34 | } 35 | -------------------------------------------------------------------------------- /example/proguard.cfg: -------------------------------------------------------------------------------- 1 | -optimizationpasses 5 2 | -dontusemixedcaseclassnames 3 | -dontskipnonpubliclibraryclasses 4 | -dontpreverify 5 | -verbose 6 | -optimizations !code/simplification/arithmetic,!field/*,!class/merging/* 7 | 8 | -keep public class * extends android.app.Activity 9 | -keep public class * extends android.app.Application 10 | -keep public class * extends android.app.Service 11 | -keep public class * extends android.content.BroadcastReceiver 12 | -keep public class * extends android.content.ContentProvider 13 | -keep public class * extends android.app.backup.BackupAgentHelper 14 | -keep public class * extends android.preference.Preference 15 | -keep public class com.android.vending.licensing.ILicensingService 16 | 17 | -keepclasseswithmembernames class * { 18 | native ; 19 | } 20 | 21 | -keepclasseswithmembers class * { 22 | public (android.content.Context, android.util.AttributeSet); 23 | } 24 | 25 | -keepclasseswithmembers class * { 26 | public (android.content.Context, android.util.AttributeSet, int); 27 | } 28 | 29 | -keepclassmembers class * extends android.app.Activity { 30 | public void *(android.view.View); 31 | } 32 | 33 | -keepclassmembers enum * { 34 | public static **[] values(); 35 | public static ** valueOf(java.lang.String); 36 | } 37 | 38 | -keep class * implements android.os.Parcelable { 39 | public static final android.os.Parcelable$Creator *; 40 | } 41 | -------------------------------------------------------------------------------- /test/src/edu/mit/mobile/android/content/test/SampleProvider1.java: -------------------------------------------------------------------------------- 1 | package edu.mit.mobile.android.content.test; 2 | 3 | import edu.mit.mobile.android.content.DBHelper; 4 | import edu.mit.mobile.android.content.GenericDBHelper; 5 | import edu.mit.mobile.android.content.SimpleContentProvider; 6 | import edu.mit.mobile.android.content.test.sample1.Message; 7 | 8 | public class SampleProvider1 extends SimpleContentProvider { 9 | public static final String AUTHORITY = "edu.mit.mobile.android.content.test.sampleprovider1"; 10 | 11 | public SampleProvider1() { 12 | // authority DB ver 13 | super(AUTHORITY, 1); 14 | 15 | // This helper creates the table and can do basic CRUD for items that 16 | // use the dir/item scheme with the BaseColumns._ID integer primary key. 17 | final DBHelper messageHelper = new GenericDBHelper(Message.class); 18 | 19 | // Adds a mapping between the given content:// URI path and the 20 | // helper. 21 | // 22 | // There's an optional fourth parameter which lets you have different 23 | // helpers handle different SQL verbs (eg. use a GenericDBHelper for 24 | // basic insert, delete, update, but have a custom helper for querying). 25 | addDirUri(messageHelper, Message.PATH, getDirType(Message.PATH)); 26 | addItemUri(messageHelper, Message.PATH + "/#", getItemType(Message.PATH)); 27 | 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /example/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | SimpleContentProvider Example 4 | Title 5 | Body 6 | Save 7 | Add 8 | Cancel 9 | ID 10 | Clear All 11 | Add Random 12 | Add Many 13 | View 14 | Edit 15 | Delete 16 | There are no items in the list. 17 | Confirm Delete 18 | Are you sure you want to delete this item? 19 | Title or body 20 | SimpleContentProvider example global search 21 | Enter a QuerystringWrapper query string to limit the shown messages. Valid columns are \"title\", \"body\", and \"created\". Try: body~=awesome|title~=rock 22 | query string 23 | 24 | -------------------------------------------------------------------------------- /test/src/edu/mit/mobile/android/content/test/sample1/Message.java: -------------------------------------------------------------------------------- 1 | package edu.mit.mobile.android.content.test.sample1; 2 | 3 | import android.net.Uri; 4 | import edu.mit.mobile.android.content.ContentItem; 5 | import edu.mit.mobile.android.content.ProviderUtils; 6 | import edu.mit.mobile.android.content.column.DBColumn; 7 | import edu.mit.mobile.android.content.column.TextColumn; 8 | import edu.mit.mobile.android.content.column.TimestampColumn; 9 | import edu.mit.mobile.android.content.test.SampleProvider1; 10 | 11 | /** 12 | * A simple message with a body and creation date. 13 | */ 14 | public class Message implements ContentItem { 15 | 16 | // Column definitions below. ContentItem contains one column definition 17 | // for the BaseColumns._ID which defines the primary key. 18 | @DBColumn(type = TimestampColumn.class, defaultValue = TimestampColumn.CURRENT_TIMESTAMP) 19 | public static final String CREATED_DATE = "created"; 20 | 21 | @DBColumn(type = TextColumn.class) 22 | public static final String BODY = "body"; 23 | 24 | // The path component of the content URI. 25 | public static final String PATH = "message"; 26 | 27 | // The SimpleContentProvider constructs content URIs based on your provided 28 | // path and authority. 29 | // This constant is not necessary, but is very handy for doing queries. 30 | public static final Uri CONTENT_URI = ProviderUtils.toContentUri(SampleProvider1.AUTHORITY, 31 | PATH); 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/edu/mit/mobile/android/content/DBTable.java: -------------------------------------------------------------------------------- 1 | package edu.mit.mobile.android.content; 2 | /* 3 | * Copyright (C) 2011-2013 MIT Mobile Experience Lab 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License version 2.1 as published by the Free Software Foundation. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, visit 16 | * http://www.gnu.org/licenses/lgpl.html 17 | */ 18 | 19 | import java.lang.annotation.Documented; 20 | import java.lang.annotation.ElementType; 21 | import java.lang.annotation.Retention; 22 | import java.lang.annotation.RetentionPolicy; 23 | import java.lang.annotation.Target; 24 | 25 | /** 26 | * Specifies the table name for the given {@link ContentItem}. Pass a string, which will be used as 27 | * the table name. 28 | * 29 | * @author Steve Pomeroy 30 | * 31 | */ 32 | @Retention(RetentionPolicy.RUNTIME) 33 | @Target(ElementType.TYPE) 34 | @Documented 35 | public @interface DBTable { 36 | 37 | /** 38 | * @return the name of the table 39 | */ 40 | String value(); 41 | 42 | } 43 | -------------------------------------------------------------------------------- /test/src/edu/mit/mobile/android/content/test/sample3/Project.java: -------------------------------------------------------------------------------- 1 | package edu.mit.mobile.android.content.test.sample3; 2 | 3 | import java.util.Date; 4 | 5 | import android.content.ContentValues; 6 | import android.net.Uri; 7 | import edu.mit.mobile.android.content.ContentItem; 8 | import edu.mit.mobile.android.content.ProviderUtils; 9 | import edu.mit.mobile.android.content.UriPath; 10 | import edu.mit.mobile.android.content.column.DBColumn; 11 | import edu.mit.mobile.android.content.column.DatetimeColumn; 12 | import edu.mit.mobile.android.content.column.TextColumn; 13 | import edu.mit.mobile.android.content.m2m.M2MManager; 14 | import edu.mit.mobile.android.content.test.SampleProvider3; 15 | 16 | @UriPath(Project.PATH) 17 | public class Project implements ContentItem { 18 | 19 | @DBColumn(type = TextColumn.class) 20 | public static final String NAME = "name"; 21 | 22 | @DBColumn(type = DatetimeColumn.class) 23 | public static final String DUE_DATE = "due_date"; 24 | 25 | public static final M2MManager PEOPLE = new M2MManager(Person.class); 26 | 27 | public static final String PATH = "project"; 28 | 29 | public static final Uri CONTENT_URI = ProviderUtils.toContentUri(SampleProvider3.AUTHORITY, 30 | PATH); 31 | 32 | public static ContentValues toCv(String name, Date dueDate) { 33 | final ContentValues cv = new ContentValues(); 34 | 35 | cv.put(NAME, name); 36 | cv.put(DUE_DATE, dueDate.getTime()); 37 | 38 | return cv; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /test/src/edu/mit/mobile/android/content/test/sample5/SampleProvider5.java: -------------------------------------------------------------------------------- 1 | package edu.mit.mobile.android.content.test.sample5; 2 | 3 | import edu.mit.mobile.android.content.GenericDBHelper; 4 | import edu.mit.mobile.android.content.SimpleContentProvider; 5 | import edu.mit.mobile.android.content.m2m.M2MDBHelper; 6 | import edu.mit.mobile.android.content.m2m.M2MReverseHelper; 7 | 8 | public class SampleProvider5 extends SimpleContentProvider { 9 | 10 | public static final int DB_VER = 1; 11 | public static final String AUTHORITY = "edu.mit.mobile.android.content.test.sampleprovider5"; 12 | 13 | public SampleProvider5() { 14 | super(AUTHORITY, DB_VER); 15 | 16 | final GenericDBHelper bookmarks = new GenericDBHelper(Bookmark.class); 17 | 18 | final GenericDBHelper tags = new GenericDBHelper(Tag.class); 19 | 20 | // /bookmark/ 21 | addDirAndItemUri(bookmarks, Bookmark.PATH); 22 | 23 | // /tag/ 24 | // /tag/1/ 25 | addDirAndItemUri(tags, Tag.PATH); 26 | 27 | final M2MDBHelper bookmarks_tags = new M2MDBHelper(bookmarks, tags, 28 | new IdenticalTagFinder()); 29 | 30 | // /bookmark/#/tag/ 31 | // /bookmark/#/tag/1/ 32 | addChildDirAndItemUri(bookmarks_tags, Bookmark.PATH, Tag.PATH); 33 | 34 | final M2MReverseHelper tags_bookmarks = new M2MReverseHelper(bookmarks_tags); 35 | 36 | // /tag/#/bookmark/ 37 | // /tag/#/bookmark/1/ 38 | addChildDirAndItemUri(tags_bookmarks, Tag.PATH, Bookmark.PATH); 39 | 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/edu/mit/mobile/android/content/ContentItemRegisterable.java: -------------------------------------------------------------------------------- 1 | package edu.mit.mobile.android.content; 2 | 3 | /* 4 | * Copyright (C) 2011-2013 MIT Mobile Experience Lab 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License version 2.1 as published by the Free Software Foundation. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, visit 17 | * http://www.gnu.org/licenses/lgpl.html 18 | */ 19 | 20 | /** 21 | * If a {@link DBHelper} has a specific {@link ContentItem} that's associated with the given data, 22 | * it should implement this interface and return that ContentItem. This can later be retrieved from 23 | * {@link SimpleContentProvider#getContentItem(android.net.Uri)}. 24 | * 25 | */ 26 | public interface ContentItemRegisterable { 27 | 28 | /** 29 | * Implement this to return the {@link ContentItem} associated with the implementing class. 30 | * 31 | * @param isItem 32 | * true if the registration is being done for an item. False if it's a directory. 33 | * @return the class of the {@link ContentItem} 34 | */ 35 | public Class getContentItem(boolean isItem); 36 | } 37 | -------------------------------------------------------------------------------- /src/edu/mit/mobile/android/content/column/TimestampColumn.java: -------------------------------------------------------------------------------- 1 | package edu.mit.mobile.android.content.column; 2 | /* 3 | * Copyright (C) 2011-2013 MIT Mobile Experience Lab 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License version 2.1 as published by the Free Software Foundation. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, visit 16 | * http://www.gnu.org/licenses/lgpl.html 17 | */ 18 | 19 | import android.database.Cursor; 20 | 21 | /** 22 | * A string-based timestamp. 23 | * 24 | * @author steve 25 | * 26 | */ 27 | public class TimestampColumn extends DBColumnType { 28 | 29 | public final static String CURRENT_TIMESTAMP = DEFAULT_VALUE_ESCAPE + "CURRENT_TIMESTAMP"; 30 | public final static String CURRENT_DATE = DEFAULT_VALUE_ESCAPE + "CURRENT_DATE"; 31 | public final static String CURRENT_TIME = DEFAULT_VALUE_ESCAPE + "CURRENT_TIME"; 32 | 33 | @Override 34 | public String toCreateColumn(String colName) { 35 | return toColumnDef(colName, "TIMESTAMP"); 36 | } 37 | 38 | @Override 39 | public String get(Cursor c, int colNumber) { 40 | return c.getString(colNumber); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /test/src/edu/mit/mobile/android/content/test/sample4/Person.java: -------------------------------------------------------------------------------- 1 | package edu.mit.mobile.android.content.test.sample4; 2 | 3 | import android.content.ContentValues; 4 | import android.net.Uri; 5 | import edu.mit.mobile.android.content.ContentItem; 6 | import edu.mit.mobile.android.content.DBTable; 7 | import edu.mit.mobile.android.content.ForeignKeyManager; 8 | import edu.mit.mobile.android.content.ProviderUtils; 9 | import edu.mit.mobile.android.content.UriPath; 10 | import edu.mit.mobile.android.content.column.DBColumn; 11 | import edu.mit.mobile.android.content.column.DBForeignKeyColumn; 12 | import edu.mit.mobile.android.content.column.TextColumn; 13 | import edu.mit.mobile.android.content.test.SampleProvider4; 14 | 15 | @UriPath(Person.PATH) 16 | @DBTable("kittens") 17 | public class Person implements ContentItem { 18 | 19 | @DBColumn(type = TextColumn.class) 20 | public static final String NAME = "name"; 21 | 22 | @DBForeignKeyColumn(parent = Person.class, notnull = false) 23 | public static final String SUPERVISOR = "supervisor"; 24 | 25 | public static final String PATH = "person"; 26 | 27 | public static final String SUBORDINATE_PATH = "subordinates"; 28 | 29 | public static final ForeignKeyManager SUBORDINATES = new ForeignKeyManager(Person.class, 30 | SUBORDINATE_PATH); 31 | 32 | public static final Uri CONTENT_URI = ProviderUtils.toContentUri(SampleProvider4.AUTHORITY, 33 | PATH); 34 | 35 | public static ContentValues toCv(String name) { 36 | final ContentValues cv = new ContentValues(); 37 | 38 | cv.put(NAME, name); 39 | 40 | return cv; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/edu/mit/mobile/android/content/DBSortOrder.java: -------------------------------------------------------------------------------- 1 | package edu.mit.mobile.android.content; 2 | 3 | /* 4 | * Copyright (C) 2011-2013 MIT Mobile Experience Lab 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License version 2.1 as published by the Free Software Foundation. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, visit 17 | * http://www.gnu.org/licenses/lgpl.html 18 | */ 19 | import java.lang.annotation.Documented; 20 | import java.lang.annotation.ElementType; 21 | import java.lang.annotation.Retention; 22 | import java.lang.annotation.RetentionPolicy; 23 | import java.lang.annotation.Target; 24 | 25 | /** 26 | * Annotate your {@link ContentItem} class with this in order to specify a default sort order when 27 | * queried using {@link GenericDBHelper}. It's often easiest to define the sort order as a 28 | * {@code static final String} in the class and then refer to it in this annotation value. 29 | * 30 | * @author Steve Pomeroy 31 | * 32 | */ 33 | @Retention(RetentionPolicy.RUNTIME) 34 | @Target(ElementType.TYPE) 35 | @Documented 36 | public @interface DBSortOrder { 37 | 38 | /** 39 | * @return the default sort order for this type 40 | */ 41 | public String value(); 42 | } 43 | -------------------------------------------------------------------------------- /test/src/edu/mit/mobile/android/content/test/sample2/Comment.java: -------------------------------------------------------------------------------- 1 | package edu.mit.mobile.android.content.test.sample2; 2 | 3 | import android.net.Uri; 4 | import edu.mit.mobile.android.content.ContentItem; 5 | import edu.mit.mobile.android.content.ForeignKeyDBHelper; 6 | import edu.mit.mobile.android.content.ProviderUtils; 7 | import edu.mit.mobile.android.content.UriPath; 8 | import edu.mit.mobile.android.content.column.DBColumn; 9 | import edu.mit.mobile.android.content.column.DBForeignKeyColumn; 10 | import edu.mit.mobile.android.content.column.DatetimeColumn; 11 | import edu.mit.mobile.android.content.column.TextColumn; 12 | import edu.mit.mobile.android.content.test.SampleProvider2; 13 | 14 | @UriPath(Comment.PATH) 15 | public class Comment implements ContentItem { 16 | 17 | @DBColumn(type = DatetimeColumn.class, defaultValue = DatetimeColumn.NOW_IN_MILLISECONDS) 18 | public static final String CREATED_DATE = "created"; 19 | 20 | @DBColumn(type = TextColumn.class) 21 | public static final String BODY = "body"; 22 | 23 | // this creates a foreign key relationship to the blog post. In effect, this 24 | // is the child storing the ID of its parent. The ForeignKeyManager will help 25 | // access this relationship. 26 | @DBForeignKeyColumn(parent = BlogPost.class) 27 | public static final String POST = "post"; 28 | 29 | public static final String PATH = "comment"; 30 | 31 | public static final String PATH_ALL_COMMENTS = BlogPost.PATH + "/" 32 | + ForeignKeyDBHelper.WILDCARD_PATH_SEGMENT + "/" + PATH; 33 | 34 | public static final Uri ALL_COMMENTS = ProviderUtils.toContentUri(SampleProvider2.AUTHORITY, 35 | PATH_ALL_COMMENTS); 36 | } 37 | -------------------------------------------------------------------------------- /src/edu/mit/mobile/android/content/UriPath.java: -------------------------------------------------------------------------------- 1 | package edu.mit.mobile.android.content; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | /** 10 | * Optional. For use on {@link ContentItem} classes. This specifies the path under which the content 11 | * items are found so that helpers like {@link ForeignKeyManager} can automatically construct URLs. 12 | * 13 | */ 14 | @Retention(RetentionPolicy.RUNTIME) 15 | @Target(ElementType.TYPE) 16 | @Documented 17 | public @interface UriPath { 18 | 19 | public String value(); 20 | 21 | public static class Extractor { 22 | /** 23 | * Extract the UriPath value from the given class. 24 | * 25 | * @param contentItem 26 | * @param required 27 | * @return the path as specified by the UriPath annotation or null. 28 | * @throws SQLGenerationException 29 | * if required is true and the annotation is missing. 30 | * 31 | */ 32 | public static String extractUriPath(Class contentItem, 33 | boolean required) { 34 | String pathString; 35 | final UriPath path = contentItem.getAnnotation(UriPath.class); 36 | pathString = path != null ? path.value() : null; 37 | if (required && pathString == null) { 38 | throw new SQLGenerationException("ForeignKeyManager: missing @UriPath on " 39 | + contentItem); 40 | } 41 | return pathString; 42 | } 43 | }; 44 | } 45 | -------------------------------------------------------------------------------- /src/edu/mit/mobile/android/content/column/DBForeignKeyColumn.java: -------------------------------------------------------------------------------- 1 | package edu.mit.mobile.android.content.column; 2 | /* 3 | * Copyright (C) 2011-2013 MIT Mobile Experience Lab 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License version 2.1 as published by the Free Software Foundation. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, visit 16 | * http://www.gnu.org/licenses/lgpl.html 17 | */ 18 | 19 | import java.lang.annotation.Documented; 20 | import java.lang.annotation.ElementType; 21 | import java.lang.annotation.Retention; 22 | import java.lang.annotation.RetentionPolicy; 23 | import java.lang.annotation.Target; 24 | 25 | import edu.mit.mobile.android.content.ContentItem; 26 | 27 | @Retention(RetentionPolicy.RUNTIME) 28 | @Target(ElementType.FIELD) 29 | @Documented 30 | public @interface DBForeignKeyColumn { 31 | 32 | Class parent(); 33 | 34 | /** 35 | * Sets this column to be NOT NULL. 36 | * 37 | * @return true if the column is NOT NULL 38 | */ 39 | boolean notnull() default false; 40 | 41 | /** 42 | * Suffixes the column declaration with this string. 43 | * 44 | * @return a string of any supplemental column declarations 45 | */ 46 | String extraColDef() default DBColumn.NULL; 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/edu/mit/mobile/android/content/m2m/IdenticalChildFinder.java: -------------------------------------------------------------------------------- 1 | package edu.mit.mobile.android.content.m2m; 2 | /* 3 | * Copyright (C) 2011-2013 MIT Mobile Experience Lab 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License version 2.1 as published by the Free Software Foundation. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, visit 16 | * http://www.gnu.org/licenses/lgpl.html 17 | */ 18 | 19 | import android.content.ContentValues; 20 | import android.database.sqlite.SQLiteDatabase; 21 | import android.net.Uri; 22 | import edu.mit.mobile.android.content.DBHelper; 23 | 24 | public interface IdenticalChildFinder { 25 | /** 26 | * Search the database and see if there is a child that is identical (using whatever criteria you prefer) to the one described in values. 27 | * 28 | * @param m2m the DBHelper for the parent/child relationship 29 | * @param parentChildDir the URI of the parent's children 30 | * @param db the database to do lookups on 31 | * @param childTable the child table to look into 32 | * @param values the values that describe the child in question. 33 | * @return if an identical child is found, returns its Uri. If none are found, returns null. 34 | */ 35 | public Uri getIdenticalChild(DBHelper m2m, Uri parentChildDir, SQLiteDatabase db, String childTable, ContentValues values); 36 | } 37 | -------------------------------------------------------------------------------- /test/src/edu/mit/mobile/android/content/test/sample5/Bookmark.java: -------------------------------------------------------------------------------- 1 | package edu.mit.mobile.android.content.test.sample5; 2 | 3 | import java.util.HashSet; 4 | import java.util.Set; 5 | 6 | import android.content.ContentResolver; 7 | import android.database.Cursor; 8 | import android.net.Uri; 9 | import edu.mit.mobile.android.content.ContentItem; 10 | import edu.mit.mobile.android.content.ProviderUtils; 11 | import edu.mit.mobile.android.content.UriPath; 12 | import edu.mit.mobile.android.content.column.DBColumn; 13 | import edu.mit.mobile.android.content.column.TextColumn; 14 | import edu.mit.mobile.android.content.m2m.M2MManager; 15 | 16 | @UriPath(Bookmark.PATH) 17 | public class Bookmark implements ContentItem { 18 | 19 | @DBColumn(type = TextColumn.class, notnull = true) 20 | public static final String TITLE = "title"; 21 | 22 | @DBColumn(type = TextColumn.class, notnull = true) 23 | public static final String URL = "url"; 24 | 25 | public static final String PATH = "bookmark"; 26 | 27 | public static M2MManager TAGS = new M2MManager(Tag.class); 28 | 29 | public static Uri CONTENT_URI = ProviderUtils.toContentUri(SampleProvider5.AUTHORITY, PATH); 30 | 31 | public static final String[] TAG_PROJECTION = new String[] { Tag.NAME }; 32 | 33 | public static Set getTags(ContentResolver cr, Uri tagDir) { 34 | final Set tags = new HashSet(); 35 | 36 | final Cursor c = cr.query(tagDir, TAG_PROJECTION, null, null, null); 37 | 38 | try { 39 | final int tagNameCol = c.getColumnIndexOrThrow(Tag.NAME); 40 | 41 | while (c.moveToNext()) { 42 | tags.add(c.getString(tagNameCol)); 43 | } 44 | } finally { 45 | c.close(); 46 | } 47 | 48 | return tags; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/edu/mit/mobile/android/content/OnSaveListener.java: -------------------------------------------------------------------------------- 1 | package edu.mit.mobile.android.content; 2 | /* 3 | * Copyright (C) 2011-2013 MIT Mobile Experience Lab 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License version 2.1 as published by the Free Software Foundation. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, visit 16 | * http://www.gnu.org/licenses/lgpl.html 17 | */ 18 | 19 | import android.content.ContentValues; 20 | import android.database.sqlite.SQLiteDatabase; 21 | import android.net.Uri; 22 | 23 | /** 24 | * This hook runs right before insert or update, allowing the data to be modified before being saved 25 | * to the database. 26 | * 27 | * @author Steve Pomeroy 28 | * 29 | */ 30 | public interface OnSaveListener { 31 | 32 | /** 33 | * This hook runs right before insert or update, allowing the data to be modified before being 34 | * saved to the database. 35 | * 36 | * @param db 37 | * 38 | * @param uri 39 | * the uri of the item being updated or null if the item is being inserted. 40 | * 41 | * @param cv 42 | * the requested data to be updated or inserted. There is no guarantee that any of 43 | * the values will be present. 44 | * 45 | * @return the data that will be used for the save. This will usually be the same as the 46 | * passed-in cv. 47 | */ 48 | public ContentValues onPreSave(SQLiteDatabase db, Uri uri, ContentValues cv); 49 | } 50 | -------------------------------------------------------------------------------- /example/res/layout/main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 19 | 20 | 25 | 26 | 34 | 41 | 49 | 50 |