mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-20 12:09:45 +01:00
First step towards mention chips
Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
parent
19131ad853
commit
f4f96bb7d9
@ -17,8 +17,8 @@ android {
|
|||||||
targetSdkVersion 28
|
targetSdkVersion 28
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
|
|
||||||
versionCode 90
|
versionCode 91
|
||||||
versionName "6.0.0beta2"
|
versionName "6.0.0beta3"
|
||||||
|
|
||||||
flavorDimensions "default"
|
flavorDimensions "default"
|
||||||
renderscriptTargetApi 19
|
renderscriptTargetApi 19
|
||||||
@ -100,7 +100,6 @@ android {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ext {
|
ext {
|
||||||
supportLibraryVersion = '28.0.0'
|
|
||||||
workVersion = "1.0.0"
|
workVersion = "1.0.0"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,17 +114,17 @@ dependencies {
|
|||||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||||
implementation 'androidx.appcompat:appcompat:1.0.2'
|
implementation 'androidx.appcompat:appcompat:1.0.2'
|
||||||
implementation 'com.google.android.material:material:1.0.0'
|
implementation 'com.google.android.material:material:1.0.0'
|
||||||
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha3'
|
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha4'
|
||||||
implementation 'com.github.vanniktech:Emoji:746caa4623'
|
implementation 'com.github.vanniktech:Emoji:746caa4623'
|
||||||
implementation 'org.michaelevans.colorart:library:0.0.3'
|
implementation 'org.michaelevans.colorart:library:0.0.3'
|
||||||
implementation "android.arch.work:work-runtime:${workVersion}"
|
implementation "android.arch.work:work-runtime:${workVersion}"
|
||||||
implementation "android.arch.work:work-rxjava2:${workVersion}"
|
implementation "android.arch.work:work-rxjava2:${workVersion}"
|
||||||
androidTestImplementation "android.arch.work:work-testing:${workVersion}"
|
androidTestImplementation "android.arch.work:work-testing:${workVersion}"
|
||||||
|
|
||||||
implementation 'androidx.biometric:biometric:1.0.0-alpha03'
|
implementation 'androidx.biometric:biometric:1.0.0-alpha04'
|
||||||
implementation "androidx.lifecycle:lifecycle-extensions:2.0.0"
|
implementation "androidx.lifecycle:lifecycle-extensions:2.0.0"
|
||||||
|
|
||||||
implementation 'androidx.multidex:multidex:2.0.0'
|
implementation 'androidx.multidex:multidex:2.0.1'
|
||||||
|
|
||||||
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
|
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
|
||||||
implementation "io.reactivex.rxjava2:rxjava:2.2.7"
|
implementation "io.reactivex.rxjava2:rxjava:2.2.7"
|
||||||
|
@ -145,18 +145,22 @@ public class MagicIncomingTextMessageViewHolder
|
|||||||
Map<String, String> individualHashMap = message.getMessageParameters().get(key);
|
Map<String, String> individualHashMap = message.getMessageParameters().get(key);
|
||||||
if (individualHashMap != null) {
|
if (individualHashMap != null) {
|
||||||
if (individualHashMap.get("type").equals("user") || individualHashMap.get("type").equals("guest") || individualHashMap.get("type").equals("call")) {
|
if (individualHashMap.get("type").equals("user") || individualHashMap.get("type").equals("guest") || individualHashMap.get("type").equals("call")) {
|
||||||
int color;
|
|
||||||
|
|
||||||
if (individualHashMap.get("id").equals(message.getActiveUserId())) {
|
if (individualHashMap.get("id").equals(message.getActiveUserId())) {
|
||||||
color = NextcloudTalkApplication.getSharedApplication().getResources().getColor(R.color
|
messageString =
|
||||||
.nc_incoming_text_mention_you);
|
DisplayUtils.searchAndReplaceWithMentionSpan(messageText.getContext(),
|
||||||
|
messageString,
|
||||||
|
individualHashMap.get("id"),
|
||||||
|
individualHashMap.get("name"),
|
||||||
|
R.xml.chip_simple_background);
|
||||||
} else {
|
} else {
|
||||||
color = NextcloudTalkApplication.getSharedApplication().getResources().getColor(R.color
|
messageString =
|
||||||
.nc_incoming_text_mention_others);
|
DisplayUtils.searchAndReplaceWithMentionSpan(messageText.getContext(),
|
||||||
|
messageString,
|
||||||
|
individualHashMap.get("id"),
|
||||||
|
individualHashMap.get("name"),
|
||||||
|
R.xml.chip_accent_background);
|
||||||
}
|
}
|
||||||
|
|
||||||
messageString = DisplayUtils.searchAndColor(messageString,
|
|
||||||
"@" + individualHashMap.get("name"), color);
|
|
||||||
} else if (individualHashMap.get("type").equals("file")) {
|
} else if (individualHashMap.get("type").equals("file")) {
|
||||||
itemView.setOnClickListener(v -> {
|
itemView.setOnClickListener(v -> {
|
||||||
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(individualHashMap.get("link")));
|
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(individualHashMap.get("link")));
|
||||||
|
@ -58,6 +58,9 @@ public class MagicOutcomingTextMessageViewHolder extends MessageHolders.Outcomin
|
|||||||
@Inject
|
@Inject
|
||||||
UserUtils userUtils;
|
UserUtils userUtils;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
Context context;
|
||||||
|
|
||||||
private View itemView;
|
private View itemView;
|
||||||
|
|
||||||
public MagicOutcomingTextMessageViewHolder(View itemView) {
|
public MagicOutcomingTextMessageViewHolder(View itemView) {
|
||||||
@ -76,7 +79,6 @@ public class MagicOutcomingTextMessageViewHolder extends MessageHolders.Outcomin
|
|||||||
|
|
||||||
Spannable messageString = new SpannableString(message.getText());
|
Spannable messageString = new SpannableString(message.getText());
|
||||||
|
|
||||||
Context context = NextcloudTalkApplication.getSharedApplication().getApplicationContext();
|
|
||||||
itemView.setSelected(false);
|
itemView.setSelected(false);
|
||||||
messageTimeView.setTextColor(context.getResources().getColor(R.color.white60));
|
messageTimeView.setTextColor(context.getResources().getColor(R.color.white60));
|
||||||
|
|
||||||
@ -92,11 +94,19 @@ public class MagicOutcomingTextMessageViewHolder extends MessageHolders.Outcomin
|
|||||||
if (individualHashMap.get("type").equals("user") || individualHashMap.get("type").equals("guest") || individualHashMap.get("type").equals("call")) {
|
if (individualHashMap.get("type").equals("user") || individualHashMap.get("type").equals("guest") || individualHashMap.get("type").equals("call")) {
|
||||||
if (!individualHashMap.get("id").equals(message.getActiveUserId())) {
|
if (!individualHashMap.get("id").equals(message.getActiveUserId())) {
|
||||||
messageString =
|
messageString =
|
||||||
DisplayUtils.searchAndColor(messageString,
|
DisplayUtils.searchAndReplaceWithMentionSpan(messageText.getContext(),
|
||||||
"@" + individualHashMap.get("name"), NextcloudTalkApplication
|
messageString,
|
||||||
.getSharedApplication().getResources().getColor(R.color.nc_outcoming_text_default));
|
individualHashMap.get("id"),
|
||||||
|
individualHashMap.get("name"),
|
||||||
|
R.xml.chip_simple_background);
|
||||||
|
} else {
|
||||||
|
messageString =
|
||||||
|
DisplayUtils.searchAndReplaceWithMentionSpan(messageText.getContext(),
|
||||||
|
messageString,
|
||||||
|
individualHashMap.get("id"),
|
||||||
|
individualHashMap.get("name"),
|
||||||
|
R.xml.chip_outgoing_own_mention);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (individualHashMap.get("type").equals("file")) {
|
} else if (individualHashMap.get("type").equals("file")) {
|
||||||
itemView.setOnClickListener(v -> {
|
itemView.setOnClickListener(v -> {
|
||||||
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(individualHashMap.get("link")));
|
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(individualHashMap.get("link")));
|
||||||
|
@ -20,15 +20,24 @@
|
|||||||
|
|
||||||
package com.nextcloud.talk.callbacks;
|
package com.nextcloud.talk.callbacks;
|
||||||
|
|
||||||
import android.graphics.Typeface;
|
import android.content.Context;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
import android.text.Spanned;
|
import android.text.Spanned;
|
||||||
|
import android.text.style.DynamicDrawableSpan;
|
||||||
|
import com.nextcloud.talk.R;
|
||||||
import com.nextcloud.talk.models.json.mention.Mention;
|
import com.nextcloud.talk.models.json.mention.Mention;
|
||||||
|
import com.nextcloud.talk.utils.DisplayUtils;
|
||||||
import com.nextcloud.talk.utils.MagicCharPolicy;
|
import com.nextcloud.talk.utils.MagicCharPolicy;
|
||||||
import com.nextcloud.talk.utils.text.Spans;
|
import com.nextcloud.talk.utils.text.Spans;
|
||||||
import com.otaliastudios.autocomplete.AutocompleteCallback;
|
import com.otaliastudios.autocomplete.AutocompleteCallback;
|
||||||
|
|
||||||
public class MentionAutocompleteCallback implements AutocompleteCallback<Mention> {
|
public class MentionAutocompleteCallback implements AutocompleteCallback<Mention> {
|
||||||
|
private Context context;
|
||||||
|
|
||||||
|
public MentionAutocompleteCallback(Context context) {
|
||||||
|
this.context = context;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onPopupItemClicked(Editable editable, Mention item) {
|
public boolean onPopupItemClicked(Editable editable, Mention item) {
|
||||||
int[] range = MagicCharPolicy.getQueryRange(editable);
|
int[] range = MagicCharPolicy.getQueryRange(editable);
|
||||||
@ -37,8 +46,12 @@ public class MentionAutocompleteCallback implements AutocompleteCallback<Mention
|
|||||||
int end = range[1];
|
int end = range[1];
|
||||||
String replacement = item.getLabel();
|
String replacement = item.getLabel();
|
||||||
editable.replace(start, end, replacement + " ");
|
editable.replace(start, end, replacement + " ");
|
||||||
Spans.MentionSpan mentionSpan = new Spans.MentionSpan(Typeface.BOLD, item.getId(), item.getLabel());
|
Spans.MentionChipSpan mentionChipSpan =
|
||||||
editable.setSpan(mentionSpan, start, start + item.getLabel().length() , Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
|
new Spans.MentionChipSpan(DisplayUtils.getDrawableForMentionChipSpan(context,
|
||||||
|
item.getLabel(), R.xml.chip_accent_background), DynamicDrawableSpan.ALIGN_BASELINE,
|
||||||
|
item.getId(), item.getLabel());
|
||||||
|
editable.setSpan(mentionChipSpan, start, start + item.getLabel().length() ,
|
||||||
|
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,6 +118,8 @@ public class ChatController extends BaseController implements MessagesListAdapte
|
|||||||
UserUtils userUtils;
|
UserUtils userUtils;
|
||||||
@Inject
|
@Inject
|
||||||
AppPreferences appPreferences;
|
AppPreferences appPreferences;
|
||||||
|
@Inject
|
||||||
|
Context context;
|
||||||
@BindView(R.id.messagesListView)
|
@BindView(R.id.messagesListView)
|
||||||
MessagesList messagesListView;
|
MessagesList messagesListView;
|
||||||
@BindView(R.id.messageInputView)
|
@BindView(R.id.messageInputView)
|
||||||
@ -385,8 +387,9 @@ public class ChatController extends BaseController implements MessagesListAdapte
|
|||||||
}
|
}
|
||||||
|
|
||||||
Editable editable = messageInput.getEditableText();
|
Editable editable = messageInput.getEditableText();
|
||||||
Spans.MentionSpan[] mentionSpans = editable.getSpans(0, messageInput.length(), Spans.MentionSpan.class);
|
Spans.MentionChipSpan[] mentionSpans = editable.getSpans(0, messageInput.length(),
|
||||||
Spans.MentionSpan mentionSpan;
|
Spans.MentionChipSpan.class);
|
||||||
|
Spans.MentionChipSpan mentionSpan;
|
||||||
for (int i = 0; i < mentionSpans.length; i++) {
|
for (int i = 0; i < mentionSpans.length; i++) {
|
||||||
mentionSpan = mentionSpans[i];
|
mentionSpan = mentionSpans[i];
|
||||||
if (start >= editable.getSpanStart(mentionSpan) && start < editable.getSpanEnd(mentionSpan)) {
|
if (start >= editable.getSpanStart(mentionSpan) && start < editable.getSpanEnd(mentionSpan)) {
|
||||||
@ -482,7 +485,7 @@ public class ChatController extends BaseController implements MessagesListAdapte
|
|||||||
float elevation = 6f;
|
float elevation = 6f;
|
||||||
Drawable backgroundDrawable = new ColorDrawable(Color.WHITE);
|
Drawable backgroundDrawable = new ColorDrawable(Color.WHITE);
|
||||||
AutocompletePresenter<Mention> presenter = new MentionAutocompletePresenter(getApplicationContext(), roomToken);
|
AutocompletePresenter<Mention> presenter = new MentionAutocompletePresenter(getApplicationContext(), roomToken);
|
||||||
AutocompleteCallback<Mention> callback = new MentionAutocompleteCallback();
|
AutocompleteCallback<Mention> callback = new MentionAutocompleteCallback(getActivity());
|
||||||
|
|
||||||
if (mentionAutocomplete == null && messageInput != null) {
|
if (mentionAutocomplete == null && messageInput != null) {
|
||||||
mentionAutocomplete = Autocomplete.<Mention>on(messageInput)
|
mentionAutocomplete = Autocomplete.<Mention>on(messageInput)
|
||||||
@ -728,8 +731,9 @@ public class ChatController extends BaseController implements MessagesListAdapte
|
|||||||
|
|
||||||
private void submitMessage() {
|
private void submitMessage() {
|
||||||
final Editable editable = messageInput.getEditableText();
|
final Editable editable = messageInput.getEditableText();
|
||||||
Spans.MentionSpan mentionSpans[] = editable.getSpans(0, editable.length(), Spans.MentionSpan.class);
|
Spans.MentionChipSpan mentionSpans[] = editable.getSpans(0, editable.length(),
|
||||||
Spans.MentionSpan mentionSpan;
|
Spans.MentionChipSpan.class);
|
||||||
|
Spans.MentionChipSpan mentionSpan;
|
||||||
for (int i = 0; i < mentionSpans.length; i++) {
|
for (int i = 0; i < mentionSpans.length; i++) {
|
||||||
mentionSpan = mentionSpans[i];
|
mentionSpan = mentionSpans[i];
|
||||||
editable.replace(editable.getSpanStart(mentionSpan), editable.getSpanEnd(mentionSpan), "@" + mentionSpan.getId());
|
editable.replace(editable.getSpanStart(mentionSpan), editable.getSpanEnd(mentionSpan), "@" + mentionSpan.getId());
|
||||||
|
@ -32,6 +32,7 @@ import android.view.ViewGroup;
|
|||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.RequiresApi;
|
import androidx.annotation.RequiresApi;
|
||||||
import androidx.biometric.BiometricPrompt;
|
import androidx.biometric.BiometricPrompt;
|
||||||
|
import androidx.fragment.app.FragmentActivity;
|
||||||
import autodagger.AutoInjector;
|
import autodagger.AutoInjector;
|
||||||
import butterknife.OnClick;
|
import butterknife.OnClick;
|
||||||
import com.nextcloud.talk.R;
|
import com.nextcloud.talk.R;
|
||||||
@ -88,7 +89,7 @@ public class LockedController extends BaseController {
|
|||||||
|
|
||||||
Executor executor = Executors.newSingleThreadExecutor();
|
Executor executor = Executors.newSingleThreadExecutor();
|
||||||
|
|
||||||
final BiometricPrompt biometricPrompt = new BiometricPrompt((MainActivity) context, executor,
|
final BiometricPrompt biometricPrompt = new BiometricPrompt((FragmentActivity) context, executor,
|
||||||
new BiometricPrompt.AuthenticationCallback() {
|
new BiometricPrompt.AuthenticationCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onAuthenticationSucceeded(@NonNull BiometricPrompt.AuthenticationResult result) {
|
public void onAuthenticationSucceeded(@NonNull BiometricPrompt.AuthenticationResult result) {
|
||||||
|
@ -37,10 +37,7 @@ import android.net.Uri;
|
|||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.text.*;
|
import android.text.*;
|
||||||
import android.text.method.LinkMovementMethod;
|
import android.text.method.LinkMovementMethod;
|
||||||
import android.text.style.AbsoluteSizeSpan;
|
import android.text.style.*;
|
||||||
import android.text.style.ClickableSpan;
|
|
||||||
import android.text.style.ForegroundColorSpan;
|
|
||||||
import android.text.style.StyleSpan;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.TypedValue;
|
import android.util.TypedValue;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@ -57,8 +54,10 @@ import com.facebook.imagepipeline.image.ImageInfo;
|
|||||||
import com.facebook.imagepipeline.postprocessors.RoundAsCirclePostprocessor;
|
import com.facebook.imagepipeline.postprocessors.RoundAsCirclePostprocessor;
|
||||||
import com.facebook.imagepipeline.request.ImageRequest;
|
import com.facebook.imagepipeline.request.ImageRequest;
|
||||||
import com.facebook.imagepipeline.request.ImageRequestBuilder;
|
import com.facebook.imagepipeline.request.ImageRequestBuilder;
|
||||||
|
import com.google.android.material.chip.ChipDrawable;
|
||||||
import com.nextcloud.talk.R;
|
import com.nextcloud.talk.R;
|
||||||
import com.nextcloud.talk.application.NextcloudTalkApplication;
|
import com.nextcloud.talk.application.NextcloudTalkApplication;
|
||||||
|
import com.nextcloud.talk.utils.text.Spans;
|
||||||
import com.vanniktech.emoji.EmojiTextView;
|
import com.vanniktech.emoji.EmojiTextView;
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
@ -209,6 +208,38 @@ public class DisplayUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static Drawable getDrawableForMentionChipSpan(Context context, String label, @XmlRes int chipResource) {
|
||||||
|
ChipDrawable chip = ChipDrawable.createFromResource(context, chipResource);
|
||||||
|
chip.setText(label);
|
||||||
|
chip.setBounds(0, 0, chip.getIntrinsicWidth(), chip.getIntrinsicHeight());
|
||||||
|
return chip;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Spannable searchAndReplaceWithMentionSpan(Context context, Spannable text,
|
||||||
|
String id, String label,
|
||||||
|
@XmlRes int chipXmlRes) {
|
||||||
|
|
||||||
|
Spannable spannableString = new SpannableString(text);
|
||||||
|
String stringText = text.toString();
|
||||||
|
|
||||||
|
Matcher m = Pattern.compile("@" + label,
|
||||||
|
Pattern.CASE_INSENSITIVE | Pattern.LITERAL | Pattern.MULTILINE)
|
||||||
|
.matcher(spannableString);
|
||||||
|
|
||||||
|
int lastStartIndex = -1;
|
||||||
|
Spans.MentionChipSpan mentionChipSpan;
|
||||||
|
while (m.find()) {
|
||||||
|
int start = stringText.indexOf(m.group(), lastStartIndex);
|
||||||
|
int end = start + m.group().length();
|
||||||
|
lastStartIndex = end;
|
||||||
|
mentionChipSpan = new Spans.MentionChipSpan(DisplayUtils.getDrawableForMentionChipSpan(context,
|
||||||
|
label, chipXmlRes), DynamicDrawableSpan.ALIGN_BASELINE, id, label);
|
||||||
|
spannableString.setSpan(mentionChipSpan, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||||
|
}
|
||||||
|
|
||||||
|
return spannableString;
|
||||||
|
|
||||||
|
}
|
||||||
public static Spannable searchAndColor(Spannable text, String searchText, @ColorInt int color) {
|
public static Spannable searchAndColor(Spannable text, String searchText, @ColorInt int color) {
|
||||||
|
|
||||||
Spannable spannableString = new SpannableString(text);
|
Spannable spannableString = new SpannableString(text);
|
||||||
|
@ -20,20 +20,23 @@
|
|||||||
|
|
||||||
package com.nextcloud.talk.utils.text;
|
package com.nextcloud.talk.utils.text;
|
||||||
|
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
import android.text.style.StyleSpan;
|
import android.text.style.StyleSpan;
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
public class Spans {
|
public class Spans {
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public static class MentionSpan extends StyleSpan {
|
public static class MentionChipSpan extends TextAlignedImageSpan {
|
||||||
String id;
|
String id;
|
||||||
String label;
|
String label;
|
||||||
|
|
||||||
public MentionSpan(int style, String id, String label) {
|
public MentionChipSpan(@NonNull Drawable drawable, int verticalAlignment, String id, String label) {
|
||||||
super(style);
|
super(drawable, verticalAlignment);
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.label = label;
|
this.label = label;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@ -0,0 +1,71 @@
|
|||||||
|
/*
|
||||||
|
* Nextcloud Talk application
|
||||||
|
*
|
||||||
|
* @author Mario Danic
|
||||||
|
* Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* Taken and adapter from
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.nextcloud.talk.utils.text;
|
||||||
|
|
||||||
|
import android.graphics.Canvas;
|
||||||
|
import android.graphics.Paint;
|
||||||
|
import android.graphics.Rect;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.text.style.ImageSpan;
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
|
public class TextAlignedImageSpan extends ImageSpan {
|
||||||
|
public TextAlignedImageSpan(@NonNull Drawable drawable, int verticalAlignment) {
|
||||||
|
super(drawable, verticalAlignment);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSize(@NonNull Paint paint, CharSequence text, int start, int end,
|
||||||
|
Paint.FontMetricsInt fontMetricsInt) {
|
||||||
|
Drawable drawable = getDrawable();
|
||||||
|
Rect drawableBounds = drawable.getBounds();
|
||||||
|
|
||||||
|
if (fontMetricsInt != null) {
|
||||||
|
Paint.FontMetricsInt fmPaint = paint.getFontMetricsInt();
|
||||||
|
int fontHeight = fmPaint.bottom - fmPaint.top;
|
||||||
|
int drHeight = drawableBounds.bottom - drawableBounds.top;
|
||||||
|
|
||||||
|
int top = drHeight / 2 - fontHeight / 4;
|
||||||
|
int bottom = drHeight / 2 + fontHeight / 4;
|
||||||
|
|
||||||
|
fontMetricsInt.ascent = -bottom;
|
||||||
|
fontMetricsInt.top = -bottom;
|
||||||
|
fontMetricsInt.bottom = top;
|
||||||
|
fontMetricsInt.descent = top;
|
||||||
|
}
|
||||||
|
|
||||||
|
return drawableBounds.right;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void draw(@NonNull Canvas canvas, CharSequence text, int start, int end,
|
||||||
|
float x, int top, int y, int bottom, @NonNull Paint paint) {
|
||||||
|
Drawable drawable = getDrawable();
|
||||||
|
canvas.save();
|
||||||
|
int transY;
|
||||||
|
transY = ((bottom - top) - drawable.getBounds().bottom) / 2 + top;
|
||||||
|
canvas.translate(x, transY);
|
||||||
|
drawable.draw(canvas);
|
||||||
|
canvas.restore();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -52,6 +52,7 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:textColor="@color/colorPrimary"
|
android:textColor="@color/colorPrimary"
|
||||||
|
android:layout_marginBottom="4dp"
|
||||||
android:textSize="12sp" />
|
android:textSize="12sp" />
|
||||||
|
|
||||||
<com.vanniktech.emoji.EmojiTextView
|
<com.vanniktech.emoji.EmojiTextView
|
||||||
@ -59,11 +60,11 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:textIsSelectable="true"
|
android:textIsSelectable="true"
|
||||||
|
android:lineSpacingMultiplier="1.2"
|
||||||
app:layout_alignSelf="flex_start"
|
app:layout_alignSelf="flex_start"
|
||||||
app:layout_flexGrow="1"
|
app:layout_flexGrow="1"
|
||||||
app:layout_wrapBefore="true" />
|
app:layout_wrapBefore="true" />
|
||||||
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@id/messageTime"
|
android:id="@id/messageTime"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
@ -44,6 +44,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_alignWithParentIfMissing="true"
|
android:layout_alignWithParentIfMissing="true"
|
||||||
android:textColorHighlight="@color/nc_grey"
|
android:textColorHighlight="@color/nc_grey"
|
||||||
|
android:lineSpacingMultiplier="1.2"
|
||||||
android:textIsSelectable="true" />
|
android:textIsSelectable="true" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
@ -40,6 +40,7 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_centerVertical="true"
|
android:layout_centerVertical="true"
|
||||||
|
android:lineSpacingMultiplier="1.2"
|
||||||
android:imeOptions="actionDone"
|
android:imeOptions="actionDone"
|
||||||
android:layout_toStartOf="@id/sendButtonSpace"
|
android:layout_toStartOf="@id/sendButtonSpace"
|
||||||
android:inputType="textAutoCorrect|textMultiLine|textCapSentences"/>
|
android:inputType="textAutoCorrect|textMultiLine|textCapSentences"/>
|
||||||
|
@ -15,4 +15,12 @@
|
|||||||
<item name="android:textSize">12sp</item>
|
<item name="android:textSize">12sp</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
<style name="ChipTextAppearance" parent="TextAppearance.MaterialComponents.Chip">
|
||||||
|
<item name="android:textColor">@android:color/white</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<style name="ChipAccentTextAppearance" parent="TextAppearance.MaterialComponents.Chip">
|
||||||
|
<item name="android:textColor">@color/colorAccent</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
26
app/src/main/res/xml/chip_accent_background.xml
Normal file
26
app/src/main/res/xml/chip_accent_background.xml
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
~ Nextcloud Talk application
|
||||||
|
~
|
||||||
|
~ @author Mario Danic
|
||||||
|
~ Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com>
|
||||||
|
~
|
||||||
|
~ This program is free software: you can redistribute it and/or modify
|
||||||
|
~ it under the terms of the GNU General Public License as published by
|
||||||
|
~ the Free Software Foundation, either version 3 of the License, or
|
||||||
|
~ at your option) any later version.
|
||||||
|
~
|
||||||
|
~ This program is distributed in the hope that it will be useful,
|
||||||
|
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
~ GNU General Public License for more details.
|
||||||
|
~
|
||||||
|
~ You should have received a copy of the GNU General Public License
|
||||||
|
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<chip xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:textAppearance="@style/ChipTextAppearance"
|
||||||
|
app:chipBackgroundColor="@color/colorAccent"
|
||||||
|
app:closeIconEnabled="false"/>
|
26
app/src/main/res/xml/chip_outgoing_own_mention.xml
Normal file
26
app/src/main/res/xml/chip_outgoing_own_mention.xml
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
~ Nextcloud Talk application
|
||||||
|
~
|
||||||
|
~ @author Mario Danic
|
||||||
|
~ Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com>
|
||||||
|
~
|
||||||
|
~ This program is free software: you can redistribute it and/or modify
|
||||||
|
~ it under the terms of the GNU General Public License as published by
|
||||||
|
~ the Free Software Foundation, either version 3 of the License, or
|
||||||
|
~ at your option) any later version.
|
||||||
|
~
|
||||||
|
~ This program is distributed in the hope that it will be useful,
|
||||||
|
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
~ GNU General Public License for more details.
|
||||||
|
~
|
||||||
|
~ You should have received a copy of the GNU General Public License
|
||||||
|
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<chip xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:textAppearance="@style/ChipTextAppearance"
|
||||||
|
app:chipBackgroundColor="@color/white_five"
|
||||||
|
app:closeIconEnabled="false" />
|
26
app/src/main/res/xml/chip_simple_background.xml
Normal file
26
app/src/main/res/xml/chip_simple_background.xml
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
~ Nextcloud Talk application
|
||||||
|
~
|
||||||
|
~ @author Mario Danic
|
||||||
|
~ Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com>
|
||||||
|
~
|
||||||
|
~ This program is free software: you can redistribute it and/or modify
|
||||||
|
~ it under the terms of the GNU General Public License as published by
|
||||||
|
~ the Free Software Foundation, either version 3 of the License, or
|
||||||
|
~ at your option) any later version.
|
||||||
|
~
|
||||||
|
~ This program is distributed in the hope that it will be useful,
|
||||||
|
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
~ GNU General Public License for more details.
|
||||||
|
~
|
||||||
|
~ You should have received a copy of the GNU General Public License
|
||||||
|
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<chip xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:textAppearance="@style/ChipAccentTextAppearance"
|
||||||
|
app:chipBackgroundColor="@color/white"
|
||||||
|
app:closeIconEnabled="false" />
|
Loading…
Reference in New Issue
Block a user