Search in sources :

Example 16 with Media

use of org.thoughtcrime.securesms.mediasend.Media in project Signal-Android by WhisperSystems.

the class ConversationParentFragment method initializeDraft.

// /// Initializers
private ListenableFuture<Boolean> initializeDraft(@NonNull ConversationIntents.Args args) {
    final SettableFuture<Boolean> result = new SettableFuture<>();
    final CharSequence draftText = args.getDraftText();
    final Uri draftMedia = requireActivity().getIntent().getData();
    final String draftContentType = requireActivity().getIntent().getType();
    final MediaType draftMediaType = MediaType.from(draftContentType);
    final List<Media> mediaList = args.getMedia();
    final StickerLocator stickerLocator = args.getStickerLocator();
    final boolean borderless = args.isBorderless();
    if (stickerLocator != null && draftMedia != null) {
        Log.d(TAG, "Handling shared sticker.");
        sendSticker(stickerLocator, Objects.requireNonNull(draftContentType), draftMedia, 0, true);
        return new SettableFuture<>(false);
    }
    if (draftMedia != null && draftContentType != null && borderless) {
        SimpleTask.run(getLifecycle(), () -> getKeyboardImageDetails(draftMedia), details -> sendKeyboardImage(draftMedia, draftContentType, details));
        return new SettableFuture<>(false);
    }
    if (!Util.isEmpty(mediaList)) {
        Log.d(TAG, "Handling shared Media.");
        Intent sendIntent = MediaSelectionActivity.editor(requireContext(), sendButton.getSelectedTransport(), mediaList, recipient.getId(), draftText);
        startActivityForResult(sendIntent, MEDIA_SENDER);
        return new SettableFuture<>(false);
    }
    if (draftText != null) {
        composeText.setText("");
        composeText.append(draftText);
        result.set(true);
    }
    if (draftMedia != null && draftMediaType != null) {
        Log.d(TAG, "Handling shared Data.");
        return setMedia(draftMedia, draftMediaType);
    }
    if (draftText == null && draftMedia == null && draftMediaType == null) {
        return initializeDraftFromDatabase();
    } else {
        updateToggleButtonState();
        result.set(false);
    }
    return result;
}
Also used : SettableFuture(org.thoughtcrime.securesms.util.concurrent.SettableFuture) Media(org.thoughtcrime.securesms.mediasend.Media) StickerLocator(org.thoughtcrime.securesms.stickers.StickerLocator) MediaType(org.thoughtcrime.securesms.mms.SlideFactory.MediaType) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) SpannableString(android.text.SpannableString) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Uri(android.net.Uri)

Example 17 with Media

use of org.thoughtcrime.securesms.mediasend.Media in project Signal-Android by WhisperSystems.

the class AddGroupDetailsFragment method showAvatarPicker.

private void showAvatarPicker() {
    Media media = viewModel.getAvatarMedia();
    SafeNavigation.safeNavigate(Navigation.findNavController(requireView()), AddGroupDetailsFragmentDirections.actionAddGroupDetailsFragmentToAvatarPicker(null, media).setIsNewGroup(true));
}
Also used : Media(org.thoughtcrime.securesms.mediasend.Media)

Example 18 with Media

use of org.thoughtcrime.securesms.mediasend.Media in project Signal-Android by signalapp.

the class AddGroupDetailsFragment method handleMediaResult.

private void handleMediaResult(Bundle data) {
    if (data.getBoolean(AvatarPickerFragment.SELECT_AVATAR_CLEAR)) {
        viewModel.setAvatarMedia(null);
        viewModel.setAvatar(null);
        return;
    }
    final Media result = data.getParcelable(AvatarPickerFragment.SELECT_AVATAR_MEDIA);
    final DecryptableStreamUriLoader.DecryptableUri decryptableUri = new DecryptableStreamUriLoader.DecryptableUri(result.getUri());
    viewModel.setAvatarMedia(result);
    GlideApp.with(this).asBitmap().load(decryptableUri).skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).centerCrop().override(AvatarHelper.AVATAR_DIMENSIONS, AvatarHelper.AVATAR_DIMENSIONS).into(new CustomTarget<Bitmap>() {

        @Override
        public void onResourceReady(@NonNull Bitmap resource, Transition<? super Bitmap> transition) {
            viewModel.setAvatar(Objects.requireNonNull(BitmapUtil.toByteArray(resource)));
        }

        @Override
        public void onLoadCleared(@Nullable Drawable placeholder) {
        }
    });
}
Also used : Bitmap(android.graphics.Bitmap) Media(org.thoughtcrime.securesms.mediasend.Media) Drawable(android.graphics.drawable.Drawable) InsetDrawable(android.graphics.drawable.InsetDrawable) DecryptableStreamUriLoader(org.thoughtcrime.securesms.mms.DecryptableStreamUriLoader)

Example 19 with Media

use of org.thoughtcrime.securesms.mediasend.Media in project Signal-Android by signalapp.

the class ShareRepository method getResolvedInternal.

@WorkerThread
@Nullable
private ShareData getResolvedInternal(@NonNull List<Uri> uris) throws IOException {
    Context context = ApplicationDependencies.getApplication();
    Map<Uri, String> mimeTypes = Stream.of(uris).map(uri -> new Pair<>(uri, getMimeType(context, uri, null))).filter(p -> MediaUtil.isImageType(p.second) || MediaUtil.isVideoType(p.second)).collect(Collectors.toMap(p -> p.first, p -> p.second));
    if (mimeTypes.isEmpty()) {
        return null;
    }
    List<Media> media = new ArrayList<>(mimeTypes.size());
    for (Map.Entry<Uri, String> entry : mimeTypes.entrySet()) {
        Uri uri = entry.getKey();
        String mimeType = entry.getValue();
        InputStream stream;
        try {
            stream = context.getContentResolver().openInputStream(uri);
            if (stream == null) {
                throw new IOException("Failed to open stream!");
            }
        } catch (IOException e) {
            Log.w(TAG, "Failed to open: " + uri);
            continue;
        }
        long size = getSize(context, uri);
        Pair<Integer, Integer> dimens = MediaUtil.getDimensions(context, mimeType, uri);
        long duration = getDuration(context, uri);
        Uri blobUri = BlobProvider.getInstance().forData(stream, size).withMimeType(mimeType).createForSingleSessionOnDisk(context);
        media.add(new Media(blobUri, mimeType, System.currentTimeMillis(), dimens.first, dimens.second, size, duration, false, false, Optional.of(Media.ALL_MEDIA_BUCKET_ID), Optional.absent(), Optional.absent()));
        if (media.size() >= MediaSendConstants.MAX_PUSH) {
            Log.w(TAG, "Exceeded the attachment limit! Skipping the rest.");
            break;
        }
    }
    if (media.size() > 0) {
        boolean isMmsSupported = Stream.of(media).allMatch(m -> isMmsSupported(context, asUriAttachment(m.getUri(), m.getMimeType(), m.getSize())));
        return ShareData.forMedia(media, isMmsSupported);
    } else {
        return null;
    }
}
Also used : Context(android.content.Context) MediaUtil(org.thoughtcrime.securesms.util.MediaUtil) Context(android.content.Context) Stream(com.annimon.stream.Stream) PackageManager(android.content.pm.PackageManager) Util(org.thoughtcrime.securesms.util.Util) NonNull(androidx.annotation.NonNull) Uri(android.net.Uri) Pair(android.util.Pair) WorkerThread(androidx.annotation.WorkerThread) UriAttachment(org.thoughtcrime.securesms.attachments.UriAttachment) ArrayList(java.util.ArrayList) Manifest(android.Manifest) TransportOption(org.thoughtcrime.securesms.TransportOption) Media(org.thoughtcrime.securesms.mediasend.Media) Map(java.util.Map) PartAuthority(org.thoughtcrime.securesms.mms.PartAuthority) ContextCompat(androidx.core.content.ContextCompat) UriUtil(org.thoughtcrime.securesms.util.UriUtil) Cursor(android.database.Cursor) SignalExecutors(org.signal.core.util.concurrent.SignalExecutors) Collectors(com.annimon.stream.Collectors) ApplicationDependencies(org.thoughtcrime.securesms.dependencies.ApplicationDependencies) BlobProvider(org.thoughtcrime.securesms.providers.BlobProvider) IOException(java.io.IOException) OpenableColumns(android.provider.OpenableColumns) Optional(org.whispersystems.libsignal.util.guava.Optional) Log(org.signal.core.util.logging.Log) List(java.util.List) Nullable(androidx.annotation.Nullable) TransportOptions(org.thoughtcrime.securesms.TransportOptions) MediaConstraints(org.thoughtcrime.securesms.mms.MediaConstraints) MediaSendConstants(org.thoughtcrime.securesms.mediasend.MediaSendConstants) Attachment(org.thoughtcrime.securesms.attachments.Attachment) InputStream(java.io.InputStream) InputStream(java.io.InputStream) Media(org.thoughtcrime.securesms.mediasend.Media) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Uri(android.net.Uri) Map(java.util.Map) WorkerThread(androidx.annotation.WorkerThread) Nullable(androidx.annotation.Nullable)

Example 20 with Media

use of org.thoughtcrime.securesms.mediasend.Media in project Signal-Android by signalapp.

the class AttachmentKeyboard method init.

private void init(@NonNull Context context) {
    inflate(context, R.layout.attachment_keyboard, this);
    this.container = findViewById(R.id.attachment_keyboard_container);
    this.mediaList = findViewById(R.id.attachment_keyboard_media_list);
    this.permissionText = findViewById(R.id.attachment_keyboard_permission_text);
    this.permissionButton = findViewById(R.id.attachment_keyboard_permission_button);
    RecyclerView buttonList = findViewById(R.id.attachment_keyboard_button_list);
    mediaAdapter = new AttachmentKeyboardMediaAdapter(GlideApp.with(this), media -> {
        if (callback != null) {
            callback.onAttachmentMediaClicked(media);
        }
    });
    buttonAdapter = new AttachmentKeyboardButtonAdapter(button -> {
        if (callback != null) {
            callback.onAttachmentSelectorClicked(button);
        }
    });
    mediaList.setAdapter(mediaAdapter);
    buttonList.setAdapter(buttonAdapter);
    mediaList.setLayoutManager(new GridLayoutManager(context, 1, GridLayoutManager.HORIZONTAL, false));
    buttonList.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false));
    buttonAdapter.setButtons(DEFAULT_BUTTONS);
}
Also used : Context(android.content.Context) Arrays(java.util.Arrays) GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) Stream(com.annimon.stream.Stream) NonNull(androidx.annotation.NonNull) FrameLayout(android.widget.FrameLayout) R(org.thoughtcrime.securesms.R) ViewGroup(android.view.ViewGroup) StorageUtil(org.thoughtcrime.securesms.util.StorageUtil) List(java.util.List) Nullable(androidx.annotation.Nullable) AttributeSet(android.util.AttributeSet) Media(org.thoughtcrime.securesms.mediasend.Media) View(android.view.View) InputAwareLayout(org.thoughtcrime.securesms.components.InputAwareLayout) Predicate(com.annimon.stream.function.Predicate) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) RecyclerView(androidx.recyclerview.widget.RecyclerView) GlideApp(org.thoughtcrime.securesms.mms.GlideApp) GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) RecyclerView(androidx.recyclerview.widget.RecyclerView) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager)

Aggregations

Media (org.thoughtcrime.securesms.mediasend.Media)22 Intent (android.content.Intent)8 PendingIntent (android.app.PendingIntent)6 Context (android.content.Context)6 Uri (android.net.Uri)6 View (android.view.View)6 NonNull (androidx.annotation.NonNull)6 Nullable (androidx.annotation.Nullable)6 Stream (com.annimon.stream.Stream)6 ArrayList (java.util.ArrayList)6 List (java.util.List)6 TransportOption (org.thoughtcrime.securesms.TransportOption)6 Manifest (android.Manifest)4 SuppressLint (android.annotation.SuppressLint)4 Bitmap (android.graphics.Bitmap)4 Drawable (android.graphics.drawable.Drawable)4 SpannableString (android.text.SpannableString)4 ImageView (android.widget.ImageView)4 TextView (android.widget.TextView)4 WorkerThread (androidx.annotation.WorkerThread)4