Search in sources :

Example 81 with Uri

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;
}
Also used : RowBuilder(android.database.MatrixCursor.RowBuilder) Uri(android.net.Uri) MatrixCursor(android.database.MatrixCursor)

Example 82 with Uri

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);
        }
    }
}
Also used : Bitmap(android.graphics.Bitmap) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) Intent(android.content.Intent) IOException(java.io.IOException) File(java.io.File) Uri(android.net.Uri)

Example 83 with Uri

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);
}
Also used : Uri(android.net.Uri)

Example 84 with Uri

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);
}
Also used : Uri(android.net.Uri)

Example 85 with Uri

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);
}
Also used : Uri(android.net.Uri)

Aggregations

Uri (android.net.Uri)3406 Intent (android.content.Intent)732 Cursor (android.database.Cursor)466 ContentValues (android.content.ContentValues)349 File (java.io.File)339 IOException (java.io.IOException)254 ContentResolver (android.content.ContentResolver)242 ArrayList (java.util.ArrayList)209 Test (org.junit.Test)194 RemoteException (android.os.RemoteException)190 Bundle (android.os.Bundle)154 Bitmap (android.graphics.Bitmap)129 Context (android.content.Context)118 InputStream (java.io.InputStream)110 PendingIntent (android.app.PendingIntent)104 LargeTest (android.test.suitebuilder.annotation.LargeTest)97 View (android.view.View)95 FileNotFoundException (java.io.FileNotFoundException)94 Request (android.app.DownloadManager.Request)83 TextView (android.widget.TextView)73