Skip to content

Commit

Permalink
load url in WfcWebViewActivity
Browse files Browse the repository at this point in the history
  • Loading branch information
imndx committed Aug 30, 2019
1 parent 184352f commit 03c48e6
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 6 deletions.
17 changes: 11 additions & 6 deletions chat/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,19 @@
<activity android:name="cn.wildfire.chat.kit.channel.ChannelInfoActivity" />
<activity
android:name="cn.wildfire.chat.app.main.MainActivity"
android:launchMode="singleTask"
android:label="火信">
android:label="火信"
android:launchMode="singleTask">
<intent-filter>
<action android:name="${applicationId}.main" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="cn.wildfire.chat.kit.WfcWebViewActivity" />
<activity android:name="cn.wildfire.chat.kit.WfcWebViewActivity">
<intent-filter>
<action android:name="${applicationId}.webview" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="cn.wildfire.chat.kit.search.SearchMessageActivity" />
<activity android:name="cn.wildfire.chat.kit.channel.SearchChannelActivity" />
<activity android:name="cn.wildfire.chat.kit.group.PickGroupMemberActivity" />
Expand All @@ -216,10 +221,10 @@
<activity android:name="cn.wildfire.chat.kit.group.manage.AddGroupManagerActivity" />
<activity android:name="cn.wildfire.chat.kit.group.manage.GroupMuteActivity" />
<activity android:name="cn.wildfire.chat.kit.group.manage.GroupMemberPermissionActivity" />
<activity android:name="cn.wildfire.chat.kit.group.GroupMemberListActivity"
<activity
android:name="cn.wildfire.chat.kit.group.GroupMemberListActivity"
android:label="群成员列表"
android:screenOrientation="portrait"
/>
android:screenOrientation="portrait" />

<provider
android:name="androidx.core.content.FileProvider"
Expand Down
1 change: 1 addition & 0 deletions chat/src/main/java/cn/wildfire/chat/kit/WfcIntent.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ public interface WfcIntent {
String ACTION_USER_INFO = BuildConfig.APPLICATION_ID + ".user.info";
String ACTION_GROUP_INFO = BuildConfig.APPLICATION_ID + ".group.info";
String ACTION_VOIP_SINGLE = BuildConfig.APPLICATION_ID + ".kit.voip.single";
String ACTION_VIEW = BuildConfig.APPLICATION_ID + ".webview";
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@

import butterknife.Bind;
import butterknife.OnClick;
import cn.wildfire.chat.kit.WfcWebViewActivity;
import cn.wildfire.chat.kit.annotation.EnableContextMenu;
import cn.wildfire.chat.kit.annotation.MessageContentType;
import cn.wildfire.chat.kit.annotation.MessageContextMenuItem;
import cn.wildfire.chat.kit.annotation.ReceiveLayoutRes;
import cn.wildfire.chat.kit.annotation.SendLayoutRes;
import cn.wildfire.chat.kit.conversation.message.model.UiMessage;
import cn.wildfire.chat.kit.widget.LinkClickListener;
import cn.wildfire.chat.kit.widget.LinkTextViewMovementMethod;
import cn.wildfirechat.chat.R;
import cn.wildfirechat.message.TextMessageContent;

Expand All @@ -39,6 +42,13 @@ public TextMessageContentViewHolder(FragmentActivity activity, RecyclerView.Adap
@Override
public void onBind(UiMessage message) {
MoonUtils.identifyFaceExpression(context, contentTextView, ((TextMessageContent) message.message.content).getContent(), ImageSpan.ALIGN_BOTTOM);
contentTextView.setMovementMethod(new LinkTextViewMovementMethod(new LinkClickListener() {
@Override
public boolean onLinkClick(String link) {
WfcWebViewActivity.loadUrl(context, "", link);
return true;
}
}));
}

@OnClick(R.id.contentTextView)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package cn.wildfire.chat.kit.widget;

public interface LinkClickListener {
boolean onLinkClick(String link);
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package cn.wildfire.chat.kit.widget;

import android.text.Layout;
import android.text.Spannable;
import android.text.method.LinkMovementMethod;
import android.text.method.Touch;
import android.text.style.ClickableSpan;
import android.text.style.URLSpan;
import android.view.MotionEvent;
import android.view.ViewConfiguration;
import android.widget.TextView;

public class LinkTextViewMovementMethod extends LinkMovementMethod {

private long mLastActionDownTime;
private LinkClickListener mListener;

public LinkTextViewMovementMethod(LinkClickListener listener) {
mListener = listener;
}

@Override
public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
int action = event.getAction();

if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_DOWN) {
int x = (int) event.getX();
int y = (int) event.getY();

x -= widget.getTotalPaddingLeft();
y -= widget.getTotalPaddingTop();

x += widget.getScrollX();
y += widget.getScrollY();

Layout layout = widget.getLayout();
int line = layout.getLineForVertical(y);
int off = layout.getOffsetForHorizontal(line, x);

ClickableSpan[] link = buffer.getSpans(off, off, ClickableSpan.class);

if (link.length != 0) {
if (action == MotionEvent.ACTION_UP) {
long actionUpTime = System.currentTimeMillis();
if (actionUpTime - mLastActionDownTime > ViewConfiguration.getLongPressTimeout()) {
return true;
}
String url = null;
if (link[0] instanceof URLSpan)
url = ((URLSpan) link[0]).getURL();
if (mListener != null && mListener.onLinkClick(url))
return true;
else
link[0].onClick(widget);
} else if (action == MotionEvent.ACTION_DOWN) {
mLastActionDownTime = System.currentTimeMillis();
}
return true;
} else {
Touch.onTouchEvent(widget, buffer, event);
return false;
}
}
return Touch.onTouchEvent(widget, buffer, event);
}
}


0 comments on commit 03c48e6

Please sign in to comment.