├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ ├── colors.xml │ │ │ │ ├── dimens.xml │ │ │ │ └── styles.xml │ │ │ ├── mipmap-hdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-mdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxxhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── values-w820dp │ │ │ │ └── dimens.xml │ │ │ └── layout │ │ │ │ └── activity_main.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ │ └── org │ │ │ └── wangchenlong │ │ │ └── contentproviderdemo │ │ │ ├── Book.java │ │ │ ├── DbOpenHelper.java │ │ │ ├── User.java │ │ │ ├── MainActivity.java │ │ │ └── BookProvider.java │ ├── test │ │ └── java │ │ │ └── org │ │ │ └── wangchenlong │ │ │ └── contentproviderdemo │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── org │ │ └── wangchenlong │ │ └── contentproviderdemo │ │ └── ApplicationTest.java ├── build.gradle └── proguard-rules.pro ├── .idea ├── .name ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── vcs.xml ├── modules.xml ├── runConfigurations.xml ├── compiler.xml ├── gradle.xml └── misc.xml ├── settings.gradle ├── articles └── demo-anim.gif ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── gradle.properties ├── gradlew.bat ├── gradlew └── README.md /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | ContentProviderDemo -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | -------------------------------------------------------------------------------- /articles/demo-anim.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SpikeKing/ContentProviderDemo/HEAD/articles/demo-anim.gif -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | ContentProviderDemo 3 | 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SpikeKing/ContentProviderDemo/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SpikeKing/ContentProviderDemo/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SpikeKing/ContentProviderDemo/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SpikeKing/ContentProviderDemo/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SpikeKing/ContentProviderDemo/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SpikeKing/ContentProviderDemo/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Dec 28 10:00:20 PST 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip 7 | -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/test/java/org/wangchenlong/contentproviderdemo/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package org.wangchenlong.contentproviderdemo; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * To work on unit tests, switch the Test Artifact in the Build Variants view. 9 | */ 10 | public class ExampleUnitTest { 11 | @Test 12 | public void addition_isCorrect() throws Exception { 13 | assertEquals(4, 2 + 2); 14 | } 15 | } -------------------------------------------------------------------------------- /app/src/androidTest/java/org/wangchenlong/contentproviderdemo/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package org.wangchenlong.contentproviderdemo; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.2" 6 | 7 | defaultConfig { 8 | applicationId "org.wangchenlong.contentproviderdemo" 9 | minSdkVersion 16 10 | targetSdkVersion 23 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | testCompile 'junit:junit:4.12' 25 | compile 'com.android.support:appcompat-v7:23.3.0' 26 | } 27 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/wangchenlong/Installations/android-sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | 23 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /app/src/main/java/org/wangchenlong/contentproviderdemo/Book.java: -------------------------------------------------------------------------------- 1 | package org.wangchenlong.contentproviderdemo; 2 | 3 | import android.os.Parcel; 4 | import android.os.Parcelable; 5 | 6 | public class Book implements Parcelable { 7 | 8 | public int bookId; 9 | public String bookName; 10 | 11 | public Book() { 12 | 13 | } 14 | 15 | public Book(int bookId, String bookName) { 16 | this.bookId = bookId; 17 | this.bookName = bookName; 18 | } 19 | 20 | public int describeContents() { 21 | return 0; 22 | } 23 | 24 | public void writeToParcel(Parcel out, int flags) { 25 | out.writeInt(bookId); 26 | out.writeString(bookName); 27 | } 28 | 29 | public static final Creator CREATOR = new Creator() { 30 | public Book createFromParcel(Parcel in) { 31 | return new Book(in); 32 | } 33 | 34 | public Book[] newArray(int size) { 35 | return new Book[size]; 36 | } 37 | }; 38 | 39 | private Book(Parcel in) { 40 | bookId = in.readInt(); 41 | bookName = in.readString(); 42 | } 43 | 44 | @Override 45 | public String toString() { 46 | return String.format("[bookId:%s, bookName:%s]", bookId, bookName); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /app/src/main/java/org/wangchenlong/contentproviderdemo/DbOpenHelper.java: -------------------------------------------------------------------------------- 1 | package org.wangchenlong.contentproviderdemo; 2 | 3 | import android.content.Context; 4 | import android.database.sqlite.SQLiteDatabase; 5 | import android.database.sqlite.SQLiteOpenHelper; 6 | 7 | /** 8 | * 书籍的数据库 9 | *

10 | * Created by wangchenlong on 16/6/14. 11 | */ 12 | public class DbOpenHelper extends SQLiteOpenHelper { 13 | private static final String DB_NAME = "book_provider.db"; 14 | public static final String BOOK_TABLE_NAME = "book"; 15 | public static final String USER_TABLE_NAME = "user"; 16 | 17 | private static final int DB_VERSION = 1; 18 | 19 | private String CREATE_BOOK_TABLE = "CREATE TABLE IF NOT EXISTS " 20 | + BOOK_TABLE_NAME + "(_id INTEGER PRIMARY KEY, name TEXT)"; 21 | 22 | private String CREATE_USER_TABLE = "CREATE TABLE IF NOT EXISTS " 23 | + USER_TABLE_NAME + "(_id INTEGER PRIMARY KEY, name TEXT, sex INT)"; 24 | 25 | public DbOpenHelper(Context context) { 26 | super(context, DB_NAME, null, DB_VERSION); 27 | } 28 | 29 | @Override public void onCreate(SQLiteDatabase db) { 30 | db.execSQL(CREATE_BOOK_TABLE); 31 | db.execSQL(CREATE_USER_TABLE); 32 | } 33 | 34 | @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { 35 | 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /app/src/main/java/org/wangchenlong/contentproviderdemo/User.java: -------------------------------------------------------------------------------- 1 | package org.wangchenlong.contentproviderdemo; 2 | 3 | import android.os.Parcel; 4 | import android.os.Parcelable; 5 | 6 | import java.io.Serializable; 7 | 8 | public class User implements Parcelable { 9 | public int userId; 10 | public String userName; 11 | public boolean isMale; 12 | public Book book; 13 | 14 | public User() { 15 | } 16 | 17 | public User(int userId, String userName, boolean isMale) { 18 | this.userId = userId; 19 | this.userName = userName; 20 | this.isMale = isMale; 21 | } 22 | 23 | public int describeContents() { 24 | return 0; 25 | } 26 | 27 | public void writeToParcel(Parcel out, int flags) { 28 | out.writeInt(userId); 29 | out.writeString(userName); 30 | out.writeInt(isMale ? 1 : 0); 31 | out.writeParcelable(book, 0); 32 | } 33 | 34 | public static final Creator CREATOR = new Creator() { 35 | public User createFromParcel(Parcel in) { 36 | return new User(in); 37 | } 38 | 39 | public User[] newArray(int size) { 40 | return new User[size]; 41 | } 42 | }; 43 | 44 | private User(Parcel in) { 45 | userId = in.readInt(); 46 | userName = in.readString(); 47 | isMale = in.readInt() == 1; 48 | book = in 49 | .readParcelable(Thread.currentThread().getContextClassLoader()); 50 | } 51 | 52 | @Override 53 | public String toString() { 54 | return String.format( 55 | "[userId:%s, userName:%s, isMale:%s, book:{%s}]", 56 | userId, userName, isMale, book); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | 14 |