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]);
}
}
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));
}
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;
}
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;
}
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;
}
Aggregations