Search in sources :

Example 21 with Pair

use of org.whispersystems.libsignal.util.Pair in project Signal-Android by signalapp.

the class CdshService method createTlsSocketFactory.

private static Pair<SSLSocketFactory, X509TrustManager> createTlsSocketFactory(TrustStore trustStore) {
    try {
        SSLContext context = SSLContext.getInstance("TLS");
        TrustManager[] trustManagers = BlacklistingTrustManager.createFor(trustStore);
        context.init(null, trustManagers, null);
        return new Pair<>(context.getSocketFactory(), (X509TrustManager) trustManagers[0]);
    } catch (NoSuchAlgorithmException | KeyManagementException e) {
        throw new AssertionError(e);
    }
}
Also used : SSLContext(javax.net.ssl.SSLContext) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) KeyManagementException(java.security.KeyManagementException) TrustManager(javax.net.ssl.TrustManager) X509TrustManager(javax.net.ssl.X509TrustManager) BlacklistingTrustManager(org.whispersystems.signalservice.internal.util.BlacklistingTrustManager) Pair(org.whispersystems.libsignal.util.Pair)

Example 22 with Pair

use of org.whispersystems.libsignal.util.Pair in project Signal-Android by signalapp.

the class SearchUtil method getStrictHighlightRanges.

static List<Pair<Integer, Integer>> getStrictHighlightRanges(@NonNull Locale locale, @NonNull String text, @NonNull String highlight) {
    if (text.length() == 0) {
        return Collections.emptyList();
    }
    String normalizedText = text.toLowerCase(locale);
    String normalizedHighlight = highlight.toLowerCase(locale);
    List<String> highlightTokens = Stream.of(normalizedHighlight.split("\\s")).filter(s -> s.trim().length() > 0).toList();
    List<Pair<Integer, Integer>> ranges = new LinkedList<>();
    int lastHighlightEndIndex = 0;
    for (String highlightToken : highlightTokens) {
        int index;
        do {
            index = normalizedText.indexOf(highlightToken, lastHighlightEndIndex);
            lastHighlightEndIndex = index + highlightToken.length();
        } while (index > 0 && !Character.isWhitespace(normalizedText.charAt(index - 1)));
        if (index >= 0) {
            ranges.add(new Pair<>(index, lastHighlightEndIndex));
        }
        if (index < 0 || lastHighlightEndIndex >= normalizedText.length()) {
            break;
        }
    }
    if (ranges.size() != highlightTokens.size()) {
        return Collections.emptyList();
    }
    return ranges;
}
Also used : Stream(com.annimon.stream.Stream) SpannableString(android.text.SpannableString) NonNull(androidx.annotation.NonNull) Spannable(android.text.Spannable) TextUtils(android.text.TextUtils) Pair(org.whispersystems.libsignal.util.Pair) List(java.util.List) Nullable(androidx.annotation.Nullable) InvalidParameterException(java.security.InvalidParameterException) Locale(java.util.Locale) CharacterStyle(android.text.style.CharacterStyle) LinkedList(java.util.LinkedList) Collections(java.util.Collections) SpannableString(android.text.SpannableString) LinkedList(java.util.LinkedList) Pair(org.whispersystems.libsignal.util.Pair)

Example 23 with Pair

use of org.whispersystems.libsignal.util.Pair in project Signal-Android by signalapp.

the class SearchUtil method getHighlightRanges.

static List<Pair<Integer, Integer>> getHighlightRanges(@NonNull Locale locale, @NonNull String text, @NonNull String highlight) {
    if (text.length() == 0) {
        return Collections.emptyList();
    }
    String normalizedText = text.toLowerCase(locale);
    String normalizedHighlight = highlight.toLowerCase(locale);
    List<String> highlightTokens = Stream.of(normalizedHighlight.split("\\s")).filter(s -> s.trim().length() > 0).toList();
    List<Pair<Integer, Integer>> ranges = new LinkedList<>();
    int lastHighlightEndIndex = 0;
    for (String highlightToken : highlightTokens) {
        int index = 0;
        lastHighlightEndIndex = 0;
        while (index != -1) {
            index = normalizedText.indexOf(highlightToken, lastHighlightEndIndex);
            if (index != -1) {
                lastHighlightEndIndex = index + highlightToken.length();
                ranges.add(new Pair<>(index, lastHighlightEndIndex));
                index = lastHighlightEndIndex;
            }
        }
    }
    return ranges;
}
Also used : Stream(com.annimon.stream.Stream) SpannableString(android.text.SpannableString) NonNull(androidx.annotation.NonNull) Spannable(android.text.Spannable) TextUtils(android.text.TextUtils) Pair(org.whispersystems.libsignal.util.Pair) List(java.util.List) Nullable(androidx.annotation.Nullable) InvalidParameterException(java.security.InvalidParameterException) Locale(java.util.Locale) CharacterStyle(android.text.style.CharacterStyle) LinkedList(java.util.LinkedList) Collections(java.util.Collections) SpannableString(android.text.SpannableString) LinkedList(java.util.LinkedList) Pair(org.whispersystems.libsignal.util.Pair)

Example 24 with Pair

use of org.whispersystems.libsignal.util.Pair in project Signal-Android by signalapp.

the class SearchUtil method getHighlightedSpan.

public static Spannable getHighlightedSpan(@NonNull Locale locale, @NonNull StyleFactory styleFactory, @Nullable Spannable text, @Nullable String highlight, int matchMode) {
    if (TextUtils.isEmpty(text)) {
        return new SpannableString("");
    }
    if (TextUtils.isEmpty(highlight)) {
        return text;
    }
    SpannableString spanned = new SpannableString(text);
    List<Pair<Integer, Integer>> ranges;
    switch(matchMode) {
        case STRICT:
            ranges = getStrictHighlightRanges(locale, text.toString(), highlight);
            break;
        case MATCH_ALL:
            ranges = getHighlightRanges(locale, text.toString(), highlight);
            break;
        default:
            throw new InvalidParameterException("match mode must be STRICT or MATCH_ALL: " + matchMode);
    }
    if (matchMode == STRICT) {
        ranges = getStrictHighlightRanges(locale, text.toString(), highlight);
    } else {
        ranges = getHighlightRanges(locale, text.toString(), highlight);
    }
    for (Pair<Integer, Integer> range : ranges) {
        spanned.setSpan(styleFactory.create(), range.first(), range.second(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
    }
    return spanned;
}
Also used : SpannableString(android.text.SpannableString) InvalidParameterException(java.security.InvalidParameterException) Pair(org.whispersystems.libsignal.util.Pair)

Example 25 with Pair

use of org.whispersystems.libsignal.util.Pair in project Signal-Android by signalapp.

the class LogSectionPermissions method getContent.

@Override
@NonNull
public CharSequence getContent(@NonNull Context context) {
    StringBuilder out = new StringBuilder();
    List<Pair<String, Boolean>> status = new ArrayList<>();
    try {
        PackageInfo info = context.getPackageManager().getPackageInfo(BuildConfig.APPLICATION_ID, PackageManager.GET_PERMISSIONS);
        for (int i = 0; i < info.requestedPermissions.length; i++) {
            status.add(new Pair<>(info.requestedPermissions[i], (info.requestedPermissionsFlags[i] & PackageInfo.REQUESTED_PERMISSION_GRANTED) != 0));
        }
    } catch (PackageManager.NameNotFoundException e) {
        return "Unable to retrieve.";
    }
    Collections.sort(status, (o1, o2) -> o1.first().compareTo(o2.first()));
    for (Pair<String, Boolean> pair : status) {
        out.append(pair.first()).append(": ");
        out.append(pair.second() ? "YES" : "NO");
        out.append("\n");
    }
    return out;
}
Also used : PackageManager(android.content.pm.PackageManager) PackageInfo(android.content.pm.PackageInfo) ArrayList(java.util.ArrayList) Pair(org.whispersystems.libsignal.util.Pair) NonNull(androidx.annotation.NonNull)

Aggregations

Pair (org.whispersystems.libsignal.util.Pair)49 NonNull (androidx.annotation.NonNull)26 List (java.util.List)18 LinkedList (java.util.LinkedList)15 Context (android.content.Context)14 Stream (com.annimon.stream.Stream)14 IOException (java.io.IOException)14 Recipient (org.thoughtcrime.securesms.recipients.Recipient)14 RecipientId (org.thoughtcrime.securesms.recipients.RecipientId)14 Nullable (androidx.annotation.Nullable)12 SpannableString (android.text.SpannableString)10 TextUtils (android.text.TextUtils)10 ArrayList (java.util.ArrayList)10 Collections (java.util.Collections)10 Cursor (android.database.Cursor)9 ContentValues (android.content.ContentValues)8 HashSet (java.util.HashSet)8 Locale (java.util.Locale)8 Set (java.util.Set)8 Log (org.signal.core.util.logging.Log)8