Search in sources :

Example 1 with ContentResolver

use of android.content.ContentResolver in project Launcher3 by chislon.

the class UninstallShortcutReceiver method removeShortcut.

private static void removeShortcut(Context context, Intent data) {
    Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
    String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
    boolean duplicate = data.getBooleanExtra(Launcher.EXTRA_SHORTCUT_DUPLICATE, true);
    if (intent != null && name != null) {
        final ContentResolver cr = context.getContentResolver();
        Cursor c = cr.query(LauncherSettings.Favorites.CONTENT_URI, new String[] { LauncherSettings.Favorites._ID, LauncherSettings.Favorites.INTENT }, LauncherSettings.Favorites.TITLE + "=?", new String[] { name }, null);
        final int intentIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.INTENT);
        final int idIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites._ID);
        boolean changed = false;
        try {
            while (c.moveToNext()) {
                try {
                    if (intent.filterEquals(Intent.parseUri(c.getString(intentIndex), 0))) {
                        final long id = c.getLong(idIndex);
                        final Uri uri = LauncherSettings.Favorites.getContentUri(id, false);
                        cr.delete(uri, null, null);
                        changed = true;
                        if (!duplicate) {
                            break;
                        }
                    }
                } catch (URISyntaxException e) {
                // Ignore
                }
            }
        } finally {
            c.close();
        }
        if (changed) {
            cr.notifyChange(LauncherSettings.Favorites.CONTENT_URI, null);
            Toast.makeText(context, context.getString(R.string.shortcut_uninstalled, name), Toast.LENGTH_SHORT).show();
        }
    }
}
Also used : Intent(android.content.Intent) URISyntaxException(java.net.URISyntaxException) Cursor(android.database.Cursor) Uri(android.net.Uri) ContentResolver(android.content.ContentResolver)

Example 2 with ContentResolver

use of android.content.ContentResolver in project Launcher3 by chislon.

the class LauncherBackupHelper method backupWidgets.

/**
     * Write all the static widget resources we need to render placeholders
     * for a package that is not installed.
     *
     * @param in notes from last backup
     * @param data output stream for key/value pairs
     * @param out notes about this backup
     * @param keys keys to mark as clean in the notes for next backup
     * @throws IOException
     */
private void backupWidgets(Journal in, BackupDataOutput data, Journal out, ArrayList<Key> keys) throws IOException {
    // persist static widget info that hasn't been persisted yet
    final LauncherAppState appState = LauncherAppState.getInstanceNoCreate();
    if (appState == null) {
        // try again later
        dataChanged();
        if (DEBUG)
            Log.d(TAG, "Launcher is not initialized, delaying widget backup");
        return;
    }
    final ContentResolver cr = mContext.getContentResolver();
    final WidgetPreviewLoader previewLoader = new WidgetPreviewLoader(mContext);
    final PagedViewCellLayout widgetSpacingLayout = new PagedViewCellLayout(mContext);
    final IconCache iconCache = appState.getIconCache();
    final int dpi = mContext.getResources().getDisplayMetrics().densityDpi;
    final DeviceProfile profile = appState.getDynamicGrid().getDeviceProfile();
    if (DEBUG)
        Log.d(TAG, "cellWidthPx: " + profile.cellWidthPx);
    // read the old ID set
    Set<String> savedIds = getSavedIdsByType(Key.WIDGET, in);
    if (DEBUG)
        Log.d(TAG, "widgets savedIds.size()=" + savedIds.size());
    int startRows = out.rows;
    if (DEBUG)
        Log.d(TAG, "starting here: " + startRows);
    String where = Favorites.ITEM_TYPE + "=" + Favorites.ITEM_TYPE_APPWIDGET;
    Cursor cursor = cr.query(Favorites.CONTENT_URI, FAVORITE_PROJECTION, where, null, null);
    Set<String> currentIds = new HashSet<String>(cursor.getCount());
    try {
        cursor.moveToPosition(-1);
        while (cursor.moveToNext()) {
            final long id = cursor.getLong(ID_INDEX);
            final String providerName = cursor.getString(APPWIDGET_PROVIDER_INDEX);
            final int spanX = cursor.getInt(SPANX_INDEX);
            final int spanY = cursor.getInt(SPANY_INDEX);
            final ComponentName provider = ComponentName.unflattenFromString(providerName);
            Key key = null;
            String backupKey = null;
            if (provider != null) {
                key = getKey(Key.WIDGET, providerName);
                backupKey = keyToBackupKey(key);
                currentIds.add(backupKey);
            } else {
                Log.w(TAG, "empty intent on appwidget: " + id);
            }
            if (savedIds.contains(backupKey)) {
                if (DEBUG)
                    Log.d(TAG, "already saved widget " + backupKey);
                // remember that we already backed this up previously
                keys.add(key);
            } else if (backupKey != null) {
                if (DEBUG)
                    Log.d(TAG, "I can count this high: " + out.rows);
                if ((out.rows - startRows) < MAX_WIDGETS_PER_PASS) {
                    if (DEBUG)
                        Log.d(TAG, "saving widget " + backupKey);
                    previewLoader.setPreviewSize(spanX * profile.cellWidthPx, spanY * profile.cellHeightPx, widgetSpacingLayout);
                    byte[] blob = packWidget(dpi, previewLoader, iconCache, provider);
                    keys.add(key);
                    writeRowToBackup(key, blob, out, data);
                } else {
                    if (DEBUG)
                        Log.d(TAG, "scheduling another run for widget " + backupKey);
                    // too many widgets for this pass, request another.
                    dataChanged();
                }
            }
        }
    } finally {
        cursor.close();
    }
    if (DEBUG)
        Log.d(TAG, "widget currentIds.size()=" + currentIds.size());
    // these IDs must have been deleted
    savedIds.removeAll(currentIds);
    out.rows += removeDeletedKeysFromBackup(savedIds, data);
}
Also used : Cursor(android.database.Cursor) ContentResolver(android.content.ContentResolver) ComponentName(android.content.ComponentName) Key(com.android.launcher3.backup.BackupProtos.Key) HashSet(java.util.HashSet)

Example 3 with ContentResolver

use of android.content.ContentResolver in project cw-omnibus by commonsguy.

the class RowController method bindModel.

void bindModel(Cursor row) {
    title.setText(row.getString(row.getColumnIndex(MediaStore.Video.Media.TITLE)));
    int uriColumn = row.getColumnIndex(MediaStore.Video.Media.DATA);
    int mimeTypeColumn = row.getColumnIndex(MediaStore.Video.Media.MIME_TYPE);
    int videoId = row.getInt(row.getColumnIndex(MediaStore.Video.Media._ID));
    videoUri = row.getString(uriColumn);
    videoMimeType = row.getString(mimeTypeColumn);
    if (BuildConfig.BE_STUPID) {
        ContentResolver cr = thumbnail.getContext().getContentResolver();
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inSampleSize = 1;
        Bitmap thumb = MediaStore.Video.Thumbnails.getThumbnail(cr, videoId, MediaStore.Video.Thumbnails.MICRO_KIND, options);
        thumbnail.setImageBitmap(thumb);
    } else {
        Uri video = ContentUris.withAppendedId(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, videoId);
        Picasso.with(thumbnail.getContext()).load(video.toString()).fit().centerCrop().placeholder(R.drawable.ic_media_video_poster).into(thumbnail);
    }
}
Also used : Bitmap(android.graphics.Bitmap) BitmapFactory(android.graphics.BitmapFactory) Uri(android.net.Uri) ContentResolver(android.content.ContentResolver)

Example 4 with ContentResolver

use of android.content.ContentResolver in project android_frameworks_base by ParanoidAndroid.

the class ApplicationPackageManager method queryIntentActivityOptions.

@Override
public List<ResolveInfo> queryIntentActivityOptions(ComponentName caller, Intent[] specifics, Intent intent, int flags) {
    final ContentResolver resolver = mContext.getContentResolver();
    String[] specificTypes = null;
    if (specifics != null) {
        final int N = specifics.length;
        for (int i = 0; i < N; i++) {
            Intent sp = specifics[i];
            if (sp != null) {
                String t = sp.resolveTypeIfNeeded(resolver);
                if (t != null) {
                    if (specificTypes == null) {
                        specificTypes = new String[N];
                    }
                    specificTypes[i] = t;
                }
            }
        }
    }
    try {
        return mPM.queryIntentActivityOptions(caller, specifics, specificTypes, intent, intent.resolveTypeIfNeeded(resolver), flags, mContext.getUserId());
    } catch (RemoteException e) {
        throw new RuntimeException("Package manager has died", e);
    }
}
Also used : Intent(android.content.Intent) RemoteException(android.os.RemoteException) ContentResolver(android.content.ContentResolver)

Example 5 with ContentResolver

use of android.content.ContentResolver in project android_frameworks_base by ParanoidAndroid.

the class SearchRecentSuggestions method saveRecentQueryBlocking.

private void saveRecentQueryBlocking(String queryString, String line2) {
    ContentResolver cr = mContext.getContentResolver();
    long now = System.currentTimeMillis();
    // Use content resolver (not cursor) to insert/update this query
    try {
        ContentValues values = new ContentValues();
        values.put(SuggestionColumns.DISPLAY1, queryString);
        if (mTwoLineDisplay) {
            values.put(SuggestionColumns.DISPLAY2, line2);
        }
        values.put(SuggestionColumns.QUERY, queryString);
        values.put(SuggestionColumns.DATE, now);
        cr.insert(mSuggestionsUri, values);
    } catch (RuntimeException e) {
        Log.e(LOG_TAG, "saveRecentQuery", e);
    }
    // Shorten the list (if it has become too long)
    truncateHistory(cr, MAX_HISTORY_COUNT);
}
Also used : ContentValues(android.content.ContentValues) ContentResolver(android.content.ContentResolver)

Aggregations

ContentResolver (android.content.ContentResolver)1121 Uri (android.net.Uri)236 Cursor (android.database.Cursor)190 ContentValues (android.content.ContentValues)112 Intent (android.content.Intent)90 RemoteException (android.os.RemoteException)67 IOException (java.io.IOException)59 Context (android.content.Context)52 File (java.io.File)46 ArrayList (java.util.ArrayList)46 Resources (android.content.res.Resources)45 ComponentName (android.content.ComponentName)44 MediumTest (android.test.suitebuilder.annotation.MediumTest)37 PreferenceScreen (android.support.v7.preference.PreferenceScreen)33 Bitmap (android.graphics.Bitmap)31 ContentObserver (android.database.ContentObserver)28 FileNotFoundException (java.io.FileNotFoundException)28 PendingIntent (android.app.PendingIntent)25 MockContentResolver (android.test.mock.MockContentResolver)25 AssetFileDescriptor (android.content.res.AssetFileDescriptor)24