use of android.net.Uri in project platform_frameworks_base by android.
the class TestDocumentsProvider method queryRoots.
@Override
public Cursor queryRoots(String[] projection) throws FileNotFoundException {
Log.d(TAG, "Someone asked for our roots!");
if (LAG)
lagUntilCanceled(null);
if (ROOTS_WEDGE)
wedgeUntilCanceled(null);
if (ROOTS_CRASH)
System.exit(12);
if (ROOTS_REFRESH) {
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
SystemClock.sleep(3000);
Log.d(TAG, "Notifying that something changed!!");
final Uri uri = DocumentsContract.buildRootsUri(mAuthority);
getContext().getContentResolver().notifyChange(uri, null, false);
return null;
}
}.execute();
}
final MatrixCursor result = new MatrixCursor(resolveRootProjection(projection));
final RowBuilder row = result.newRow();
row.add(Root.COLUMN_ROOT_ID, MY_ROOT_ID);
row.add(Root.COLUMN_FLAGS, Root.FLAG_SUPPORTS_RECENTS | Root.FLAG_SUPPORTS_CREATE);
row.add(Root.COLUMN_TITLE, "_Test title which is really long");
row.add(Root.COLUMN_SUMMARY, SystemClock.elapsedRealtime() + " summary which is also super long text");
row.add(Root.COLUMN_DOCUMENT_ID, MY_DOC_ID);
row.add(Root.COLUMN_AVAILABLE_BYTES, 1024);
return result;
}
use of android.net.Uri in project platform_frameworks_base by android.
the class NekoLand method shareCat.
private void shareCat(Cat cat) {
final File dir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), getString(R.string.directory_name));
if (!dir.exists() && !dir.mkdirs()) {
Log.e("NekoLand", "save: error: can't create Pictures directory");
return;
}
final File png = new File(dir, cat.getName().replaceAll("[/ #:]+", "_") + ".png");
Bitmap bitmap = cat.createBitmap(EXPORT_BITMAP_SIZE, EXPORT_BITMAP_SIZE);
if (bitmap != null) {
try {
OutputStream os = new FileOutputStream(png);
bitmap.compress(Bitmap.CompressFormat.PNG, 0, os);
os.close();
MediaScannerConnection.scanFile(this, new String[] { png.toString() }, new String[] { "image/png" }, null);
Uri uri = Uri.fromFile(png);
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_STREAM, uri);
intent.putExtra(Intent.EXTRA_SUBJECT, cat.getName());
intent.setType("image/png");
startActivity(Intent.createChooser(intent, null));
cat.logShare(this);
} catch (IOException e) {
Log.e("NekoLand", "save: error: " + e);
}
}
}
use of android.net.Uri in project platform_frameworks_base by android.
the class MoveJobTest method testMoveVirtualTypedFile.
public void testMoveVirtualTypedFile() throws Exception {
mDocs.createFolder(mSrcRoot, "hello");
Uri testFile = mDocs.createVirtualFile(mSrcRoot, "/hello/virtual.sth", "virtual/mime-type", FRUITY_BYTES, "application/pdf", "text/html");
createJob(newArrayList(testFile)).run();
mJobListener.waitForFinished();
// Should have failed, source not deleted. Moving by bytes for virtual files
// is not supported.
mDocs.assertChildCount(mDestRoot, 0);
mDocs.assertChildCount(mSrcRoot, 1);
}
use of android.net.Uri in project platform_frameworks_base by android.
the class AbstractCopyJobTest method runCopyFileWithReadErrorsTest.
public void runCopyFileWithReadErrorsTest() throws Exception {
Uri testFile = mDocs.createDocument(mSrcRoot, "text/plain", "test1.txt");
mDocs.writeDocument(testFile, HAM_BYTES);
String testId = DocumentsContract.getDocumentId(testFile);
mClient.call("simulateReadErrorsForFile", testId, null);
createJob(newArrayList(testFile)).run();
mJobListener.waitForFinished();
mJobListener.assertFailed();
mJobListener.assertFilesFailed(newArrayList("test1.txt"));
mDocs.assertChildCount(mDestRoot, 0);
}
use of android.net.Uri in project platform_frameworks_base by android.
the class AbstractCopyJobTest method runCopyVirtualNonTypedFileTest.
public void runCopyVirtualNonTypedFileTest() throws Exception {
Uri testFile = mDocs.createVirtualFile(mSrcRoot, "/virtual.sth", "virtual/mime-type", FRUITY_BYTES);
createJob(newArrayList(testFile)).run();
mJobListener.waitForFinished();
mJobListener.assertFailed();
mJobListener.assertFilesFailed(newArrayList("virtual.sth"));
mDocs.assertChildCount(mDestRoot, 0);
}
Aggregations