Search in sources :

Example 36 with Address

use of org.thoughtcrime.securesms.database.Address in project Signal-Android by signalapp.

the class PushGroupUpdateJob method onRun.

@Override
public void onRun() throws IOException, UntrustedIdentityException {
    GroupDatabase groupDatabase = DatabaseFactory.getGroupDatabase(context);
    Optional<GroupRecord> record = groupDatabase.getGroup(GroupUtil.getEncodedId(groupId, false));
    SignalServiceAttachment avatar = null;
    if (record == null) {
        Log.w(TAG, "No information for group record info request: " + new String(groupId));
        return;
    }
    if (record.get().getAvatar() != null) {
        avatar = SignalServiceAttachmentStream.newStreamBuilder().withContentType("image/jpeg").withStream(new ByteArrayInputStream(record.get().getAvatar())).withLength(record.get().getAvatar().length).build();
    }
    List<String> members = new LinkedList<>();
    for (Address member : record.get().getMembers()) {
        members.add(member.serialize());
    }
    SignalServiceGroup groupContext = SignalServiceGroup.newBuilder(Type.UPDATE).withAvatar(avatar).withId(groupId).withMembers(members).withName(record.get().getTitle()).build();
    SignalServiceDataMessage message = SignalServiceDataMessage.newBuilder().asGroupMessage(groupContext).withTimestamp(System.currentTimeMillis()).build();
    messageSender.sendMessage(new SignalServiceAddress(source), message);
}
Also used : SignalServiceAttachment(org.whispersystems.signalservice.api.messages.SignalServiceAttachment) SignalServiceDataMessage(org.whispersystems.signalservice.api.messages.SignalServiceDataMessage) Address(org.thoughtcrime.securesms.database.Address) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) ByteArrayInputStream(java.io.ByteArrayInputStream) GroupDatabase(org.thoughtcrime.securesms.database.GroupDatabase) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) GroupRecord(org.thoughtcrime.securesms.database.GroupDatabase.GroupRecord) SignalServiceGroup(org.whispersystems.signalservice.api.messages.SignalServiceGroup) LinkedList(java.util.LinkedList)

Example 37 with Address

use of org.thoughtcrime.securesms.database.Address in project Signal-Android by signalapp.

the class CreateProfileActivity method initializeProfileAvatar.

private void initializeProfileAvatar(boolean excludeSystem) {
    Address ourAddress = Address.fromSerialized(TextSecurePreferences.getLocalNumber(this));
    if (AvatarHelper.getAvatarFile(this, ourAddress).exists() && AvatarHelper.getAvatarFile(this, ourAddress).length() > 0) {
        new AsyncTask<Void, Void, byte[]>() {

            @Override
            protected byte[] doInBackground(Void... params) {
                try {
                    return Util.readFully(AvatarHelper.getInputStreamFor(CreateProfileActivity.this, ourAddress));
                } catch (IOException e) {
                    Log.w(TAG, e);
                    return null;
                }
            }

            @Override
            protected void onPostExecute(byte[] result) {
                if (result != null) {
                    avatarBytes = result;
                    GlideApp.with(CreateProfileActivity.this).load(result).circleCrop().into(avatar);
                }
            }
        }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    } else if (!excludeSystem) {
        SystemProfileUtil.getSystemProfileAvatar(this, new ProfileMediaConstraints()).addListener(new ListenableFuture.Listener<byte[]>() {

            @Override
            public void onSuccess(byte[] result) {
                if (result != null) {
                    avatarBytes = result;
                    GlideApp.with(CreateProfileActivity.this).load(result).circleCrop().into(avatar);
                }
            }

            @Override
            public void onFailure(ExecutionException e) {
                Log.w(TAG, e);
            }
        });
    }
}
Also used : Address(org.thoughtcrime.securesms.database.Address) ProfileMediaConstraints(org.thoughtcrime.securesms.profiles.ProfileMediaConstraints) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Example 38 with Address

use of org.thoughtcrime.securesms.database.Address in project Signal-Android by signalapp.

the class ShareActivity method handleResolvedMedia.

private void handleResolvedMedia(Intent intent, boolean animate) {
    long threadId = intent.getLongExtra(EXTRA_THREAD_ID, -1);
    int distributionType = intent.getIntExtra(EXTRA_DISTRIBUTION_TYPE, -1);
    Address address = null;
    if (intent.hasExtra(EXTRA_ADDRESS_MARSHALLED)) {
        Parcel parcel = Parcel.obtain();
        byte[] marshalled = intent.getByteArrayExtra(EXTRA_ADDRESS_MARSHALLED);
        parcel.unmarshall(marshalled, 0, marshalled.length);
        parcel.setDataPosition(0);
        address = parcel.readParcelable(getClassLoader());
        parcel.recycle();
    }
    boolean hasResolvedDestination = threadId != -1 && address != null && distributionType != -1;
    if (!hasResolvedDestination && animate) {
        ViewUtil.fadeIn(contactsFragment.getView(), 300);
        ViewUtil.fadeOut(progressWheel, 300);
    } else if (!hasResolvedDestination) {
        contactsFragment.getView().setVisibility(View.VISIBLE);
        progressWheel.setVisibility(View.GONE);
    } else {
        createConversation(threadId, address, distributionType);
    }
}
Also used : Address(org.thoughtcrime.securesms.database.Address) Parcel(android.os.Parcel) SuppressLint(android.annotation.SuppressLint)

Example 39 with Address

use of org.thoughtcrime.securesms.database.Address in project Signal-Android by signalapp.

the class MediaPreviewActivity method initializeResources.

private void initializeResources() {
    Address address = getIntent().getParcelableExtra(ADDRESS_EXTRA);
    initialMediaUri = getIntent().getData();
    initialMediaType = getIntent().getType();
    initialMediaSize = getIntent().getLongExtra(SIZE_EXTRA, 0);
    leftIsRecent = getIntent().getBooleanExtra(LEFT_IS_RECENT_EXTRA, false);
    restartItem = -1;
    if (address != null) {
        conversationRecipient = Recipient.from(this, address, true);
    } else {
        conversationRecipient = null;
    }
}
Also used : Address(org.thoughtcrime.securesms.database.Address)

Example 40 with Address

use of org.thoughtcrime.securesms.database.Address in project Signal-Android by signalapp.

the class GroupCreateActivity method onActivityResult.

@Override
public void onActivityResult(int reqCode, int resultCode, final Intent data) {
    super.onActivityResult(reqCode, resultCode, data);
    Uri outputFile = Uri.fromFile(new File(getCacheDir(), "cropped"));
    if (data == null || resultCode != Activity.RESULT_OK)
        return;
    switch(reqCode) {
        case PICK_CONTACT:
            List<String> selected = data.getStringArrayListExtra("contacts");
            for (String contact : selected) {
                Address address = Address.fromExternal(this, contact);
                Recipient recipient = Recipient.from(this, address, false);
                addSelectedContacts(recipient);
            }
            break;
        case Crop.REQUEST_PICK:
            new Crop(data.getData()).output(outputFile).asSquare().start(this);
            break;
        case Crop.REQUEST_CROP:
            GlideApp.with(this).asBitmap().load(Crop.getOutput(data)).skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).centerCrop().override(AVATAR_SIZE, AVATAR_SIZE).into(new SimpleTarget<Bitmap>() {

                @Override
                public void onResourceReady(@NonNull Bitmap resource, Transition<? super Bitmap> transition) {
                    setAvatar(Crop.getOutput(data), resource);
                }
            });
    }
}
Also used : Crop(com.soundcloud.android.crop.Crop) Bitmap(android.graphics.Bitmap) Address(org.thoughtcrime.securesms.database.Address) Recipient(org.thoughtcrime.securesms.recipients.Recipient) Uri(android.net.Uri) File(java.io.File)

Aggregations

Address (org.thoughtcrime.securesms.database.Address)40 Recipient (org.thoughtcrime.securesms.recipients.Recipient)13 LinkedList (java.util.LinkedList)10 Uri (android.net.Uri)9 GroupDatabase (org.thoughtcrime.securesms.database.GroupDatabase)7 Cursor (android.database.Cursor)6 ByteString (com.google.protobuf.ByteString)6 IOException (java.io.IOException)6 File (java.io.File)5 GroupContext (org.whispersystems.signalservice.internal.push.SignalServiceProtos.GroupContext)5 NonNull (android.support.annotation.NonNull)4 Attachment (org.thoughtcrime.securesms.attachments.Attachment)4 InsertResult (org.thoughtcrime.securesms.database.MessagingDatabase.InsertResult)4 SignalServiceAttachment (org.whispersystems.signalservice.api.messages.SignalServiceAttachment)4 SignalServiceAddress (org.whispersystems.signalservice.api.push.SignalServiceAddress)4 SuppressLint (android.annotation.SuppressLint)3 Nullable (android.support.annotation.Nullable)3 HashSet (java.util.HashSet)3 List (java.util.List)3 ContentValues (android.content.ContentValues)2