mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-20 08:39:22 +01:00
Add UI components for Release Channel.
This commit is contained in:
@@ -111,6 +111,7 @@ public class AttachmentUtil {
|
||||
return recipient.isSystemContact() ||
|
||||
recipient.isProfileSharing() ||
|
||||
message.isOutgoing() ||
|
||||
recipient.isSelf();
|
||||
recipient.isSelf() ||
|
||||
recipient.isReleaseNotes();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.thoughtcrime.securesms.util;
|
||||
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.ColorInt;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
/**
|
||||
@@ -14,7 +15,15 @@ public final class InterceptableLongClickCopyLinkSpan extends LongClickCopySpan
|
||||
public InterceptableLongClickCopyLinkSpan(@NonNull String url,
|
||||
@NonNull UrlClickHandler onClickListener)
|
||||
{
|
||||
super(url);
|
||||
this(url, onClickListener, null, true);
|
||||
}
|
||||
|
||||
public InterceptableLongClickCopyLinkSpan(@NonNull String url,
|
||||
@NonNull UrlClickHandler onClickListener,
|
||||
@ColorInt Integer textColor,
|
||||
boolean underline)
|
||||
{
|
||||
super(url, textColor, underline);
|
||||
this.onClickListener = onClickListener;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package org.thoughtcrime.securesms.util;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.ClipData;
|
||||
import android.content.Context;
|
||||
import android.text.TextPaint;
|
||||
import android.text.style.URLSpan;
|
||||
@@ -21,23 +19,34 @@ public class LongClickCopySpan extends URLSpan {
|
||||
@ColorInt
|
||||
private int highlightColor;
|
||||
|
||||
private final Integer textColor;
|
||||
private final boolean underline;
|
||||
|
||||
public LongClickCopySpan(String url) {
|
||||
this(url, null, true);
|
||||
}
|
||||
|
||||
public LongClickCopySpan(String url, @ColorInt Integer textColor, boolean underline) {
|
||||
super(url);
|
||||
this.textColor = textColor;
|
||||
this.underline = underline;
|
||||
}
|
||||
|
||||
void onLongClick(View widget) {
|
||||
Context context = widget.getContext();
|
||||
String preparedUrl = prepareUrl(getURL());
|
||||
copyUrl(context, preparedUrl);
|
||||
Toast.makeText(context,
|
||||
context.getString(R.string.ConversationItem_copied_text, preparedUrl), Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(context, context.getString(R.string.ConversationItem_copied_text, preparedUrl), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDrawState(@NonNull TextPaint ds) {
|
||||
super.updateDrawState(ds);
|
||||
if (textColor != null) {
|
||||
ds.setColor(textColor);
|
||||
}
|
||||
ds.bgColor = highlightColor;
|
||||
ds.setUnderlineText(!isHighlighted);
|
||||
ds.setUnderlineText(!isHighlighted && underline);
|
||||
}
|
||||
|
||||
void setHighlighted(boolean highlighted, @ColorInt int highlightColor) {
|
||||
@@ -46,22 +55,7 @@ public class LongClickCopySpan extends URLSpan {
|
||||
}
|
||||
|
||||
private void copyUrl(Context context, String url) {
|
||||
int sdk = android.os.Build.VERSION.SDK_INT;
|
||||
if (sdk < android.os.Build.VERSION_CODES.HONEYCOMB) {
|
||||
@SuppressWarnings("deprecation") android.text.ClipboardManager clipboard =
|
||||
(android.text.ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
clipboard.setText(url);
|
||||
} else {
|
||||
copyUriSdk11(context, url);
|
||||
}
|
||||
}
|
||||
|
||||
@TargetApi(android.os.Build.VERSION_CODES.HONEYCOMB)
|
||||
private void copyUriSdk11(Context context, String url) {
|
||||
android.content.ClipboardManager clipboard =
|
||||
(android.content.ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
ClipData clip = ClipData.newPlainText(context.getString(R.string.app_name), url);
|
||||
clipboard.setPrimaryClip(clip);
|
||||
Util.writeTextToClipboard(context, url);
|
||||
}
|
||||
|
||||
private String prepareUrl(String url) {
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package org.thoughtcrime.securesms.util
|
||||
|
||||
/**
|
||||
* LinkifyCompat.addLinks() will strip pre-existing URLSpans. This acts as a way to
|
||||
* indicate where a link should be added without being stripped. The consumer is
|
||||
* responsible for replacing the placeholder with an actual URLSpan.
|
||||
*/
|
||||
class PlaceholderURLSpan(url: String) : android.text.Annotation("placeholderUrl", url)
|
||||
@@ -47,6 +47,7 @@ import com.google.i18n.phonenumbers.Phonenumber;
|
||||
|
||||
import org.signal.core.util.logging.Log;
|
||||
import org.thoughtcrime.securesms.BuildConfig;
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.components.ComposeText;
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore;
|
||||
import org.thoughtcrime.securesms.mms.OutgoingLegacyMmsConnection;
|
||||
@@ -466,10 +467,13 @@ public class Util {
|
||||
}
|
||||
|
||||
public static void writeTextToClipboard(@NonNull Context context, @NonNull String text) {
|
||||
{
|
||||
ClipboardManager clipboardManager = (ClipboardManager)context.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
clipboardManager.setPrimaryClip(ClipData.newPlainText("Safety numbers", text));
|
||||
}
|
||||
writeTextToClipboard(context, context.getString(R.string.app_name), text);
|
||||
}
|
||||
|
||||
public static void writeTextToClipboard(@NonNull Context context, @NonNull String label, @NonNull String text) {
|
||||
android.content.ClipboardManager clipboard = (android.content.ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
ClipData clip = ClipData.newPlainText(label, text);
|
||||
clipboard.setPrimaryClip(clip);
|
||||
}
|
||||
|
||||
public static int toIntExact(long value) {
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package org.thoughtcrime.securesms.util.views
|
||||
|
||||
import android.view.View
|
||||
import android.view.ViewTreeObserver
|
||||
import androidx.core.util.Consumer
|
||||
|
||||
/**
|
||||
* Given a view and a corner radius set callback, calculate the appropriate radius to
|
||||
* make the view have fully rounded sides (height/2).
|
||||
*/
|
||||
class AutoRounder<T : View> private constructor(private val view: T, private val setRadius: Consumer<Float>) : ViewTreeObserver.OnGlobalLayoutListener {
|
||||
override fun onGlobalLayout() {
|
||||
if (view.height > 0) {
|
||||
setRadius.accept(view.height.toFloat() / 2f)
|
||||
view.viewTreeObserver.removeOnGlobalLayoutListener(this)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun <VIEW : View> autoSetCorners(view: VIEW, setRadius: Consumer<Float>) {
|
||||
view.viewTreeObserver.addOnGlobalLayoutListener(AutoRounder(view, setRadius))
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user