List of usage examples for android.text SpannableStringBuilder replace
public SpannableStringBuilder replace(int start, int end, CharSequence tb)
From source file:com.tct.mail.browse.ConversationItemView.java
private void createSubject(final boolean isUnread) { final String badgeText = mHeader.badgeText == null ? "" : mHeader.badgeText; String subject = filterTag(getContext(), mHeader.conversation.subject); subject = Conversation.getSubjectForDisplay(mContext, badgeText, subject); /// TCT: add for search term highlight // process subject and snippet respectively @{ SpannableStringBuilder subjectToHighlight = new SpannableStringBuilder(subject); boolean hasFilter = (mSearchParams != null && !TextUtils.isEmpty(mSearchParams.mFilter)); if (hasFilter) { boolean fieldMatchedSubject = (mSearchParams != null && (SearchParams.SEARCH_FIELD_SUBJECT.equals(mSearchParams.mField) || SearchParams.SEARCH_FIELD_ALL.equals(mSearchParams.mField))); /// TCT: Only highlight un-empty subject if (fieldMatchedSubject && !TextUtils.isEmpty(subject)) { CharSequence subjectChars = TextUtilities.highlightTermsInText(subject, mSearchParams.mFilter); subjectToHighlight.replace(0, subject.length(), subjectChars); }// ww w . ja v a2s . c om } /// @} final Spannable displayedStringBuilder = new SpannableString(subjectToHighlight); // since spans affect text metrics, add spans to the string before measure/layout or fancy // ellipsizing final int badgeTextLength = formatBadgeText(displayedStringBuilder, badgeText); if (!TextUtils.isEmpty(subject)) { displayedStringBuilder.setSpan( TextAppearanceSpan.wrap(isUnread ? sSubjectTextUnreadSpan : sSubjectTextReadSpan), badgeTextLength, subject.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } if (isActivated() && showActivatedText()) { displayedStringBuilder.setSpan(sActivatedTextSpan, badgeTextLength, displayedStringBuilder.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE); } final int subjectWidth = mSubjectWidth;//TS: yanhua.chen 2015-9-2 EMAIL CR_540046 MOD final int subjectHeight = mCoordinates.subjectHeight; mSubjectTextView.setLayoutParams(new ViewGroup.LayoutParams(subjectWidth, subjectHeight)); mSubjectTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mCoordinates.subjectFontSize); layoutViewExactly(mSubjectTextView, subjectWidth, subjectHeight); //[FEATURE]-Mod-BEGIN by CDTS.zhonghua.tuo,05/29/2014,FR 670064 SpannableStringBuilder builder = new SpannableStringBuilder(); boolean filterSubject = false; if (mField == UIProvider.LOCAL_SEARCH_ALL || mField == UIProvider.LOCAL_SEARCH_SUBJECT) { filterSubject = true; } if (mQueryText != null && filterSubject) { CharSequence formatSubject = displayedStringBuilder; formatSubject = TextUtilities.highlightTermsInText(subject, mQueryText); builder.append(formatSubject); mSubjectTextView.setText(builder); // TS: chao.zhang 2015-09-14 EMAIL FEATURE-585337 ADD_S //store the displayed subject for calculate the statusView's X and width mHeader.subjectText = builder.toString(); // TS: chao.zhang 2015-09-14 EMAIL FEATURE-585337 ADD_E } else { mSubjectTextView.setText(displayedStringBuilder); // TS: chao.zhang 2015-09-14 EMAIL FEATURE-585337 ADD_S mHeader.subjectText = displayedStringBuilder.toString(); // TS: chao.zhang 2015-09-14 EMAIL FEATURE-585337 ADD_E } //[FEATURE]-Mod-END by CDTS.zhonghua.tuo }
From source file:com.juick.android.JuickMessagesAdapter.java
public static ParsedMessage formatMessageText(final Context ctx, final JuickMessage jmsg, boolean condensed) { if (jmsg.parsedText != null) { return (ParsedMessage) jmsg.parsedText; // was parsed before }//from w w w.j av a 2 s . c o m getColorTheme(ctx); SpannableStringBuilder ssb = new SpannableStringBuilder(); int spanOffset = 0; final boolean isMainMessage = jmsg.getRID() == 0; final boolean doCompactComment = !isMainMessage && compactComments; if (jmsg.continuationInformation != null) { ssb.append(jmsg.continuationInformation + "\n"); ssb.setSpan(new StyleSpan(Typeface.ITALIC), spanOffset, ssb.length() - 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } // // NAME // spanOffset = ssb.length(); String name = '@' + jmsg.User.UName; int userNameStart = ssb.length(); ssb.append(name); int userNameEnd = ssb.length(); StyleSpan userNameBoldSpan; ForegroundColorSpan userNameColorSpan; ssb.setSpan(userNameBoldSpan = new StyleSpan(Typeface.BOLD), spanOffset, ssb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); ssb.setSpan( userNameColorSpan = new ForegroundColorSpan( colorTheme.getColor(ColorsTheme.ColorKey.USERNAME, 0xFFC8934E)), spanOffset, ssb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); if (helvNueFonts) { ssb.setSpan(new CustomTypefaceSpan("", JuickAdvancedApplication.helvNueBold), spanOffset, ssb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } ssb.append(' '); spanOffset = ssb.length(); if (!condensed) { // // TAGS // String tags = jmsg.getTags(); if (feedlyFonts) tags = tags.toUpperCase(); ssb.append(tags + "\n"); if (tags.length() > 0) { ssb.setSpan(new ForegroundColorSpan(colorTheme.getColor(ColorsTheme.ColorKey.TAGS, 0xFF0000CC)), spanOffset, ssb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); if (feedlyFonts) { ssb.setSpan(new CustomTypefaceSpan("", JuickAdvancedApplication.dinWebPro), spanOffset, ssb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } else if (helvNueFonts) { ssb.setSpan(new CustomTypefaceSpan("", JuickAdvancedApplication.helvNue), spanOffset, ssb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } spanOffset = ssb.length(); } if (jmsg.translated) { // // 'translated' // ssb.append("translated: "); ssb.setSpan( new ForegroundColorSpan(colorTheme.getColor(ColorsTheme.ColorKey.TRANSLATED_LABEL, 0xFF4ec856)), spanOffset, ssb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); ssb.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), spanOffset, ssb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); spanOffset = ssb.length(); } int bodyOffset = ssb.length(); int messageNumberStart = -1, messageNumberEnd = -1; if (showNumbers(ctx) && !condensed) { // // numbers // if (isMainMessage) { messageNumberStart = ssb.length(); ssb.append(jmsg.getDisplayMessageNo()); messageNumberEnd = ssb.length(); } else { ssb.append("/" + jmsg.getRID()); if (jmsg.getReplyTo() != 0) { ssb.append("->" + jmsg.getReplyTo()); } } ssb.append(" "); ssb.setSpan(new ForegroundColorSpan(colorTheme.getColor(ColorsTheme.ColorKey.MESSAGE_ID, 0xFFa0a5bd)), spanOffset, ssb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); spanOffset = ssb.length(); } // // MESSAGE BODY // String txt = Censor.getCensoredText(jmsg.Text); if (!condensed) { if (jmsg.Photo != null) { txt = jmsg.Photo + "\n" + txt; } if (jmsg.Video != null) { txt = jmsg.Video + "\n" + txt; } } ssb.append(txt); boolean ssbChanged = false; // allocation optimization // Highlight links http://example.com/ ArrayList<ExtractURLFromMessage.FoundURL> foundURLs = ExtractURLFromMessage.extractUrls(txt, jmsg.getMID()); ArrayList<String> urls = new ArrayList<String>(); for (ExtractURLFromMessage.FoundURL foundURL : foundURLs) { setSSBSpan(ssb, new ForegroundColorSpan(colorTheme.getColor(ColorsTheme.ColorKey.URLS, 0xFF0000CC)), spanOffset + foundURL.start, spanOffset + foundURL.end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); urls.add(foundURL.url); if (foundURL.title != null) { ssb.replace(spanOffset + foundURL.title.start - 1, spanOffset + foundURL.title.start, " "); ssb.replace(spanOffset + foundURL.title.end, spanOffset + foundURL.title.end + 1, " "); ssb.replace(spanOffset + foundURL.start - 1, spanOffset + foundURL.start, "("); ssb.replace(spanOffset + foundURL.end, spanOffset + foundURL.end + 1, ")"); ssb.setSpan(new StyleSpan(Typeface.BOLD), spanOffset + foundURL.title.start, spanOffset + foundURL.title.end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } ssbChanged = true; } // bold italic underline if (jmsg.Text.indexOf("*") != -1) { setStyleSpans(ssb, spanOffset, Typeface.BOLD, "*"); ssbChanged = true; } if (jmsg.Text.indexOf("/") != 0) { setStyleSpans(ssb, spanOffset, Typeface.ITALIC, "/"); ssbChanged = true; } if (jmsg.Text.indexOf("_") != 0) { setStyleSpans(ssb, spanOffset, UnderlineSpan.class, "_"); ssbChanged = true; } if (ssbChanged) { txt = ssb.subSequence(spanOffset, ssb.length()).toString(); // ssb was modified in between } // Highlight nick String accountName = XMPPService.getMyAccountName(jmsg.getMID(), ctx); if (accountName != null) { int scan = spanOffset; String nickScanArea = (ssb + " ").toUpperCase(); while (true) { int myNick = nickScanArea.indexOf("@" + accountName.toUpperCase(), scan); if (myNick != -1) { if (!isNickPart(nickScanArea.charAt(myNick + accountName.length() + 1))) { setSSBSpan(ssb, new BackgroundColorSpan( colorTheme.getColor(ColorsTheme.ColorKey.USERNAME_ME, 0xFF938e00)), myNick - 1, myNick + accountName.length() + 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } scan = myNick + 1; } else { break; } } } // Highlight messages #1234 int pos = 0; Matcher m = getCrossReferenceMsgPattern(jmsg.getMID()).matcher(txt); while (m.find(pos)) { ssb.setSpan(new ForegroundColorSpan(colorTheme.getColor(ColorsTheme.ColorKey.URLS, 0xFF0000CC)), spanOffset + m.start(), spanOffset + m.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); pos = m.end(); } SpannableStringBuilder compactDt = null; if (!condensed) { // found messages count (search results) if (jmsg.myFoundCount != 0 || jmsg.hisFoundCount != 0) { ssb.append("\n"); int where = ssb.length(); if (jmsg.myFoundCount != 0) { ssb.append(ctx.getString(R.string.MyReplies_) + jmsg.myFoundCount + " "); } if (jmsg.hisFoundCount != 0) { ssb.append(ctx.getString(R.string.UserReplies_) + jmsg.hisFoundCount); } ssb.setSpan( new ForegroundColorSpan( colorTheme.getColor(ColorsTheme.ColorKey.TRANSLATED_LABEL, 0xFF4ec856)), where, ssb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } int rightPartOffset = spanOffset = ssb.length(); if (!doCompactComment) { // // TIME (bottom of message) // try { DateFormat df = new SimpleDateFormat("HH:mm dd/MMM/yy"); String date = jmsg.Timestamp != null ? df.format(jmsg.Timestamp) : "[bad date]"; if (date.endsWith("/76")) date = date.substring(0, date.length() - 3); // special case for no year in datasource ssb.append("\n" + date + " "); } catch (Exception e) { ssb.append("\n[fmt err] "); } ssb.setSpan(new ForegroundColorSpan(colorTheme.getColor(ColorsTheme.ColorKey.DATE, 0xFFAAAAAA)), spanOffset, ssb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } else { compactDt = new SpannableStringBuilder(); try { if (true || jmsg.deltaTime != Long.MIN_VALUE) { compactDt.append(com.juickadvanced.Utils.toRelaviteDate(jmsg.Timestamp.getTime(), russian)); } else { DateFormat df = new SimpleDateFormat("HH:mm dd/MMM/yy"); String date = jmsg.Timestamp != null ? df.format(jmsg.Timestamp) : "[bad date]"; if (date.endsWith("/76")) date = date.substring(0, date.length() - 3); // special case for no year in datasource compactDt.append(date); } } catch (Exception e) { compactDt.append("\n[fmt err] "); } compactDt.setSpan( new ForegroundColorSpan(colorTheme.getColor(ColorsTheme.ColorKey.DATE, 0xFFAAAAAA)), 0, compactDt.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } spanOffset = ssb.length(); // // Number of REPLIES // if (jmsg.replies > 0) { String replies = Replies + jmsg.replies; ssb.append(" " + replies); ssb.setSpan( new ForegroundColorSpan( colorTheme.getColor(ColorsTheme.ColorKey.NUMBER_OF_COMMENTS, 0xFFC8934E)), spanOffset, ssb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); ssb.setSpan(new WrapTogetherSpan() { }, spanOffset, ssb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } if (!doCompactComment) { // right align ssb.setSpan(new AlignmentSpan.Standard(Alignment.ALIGN_OPPOSITE), rightPartOffset, ssb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } if (helvNueFonts) { ssb.setSpan(new CustomTypefaceSpan("", JuickAdvancedApplication.helvNue), bodyOffset, ssb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } LeadingMarginSpan.LeadingMarginSpan2 userpicSpan = null; if (showUserpics(ctx) && !condensed) { userpicSpan = new LeadingMarginSpan.LeadingMarginSpan2() { @Override public int getLeadingMarginLineCount() { if (_wrapUserpics) { return 2; } else { return 22222; } } @Override public int getLeadingMargin(boolean first) { if (first) { return (int) (2 * getLineHeight(ctx, (double) textScale)); } else { return 0; } } @Override public void drawLeadingMargin(Canvas c, Paint p, int x, int dir, int top, int baseline, int bottom, CharSequence text, int start, int end, boolean first, Layout layout) { } }; ssb.setSpan(userpicSpan, 0, ssb.length(), 0); } ParsedMessage parsedMessage = new ParsedMessage(ssb, urls); parsedMessage.userpicSpan = userpicSpan; parsedMessage.userNameBoldSpan = userNameBoldSpan; parsedMessage.userNameColorSpan = userNameColorSpan; parsedMessage.userNameStart = userNameStart; parsedMessage.userNameEnd = userNameEnd; parsedMessage.messageNumberStart = messageNumberStart; parsedMessage.messageNumberEnd = messageNumberEnd; parsedMessage.compactDate = compactDt; return parsedMessage; }
From source file:org.telegram.ui.PassportActivity.java
@Override public View createView(Context context) { actionBar.setBackButtonImage(R.drawable.ic_ab_back); actionBar.setAllowOverlayTitle(true); actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() { private boolean onIdentityDone(Runnable finishRunnable, ErrorRunnable errorRunnable) { if (!uploadingDocuments.isEmpty() || checkFieldsForError()) { return false; }/*www . j a v a2 s. c o m*/ if (allowNonLatinName) { allowNonLatinName = false; boolean error = false; for (int a = 0; a < nonLatinNames.length; a++) { if (nonLatinNames[a]) { inputFields[a].setErrorText(LocaleController.getString("PassportUseLatinOnly", R.string.PassportUseLatinOnly)); if (!error) { error = true; String firstName = nonLatinNames[0] ? getTranslitString( inputExtraFields[FIELD_NATIVE_NAME].getText().toString()) : inputFields[FIELD_NAME].getText().toString(); String middleName = nonLatinNames[1] ? getTranslitString( inputExtraFields[FIELD_NATIVE_MIDNAME].getText().toString()) : inputFields[FIELD_MIDNAME].getText().toString(); String lastName = nonLatinNames[2] ? getTranslitString( inputExtraFields[FIELD_NATIVE_SURNAME].getText().toString()) : inputFields[FIELD_SURNAME].getText().toString(); if (!TextUtils.isEmpty(firstName) && !TextUtils.isEmpty(middleName) && !TextUtils.isEmpty(lastName)) { int num = a; AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setMessage(LocaleController.formatString("PassportNameCheckAlert", R.string.PassportNameCheckAlert, firstName, middleName, lastName)); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setPositiveButton(LocaleController.getString("Done", R.string.Done), (dialogInterface, i) -> { inputFields[FIELD_NAME].setText(firstName); inputFields[FIELD_MIDNAME].setText(middleName); inputFields[FIELD_SURNAME].setText(lastName); showEditDoneProgress(true, true); onIdentityDone(finishRunnable, errorRunnable); }); builder.setNegativeButton(LocaleController.getString("Edit", R.string.Edit), (dialogInterface, i) -> onFieldError(inputFields[num])); showDialog(builder.create()); } else { onFieldError(inputFields[a]); } } } } if (error) { return false; } } if (isHasNotAnyChanges()) { finishFragment(); return false; } JSONObject json = null; JSONObject documentsJson = null; try { if (!documentOnly) { HashMap<String, String> valuesToSave = new HashMap<>(currentValues); if (currentType.native_names) { if (nativeInfoCell.getVisibility() == View.VISIBLE) { valuesToSave.put("first_name_native", inputExtraFields[FIELD_NATIVE_NAME].getText().toString()); valuesToSave.put("middle_name_native", inputExtraFields[FIELD_NATIVE_MIDNAME].getText().toString()); valuesToSave.put("last_name_native", inputExtraFields[FIELD_NATIVE_SURNAME].getText().toString()); } else { valuesToSave.put("first_name_native", inputFields[FIELD_NATIVE_NAME].getText().toString()); valuesToSave.put("middle_name_native", inputFields[FIELD_NATIVE_MIDNAME].getText().toString()); valuesToSave.put("last_name_native", inputFields[FIELD_NATIVE_SURNAME].getText().toString()); } } valuesToSave.put("first_name", inputFields[FIELD_NAME].getText().toString()); valuesToSave.put("middle_name", inputFields[FIELD_MIDNAME].getText().toString()); valuesToSave.put("last_name", inputFields[FIELD_SURNAME].getText().toString()); valuesToSave.put("birth_date", inputFields[FIELD_BIRTHDAY].getText().toString()); valuesToSave.put("gender", currentGender); valuesToSave.put("country_code", currentCitizeship); valuesToSave.put("residence_country_code", currentResidence); json = new JSONObject(); ArrayList<String> keys = new ArrayList<>(valuesToSave.keySet()); Collections.sort(keys, (key1, key2) -> { int val1 = getFieldCost(key1); int val2 = getFieldCost(key2); if (val1 < val2) { return -1; } else if (val1 > val2) { return 1; } return 0; }); for (int a = 0, size = keys.size(); a < size; a++) { String key = keys.get(a); json.put(key, valuesToSave.get(key)); } } if (currentDocumentsType != null) { HashMap<String, String> valuesToSave = new HashMap<>(currentDocumentValues); valuesToSave.put("document_no", inputFields[FIELD_CARDNUMBER].getText().toString()); if (currentExpireDate[0] != 0) { valuesToSave.put("expiry_date", String.format(Locale.US, "%02d.%02d.%d", currentExpireDate[2], currentExpireDate[1], currentExpireDate[0])); } else { valuesToSave.put("expiry_date", ""); } documentsJson = new JSONObject(); ArrayList<String> keys = new ArrayList<>(valuesToSave.keySet()); Collections.sort(keys, (key1, key2) -> { int val1 = getFieldCost(key1); int val2 = getFieldCost(key2); if (val1 < val2) { return -1; } else if (val1 > val2) { return 1; } return 0; }); for (int a = 0, size = keys.size(); a < size; a++) { String key = keys.get(a); documentsJson.put(key, valuesToSave.get(key)); } } } catch (Exception ignore) { } if (fieldsErrors != null) { fieldsErrors.clear(); } if (documentsErrors != null) { documentsErrors.clear(); } delegate.saveValue(currentType, null, json != null ? json.toString() : null, currentDocumentsType, documentsJson != null ? documentsJson.toString() : null, null, selfieDocument, translationDocuments, frontDocument, reverseLayout != null && reverseLayout.getVisibility() == View.VISIBLE ? reverseDocument : null, finishRunnable, errorRunnable); return true; } @Override public void onItemClick(int id) { if (id == -1) { if (checkDiscard()) { return; } if (currentActivityType == TYPE_REQUEST || currentActivityType == TYPE_PASSWORD) { callCallback(false); } finishFragment(); } else if (id == info_item) { if (getParentActivity() == null) { return; } final TextView message = new TextView(getParentActivity()); String str2 = LocaleController.getString("PassportInfo2", R.string.PassportInfo2); SpannableStringBuilder spanned = new SpannableStringBuilder(str2); int index1 = str2.indexOf('*'); int index2 = str2.lastIndexOf('*'); if (index1 != -1 && index2 != -1) { spanned.replace(index2, index2 + 1, ""); spanned.replace(index1, index1 + 1, ""); spanned.setSpan(new URLSpanNoUnderline( LocaleController.getString("PassportInfoUrl", R.string.PassportInfoUrl)) { @Override public void onClick(View widget) { dismissCurrentDialig(); super.onClick(widget); } }, index1, index2 - 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } message.setText(spanned); message.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16); message.setLinkTextColor(Theme.getColor(Theme.key_dialogTextLink)); message.setHighlightColor(Theme.getColor(Theme.key_dialogLinkSelection)); message.setPadding(AndroidUtilities.dp(23), 0, AndroidUtilities.dp(23), 0); message.setMovementMethod(new AndroidUtilities.LinkMovementMethodMy()); message.setTextColor(Theme.getColor(Theme.key_dialogTextBlack)); AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setView(message); builder.setTitle(LocaleController.getString("PassportInfoTitle", R.string.PassportInfoTitle)); builder.setNegativeButton(LocaleController.getString("Close", R.string.Close), null); showDialog(builder.create()); } else if (id == done_button) { if (currentActivityType == TYPE_PASSWORD) { onPasswordDone(false); return; } if (currentActivityType == TYPE_PHONE_VERIFICATION) { views[currentViewNum].onNextPressed(); } else { final Runnable finishRunnable = () -> finishFragment(); final ErrorRunnable errorRunnable = new ErrorRunnable() { @Override public void onError(String error, String text) { if ("PHONE_VERIFICATION_NEEDED".equals(error)) { startPhoneVerification(true, text, finishRunnable, this, delegate); } else { showEditDoneProgress(true, false); } } }; if (currentActivityType == TYPE_EMAIL) { String value; if (useCurrentValue) { value = currentEmail; } else { if (checkFieldsForError()) { return; } value = inputFields[FIELD_EMAIL].getText().toString(); } delegate.saveValue(currentType, value, null, null, null, null, null, null, null, null, finishRunnable, errorRunnable); } else if (currentActivityType == TYPE_PHONE) { String value; if (useCurrentValue) { value = UserConfig.getInstance(currentAccount).getCurrentUser().phone; } else { if (checkFieldsForError()) { return; } value = inputFields[FIELD_PHONECODE].getText().toString() + inputFields[FIELD_PHONE].getText().toString(); } delegate.saveValue(currentType, value, null, null, null, null, null, null, null, null, finishRunnable, errorRunnable); } else if (currentActivityType == TYPE_ADDRESS) { if (!uploadingDocuments.isEmpty() || checkFieldsForError()) { return; } if (isHasNotAnyChanges()) { finishFragment(); return; } JSONObject json = null; try { if (!documentOnly) { json = new JSONObject(); json.put("street_line1", inputFields[FIELD_STREET1].getText().toString()); json.put("street_line2", inputFields[FIELD_STREET2].getText().toString()); json.put("post_code", inputFields[FIELD_POSTCODE].getText().toString()); json.put("city", inputFields[FIELD_CITY].getText().toString()); json.put("state", inputFields[FIELD_STATE].getText().toString()); json.put("country_code", currentCitizeship); } } catch (Exception ignore) { } if (fieldsErrors != null) { fieldsErrors.clear(); } if (documentsErrors != null) { documentsErrors.clear(); } delegate.saveValue(currentType, null, json != null ? json.toString() : null, currentDocumentsType, null, documents, selfieDocument, translationDocuments, null, null, finishRunnable, errorRunnable); } else if (currentActivityType == TYPE_IDENTITY) { if (!onIdentityDone(finishRunnable, errorRunnable)) { return; } } else if (currentActivityType == TYPE_EMAIL_VERIFICATION) { final TLRPC.TL_account_verifyEmail req = new TLRPC.TL_account_verifyEmail(); req.email = currentValues.get("email"); req.code = inputFields[FIELD_EMAIL].getText().toString(); int reqId = ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> { if (error == null) { delegate.saveValue(currentType, currentValues.get("email"), null, null, null, null, null, null, null, null, finishRunnable, errorRunnable); } else { AlertsCreator.processError(currentAccount, error, PassportActivity.this, req); errorRunnable.onError(null, null); } })); ConnectionsManager.getInstance(currentAccount).bindRequestToGuid(reqId, classGuid); } showEditDoneProgress(true, true); } } } }); if (currentActivityType == TYPE_PHONE_VERIFICATION) { fragmentView = scrollView = new ScrollView(context) { @Override protected boolean onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect) { return false; } @Override public boolean requestChildRectangleOnScreen(View child, Rect rectangle, boolean immediate) { if (currentViewNum == 1 || currentViewNum == 2 || currentViewNum == 4) { rectangle.bottom += AndroidUtilities.dp(40); } return super.requestChildRectangleOnScreen(child, rectangle, immediate); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { scrollHeight = MeasureSpec.getSize(heightMeasureSpec) - AndroidUtilities.dp(30); super.onMeasure(widthMeasureSpec, heightMeasureSpec); } }; scrollView.setFillViewport(true); AndroidUtilities.setScrollViewEdgeEffectColor(scrollView, Theme.getColor(Theme.key_actionBarDefault)); } else { fragmentView = new FrameLayout(context); FrameLayout frameLayout = (FrameLayout) fragmentView; fragmentView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundGray)); scrollView = new ScrollView(context) { @Override protected boolean onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect) { return false; } @Override public boolean requestChildRectangleOnScreen(View child, Rect rectangle, boolean immediate) { rectangle.offset(child.getLeft() - child.getScrollX(), child.getTop() - child.getScrollY()); rectangle.top += AndroidUtilities.dp(20); rectangle.bottom += AndroidUtilities.dp(50); return super.requestChildRectangleOnScreen(child, rectangle, immediate); } }; scrollView.setFillViewport(true); AndroidUtilities.setScrollViewEdgeEffectColor(scrollView, Theme.getColor(Theme.key_actionBarDefault)); frameLayout.addView(scrollView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP, 0, 0, 0, currentActivityType == TYPE_REQUEST ? 48 : 0)); linearLayout2 = new LinearLayout(context); linearLayout2.setOrientation(LinearLayout.VERTICAL); scrollView.addView(linearLayout2, new ScrollView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); } if (currentActivityType != TYPE_REQUEST && currentActivityType != TYPE_MANAGE) { ActionBarMenu menu = actionBar.createMenu(); doneItem = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56)); progressView = new ContextProgressView(context, 1); progressView.setAlpha(0.0f); progressView.setScaleX(0.1f); progressView.setScaleY(0.1f); progressView.setVisibility(View.INVISIBLE); doneItem.addView(progressView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT)); if (currentActivityType == TYPE_IDENTITY || currentActivityType == TYPE_ADDRESS) { if (chatAttachAlert != null) { try { if (chatAttachAlert.isShowing()) { chatAttachAlert.dismiss(); } } catch (Exception ignore) { } chatAttachAlert.onDestroy(); chatAttachAlert = null; } } } if (currentActivityType == TYPE_PASSWORD) { createPasswordInterface(context); } else if (currentActivityType == TYPE_REQUEST) { createRequestInterface(context); } else if (currentActivityType == TYPE_IDENTITY) { createIdentityInterface(context); fillInitialValues(); } else if (currentActivityType == TYPE_ADDRESS) { createAddressInterface(context); fillInitialValues(); } else if (currentActivityType == TYPE_PHONE) { createPhoneInterface(context); } else if (currentActivityType == TYPE_EMAIL) { createEmailInterface(context); } else if (currentActivityType == TYPE_EMAIL_VERIFICATION) { createEmailVerificationInterface(context); } else if (currentActivityType == TYPE_PHONE_VERIFICATION) { createPhoneVerificationInterface(context); } else if (currentActivityType == TYPE_MANAGE) { createManageInterface(context); } return fragmentView; }
From source file:org.telegram.ui.PassportActivity.java
private void createRequestInterface(Context context) { TLRPC.User botUser = null;//from ww w .java 2 s. c o m if (currentForm != null) { for (int a = 0; a < currentForm.users.size(); a++) { TLRPC.User user = currentForm.users.get(a); if (user.id == currentBotId) { botUser = user; break; } } } FrameLayout frameLayout = (FrameLayout) fragmentView; actionBar.setTitle(LocaleController.getString("TelegramPassport", R.string.TelegramPassport)); actionBar.createMenu().addItem(info_item, R.drawable.profile_info); if (botUser != null) { FrameLayout avatarContainer = new FrameLayout(context); linearLayout2.addView(avatarContainer, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 100)); BackupImageView avatarImageView = new BackupImageView(context); avatarImageView.setRoundRadius(AndroidUtilities.dp(32)); avatarContainer.addView(avatarImageView, LayoutHelper.createFrame(64, 64, Gravity.CENTER, 0, 8, 0, 0)); AvatarDrawable avatarDrawable = new AvatarDrawable(botUser); TLRPC.FileLocation photo = null; if (botUser.photo != null) { photo = botUser.photo.photo_small; } avatarImageView.setImage(photo, "50_50", avatarDrawable, botUser); bottomCell = new TextInfoPrivacyCell(context); bottomCell.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider_top, Theme.key_windowBackgroundGrayShadow)); bottomCell.setText(AndroidUtilities.replaceTags(LocaleController.formatString("PassportRequest", R.string.PassportRequest, UserObject.getFirstName(botUser)))); bottomCell.getTextView().setGravity(Gravity.CENTER_HORIZONTAL); ((FrameLayout.LayoutParams) bottomCell.getTextView() .getLayoutParams()).gravity = Gravity.CENTER_HORIZONTAL; linearLayout2.addView(bottomCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); } headerCell = new HeaderCell(context); headerCell.setText( LocaleController.getString("PassportRequestedInformation", R.string.PassportRequestedInformation)); headerCell.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite)); linearLayout2.addView(headerCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); if (currentForm != null) { int size = currentForm.required_types.size(); ArrayList<TLRPC.TL_secureRequiredType> personalDocuments = new ArrayList<>(); ArrayList<TLRPC.TL_secureRequiredType> addressDocuments = new ArrayList<>(); int personalCount = 0; int addressCount = 0; boolean hasPersonalInfo = false; boolean hasAddressInfo = false; for (int a = 0; a < size; a++) { TLRPC.SecureRequiredType secureRequiredType = currentForm.required_types.get(a); if (secureRequiredType instanceof TLRPC.TL_secureRequiredType) { TLRPC.TL_secureRequiredType requiredType = (TLRPC.TL_secureRequiredType) secureRequiredType; if (isPersonalDocument(requiredType.type)) { personalDocuments.add(requiredType); personalCount++; } else if (isAddressDocument(requiredType.type)) { addressDocuments.add(requiredType); addressCount++; } else if (requiredType.type instanceof TLRPC.TL_secureValueTypePersonalDetails) { hasPersonalInfo = true; } else if (requiredType.type instanceof TLRPC.TL_secureValueTypeAddress) { hasAddressInfo = true; } } else if (secureRequiredType instanceof TLRPC.TL_secureRequiredTypeOneOf) { TLRPC.TL_secureRequiredTypeOneOf requiredTypeOneOf = (TLRPC.TL_secureRequiredTypeOneOf) secureRequiredType; if (requiredTypeOneOf.types.isEmpty()) { continue; } TLRPC.SecureRequiredType innerType = requiredTypeOneOf.types.get(0); if (!(innerType instanceof TLRPC.TL_secureRequiredType)) { continue; } TLRPC.TL_secureRequiredType requiredType = (TLRPC.TL_secureRequiredType) innerType; if (isPersonalDocument(requiredType.type)) { for (int b = 0, size2 = requiredTypeOneOf.types.size(); b < size2; b++) { innerType = requiredTypeOneOf.types.get(b); if (!(innerType instanceof TLRPC.TL_secureRequiredType)) { continue; } personalDocuments.add((TLRPC.TL_secureRequiredType) innerType); } personalCount++; } else if (isAddressDocument(requiredType.type)) { for (int b = 0, size2 = requiredTypeOneOf.types.size(); b < size2; b++) { innerType = requiredTypeOneOf.types.get(b); if (!(innerType instanceof TLRPC.TL_secureRequiredType)) { continue; } addressDocuments.add((TLRPC.TL_secureRequiredType) innerType); } addressCount++; } } } boolean separatePersonal = !hasPersonalInfo || personalCount > 1; boolean separateAddress = !hasAddressInfo || addressCount > 1; for (int a = 0; a < size; a++) { TLRPC.SecureRequiredType secureRequiredType = currentForm.required_types.get(a); ArrayList<TLRPC.TL_secureRequiredType> documentTypes; TLRPC.TL_secureRequiredType requiredType; boolean documentOnly; if (secureRequiredType instanceof TLRPC.TL_secureRequiredType) { requiredType = (TLRPC.TL_secureRequiredType) secureRequiredType; if (requiredType.type instanceof TLRPC.TL_secureValueTypePhone || requiredType.type instanceof TLRPC.TL_secureValueTypeEmail) { documentTypes = null; documentOnly = false; } else if (requiredType.type instanceof TLRPC.TL_secureValueTypePersonalDetails) { if (separatePersonal) { documentTypes = null; } else { documentTypes = personalDocuments; } documentOnly = false; } else if (requiredType.type instanceof TLRPC.TL_secureValueTypeAddress) { if (separateAddress) { documentTypes = null; } else { documentTypes = addressDocuments; } documentOnly = false; } else if (separatePersonal && isPersonalDocument(requiredType.type)) { documentTypes = new ArrayList<>(); documentTypes.add(requiredType); requiredType = new TLRPC.TL_secureRequiredType(); requiredType.type = new TLRPC.TL_secureValueTypePersonalDetails(); documentOnly = true; } else if (separateAddress && isAddressDocument(requiredType.type)) { documentTypes = new ArrayList<>(); documentTypes.add(requiredType); requiredType = new TLRPC.TL_secureRequiredType(); requiredType.type = new TLRPC.TL_secureValueTypeAddress(); documentOnly = true; } else { continue; } } else if (secureRequiredType instanceof TLRPC.TL_secureRequiredTypeOneOf) { TLRPC.TL_secureRequiredTypeOneOf requiredTypeOneOf = (TLRPC.TL_secureRequiredTypeOneOf) secureRequiredType; if (requiredTypeOneOf.types.isEmpty()) { continue; } TLRPC.SecureRequiredType innerType = requiredTypeOneOf.types.get(0); if (!(innerType instanceof TLRPC.TL_secureRequiredType)) { continue; } requiredType = (TLRPC.TL_secureRequiredType) innerType; if (separatePersonal && isPersonalDocument(requiredType.type) || separateAddress && isAddressDocument(requiredType.type)) { documentTypes = new ArrayList<>(); for (int b = 0, size2 = requiredTypeOneOf.types.size(); b < size2; b++) { innerType = requiredTypeOneOf.types.get(b); if (!(innerType instanceof TLRPC.TL_secureRequiredType)) { continue; } documentTypes.add((TLRPC.TL_secureRequiredType) innerType); } if (isPersonalDocument(requiredType.type)) { requiredType = new TLRPC.TL_secureRequiredType(); requiredType.type = new TLRPC.TL_secureValueTypePersonalDetails(); } else { requiredType = new TLRPC.TL_secureRequiredType(); requiredType.type = new TLRPC.TL_secureValueTypeAddress(); } documentOnly = true; } else { continue; } } else { continue; } addField(context, requiredType, documentTypes, documentOnly, a == size - 1); } } if (botUser != null) { bottomCell = new TextInfoPrivacyCell(context); bottomCell.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow)); bottomCell.setLinkTextColorKey(Theme.key_windowBackgroundWhiteGrayText4); if (!TextUtils.isEmpty(currentForm.privacy_policy_url)) { String str2 = LocaleController.formatString("PassportPolicy", R.string.PassportPolicy, UserObject.getFirstName(botUser), botUser.username); SpannableStringBuilder text = new SpannableStringBuilder(str2); int index1 = str2.indexOf('*'); int index2 = str2.lastIndexOf('*'); if (index1 != -1 && index2 != -1) { bottomCell.getTextView().setMovementMethod(new AndroidUtilities.LinkMovementMethodMy()); text.replace(index2, index2 + 1, ""); text.replace(index1, index1 + 1, ""); text.setSpan(new LinkSpan(), index1, index2 - 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } bottomCell.setText(text); } else { bottomCell.setText(AndroidUtilities.replaceTags(LocaleController.formatString("PassportNoPolicy", R.string.PassportNoPolicy, UserObject.getFirstName(botUser), botUser.username))); } bottomCell.getTextView().setHighlightColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText4)); bottomCell.getTextView().setGravity(Gravity.CENTER_HORIZONTAL); linearLayout2.addView(bottomCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); } bottomLayout = new FrameLayout(context); bottomLayout.setBackgroundDrawable( Theme.createSelectorWithBackgroundDrawable(Theme.getColor(Theme.key_passport_authorizeBackground), Theme.getColor(Theme.key_passport_authorizeBackgroundSelected))); frameLayout.addView(bottomLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.BOTTOM)); bottomLayout.setOnClickListener(view -> { class ValueToSend { TLRPC.TL_secureValue value; boolean selfie_required; boolean translation_required; public ValueToSend(TLRPC.TL_secureValue v, boolean s, boolean t) { value = v; selfie_required = s; translation_required = t; } } ArrayList<ValueToSend> valuesToSend = new ArrayList<>(); for (int a = 0, size = currentForm.required_types.size(); a < size; a++) { TLRPC.TL_secureRequiredType requiredType; TLRPC.SecureRequiredType secureRequiredType = currentForm.required_types.get(a); if (secureRequiredType instanceof TLRPC.TL_secureRequiredType) { requiredType = (TLRPC.TL_secureRequiredType) secureRequiredType; } else if (secureRequiredType instanceof TLRPC.TL_secureRequiredTypeOneOf) { TLRPC.TL_secureRequiredTypeOneOf requiredTypeOneOf = (TLRPC.TL_secureRequiredTypeOneOf) secureRequiredType; if (requiredTypeOneOf.types.isEmpty()) { continue; } secureRequiredType = requiredTypeOneOf.types.get(0); if (!(secureRequiredType instanceof TLRPC.TL_secureRequiredType)) { continue; } requiredType = (TLRPC.TL_secureRequiredType) secureRequiredType; for (int b = 0, size2 = requiredTypeOneOf.types.size(); b < size2; b++) { secureRequiredType = requiredTypeOneOf.types.get(b); if (!(secureRequiredType instanceof TLRPC.TL_secureRequiredType)) { continue; } TLRPC.TL_secureRequiredType innerType = (TLRPC.TL_secureRequiredType) secureRequiredType; if (getValueByType(innerType, true) != null) { requiredType = innerType; break; } } } else { continue; } TLRPC.TL_secureValue value = getValueByType(requiredType, true); if (value == null) { Vibrator v = (Vibrator) getParentActivity().getSystemService(Context.VIBRATOR_SERVICE); if (v != null) { v.vibrate(200); } AndroidUtilities.shakeView(getViewByType(requiredType), 2, 0); return; } String key = getNameForType(requiredType.type); HashMap<String, String> errors = errorsMap.get(key); if (errors != null && !errors.isEmpty()) { Vibrator v = (Vibrator) getParentActivity().getSystemService(Context.VIBRATOR_SERVICE); if (v != null) { v.vibrate(200); } AndroidUtilities.shakeView(getViewByType(requiredType), 2, 0); return; } valuesToSend.add( new ValueToSend(value, requiredType.selfie_required, requiredType.translation_required)); } showEditDoneProgress(false, true); TLRPC.TL_account_acceptAuthorization req = new TLRPC.TL_account_acceptAuthorization(); req.bot_id = currentBotId; req.scope = currentScope; req.public_key = currentPublicKey; JSONObject jsonObject = new JSONObject(); for (int a = 0, size = valuesToSend.size(); a < size; a++) { ValueToSend valueToSend = valuesToSend.get(a); TLRPC.TL_secureValue secureValue = valueToSend.value; JSONObject data = new JSONObject(); if (secureValue.plain_data != null) { if (secureValue.plain_data instanceof TLRPC.TL_securePlainEmail) { TLRPC.TL_securePlainEmail securePlainEmail = (TLRPC.TL_securePlainEmail) secureValue.plain_data; } else if (secureValue.plain_data instanceof TLRPC.TL_securePlainPhone) { TLRPC.TL_securePlainPhone securePlainPhone = (TLRPC.TL_securePlainPhone) secureValue.plain_data; } } else { try { JSONObject result = new JSONObject(); if (secureValue.data != null) { byte[] decryptedSecret = decryptValueSecret(secureValue.data.secret, secureValue.data.data_hash); data.put("data_hash", Base64.encodeToString(secureValue.data.data_hash, Base64.NO_WRAP)); data.put("secret", Base64.encodeToString(decryptedSecret, Base64.NO_WRAP)); result.put("data", data); } if (!secureValue.files.isEmpty()) { JSONArray files = new JSONArray(); for (int b = 0, size2 = secureValue.files.size(); b < size2; b++) { TLRPC.TL_secureFile secureFile = (TLRPC.TL_secureFile) secureValue.files.get(b); byte[] decryptedSecret = decryptValueSecret(secureFile.secret, secureFile.file_hash); JSONObject file = new JSONObject(); file.put("file_hash", Base64.encodeToString(secureFile.file_hash, Base64.NO_WRAP)); file.put("secret", Base64.encodeToString(decryptedSecret, Base64.NO_WRAP)); files.put(file); } result.put("files", files); } if (secureValue.front_side instanceof TLRPC.TL_secureFile) { TLRPC.TL_secureFile secureFile = (TLRPC.TL_secureFile) secureValue.front_side; byte[] decryptedSecret = decryptValueSecret(secureFile.secret, secureFile.file_hash); JSONObject front = new JSONObject(); front.put("file_hash", Base64.encodeToString(secureFile.file_hash, Base64.NO_WRAP)); front.put("secret", Base64.encodeToString(decryptedSecret, Base64.NO_WRAP)); result.put("front_side", front); } if (secureValue.reverse_side instanceof TLRPC.TL_secureFile) { TLRPC.TL_secureFile secureFile = (TLRPC.TL_secureFile) secureValue.reverse_side; byte[] decryptedSecret = decryptValueSecret(secureFile.secret, secureFile.file_hash); JSONObject reverse = new JSONObject(); reverse.put("file_hash", Base64.encodeToString(secureFile.file_hash, Base64.NO_WRAP)); reverse.put("secret", Base64.encodeToString(decryptedSecret, Base64.NO_WRAP)); result.put("reverse_side", reverse); } if (valueToSend.selfie_required && secureValue.selfie instanceof TLRPC.TL_secureFile) { TLRPC.TL_secureFile secureFile = (TLRPC.TL_secureFile) secureValue.selfie; byte[] decryptedSecret = decryptValueSecret(secureFile.secret, secureFile.file_hash); JSONObject selfie = new JSONObject(); selfie.put("file_hash", Base64.encodeToString(secureFile.file_hash, Base64.NO_WRAP)); selfie.put("secret", Base64.encodeToString(decryptedSecret, Base64.NO_WRAP)); result.put("selfie", selfie); } if (valueToSend.translation_required && !secureValue.translation.isEmpty()) { JSONArray translation = new JSONArray(); for (int b = 0, size2 = secureValue.translation.size(); b < size2; b++) { TLRPC.TL_secureFile secureFile = (TLRPC.TL_secureFile) secureValue.translation .get(b); byte[] decryptedSecret = decryptValueSecret(secureFile.secret, secureFile.file_hash); JSONObject file = new JSONObject(); file.put("file_hash", Base64.encodeToString(secureFile.file_hash, Base64.NO_WRAP)); file.put("secret", Base64.encodeToString(decryptedSecret, Base64.NO_WRAP)); translation.put(file); } result.put("translation", translation); } jsonObject.put(getNameForType(secureValue.type), result); } catch (Exception ignore) { } } TLRPC.TL_secureValueHash hash = new TLRPC.TL_secureValueHash(); hash.type = secureValue.type; hash.hash = secureValue.hash; req.value_hashes.add(hash); } JSONObject result = new JSONObject(); try { result.put("secure_data", jsonObject); } catch (Exception ignore) { } if (currentPayload != null) { try { result.put("payload", currentPayload); } catch (Exception ignore) { } } if (currentNonce != null) { try { result.put("nonce", currentNonce); } catch (Exception ignore) { } } String json = result.toString(); EncryptionResult encryptionResult = encryptData(AndroidUtilities.getStringBytes(json)); req.credentials = new TLRPC.TL_secureCredentialsEncrypted(); req.credentials.hash = encryptionResult.fileHash; req.credentials.data = encryptionResult.encryptedData; try { String key = currentPublicKey.replaceAll("\\n", "").replace("-----BEGIN PUBLIC KEY-----", "") .replace("-----END PUBLIC KEY-----", ""); KeyFactory kf = KeyFactory.getInstance("RSA"); X509EncodedKeySpec keySpecX509 = new X509EncodedKeySpec(Base64.decode(key, Base64.DEFAULT)); RSAPublicKey pubKey = (RSAPublicKey) kf.generatePublic(keySpecX509); Cipher c = Cipher.getInstance("RSA/NONE/OAEPWithSHA1AndMGF1Padding", "BC"); c.init(Cipher.ENCRYPT_MODE, pubKey); req.credentials.secret = c.doFinal(encryptionResult.decrypyedFileSecret); } catch (Exception e) { FileLog.e(e); } int reqId = ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> { if (error == null) { ignoreOnFailure = true; callCallback(true); finishFragment(); } else { showEditDoneProgress(false, false); if ("APP_VERSION_OUTDATED".equals(error.text)) { AlertsCreator.showUpdateAppAlert(getParentActivity(), LocaleController.getString("UpdateAppAlert", R.string.UpdateAppAlert), true); } else { showAlertWithText(LocaleController.getString("AppName", R.string.AppName), error.text); } } })); ConnectionsManager.getInstance(currentAccount).bindRequestToGuid(reqId, classGuid); }); acceptTextView = new TextView(context); acceptTextView.setCompoundDrawablePadding(AndroidUtilities.dp(8)); acceptTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.authorize, 0, 0, 0); acceptTextView.setTextColor(Theme.getColor(Theme.key_passport_authorizeText)); acceptTextView.setText(LocaleController.getString("PassportAuthorize", R.string.PassportAuthorize)); acceptTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); acceptTextView.setGravity(Gravity.CENTER); acceptTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); bottomLayout.addView(acceptTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, Gravity.CENTER)); progressViewButton = new ContextProgressView(context, 0); progressViewButton.setVisibility(View.INVISIBLE); bottomLayout.addView(progressViewButton, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT)); View shadow = new View(context); shadow.setBackgroundResource(R.drawable.header_shadow_reverse); frameLayout.addView(shadow, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 3, Gravity.LEFT | Gravity.BOTTOM, 0, 0, 0, 48)); }