Links in text messages are clickable and shorten if possible
This commit is contained in:
parent
6745c4eea0
commit
16a05cf208
5 changed files with 44 additions and 13 deletions
|
@ -19,6 +19,8 @@
|
||||||
android:gravity="bottom"
|
android:gravity="bottom"
|
||||||
android:singleLine="true"
|
android:singleLine="true"
|
||||||
android:paddingLeft="5dp"
|
android:paddingLeft="5dp"
|
||||||
|
android:linksClickable="true"
|
||||||
|
android:autoLink="web"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="match_parent" />
|
android:layout_height="match_parent" />
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,8 @@
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/message"
|
android:id="@+id/message"
|
||||||
|
android:linksClickable="true"
|
||||||
|
android:autoLink="web"
|
||||||
android:textColor="@android:color/black"
|
android:textColor="@android:color/black"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content" />
|
android:layout_height="wrap_content" />
|
||||||
|
|
|
@ -19,6 +19,8 @@
|
||||||
android:textSize="12dp"
|
android:textSize="12dp"
|
||||||
android:singleLine="true"
|
android:singleLine="true"
|
||||||
android:paddingLeft="5dp"
|
android:paddingLeft="5dp"
|
||||||
|
android:linksClickable="true"
|
||||||
|
android:autoLink="web"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content" />
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
android:id="@+id/message"
|
android:id="@+id/message"
|
||||||
android:layout_gravity="right"
|
android:layout_gravity="right"
|
||||||
android:textColor="@android:color/black"
|
android:textColor="@android:color/black"
|
||||||
|
android:linksClickable="true"
|
||||||
|
android:autoLink="web"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content" />
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
|
|
|
@ -28,8 +28,11 @@ import org.linphone.core.LinphoneChatMessage;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
|
import android.text.Html;
|
||||||
import android.text.Spannable;
|
import android.text.Spannable;
|
||||||
import android.text.SpannableStringBuilder;
|
import android.text.SpannableStringBuilder;
|
||||||
|
import android.text.Spanned;
|
||||||
|
import android.text.method.LinkMovementMethod;
|
||||||
import android.text.style.ImageSpan;
|
import android.text.style.ImageSpan;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
@ -62,7 +65,7 @@ public class BubbleChat {
|
||||||
emoticons.put(":-*", R.drawable.emo_im_kissing);
|
emoticons.put(":-*", R.drawable.emo_im_kissing);
|
||||||
emoticons.put(":*", R.drawable.emo_im_kissing);
|
emoticons.put(":*", R.drawable.emo_im_kissing);
|
||||||
emoticons.put(":-/", R.drawable.emo_im_undecided);
|
emoticons.put(":-/", R.drawable.emo_im_undecided);
|
||||||
emoticons.put(":/", R.drawable.emo_im_undecided);
|
emoticons.put(":/ ", R.drawable.emo_im_undecided);
|
||||||
emoticons.put(":-\\", R.drawable.emo_im_undecided);
|
emoticons.put(":-\\", R.drawable.emo_im_undecided);
|
||||||
emoticons.put(":\\", R.drawable.emo_im_undecided);
|
emoticons.put(":\\", R.drawable.emo_im_undecided);
|
||||||
emoticons.put(":-O", R.drawable.emo_im_surprised);
|
emoticons.put(":-O", R.drawable.emo_im_surprised);
|
||||||
|
@ -100,6 +103,13 @@ public class BubbleChat {
|
||||||
layoutParams.setMargins(0, LinphoneUtils.pixelsToDpi(context.getResources(), 10), 0, 0);
|
layoutParams.setMargins(0, LinphoneUtils.pixelsToDpi(context.getResources(), 10), 0, 0);
|
||||||
view.setLayoutParams(layoutParams);
|
view.setLayoutParams(layoutParams);
|
||||||
|
|
||||||
|
Spanned text;
|
||||||
|
if (context.getResources().getBoolean(R.bool.emoticons_in_messages)) {
|
||||||
|
text = getSmiledText(context, getTextWithHttpLinks(message));
|
||||||
|
} else {
|
||||||
|
text = getTextWithHttpLinks(message);
|
||||||
|
}
|
||||||
|
|
||||||
if (context.getResources().getBoolean(R.bool.display_messages_time)) {
|
if (context.getResources().getBoolean(R.bool.display_messages_time)) {
|
||||||
LinearLayout layout;
|
LinearLayout layout;
|
||||||
if (context.getResources().getBoolean(R.bool.display_time_aside)) {
|
if (context.getResources().getBoolean(R.bool.display_time_aside)) {
|
||||||
|
@ -117,11 +127,8 @@ public class BubbleChat {
|
||||||
}
|
}
|
||||||
|
|
||||||
TextView msgView = (TextView) layout.findViewById(R.id.message);
|
TextView msgView = (TextView) layout.findViewById(R.id.message);
|
||||||
if (context.getResources().getBoolean(R.bool.emoticons_in_messages)) {
|
msgView.setText(text);
|
||||||
msgView.setText(getSmiledText(context, message));
|
msgView.setMovementMethod(LinkMovementMethod.getInstance());
|
||||||
} else {
|
|
||||||
msgView.setText(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
TextView timeView = (TextView) layout.findViewById(R.id.time);
|
TextView timeView = (TextView) layout.findViewById(R.id.time);
|
||||||
timeView.setText(timestampToHumanDate(context, time));
|
timeView.setText(timestampToHumanDate(context, time));
|
||||||
|
@ -143,12 +150,9 @@ public class BubbleChat {
|
||||||
messageView.setId(id);
|
messageView.setId(id);
|
||||||
messageView.setTextColor(Color.BLACK);
|
messageView.setTextColor(Color.BLACK);
|
||||||
messageView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
|
messageView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
|
||||||
|
messageView.setText(text);
|
||||||
if (context.getResources().getBoolean(R.bool.emoticons_in_messages)) {
|
messageView.setLinksClickable(true);
|
||||||
messageView.setText(getSmiledText(context, message));
|
messageView.setMovementMethod(LinkMovementMethod.getInstance());
|
||||||
} else {
|
|
||||||
messageView.setText(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
view.addView(messageView);
|
view.addView(messageView);
|
||||||
}
|
}
|
||||||
|
@ -205,7 +209,7 @@ public class BubbleChat {
|
||||||
cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR));
|
cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Spannable getSmiledText(Context context, String text) {
|
public static Spannable getSmiledText(Context context, Spanned text) {
|
||||||
SpannableStringBuilder builder = new SpannableStringBuilder(text);
|
SpannableStringBuilder builder = new SpannableStringBuilder(text);
|
||||||
int index;
|
int index;
|
||||||
|
|
||||||
|
@ -224,4 +228,23 @@ public class BubbleChat {
|
||||||
}
|
}
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Spanned getTextWithHttpLinks(String text) {
|
||||||
|
if (text.contains("http://")) {
|
||||||
|
int indexHttp = text.indexOf("http://");
|
||||||
|
int indexFinHttp = text.indexOf(" ", indexHttp) == -1 ? text.length() : text.indexOf(" ", indexHttp);
|
||||||
|
String link = text.substring(indexHttp, indexFinHttp);
|
||||||
|
String linkWithoutScheme = link.replace("http://", "");
|
||||||
|
text = text.replaceFirst(link, "<a href=\"" + link + "\">" + linkWithoutScheme + "</a>");
|
||||||
|
}
|
||||||
|
if (text.contains("https://")) {
|
||||||
|
int indexHttp = text.indexOf("https://");
|
||||||
|
int indexFinHttp = text.indexOf(" ", indexHttp) == -1 ? text.length() : text.indexOf(" ", indexHttp);
|
||||||
|
String link = text.substring(indexHttp, indexFinHttp);
|
||||||
|
String linkWithoutScheme = link.replace("https://", "");
|
||||||
|
text = text.replaceFirst(link, "<a href=\"" + link + "\">" + linkWithoutScheme + "</a>");
|
||||||
|
}
|
||||||
|
|
||||||
|
return Html.fromHtml(text);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue