Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <provider android:name="NaTempsProvider"
- android:authorities="com.sdnsoft.natemps.natemps.data.NaTempsProvider.provider"
- android:exported="false"
- android:enabled="true">
- <grant-uri-permission android:pathPattern=".*" />
- </provider>
- public class NaTempsContract {
- public static final String AUTHORITY = "com.sdnsoft.natemps.natemps.data.NaTempsProvider.provider";// This class cannot be instantiated
- private NaTempsContract() {
- }
- public static final class app_role implements BaseColumns {
- // This class cannot be instantiated
- private app_role() {
- }
- /**
- * The table name offered by this provider
- */
- public static final String TABLE_NAME = "app_role";
- /*
- * URI definitions
- */
- /**
- * The scheme part for this provider's URI
- */
- private static final String SCHEME = "content://";
- /**
- * Path part for the app_role URI
- */
- private static final String PATH_APP_ROLE = "/app_role";
- /**
- * Path part for the app_role ID URI
- */
- private static final String PATH_APP_ROLE_ID = "/app_role/";
- /**
- * The content:// style URL for this table
- */
- public static final Uri CONTENT_URI = Uri.parse(SCHEME + AUTHORITY + PATH_APP_ROLE);
- /**
- * The default sort order for this table
- */
- public static final String DEFAULT_SORT_ORDER = "name DESC";
- /*
- * Column definitions
- */
- /**
- * <P>Type: INTEGER</P>
- */
- public static final String COLUMN_NAME_ID = "id";
- /**
- * <P>Type: TEXT</P>
- */
- public static final String COLUMN_NAME_NAME = "name";
- /**
- * <P>Type: TEXT</P>
- */
- public static final String COLUMN_NAME_DISPLAY_NAME = "display_name";
- }}
- public class NaTempsProvider
- extends ContentProvider implements ContentProvider.PipeDataWriter<Cursor> { // Used for debugging and loggingprivate static final String TAG = "NaTempsProvider";
- private static final int DATABASE_VERSION = 1;
- // Handle to a new DatabaseHelper.
- private DatabaseHelper mOpenHelper;
- static class DatabaseHelper extends SQLiteOpenHelper {
- DatabaseHelper(Context context) {
- // calls the super constructor, requesting the default cursor factory.
- super(context, DATABASE_NAME, null, DATABASE_VERSION);
- } // all type into database
- public static final String PRIMARY_KEY_TYPE = " INTEGER PRIMARY KEY AUTOINCREMENT ";
- // Structure de la table `app_role`
- public static final String APP_ROLE_TABLE_NAME = "app_role";
- public static final String APP_ROLE_PRIMARY_KEY = "id";
- public static final String APP_ROLE_NAME = "name";
- public static final String APP_ROLE_DISPLAY_NAME = "display_name";
- public static final String APP_ROLE_CREATE =
- "CREATE TABLE " + APP_ROLE_TABLE_NAME + " (" +
- APP_ROLE_PRIMARY_KEY + PRIMARY_KEY_TYPE + "," +
- APP_ROLE_NAME + " TEXT," +
- APP_ROLE_DISPLAY_NAME +
- " TEXT);INSERT INTO `app_role` (`id`, `name`, `display_name`) VALUESn" +
- "(1, 'accueil', 'Accueil'),n" +
- "(2, 'responsable_cercle', 'responsable de cercle');n";
- public static final String APP_ROLE_TABLE_DROP = "DROP TABLE IF EXISTS " + APP_ROLE_TABLE_NAME + ";";
- @Override
- public void onCreate(SQLiteDatabase db) {
- db.execSQL(
- APP_ROLE_CREATE
- );
- }
- @Override
- public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
- db.execSQL(
- APP_ROLE_TABLE_DROP
- );
- onCreate(db);
- }
- }
- @Override
- public boolean onCreate() {
- // Creates a new helper object. Note that the database itself isn't opened until
- // something tries to access it, and it's only created if it doesn't already exist.
- mOpenHelper = new DatabaseHelper(getContext());
- // Assumes that any failures will be reported by a thrown exception.
- return true;
- }
- ...}
- // If there is no data associated with the Intent, sets the data to the default URI, which
- // accesses a list of notes.
- if (intent.getData() == null) {
- intent.setData(NaTempsContract.app_role.CONTENT_URI);
- }
- /* Performs a managed query. The Activity handles closing and requerying the cursor
- * when needed.
- *
- * Please see the introductory note about performing provider operations on the UI thread.
- */
- Cursor cursor = managedQuery(
- getIntent().getData(), // Use the default content URI for the provider.
- NaTempsProjections.APP_ROLE_PROJECTION, // Return the note ID and title for each note.
- null, // No where clause, return all records.
- null, // No where clause, therefore no where column values.
- null // Use the default sort order.
- );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement