Example usage for android.content ContentProviderClient release

List of usage examples for android.content ContentProviderClient release

Introduction

In this page you can find the example usage for android.content ContentProviderClient release.

Prototype

@Deprecated
public boolean release() 

Source Link

Usage

From source file:org.totschnig.myexpenses.provider.DbUtils.java

public static Result backup(File backupDir) {
    cacheEventData();//from   w w w  . j  a v  a 2 s .  c o m
    ContentResolver resolver = MyApplication.getInstance().getContentResolver();
    ContentProviderClient client = resolver.acquireContentProviderClient(TransactionProvider.AUTHORITY);
    TransactionProvider provider = (TransactionProvider) client.getLocalContentProvider();
    Result result = provider.backup(backupDir);
    client.release();
    return result;
}

From source file:can.yrt.onebusaway.backup.Backup.java

/**
 * Performs a restore from the SD card.//from w ww.j av  a2  s  .co m
 *
 * @param context
 */
public static void restore(Context context) throws IOException {
    File dbPath = getDB(context);
    File backupPath = getBackup(context);

    // At least here we can decide that the database is closed.
    ContentProviderClient client = null;
    try {
        client = context.getContentResolver().acquireContentProviderClient(ObaContract.AUTHORITY);
        ObaProvider provider = (ObaProvider) client.getLocalContentProvider();
        provider.closeDB();

        FileUtils.copyFile(backupPath, dbPath);

    } finally {
        if (client != null) {
            client.release();
        }
    }
}

From source file:org.totschnig.myexpenses.provider.DbUtils.java

public static boolean restore(File backupFile) {
    boolean result = false;
    MyApplication app = MyApplication.getInstance();
    try {//from  w  w  w  .j  av a2  s.co  m
        DailyAutoBackupScheduler.cancelAutoBackup(app);
        PlanExecutor.cancelPlans(app);
        Account.clear();
        PaymentMethod.clear();

        if (backupFile.exists()) {
            ContentResolver resolver = app.getContentResolver();
            ContentProviderClient client = resolver.acquireContentProviderClient(TransactionProvider.AUTHORITY);
            TransactionProvider provider = (TransactionProvider) client.getLocalContentProvider();
            result = provider.restore(backupFile);
            client.release();
        }
    } catch (Exception e) {
        AcraHelper.report(e);
    }
    app.initPlanner();
    DailyAutoBackupScheduler.updateAutoBackupAlarms(app);
    return result;
}

From source file:com.marvin.rocklock.PlaylistUtils.java

/**
 * Writes to a playlist given a list of new song IDs and the playlist name
 *
 * @param context the activity calling this method
 * @param playlistName the playlist name
 * @param ids the song IDs to add// w  w  w.j a v  a 2  s  . co  m
 */
public static void writePlaylist(RockLockActivity context, String playlistName, ArrayList<String> ids) {

    ContentResolver resolver = context.getContentResolver();
    int playlistId = getPlaylistId(context, playlistName);

    Uri uri;
    int playOrder = 1;
    if (playlistId == -1) {
        // Case: new playlist
        ContentValues values = new ContentValues(1);
        values.put(MediaStore.Audio.Playlists.NAME, playlistName);
        // this might be missing a members extension...
        uri = resolver.insert(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, values);
    } else {
        // Case: exists playlist
        uri = MediaStore.Audio.Playlists.Members.getContentUri("external", playlistId);
        // Get most recent play order ID from playlist, so we can append
        Cursor orderCursor = resolver.query(uri, new String[] { MediaStore.Audio.Playlists.Members.PLAY_ORDER },
                null, null, MediaStore.Audio.Playlists.Members.PLAY_ORDER + " DESC ");

        if (orderCursor != null) {
            if (orderCursor.moveToFirst()) {
                playOrder = orderCursor.getInt(0) + 1;
            }
            orderCursor.close();
        }
    }

    Log.d("PLAYLIST ACTIVITY", String.format("Writing playlist %s", uri));

    // Add all the new tracks to the playlist.
    int size = ids.size();
    ContentValues values[] = new ContentValues[size];

    final ContentProviderClient provider = resolver.acquireContentProviderClient(uri);
    for (int i = 0; i < size; ++i) {
        values[i] = new ContentValues();
        values[i].put(MediaStore.Audio.Playlists.Members.AUDIO_ID, ids.get(i));
        values[i].put(MediaStore.Audio.Playlists.Members.PLAY_ORDER, playOrder++);
        resolver.insert(uri, values[i]);
    }
    provider.release();
}

From source file:dev.drsoran.moloko.sync.SyncAdapter.java

public final static ModificationSet getModificationsFor(Context context, Uri... entityUris) {
    ModificationSet modifications = new ModificationSet();

    if (entityUris.length > 0) {
        final ContentProviderClient client = context.getContentResolver()
                .acquireContentProviderClient(Modifications.CONTENT_URI);

        if (client != null) {
            final List<Modification> mods = ModificationsProviderPart.getModifications(client, entityUris);
            client.release();

            if (mods != null) {
                modifications = new ModificationSet(mods);
            } else {
                MolokoApp.Log.e(TAG, LogUtils.GENERIC_DB_ERROR);
            }/*from  w  ww.  j a v  a 2 s.c  o  m*/
        } else {
            MolokoApp.Log.e(TAG, LogUtils.GENERIC_DB_ERROR);
        }
    }

    return modifications;
}

From source file:saschpe.birthdays.service.CalendarSyncService.java

/**
 * Updates the calendar color//from w w w  .  jav a 2s .co  m
 */
public static void updateCalendarColor(Context context) {
    int color = PreferencesHelper.getCalendarColor(context);
    ContentResolver cr = context.getContentResolver();
    Uri uri = ContentUris.withAppendedId(getCalendarUri(context, CalendarContract.Calendars.CONTENT_URI),
            getCalendar(context));

    Log.d(TAG, "Updating calendar " + uri.toString() + " color " + color);

    ContentProviderClient client = cr.acquireContentProviderClient(CalendarContract.AUTHORITY);

    ContentValues values = new ContentValues();
    values.put(CalendarContract.Calendars.CALENDAR_COLOR, color);
    try {
        client.update(uri, values, null, null);
    } catch (RemoteException e) {
        Log.e(TAG, "Failed to update calendar color!", e);
    }
    client.release();
}

From source file:dev.drsoran.moloko.loaders.AbstractLoader.java

@Override
public D loadInBackground() {
    D result = null;/*from www.jav  a2 s  . co  m*/

    final ContentProviderClient client = getContentProviderClient();

    if (client != null) {
        result = queryResultInBackground(client);

        client.release();

        if (result != null && respectContentChanges.get())
            registerContentObserver(observer);
    } else {
        LogUtils.logDBError(getContext(), getClass(), LogUtils.GENERIC_DB_ERROR);
    }

    return result;
}

From source file:fr.free.nrw.commons.contributions.ContributionDao.java

Cursor loadAllContributions() {
    ContentProviderClient db = clientProvider.get();
    try {/*from   w ww.  ja va2s.co  m*/
        return db.query(BASE_URI, ALL_FIELDS, "", null, CONTRIBUTION_SORT);
    } catch (RemoteException e) {
        return null;
    } finally {
        db.release();
    }
}

From source file:dev.drsoran.moloko.sync.SyncAdapter.java

private final Pair<Long, Long> getSyncTime() {
    Pair<Long, Long> result = null;

    final ContentProviderClient client = context.getContentResolver()
            .acquireContentProviderClient(Sync.CONTENT_URI);

    if (client != null) {
        result = SyncProviderPart.getLastInAndLastOut(client);

        client.release();

        if (result != null) {
            // SPECIAL CASE: We check the returned dates. In case the device clock
            // was adjusted, we may have stored a date that is way too far in the
            // future. This may break the incremental sync for a long time. In this case we do a
            // full sync and store the new date.
            if ((result.first != null && result.first > System.currentTimeMillis())
                    || (result.second != null && result.second > System.currentTimeMillis())) {
                result = new Pair<Long, Long>(null, null);
            }/*w  w  w . j a v a2 s .  c om*/
        } else {
            MolokoApp.Log.e(TAG, LogUtils.GENERIC_DB_ERROR);
        }
    }

    return result;
}

From source file:dev.drsoran.moloko.sync.SyncAdapter.java

private final void updateSyncTime() {
    final ContentProviderClient client = context.getContentResolver()
            .acquireContentProviderClient(Sync.CONTENT_URI);

    if (client != null) {
        final Long millis = Long.valueOf(System.currentTimeMillis());
        SyncProviderPart.updateSync(client, millis, millis);

        client.release();
    }/* w ww.j  a  v  a2 s. c  o m*/
}