use of org.telegram.ui.Components.URLSpanNoUnderline in project Telegram-FOSS by Telegram-FOSS-Team.
the class MessageObject method addEntitiesToText.
public static boolean addEntitiesToText(CharSequence text, ArrayList<TLRPC.MessageEntity> entities, boolean out, boolean usernames, boolean photoViewer, boolean useManualParse) {
if (!(text instanceof Spannable)) {
return false;
}
Spannable spannable = (Spannable) text;
URLSpan[] spans = spannable.getSpans(0, text.length(), URLSpan.class);
boolean hasUrls = spans != null && spans.length > 0;
if (entities.isEmpty()) {
return hasUrls;
}
byte t;
if (photoViewer) {
t = 2;
} else if (out) {
t = 1;
} else {
t = 0;
}
ArrayList<TextStyleSpan.TextStyleRun> runs = new ArrayList<>();
ArrayList<TLRPC.MessageEntity> entitiesCopy = new ArrayList<>(entities);
Collections.sort(entitiesCopy, (o1, o2) -> {
if (o1.offset > o2.offset) {
return 1;
} else if (o1.offset < o2.offset) {
return -1;
}
return 0;
});
for (int a = 0, N = entitiesCopy.size(); a < N; a++) {
TLRPC.MessageEntity entity = entitiesCopy.get(a);
if (entity.length <= 0 || entity.offset < 0 || entity.offset >= text.length()) {
continue;
} else if (entity.offset + entity.length > text.length()) {
entity.length = text.length() - entity.offset;
}
if (!useManualParse || entity instanceof TLRPC.TL_messageEntityBold || entity instanceof TLRPC.TL_messageEntityItalic || entity instanceof TLRPC.TL_messageEntityStrike || entity instanceof TLRPC.TL_messageEntityUnderline || entity instanceof TLRPC.TL_messageEntityBlockquote || entity instanceof TLRPC.TL_messageEntityCode || entity instanceof TLRPC.TL_messageEntityPre || entity instanceof TLRPC.TL_messageEntityMentionName || entity instanceof TLRPC.TL_inputMessageEntityMentionName || entity instanceof TLRPC.TL_messageEntityTextUrl || entity instanceof TLRPC.TL_messageEntitySpoiler) {
if (spans != null && spans.length > 0) {
for (int b = 0; b < spans.length; b++) {
if (spans[b] == null) {
continue;
}
int start = spannable.getSpanStart(spans[b]);
int end = spannable.getSpanEnd(spans[b]);
if (entity.offset <= start && entity.offset + entity.length >= start || entity.offset <= end && entity.offset + entity.length >= end) {
spannable.removeSpan(spans[b]);
spans[b] = null;
}
}
}
}
TextStyleSpan.TextStyleRun newRun = new TextStyleSpan.TextStyleRun();
newRun.start = entity.offset;
newRun.end = newRun.start + entity.length;
TLRPC.MessageEntity urlEntity = null;
if (entity instanceof TLRPC.TL_messageEntitySpoiler) {
newRun.flags = TextStyleSpan.FLAG_STYLE_SPOILER;
} else if (entity instanceof TLRPC.TL_messageEntityStrike) {
newRun.flags = TextStyleSpan.FLAG_STYLE_STRIKE;
} else if (entity instanceof TLRPC.TL_messageEntityUnderline) {
newRun.flags = TextStyleSpan.FLAG_STYLE_UNDERLINE;
} else if (entity instanceof TLRPC.TL_messageEntityBlockquote) {
newRun.flags = TextStyleSpan.FLAG_STYLE_QUOTE;
} else if (entity instanceof TLRPC.TL_messageEntityBold) {
newRun.flags = TextStyleSpan.FLAG_STYLE_BOLD;
} else if (entity instanceof TLRPC.TL_messageEntityItalic) {
newRun.flags = TextStyleSpan.FLAG_STYLE_ITALIC;
} else if (entity instanceof TLRPC.TL_messageEntityCode || entity instanceof TLRPC.TL_messageEntityPre) {
newRun.flags = TextStyleSpan.FLAG_STYLE_MONO;
} else if (entity instanceof TLRPC.TL_messageEntityMentionName) {
if (!usernames) {
continue;
}
newRun.flags = TextStyleSpan.FLAG_STYLE_MENTION;
newRun.urlEntity = entity;
} else if (entity instanceof TLRPC.TL_inputMessageEntityMentionName) {
if (!usernames) {
continue;
}
newRun.flags = TextStyleSpan.FLAG_STYLE_MENTION;
newRun.urlEntity = entity;
} else {
if (useManualParse && !(entity instanceof TLRPC.TL_messageEntityTextUrl)) {
continue;
}
if ((entity instanceof TLRPC.TL_messageEntityUrl || entity instanceof TLRPC.TL_messageEntityTextUrl) && Browser.isPassportUrl(entity.url)) {
continue;
}
if (entity instanceof TLRPC.TL_messageEntityMention && !usernames) {
continue;
}
newRun.flags = TextStyleSpan.FLAG_STYLE_URL;
newRun.urlEntity = entity;
}
for (int b = 0, N2 = runs.size(); b < N2; b++) {
TextStyleSpan.TextStyleRun run = runs.get(b);
if (newRun.start > run.start) {
if (newRun.start >= run.end) {
continue;
}
if (newRun.end < run.end) {
TextStyleSpan.TextStyleRun r = new TextStyleSpan.TextStyleRun(newRun);
r.merge(run);
b++;
N2++;
runs.add(b, r);
r = new TextStyleSpan.TextStyleRun(run);
r.start = newRun.end;
b++;
N2++;
runs.add(b, r);
} else {
TextStyleSpan.TextStyleRun r = new TextStyleSpan.TextStyleRun(newRun);
r.merge(run);
r.end = run.end;
b++;
N2++;
runs.add(b, r);
}
int temp = newRun.start;
newRun.start = run.end;
run.end = temp;
} else {
if (run.start >= newRun.end) {
continue;
}
int temp = run.start;
if (newRun.end == run.end) {
run.merge(newRun);
} else if (newRun.end < run.end) {
TextStyleSpan.TextStyleRun r = new TextStyleSpan.TextStyleRun(run);
r.merge(newRun);
r.end = newRun.end;
b++;
N2++;
runs.add(b, r);
run.start = newRun.end;
} else {
TextStyleSpan.TextStyleRun r = new TextStyleSpan.TextStyleRun(newRun);
r.start = run.end;
b++;
N2++;
runs.add(b, r);
run.merge(newRun);
}
newRun.end = temp;
}
}
if (newRun.start < newRun.end) {
runs.add(newRun);
}
}
int count = runs.size();
for (int a = 0; a < count; a++) {
TextStyleSpan.TextStyleRun run = runs.get(a);
boolean setRun = false;
String url = run.urlEntity != null ? TextUtils.substring(text, run.urlEntity.offset, run.urlEntity.offset + run.urlEntity.length) : null;
if (run.urlEntity instanceof TLRPC.TL_messageEntityBotCommand) {
spannable.setSpan(new URLSpanBotCommand(url, t, run), run.start, run.end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
} else if (run.urlEntity instanceof TLRPC.TL_messageEntityHashtag || run.urlEntity instanceof TLRPC.TL_messageEntityMention || run.urlEntity instanceof TLRPC.TL_messageEntityCashtag) {
spannable.setSpan(new URLSpanNoUnderline(url, run), run.start, run.end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
} else if (run.urlEntity instanceof TLRPC.TL_messageEntityEmail) {
spannable.setSpan(new URLSpanReplacement("mailto:" + url, run), run.start, run.end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
} else if (run.urlEntity instanceof TLRPC.TL_messageEntityUrl) {
hasUrls = true;
String lowerCase = url.toLowerCase();
if (!lowerCase.contains("://")) {
spannable.setSpan(new URLSpanBrowser("http://" + url, run), run.start, run.end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
} else {
spannable.setSpan(new URLSpanBrowser(url, run), run.start, run.end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
} else if (run.urlEntity instanceof TLRPC.TL_messageEntityBankCard) {
hasUrls = true;
spannable.setSpan(new URLSpanNoUnderline("card:" + url, run), run.start, run.end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
} else if (run.urlEntity instanceof TLRPC.TL_messageEntityPhone) {
hasUrls = true;
String tel = PhoneFormat.stripExceptNumbers(url);
if (url.startsWith("+")) {
tel = "+" + tel;
}
spannable.setSpan(new URLSpanBrowser("tel:" + tel, run), run.start, run.end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
} else if (run.urlEntity instanceof TLRPC.TL_messageEntityTextUrl) {
spannable.setSpan(new URLSpanReplacement(run.urlEntity.url, run), run.start, run.end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
} else if (run.urlEntity instanceof TLRPC.TL_messageEntityMentionName) {
spannable.setSpan(new URLSpanUserMention("" + ((TLRPC.TL_messageEntityMentionName) run.urlEntity).user_id, t, run), run.start, run.end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
} else if (run.urlEntity instanceof TLRPC.TL_inputMessageEntityMentionName) {
spannable.setSpan(new URLSpanUserMention("" + ((TLRPC.TL_inputMessageEntityMentionName) run.urlEntity).user_id.user_id, t, run), run.start, run.end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
} else if ((run.flags & TextStyleSpan.FLAG_STYLE_MONO) != 0) {
spannable.setSpan(new URLSpanMono(spannable, run.start, run.end, t, run), run.start, run.end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
} else {
setRun = true;
spannable.setSpan(new TextStyleSpan(run), run.start, run.end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
if (!setRun && (run.flags & TextStyleSpan.FLAG_STYLE_SPOILER) != 0) {
spannable.setSpan(new TextStyleSpan(run), run.start, run.end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
return hasUrls;
}
use of org.telegram.ui.Components.URLSpanNoUnderline in project Telegram-FOSS by Telegram-FOSS-Team.
the class AdminedChannelCell method setChannel.
public void setChannel(TLRPC.Chat channel, boolean last) {
final String url = MessagesController.getInstance(currentAccount).linkPrefix + "/";
currentChannel = channel;
avatarDrawable.setInfo(channel);
nameTextView.setText(channel.title);
SpannableStringBuilder stringBuilder = new SpannableStringBuilder(url + channel.username);
stringBuilder.setSpan(new URLSpanNoUnderline(""), url.length(), stringBuilder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
statusTextView.setText(stringBuilder);
avatarImageView.setForUserOrChat(channel, avatarDrawable);
isLast = last;
}
use of org.telegram.ui.Components.URLSpanNoUnderline in project Telegram-FOSS by Telegram-FOSS-Team.
the class BotHelpCell method onTouchEvent.
@Override
public boolean onTouchEvent(MotionEvent event) {
float x = event.getX();
float y = event.getY();
boolean result = false;
if (textLayout != null) {
if (event.getAction() == MotionEvent.ACTION_DOWN || pressedLink != null && event.getAction() == MotionEvent.ACTION_UP) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
resetPressedLink();
try {
int x2 = (int) (x - textX);
int y2 = (int) (y - textY);
final int line = textLayout.getLineForVertical(y2);
final int off = textLayout.getOffsetForHorizontal(line, x2);
final float left = textLayout.getLineLeft(line);
if (left <= x2 && left + textLayout.getLineWidth(line) >= x2) {
Spannable buffer = (Spannable) textLayout.getText();
ClickableSpan[] link = buffer.getSpans(off, off, ClickableSpan.class);
if (link.length != 0) {
resetPressedLink();
pressedLink = link[0];
result = true;
try {
int start = buffer.getSpanStart(pressedLink);
urlPath.setCurrentLayout(textLayout, start, 0);
textLayout.getSelectionPath(start, buffer.getSpanEnd(pressedLink), urlPath);
} catch (Exception e) {
FileLog.e(e);
}
} else {
resetPressedLink();
}
} else {
resetPressedLink();
}
} catch (Exception e) {
resetPressedLink();
FileLog.e(e);
}
} else if (pressedLink != null) {
try {
if (pressedLink instanceof URLSpanNoUnderline) {
String url = ((URLSpanNoUnderline) pressedLink).getURL();
if (url.startsWith("@") || url.startsWith("#") || url.startsWith("/")) {
if (delegate != null) {
delegate.didPressUrl(url);
}
}
} else {
if (pressedLink instanceof URLSpan) {
if (delegate != null) {
delegate.didPressUrl(((URLSpan) pressedLink).getURL());
}
} else {
pressedLink.onClick(this);
}
}
} catch (Exception e) {
FileLog.e(e);
}
resetPressedLink();
result = true;
}
} else if (event.getAction() == MotionEvent.ACTION_CANCEL) {
resetPressedLink();
}
}
return result || super.onTouchEvent(event);
}
use of org.telegram.ui.Components.URLSpanNoUnderline in project Telegram-FOSS by Telegram-FOSS-Team.
the class CameraScanActivity method createView.
@Override
public View createView(Context context) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setItemsColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText2), false);
actionBar.setItemsBackgroundColor(Theme.getColor(Theme.key_actionBarWhiteSelector), false);
actionBar.setCastShadows(false);
if (!AndroidUtilities.isTablet() && !isQr()) {
actionBar.showActionModeTop();
}
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
}
}
});
paint.setColor(0x7f000000);
cornerPaint.setColor(0xffffffff);
cornerPaint.setStyle(Paint.Style.STROKE);
cornerPaint.setStrokeWidth(AndroidUtilities.dp(4));
cornerPaint.setStrokeJoin(Paint.Join.ROUND);
ViewGroup viewGroup = new ViewGroup(context) {
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int width = MeasureSpec.getSize(widthMeasureSpec);
int height = MeasureSpec.getSize(heightMeasureSpec);
actionBar.measure(widthMeasureSpec, heightMeasureSpec);
if (currentType == TYPE_MRZ) {
cameraView.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec((int) (width * 0.704f), MeasureSpec.EXACTLY));
} else {
cameraView.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
recognizedMrzView.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.UNSPECIFIED));
if (galleryButton != null) {
galleryButton.measure(MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(60), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(60), MeasureSpec.EXACTLY));
}
flashButton.measure(MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(60), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(60), MeasureSpec.EXACTLY));
}
titleTextView.measure(MeasureSpec.makeMeasureSpec(width - AndroidUtilities.dp(72), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.UNSPECIFIED));
descriptionText.measure(MeasureSpec.makeMeasureSpec((int) (width * 0.9f), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.UNSPECIFIED));
setMeasuredDimension(width, height);
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
int width = r - l;
int height = b - t;
int y = 0;
if (currentType == TYPE_MRZ) {
cameraView.layout(0, y, cameraView.getMeasuredWidth(), y + cameraView.getMeasuredHeight());
y = (int) (height * 0.65f);
titleTextView.layout(AndroidUtilities.dp(36), y, AndroidUtilities.dp(36) + titleTextView.getMeasuredWidth(), y + titleTextView.getMeasuredHeight());
recognizedMrzView.setTextSize(TypedValue.COMPLEX_UNIT_PX, cameraView.getMeasuredHeight() / 22);
recognizedMrzView.setPadding(0, 0, 0, cameraView.getMeasuredHeight() / 15);
} else {
actionBar.layout(0, 0, actionBar.getMeasuredWidth(), actionBar.getMeasuredHeight());
cameraView.layout(0, 0, cameraView.getMeasuredWidth(), cameraView.getMeasuredHeight());
int size = (int) (Math.min(cameraView.getWidth(), cameraView.getHeight()) / 1.5f);
if (currentType == TYPE_QR) {
y = (cameraView.getMeasuredHeight() - size) / 2 - titleTextView.getMeasuredHeight() - AndroidUtilities.dp(30);
} else {
y = (cameraView.getMeasuredHeight() - size) / 2 - titleTextView.getMeasuredHeight() - AndroidUtilities.dp(64);
}
titleTextView.layout(AndroidUtilities.dp(36), y, AndroidUtilities.dp(36) + titleTextView.getMeasuredWidth(), y + titleTextView.getMeasuredHeight());
recognizedMrzView.layout(0, getMeasuredHeight() - recognizedMrzView.getMeasuredHeight(), getMeasuredWidth(), getMeasuredHeight());
int x;
if (needGalleryButton) {
x = cameraView.getMeasuredWidth() / 2 + AndroidUtilities.dp(35);
} else {
x = cameraView.getMeasuredWidth() / 2 - flashButton.getMeasuredWidth() / 2;
}
y = (cameraView.getMeasuredHeight() - size) / 2 + size + AndroidUtilities.dp(30);
flashButton.layout(x, y, x + flashButton.getMeasuredWidth(), y + flashButton.getMeasuredHeight());
if (galleryButton != null) {
x = cameraView.getMeasuredWidth() / 2 - AndroidUtilities.dp(35) - galleryButton.getMeasuredWidth();
galleryButton.layout(x, y, x + galleryButton.getMeasuredWidth(), y + galleryButton.getMeasuredHeight());
}
}
y = (int) (height * 0.74f);
int x = (int) (width * 0.05f);
descriptionText.layout(x, y, x + descriptionText.getMeasuredWidth(), y + descriptionText.getMeasuredHeight());
}
@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
boolean result = super.drawChild(canvas, child, drawingTime);
if (isQr() && child == cameraView) {
int size = (int) (Math.min(child.getWidth(), child.getHeight()) / 1.5f);
int x = (child.getWidth() - size) / 2;
int y = (child.getHeight() - size) / 2;
canvas.drawRect(0, 0, child.getMeasuredWidth(), y, paint);
canvas.drawRect(0, y + size, child.getMeasuredWidth(), child.getMeasuredHeight(), paint);
canvas.drawRect(0, y, x, y + size, paint);
canvas.drawRect(x + size, y, child.getMeasuredWidth(), y + size, paint);
path.reset();
path.moveTo(x, y + AndroidUtilities.dp(20));
path.lineTo(x, y);
path.lineTo(x + AndroidUtilities.dp(20), y);
canvas.drawPath(path, cornerPaint);
path.reset();
path.moveTo(x + size, y + AndroidUtilities.dp(20));
path.lineTo(x + size, y);
path.lineTo(x + size - AndroidUtilities.dp(20), y);
canvas.drawPath(path, cornerPaint);
path.reset();
path.moveTo(x, y + size - AndroidUtilities.dp(20));
path.lineTo(x, y + size);
path.lineTo(x + AndroidUtilities.dp(20), y + size);
canvas.drawPath(path, cornerPaint);
path.reset();
path.moveTo(x + size, y + size - AndroidUtilities.dp(20));
path.lineTo(x + size, y + size);
path.lineTo(x + size - AndroidUtilities.dp(20), y + size);
canvas.drawPath(path, cornerPaint);
}
return result;
}
};
viewGroup.setOnTouchListener((v, event) -> true);
fragmentView = viewGroup;
cameraView = new CameraView(context, false);
cameraView.setUseMaxPreview(true);
cameraView.setOptimizeForBarcode(true);
cameraView.setDelegate(new CameraView.CameraViewDelegate() {
@Override
public void onCameraCreated(Camera camera) {
}
@Override
public void onCameraInit() {
startRecognizing();
}
});
viewGroup.addView(cameraView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
if (currentType == TYPE_MRZ) {
actionBar.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
fragmentView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
} else {
actionBar.setBackgroundDrawable(null);
actionBar.setAddToContainer(false);
actionBar.setItemsColor(0xffffffff, false);
actionBar.setItemsBackgroundColor(0x22ffffff, false);
viewGroup.setBackgroundColor(Theme.getColor(Theme.key_wallet_blackBackground));
viewGroup.addView(actionBar);
}
if (currentType == TYPE_QR_LOGIN) {
actionBar.setTitle(LocaleController.getString("AuthAnotherClientScan", R.string.AuthAnotherClientScan));
}
Paint selectionPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
selectionPaint.setColor(ColorUtils.setAlphaComponent(Color.WHITE, 100));
titleTextView = new TextView(context) {
LinkPath textPath;
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
if (getText() instanceof Spanned) {
Spanned spanned = (Spanned) getText();
URLSpanNoUnderline[] innerSpans = spanned.getSpans(0, spanned.length(), URLSpanNoUnderline.class);
if (innerSpans != null && innerSpans.length > 0) {
textPath = new LinkPath(true);
textPath.setAllowReset(false);
for (int a = 0; a < innerSpans.length; a++) {
int start = spanned.getSpanStart(innerSpans[a]);
int end = spanned.getSpanEnd(innerSpans[a]);
textPath.setCurrentLayout(getLayout(), start, 0);
int shift = getText() != null ? getPaint().baselineShift : 0;
textPath.setBaselineShift(shift != 0 ? shift + AndroidUtilities.dp(shift > 0 ? 5 : -2) : 0);
getLayout().getSelectionPath(start, end, textPath);
}
textPath.setAllowReset(true);
}
}
}
@Override
protected void onDraw(Canvas canvas) {
if (textPath != null) {
canvas.drawPath(textPath, selectionPaint);
}
super.onDraw(canvas);
}
};
titleTextView.setGravity(Gravity.CENTER_HORIZONTAL);
titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 24);
viewGroup.addView(titleTextView);
descriptionText = new TextView(context);
descriptionText.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText6));
descriptionText.setGravity(Gravity.CENTER_HORIZONTAL);
descriptionText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
viewGroup.addView(descriptionText);
recognizedMrzView = new TextView(context);
recognizedMrzView.setTextColor(0xffffffff);
recognizedMrzView.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM);
recognizedMrzView.setAlpha(0);
if (currentType == TYPE_MRZ) {
titleTextView.setText(LocaleController.getString("PassportScanPassport", R.string.PassportScanPassport));
descriptionText.setText(LocaleController.getString("PassportScanPassportInfo", R.string.PassportScanPassportInfo));
titleTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
recognizedMrzView.setTypeface(Typeface.MONOSPACE);
cameraView.addView(recognizedMrzView);
} else {
if (needGalleryButton) {
// titleTextView.setText(LocaleController.getString("WalletScanCode", R.string.WalletScanCode));
} else {
if (currentType == TYPE_QR) {
titleTextView.setText(LocaleController.getString("AuthAnotherClientScan", R.string.AuthAnotherClientScan));
} else {
String text = LocaleController.getString("AuthAnotherClientInfo5", R.string.AuthAnotherClientInfo5);
SpannableStringBuilder spanned = new SpannableStringBuilder(text);
int index1 = text.indexOf('*');
int index2 = text.indexOf('*', index1 + 1);
if (index1 != -1 && index2 != -1 && index1 != index2) {
titleTextView.setMovementMethod(new AndroidUtilities.LinkMovementMethodMy());
spanned.replace(index2, index2 + 1, " ");
spanned.replace(index1, index1 + 1, " ");
index1 += 1;
index2 += 1;
spanned.setSpan(new URLSpanNoUnderline(LocaleController.getString("AuthAnotherClientDownloadClientUrl", R.string.AuthAnotherClientDownloadClientUrl)), index1, index2 - 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
spanned.setSpan(new TypefaceSpan(AndroidUtilities.getTypeface("fonts/rmedium.ttf")), index1, index2 - 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
text = spanned.toString();
index1 = text.indexOf('*');
index2 = text.indexOf('*', index1 + 1);
if (index1 != -1 && index2 != -1 && index1 != index2) {
spanned.replace(index2, index2 + 1, " ");
spanned.replace(index1, index1 + 1, " ");
index1 += 1;
index2 += 1;
spanned.setSpan(new URLSpanNoUnderline(LocaleController.getString("AuthAnotherWebClientUrl", R.string.AuthAnotherWebClientUrl)), index1, index2 - 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
spanned.setSpan(new TypefaceSpan(AndroidUtilities.getTypeface("fonts/rmedium.ttf")), index1, index2 - 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
titleTextView.setLinkTextColor(Color.WHITE);
titleTextView.setHighlightColor(Theme.getColor(Theme.key_windowBackgroundWhiteLinkSelection));
titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
titleTextView.setLineSpacing(AndroidUtilities.dp(2), 1.0f);
titleTextView.setPadding(0, 0, 0, 0);
titleTextView.setText(spanned);
}
}
titleTextView.setTextColor(0xffffffff);
recognizedMrzView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
recognizedMrzView.setPadding(AndroidUtilities.dp(10), 0, AndroidUtilities.dp(10), AndroidUtilities.dp(10));
if (needGalleryButton) {
// recognizedMrzView.setText(LocaleController.getString("WalletScanCodeNotFound", R.string.WalletScanCodeNotFound));
} else {
recognizedMrzView.setText(LocaleController.getString("AuthAnotherClientNotFound", R.string.AuthAnotherClientNotFound));
}
viewGroup.addView(recognizedMrzView);
if (needGalleryButton) {
galleryButton = new ImageView(context);
galleryButton.setScaleType(ImageView.ScaleType.CENTER);
galleryButton.setImageResource(R.drawable.qr_gallery);
galleryButton.setBackgroundDrawable(Theme.createSelectorDrawableFromDrawables(Theme.createCircleDrawable(AndroidUtilities.dp(60), 0x22ffffff), Theme.createCircleDrawable(AndroidUtilities.dp(60), 0x44ffffff)));
viewGroup.addView(galleryButton);
galleryButton.setOnClickListener(currentImage -> {
if (getParentActivity() == null) {
return;
}
if (Build.VERSION.SDK_INT >= 23) {
if (getParentActivity().checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
getParentActivity().requestPermissions(new String[] { Manifest.permission.READ_EXTERNAL_STORAGE }, 4);
return;
}
}
PhotoAlbumPickerActivity fragment = new PhotoAlbumPickerActivity(PhotoAlbumPickerActivity.SELECT_TYPE_QR, false, false, null);
fragment.setMaxSelectedPhotos(1, false);
fragment.setAllowSearchImages(false);
fragment.setDelegate(new PhotoAlbumPickerActivity.PhotoAlbumPickerActivityDelegate() {
@Override
public void didSelectPhotos(ArrayList<SendMessagesHelper.SendingMediaInfo> photos, boolean notify, int scheduleDate) {
try {
if (!photos.isEmpty()) {
SendMessagesHelper.SendingMediaInfo info = photos.get(0);
if (info.path != null) {
Point screenSize = AndroidUtilities.getRealScreenSize();
Bitmap bitmap = ImageLoader.loadBitmap(info.path, null, screenSize.x, screenSize.y, true);
String text = tryReadQr(null, null, 0, 0, 0, bitmap);
if (text != null) {
if (delegate != null) {
delegate.didFindQr(text);
}
removeSelfFromStack();
}
}
}
} catch (Throwable e) {
FileLog.e(e);
}
}
@Override
public void startPhotoSelectActivity() {
try {
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.setType("image/*");
getParentActivity().startActivityForResult(photoPickerIntent, 11);
} catch (Exception e) {
FileLog.e(e);
}
}
});
presentFragment(fragment);
});
}
flashButton = new ImageView(context);
flashButton.setScaleType(ImageView.ScaleType.CENTER);
flashButton.setImageResource(R.drawable.qr_flashlight);
flashButton.setBackgroundDrawable(Theme.createCircleDrawable(AndroidUtilities.dp(60), 0x22ffffff));
viewGroup.addView(flashButton);
flashButton.setOnClickListener(currentImage -> {
CameraSession session = cameraView.getCameraSession();
if (session != null) {
ShapeDrawable shapeDrawable = (ShapeDrawable) flashButton.getBackground();
if (flashAnimator != null) {
flashAnimator.cancel();
flashAnimator = null;
}
flashAnimator = new AnimatorSet();
ObjectAnimator animator = ObjectAnimator.ofInt(shapeDrawable, AnimationProperties.SHAPE_DRAWABLE_ALPHA, flashButton.getTag() == null ? 0x44 : 0x22);
animator.addUpdateListener(animation -> flashButton.invalidate());
flashAnimator.playTogether(animator);
flashAnimator.setDuration(200);
flashAnimator.setInterpolator(CubicBezierInterpolator.DEFAULT);
flashAnimator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
flashAnimator = null;
}
});
flashAnimator.start();
if (flashButton.getTag() == null) {
flashButton.setTag(1);
session.setTorchEnabled(true);
} else {
flashButton.setTag(null);
session.setTorchEnabled(false);
}
}
});
}
if (getParentActivity() != null) {
getParentActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
fragmentView.setKeepScreenOn(true);
return fragmentView;
}
use of org.telegram.ui.Components.URLSpanNoUnderline in project Telegram-FOSS by Telegram-FOSS-Team.
the class ActionIntroActivity method createView.
@Override
public View createView(Context context) {
if (actionBar != null) {
actionBar.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setItemsColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText2), false);
actionBar.setItemsBackgroundColor(Theme.getColor(Theme.key_actionBarWhiteSelector), false);
actionBar.setCastShadows(false);
actionBar.setAddToContainer(false);
if (!AndroidUtilities.isTablet()) {
actionBar.showActionModeTop();
}
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
}
}
});
}
fragmentView = new ViewGroup(context) {
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int width = MeasureSpec.getSize(widthMeasureSpec);
int height = MeasureSpec.getSize(heightMeasureSpec);
if (actionBar != null) {
actionBar.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), heightMeasureSpec);
}
switch(currentType) {
case ACTION_TYPE_CHANNEL_CREATE:
{
if (width > height) {
imageView.measure(MeasureSpec.makeMeasureSpec((int) (width * 0.45f), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec((int) (height * 0.68f), MeasureSpec.EXACTLY));
titleTextView.measure(MeasureSpec.makeMeasureSpec((int) (width * 0.6f), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.UNSPECIFIED));
descriptionText.measure(MeasureSpec.makeMeasureSpec((int) (width * 0.6f), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.UNSPECIFIED));
buttonTextView.measure(MeasureSpec.makeMeasureSpec((int) (width * 0.6f), MeasureSpec.AT_MOST), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(42), MeasureSpec.EXACTLY));
} else {
imageView.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec((int) (height * 0.399f), MeasureSpec.EXACTLY));
titleTextView.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.UNSPECIFIED));
descriptionText.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.UNSPECIFIED));
buttonTextView.measure(MeasureSpec.makeMeasureSpec(width - AndroidUtilities.dp(86), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(42), MeasureSpec.EXACTLY));
}
break;
}
case ACTION_TYPE_QR_LOGIN:
{
if (showingAsBottomSheet) {
imageView.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec((int) (height * 0.32f), MeasureSpec.EXACTLY));
titleTextView.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.UNSPECIFIED));
descriptionLayout.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.AT_MOST), MeasureSpec.makeMeasureSpec(height, MeasureSpec.UNSPECIFIED));
buttonTextView.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.AT_MOST), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(42), MeasureSpec.EXACTLY));
height = imageView.getMeasuredHeight() + titleTextView.getMeasuredHeight() + AndroidUtilities.dp(20) + titleTextView.getMeasuredHeight() + descriptionLayout.getMeasuredHeight() + buttonTextView.getMeasuredHeight();
} else if (width > height) {
imageView.measure(MeasureSpec.makeMeasureSpec((int) (width * 0.45f), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec((int) (height * 0.68f), MeasureSpec.EXACTLY));
titleTextView.measure(MeasureSpec.makeMeasureSpec((int) (width * 0.6f), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.UNSPECIFIED));
descriptionLayout.measure(MeasureSpec.makeMeasureSpec((int) (width * 0.6f), MeasureSpec.AT_MOST), MeasureSpec.makeMeasureSpec(height, MeasureSpec.UNSPECIFIED));
buttonTextView.measure(MeasureSpec.makeMeasureSpec((int) (width * 0.6f), MeasureSpec.AT_MOST), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(42), MeasureSpec.EXACTLY));
} else {
imageView.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec((int) (height * 0.399f), MeasureSpec.EXACTLY));
titleTextView.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.UNSPECIFIED));
descriptionLayout.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.AT_MOST), MeasureSpec.makeMeasureSpec(height, MeasureSpec.UNSPECIFIED));
buttonTextView.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.AT_MOST), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(42), MeasureSpec.EXACTLY));
}
break;
}
case ACTION_TYPE_NEARBY_LOCATION_ACCESS:
case ACTION_TYPE_NEARBY_LOCATION_ENABLED:
{
imageView.measure(MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(100), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(100), MeasureSpec.EXACTLY));
if (width > height) {
titleTextView.measure(MeasureSpec.makeMeasureSpec((int) (width * 0.6f), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.UNSPECIFIED));
descriptionText.measure(MeasureSpec.makeMeasureSpec((int) (width * 0.6f), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.UNSPECIFIED));
buttonTextView.measure(MeasureSpec.makeMeasureSpec((int) (width * 0.6f), MeasureSpec.AT_MOST), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(42), MeasureSpec.EXACTLY));
} else {
titleTextView.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.UNSPECIFIED));
descriptionText.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.UNSPECIFIED));
buttonTextView.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.AT_MOST), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(42), MeasureSpec.EXACTLY));
}
break;
}
case ACTION_TYPE_NEARBY_GROUP_CREATE:
{
if (width > height) {
imageView.measure(MeasureSpec.makeMeasureSpec((int) (width * 0.45f), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec((int) (height * 0.78f), MeasureSpec.AT_MOST));
subtitleTextView.measure(MeasureSpec.makeMeasureSpec((int) (width * 0.45f), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.UNSPECIFIED));
titleTextView.measure(MeasureSpec.makeMeasureSpec((int) (width * 0.6f), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.UNSPECIFIED));
descriptionText.measure(MeasureSpec.makeMeasureSpec((int) (width * 0.6f), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.UNSPECIFIED));
descriptionText2.measure(MeasureSpec.makeMeasureSpec((int) (width * 0.6f), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.UNSPECIFIED));
buttonTextView.measure(MeasureSpec.makeMeasureSpec((int) (width * 0.6f), MeasureSpec.AT_MOST), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(42), MeasureSpec.EXACTLY));
} else {
imageView.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec((int) (height * 0.44f), MeasureSpec.AT_MOST));
titleTextView.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.UNSPECIFIED));
subtitleTextView.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.UNSPECIFIED));
descriptionText.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.UNSPECIFIED));
descriptionText2.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.UNSPECIFIED));
buttonTextView.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.AT_MOST), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(42), MeasureSpec.EXACTLY));
}
break;
}
case ACTION_TYPE_CHANGE_PHONE_NUMBER:
{
if (width > height) {
imageView.measure(MeasureSpec.makeMeasureSpec((int) (width * 0.45f), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec((int) (height * 0.78f), MeasureSpec.AT_MOST));
subtitleTextView.measure(MeasureSpec.makeMeasureSpec((int) (width * 0.45f), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.UNSPECIFIED));
titleTextView.measure(MeasureSpec.makeMeasureSpec((int) (width * 0.6f), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.UNSPECIFIED));
descriptionText.measure(MeasureSpec.makeMeasureSpec((int) (width * 0.6f), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.UNSPECIFIED));
buttonTextView.measure(MeasureSpec.makeMeasureSpec((int) (width * 0.6f), MeasureSpec.AT_MOST), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(42), MeasureSpec.EXACTLY));
} else {
imageView.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec((int) (height * 0.44f), MeasureSpec.AT_MOST));
titleTextView.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.UNSPECIFIED));
subtitleTextView.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.UNSPECIFIED));
descriptionText.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.UNSPECIFIED));
buttonTextView.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.AT_MOST), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(42), MeasureSpec.EXACTLY));
}
break;
}
}
setMeasuredDimension(width, height);
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
if (actionBar != null) {
actionBar.layout(0, 0, r, actionBar.getMeasuredHeight());
}
int width = r - l;
int height = b - t;
switch(currentType) {
case ACTION_TYPE_CHANNEL_CREATE:
{
if (r > b) {
int y = (height - imageView.getMeasuredHeight()) / 2;
imageView.layout(0, y, imageView.getMeasuredWidth(), y + imageView.getMeasuredHeight());
int x = (int) (width * 0.4f);
y = (int) (height * 0.22f);
titleTextView.layout(x, y, x + titleTextView.getMeasuredWidth(), y + titleTextView.getMeasuredHeight());
x = (int) (width * 0.4f);
y = (int) (height * 0.39f);
descriptionText.layout(x, y, x + descriptionText.getMeasuredWidth(), y + descriptionText.getMeasuredHeight());
x = (int) (width * 0.4f + (width * 0.6f - buttonTextView.getMeasuredWidth()) / 2);
y = (int) (height * 0.69f);
buttonTextView.layout(x, y, x + buttonTextView.getMeasuredWidth(), y + buttonTextView.getMeasuredHeight());
} else {
int y = (int) (height * 0.188f);
imageView.layout(0, y, imageView.getMeasuredWidth(), y + imageView.getMeasuredHeight());
y = (int) (height * 0.651f);
titleTextView.layout(0, y, titleTextView.getMeasuredWidth(), y + titleTextView.getMeasuredHeight());
y = (int) (height * 0.731f);
descriptionText.layout(0, y, descriptionText.getMeasuredWidth(), y + descriptionText.getMeasuredHeight());
int x = (width - buttonTextView.getMeasuredWidth()) / 2;
y = (int) (height * 0.853f);
buttonTextView.layout(x, y, x + buttonTextView.getMeasuredWidth(), y + buttonTextView.getMeasuredHeight());
}
break;
}
case ACTION_TYPE_QR_LOGIN:
{
if (showingAsBottomSheet) {
int y;
y = 0;
imageView.layout(0, y, imageView.getMeasuredWidth(), y + imageView.getMeasuredHeight());
y = (int) (height * 0.403f);
titleTextView.layout(0, y, titleTextView.getMeasuredWidth(), y + titleTextView.getMeasuredHeight());
y = (int) (height * 0.631f);
int x = (getMeasuredWidth() - descriptionLayout.getMeasuredWidth()) / 2;
descriptionLayout.layout(x, y, x + descriptionLayout.getMeasuredWidth(), y + descriptionLayout.getMeasuredHeight());
x = (width - buttonTextView.getMeasuredWidth()) / 2;
y = (int) (height * 0.853f);
buttonTextView.layout(x, y, x + buttonTextView.getMeasuredWidth(), y + buttonTextView.getMeasuredHeight());
} else if (r > b) {
int y = (height - imageView.getMeasuredHeight()) / 2;
imageView.layout(0, y, imageView.getMeasuredWidth(), y + imageView.getMeasuredHeight());
int x = (int) (width * 0.4f);
y = (int) (height * 0.08f);
titleTextView.layout(x, y, x + titleTextView.getMeasuredWidth(), y + titleTextView.getMeasuredHeight());
x = (int) (width * 0.4f + (width * 0.6f - descriptionLayout.getMeasuredWidth()) / 2);
y = (int) (height * 0.25f);
descriptionLayout.layout(x, y, x + descriptionLayout.getMeasuredWidth(), y + descriptionLayout.getMeasuredHeight());
x = (int) (width * 0.4f + (width * 0.6f - buttonTextView.getMeasuredWidth()) / 2);
y = (int) (height * 0.78f);
buttonTextView.layout(x, y, x + buttonTextView.getMeasuredWidth(), y + buttonTextView.getMeasuredHeight());
} else {
int y;
if (AndroidUtilities.displaySize.y < 1800) {
y = (int) (height * 0.06f);
imageView.layout(0, y, imageView.getMeasuredWidth(), y + imageView.getMeasuredHeight());
y = (int) (height * 0.463f);
titleTextView.layout(0, y, titleTextView.getMeasuredWidth(), y + titleTextView.getMeasuredHeight());
y = (int) (height * 0.543f);
} else {
y = (int) (height * 0.148f);
imageView.layout(0, y, imageView.getMeasuredWidth(), y + imageView.getMeasuredHeight());
y = (int) (height * 0.551f);
titleTextView.layout(0, y, titleTextView.getMeasuredWidth(), y + titleTextView.getMeasuredHeight());
y = (int) (height * 0.631f);
}
int x = (getMeasuredWidth() - descriptionLayout.getMeasuredWidth()) / 2;
descriptionLayout.layout(x, y, x + descriptionLayout.getMeasuredWidth(), y + descriptionLayout.getMeasuredHeight());
x = (width - buttonTextView.getMeasuredWidth()) / 2;
y = (int) (height * 0.853f);
buttonTextView.layout(x, y, x + buttonTextView.getMeasuredWidth(), y + buttonTextView.getMeasuredHeight());
}
break;
}
case ACTION_TYPE_NEARBY_LOCATION_ACCESS:
case ACTION_TYPE_NEARBY_LOCATION_ENABLED:
{
if (r > b) {
int y = (height - imageView.getMeasuredHeight()) / 2;
int x = (int) (width * 0.5f - imageView.getMeasuredWidth()) / 2;
imageView.layout(x, y, x + imageView.getMeasuredWidth(), y + imageView.getMeasuredHeight());
x = (int) (width * 0.4f);
y = (int) (height * 0.14f);
titleTextView.layout(x, y, x + titleTextView.getMeasuredWidth(), y + titleTextView.getMeasuredHeight());
x = (int) (width * 0.4f);
y = (int) (height * 0.31f);
descriptionText.layout(x, y, x + descriptionText.getMeasuredWidth(), y + descriptionText.getMeasuredHeight());
x = (int) (width * 0.4f + (width * 0.6f - buttonTextView.getMeasuredWidth()) / 2);
y = (int) (height * 0.78f);
buttonTextView.layout(x, y, x + buttonTextView.getMeasuredWidth(), y + buttonTextView.getMeasuredHeight());
} else {
int y = (int) (height * 0.214f);
int x = (width - imageView.getMeasuredWidth()) / 2;
imageView.layout(x, y, x + imageView.getMeasuredWidth(), y + imageView.getMeasuredHeight());
y = (int) (height * 0.414f);
titleTextView.layout(0, y, titleTextView.getMeasuredWidth(), y + titleTextView.getMeasuredHeight());
y = (int) (height * 0.493f);
descriptionText.layout(0, y, descriptionText.getMeasuredWidth(), y + descriptionText.getMeasuredHeight());
x = (width - buttonTextView.getMeasuredWidth()) / 2;
y = (int) (height * 0.71f);
buttonTextView.layout(x, y, x + buttonTextView.getMeasuredWidth(), y + buttonTextView.getMeasuredHeight());
}
break;
}
case ACTION_TYPE_NEARBY_GROUP_CREATE:
{
if (r > b) {
int y = (int) (height * 0.9f - imageView.getMeasuredHeight()) / 2;
imageView.layout(0, y, imageView.getMeasuredWidth(), y + imageView.getMeasuredHeight());
y += imageView.getMeasuredHeight() + AndroidUtilities.dp(10);
subtitleTextView.layout(0, y, subtitleTextView.getMeasuredWidth(), y + subtitleTextView.getMeasuredHeight());
int x = (int) (width * 0.4f);
y = (int) (height * 0.12f);
titleTextView.layout(x, y, x + titleTextView.getMeasuredWidth(), y + titleTextView.getMeasuredHeight());
x = (int) (width * 0.4f);
y = (int) (height * 0.26f);
descriptionText.layout(x, y, x + descriptionText.getMeasuredWidth(), y + descriptionText.getMeasuredHeight());
x = (int) (width * 0.4f + (width * 0.6f - buttonTextView.getMeasuredWidth()) / 2);
y = (int) (height * 0.6f);
buttonTextView.layout(x, y, x + buttonTextView.getMeasuredWidth(), y + buttonTextView.getMeasuredHeight());
x = (int) (width * 0.4f);
y = getMeasuredHeight() - descriptionText2.getMeasuredHeight() - AndroidUtilities.dp(20);
descriptionText2.layout(x, y, x + descriptionText2.getMeasuredWidth(), y + descriptionText2.getMeasuredHeight());
} else {
int y = (int) (height * 0.197f);
imageView.layout(0, y, imageView.getMeasuredWidth(), y + imageView.getMeasuredHeight());
y = (int) (height * 0.421f);
titleTextView.layout(0, y, titleTextView.getMeasuredWidth(), y + titleTextView.getMeasuredHeight());
y = (int) (height * 0.477f);
subtitleTextView.layout(0, y, subtitleTextView.getMeasuredWidth(), y + subtitleTextView.getMeasuredHeight());
y = (int) (height * 0.537f);
descriptionText.layout(0, y, descriptionText.getMeasuredWidth(), y + descriptionText.getMeasuredHeight());
int x = (width - buttonTextView.getMeasuredWidth()) / 2;
y = (int) (height * 0.71f);
buttonTextView.layout(x, y, x + buttonTextView.getMeasuredWidth(), y + buttonTextView.getMeasuredHeight());
y = getMeasuredHeight() - descriptionText2.getMeasuredHeight() - AndroidUtilities.dp(20);
descriptionText2.layout(0, y, descriptionText2.getMeasuredWidth(), y + descriptionText2.getMeasuredHeight());
}
break;
}
case ACTION_TYPE_CHANGE_PHONE_NUMBER:
{
if (r > b) {
int y = (int) (height * 0.95f - imageView.getMeasuredHeight()) / 2;
imageView.layout(0, y, imageView.getMeasuredWidth(), y + imageView.getMeasuredHeight());
y += imageView.getMeasuredHeight() + AndroidUtilities.dp(10);
subtitleTextView.layout(0, y, subtitleTextView.getMeasuredWidth(), y + subtitleTextView.getMeasuredHeight());
int x = (int) (width * 0.4f);
y = (int) (height * 0.12f);
titleTextView.layout(x, y, x + titleTextView.getMeasuredWidth(), y + titleTextView.getMeasuredHeight());
x = (int) (width * 0.4f);
y = (int) (height * 0.24f);
descriptionText.layout(x, y, x + descriptionText.getMeasuredWidth(), y + descriptionText.getMeasuredHeight());
x = (int) (width * 0.4f + (width * 0.6f - buttonTextView.getMeasuredWidth()) / 2);
y = (int) (height * 0.8f);
buttonTextView.layout(x, y, x + buttonTextView.getMeasuredWidth(), y + buttonTextView.getMeasuredHeight());
} else {
int y = (int) (height * 0.2229f);
imageView.layout(0, y, imageView.getMeasuredWidth(), y + imageView.getMeasuredHeight());
y = (int) (height * 0.352f);
titleTextView.layout(0, y, titleTextView.getMeasuredWidth(), y + titleTextView.getMeasuredHeight());
y = (int) (height * 0.409f);
subtitleTextView.layout(0, y, subtitleTextView.getMeasuredWidth(), y + subtitleTextView.getMeasuredHeight());
y = (int) (height * 0.468f);
descriptionText.layout(0, y, descriptionText.getMeasuredWidth(), y + descriptionText.getMeasuredHeight());
int x = (width - buttonTextView.getMeasuredWidth()) / 2;
y = (int) (height * 0.805f);
buttonTextView.layout(x, y, x + buttonTextView.getMeasuredWidth(), y + buttonTextView.getMeasuredHeight());
}
break;
}
}
}
};
fragmentView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
ViewGroup viewGroup = (ViewGroup) fragmentView;
viewGroup.setOnTouchListener((v, event) -> true);
if (actionBar != null) {
viewGroup.addView(actionBar);
}
imageView = new RLottieImageView(context);
viewGroup.addView(imageView);
titleTextView = new TextView(context);
titleTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
titleTextView.setGravity(Gravity.CENTER_HORIZONTAL);
titleTextView.setPadding(AndroidUtilities.dp(32), 0, AndroidUtilities.dp(32), 0);
titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 24);
viewGroup.addView(titleTextView);
subtitleTextView = new TextView(context);
subtitleTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
subtitleTextView.setGravity(Gravity.CENTER_HORIZONTAL);
subtitleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
subtitleTextView.setSingleLine(true);
subtitleTextView.setEllipsize(TextUtils.TruncateAt.END);
if (currentType == ACTION_TYPE_NEARBY_GROUP_CREATE) {
subtitleTextView.setPadding(AndroidUtilities.dp(24), 0, AndroidUtilities.dp(24), 0);
} else {
subtitleTextView.setPadding(AndroidUtilities.dp(32), 0, AndroidUtilities.dp(32), 0);
}
subtitleTextView.setVisibility(View.GONE);
viewGroup.addView(subtitleTextView);
descriptionText = new TextView(context);
descriptionText.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText6));
descriptionText.setGravity(Gravity.CENTER_HORIZONTAL);
descriptionText.setLineSpacing(AndroidUtilities.dp(2), 1);
descriptionText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
if (currentType == ACTION_TYPE_NEARBY_GROUP_CREATE) {
descriptionText.setPadding(AndroidUtilities.dp(24), 0, AndroidUtilities.dp(24), 0);
} else {
descriptionText.setPadding(AndroidUtilities.dp(32), 0, AndroidUtilities.dp(32), 0);
}
viewGroup.addView(descriptionText);
if (currentType == ACTION_TYPE_QR_LOGIN) {
descriptionLayout = new LinearLayout(context);
descriptionLayout.setOrientation(LinearLayout.VERTICAL);
descriptionLayout.setPadding(AndroidUtilities.dp(24), 0, AndroidUtilities.dp(24), 0);
descriptionLayout.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
viewGroup.addView(descriptionLayout);
for (int a = 0; a < 3; a++) {
LinearLayout linearLayout = new LinearLayout(context);
linearLayout.setOrientation(LinearLayout.HORIZONTAL);
descriptionLayout.addView(linearLayout, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, 0, 0, 0, a != 2 ? 7 : 0));
desctiptionLines[a * 2] = new TextView(context);
desctiptionLines[a * 2].setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
desctiptionLines[a * 2].setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
desctiptionLines[a * 2].setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
desctiptionLines[a * 2].setText(String.format(LocaleController.isRTL ? ".%d" : "%d.", a + 1));
desctiptionLines[a * 2].setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
desctiptionLines[a * 2 + 1] = new TextView(context);
desctiptionLines[a * 2 + 1].setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
desctiptionLines[a * 2 + 1].setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
desctiptionLines[a * 2 + 1].setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
if (a == 0) {
desctiptionLines[a * 2 + 1].setLinkTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteLinkText));
desctiptionLines[a * 2 + 1].setHighlightColor(Theme.getColor(Theme.key_windowBackgroundWhiteLinkSelection));
String text = LocaleController.getString("AuthAnotherClientInfo1", R.string.AuthAnotherClientInfo1);
SpannableStringBuilder spanned = new SpannableStringBuilder(text);
int index1 = text.indexOf('*');
int index2 = text.lastIndexOf('*');
if (index1 != -1 && index2 != -1 && index1 != index2) {
desctiptionLines[a * 2 + 1].setMovementMethod(new AndroidUtilities.LinkMovementMethodMy());
spanned.replace(index2, index2 + 1, "");
spanned.replace(index1, index1 + 1, "");
spanned.setSpan(new URLSpanNoUnderline(LocaleController.getString("AuthAnotherClientDownloadClientUrl", R.string.AuthAnotherClientDownloadClientUrl)), index1, index2 - 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
desctiptionLines[a * 2 + 1].setText(spanned);
} else if (a == 1) {
desctiptionLines[a * 2 + 1].setText(LocaleController.getString("AuthAnotherClientInfo2", R.string.AuthAnotherClientInfo2));
} else {
desctiptionLines[a * 2 + 1].setText(LocaleController.getString("AuthAnotherClientInfo3", R.string.AuthAnotherClientInfo3));
}
if (LocaleController.isRTL) {
linearLayout.setGravity(Gravity.RIGHT);
linearLayout.addView(desctiptionLines[a * 2 + 1], LayoutHelper.createLinear(0, LayoutHelper.WRAP_CONTENT, 1.0f));
linearLayout.addView(desctiptionLines[a * 2], LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, 4, 0, 0, 0));
} else {
linearLayout.addView(desctiptionLines[a * 2], LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, 0, 0, 4, 0));
linearLayout.addView(desctiptionLines[a * 2 + 1], LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT));
}
}
descriptionText.setVisibility(View.GONE);
}
descriptionText2 = new TextView(context);
descriptionText2.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText6));
descriptionText2.setGravity(Gravity.CENTER_HORIZONTAL);
descriptionText2.setLineSpacing(AndroidUtilities.dp(2), 1);
descriptionText2.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 13);
descriptionText2.setVisibility(View.GONE);
if (currentType == ACTION_TYPE_NEARBY_GROUP_CREATE) {
descriptionText2.setPadding(AndroidUtilities.dp(18), 0, AndroidUtilities.dp(18), 0);
} else {
descriptionText2.setPadding(AndroidUtilities.dp(32), 0, AndroidUtilities.dp(32), 0);
}
viewGroup.addView(descriptionText2);
buttonTextView = new TextView(context) {
CellFlickerDrawable cellFlickerDrawable;
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (flickerButton) {
if (cellFlickerDrawable == null) {
cellFlickerDrawable = new CellFlickerDrawable();
cellFlickerDrawable.drawFrame = false;
cellFlickerDrawable.repeatProgress = 2f;
}
cellFlickerDrawable.setParentWidth(getMeasuredWidth());
AndroidUtilities.rectTmp.set(0, 0, getMeasuredWidth(), getMeasuredHeight());
cellFlickerDrawable.draw(canvas, AndroidUtilities.rectTmp, AndroidUtilities.dp(4));
invalidate();
}
}
};
buttonTextView.setPadding(AndroidUtilities.dp(34), 0, AndroidUtilities.dp(34), 0);
buttonTextView.setGravity(Gravity.CENTER);
buttonTextView.setTextColor(Theme.getColor(Theme.key_featuredStickers_buttonText));
buttonTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
buttonTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
buttonTextView.setBackgroundDrawable(Theme.createSimpleSelectorRoundRectDrawable(AndroidUtilities.dp(4), Theme.getColor(Theme.key_featuredStickers_addButton), Theme.getColor(Theme.key_featuredStickers_addButtonPressed)));
viewGroup.addView(buttonTextView);
buttonTextView.setOnClickListener(v -> {
if (getParentActivity() == null) {
return;
}
switch(currentType) {
case ACTION_TYPE_QR_LOGIN:
{
if (getParentActivity() == null) {
return;
}
if (Build.VERSION.SDK_INT >= 23 && getParentActivity().checkSelfPermission(Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
getParentActivity().requestPermissions(new String[] { Manifest.permission.CAMERA }, CAMERA_PERMISSION_REQUEST_CODE);
return;
}
processOpenQrReader();
break;
}
case ACTION_TYPE_CHANNEL_CREATE:
{
Bundle args = new Bundle();
args.putInt("step", 0);
presentFragment(new ChannelCreateActivity(args), true);
break;
}
case ACTION_TYPE_NEARBY_LOCATION_ACCESS:
{
getParentActivity().requestPermissions(new String[] { Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION }, 2);
break;
}
case ACTION_TYPE_NEARBY_LOCATION_ENABLED:
{
try {
getParentActivity().startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
} catch (Exception e) {
FileLog.e(e);
}
break;
}
case ACTION_TYPE_NEARBY_GROUP_CREATE:
{
if (currentGroupCreateAddress == null || currentGroupCreateLocation == null) {
return;
}
Bundle args = new Bundle();
long[] array = new long[] { getUserConfig().getClientUserId() };
args.putLongArray("result", array);
args.putInt("chatType", ChatObject.CHAT_TYPE_MEGAGROUP);
args.putString("address", currentGroupCreateAddress);
args.putParcelable("location", currentGroupCreateLocation);
presentFragment(new GroupCreateFinalActivity(args), true);
break;
}
case ACTION_TYPE_CHANGE_PHONE_NUMBER:
{
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("PhoneNumberChangeTitle", R.string.PhoneNumberChangeTitle));
builder.setMessage(LocaleController.getString("PhoneNumberAlert", R.string.PhoneNumberAlert));
builder.setPositiveButton(LocaleController.getString("Change", R.string.Change), (dialogInterface, i) -> presentFragment(new ChangePhoneActivity(), true));
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showDialog(builder.create());
break;
}
}
});
switch(currentType) {
case ACTION_TYPE_CHANNEL_CREATE:
{
imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
imageView.setAnimation(R.raw.channel_create, 200, 200);
titleTextView.setText(LocaleController.getString("ChannelAlertTitle", R.string.ChannelAlertTitle));
descriptionText.setText(LocaleController.getString("ChannelAlertText", R.string.ChannelAlertText));
buttonTextView.setText(LocaleController.getString("ChannelAlertCreate2", R.string.ChannelAlertCreate2));
imageView.playAnimation();
flickerButton = true;
break;
}
case ACTION_TYPE_NEARBY_LOCATION_ACCESS:
{
imageView.setBackgroundDrawable(Theme.createCircleDrawable(AndroidUtilities.dp(100), Theme.getColor(Theme.key_chats_archiveBackground)));
imageView.setImageDrawable(new ShareLocationDrawable(context, 3));
imageView.setScaleType(ImageView.ScaleType.CENTER);
titleTextView.setText(LocaleController.getString("PeopleNearby", R.string.PeopleNearby));
descriptionText.setText(LocaleController.getString("PeopleNearbyAccessInfo", R.string.PeopleNearbyAccessInfo));
buttonTextView.setText(LocaleController.getString("PeopleNearbyAllowAccess", R.string.PeopleNearbyAllowAccess));
break;
}
case ACTION_TYPE_NEARBY_LOCATION_ENABLED:
{
imageView.setBackgroundDrawable(Theme.createCircleDrawable(AndroidUtilities.dp(100), Theme.getColor(Theme.key_chats_archiveBackground)));
imageView.setImageDrawable(new ShareLocationDrawable(context, 3));
imageView.setScaleType(ImageView.ScaleType.CENTER);
titleTextView.setText(LocaleController.getString("PeopleNearby", R.string.PeopleNearby));
descriptionText.setText(LocaleController.getString("PeopleNearbyGpsInfo", R.string.PeopleNearbyGpsInfo));
buttonTextView.setText(LocaleController.getString("PeopleNearbyGps", R.string.PeopleNearbyGps));
break;
}
case ACTION_TYPE_QR_LOGIN:
{
colors = new int[8];
updateColors();
imageView.setAnimation(R.raw.qr_login, 334, 334, colors);
imageView.setScaleType(ImageView.ScaleType.CENTER);
titleTextView.setText(LocaleController.getString("AuthAnotherClient", R.string.AuthAnotherClient));
buttonTextView.setText(LocaleController.getString("AuthAnotherClientScan", R.string.AuthAnotherClientScan));
imageView.playAnimation();
break;
}
case ACTION_TYPE_NEARBY_GROUP_CREATE:
{
subtitleTextView.setVisibility(View.VISIBLE);
descriptionText2.setVisibility(View.VISIBLE);
imageView.setImageResource(Theme.getCurrentTheme().isDark() ? R.drawable.groupsintro2 : R.drawable.groupsintro);
imageView.setScaleType(ImageView.ScaleType.CENTER);
subtitleTextView.setText(currentGroupCreateDisplayAddress != null ? currentGroupCreateDisplayAddress : "");
titleTextView.setText(LocaleController.getString("NearbyCreateGroup", R.string.NearbyCreateGroup));
descriptionText.setText(LocaleController.getString("NearbyCreateGroupInfo", R.string.NearbyCreateGroupInfo));
descriptionText2.setText(LocaleController.getString("NearbyCreateGroupInfo2", R.string.NearbyCreateGroupInfo2));
buttonTextView.setText(LocaleController.getString("NearbyStartGroup", R.string.NearbyStartGroup));
break;
}
case ACTION_TYPE_CHANGE_PHONE_NUMBER:
{
subtitleTextView.setVisibility(View.VISIBLE);
drawable1 = context.getResources().getDrawable(R.drawable.sim_old);
drawable2 = context.getResources().getDrawable(R.drawable.sim_new);
drawable1.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_changephoneinfo_image), PorterDuff.Mode.MULTIPLY));
drawable2.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_changephoneinfo_image2), PorterDuff.Mode.MULTIPLY));
imageView.setImageDrawable(new CombinedDrawable(drawable1, drawable2));
imageView.setScaleType(ImageView.ScaleType.CENTER);
UserConfig userConfig = getUserConfig();
TLRPC.User user = getMessagesController().getUser(userConfig.clientUserId);
if (user == null) {
user = userConfig.getCurrentUser();
}
if (user != null) {
subtitleTextView.setText(PhoneFormat.getInstance().format("+" + user.phone));
}
titleTextView.setText(LocaleController.getString("PhoneNumberChange2", R.string.PhoneNumberChange2));
descriptionText.setText(AndroidUtilities.replaceTags(LocaleController.getString("PhoneNumberHelp", R.string.PhoneNumberHelp)));
buttonTextView.setText(LocaleController.getString("PhoneNumberChange2", R.string.PhoneNumberChange2));
break;
}
}
if (flickerButton) {
buttonTextView.setPadding(AndroidUtilities.dp(34), AndroidUtilities.dp(8), AndroidUtilities.dp(34), AndroidUtilities.dp(8));
buttonTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
}
return fragmentView;
}
Aggregations