Search in sources :

Example 21 with Cursor

use of android.database.Cursor in project cw-omnibus by commonsguy.

the class QuestionsFragment method onListItemClick.

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    SimpleCursorAdapter adapter = (SimpleCursorAdapter) getListAdapter();
    Cursor row = (Cursor) adapter.getItem(position);
    int link = row.getColumnIndex(DatabaseHelper.LINK);
    ((Contract) getActivity()).onQuestionClicked(row.getString(link));
}
Also used : SimpleCursorAdapter(android.widget.SimpleCursorAdapter) Cursor(android.database.Cursor)

Example 22 with Cursor

use of android.database.Cursor in project cw-omnibus by commonsguy.

the class NewContactsAdapterBridge method buildPhonesAdapter.

SpinnerAdapter buildPhonesAdapter(Activity a) {
    String[] PROJECTION = new String[] { Contacts._ID, Contacts.DISPLAY_NAME, Phone.NUMBER };
    String[] ARGS = { String.valueOf(Phone.TYPE_MOBILE) };
    Cursor c = a.managedQuery(Phone.CONTENT_URI, PROJECTION, Phone.TYPE + "=?", ARGS, Contacts.DISPLAY_NAME);
    SimpleCursorAdapter adapter = new SimpleCursorAdapter(a, android.R.layout.simple_spinner_item, c, new String[] { Contacts.DISPLAY_NAME }, new int[] { android.R.id.text1 });
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    return (adapter);
}
Also used : SimpleCursorAdapter(android.widget.SimpleCursorAdapter) Cursor(android.database.Cursor)

Example 23 with Cursor

use of android.database.Cursor in project cw-omnibus by commonsguy.

the class OldContactsAdapterBridge method buildPhonesAdapter.

SpinnerAdapter buildPhonesAdapter(Activity a) {
    String[] PROJECTION = new String[] { Contacts.Phones._ID, Contacts.Phones.NAME, Contacts.Phones.NUMBER };
    String[] ARGS = { String.valueOf(Contacts.Phones.TYPE_MOBILE) };
    Cursor c = a.managedQuery(Contacts.Phones.CONTENT_URI, PROJECTION, Contacts.Phones.TYPE + "=?", ARGS, Contacts.Phones.NAME);
    SimpleCursorAdapter adapter = new SimpleCursorAdapter(a, android.R.layout.simple_spinner_item, c, new String[] { Contacts.Phones.NAME }, new int[] { android.R.id.text1 });
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    return (adapter);
}
Also used : SimpleCursorAdapter(android.widget.SimpleCursorAdapter) Cursor(android.database.Cursor)

Example 24 with Cursor

use of android.database.Cursor in project Launcher3 by chislon.

the class LauncherModel method getFolderById.

/**
     * Find a folder in the db, creating the FolderInfo if necessary, and adding it to folderList.
     */
FolderInfo getFolderById(Context context, HashMap<Long, FolderInfo> folderList, long id) {
    final ContentResolver cr = context.getContentResolver();
    Cursor c = cr.query(LauncherSettings.Favorites.CONTENT_URI, null, "_id=? and (itemType=? or itemType=?)", new String[] { String.valueOf(id), String.valueOf(LauncherSettings.Favorites.ITEM_TYPE_FOLDER) }, null);
    try {
        if (c.moveToFirst()) {
            final int itemTypeIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.ITEM_TYPE);
            final int titleIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.TITLE);
            final int containerIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.CONTAINER);
            final int screenIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.SCREEN);
            final int cellXIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.CELLX);
            final int cellYIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.CELLY);
            FolderInfo folderInfo = null;
            switch(c.getInt(itemTypeIndex)) {
                case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
                    folderInfo = findOrMakeFolder(folderList, id);
                    break;
            }
            folderInfo.title = c.getString(titleIndex);
            folderInfo.id = id;
            folderInfo.container = c.getInt(containerIndex);
            folderInfo.screenId = c.getInt(screenIndex);
            folderInfo.cellX = c.getInt(cellXIndex);
            folderInfo.cellY = c.getInt(cellYIndex);
            return folderInfo;
        }
    } finally {
        c.close();
    }
    return null;
}
Also used : Cursor(android.database.Cursor)

Example 25 with Cursor

use of android.database.Cursor 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)

Aggregations

Cursor (android.database.Cursor)3795 ArrayList (java.util.ArrayList)522 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)499 Uri (android.net.Uri)455 ContentValues (android.content.ContentValues)300 ContentResolver (android.content.ContentResolver)188 RemoteException (android.os.RemoteException)182 Test (org.junit.Test)172 File (java.io.File)164 IOException (java.io.IOException)156 MatrixCursor (android.database.MatrixCursor)154 Intent (android.content.Intent)119 MediumTest (android.test.suitebuilder.annotation.MediumTest)116 SQLException (android.database.SQLException)115 HashMap (java.util.HashMap)108 SQLiteCursor (android.database.sqlite.SQLiteCursor)88 SQLiteException (android.database.sqlite.SQLiteException)85 Query (android.app.DownloadManager.Query)76 MergeCursor (android.database.MergeCursor)75 LargeTest (android.test.suitebuilder.annotation.LargeTest)69