Search in sources :

Example 1 with OnCloseListener

use of android.os.ParcelFileDescriptor.OnCloseListener in project platform_frameworks_base by android.

the class ExternalStorageProvider method openDocument.

@Override
public ParcelFileDescriptor openDocument(String documentId, String mode, CancellationSignal signal) throws FileNotFoundException {
    if (mArchiveHelper.isArchivedDocument(documentId)) {
        return mArchiveHelper.openDocument(documentId, mode, signal);
    }
    final File file = getFileForDocId(documentId);
    final File visibleFile = getFileForDocId(documentId, true);
    final int pfdMode = ParcelFileDescriptor.parseMode(mode);
    if (pfdMode == ParcelFileDescriptor.MODE_READ_ONLY || visibleFile == null) {
        return ParcelFileDescriptor.open(file, pfdMode);
    } else {
        try {
            // When finished writing, kick off media scanner
            return ParcelFileDescriptor.open(file, pfdMode, mHandler, new OnCloseListener() {

                @Override
                public void onClose(IOException e) {
                    final Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
                    intent.setData(Uri.fromFile(visibleFile));
                    getContext().sendBroadcast(intent);
                }
            });
        } catch (IOException e) {
            throw new FileNotFoundException("Failed to open for writing: " + e);
        }
    }
}
Also used : OnCloseListener(android.os.ParcelFileDescriptor.OnCloseListener) FileNotFoundException(java.io.FileNotFoundException) Intent(android.content.Intent) IOException(java.io.IOException) File(java.io.File) Point(android.graphics.Point)

Example 2 with OnCloseListener

use of android.os.ParcelFileDescriptor.OnCloseListener in project android_frameworks_base by ResurrectionRemix.

the class ExternalStorageProvider method openDocument.

@Override
public ParcelFileDescriptor openDocument(String documentId, String mode, CancellationSignal signal) throws FileNotFoundException {
    if (mArchiveHelper.isArchivedDocument(documentId)) {
        return mArchiveHelper.openDocument(documentId, mode, signal);
    }
    final File file = getFileForDocId(documentId);
    final File visibleFile = getFileForDocId(documentId, true);
    final int pfdMode = ParcelFileDescriptor.parseMode(mode);
    if (pfdMode == ParcelFileDescriptor.MODE_READ_ONLY || visibleFile == null) {
        return ParcelFileDescriptor.open(file, pfdMode);
    } else {
        try {
            // When finished writing, kick off media scanner
            return ParcelFileDescriptor.open(file, pfdMode, mHandler, new OnCloseListener() {

                @Override
                public void onClose(IOException e) {
                    final Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
                    intent.setData(Uri.fromFile(visibleFile));
                    getContext().sendBroadcast(intent);
                }
            });
        } catch (IOException e) {
            throw new FileNotFoundException("Failed to open for writing: " + e);
        }
    }
}
Also used : OnCloseListener(android.os.ParcelFileDescriptor.OnCloseListener) FileNotFoundException(java.io.FileNotFoundException) Intent(android.content.Intent) IOException(java.io.IOException) File(java.io.File) Point(android.graphics.Point)

Example 3 with OnCloseListener

use of android.os.ParcelFileDescriptor.OnCloseListener in project android_frameworks_base by crdroidandroid.

the class ExternalStorageProvider method openDocument.

@Override
public ParcelFileDescriptor openDocument(String documentId, String mode, CancellationSignal signal) throws FileNotFoundException {
    if (mArchiveHelper.isArchivedDocument(documentId)) {
        return mArchiveHelper.openDocument(documentId, mode, signal);
    }
    final File file = getFileForDocId(documentId);
    final File visibleFile = getFileForDocId(documentId, true);
    final int pfdMode = ParcelFileDescriptor.parseMode(mode);
    if (pfdMode == ParcelFileDescriptor.MODE_READ_ONLY || visibleFile == null) {
        return ParcelFileDescriptor.open(file, pfdMode);
    } else {
        try {
            // When finished writing, kick off media scanner
            return ParcelFileDescriptor.open(file, pfdMode, mHandler, new OnCloseListener() {

                @Override
                public void onClose(IOException e) {
                    final Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
                    intent.setData(Uri.fromFile(visibleFile));
                    getContext().sendBroadcast(intent);
                }
            });
        } catch (IOException e) {
            throw new FileNotFoundException("Failed to open for writing: " + e);
        }
    }
}
Also used : OnCloseListener(android.os.ParcelFileDescriptor.OnCloseListener) FileNotFoundException(java.io.FileNotFoundException) Intent(android.content.Intent) IOException(java.io.IOException) File(java.io.File) Point(android.graphics.Point)

Example 4 with OnCloseListener

use of android.os.ParcelFileDescriptor.OnCloseListener in project android_frameworks_base by AOSPA.

the class ExternalStorageProvider method openDocument.

@Override
public ParcelFileDescriptor openDocument(String documentId, String mode, CancellationSignal signal) throws FileNotFoundException {
    if (mArchiveHelper.isArchivedDocument(documentId)) {
        return mArchiveHelper.openDocument(documentId, mode, signal);
    }
    final File file = getFileForDocId(documentId);
    final File visibleFile = getFileForDocId(documentId, true);
    final int pfdMode = ParcelFileDescriptor.parseMode(mode);
    if (pfdMode == ParcelFileDescriptor.MODE_READ_ONLY || visibleFile == null) {
        return ParcelFileDescriptor.open(file, pfdMode);
    } else {
        try {
            // When finished writing, kick off media scanner
            return ParcelFileDescriptor.open(file, pfdMode, mHandler, new OnCloseListener() {

                @Override
                public void onClose(IOException e) {
                    final Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
                    intent.setData(Uri.fromFile(visibleFile));
                    getContext().sendBroadcast(intent);
                }
            });
        } catch (IOException e) {
            throw new FileNotFoundException("Failed to open for writing: " + e);
        }
    }
}
Also used : OnCloseListener(android.os.ParcelFileDescriptor.OnCloseListener) FileNotFoundException(java.io.FileNotFoundException) Intent(android.content.Intent) IOException(java.io.IOException) File(java.io.File) Point(android.graphics.Point)

Example 5 with OnCloseListener

use of android.os.ParcelFileDescriptor.OnCloseListener in project android_frameworks_base by DirtyUnicorns.

the class ExternalStorageProvider method openDocument.

@Override
public ParcelFileDescriptor openDocument(String documentId, String mode, CancellationSignal signal) throws FileNotFoundException {
    if (mArchiveHelper.isArchivedDocument(documentId)) {
        return mArchiveHelper.openDocument(documentId, mode, signal);
    }
    final File file = getFileForDocId(documentId);
    final File visibleFile = getFileForDocId(documentId, true);
    final int pfdMode = ParcelFileDescriptor.parseMode(mode);
    if (pfdMode == ParcelFileDescriptor.MODE_READ_ONLY || visibleFile == null) {
        return ParcelFileDescriptor.open(file, pfdMode);
    } else {
        try {
            // When finished writing, kick off media scanner
            return ParcelFileDescriptor.open(file, pfdMode, mHandler, new OnCloseListener() {

                @Override
                public void onClose(IOException e) {
                    final Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
                    intent.setData(Uri.fromFile(visibleFile));
                    getContext().sendBroadcast(intent);
                }
            });
        } catch (IOException e) {
            throw new FileNotFoundException("Failed to open for writing: " + e);
        }
    }
}
Also used : OnCloseListener(android.os.ParcelFileDescriptor.OnCloseListener) FileNotFoundException(java.io.FileNotFoundException) Intent(android.content.Intent) IOException(java.io.IOException) File(java.io.File) Point(android.graphics.Point)

Aggregations

Intent (android.content.Intent)5 Point (android.graphics.Point)5 OnCloseListener (android.os.ParcelFileDescriptor.OnCloseListener)5 File (java.io.File)5 FileNotFoundException (java.io.FileNotFoundException)5 IOException (java.io.IOException)5