Commit 99e2ef44 by zhengnw@sobot.com

widget 1.1.0 html 富文本,webview

parent 29b542d6
......@@ -7,10 +7,8 @@ import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.widget.ImageView;
import android.widget.TextView;
import com.sobot.common.login.SobotLoginTools;
import com.sobot.common.login.callback.SobotResultBlock;
import com.sobot.common.login.callback.SobotResultCode;
import com.sobot.common.utils.SobotImageUtils;
import com.sobot.pictureframe.SobotBitmapUtil;
import com.sobot.utils.SobotLogUtils;
......@@ -23,6 +21,7 @@ import com.sobot.widget.refresh.layout.footer.ClassicsFooter;
import com.sobot.widget.refresh.layout.header.ClassicsHeader;
import com.sobot.widget.ui.SobotMarkConfig;
import com.sobot.widget.ui.base.SobotBaseActivity;
import com.sobot.widget.ui.rich.HtmlToolUtils;
import com.sobot.widget.ui.toast.SobotToastUtil;
import java.io.File;
......@@ -34,6 +33,7 @@ public class MainActivity extends SobotBaseActivity {
private ImageView img;
private SobotPhotoView img2;
private SobotLoadingLayout loadinglayout;
private TextView tv;
@Override
......@@ -43,7 +43,8 @@ public class MainActivity extends SobotBaseActivity {
@Override
protected void initView() {
tv = findViewById(R.id.tv);
HtmlToolUtils.getInstance(MainActivity.this).setRichText(tv, "<h3><span style=\"color: rgb(255, 77, 79);\"><strong>【若摄像机因出现自动呼叫导致设备离线,建议您</strong></span><span style=\"color: rgb(0, 0, 0);\"><strong>优先更换电</strong></span><span style=\"color: rgb(255, 77, 79);\"><strong>源适配器尝试。若</strong></span><span style=\"color: rgb(235, 144, 58);\"><strong>设备恢复正常建</strong></span><span style=\"color: rgb(255, 77, 79);\"><strong>议联系在</strong></span><span style=\"color: rgb(115, 209, 61);\"><strong>线人工客服</strong></span><span style=\"color: rgb(255, 77, 79);\"><strong>咨询(早9-晚21),</strong></span><span style=\"color: rgb(38, 38, 38);\"><strong>若仍无法解决</strong></span><span style=\"color: rgb(255, 77, 79);\"><strong>建议您按以下方式排查】</strong></span></h3><h2>您好,若是摄像机联网成功后,突然离线,建议您按以下方式排查:一、离线后,请确认最近摄像机环境是否有变化,是否更换过路由器,目前仅<span style=\"color: rgb(225, 60, 57);\">AB2L、P8MAX、K6pro、P8 pro</span>型号摄像机支持5GWiFi,其余型号摄像机需连接2.4G网络。请查看摄像机信息里面的WIFI信号强度(尽可能大于80%),检查摄像机所处环境中电源、网络是否正常。</h2><h2>二、重新插拔电源线,如果设备没有问题,18510555567每次通电后,都是先绿灯常亮然后是绿灯闪烁。如果不亮,可能是适配器电源线或者摄像机有问题,这种情况建议您更换适配器或电源线,还不行则需要寄回售后检测维修。</h2><p>三、建议您重新连接(如果有安装内存卡,建议取出内存卡,不排除内存卡损坏导致设备离线的可能),重新连接方式如下:</p><p>1)直接点击右上角加号,选择“连接我的摄像机”2)摄像机设置中,选择“让摄像机连接到其他WIFI”</p><p>四、建议更换网络WiFi或连接手机热点尝试。五、查看固件 <a href=\"https://www.baidu.com\" target=\"_blank\">百度</a> 版本是否最新,若不是建议升级固件,并重新联网尝试。</p><p>若仍无法解决,可点击【自助报修】或通过“360智慧生活服务”公众号报修。&lt;/p&gt;</p>", R.color.sobot_common_green);
SobotToastUtil.showCustomToast(getSobotBaseActivity(), "sdafdsafsadfasdfsdaf");
SobotWidgetApi.setSwitchMarkStatus(SobotMarkConfig.SHOW_PERMISSION_TIPS_POP, true);
setTitle("ddddd");
......
......@@ -19,6 +19,7 @@
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!" />
......
......@@ -13,7 +13,7 @@ ext {
PUBLISH_GROUP_ID = "com.sobot.library" //项目包名
PUBLISH_ARTIFACT_ID = 'widget' //项目名
// PUBLISH_ARTIFACT_ID = 'widget_x' //项目名
PUBLISH_VERSION = '1.0.9' //版本号
PUBLISH_VERSION = '1.1.0' //版本号
}
......
......@@ -23,5 +23,12 @@
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/sobot_provider_paths" />
</provider>
<activity
android:name=".ui.webview.SobotWebViewActivity"
android:configChanges="orientation|keyboardHidden|screenSize|touchscreen|navigation|locale|fontScale|uiMode|screenLayout|smallestScreenSize"
android:screenOrientation="behind"
android:theme="@style/sobot_activity_def_theme"
android:windowSoftInputMode="adjustResize" />
</application>
</manifest>
\ No newline at end of file
package com.sobot.widget.ui.rich;
import android.app.Activity;
import android.content.Context;
import android.support.v4.app.ShareCompat;
import android.text.TextPaint;
import android.text.style.ClickableSpan;
import android.view.View;
public class EmailSpan extends ClickableSpan {
private String email;
private int color;
private Context context;
public EmailSpan(Context context, String email, int color) {
this.email = email;
this.context=context;
this.color = context.getResources().getColor(color);
}
@Override
public void onClick(View widget) {
if (SobotOption.hyperlinkListener != null) {
//如果返回true,拦截;false 不拦截
boolean isIntercept = SobotOption.hyperlinkListener.onEmailClick(context,email);
if (isIntercept) {
return;
}
}
try {
ShareCompat.IntentBuilder builder = ShareCompat.IntentBuilder
.from((Activity) widget.getContext());
builder.setType("message/rfc822");
builder.addEmailTo(email);
builder.setSubject("");
builder.setChooserTitle("");
builder.startChooser();
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void updateDrawState(TextPaint ds) {
ds.setColor(color);
ds.setUnderlineText(false); // 去掉下划线
}
}
\ No newline at end of file
package com.sobot.widget.ui.rich;
import android.content.Context;
/**
* 超链接点击的监听事件
*/
public interface HyperlinkListener {
// 链接的点击事件, 根据返回结果判断是否拦截 如果返回true,拦截;false 不拦截
boolean onUrlClick(Context context, String url);
//邮箱的点击拦截事件, 根据返回结果判断是否拦截 如果返回true,拦截;false 不拦截
boolean onEmailClick(Context context, String email);
//电话的点击拦截事件, 根据返回结果判断是否拦截 如果返回true,拦截;false 不拦截
boolean onPhoneClick(Context context, String phone);
}
\ No newline at end of file
package com.sobot.widget.ui.rich;
import android.text.Layout;
import android.text.Selection;
import android.text.Spannable;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.view.MotionEvent;
import android.widget.TextView;
public class LinkMovementClickMethod extends LinkMovementMethod {
private long lastClickTime;
private static final long CLICK_DELAY = 500l;
@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) {
if(System.currentTimeMillis() - lastClickTime < CLICK_DELAY){
link[0].onClick(widget);
}
} else if (action == MotionEvent.ACTION_DOWN) {
Selection.setSelection(buffer,
buffer.getSpanStart(link[0]),
buffer.getSpanEnd(link[0]));
lastClickTime = System.currentTimeMillis();
}
return true;
} else {
Selection.removeSelection(buffer);
}
}
return super.onTouchEvent(widget, buffer, event);
}
public static LinkMovementClickMethod getInstance(){
if(null == sInstance){
sInstance = new LinkMovementClickMethod();
}
return sInstance;
}
private static LinkMovementClickMethod sInstance;
}
package com.sobot.widget.ui.rich;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.text.TextPaint;
import android.text.style.URLSpan;
import android.view.View;
import com.sobot.utils.SobotLogUtils;
import com.sobot.widget.ui.webview.SobotWebViewActivity;
public class MyURLSpan extends URLSpan {
private Context context;
private int color;
private boolean isShowLine;// 下划线
public MyURLSpan(Context context, String url, int color) {
this(context, url, color, false);
}
public MyURLSpan(Context context, String url, int color, boolean isShowLine) {
super(url);
this.context = context;
this.color = context.getResources().getColor(color);
this.isShowLine = isShowLine;
}
@Override
public void onClick(View widget) {
String url = getURL();
// LogUtils.i("url:" + url);
if (url.startsWith("innerUrl:")) {
//不是超链接 而是自己内部的逻辑链接
if (SobotOption.hyperlinkListener != null) {
//如果返回true,拦截;false 不拦截
boolean isIntercept = SobotOption.hyperlinkListener.onUrlClick(context, url);
if (isIntercept) {
return;
}
}
} else {
if (url.endsWith(".doc") || url.endsWith(".docx") || url.endsWith(".xls")
|| url.endsWith(".txt") || url.endsWith(".ppt") || url.endsWith(".pptx")
|| url.endsWith(".xlsx") || url.endsWith(".pdf") || url.endsWith(".rar")
|| url.endsWith(".zip")) {// 内部浏览器不支持,所以打开外部
if (SobotOption.hyperlinkListener != null) {
//如果返回true,拦截;false 不拦截
boolean isIntercept = SobotOption.hyperlinkListener.onUrlClick(context, url);
if (isIntercept) {
return;
}
}
url = fixUrl(url);
// 外部浏览器
Intent intent = new Intent();
intent.setAction("android.intent.action.VIEW");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Uri content = Uri.parse(url);
intent.setData(content);
context.startActivity(intent);
} else if (url.startsWith("tel:")) {
if (SobotOption.hyperlinkListener != null) {
boolean isIntercept = SobotOption.hyperlinkListener.onPhoneClick(context, url);
if (isIntercept) {
return;
}
}
Intent intent = new Intent();
intent.setAction("android.intent.action.VIEW");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setData(Uri.parse(url));// mobile为你要拨打的电话号码,模拟器中为模拟器编号也可
context.startActivity(intent);
} else {
// 内部浏览器
if (SobotOption.hyperlinkListener != null) {
//如果返回true,拦截;false 不拦截
boolean isIntercept = SobotOption.hyperlinkListener.onUrlClick(context, url);
if (isIntercept) {
return;
}
}
url = fixUrl(url);
Intent intent = new Intent(context, SobotWebViewActivity.class);
intent.putExtra("url", url);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
}
}
private String fixUrl(String url) {
if (!(url.startsWith("http://") || url.startsWith("https://"))) {
url = "https://" + url;
SobotLogUtils.i("url:" + url);
}
return url;
}
@Override
public void updateDrawState(TextPaint ds) {
ds.setColor(color);
ds.setUnderlineText(isShowLine);
}
}
\ No newline at end of file
package com.sobot.widget.ui.rich;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.text.TextPaint;
import android.text.style.ClickableSpan;
import android.view.View;
import com.sobot.widget.R;
import com.sobot.widget.ui.toast.SobotToastUtil;
public class PhoneSpan extends ClickableSpan {
private String phone;
private int color;
private Context context;
public PhoneSpan(Context context, String phone, int color) {
this.phone = phone;
this.color = context.getResources().getColor(color);
this.context = context;
}
@Override
public void onClick(View widget) {
if (SobotOption.hyperlinkListener != null) {
boolean isIntercept = SobotOption.hyperlinkListener.onPhoneClick(context,"tel:" + phone);
if (isIntercept) {
return;
}
}
callUp(phone, context);
}
@Override
public void updateDrawState(TextPaint ds) {
ds.setColor(color);
ds.setUnderlineText(false); // 去掉下划线
}
public static void callUp(String phone, Context context) {
try {
Intent intent = new Intent();
intent.setAction("android.intent.action.VIEW");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setData(Uri.parse("tel:" + phone));// mobile为你要拨打的电话号码,模拟器中为模拟器编号也可
context.startActivity(intent);
} catch (Exception e) {
SobotToastUtil.showCustomToast(context, context.getString(R.string.sobot_srl_no_support_call));
e.printStackTrace();
}
}
}
\ No newline at end of file
package com.sobot.widget.ui.rich;
public class SobotOption {
public static HyperlinkListener hyperlinkListener;//超链接的点击监听事件
}
package com.sobot.widget.ui.rich.html;
import java.util.List;
public class SobotHtmlLabelBean {
public String tag;//当前Tag
public int startIndex;//tag开始角标
public int endIndex;//tag结束的角标
public List<SobotHtmlLabelRangeBean> ranges;
public String color;
public String fontSize;
public String textdecoration;
public String textdecorationline;
public String backgroundColor;
public String background;
public String fontweight;
public String fontstyle;
}
package com.sobot.widget.ui.rich.html;
public class SobotHtmlLabelRangeBean {
public int start;//tag开始角标
public int end;//tag结束的角标
}
package com.sobot.widget.ui.webview;
import android.content.Context;
import android.util.AttributeSet;
import android.webkit.WebView;
/**
* 自定义webivew使用改成super(context.getApplicationContext(),避免(vivo(Android5.1),使用原生WebView空白)
*/
public class CustomWebview extends WebView {
public CustomWebview(Context context) {
super(context.getApplicationContext());
}
public CustomWebview(Context context, AttributeSet attrs) {
super(context.getApplicationContext(), attrs);
}
public CustomWebview(Context context, AttributeSet attrs, int defStyleAttr) {
super(context.getApplicationContext(), attrs, defStyleAttr);
}
}
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<gradient
android:angle="90"/>
<!-- stroke 描边 -->
<stroke
android:width="0.5dip"
android:color="#C3C3C3" />
<!-- corners 圆角 android:radius为角的弧度,值越大角越圆。 -->
<corners android:radius="5dip" />
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/sobot_webview_toolsbar_back_disable" android:state_enabled="false" />
<item android:drawable="@drawable/sobot_webview_toolsbar_back_normal" />
<item android:drawable="@drawable/sobot_webview_toolsbar_back_pressed" android:state_pressed="true" />
</selector>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/sobot_webview_toolsbar_copy_normal" />
<item android:drawable="@drawable/sobot_webview_toolsbar_copy_pressed" android:state_pressed="true" />
</selector>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/sobot_webview_toolsbar_forward_disable" android:state_enabled="false" />
<item android:drawable="@drawable/sobot_webview_toolsbar_forward_normal" />
<item android:drawable="@drawable/sobot_webview_toolsbar_forward_pressed" android:state_pressed="true" />
</selector>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/sobot_webview_toolsbar_reload_normal" />
<item android:drawable="@drawable/sobot_webview_toolsbar_reload_pressed" android:state_pressed="true" />
</selector>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/sobot_common_gray6"
android:orientation="vertical">
<include layout="@layout/sobot_common_layout_titlebar" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<ProgressBar
android:id="@+id/sobot_loadProgress"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="fill_parent"
android:layout_height="5dip"
android:max="100"
android:paddingLeft="1dip"
android:paddingRight="1dip"
android:progress="0"
android:paddingEnd="1dip"
android:paddingStart="1dip" />
<com.sobot.widget.ui.webview.CustomWebview
android:id="@+id/sobot_mWebView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none" />
</LinearLayout>
<LinearLayout
android:id="@+id/sobot_webview_toolsbar"
android:layout_width="match_parent"
android:layout_height="40dp"
android:orientation="vertical">
<View
android:layout_width="fill_parent"
android:layout_height="0.1dp"
android:background="#b5b5b5" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="43dp"
android:background="@color/sobot_white"
android:orientation="horizontal"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:paddingStart="15dp"
android:paddingEnd="15dp">
<ImageView
android:id="@+id/sobot_webview_goback"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:src="@drawable/sobot_webview_btn_back_selector" />
<ImageView
android:id="@+id/sobot_webview_forward"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:src="@drawable/sobot_webview_btn_forward_selector" />
<ImageView
android:id="@+id/sobot_webview_reload"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:src="@drawable/sobot_webview_btn_reload_selector" />
<ImageView
android:id="@+id/sobot_webview_copy"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:src="@drawable/sobot_webview_btn_copy_selector"
android:visibility="gone" />
</LinearLayout>
</LinearLayout>
<include
android:id="@+id/sobot_rl_net_error"
layout="@layout/sobot_layout_net_error" />
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/sobot_common_gray6">
<!-- 显示加载文字的动画 -->
<TextView
android:id="@+id/sobot_txt_loading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:textSize="16sp"
android:visibility="gone" />
<TextView
android:id="@+id/sobot_textReConnect"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/sobot_txt_loading"
android:layout_centerInParent="true"
android:layout_marginTop="20dp"
android:layout_marginStart="15dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginEnd="15dp"
android:textColor="@color/sobot_common_gray1"
android:textSize="16sp" />
<ImageView
android:id="@+id/sobot_icon_nonet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/sobot_textReConnect"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:contentDescription="@null"
android:src="@drawable/sobot_icon_nonet" />
<Button
android:id="@+id/sobot_btn_reconnect"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/sobot_textReConnect"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dp"
android:background="@drawable/sobot_button_style"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textColor="@color/sobot_common_gray1"
android:textSize="12sp"
android:paddingStart="10dp"
android:paddingEnd="10dp" />
</RelativeLayout>
\ No newline at end of file
......@@ -180,4 +180,9 @@
<string name="app_request_code_900006">Company info not found!</string>
<string name="app_request_code_900007">Blank token info. Get a new one!</string>
<string name="sobot_srl_reunicon">Tap to load again</string>
<string name="sobot_srl_ctrl_v_success">Copied successfully!</string>
<string name="sobot_srl_try_again">Network error. Please check the network and try again</string>
<string name="sobot_srl_no_support_call">The device does not support making calls</string>
</resources>
......@@ -182,4 +182,9 @@
<string name="app_request_code_900006">没有找到公司信息!</string>
<string name="app_request_code_900007">token信息为空,请重新获取! </string>
<!-- 状态码-->
<string name="sobot_srl_reunicon">点击重新连接</string>
<string name="sobot_srl_ctrl_v_success">复制成功!</string>
<string name="sobot_srl_try_again">网络错误,请检查网络后重试</string>
<string name="sobot_srl_no_support_call">该设备不支持拨打电话</string>
</resources>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment