Search in sources :

Example 1 with FileProvider.getUriForFile

use of android.support.v4.content.FileProvider.getUriForFile in project android_packages_apps_Dialer by LineageOS.

the class CallComposerActivity method sendAndCall.

@Override
public void sendAndCall() {
    if (!sessionReady()) {
        sendAndCallReady = true;
        showLoadingUi();
        LogUtil.i("CallComposerActivity.onClick", "sendAndCall pressed, but the session isn't ready");
        Logger.get(this).logImpression(DialerImpression.Type.CALL_COMPOSER_ACTIVITY_SEND_AND_CALL_PRESSED_WHEN_SESSION_NOT_READY);
        return;
    }
    sendAndCall.setEnabled(false);
    CallComposerFragment fragment = (CallComposerFragment) adapter.instantiateItem(pager, currentIndex);
    MultimediaData.Builder builder = MultimediaData.builder();
    if (fragment instanceof MessageComposerFragment) {
        MessageComposerFragment messageComposerFragment = (MessageComposerFragment) fragment;
        builder.setText(messageComposerFragment.getMessage());
        placeRCSCall(builder);
    }
    if (fragment instanceof GalleryComposerFragment) {
        GalleryComposerFragment galleryComposerFragment = (GalleryComposerFragment) fragment;
        // If the current data is not a copy, make one.
        if (!galleryComposerFragment.selectedDataIsCopy()) {
            DialerExecutors.createUiTaskBuilder(getFragmentManager(), "copyAndResizeImageToSend", new CopyAndResizeImageWorker(this.getApplicationContext())).onSuccess(output -> {
                Uri shareableUri = FileProvider.getUriForFile(CallComposerActivity.this, Constants.get().getFileProviderAuthority(), output.first);
                builder.setImage(grantUriPermission(shareableUri), output.second);
                placeRCSCall(builder);
            }).onFailure(throwable -> {
                // TODO(b/34279096) - gracefully handle message failure
                LogUtil.e("CallComposerActivity.onCopyFailed", "copy Failed", throwable);
            }).build().executeParallel(galleryComposerFragment.getGalleryData().getFileUri());
        } else {
            Uri shareableUri = FileProvider.getUriForFile(this, Constants.get().getFileProviderAuthority(), new File(galleryComposerFragment.getGalleryData().getFilePath()));
            builder.setImage(grantUriPermission(shareableUri), galleryComposerFragment.getGalleryData().getMimeType());
            placeRCSCall(builder);
        }
    }
    if (fragment instanceof CameraComposerFragment) {
        CameraComposerFragment cameraComposerFragment = (CameraComposerFragment) fragment;
        cameraComposerFragment.getCameraUriWhenReady(uri -> {
            builder.setImage(grantUriPermission(uri), cameraComposerFragment.getMimeType());
            placeRCSCall(builder);
        });
    }
}
Also used : LinearLayout(android.widget.LinearLayout) Bundle(android.os.Bundle) ProgressBar(android.widget.ProgressBar) CallIntentBuilder(com.android.dialer.callintent.CallIntentBuilder) Uri(android.net.Uri) FrameLayout(android.widget.FrameLayout) ImageView(android.widget.ImageView) Animator(android.animation.Animator) CallInitiationType(com.android.dialer.callintent.CallInitiationType) EnrichedCallComponent(com.android.dialer.enrichedcall.EnrichedCallComponent) FileProvider(android.support.v4.content.FileProvider) VisibleForTesting(android.support.annotation.VisibleForTesting) Constants(com.android.dialer.constants.Constants) DialerToolbar(com.android.dialer.widget.DialerToolbar) OnPageChangeListener(android.support.v4.view.ViewPager.OnPageChangeListener) Handler(android.os.Handler) View(android.view.View) ArgbEvaluator(android.animation.ArgbEvaluator) Session(com.android.dialer.enrichedcall.Session) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) LockableViewPager(com.android.dialer.widget.LockableViewPager) ContactPhotoManager(com.android.contacts.common.ContactPhotoManager) DialerImpression(com.android.dialer.logging.DialerImpression) ContextCompat(android.support.v4.content.ContextCompat) ViewAnimationUtils(android.view.ViewAnimationUtils) CallComposerListener(com.android.dialer.callcomposer.CallComposerFragment.CallComposerListener) AppCompatActivity(android.support.v7.app.AppCompatActivity) ViewGroup(android.view.ViewGroup) TextView(android.widget.TextView) RelativeLayout(android.widget.RelativeLayout) TelecomUtil(com.android.dialer.telecom.TelecomUtil) AnimatorListener(android.animation.Animator.AnimatorListener) Assert(com.android.dialer.common.Assert) Context(android.content.Context) LogUtil(com.android.dialer.common.LogUtil) FastOutSlowInInterpolator(android.support.v4.view.animation.FastOutSlowInInterpolator) DialerExecutors(com.android.dialer.common.concurrent.DialerExecutors) Intent(android.content.Intent) MultimediaData(com.android.dialer.multimedia.MultimediaData) NonNull(android.support.annotation.NonNull) ViewUtil(com.android.dialer.util.ViewUtil) StateExtension(com.android.dialer.enrichedcall.extensions.StateExtension) ProtoParsers(com.android.dialer.protos.ProtoParsers) Toast(android.widget.Toast) State(com.android.dialer.enrichedcall.Session.State) DialerContact(com.android.dialer.dialercontact.DialerContact) AnimatorSet(android.animation.AnimatorSet) ConfigProviderBindings(com.android.dialer.configprovider.ConfigProviderBindings) Logger(com.android.dialer.logging.Logger) ThreadUtil(com.android.dialer.common.concurrent.ThreadUtil) QuickContactBadge(android.widget.QuickContactBadge) EnrichedCallManager(com.android.dialer.enrichedcall.EnrichedCallManager) TextUtils(android.text.TextUtils) File(java.io.File) Gravity(android.view.Gravity) SharedPreferences(android.content.SharedPreferences) Configuration(android.content.res.Configuration) Base64(android.util.Base64) DialerUtils(com.android.dialer.util.DialerUtils) UiUtil(com.android.dialer.common.UiUtil) ValueAnimator(android.animation.ValueAnimator) OnClickListener(android.view.View.OnClickListener) MultimediaData(com.android.dialer.multimedia.MultimediaData) Uri(android.net.Uri) File(java.io.File)

Example 2 with FileProvider.getUriForFile

use of android.support.v4.content.FileProvider.getUriForFile in project PainlessMusicPlayer by Doctoror.

the class MediaBrowserImpl method createMediaItemAlbum.

@NonNull
private MediaItem createMediaItemAlbum(@NonNull final Cursor c) {
    final MediaDescriptionCompat.Builder description = new MediaDescriptionCompat.Builder().setMediaId(MediaBrowserConstants.MEDIA_ID_PREFIX_ALBUM.concat(c.getString(AlbumsProvider.COLUMN_ID))).setTitle(c.getString(AlbumsProvider.COLUMN_ALBUM));
    final String art = c.getString(AlbumsProvider.COLUMN_ALBUM_ART);
    if (!TextUtils.isEmpty(art)) {
        final Uri uri = FileProvider.getUriForFile(mContext, mContext.getPackageName().concat(".provider.album_thumbs"), new File(art));
        for (final String p : mMediaBrowserCallerPackageNames) {
            mContext.grantUriPermission(p, uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
        }
        description.setIconUri(uri);
    }
    return new MediaItem(description.build(), MediaItem.FLAG_PLAYABLE);
}
Also used : MediaItem(android.support.v4.media.MediaBrowserCompat.MediaItem) Uri(android.net.Uri) File(java.io.File) MediaDescriptionCompat(android.support.v4.media.MediaDescriptionCompat) NonNull(android.support.annotation.NonNull)

Example 3 with FileProvider.getUriForFile

use of android.support.v4.content.FileProvider.getUriForFile in project cw-omnibus by commonsguy.

the class Downloader method raiseNotification.

private void raiseNotification(Intent inbound, File output, Exception e) {
    NotificationCompat.Builder b = new NotificationCompat.Builder(this);
    b.setAutoCancel(true).setDefaults(Notification.DEFAULT_ALL).setWhen(System.currentTimeMillis());
    if (e == null) {
        b.setContentTitle(getString(R.string.download_complete)).setContentText(getString(R.string.fun)).setSmallIcon(android.R.drawable.stat_sys_download_done).setTicker(getString(R.string.download_complete));
        Intent outbound = new Intent(Intent.ACTION_VIEW);
        Uri outputUri = FileProvider.getUriForFile(this, AUTHORITY, output);
        outbound.setDataAndType(outputUri, inbound.getType());
        outbound.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        PendingIntent pi = PendingIntent.getActivity(this, 0, outbound, PendingIntent.FLAG_UPDATE_CURRENT);
        b.setContentIntent(pi);
    } else {
        b.setContentTitle(getString(R.string.exception)).setContentText(e.getMessage()).setSmallIcon(android.R.drawable.stat_notify_error).setTicker(getString(R.string.exception));
    }
    NotificationManager mgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    mgr.notify(NOTIFY_ID, b.build());
}
Also used : NotificationManager(android.app.NotificationManager) NotificationCompat(android.support.v4.app.NotificationCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) Uri(android.net.Uri)

Example 4 with FileProvider.getUriForFile

use of android.support.v4.content.FileProvider.getUriForFile in project cw-omnibus by commonsguy.

the class Downloader method raiseNotification.

private void raiseNotification(String mimeType, File output, Exception e) {
    NotificationCompat.Builder b = new NotificationCompat.Builder(this);
    b.setAutoCancel(true).setDefaults(Notification.DEFAULT_ALL);
    if (e == null) {
        b.setContentTitle(getString(R.string.download_complete)).setContentText(getString(R.string.fun)).setSmallIcon(android.R.drawable.stat_sys_download_done).setTicker(getString(R.string.download_complete));
        Intent outbound = new Intent(Intent.ACTION_VIEW);
        Uri outputUri = FileProvider.getUriForFile(this, AUTHORITY, output);
        outbound.setDataAndType(outputUri, mimeType);
        outbound.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        PendingIntent pi = PendingIntent.getActivity(this, 0, outbound, PendingIntent.FLAG_UPDATE_CURRENT);
        b.setContentIntent(pi);
    } else {
        b.setContentTitle(getString(R.string.exception)).setContentText(e.getMessage()).setSmallIcon(android.R.drawable.stat_notify_error).setTicker(getString(R.string.exception));
    }
    NotificationManager mgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    mgr.notify(NOTIFY_ID, b.build());
}
Also used : NotificationManager(android.app.NotificationManager) NotificationCompat(android.support.v4.app.NotificationCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) Uri(android.net.Uri)

Example 5 with FileProvider.getUriForFile

use of android.support.v4.content.FileProvider.getUriForFile in project LeafPic by HoraApps.

the class StorageHelper method getMediaPath.

public static String getMediaPath(final Context context, final Uri uri) {
    // DocumentProvider
    if (DocumentsContract.isDocumentUri(context, uri)) {
        // ExternalStorageProvider
        if (isExternalStorageDocument(uri)) {
            final String docId = DocumentsContract.getDocumentId(uri);
            final String[] split = docId.split(":");
            final String type = split[0];
            if ("primary".equalsIgnoreCase(type)) {
                return Environment.getExternalStorageDirectory() + "/" + split[1];
            }
        // TODO handle non-primary volumes
        } else // DownloadsProvider
        if (isDownloadsDocument(uri)) {
            final String id = DocumentsContract.getDocumentId(uri);
            final Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
            return getDataColumn(context, contentUri, null, null);
        } else // MediaProvider
        if (isMediaDocument(uri)) {
            final String docId = DocumentsContract.getDocumentId(uri);
            final String[] split = docId.split(":");
            final String type = split[0];
            Uri contentUri = null;
            if ("image".equals(type)) {
                contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
            } else if ("video".equals(type)) {
                contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
            } else if ("audio".equals(type)) {
                contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
            }
            final String selection = "_id=?";
            final String[] selectionArgs = new String[] { split[1] };
            return getDataColumn(context, contentUri, selection, selectionArgs);
        }
    } else if ("downloads".equals(uri.getAuthority())) {
        // download for chrome-dev workaround
        String[] seg = uri.toString().split("/");
        final String id = seg[seg.length - 1];
        final Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
        return getDataColumn(context, contentUri, null, null);
    } else // MediaStore (and general)
    if ("content".equalsIgnoreCase(uri.getScheme())) {
        try {
            // easy way
            String a = getDataColumn(context, uri, null, null);
            if (a != null)
                return a;
        } catch (Exception ignored) {
        }
        // work around for general uri generated by FileProvider.getUriForFile()
        String[] split = uri.getPath().split("/");
        int z = -1, len = split.length;
        for (int i = 0; i < len; i++) {
            if (split[i].equals("external_files")) {
                z = i;
                break;
            }
        }
        if (z != -1) {
            StringBuilder partialPath = new StringBuilder();
            for (int i = z + 1; i < len; i++) partialPath.append(split[i]).append('/');
            String p = partialPath.toString();
            for (File file : StorageHelper.getStorageRoots(context)) {
                File f = new File(file, p);
                if (f.exists())
                    return f.getPath();
            }
        }
    } else // File
    if ("file".equalsIgnoreCase(uri.getScheme())) {
        return uri.getPath();
    }
    return null;
}
Also used : Uri(android.net.Uri) File(java.io.File) DocumentFile(android.support.v4.provider.DocumentFile) IOException(java.io.IOException)

Aggregations

Uri (android.net.Uri)6 Intent (android.content.Intent)4 File (java.io.File)4 NotificationManager (android.app.NotificationManager)2 PendingIntent (android.app.PendingIntent)2 Context (android.content.Context)2 NonNull (android.support.annotation.NonNull)2 NotificationCompat (android.support.v4.app.NotificationCompat)2 View (android.view.View)2 ImageView (android.widget.ImageView)2 LinearLayout (android.widget.LinearLayout)2 Animator (android.animation.Animator)1 AnimatorListener (android.animation.Animator.AnimatorListener)1 AnimatorSet (android.animation.AnimatorSet)1 ArgbEvaluator (android.animation.ArgbEvaluator)1 ValueAnimator (android.animation.ValueAnimator)1 SharedPreferences (android.content.SharedPreferences)1 Configuration (android.content.res.Configuration)1 Drawable (android.graphics.drawable.Drawable)1 Bundle (android.os.Bundle)1