Search in sources :

Example 6 with Cursor

use of android.database.Cursor in project coursera-android by aporter.

the class BrowserProvider method doSuggestQuery.

private Cursor doSuggestQuery(String selection, String[] selectionArgs, boolean bookmarksOnly) {
    String suggestSelection;
    String[] myArgs;
    if (selectionArgs[0] == null || selectionArgs[0].equals("")) {
        return new MySuggestionCursor(null, null, "");
    } else {
        String like = selectionArgs[0] + "%";
        if (selectionArgs[0].startsWith("http") || selectionArgs[0].startsWith("file")) {
            myArgs = new String[1];
            myArgs[0] = like;
            suggestSelection = selection;
        } else {
            SUGGEST_ARGS[0] = "http://" + like;
            SUGGEST_ARGS[1] = "http://www." + like;
            SUGGEST_ARGS[2] = "https://" + like;
            SUGGEST_ARGS[3] = "https://www." + like;
            // To match against titles.
            SUGGEST_ARGS[4] = like;
            myArgs = SUGGEST_ARGS;
            suggestSelection = SUGGEST_SELECTION;
        }
    }
    Cursor c = mOpenHelper.getReadableDatabase().query(TABLE_NAMES[URI_MATCH_BOOKMARKS], SUGGEST_PROJECTION, suggestSelection, myArgs, null, null, ORDER_BY, Integer.toString(mMaxSuggestionLongSize));
    if (bookmarksOnly || Patterns.WEB_URL.matcher(selectionArgs[0]).matches()) {
        return new MySuggestionCursor(c, null, "");
    } else {
        // get search suggestions if there is still space in the list
        if (myArgs != null && myArgs.length > 1 && c.getCount() < (MAX_SUGGEST_SHORT_SMALL - 1)) {
            SearchEngine searchEngine = mSettings.getSearchEngine();
            if (searchEngine != null && searchEngine.supportsSuggestions()) {
                Cursor sc = searchEngine.getSuggestions(getContext(), selectionArgs[0]);
                return new MySuggestionCursor(c, sc, selectionArgs[0]);
            }
        }
        return new MySuggestionCursor(c, null, selectionArgs[0]);
    }
}
Also used : SearchEngine(com.android.browser.search.SearchEngine) AbstractCursor(android.database.AbstractCursor) Cursor(android.database.Cursor)

Example 7 with Cursor

use of android.database.Cursor in project coursera-android by aporter.

the class CustomContactProviderDemo method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ContentResolver contentResolver = getContentResolver();
    ContentValues values = new ContentValues();
    // Insert first record
    values.put(DataContract.DATA, "Record1");
    Uri firstRecordUri = contentResolver.insert(DataContract.CONTENT_URI, values);
    values.clear();
    // Insert second record
    values.put(DataContract.DATA, "Record2");
    contentResolver.insert(DataContract.CONTENT_URI, values);
    values.clear();
    // Insert third record
    values.put(DataContract.DATA, "Record3");
    contentResolver.insert(DataContract.CONTENT_URI, values);
    // Delete first record
    contentResolver.delete(firstRecordUri, null, null);
    // Create and set cursor and list adapter
    Cursor c = contentResolver.query(DataContract.CONTENT_URI, null, null, null, null);
    setListAdapter(new SimpleCursorAdapter(this, R.layout.list_layout, c, DataContract.ALL_COLUMNS, new int[] { R.id.idString, R.id.data }, 0));
}
Also used : ContentValues(android.content.ContentValues) SimpleCursorAdapter(android.widget.SimpleCursorAdapter) Cursor(android.database.Cursor) Uri(android.net.Uri) ContentResolver(android.content.ContentResolver)

Example 8 with Cursor

use of android.database.Cursor in project coursera-android by aporter.

the class MediaPlaybackService method getCursorForId.

private Cursor getCursorForId(long lid) {
    String id = String.valueOf(lid);
    Cursor c = getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, mCursorCols, "_id=" + id, null, null);
    if (c != null) {
        c.moveToFirst();
    }
    return c;
}
Also used : Cursor(android.database.Cursor)

Example 9 with Cursor

use of android.database.Cursor in project ButterRemote-Android by se-bastiaan.

the class InstanceEditorDialogFragment method onCreateDialog.

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    View view = getActivity().getLayoutInflater().inflate(R.layout.fragment_instanceeditor, null, false);
    ButterKnife.bind(this, view);
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()).setView(view).setPositiveButton(R.string.save, new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int whichButton) {
        }
    }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    if (mIsNewInstance) {
        builder.setTitle(R.string.add_instance);
    } else {
        builder.setTitle(R.string.edit_instance);
    }
    final AlertDialog dialog = builder.create();
    dialog.setOnShowListener(new DialogInterface.OnShowListener() {

        @Override
        public void onShow(DialogInterface dialogInterface) {
            dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    mValidator.validateAsync();
                }
            });
            if (!mIsNewInstance) {
                Cursor cursor = getActivity().getContentResolver().query(Uri.withAppendedPath(InstanceProvider.INSTANCES_URI, "/" + mId), null, null, null, null);
                cursor.moveToFirst();
                ipInput.setText(cursor.getString(1));
                portInput.setText(cursor.getString(2));
                nameInput.setText(cursor.getString(3));
                usernameInput.setText(cursor.getString(4));
                passwordInput.setText(cursor.getString(5));
                cursor.close();
                ipInput.setVisibility(View.VISIBLE);
                portInput.setVisibility(View.VISIBLE);
                usernameInput.setVisibility(View.VISIBLE);
                passwordInput.setVisibility(View.VISIBLE);
                pairingLayout.setVisibility(View.GONE);
            }
        }
    });
    manualButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            ipInput.setVisibility(View.VISIBLE);
            portInput.setVisibility(View.VISIBLE);
            usernameInput.setVisibility(View.VISIBLE);
            passwordInput.setVisibility(View.VISIBLE);
            pairingLayout.setVisibility(View.GONE);
        }
    });
    PackageManager pm = getActivity().getPackageManager();
    if (pm.hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
        scanButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), PairingScannerActivity.class);
                startActivityForResult(intent, PairingScannerActivity.SCAN);
            }
        });
    } else {
        scanButton.setEnabled(false);
    }
    return dialog;
}
Also used : AlertDialog(android.app.AlertDialog) PairingScannerActivity(eu.se_bastiaan.popcorntimeremote.activities.PairingScannerActivity) DialogInterface(android.content.DialogInterface) Intent(android.content.Intent) Cursor(android.database.Cursor) View(android.view.View) PackageManager(android.content.pm.PackageManager)

Example 10 with Cursor

use of android.database.Cursor in project ADWLauncher2 by boombuler.

the class LauncherModel method shortcutExists.

/**
     * Returns true if the shortcuts already exists in the database.
     * we identify a shortcut by its title and intent.
     */
static boolean shortcutExists(Context context, String title, Intent intent) {
    final ContentResolver cr = context.getContentResolver();
    Cursor c = cr.query(LauncherSettings.Favorites.CONTENT_URI, new String[] { "title", "intent" }, "title=? and intent=?", new String[] { title, intent.toUri(0) }, null);
    boolean result = false;
    try {
        result = c.moveToFirst();
    } finally {
        c.close();
    }
    return result;
}
Also used : Cursor(android.database.Cursor) ContentResolver(android.content.ContentResolver)

Aggregations

Cursor (android.database.Cursor)4002 ArrayList (java.util.ArrayList)547 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)527 Uri (android.net.Uri)467 ContentValues (android.content.ContentValues)334 ContentResolver (android.content.ContentResolver)193 Test (org.junit.Test)183 RemoteException (android.os.RemoteException)182 File (java.io.File)170 IOException (java.io.IOException)159 MatrixCursor (android.database.MatrixCursor)154 Intent (android.content.Intent)140 SQLException (android.database.SQLException)126 MediumTest (android.test.suitebuilder.annotation.MediumTest)116 HashMap (java.util.HashMap)108 SQLiteException (android.database.sqlite.SQLiteException)94 SQLiteQueryBuilder (android.database.sqlite.SQLiteQueryBuilder)93 SQLiteCursor (android.database.sqlite.SQLiteCursor)88 Query (android.app.DownloadManager.Query)76 MergeCursor (android.database.MergeCursor)75