Search in sources :

Example 1 with Media

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

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 2 with Media

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

the class ShareActivity method openInterstitial.

private void openInterstitial(@NonNull Set<ShareContactAndThread> shareContactAndThreads, @Nullable ShareData shareData) {
    MultiShareArgs.Builder builder = new MultiShareArgs.Builder(shareContactAndThreads).withMedia(args.getExtraMedia()).withDraftText(args.getExtraText() != null ? args.getExtraText().toString() : null).withStickerLocator(args.getExtraSticker()).asBorderless(args.isBorderless());
    if (shareData != null && shareData.isForIntent()) {
        Log.i(TAG, "Shared data is a single file.");
        builder.withDataUri(shareData.getUri()).withDataType(shareData.getMimeType());
    } else if (shareData != null && shareData.isForMedia()) {
        Log.i(TAG, "Shared data is set of media.");
        builder.withMedia(shareData.getMedia());
    } else if (shareData != null && shareData.isForPrimitive()) {
        Log.i(TAG, "Shared data is a primitive type.");
    } else if (shareData == null && args.getExtraSticker() != null) {
        builder.withDataType(getIntent().getType());
    } else {
        Log.i(TAG, "Shared data was not external.");
    }
    MultiShareArgs multiShareArgs = builder.build();
    InterstitialContentType interstitialContentType = multiShareArgs.getInterstitialContentType();
    switch(interstitialContentType) {
        case TEXT:
            startActivityForResult(ShareInterstitialActivity.createIntent(this, multiShareArgs), RESULT_TEXT_CONFIRMATION);
            break;
        case MEDIA:
            List<Media> media = new ArrayList<>(multiShareArgs.getMedia());
            if (media.isEmpty()) {
                media.add(new Media(multiShareArgs.getDataUri(), multiShareArgs.getDataType(), 0, 0, 0, 0, 0, false, false, Optional.absent(), Optional.absent(), Optional.absent()));
            }
            Intent intent = MediaSelectionActivity.share(this, MultiShareSender.getWorstTransportOption(this, multiShareArgs.getShareContactAndThreads()), media, Stream.of(multiShareArgs.getShareContactAndThreads()).map(ShareContactAndThread::getRecipientId).toList(), multiShareArgs.getDraftText());
            startActivityForResult(intent, RESULT_MEDIA_CONFIRMATION);
            break;
        default:
            // noinspection CodeBlock2Expr
            MultiShareSender.send(multiShareArgs, results -> {
                MultiShareDialogs.displayResultDialog(this, results, () -> {
                    viewModel.onSuccessfulShare();
                    finish();
                });
            });
            break;
    }
}
Also used : Media(org.thoughtcrime.securesms.mediasend.Media) ArrayList(java.util.ArrayList) Intent(android.content.Intent)

Example 3 with Media

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

the class ConversationParentFragment method onActivityResult.

@Override
public void onActivityResult(final int reqCode, int resultCode, Intent data) {
    Log.i(TAG, "onActivityResult called: " + reqCode + ", " + resultCode + " , " + data);
    super.onActivityResult(reqCode, resultCode, data);
    if ((data == null && reqCode != TAKE_PHOTO && reqCode != SMS_DEFAULT) || (resultCode != Activity.RESULT_OK && reqCode != SMS_DEFAULT)) {
        updateLinkPreviewState();
        SignalStore.settings().setDefaultSms(Util.isDefaultSmsProvider(requireContext()));
        return;
    }
    switch(reqCode) {
        case PICK_DOCUMENT:
            setMedia(data.getData(), MediaType.DOCUMENT);
            break;
        case PICK_AUDIO:
            setMedia(data.getData(), MediaType.AUDIO);
            break;
        case PICK_CONTACT:
            if (isSecureText && !isSmsForced()) {
                openContactShareEditor(data.getData());
            } else {
                addAttachmentContactInfo(data.getData());
            }
            break;
        case GET_CONTACT_DETAILS:
            sendSharedContact(data.getParcelableArrayListExtra(ContactShareEditActivity.KEY_CONTACTS));
            break;
        case GROUP_EDIT:
            Recipient recipientSnapshot = recipient.get();
            onRecipientChanged(recipientSnapshot);
            titleView.setTitle(glideRequests, recipientSnapshot);
            NotificationChannels.updateContactChannelName(requireContext(), recipientSnapshot);
            setBlockedUserState(recipientSnapshot, isSecureText, isDefaultSms);
            invalidateOptionsMenu();
            break;
        case TAKE_PHOTO:
            handleImageFromDeviceCameraApp();
            break;
        case ADD_CONTACT:
            SimpleTask.run(() -> {
                try {
                    DirectoryHelper.refreshDirectoryFor(requireContext(), recipient.get(), false);
                } catch (IOException e) {
                    Log.w(TAG, "Failed to refresh user after adding to contacts.");
                }
                return null;
            }, nothing -> onRecipientChanged(recipient.get()));
            break;
        case PICK_LOCATION:
            SignalPlace place = new SignalPlace(PlacePickerActivity.addressFromData(data));
            attachmentManager.setLocation(place, getCurrentMediaConstraints());
            break;
        case PICK_GIF:
            onGifSelectSuccess(data.getData(), data.getIntExtra(GiphyActivity.EXTRA_WIDTH, 0), data.getIntExtra(GiphyActivity.EXTRA_HEIGHT, 0));
            break;
        case SMS_DEFAULT:
            initializeSecurity(isSecureText, isDefaultSms);
            break;
        case MEDIA_SENDER:
            MediaSendActivityResult result = MediaSendActivityResult.fromData(data);
            if (!Objects.equals(result.getRecipientId(), recipient.getId())) {
                Log.w(TAG, "Result's recipientId did not match ours! Result: " + result.getRecipientId() + ", Activity: " + recipient.getId());
                Toast.makeText(requireContext(), R.string.ConversationActivity_error_sending_media, Toast.LENGTH_SHORT).show();
                return;
            }
            sendButton.setTransport(result.getTransport());
            if (result.isPushPreUpload()) {
                sendMediaMessage(result);
                return;
            }
            long expiresIn = TimeUnit.SECONDS.toMillis(recipient.get().getExpiresInSeconds());
            int subscriptionId = sendButton.getSelectedTransport().getSimSubscriptionId().or(-1);
            boolean initiating = threadId == -1;
            QuoteModel quote = result.isViewOnce() ? null : inputPanel.getQuote().orNull();
            SlideDeck slideDeck = new SlideDeck();
            List<Mention> mentions = new ArrayList<>(result.getMentions());
            for (Media mediaItem : result.getNonUploadedMedia()) {
                if (MediaUtil.isVideoType(mediaItem.getMimeType())) {
                    slideDeck.addSlide(new VideoSlide(requireContext(), mediaItem.getUri(), mediaItem.getSize(), mediaItem.isVideoGif(), mediaItem.getWidth(), mediaItem.getHeight(), mediaItem.getCaption().orNull(), mediaItem.getTransformProperties().orNull()));
                } else if (MediaUtil.isGif(mediaItem.getMimeType())) {
                    slideDeck.addSlide(new GifSlide(requireContext(), mediaItem.getUri(), mediaItem.getSize(), mediaItem.getWidth(), mediaItem.getHeight(), mediaItem.isBorderless(), mediaItem.getCaption().orNull()));
                } else if (MediaUtil.isImageType(mediaItem.getMimeType())) {
                    slideDeck.addSlide(new ImageSlide(requireContext(), mediaItem.getUri(), mediaItem.getMimeType(), mediaItem.getSize(), mediaItem.getWidth(), mediaItem.getHeight(), mediaItem.isBorderless(), mediaItem.getCaption().orNull(), null, mediaItem.getTransformProperties().orNull()));
                } else {
                    Log.w(TAG, "Asked to send an unexpected mimeType: '" + mediaItem.getMimeType() + "'. Skipping.");
                }
            }
            final Context context = requireContext().getApplicationContext();
            sendMediaMessage(result.getRecipientId(), result.getTransport().isSms(), result.getBody(), slideDeck, quote, Collections.emptyList(), Collections.emptyList(), mentions, expiresIn, result.isViewOnce(), subscriptionId, initiating, true, null).addListener(new AssertedSuccessListener<Void>() {

                @Override
                public void onSuccess(Void result) {
                    AsyncTask.THREAD_POOL_EXECUTOR.execute(() -> {
                        Stream.of(slideDeck.getSlides()).map(Slide::getUri).withoutNulls().filter(BlobProvider::isAuthority).forEach(uri -> BlobProvider.getInstance().delete(context, uri));
                    });
                }
            });
            break;
    }
}
Also used : VideoSlide(org.thoughtcrime.securesms.mms.VideoSlide) Context(android.content.Context) Bundle(android.os.Bundle) BubbleOptOutReminder(org.thoughtcrime.securesms.components.reminder.BubbleOptOutReminder) LinkPreview(org.thoughtcrime.securesms.linkpreview.LinkPreview) NonNull(androidx.annotation.NonNull) ContextUtil(org.thoughtcrime.securesms.util.ContextUtil) OnBackPressedCallback(androidx.activity.OnBackPressedCallback) Media(org.thoughtcrime.securesms.mediasend.Media) EmojiEventListener(org.thoughtcrime.securesms.components.emoji.EmojiEventListener) ContextCompat(androidx.core.content.ContextCompat) OutgoingTextMessage(org.thoughtcrime.securesms.sms.OutgoingTextMessage) ConversationMessageFactory(org.thoughtcrime.securesms.conversation.ConversationMessage.ConversationMessageFactory) DecryptableStreamUriLoader(org.thoughtcrime.securesms.mms.DecryptableStreamUriLoader) EmojiStrings(org.thoughtcrime.securesms.components.emoji.EmojiStrings) ApplicationDependencies(org.thoughtcrime.securesms.dependencies.ApplicationDependencies) IntentFilter(android.content.IntentFilter) CanNotSendPaymentDialog(org.thoughtcrime.securesms.payments.CanNotSendPaymentDialog) StickerSearchDialogFragment(org.thoughtcrime.securesms.keyboard.sticker.StickerSearchDialogFragment) SearchView(androidx.appcompat.widget.SearchView) AnimatingToggle(org.thoughtcrime.securesms.components.AnimatingToggle) GroupDatabase(org.thoughtcrime.securesms.database.GroupDatabase) ThreadDatabase(org.thoughtcrime.securesms.database.ThreadDatabase) ChatWallpaper(org.thoughtcrime.securesms.wallpaper.ChatWallpaper) GroupChangeFailureReason(org.thoughtcrime.securesms.groups.ui.GroupChangeFailureReason) ServiceOutageReminder(org.thoughtcrime.securesms.components.reminder.ServiceOutageReminder) OutgoingMediaMessage(org.thoughtcrime.securesms.mms.OutgoingMediaMessage) MediaUtil(org.thoughtcrime.securesms.util.MediaUtil) QuoteId(org.thoughtcrime.securesms.mms.QuoteId) Types(org.thoughtcrime.securesms.database.MmsSmsColumns.Types) SignalDatabase(org.thoughtcrime.securesms.database.SignalDatabase) Stream(com.annimon.stream.Stream) MediaKeyboardMode(org.thoughtcrime.securesms.util.TextSecurePreferences.MediaKeyboardMode) MainActivity(org.thoughtcrime.securesms.MainActivity) GroupRecord(org.thoughtcrime.securesms.database.GroupDatabase.GroupRecord) DrawableCompat(androidx.core.graphics.drawable.DrawableCompat) RetrieveProfileJob(org.thoughtcrime.securesms.jobs.RetrieveProfileJob) ReviewBannerView(org.thoughtcrime.securesms.profiles.spoofing.ReviewBannerView) ReminderView(org.thoughtcrime.securesms.components.reminder.ReminderView) MessageRequestState(org.thoughtcrime.securesms.messagerequests.MessageRequestState) SpannableStringBuilder(android.text.SpannableStringBuilder) MenuInflater(android.view.MenuInflater) Toast(android.widget.Toast) Menu(android.view.Menu) UnverifiedBannerView(org.thoughtcrime.securesms.components.identity.UnverifiedBannerView) Type(org.thoughtcrime.securesms.TransportOption.Type) Settings(android.provider.Settings) OutgoingEncryptedMessage(org.thoughtcrime.securesms.sms.OutgoingEncryptedMessage) SignalSessionLock(org.whispersystems.signalservice.api.SignalSessionLock) ListenableFuture(org.thoughtcrime.securesms.util.concurrent.ListenableFuture) LiveRecipient(org.thoughtcrime.securesms.recipients.LiveRecipient) CustomTarget(com.bumptech.glide.request.target.CustomTarget) MessageId(org.thoughtcrime.securesms.database.model.MessageId) StickerSearchRepository(org.thoughtcrime.securesms.stickers.StickerSearchRepository) Collectors(com.annimon.stream.Collectors) DraftRepository(org.thoughtcrime.securesms.conversation.drafts.DraftRepository) UpdatedBodyAndMentions(org.thoughtcrime.securesms.database.MentionUtil.UpdatedBodyAndMentions) SafetyNumberChangeDialog(org.thoughtcrime.securesms.conversation.ui.error.SafetyNumberChangeDialog) IOException(java.io.IOException) GroupCallPeekEvent(org.thoughtcrime.securesms.events.GroupCallPeekEvent) ConversationUtil(org.thoughtcrime.securesms.util.ConversationUtil) VoiceNoteDraft(org.thoughtcrime.securesms.components.voice.VoiceNoteDraft) ManagePendingAndRequestingMembersActivity(org.thoughtcrime.securesms.groups.ui.invitesandrequests.ManagePendingAndRequestingMembersActivity) InviteReminderRepository(org.thoughtcrime.securesms.invites.InviteReminderRepository) Optional(org.whispersystems.libsignal.util.guava.Optional) ExecutionException(java.util.concurrent.ExecutionException) Reminder(org.thoughtcrime.securesms.components.reminder.Reminder) IconCompat(androidx.core.graphics.drawable.IconCompat) StickerLocator(org.thoughtcrime.securesms.stickers.StickerLocator) Drafts(org.thoughtcrime.securesms.database.DraftDatabase.Drafts) Camera(android.hardware.Camera) ImageButton(android.widget.ImageButton) ReentrantSessionLock(org.thoughtcrime.securesms.crypto.ReentrantSessionLock) StickerKeyboardPageFragment(org.thoughtcrime.securesms.keyboard.sticker.StickerKeyboardPageFragment) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) WindowManager(android.view.WindowManager) RequestGroupV2InfoJob(org.thoughtcrime.securesms.jobs.RequestGroupV2InfoJob) DrawableUtil(org.thoughtcrime.securesms.util.DrawableUtil) ViewUtil(org.thoughtcrime.securesms.util.ViewUtil) MediaKeyboard(org.thoughtcrime.securesms.components.emoji.MediaKeyboard) TypingStatusSender(org.thoughtcrime.securesms.components.TypingStatusSender) GroupV1MigrationJob(org.thoughtcrime.securesms.jobs.GroupV1MigrationJob) AttachmentManager(org.thoughtcrime.securesms.mms.AttachmentManager) PlayStoreUtil(org.thoughtcrime.securesms.util.PlayStoreUtil) LocationSlide(org.thoughtcrime.securesms.mms.LocationSlide) ContactsContract(android.provider.ContactsContract) OnFocusChangeListener(android.view.View.OnFocusChangeListener) SecurityEvent(org.thoughtcrime.securesms.crypto.SecurityEvent) RegisteredState(org.thoughtcrime.securesms.database.RecipientDatabase.RegisteredState) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Locale(java.util.Locale) AsynchronousCallback(org.thoughtcrime.securesms.util.AsynchronousCallback) ActivityInfo(android.content.pm.ActivityInfo) Button(android.widget.Button) VoiceNotePlaybackState(org.thoughtcrime.securesms.components.voice.VoiceNotePlaybackState) StickerSlide(org.thoughtcrime.securesms.mms.StickerSlide) AsyncTask(android.os.AsyncTask) RecipientDisappearingMessagesActivity(org.thoughtcrime.securesms.recipients.ui.disappearingmessages.RecipientDisappearingMessagesActivity) VoiceNotePlayerView(org.thoughtcrime.securesms.components.voice.VoiceNotePlayerView) OutgoingSecureMediaMessage(org.thoughtcrime.securesms.mms.OutgoingSecureMediaMessage) CharacterState(org.thoughtcrime.securesms.util.CharacterCalculator.CharacterState) PorterDuff(android.graphics.PorterDuff) ThreadUtil(org.signal.core.util.ThreadUtil) LinkPreviewViewModel(org.thoughtcrime.securesms.linkpreview.LinkPreviewViewModel) Objects(java.util.Objects) ChatWallpaperDimLevelUtil(org.thoughtcrime.securesms.wallpaper.ChatWallpaperDimLevelUtil) GroupsV1MigrationSuggestionsDialog(org.thoughtcrime.securesms.groups.ui.migration.GroupsV1MigrationSuggestionsDialog) Slide(org.thoughtcrime.securesms.mms.Slide) ActivityNotFoundException(android.content.ActivityNotFoundException) SignalPlace(org.thoughtcrime.securesms.components.location.SignalPlace) Draft(org.thoughtcrime.securesms.database.DraftDatabase.Draft) Toolbar(androidx.appcompat.widget.Toolbar) GiphyActivity(org.thoughtcrime.securesms.giph.ui.GiphyActivity) SmsUtil(org.thoughtcrime.securesms.util.SmsUtil) EditorInfo(android.view.inputmethod.EditorInfo) AlertDialog(androidx.appcompat.app.AlertDialog) KeyboardPage(org.thoughtcrime.securesms.keyboard.KeyboardPage) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) RecipientDatabase(org.thoughtcrime.securesms.database.RecipientDatabase) MenuItem(android.view.MenuItem) TextSecurePreferences(org.thoughtcrime.securesms.util.TextSecurePreferences) Lifecycle(androidx.lifecycle.Lifecycle) MaterialButton(com.google.android.material.button.MaterialButton) DiskCacheStrategy(com.bumptech.glide.load.engine.DiskCacheStrategy) PlacePickerActivity(org.thoughtcrime.securesms.maps.PlacePickerActivity) InviteReminderModel(org.thoughtcrime.securesms.invites.InviteReminderModel) QuoteModel(org.thoughtcrime.securesms.mms.QuoteModel) Build(android.os.Build) ShortcutLauncherActivity(org.thoughtcrime.securesms.ShortcutLauncherActivity) ConversationSearchBottomBar(org.thoughtcrime.securesms.components.ConversationSearchBottomBar) SimpleTask(org.thoughtcrime.securesms.util.concurrent.SimpleTask) StickerPackInstallEvent(org.thoughtcrime.securesms.stickers.StickerPackInstallEvent) Stub(org.thoughtcrime.securesms.util.views.Stub) LayoutInflater(android.view.LayoutInflater) MediaSelectionActivity(org.thoughtcrime.securesms.mediasend.v2.MediaSelectionActivity) FullscreenHelper(org.thoughtcrime.securesms.util.FullscreenHelper) GroupMembersDialog(org.thoughtcrime.securesms.GroupMembersDialog) GifSlide(org.thoughtcrime.securesms.mms.GifSlide) BlobProvider(org.thoughtcrime.securesms.providers.BlobProvider) CommunicationActions(org.thoughtcrime.securesms.util.CommunicationActions) WindowUtil(org.thoughtcrime.securesms.util.WindowUtil) Color(android.graphics.Color) GifKeyboardPageFragment(org.thoughtcrime.securesms.keyboard.gif.GifKeyboardPageFragment) OnKeyListener(android.view.View.OnKeyListener) ComposeText(org.thoughtcrime.securesms.components.ComposeText) MediaConstraints(org.thoughtcrime.securesms.mms.MediaConstraints) Bitmap(android.graphics.Bitmap) Transition(com.bumptech.glide.request.transition.Transition) Vibrator(android.os.Vibrator) ContactData(org.thoughtcrime.securesms.contacts.ContactAccessor.ContactData) DraftViewModel(org.thoughtcrime.securesms.conversation.drafts.DraftViewModel) Activity(android.app.Activity) ContactShareEditActivity(org.thoughtcrime.securesms.contactshare.ContactShareEditActivity) UnauthorizedReminder(org.thoughtcrime.securesms.components.reminder.UnauthorizedReminder) PendingGroupJoinRequestsReminder(org.thoughtcrime.securesms.components.reminder.PendingGroupJoinRequestsReminder) RecaptchaProofBottomSheetFragment(org.thoughtcrime.securesms.ratelimit.RecaptchaProofBottomSheetFragment) RecipientUtil(org.thoughtcrime.securesms.recipients.RecipientUtil) SendButton(org.thoughtcrime.securesms.components.SendButton) Uri(android.net.Uri) FrameLayout(android.widget.FrameLayout) ImageView(android.widget.ImageView) EmojiSearchFragment(org.thoughtcrime.securesms.keyboard.emoji.search.EmojiSearchFragment) MediaOverviewActivity(org.thoughtcrime.securesms.mediaoverview.MediaOverviewActivity) Drawable(android.graphics.drawable.Drawable) ImageSlide(org.thoughtcrime.securesms.mms.ImageSlide) ShortcutManagerCompat(androidx.core.content.pm.ShortcutManagerCompat) SecureRandom(java.security.SecureRandom) MentionUtil(org.thoughtcrime.securesms.database.MentionUtil) Manifest(android.Manifest) ReviewCardDialogFragment(org.thoughtcrime.securesms.profiles.spoofing.ReviewCardDialogFragment) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) MmsMessageRecord(org.thoughtcrime.securesms.database.model.MmsMessageRecord) Fragment(androidx.fragment.app.Fragment) TargetApi(android.annotation.TargetApi) ServiceUtil(org.thoughtcrime.securesms.util.ServiceUtil) Set(java.util.Set) ReactionRecord(org.thoughtcrime.securesms.database.model.ReactionRecord) StickerManagementActivity(org.thoughtcrime.securesms.stickers.StickerManagementActivity) IdRes(androidx.annotation.IdRes) Nullable(androidx.annotation.Nullable) InsightsLauncher(org.thoughtcrime.securesms.insights.InsightsLauncher) IdentityRecord(org.thoughtcrime.securesms.database.model.IdentityRecord) Attachment(org.thoughtcrime.securesms.attachments.Attachment) TextWatcher(android.text.TextWatcher) Util(org.thoughtcrime.securesms.util.Util) WorkerThread(androidx.annotation.WorkerThread) Editable(android.text.Editable) MessageRequestsBottomView(org.thoughtcrime.securesms.messagerequests.MessageRequestsBottomView) ArrayList(java.util.ArrayList) GroupsV1MigrationInitiationBottomSheetDialogFragment(org.thoughtcrime.securesms.groups.ui.migration.GroupsV1MigrationInitiationBottomSheetDialogFragment) RecipientFormattingException(org.thoughtcrime.securesms.recipients.RecipientFormattingException) AudioRecorder(org.thoughtcrime.securesms.audio.AudioRecorder) KeyCachingService(org.thoughtcrime.securesms.service.KeyCachingService) InputAwareLayout(org.thoughtcrime.securesms.components.InputAwareLayout) IdentityUtil(org.thoughtcrime.securesms.util.IdentityUtil) ViewModelProvider(androidx.lifecycle.ViewModelProvider) Contact(org.thoughtcrime.securesms.contactshare.Contact) SpannableString(android.text.SpannableString) PaymentsValues(org.thoughtcrime.securesms.keyvalue.PaymentsValues) Permissions(org.thoughtcrime.securesms.permissions.Permissions) SpanUtil(org.thoughtcrime.securesms.util.SpanUtil) IdentityRecordList(org.thoughtcrime.securesms.database.identity.IdentityRecordList) AudioSlide(org.thoughtcrime.securesms.mms.AudioSlide) LinkPreviewRepository(org.thoughtcrime.securesms.linkpreview.LinkPreviewRepository) ContactAccessor(org.thoughtcrime.securesms.contacts.ContactAccessor) Configuration(android.content.res.Configuration) RecipientExporter(org.thoughtcrime.securesms.recipients.RecipientExporter) GroupErrors(org.thoughtcrime.securesms.groups.ui.GroupErrors) SignalStore(org.thoughtcrime.securesms.keyvalue.SignalStore) SlideDeck(org.thoughtcrime.securesms.mms.SlideDeck) BubbleUtil(org.thoughtcrime.securesms.util.BubbleUtil) MessageSender(org.thoughtcrime.securesms.sms.MessageSender) BlockUnblockDialog(org.thoughtcrime.securesms.BlockUnblockDialog) GroupCallViewModel(org.thoughtcrime.securesms.conversation.ui.groupcall.GroupCallViewModel) Spannable(android.text.Spannable) TimeoutException(java.util.concurrent.TimeoutException) PendingIntent(android.app.PendingIntent) LinkMovementMethod(android.text.method.LinkMovementMethod) R(org.thoughtcrime.securesms.R) Mention(org.thoughtcrime.securesms.database.model.Mention) MessageRecord(org.thoughtcrime.securesms.database.model.MessageRecord) Browser(android.provider.Browser) KeyboardPagerViewModel(org.thoughtcrime.securesms.keyboard.KeyboardPagerViewModel) View(android.view.View) Recipient(org.thoughtcrime.securesms.recipients.Recipient) SignalExecutors(org.signal.core.util.concurrent.SignalExecutors) MediaType(org.thoughtcrime.securesms.mms.SlideFactory.MediaType) ExpiredBuildReminder(org.thoughtcrime.securesms.components.reminder.ExpiredBuildReminder) Base64(org.thoughtcrime.securesms.util.Base64) StickerEventListener(org.thoughtcrime.securesms.stickers.StickerEventListener) ContactUtil(org.thoughtcrime.securesms.contactshare.ContactUtil) SimpleTextWatcher(org.thoughtcrime.securesms.contactshare.SimpleTextWatcher) InputPanel(org.thoughtcrime.securesms.components.InputPanel) MessageRequestViewModel(org.thoughtcrime.securesms.messagerequests.MessageRequestViewModel) InvalidMessageException(org.whispersystems.libsignal.InvalidMessageException) DraftDatabase(org.thoughtcrime.securesms.database.DraftDatabase) ThreadMode(org.greenrobot.eventbus.ThreadMode) BroadcastReceiver(android.content.BroadcastReceiver) ViewGroup(android.view.ViewGroup) Log(org.signal.core.util.logging.Log) List(java.util.List) TextView(android.widget.TextView) MentionAnnotation(org.thoughtcrime.securesms.components.mention.MentionAnnotation) GroupId(org.thoughtcrime.securesms.groups.GroupId) MessageResult(org.thoughtcrime.securesms.search.MessageResult) GlideRequests(org.thoughtcrime.securesms.mms.GlideRequests) GroupV2UpdateSelfProfileKeyJob(org.thoughtcrime.securesms.jobs.GroupV2UpdateSelfProfileKeyJob) BitmapUtil(org.thoughtcrime.securesms.util.BitmapUtil) GlideApp(org.thoughtcrime.securesms.mms.GlideApp) VideoSlide(org.thoughtcrime.securesms.mms.VideoSlide) Context(android.content.Context) RegistrationNavigationActivity(org.thoughtcrime.securesms.registration.RegistrationNavigationActivity) KeyEvent(android.view.KeyEvent) DirectoryHelper(org.thoughtcrime.securesms.contacts.sync.DirectoryHelper) ReactionsBottomSheetDialogFragment(org.thoughtcrime.securesms.reactions.ReactionsBottomSheetDialogFragment) SignalLocalMetrics(org.thoughtcrime.securesms.util.SignalLocalMetrics) Intent(android.content.Intent) AssertedSuccessListener(org.thoughtcrime.securesms.util.concurrent.AssertedSuccessListener) OnKeyboardShownListener(org.thoughtcrime.securesms.components.KeyboardAwareLinearLayout.OnKeyboardShownListener) TooltipPopup(org.thoughtcrime.securesms.components.TooltipPopup) SuppressLint(android.annotation.SuppressLint) Pair(org.whispersystems.libsignal.util.Pair) NotificationChannels(org.thoughtcrime.securesms.notifications.NotificationChannels) TransportOption(org.thoughtcrime.securesms.TransportOption) EmojiKeyboardPageFragment(org.thoughtcrime.securesms.keyboard.emoji.EmojiKeyboardPageFragment) MotionEvent(android.view.MotionEvent) EventBus(org.greenrobot.eventbus.EventBus) MessageUtil(org.thoughtcrime.securesms.util.MessageUtil) VoiceNoteMediaController(org.thoughtcrime.securesms.components.voice.VoiceNoteMediaController) ShortcutInfoCompat(androidx.core.content.pm.ShortcutInfoCompat) SettableFuture(org.thoughtcrime.securesms.util.concurrent.SettableFuture) VerifyIdentityActivity(org.thoughtcrime.securesms.verify.VerifyIdentityActivity) PromptMmsActivity(org.thoughtcrime.securesms.PromptMmsActivity) HidingLinearLayout(org.thoughtcrime.securesms.components.HidingLinearLayout) GroupsV1MigrationSuggestionsReminder(org.thoughtcrime.securesms.components.reminder.GroupsV1MigrationSuggestionsReminder) VerifiedStatus(org.thoughtcrime.securesms.database.IdentityDatabase.VerifiedStatus) MediaSendActivityResult(org.thoughtcrime.securesms.mediasend.MediaSendActivityResult) ActivityCompat(androidx.core.app.ActivityCompat) StickerRecord(org.thoughtcrime.securesms.database.model.StickerRecord) MessageDetailsFragment(org.thoughtcrime.securesms.messagedetails.MessageDetailsFragment) TombstoneAttachment(org.thoughtcrime.securesms.attachments.TombstoneAttachment) GroupActiveState(org.thoughtcrime.securesms.conversation.ConversationGroupViewModel.GroupActiveState) ConversationSettingsActivity(org.thoughtcrime.securesms.components.settings.conversation.ConversationSettingsActivity) TimeUnit(java.util.concurrent.TimeUnit) ServiceOutageDetectionJob(org.thoughtcrime.securesms.jobs.ServiceOutageDetectionJob) Observer(androidx.lifecycle.Observer) MentionsPickerViewModel(org.thoughtcrime.securesms.conversation.ui.mentions.MentionsPickerViewModel) Subscribe(org.greenrobot.eventbus.Subscribe) ReminderUpdateEvent(org.thoughtcrime.securesms.events.ReminderUpdateEvent) MuteDialog(org.thoughtcrime.securesms.MuteDialog) ReactWithAnyEmojiBottomSheetDialogFragment(org.thoughtcrime.securesms.reactions.any.ReactWithAnyEmojiBottomSheetDialogFragment) LeaveGroupDialog(org.thoughtcrime.securesms.groups.ui.LeaveGroupDialog) Collections(java.util.Collections) OnClickListener(android.view.View.OnClickListener) ArrayList(java.util.ArrayList) Media(org.thoughtcrime.securesms.mediasend.Media) LiveRecipient(org.thoughtcrime.securesms.recipients.LiveRecipient) Recipient(org.thoughtcrime.securesms.recipients.Recipient) MediaSendActivityResult(org.thoughtcrime.securesms.mediasend.MediaSendActivityResult) IOException(java.io.IOException) SlideDeck(org.thoughtcrime.securesms.mms.SlideDeck) SignalPlace(org.thoughtcrime.securesms.components.location.SignalPlace) SuppressLint(android.annotation.SuppressLint) QuoteModel(org.thoughtcrime.securesms.mms.QuoteModel) ImageSlide(org.thoughtcrime.securesms.mms.ImageSlide) LocationSlide(org.thoughtcrime.securesms.mms.LocationSlide) StickerSlide(org.thoughtcrime.securesms.mms.StickerSlide) Slide(org.thoughtcrime.securesms.mms.Slide) GifSlide(org.thoughtcrime.securesms.mms.GifSlide) ImageSlide(org.thoughtcrime.securesms.mms.ImageSlide) AudioSlide(org.thoughtcrime.securesms.mms.AudioSlide) VideoSlide(org.thoughtcrime.securesms.mms.VideoSlide) Mention(org.thoughtcrime.securesms.database.model.Mention) GifSlide(org.thoughtcrime.securesms.mms.GifSlide) BlobProvider(org.thoughtcrime.securesms.providers.BlobProvider)

Example 4 with Media

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

the class ConversationParentFragment method sendSticker.

private void sendSticker(@NonNull StickerLocator stickerLocator, @NonNull String contentType, @NonNull Uri uri, long size, boolean clearCompose) {
    if (sendButton.getSelectedTransport().isSms()) {
        Media media = new Media(uri, contentType, System.currentTimeMillis(), StickerSlide.WIDTH, StickerSlide.HEIGHT, size, 0, false, false, Optional.absent(), Optional.absent(), Optional.absent());
        Intent intent = MediaSelectionActivity.editor(requireContext(), sendButton.getSelectedTransport(), Collections.singletonList(media), recipient.getId(), composeText.getTextTrimmed());
        startActivityForResult(intent, MEDIA_SENDER);
        return;
    }
    long expiresIn = TimeUnit.SECONDS.toMillis(recipient.get().getExpiresInSeconds());
    int subscriptionId = sendButton.getSelectedTransport().getSimSubscriptionId().or(-1);
    boolean initiating = threadId == -1;
    TransportOption transport = sendButton.getSelectedTransport();
    SlideDeck slideDeck = new SlideDeck();
    Slide stickerSlide = new StickerSlide(requireContext(), uri, size, stickerLocator, contentType);
    slideDeck.addSlide(stickerSlide);
    sendMediaMessage(recipient.getId(), transport.isSms(), "", slideDeck, null, Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), expiresIn, false, subscriptionId, initiating, clearCompose, null);
}
Also used : TransportOption(org.thoughtcrime.securesms.TransportOption) LocationSlide(org.thoughtcrime.securesms.mms.LocationSlide) StickerSlide(org.thoughtcrime.securesms.mms.StickerSlide) Slide(org.thoughtcrime.securesms.mms.Slide) GifSlide(org.thoughtcrime.securesms.mms.GifSlide) ImageSlide(org.thoughtcrime.securesms.mms.ImageSlide) AudioSlide(org.thoughtcrime.securesms.mms.AudioSlide) VideoSlide(org.thoughtcrime.securesms.mms.VideoSlide) Media(org.thoughtcrime.securesms.mediasend.Media) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) SlideDeck(org.thoughtcrime.securesms.mms.SlideDeck) StickerSlide(org.thoughtcrime.securesms.mms.StickerSlide) SuppressLint(android.annotation.SuppressLint)

Example 5 with Media

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

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)

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