com.activeandroid.Configuration Java Examples

The following examples show how to use com.activeandroid.Configuration. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DatabaseUtil.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
public static void loadSql(Context context, Uri uri) {
    try {
        final String databaseName = new Configuration.Builder(context).create().getDatabaseName();

        final File currentDB = context.getDatabasePath(databaseName);
        final File replacement = new File(uri.getPath());
        if (currentDB.canWrite()) {
            final FileInputStream srcStream = new FileInputStream(replacement);
            final FileChannel src = srcStream.getChannel();
            final FileOutputStream destStream = new FileOutputStream(currentDB);
            final FileChannel dst = destStream.getChannel();
            dst.transferFrom(src, 0, src.size());
            src.close();
            srcStream.close();
            dst.close();
            destStream.close();
        } else {
            throw new RuntimeException("Couldn't write to " + currentDB);
        }
    } catch (final Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example #2
Source File: Sensor.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
public static void InitDb(Context context) {//KS
    Configuration dbConfiguration = new Configuration.Builder(context).create();
    try {
        SQLiteDatabase db = Cache.openDatabase();
        if (db != null) {
            Log.d("wearSENSOR", "InitDb DB exists");
        }
        else {
            ActiveAndroid.initialize(dbConfiguration);
            Log.d("wearSENSOR", "InitDb DB does NOT exist. Call ActiveAndroid.initialize()");
        }
    } catch (Exception e) {
        ActiveAndroid.initialize(dbConfiguration);
        Log.d("wearSENSOR", "InitDb CATCH: DB does NOT exist. Call ActiveAndroid.initialize()");
    }
}
 
Example #3
Source File: Sensor.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
public static void InitDb(Context context) {//KS
    Configuration dbConfiguration = new Configuration.Builder(context).create();
    try {
        SQLiteDatabase db = Cache.openDatabase();
        if (db != null) {
            Log.d("wearSENSOR", "InitDb DB exists");
        }
        else {
            ActiveAndroid.initialize(dbConfiguration);
            Log.d("wearSENSOR", "InitDb DB does NOT exist. Call ActiveAndroid.initialize()");
        }
    } catch (Exception e) {
        ActiveAndroid.initialize(dbConfiguration);
        Log.d("wearSENSOR", "InitDb CATCH: DB does NOT exist. Call ActiveAndroid.initialize()");
    }
}
 
Example #4
Source File: MainApplication.java    From AndroidDatabaseLibraryComparison with MIT License 6 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();

    ActiveAndroid.initialize(new Configuration.Builder(this)
                                     .setDatabaseName("activeandroid")
                                     .setDatabaseVersion(1)
                                     .setModelClasses(SimpleAddressItem.class, AddressItem.class,
                                                      AddressBook.class, Contact.class).create());

    Ollie.with(this)
            .setName("ollie")
            .setVersion(1)
            .setLogLevel(Ollie.LogLevel.FULL)
            .init();

    FlowManager.init(this);

    Sprinkles.init(this, "sprinkles.db", 2);

    RealmConfiguration realmConfig = new RealmConfiguration.Builder(this).build();
    Realm.setDefaultConfiguration(realmConfig);

    mDatabase = getDatabase();
}
 
Example #5
Source File: ParserConfigurationTest.java    From clear-todolist with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Should try to use the legacy parser by default, which is be unable to handle the SQL script.
 */
public void testLegacyMigration() {

    try {
        Configuration configuration = new Configuration.Builder(getContext())
                .setDatabaseName("migration.db")
                .setDatabaseVersion(2)
                .create();

        DatabaseHelper helper = new DatabaseHelper(configuration);
        SQLiteDatabase db = helper.getWritableDatabase();
        helper.onUpgrade(db, 1, 2);

        fail("Should not be able to parse the SQL script.");

    } catch (SQLException e) {
        final String message = e.getMessage();

        assertNotNull(message);
        assertTrue(message.contains("syntax error"));
        assertTrue(message.contains("near \"MockMigration\""));
    }
}
 
Example #6
Source File: ParserConfigurationTest.java    From clear-todolist with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Should use the new parser if configured to do so.
 */
public void testDelimitedMigration() {
    Configuration configuration = new Configuration.Builder(getContext())
            .setSqlParser(Configuration.SQL_PARSER_DELIMITED)
            .setDatabaseName("migration.db")
            .setDatabaseVersion(2)
            .create();

    DatabaseHelper helper = new DatabaseHelper(configuration);
    SQLiteDatabase db = helper.getWritableDatabase();
    helper.onUpgrade(db, 1, 2);
}
 
Example #7
Source File: DatabaseUtil.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public static String saveSql(Context context) {
    try {

        final String databaseName = new Configuration.Builder(context).create().getDatabaseName();

        final String dir = getExternalDir();
        makeSureDirectoryExists(dir);

        final StringBuilder sb = new StringBuilder();
        sb.append(dir);
        sb.append("/export");
        sb.append(DateFormat.format("yyyyMMdd-kkmmss", System.currentTimeMillis()));
        sb.append(".sqlite");

        final String filename = sb.toString();
        final File sd = Environment.getExternalStorageDirectory();
        if (sd.canWrite()) {
            final File currentDB = context.getDatabasePath(databaseName);
            final File backupDB = new File(filename);
            if (currentDB.exists()) {
                final FileInputStream srcStream = new FileInputStream(currentDB);
                final FileChannel src = srcStream.getChannel();
                final FileOutputStream destStream = new FileOutputStream(backupDB);
                final FileChannel dst = destStream.getChannel();
                dst.transferFrom(src, 0, src.size());
                src.close();
                srcStream.close();
                dst.close();
                destStream.close();
            }
        }

        return filename;
    } catch (final Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example #8
Source File: PerfTestActiveAndroid.java    From android-database-performance with Apache License 2.0 5 votes vote down vote up
@Override
protected void onRunSetup() throws Exception {
    super.onRunSetup();

    // set up database
    Configuration dbConfiguration = new Configuration.Builder(getTargetContext())
            .setDatabaseName(DATABASE_NAME)
            .addModelClass(SimpleEntityNotNull.class)
            .create();
    ActiveAndroid.initialize(dbConfiguration);
}
 
Example #9
Source File: PerfTestActiveAndroid.java    From android-database-performance with Apache License 2.0 5 votes vote down vote up
@Override
protected void doIndexedStringEntityQueries() throws Exception {
    // set up database
    Configuration dbConfiguration = new Configuration.Builder(getTargetContext())
            .setDatabaseName(DATABASE_NAME)
            .addModelClass(IndexedStringEntity.class)
            .create();
    ActiveAndroid.initialize(dbConfiguration);
    log("Set up database.");

    for (int i = 0; i < RUNS; i++) {
        log("----Run " + (i + 1) + " of " + RUNS);
        indexedStringEntityQueriesRun(getBatchSize());
    }
}
 
Example #10
Source File: ConfigurationTest.java    From clear-todolist with GNU General Public License v3.0 5 votes vote down vote up
public void testCreateConfigurationWithMockModel() {
    Configuration conf = new Configuration.Builder(getContext())
            .addModelClass(ConfigurationTestModel.class)
            .create();
    List<Class<? extends Model>> modelClasses = conf.getModelClasses();
    assertEquals(1, modelClasses.size());
    assertTrue(conf.isValid());
}
 
Example #11
Source File: ConfigurationTest.java    From clear-todolist with GNU General Public License v3.0 5 votes vote down vote up
public void testDefaultValue() throws IOException, ClassNotFoundException {
    Configuration conf = new Configuration.Builder(getContext()).create();
    assertNotNull(conf.getContext());
    assertEquals(1024, conf.getCacheSize());
    assertEquals("Application.db", conf.getDatabaseName());
    assertEquals(1, conf.getDatabaseVersion());
    assertNull(conf.getModelClasses());
    assertFalse(conf.isValid());
    assertNull(conf.getTypeSerializers());
    assertEquals(Configuration.SQL_PARSER_LEGACY, conf.getSqlParser());
}
 
Example #12
Source File: CacheTest.java    From clear-todolist with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void setUp() {
    Configuration conf = new Configuration.Builder(getContext())
            .setDatabaseName("CacheTest")
            .addModelClasses(CacheTestModel.class, CacheTestModel2.class)
            .create();
    ActiveAndroid.initialize(conf, true);
}
 
Example #13
Source File: DatabaseContentProvider.java    From 10000sentences with Apache License 2.0 5 votes vote down vote up
@Override
protected Configuration getConfiguration() {
    Configuration.Builder builder = new Configuration.Builder(getContext());
    builder.addModelClass(info.puzz.a10000sentences.models.Language.class);
    builder.addModelClass(info.puzz.a10000sentences.models.Sentence.class);
    builder.addModelClass(info.puzz.a10000sentences.models.SentenceCollection.class);
    builder.addModelClass(info.puzz.a10000sentences.models.SentenceHistory.class);
    builder.addModelClass(info.puzz.a10000sentences.models.Annotation.class);
    builder.addModelClass(info.puzz.a10000sentences.models.WordAnnotation.class);
    return builder.create();
}
 
Example #14
Source File: Sensor.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public static void DeleteAndInitDb(Context context) {//KS
    Configuration dbConfiguration = new Configuration.Builder(context).create();
    try {
        ActiveAndroid.dispose();
        context.deleteDatabase("DexDrip.db");
        //ActiveAndroid.initialize(dbConfiguration);
        Log.d("wearSENSOR", "DeleteAndInitDb DexDrip.db deleted and initialized.");
    } catch (Exception e) {
        Log.e("wearSENSOR", "DeleteAndInitDb CATCH Error.");
    }
}
 
Example #15
Source File: Sensor.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public static void DeleteAndInitDb(Context context) {//KS
    Configuration dbConfiguration = new Configuration.Builder(context).create();
    try {
        ActiveAndroid.dispose();
        context.deleteDatabase("DexDrip.db");
        //ActiveAndroid.initialize(dbConfiguration);
        Log.d("wearSENSOR", "DeleteAndInitDb DexDrip.db deleted and initialized.");
    } catch (Exception e) {
        Log.e("wearSENSOR", "DeleteAndInitDb CATCH Error.");
    }
}
 
Example #16
Source File: MimiApplication.java    From mimi-reader with Apache License 2.0 4 votes vote down vote up
@SuppressLint("CheckResult")
@Override
public void onCreate() {
    super.onCreate();
    app = this;

    MimiUtil.getInstance().init(this);

    @SuppressWarnings("unchecked")
    Configuration.Builder configurationBuilder = new Configuration.Builder(this)
            .addModelClasses(
                    Board.class,
                    History.class,
                    UserPost.class,
                    HiddenThread.class,
                    PostOption.class,
                    Filter.class,
                    PostModel.class,
                    CatalogPostModel.class,
                    Archive.class,
                    ArchivedPost.class
            );

    ActiveAndroid.initialize(configurationBuilder.create());
    DatabaseUtils.createIfNeedColumn(ArchivedPost.class, ArchivedPost.THREAD_ID, DatabaseUtils.COLUMN_TYPE.LONG, false);
    DatabaseUtils.createIfNeedColumn(ArchivedPost.class, ArchivedPost.POST_ID, DatabaseUtils.COLUMN_TYPE.LONG, false);
    DatabaseUtils.createIfNeedColumn(ArchivedPost.class, ArchivedPost.BOARD_NAME, DatabaseUtils.COLUMN_TYPE.STRING, false);
    DatabaseUtils.createIfNeedColumn(ArchivedPost.class, ArchivedPost.ARCHIVE_DOMAIN, DatabaseUtils.COLUMN_TYPE.STRING, false);
    DatabaseUtils.createIfNeedColumn(ArchivedPost.class, ArchivedPost.ARCHIVE_NAME, DatabaseUtils.COLUMN_TYPE.STRING, false);
    DatabaseUtils.createIfNeedColumn(ArchivedPost.class, ArchivedPost.MEDIA_LINK, DatabaseUtils.COLUMN_TYPE.STRING, false);
    DatabaseUtils.createIfNeedColumn(ArchivedPost.class, ArchivedPost.THUMB_LINK, DatabaseUtils.COLUMN_TYPE.STRING, false);

    try {
        final File fullImageDir = new File(MimiUtil.getInstance().getCacheDir().getAbsolutePath(), "full_images/");
        MimiUtil.deleteRecursive(fullImageDir, false);
    } catch (Exception e) {
        e.printStackTrace();
    }

    final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
    final int notificationLevel = Integer.valueOf(preferences.getString(getString(R.string.background_notification_pref), "0"));
    final boolean defaultSet = preferences.getBoolean(getString(R.string.crappy_samsung_default_set), false);

    if (!defaultSet) {
        boolean useCrappyVideoPlayer = MimiUtil.isCrappySamsung();
        preferences.edit()
                .putBoolean(getString(R.string.crappy_samsung_default_set), true)
                .putBoolean(getString(R.string.use_crappy_video_player), useCrappyVideoPlayer)
                .apply();
    }

    if (notificationLevel == 0) {
        preferences.edit().putString(getString(R.string.background_notification_pref), "3").apply();
    }

    final int historyPruneDays = Integer.valueOf(preferences.getString(getString(R.string.history_prune_time_pref), "0"));

    MimiUtil.pruneHistory(historyPruneDays)
            .flatMap((Function<Boolean, Single<Boolean>>) aBoolean -> HiddenThreadTableConnection.prune(5))
            .flatMap((Function<Boolean, Single<Boolean>>) aBoolean -> UserPostTableConnection.prune(7))
            .subscribe(aBoolean -> {
                if (aBoolean) {
                    Log.d(LOG_TAG, "Pruned history");
                } else {
                    Log.e(LOG_TAG, "Failed to prune history");
                }
            }, throwable -> Log.e(LOG_TAG, "Caught exception while setting up database", throwable));

    ThreadRegistry.getInstance().init();
    BusProvider.getInstance();
    RefreshScheduler.getInstance();

    SimpleChromeCustomTabs.initialize(this);
}
 
Example #17
Source File: ContentProvider.java    From clear-todolist with GNU General Public License v3.0 4 votes vote down vote up
protected Configuration getConfiguration() {
	return new Configuration.Builder(getContext()).create();
}
 
Example #18
Source File: ContentProvider.java    From mobile-android-survey-app with MIT License 4 votes vote down vote up
protected Configuration getConfiguration() {
	return new Configuration.Builder(getContext()).create();
}