当前位置: 首页>>代码示例>>Java>>正文


Java Optional.absent方法代码示例

本文整理汇总了Java中org.whispersystems.libsignal.util.guava.Optional.absent方法的典型用法代码示例。如果您正苦于以下问题:Java Optional.absent方法的具体用法?Java Optional.absent怎么用?Java Optional.absent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.whispersystems.libsignal.util.guava.Optional的用法示例。


在下文中一共展示了Optional.absent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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();
    }
  }
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:18,代码来源:ProximityLock.java

示例2: getSignedPreKeyIndex

import org.whispersystems.libsignal.util.guava.Optional; //导入方法依赖的package包/类
private static synchronized Optional<SignedPreKeyIndex> getSignedPreKeyIndex(Context context) {
  File indexFile = new File(getSignedPreKeysDirectory(context), SignedPreKeyIndex.FILE_NAME);

  if (!indexFile.exists()) {
    return Optional.absent();
  }

  try {
    InputStreamReader reader = new InputStreamReader(new FileInputStream(indexFile));
    SignedPreKeyIndex index  = JsonUtils.fromJson(reader, SignedPreKeyIndex.class);
    reader.close();

    return Optional.of(index);
  } catch (IOException e) {
    Log.w(TAG, e);
    return Optional.absent();
  }
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:19,代码来源:PreKeyUtil.java

示例3: find

import org.whispersystems.libsignal.util.guava.Optional; //导入方法依赖的package包/类
private Optional<Long> find(SignalServiceEnvelope envelope) {
  SQLiteDatabase database = databaseHelper.getReadableDatabase();
  Cursor         cursor   = null;

  try {
    cursor = database.query(TABLE_NAME, null, TYPE + " = ? AND " + SOURCE + " = ? AND " +
                                              DEVICE_ID + " = ? AND " + LEGACY_MSG + " = ? AND " +
                                              CONTENT + " = ? AND " + TIMESTAMP + " = ?" ,
                            new String[] {String.valueOf(envelope.getType()),
                                          envelope.getSource(),
                                          String.valueOf(envelope.getSourceDevice()),
                                          envelope.hasLegacyMessage() ? Base64.encodeBytes(envelope.getLegacyMessage()) : "",
                                          envelope.hasContent() ? Base64.encodeBytes(envelope.getContent()) : "",
                                          String.valueOf(envelope.getTimestamp())},
                            null, null, null);

    if (cursor != null && cursor.moveToFirst()) {
      return Optional.of(cursor.getLong(cursor.getColumnIndexOrThrow(ID)));
    } else {
      return Optional.absent();
    }
  } finally {
    if (cursor != null) cursor.close();
  }
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:26,代码来源:PushDatabase.java

示例4: forRequest

import org.whispersystems.libsignal.util.guava.Optional; //导入方法依赖的package包/类
public static SignalServiceSyncMessage forRequest(RequestMessage request) {
  return new SignalServiceSyncMessage(Optional.<SentTranscriptMessage>absent(),
                                      Optional.<SignalServiceAttachment>absent(),
                                      Optional.<SignalServiceAttachment>absent(),
                                      Optional.<BlockedListMessage>absent(),
                                      Optional.of(request),
                                      Optional.<List<ReadMessage>>absent());
}
 
开发者ID:XecureIT,项目名称:PeSanKita-lib,代码行数:9,代码来源:SignalServiceSyncMessage.java

示例5: createAttachmentPointer

import org.whispersystems.libsignal.util.guava.Optional; //导入方法依赖的package包/类
@VisibleForTesting
SignalServiceAttachmentPointer createAttachmentPointer(MasterSecret masterSecret, Attachment attachment)
    throws InvalidPartException
{
  if (TextUtils.isEmpty(attachment.getLocation())) {
    throw new InvalidPartException("empty content id");
  }

  if (TextUtils.isEmpty(attachment.getKey())) {
    throw new InvalidPartException("empty encrypted key");
  }

  try {
    AsymmetricMasterSecret asymmetricMasterSecret = MasterSecretUtil.getAsymmetricMasterSecret(context, masterSecret);
    long                   id                     = Long.parseLong(attachment.getLocation());
    byte[]                 key                    = MediaKey.getDecrypted(masterSecret, asymmetricMasterSecret, attachment.getKey());
    String                 relay                  = null;

    if (TextUtils.isEmpty(attachment.getRelay())) {
      relay = attachment.getRelay();
    }

    return new SignalServiceAttachmentPointer(id, null, null, key, relay, Optional.<byte[]>absent());
  } catch (InvalidMessageException | IOException e) {
    Log.w(TAG, e);
    throw new InvalidPartException(e);
  }
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:29,代码来源:AttachmentDownloadJob.java

示例6: doInBackground

import org.whispersystems.libsignal.util.guava.Optional; //导入方法依赖的package包/类
@Override
protected Optional<GroupActionResult> doInBackground(Void... aVoid) {
  try {
    return Optional.of(GroupManager.createGroup(activity, masterSecret, members, avatar, name));
  } catch (InvalidNumberException e) {
    return Optional.absent();
  }
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:9,代码来源:GroupCreateActivity.java

示例7: reset

import org.whispersystems.libsignal.util.guava.Optional; //导入方法依赖的package包/类
public void reset(boolean media) {
  List<TransportOption> transportOptions = initializeAvailableTransports(media);

  this.enabledTransports.clear();
  this.enabledTransports.addAll(transportOptions);

  if (selectedOption.isPresent() && !isEnabled(selectedOption.get())) {
    setSelectedTransport(null);
  } else {
    this.defaultTransportType = Type.SMS;
    this.defaultSubscriptionId = Optional.absent();

    notifyTransportChangeListeners();
  }
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:16,代码来源:TransportOptions.java

示例8: getColor

import org.whispersystems.libsignal.util.guava.Optional; //导入方法依赖的package包/类
private Optional<String> getColor(String number) {
  if (!TextUtils.isEmpty(number)) {
    Recipients recipients = RecipientFactory.getRecipientsFromString(context, number, false);
    return Optional.of(recipients.getColor().serialize());
  } else {
    return Optional.absent();
  }
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:9,代码来源:MultiDeviceContactUpdateJob.java

示例9: getAvatar

import org.whispersystems.libsignal.util.guava.Optional; //导入方法依赖的package包/类
private Optional<SignalServiceAttachmentStream> getAvatar(@Nullable byte[] avatar) {
  if (avatar == null) return Optional.absent();

  return Optional.of(SignalServiceAttachment.newStreamBuilder()
                                            .withStream(new ByteArrayInputStream(avatar))
                                            .withContentType("image/*")
                                            .withLength(avatar.length)
                                            .build());
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:10,代码来源:MultiDeviceGroupUpdateJob.java

示例10: handleEndSessionMessage

import org.whispersystems.libsignal.util.guava.Optional; //导入方法依赖的package包/类
private void handleEndSessionMessage(@NonNull MasterSecretUnion        masterSecret,
                                     @NonNull SignalServiceEnvelope    envelope,
                                     @NonNull SignalServiceDataMessage message,
                                     @NonNull Optional<Long>           smsMessageId)
{
  EncryptingSmsDatabase smsDatabase         = DatabaseFactory.getEncryptingSmsDatabase(context);
  IncomingTextMessage   incomingTextMessage = new IncomingTextMessage(envelope.getSource(),
                                                                      envelope.getSourceDevice(),
                                                                      message.getTimestamp(),
                                                                      "", Optional.<SignalServiceGroup>absent(), 0);

  Long threadId;

  if (!smsMessageId.isPresent()) {
    IncomingEndSessionMessage incomingEndSessionMessage = new IncomingEndSessionMessage(incomingTextMessage);
    Optional<InsertResult>    insertResult              = smsDatabase.insertMessageInbox(masterSecret, incomingEndSessionMessage);

    if (insertResult.isPresent()) threadId = insertResult.get().getThreadId();
    else                          threadId = null;
  } else {
    smsDatabase.markAsEndSession(smsMessageId.get());
    threadId = smsDatabase.getThreadIdForMessage(smsMessageId.get());
  }

  if (threadId != null) {
    SessionStore sessionStore = new TextSecureSessionStore(context);
    sessionStore.deleteAllSessions(envelope.getSource());

    SecurityEvent.broadcastSecurityUpdateEvent(context);
    MessageNotifier.updateNotification(context, masterSecret.getMasterSecret().orNull(), threadId);
  }
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:33,代码来源:PushDecryptJob.java

示例11: forHangup

import org.whispersystems.libsignal.util.guava.Optional; //导入方法依赖的package包/类
public static SignalServiceCallMessage forHangup(HangupMessage hangupMessage) {
  return new SignalServiceCallMessage(Optional.<OfferMessage>absent(),
                                      Optional.<AnswerMessage>absent(),
                                      Optional.<List<IceUpdateMessage>>absent(),
                                      Optional.of(hangupMessage),
                                      Optional.<BusyMessage>absent());
}
 
开发者ID:XecureIT,项目名称:PeSanKita-lib,代码行数:8,代码来源:SignalServiceCallMessage.java

示例12: insertMessageInbox

import org.whispersystems.libsignal.util.guava.Optional; //导入方法依赖的package包/类
private Optional<InsertResult> insertMessageInbox(MasterSecretUnion masterSecret,
                                                  IncomingMediaMessage retrieved,
                                                  String contentLocation,
                                                  long threadId, long mailbox)
    throws MmsException
{
  if (threadId == -1 || retrieved.isGroupMessage()) {
    try {
      threadId = getThreadIdFor(retrieved);
    } catch (RecipientFormattingException e) {
      Log.w("MmsDatabase", e);
      if (threadId == -1)
        throw new MmsException(e);
    }
  }

  ContentValues contentValues = new ContentValues();

  contentValues.put(DATE_SENT, retrieved.getSentTimeMillis());
  contentValues.put(ADDRESS, retrieved.getAddresses().getFrom());

  contentValues.put(MESSAGE_BOX, mailbox);
  contentValues.put(MESSAGE_TYPE, PduHeaders.MESSAGE_TYPE_RETRIEVE_CONF);
  contentValues.put(THREAD_ID, threadId);
  contentValues.put(CONTENT_LOCATION, contentLocation);
  contentValues.put(STATUS, Status.DOWNLOAD_INITIALIZED);
  contentValues.put(DATE_RECEIVED, generatePduCompatTimestamp());
  contentValues.put(PART_COUNT, retrieved.getAttachments().size());
  contentValues.put(SUBSCRIPTION_ID, retrieved.getSubscriptionId());
  contentValues.put(EXPIRES_IN, retrieved.getExpiresIn());
  contentValues.put(READ, retrieved.isExpirationUpdate() ? 1 : 0);

  if (!contentValues.containsKey(DATE_SENT)) {
    contentValues.put(DATE_SENT, contentValues.getAsLong(DATE_RECEIVED));
  }

  if (retrieved.isPushMessage() && isDuplicate(retrieved, threadId)) {
    Log.w(TAG, "Ignoring duplicate media message (" + retrieved.getSentTimeMillis() + ")");
    return Optional.absent();
  }

  long messageId = insertMediaMessage(masterSecret, retrieved.getAddresses(),
                                      retrieved.getBody(), retrieved.getAttachments(),
                                      contentValues, null);

  if (!Types.isExpirationTimerUpdate(mailbox)) {
    DatabaseFactory.getThreadDatabase(context).setUnread(threadId);
    DatabaseFactory.getThreadDatabase(context).update(threadId, true);
  }

  notifyConversationListeners(threadId);
  jobManager.add(new TrimThreadJob(context, threadId));

  return Optional.of(new InsertResult(messageId, threadId));
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:56,代码来源:MmsDatabase.java

示例13: getAvatar

import org.whispersystems.libsignal.util.guava.Optional; //导入方法依赖的package包/类
private Optional<SignalServiceAttachmentStream> getAvatar(@Nullable Uri uri) throws IOException {
  if (uri == null) {
    return Optional.absent();
  }
  
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
    try {
      Uri                 displayPhotoUri = Uri.withAppendedPath(uri, ContactsContract.Contacts.Photo.DISPLAY_PHOTO);
      AssetFileDescriptor fd              = context.getContentResolver().openAssetFileDescriptor(displayPhotoUri, "r");

      return Optional.of(SignalServiceAttachment.newStreamBuilder()
                                                .withStream(fd.createInputStream())
                                                .withContentType("image/*")
                                                .withLength(fd.getLength())
                                                .build());
    } catch (IOException e) {
      Log.w(TAG, e);
    }
  }

  Uri photoUri = Uri.withAppendedPath(uri, ContactsContract.Contacts.Photo.CONTENT_DIRECTORY);

  if (photoUri == null) {
    return Optional.absent();
  }

  Cursor cursor = context.getContentResolver().query(photoUri,
                                                     new String[] {
                                                         ContactsContract.CommonDataKinds.Photo.PHOTO,
                                                         ContactsContract.CommonDataKinds.Phone.MIMETYPE
                                                     }, null, null, null);

  try {
    if (cursor != null && cursor.moveToNext()) {
      byte[] data = cursor.getBlob(0);

      if (data != null) {
        return Optional.of(SignalServiceAttachment.newStreamBuilder()
                                                  .withStream(new ByteArrayInputStream(data))
                                                  .withContentType("image/*")
                                                  .withLength(data.length)
                                                  .build());
      }
    }

    return Optional.absent();
  } finally {
    if (cursor != null) {
      cursor.close();
    }
  }
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:53,代码来源:MultiDeviceContactUpdateJob.java

示例14: getRecipientsPreferences

import org.whispersystems.libsignal.util.guava.Optional; //导入方法依赖的package包/类
public Optional<RecipientsPreferences> getRecipientsPreferences(@NonNull long[] recipients) {
  Arrays.sort(recipients);

  SQLiteDatabase database = databaseHelper.getReadableDatabase();
  Cursor         cursor   = null;

  try {
    cursor = database.query(TABLE_NAME, null, RECIPIENT_IDS + " = ?",
                            new String[] {Util.join(recipients, " ")},
                            null, null, null);

    if (cursor != null && cursor.moveToNext()) {
      boolean blocked               = cursor.getInt(cursor.getColumnIndexOrThrow(BLOCK))                == 1;
      String  notification          = cursor.getString(cursor.getColumnIndexOrThrow(NOTIFICATION));
      int     vibrateState          = cursor.getInt(cursor.getColumnIndexOrThrow(VIBRATE));
      long    muteUntil             = cursor.getLong(cursor.getColumnIndexOrThrow(MUTE_UNTIL));
      String  serializedColor       = cursor.getString(cursor.getColumnIndexOrThrow(COLOR));
      Uri     notificationUri       = notification == null ? null : Uri.parse(notification);
      boolean seenInviteReminder    = cursor.getInt(cursor.getColumnIndexOrThrow(SEEN_INVITE_REMINDER)) == 1;
      int     defaultSubscriptionId = cursor.getInt(cursor.getColumnIndexOrThrow(DEFAULT_SUBSCRIPTION_ID));
      int     expireMessages        = cursor.getInt(cursor.getColumnIndexOrThrow(EXPIRE_MESSAGES));

      MaterialColor color;

      try {
        color = serializedColor == null ? null : MaterialColor.fromSerialized(serializedColor);
      } catch (MaterialColor.UnknownColorException e) {
        Log.w(TAG, e);
        color = null;
      }

      Log.w(TAG, "Muted until: " + muteUntil);

      return Optional.of(new RecipientsPreferences(blocked, muteUntil,
                                                   VibrateState.fromId(vibrateState),
                                                   notificationUri, color, seenInviteReminder,
                                                   defaultSubscriptionId, expireMessages));
    }

    return Optional.absent();
  } finally {
    if (cursor != null) cursor.close();
  }
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:45,代码来源:RecipientPreferenceDatabase.java

示例15: IncomingJoinedMessage

import org.whispersystems.libsignal.util.guava.Optional; //导入方法依赖的package包/类
public IncomingJoinedMessage(String sender) {
  super(sender, 1, System.currentTimeMillis(), null, Optional.<SignalServiceGroup>absent(), 0);
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:4,代码来源:IncomingJoinedMessage.java


注:本文中的org.whispersystems.libsignal.util.guava.Optional.absent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。