use of android.database.Cursor in project android_frameworks_base by ParanoidAndroid.
the class SearchView method onSuggestionsKey.
/**
* React to the user typing while in the suggestions list. First, check for
* action keys. If not handled, try refocusing regular characters into the
* EditText.
*/
private boolean onSuggestionsKey(View v, int keyCode, KeyEvent event) {
// guard against possible race conditions (late arrival after dismiss)
if (mSearchable == null) {
return false;
}
if (mSuggestionsAdapter == null) {
return false;
}
if (event.getAction() == KeyEvent.ACTION_DOWN && event.hasNoModifiers()) {
// "click")
if (keyCode == KeyEvent.KEYCODE_ENTER || keyCode == KeyEvent.KEYCODE_SEARCH || keyCode == KeyEvent.KEYCODE_TAB) {
int position = mQueryTextView.getListSelection();
return onItemClicked(position, KeyEvent.KEYCODE_UNKNOWN, null);
}
// user to the edit view
if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT || keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
// give "focus" to text editor, with cursor at the beginning if
// left key, at end if right key
// TODO: Reverse left/right for right-to-left languages, e.g.
// Arabic
int selPoint = (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) ? 0 : mQueryTextView.length();
mQueryTextView.setSelection(selPoint);
mQueryTextView.setListSelection(0);
mQueryTextView.clearListSelection();
mQueryTextView.ensureImeVisible(true);
return true;
}
// Next, check for an "up and out" move
if (keyCode == KeyEvent.KEYCODE_DPAD_UP && 0 == mQueryTextView.getListSelection()) {
// let ACTV complete the move
return false;
}
// Next, check for an "action key"
SearchableInfo.ActionKeyInfo actionKey = mSearchable.findActionKey(keyCode);
if ((actionKey != null) && ((actionKey.getSuggestActionMsg() != null) || (actionKey.getSuggestActionMsgColumn() != null))) {
// launch suggestion using action key column
int position = mQueryTextView.getListSelection();
if (position != ListView.INVALID_POSITION) {
Cursor c = mSuggestionsAdapter.getCursor();
if (c.moveToPosition(position)) {
final String actionMsg = getActionKeyMessage(c, actionKey);
if (actionMsg != null && (actionMsg.length() > 0)) {
return onItemClicked(position, keyCode, actionMsg);
}
}
}
}
}
return false;
}
use of android.database.Cursor in project android_frameworks_base by ParanoidAndroid.
the class SearchView method launchSuggestion.
/**
* Launches an intent based on a suggestion.
*
* @param position The index of the suggestion to create the intent from.
* @param actionKey The key code of the action key that was pressed,
* or {@link KeyEvent#KEYCODE_UNKNOWN} if none.
* @param actionMsg The message for the action key that was pressed,
* or <code>null</code> if none.
* @return true if a successful launch, false if could not (e.g. bad position).
*/
private boolean launchSuggestion(int position, int actionKey, String actionMsg) {
Cursor c = mSuggestionsAdapter.getCursor();
if ((c != null) && c.moveToPosition(position)) {
Intent intent = createIntentFromSuggestion(c, actionKey, actionMsg);
// launch the intent
launchIntent(intent);
return true;
}
return false;
}
use of android.database.Cursor in project android_frameworks_base by ParanoidAndroid.
the class DownloadManagerBaseTest method verifyAndCleanupSingleFileDownload.
/**
* Helper to verify a standard single-file download from the mock server, and clean up after
* verification
*
* Note that this also calls the Download manager's remove, which cleans up the file from cache.
*
* @param requestId The id of the download to remove
* @param fileData The data to verify the file contains
*/
protected void verifyAndCleanupSingleFileDownload(long requestId, byte[] fileData) throws Exception {
int fileSize = fileData.length;
ParcelFileDescriptor pfd = mDownloadManager.openDownloadedFile(requestId);
Cursor cursor = mDownloadManager.query(new Query().setFilterById(requestId));
try {
assertEquals(1, cursor.getCount());
assertTrue(cursor.moveToFirst());
verifyFileSize(pfd, fileSize);
verifyFileContents(pfd, fileData);
} finally {
pfd.close();
cursor.close();
mDownloadManager.remove(requestId);
}
}
use of android.database.Cursor in project android_frameworks_base by ParanoidAndroid.
the class DownloadManagerBaseTest method doWaitForDownloadsOrTimeout.
/**
* Helper to wait for all downloads to finish, or else a timeout to occur
*
* @param query The query to pass to the download manager
* @param poll The poll time to wait between checks
* @param timeoutMillis The max amount of time (in ms) to wait for the download(s) to complete
*/
protected void doWaitForDownloadsOrTimeout(Query query, long poll, long timeoutMillis) throws TimeoutException {
int currentWaitTime = 0;
while (true) {
query.setFilterByStatus(DownloadManager.STATUS_PENDING | DownloadManager.STATUS_PAUSED | DownloadManager.STATUS_RUNNING);
Cursor cursor = mDownloadManager.query(query);
try {
if (cursor.getCount() == 0) {
Log.i(LOG_TAG, "All downloads should be done...");
break;
}
currentWaitTime = timeoutWait(currentWaitTime, poll, timeoutMillis, "Timed out waiting for all downloads to finish");
} finally {
cursor.close();
}
}
}
use of android.database.Cursor in project android_frameworks_base by ParanoidAndroid.
the class DownloadManagerFunctionalTest method testDownloadToExternal_fileExists.
/**
* Tests trying to download to SD card when the file with same name already exists.
*/
@LargeTest
public void testDownloadToExternal_fileExists() throws Exception {
File existentFile = createFileOnSD(null, 1, DataType.TEXT, null);
byte[] blobData = generateData(DEFAULT_FILE_SIZE, DataType.TEXT);
// Prepare the mock server with a standard response
enqueueResponse(buildResponse(HTTP_OK, blobData));
try {
Uri uri = getServerUri(DEFAULT_FILENAME);
Request request = new Request(uri);
Uri localUri = Uri.fromFile(existentFile);
request.setDestinationUri(localUri);
long dlRequest = mDownloadManager.enqueue(request);
// wait for the download to complete
waitForDownloadOrTimeout(dlRequest);
Cursor cursor = getCursor(dlRequest);
try {
verifyInt(cursor, DownloadManager.COLUMN_STATUS, DownloadManager.STATUS_SUCCESSFUL);
} finally {
cursor.close();
}
} finally {
existentFile.delete();
}
}
Aggregations