SimpleSQLProvider


Source link: https://github.com/ckurtm/simple-sql-provider

SimpleSQLProvider

The Fastest Way to create a sql based ContentProvider in Android using annotations (No reflection)

HOW TO ADD TO YOUR PROJECT

Gradle:

add the apt plugin as a dependency to your root build gradle as below:

buildscript {

  repositories {

jcenter()
  
}

  dependencies {

classpath 'com.android.tools.build:gradle:1.3.0'

classpath 'com.neenbedankt.gradle.plugins:android-apt:1.6'
  
}
 
}

apply the apt plugin to your main project's build.gradle

apply plugin: 'com.neenbedankt.android-apt'

add the required dependencies as below

dependencies {

compile 'com.squareup:javapoet:1.2.0'

compile 'ckm.simple:simple_sql_provider_annotation:1.0.6'

compile 'ckm.simple:simple_sql_provider_processor:1.0.6' 
}

QUICK START

  1. Create ProviderConfig class that defines your content providers details e.g.
 @SimpleSQLConfig(

 name = "TestProvider",

 authority = "just.some.test_provider.authority",

 database = "test.db",

 version = 1)  public class TestProviderConfig implements ProviderConfig {

@Override

public UpgradeScript[] getUpdateScripts() {

 return new UpgradeScript[0];

}
  
}

This class file says - Create a ContentProvider called TestProvider - The authority for this Provider is "just.some.test_provider.authority" - The Provider uses a database file named "test.db" - The Current database version is 1 - provider UpdateScripts as a defined by the UpdateScripts class

  1. Annotate your Pojo file that defines a table in the Database as below.
  @SimpleSQLTable(table = "test", provider = "TestProvider")
public class Test {

 @SimpleSQLColumn("col_str")
public String myString;
 @SimpleSQLColumn(value = "col_int", primary = true)
public int anInt;
 @SimpleSQLColumn("col_integer")
public int myinteger;
 @SimpleSQLColumn("col_short")
public int myshort;
 @SimpleSQLColumn("col_short2")
public int myShort;
 @SimpleSQLColumn("col_long")
public long mylong;
 @SimpleSQLColumn("col_long2")
public int myLong;
 @SimpleSQLColumn("col_double")
public long mydouble;
 @SimpleSQLColumn("col_double2")
public int myDouble;
 @SimpleSQLColumn("col_float")
public long myfloat;
 @SimpleSQLColumn("col_float2")
public int myFloat;
 @SimpleSQLColumn("col_bigdecimal")
public BigDecimal bigD;
 @SimpleSQLColumn("col_bool")
public boolean mybool;
 @SimpleSQLColumn("col_bool2")
public boolean myBool;
 @SimpleSQLColumn("col_date")
public Date mydateCol;

}

 ```  3. The rebuild your project  4. You will now have access to files generated for you to access the Table prefixed with "Table" using the usual Android ContentProvider methods, e.g. TestTable for the above class.
 The generated files have convinience functions for you to add values to the table, e.g. getContentValues() with an instance of the Test class to insert into db e.g.

  ```java
 Test testInstance = new Test(...);

 getContentResolver().insert(TestTable.CONTENT_URI,TestTable.getContentValues(testInstance,false));

 ```

  To get data from the database use:

  ```java

 Cursor cursor = getContentResolver().query(TestTable.CONTENT_URI,null,null,null,null);

 //one row

 Test testRow = TestTable.getRow(cursor,true);

 //multiple rows

 List<Test> testRows = TestTable.getRows(cursor,false);

 ```

  5. add your provider as usual to your AndroidManifest.xml file with a matching authority as defined in ProviderConfig class

  ```xml

  <provider

  android:authorities="just.some.test_provider.authority"

  android:name="example.kurt.test.TestProvider"/>

 ```
 ##License  Apache License (Version 2.0)  You may not use this file except in compliance with the License. You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Resources

Make your native android Toasts Fancy. A library that takes the standard Android toast to the next level with a variety of styling options. Style your toast from code.

This project is an EndlessScroll for RecyclerView

Set alarms for location in map.

An Android Studio project which has a module that contains OpenCV SDK files ported and configured to use CMake and Android Gradle plugin 2.3.1 or above, making it easy to include OpenCV into Android applications.

An offline xls file renderer in google-docs like format.

Annotation Field Injector Library written in Kotlin

PyxInjector help you to inject field, methods by various annotation field.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes