本文整理汇总了Java中org.whispersystems.libsignal.util.guava.Optional.fromNullable方法的典型用法代码示例。如果您正苦于以下问题:Java Optional.fromNullable方法的具体用法?Java Optional.fromNullable怎么用?Java Optional.fromNullable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.whispersystems.libsignal.util.guava.Optional
的用法示例。
在下文中一共展示了Optional.fromNullable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: SignalServiceDataMessage
import org.whispersystems.libsignal.util.guava.Optional; //导入方法依赖的package包/类
/**
* Construct a SignalServiceDataMessage.
*
* @param timestamp The sent timestamp.
* @param group The group information (or null if none).
* @param attachments The attachments (or null if none).
* @param body The message contents.
* @param endSession Flag indicating whether this message should close a session.
* @param expiresInSeconds Number of seconds in which the message should disappear after being seen.
*/
public SignalServiceDataMessage(long timestamp, SignalServiceGroup group,
List<SignalServiceAttachment> attachments,
String body, boolean endSession, int expiresInSeconds,
boolean expirationUpdate)
{
this.timestamp = timestamp;
this.body = Optional.fromNullable(body);
this.group = Optional.fromNullable(group);
this.endSession = endSession;
this.expiresInSeconds = expiresInSeconds;
this.expirationUpdate = expirationUpdate;
if (attachments != null && !attachments.isEmpty()) {
this.attachments = Optional.of(attachments);
} else {
this.attachments = Optional.absent();
}
}
示例2: getProximityLock
import org.whispersystems.libsignal.util.guava.Optional; //导入方法依赖的package包/类
private Optional<PowerManager.WakeLock> getProximityLock(PowerManager pm) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
if (pm.isWakeLockLevelSupported(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK)) {
return Optional.fromNullable(pm.newWakeLock(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK,
"Signal Proximity Lock"));
} else {
return Optional.absent();
}
} else {
try {
return Optional.fromNullable(pm.newWakeLock(PROXIMITY_SCREEN_OFF_WAKE_LOCK, "RedPhone Incall"));
} catch (Throwable t) {
Log.e(TAG, "Failed to create proximity lock", t);
return Optional.absent();
}
}
}
示例3: constructAttachmentFromUri
import org.whispersystems.libsignal.util.guava.Optional; //导入方法依赖的package包/类
protected static Attachment constructAttachmentFromUri(@NonNull Context context,
@NonNull Uri uri,
@NonNull String defaultMime,
long size,
boolean hasThumbnail,
@Nullable String fileName,
boolean voiceNote)
{
try {
Optional<String> resolvedType = Optional.fromNullable(MediaUtil.getMimeType(context, uri));
String fastPreflightId = String.valueOf(SecureRandom.getInstance("SHA1PRNG").nextLong());
return new UriAttachment(uri, hasThumbnail ? uri : null, resolvedType.or(defaultMime), AttachmentDatabase.TRANSFER_PROGRESS_STARTED, size, fileName, fastPreflightId, voiceNote);
} catch (NoSuchAlgorithmException e) {
throw new AssertionError(e);
}
}
示例4: read
import org.whispersystems.libsignal.util.guava.Optional; //导入方法依赖的package包/类
public DeviceContact read() throws IOException {
long detailsLength = readRawVarint32();
byte[] detailsSerialized = new byte[(int)detailsLength];
Util.readFully(in, detailsSerialized);
SignalServiceProtos.ContactDetails details = SignalServiceProtos.ContactDetails.parseFrom(detailsSerialized);
String number = details.getNumber();
Optional<String> name = Optional.fromNullable(details.getName());
Optional<SignalServiceAttachmentStream> avatar = Optional.absent();
Optional<String> color = details.hasColor() ? Optional.of(details.getColor()) : Optional.<String>absent();
if (details.hasAvatar()) {
long avatarLength = details.getAvatar().getLength();
InputStream avatarStream = new LimitedInputStream(in, avatarLength);
String avatarContentType = details.getAvatar().getContentType();
avatar = Optional.of(new SignalServiceAttachmentStream(avatarStream, avatarContentType, null, avatarLength, null));
}
return new DeviceContact(number, name, avatar, color);
}
示例5: generateFullContactUpdate
import org.whispersystems.libsignal.util.guava.Optional; //导入方法依赖的package包/类
private void generateFullContactUpdate()
throws IOException, UntrustedIdentityException, NetworkException
{
SignalServiceMessageSender messageSender = messageSenderFactory.create();
File contactDataFile = createTempFile("multidevice-contact-update");
try {
DeviceContactsOutputStream out = new DeviceContactsOutputStream(new FileOutputStream(contactDataFile));
Collection<ContactData> contacts = ContactAccessor.getInstance().getContactsWithPush(context);
for (ContactData contactData : contacts) {
Uri contactUri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, String.valueOf(contactData.id));
String number = Util.canonicalizeNumber(context, contactData.numbers.get(0).number);
Recipient recipient = RecipientFactory.getRecipientsFromString(context, number, true).getPrimaryRecipient();
Optional<IdentityDatabase.IdentityRecord> identity = DatabaseFactory.getIdentityDatabase(context).getIdentity(recipient.getRecipientId());
Optional<VerifiedMessage> verified = getVerifiedMessage(recipient, identity);
Optional<String> name = Optional.fromNullable(contactData.name);
Optional<String> color = getColor(number);
out.write(new DeviceContact(number, name, getAvatar(contactUri), color, verified));
}
out.close();
sendUpdate(messageSender, contactDataFile, true);
} catch(InvalidNumberException e) {
Log.w(TAG, e);
} finally {
if (contactDataFile != null) contactDataFile.delete();
}
}
示例6: SelectedRecipientsAdapter
import org.whispersystems.libsignal.util.guava.Optional; //导入方法依赖的package包/类
public SelectedRecipientsAdapter(@NonNull Context context,
@NonNull Collection<Recipient> existingRecipients,
@Nullable String existingOwner,
@Nullable Set<String> existingAdmins)
{
this.context = context;
this.ownerNumber = Optional.fromNullable(Util.canonicalizeNumber(context, existingOwner, existingOwner));
this.adminNumbers = Optional.fromNullable(Util.canonicalizeNumber(context, existingAdmins));
this.recipients = wrapExistingMembers(existingRecipients);
}
示例7: find
import org.whispersystems.libsignal.util.guava.Optional; //导入方法依赖的package包/类
public Optional<RecipientWrapper> find(@NonNull Recipient recipient) {
RecipientWrapper found = null;
for (RecipientWrapper wrapper : recipients) {
if (wrapper.getRecipient().equals(recipient)) {
found = wrapper;
break;
}
}
return Optional.fromNullable(found);
}
示例8: SignalServiceUrl
import org.whispersystems.libsignal.util.guava.Optional; //导入方法依赖的package包/类
public SignalServiceUrl(String url, String hostHeader,
TrustStore trustStore,
ConnectionSpec connectionSpec)
{
this.url = url;
this.hostHeader = Optional.fromNullable(hostHeader);
this.trustStore = trustStore;
this.connectionSpec = Optional.fromNullable(connectionSpec);
}
示例9: onRun
import org.whispersystems.libsignal.util.guava.Optional; //导入方法依赖的package包/类
@Override
public void onRun() throws IOException {
Log.w("DeliveryReceiptJob", "Sending delivery receipt...");
SignalServiceMessageSender messageSender = messageSenderFactory.create();
SignalServiceAddress textSecureAddress = new SignalServiceAddress(destination, Optional.fromNullable(relay));
messageSender.sendDeliveryReceipt(textSecureAddress, timestamp);
}
示例10: handleMediaMessage
import org.whispersystems.libsignal.util.guava.Optional; //导入方法依赖的package包/类
private void handleMediaMessage(@NonNull MasterSecretUnion masterSecret,
@NonNull SignalServiceEnvelope envelope,
@NonNull SignalServiceDataMessage message,
@NonNull Optional<Long> smsMessageId)
throws MmsException
{
MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
String localNumber = TextSecurePreferences.getLocalNumber(context);
Recipients recipients = getMessageDestination(envelope, message);
IncomingMediaMessage mediaMessage = new IncomingMediaMessage(masterSecret, envelope.getSource(),
localNumber, message.getTimestamp(), -1,
message.getExpiresInSeconds() * 1000, false,
Optional.fromNullable(envelope.getRelay()),
message.getBody(),
message.getGroupInfo(),
message.getAttachments());
if (message.getExpiresInSeconds() != recipients.getExpireMessages()) {
handleExpirationUpdate(masterSecret, envelope, message, Optional.<Long>absent());
}
Optional<InsertResult> insertResult = database.insertSecureDecryptedMessageInbox(masterSecret, mediaMessage, -1);
if (insertResult.isPresent()) {
List<DatabaseAttachment> attachments = DatabaseFactory.getAttachmentDatabase(context).getAttachmentsForMessage(insertResult.get().getMessageId());
for (DatabaseAttachment attachment : attachments) {
ApplicationContext.getInstance(context)
.getJobManager()
.add(new AttachmentDownloadJob(context, insertResult.get().getMessageId(),
attachment.getAttachmentId()));
}
if (smsMessageId.isPresent()) {
DatabaseFactory.getSmsDatabase(context).deleteMessage(smsMessageId.get());
}
MessageNotifier.updateNotification(context, masterSecret.getMasterSecret().orNull(), insertResult.get().getThreadId());
}
}
示例11: find
import org.whispersystems.libsignal.util.guava.Optional; //导入方法依赖的package包/类
public Optional<RecipientWrapper> find(@NonNull Recipient recipient) {
RecipientWrapper found = null;
for (RecipientWrapper wrapper : recipients) {
if (wrapper.getRecipient().equals(recipient)) found = wrapper;
}
return Optional.fromNullable(found);
}
示例12: provideSignalMessageSenderFactory
import org.whispersystems.libsignal.util.guava.Optional; //导入方法依赖的package包/类
@Provides
SignalMessageSenderFactory provideSignalMessageSenderFactory() {
return new SignalMessageSenderFactory() {
@Override
public SignalServiceMessageSender create() {
return new SignalServiceMessageSender(networkAccess.getConfiguration(context),
TextSecurePreferences.getLocalNumber(context),
TextSecurePreferences.getPushServerPassword(context),
new SignalProtocolStoreImpl(context),
BuildConfig.USER_AGENT,
Optional.fromNullable(MessageRetrievalService.getPipe()),
Optional.<SignalServiceMessageSender.EventListener>of(new SecurityEventListener(context)));
}
};
}
示例13: read
import org.whispersystems.libsignal.util.guava.Optional; //导入方法依赖的package包/类
public DeviceGroup read() throws IOException {
long detailsLength = readRawVarint32();
byte[] detailsSerialized = new byte[(int)detailsLength];
Util.readFully(in, detailsSerialized);
SignalServiceProtos.GroupDetails details = SignalServiceProtos.GroupDetails.parseFrom(detailsSerialized);
if (!details.hasId()) {
throw new IOException("ID missing on group record!");
}
byte[] id = details.getId().toByteArray();
Optional<String> name = Optional.fromNullable(details.getName());
List<String> members = details.getMembersList();
Optional<SignalServiceAttachmentStream> avatar = Optional.absent();
boolean active = details.getActive();
if (details.hasAvatar()) {
long avatarLength = details.getAvatar().getLength();
InputStream avatarStream = new ChunkedInputStream.LimitedInputStream(in, avatarLength);
String avatarContentType = details.getAvatar().getContentType();
avatar = Optional.of(new SignalServiceAttachmentStream(avatarStream, avatarContentType, null, avatarLength, null));
}
return new DeviceGroup(id, name, members, avatar, active);
}
示例14: SignalServiceAttachmentPointer
import org.whispersystems.libsignal.util.guava.Optional; //导入方法依赖的package包/类
public SignalServiceAttachmentPointer(long id, String contentType, String filename, byte[] key, String relay,
Optional<Integer> size, Optional<byte[]> preview,
Optional<byte[]> digest)
{
super(contentType, filename);
this.id = id;
this.key = key;
this.relay = Optional.fromNullable(relay);
this.size = size;
this.preview = preview;
this.digest = digest;
}
示例15: SignalServiceGroup
import org.whispersystems.libsignal.util.guava.Optional; //导入方法依赖的package包/类
/**
* Construct a group context.
* @param type The group message type (update, deliver, quit).
* @param groupId The group ID.
* @param name The group title.
* @param members The group membership list.
* @param avatar The group avatar icon.
* @param owner The group owner.
* @param admins The group admin list.
*/
public SignalServiceGroup(Type type, byte[] groupId, String name,
List<String> members,
SignalServiceAttachment avatar,
String owner, List<String> admins)
{
this.type = type;
this.groupId = groupId;
this.name = Optional.fromNullable(name);
this.members = Optional.fromNullable(members);
this.avatar = Optional.fromNullable(avatar);
this.owner = Optional.fromNullable(owner);
this.admins = Optional.fromNullable(admins);
}