Commit e3a0554a by zhengnw@sobot.com

widget 1.1.6 SobotWebViewActivity

parent 88a9137f
......@@ -26,6 +26,7 @@ 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 com.sobot.widget.ui.webview.SobotWebViewActivity;
import java.io.File;
import java.util.HashMap;
......@@ -244,6 +245,14 @@ public class MainActivity extends SobotBaseActivity {
// SobotLogUtils.i(SobotLoginTools.getInstance().getServiceInfo().getTimezone()+"----------------------------------"+SobotLoginTools.getInstance().getServiceInfo().getTimezoneId());
// }
// });
// Intent intent = new Intent(MainActivity.this, SobotWebViewActivity.class);
// intent.putExtra("url", "https://www.sobot.com/ticketclient/index.html?sysNum=75574e5fa29a48458d1f57ab5489a4c5&deployId=442eb27d9c5c4ab9a3a21023f82207a9");
//是否隐藏头部导航栏 默认false显示, true 隐藏
// intent.putExtra("isHideTitleBar", true);
//是否隐藏底部工具栏 默认false显示, true 隐藏
// intent.putExtra("isHideToolBar", true);
// startActivity(intent);
}
@Override
......
......@@ -5,17 +5,21 @@
<color name="colorAccent">#FF4081</color>
<color name="sobot_status_bar_color">#FF4081</color>
<color name="sobot_color_title_bar_bg">#FF4081</color>
<!-- 头部导航栏背景 -->
<!-- <color name="sobot_color_title_bar_bg">#FF4081</color>-->
<!-- 状态栏的颜色设置 -->
<!-- <color name="sobot_status_bar_color">#FF4081</color>-->
<!-- 头部中间昵称颜色 -->
<!-- <color name="sobot_color_title_bar_title">#FFFFFF</color>-->
<!-- &lt;!&ndash;下拉刷新 标题文字颜色&ndash;&gt;-->
<!-- <color name="sobot_refresh_text_color">#303F9F</color>-->
<!-- &lt;!&ndash;下拉刷新 更新时间文字颜色&ndash;&gt;-->
<!-- <color name="sobot_refresh_text2_color">#303F9F</color>-->
<!-- &lt;!&ndash;下拉刷新 背景颜色&ndash;&gt;-->
<!-- <color name="sobot_refresh_bg_color">@color/sobot_white</color>-->
<!-- &lt;!&ndash;下拉刷新 箭头控件颜色 &ndash;&gt;-->
<!-- <color name="sobot_refresh_arrow_color">#FF4081</color>-->
<!-- &lt;!&ndash;下拉刷新 加载中 旋转控件颜色&ndash;&gt;-->
<!-- <color name="sobot_refresh_progress_color">#FF4081</color>-->
<!-- &lt;!&ndash;下拉刷新 标题文字颜色&ndash;&gt;-->
<!-- <color name="sobot_refresh_text_color">#303F9F</color>-->
<!-- &lt;!&ndash;下拉刷新 更新时间文字颜色&ndash;&gt;-->
<!-- <color name="sobot_refresh_text2_color">#303F9F</color>-->
<!-- &lt;!&ndash;下拉刷新 背景颜色&ndash;&gt;-->
<!-- <color name="sobot_refresh_bg_color">@color/sobot_white</color>-->
<!-- &lt;!&ndash;下拉刷新 箭头控件颜色 &ndash;&gt;-->
<!-- <color name="sobot_refresh_arrow_color">#FF4081</color>-->
<!-- &lt;!&ndash;下拉刷新 加载中 旋转控件颜色&ndash;&gt;-->
<!-- <color name="sobot_refresh_progress_color">#FF4081</color>-->
</resources>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="sobot_webview_titlebar_height">44dp</dimen>
<dimen name="sobot_webview_toolsbar_height">44dp</dimen>
</resources>
......@@ -17,4 +17,7 @@
<!-- <string name="sobot_srl_footer_finish">加载完成111</string>-->
<!-- <string name="sobot_srl_footer_failed">加载失败111</string>-->
<!-- <string name="sobot_srl_footer_nothing">没有更多数据了111</string>-->
<string name="sobot_camera">相机1111</string>
<string name="sobot_camera_yongtu">2222您可以在咨询客服和留言时,发送拍摄的照片和视频获取帮助</string>
</resources>
\ No newline at end of file
......@@ -12,7 +12,7 @@ task androidSourcesJar(type: Jar) {
ext {
PUBLISH_GROUP_ID = "com.sobot.library" //项目包名
PUBLISH_ARTIFACT_ID = 'widget' //项目名
PUBLISH_VERSION = '1.1.5' //版本号
PUBLISH_VERSION = '1.1.6' //版本号
}
......
package com.sobot.widget.ui.webview;
import android.app.Activity;
import android.graphics.Rect;
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.FrameLayout;
/**
* 解决WebView中输入时弹出软键盘,挡住输入框的问题
*/
public class AndroidBug5497Workaround {
// For more information, see https://issuetracker.google.com/issues/36911528
// To use this class, simply invoke assistActivity() on an Activity that already has its content view set.
public static void assistActivity (Activity activity) {
new AndroidBug5497Workaround(activity);
}
private View mChildOfContent;
private int usableHeightPrevious;
private FrameLayout.LayoutParams frameLayoutParams;
private AndroidBug5497Workaround(Activity activity) {
FrameLayout content = (FrameLayout) activity.findViewById(android.R.id.content);
mChildOfContent = content.getChildAt(0);
mChildOfContent.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
public void onGlobalLayout() {
possiblyResizeChildOfContent();
}
});
frameLayoutParams = (FrameLayout.LayoutParams) mChildOfContent.getLayoutParams();
}
private int frameLayoutHeight = 0;
private void possiblyResizeChildOfContent() {
int usableHeightNow = computeUsableHeight();
if (usableHeightNow != usableHeightPrevious) {
int usableHeightSansKeyboard = mChildOfContent.getRootView().getHeight();
int heightDifference = usableHeightSansKeyboard - usableHeightNow;
if (heightDifference > (usableHeightSansKeyboard/4)) {
// keyboard probably just became visible
frameLayoutHeight = frameLayoutParams.height;// !!!修改前保存原有高度
frameLayoutParams.height = usableHeightSansKeyboard - heightDifference;
} else {
// keyboard probably just became hidden
if(0 != frameLayoutHeight) {
frameLayoutParams.height = frameLayoutHeight;// !!!收起键盘恢复原有高度
}
}
mChildOfContent.requestLayout();
usableHeightPrevious = usableHeightNow;
}
}
private int computeUsableHeight() {
Rect r = new Rect();
mChildOfContent.getWindowVisibleDisplayFrame(r);
return (r.bottom - r.top);
}
}
\ No newline at end of file
package com.sobot.widget.ui.webview;
import static com.sobot.widget.ui.SobotBaseConstant.REQUEST_CODE_MAKEPICTUREFROMCAMERA;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
......@@ -24,9 +27,11 @@ import android.widget.TextView;
import com.sobot.utils.SobotLogUtils;
import com.sobot.utils.SobotNetUtils;
import com.sobot.utils.SobotStringUtils;
import com.sobot.widget.R;
import com.sobot.widget.ui.base.SobotBaseActivity;
import com.sobot.widget.ui.toast.SobotToastUtil;
import com.sobot.widget.ui.utils.SobotWidgetUtils;
@SuppressLint("SetJavaScriptEnabled")
......@@ -47,10 +52,16 @@ public class SobotWebViewActivity extends SobotBaseActivity implements View.OnCl
private ImageView sobot_webview_reload;
private ImageView sobot_webview_copy;
//根据入的url判断是否url true:是;false:不是
//根据入的url判断是否url true:是;false:不是
private boolean isUrlOrText = true;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AndroidBug5497Workaround.assistActivity(SobotWebViewActivity.this);
}
@Override
protected int getContentViewResId() {
return R.layout.sobot_activity_webview;
}
......@@ -81,13 +92,6 @@ public class SobotWebViewActivity extends SobotBaseActivity implements View.OnCl
@Override
protected void initView() {
setTitle("");
showLeftMenu(getResDrawableId("sobot_icon_back"), "", true, new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
mWebView = (WebView) findViewById(R.id.sobot_mWebView);
mProgressBar = (ProgressBar) findViewById(R.id.sobot_loadProgress);
sobot_rl_net_error = (RelativeLayout) findViewById(R.id.sobot_rl_net_error);
......@@ -108,10 +112,16 @@ public class SobotWebViewActivity extends SobotBaseActivity implements View.OnCl
sobot_webview_copy.setOnClickListener(this);
sobot_webview_goback.setEnabled(false);
sobot_webview_forward.setEnabled(false);
displayInNotch(mWebView);
resetViewDisplay();
boolean isHideTitleBar = getIntent().getBooleanExtra("isHideTitleBar", false);
boolean isHideToolBar = getIntent().getBooleanExtra("isHideToolBar", false);
if (isHideTitleBar && getToolBar() != null) {
getToolBar().setVisibility(View.GONE);
}
if (isHideToolBar && sobot_webview_toolsbar != null) {
sobot_webview_toolsbar.setVisibility(View.GONE);
}
initWebView();
if (isUrlOrText) {
//加载url
......@@ -303,10 +313,34 @@ public class SobotWebViewActivity extends SobotBaseActivity implements View.OnCl
}
}
@Override
public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, FileChooserParams fileChooserParams) {
uploadMessageAboveL = filePathCallback;
chooseAlbumPic();
if (fileChooserParams != null && fileChooserParams.getAcceptTypes() != null) {
String[] acceptTypes = fileChooserParams.getAcceptTypes();
String acceptType = "*/*";
StringBuilder sb = new StringBuilder();
if (acceptTypes.length > 0) {
for (String type : acceptTypes) {
sb.append(type).append(';');
}
}
if (sb.length() > 0) {
String typeStr = sb.toString();
acceptType = typeStr.substring(0, typeStr.length() - 1);
}
SobotLogUtils.i("input file 标签的accept类型:" + acceptType + fileChooserParams.getMode());
//根据判断,触发相关的操作,如文件选择,拍照等
if ("image/*".equals(SobotStringUtils.checkStringIsNull(acceptType))) {
openCapture();
} else {
chooseFile();
}
} else {
}
return true;
}
......@@ -360,7 +394,6 @@ public class SobotWebViewActivity extends SobotBaseActivity implements View.OnCl
private static final int REQUEST_CODE_ALBUM = 0x0111;
private ValueCallback<Uri> uploadMessage;
private ValueCallback<Uri[]> uploadMessageAboveL;
public Context getContext() {
......@@ -368,56 +401,57 @@ public class SobotWebViewActivity extends SobotBaseActivity implements View.OnCl
}
/**
* 选择相册照片
* 打开相机拍照
*/
private void chooseAlbumPic() {
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.addCategory(Intent.CATEGORY_OPENABLE);
// i.setType("image/*");
i.setType("video/*;image/*");
startActivityForResult(Intent.createChooser(i, "Image Chooser"), REQUEST_CODE_ALBUM);
private void openCapture() {
openCamera();
}
/**
* 打开文件系统选取文件上传
*/
private void chooseFile() {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");//设置类型,我这里是任意类型,任意后缀的可以这样写。
intent.addCategory(Intent.CATEGORY_OPENABLE);
startActivityForResult(intent, REQUEST_CODE_ALBUM);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_CODE_ALBUM) {
if (uploadMessage == null && uploadMessageAboveL == null) {
if (requestCode == REQUEST_CODE_ALBUM || requestCode == REQUEST_CODE_MAKEPICTUREFROMCAMERA) {
if (uploadMessageAboveL == null) {
return;
}
if (resultCode != RESULT_OK) {
//一定要返回null,否则<input file> 就是没有反应
if (uploadMessage != null) {
uploadMessage.onReceiveValue(null);
uploadMessage = null;
}
if (uploadMessageAboveL != null) {
uploadMessageAboveL.onReceiveValue(null);
uploadMessageAboveL = null;
}
}
if (resultCode == RESULT_OK) {
Uri imageUri = null;
switch (requestCode) {
case REQUEST_CODE_ALBUM:
if (data != null) {
imageUri = data.getData();
} else {
if (resultCode == RESULT_OK) {
Uri imageUri = null;
switch (requestCode) {
case REQUEST_CODE_ALBUM:
if (data != null) {
imageUri = data.getData();
}
break;
case REQUEST_CODE_MAKEPICTUREFROMCAMERA:
if (cameraFile != null && cameraFile.exists()) {
imageUri = SobotWidgetUtils.getUri(SobotWebViewActivity.this, cameraFile);
}
break;
}
if (imageUri != null) {
//上传文件
if (uploadMessageAboveL != null) {
uploadMessageAboveL.onReceiveValue(new Uri[]{imageUri});
uploadMessageAboveL = null;
}
break;
}
//上传文件
if (uploadMessage != null) {
uploadMessage.onReceiveValue(imageUri);
uploadMessage = null;
}
if (uploadMessageAboveL != null) {
uploadMessageAboveL.onReceiveValue(new Uri[]{imageUri});
uploadMessageAboveL = null;
}
}
}
}
......
......@@ -5,7 +5,10 @@
android:background="@color/sobot_common_gray6"
android:orientation="vertical">
<include layout="@layout/sobot_common_layout_titlebar" />
<include
layout="@layout/sobot_common_layout_titlebar"
android:layout_height="@dimen/sobot_webview_titlebar_height"
android:layout_width="match_parent" />
<LinearLayout
android:layout_width="match_parent"
......@@ -19,11 +22,11 @@
android:layout_width="fill_parent"
android:layout_height="5dip"
android:max="100"
android:paddingStart="1dip"
android:paddingLeft="1dip"
android:paddingRight="1dip"
android:progress="0"
android:paddingEnd="1dip"
android:paddingStart="1dip" />
android:paddingRight="1dip"
android:progress="0" />
<com.sobot.widget.ui.webview.CustomWebview
android:id="@+id/sobot_mWebView"
......@@ -34,8 +37,8 @@
<LinearLayout
android:id="@+id/sobot_webview_toolsbar"
android:layout_height="@dimen/sobot_webview_toolsbar_height"
android:layout_width="match_parent"
android:layout_height="40dp"
android:orientation="vertical">
<View
......@@ -48,10 +51,10 @@
android:layout_height="43dp"
android:background="@color/sobot_white"
android:orientation="horizontal"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:paddingStart="15dp"
android:paddingEnd="15dp">
android:paddingLeft="15dp"
android:paddingEnd="15dp"
android:paddingRight="15dp">
<ImageView
android:id="@+id/sobot_webview_goback"
......
......@@ -2,6 +2,9 @@
<resources>
<dimen name="sobot_titlebar_height">44dp</dimen>
<dimen name="sobot_webview_titlebar_height">@dimen/sobot_titlebar_height</dimen>
<dimen name="sobot_webview_toolsbar_height">@dimen/sobot_titlebar_height</dimen>
<dimen name="sobot_titlebar_title_size">16sp</dimen>
</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