|
24 | 24 | public class CustomWebViewFragment extends AgentWebFragment { |
25 | 25 |
|
26 | 26 |
|
27 | | - private MarkdownView mMarkdownWebView; |
28 | | - private EditText markdownEditText; |
29 | | - |
30 | | - public static final CustomWebViewFragment getInstance(Bundle bundle){ |
31 | | - |
32 | | - CustomWebViewFragment mCustomWebViewFragment=new CustomWebViewFragment(); |
33 | | - if(bundle!=null) |
34 | | - mCustomWebViewFragment.setArguments(bundle); |
35 | | - return mCustomWebViewFragment; |
36 | | - } |
37 | | - |
38 | | - @Nullable |
39 | | - @Override |
40 | | - public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { |
41 | | - return inflater.inflate(R.layout.markdown_view, container, false); |
42 | | - } |
43 | | - @Override |
44 | | - public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { |
45 | | - getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_UNSPECIFIED); |
46 | | - //MarkdownView 是 WebView 的一个子类 |
47 | | - mMarkdownWebView = new MarkdownView(getActivity()); |
48 | | - markdownEditText = (EditText) view.findViewById(R.id.markdownText); |
49 | | - |
50 | | - LinearLayout.LayoutParams lp=new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,0); |
51 | | - lp.weight=1f; |
52 | | - mAgentWeb = AgentWeb.with(this)// |
53 | | - .setAgentWebParent((ViewGroup) view, lp)// |
54 | | - .closeIndicator()// |
55 | | - .setWebViewClient(mWebViewClient) |
56 | | - .setWebView(mMarkdownWebView) |
57 | | - .setSecurityType(AgentWeb.SecurityType.STRICT_CHECK) |
58 | | - .createAgentWeb()// |
59 | | - .ready()// |
60 | | - .go(null); |
61 | | - |
62 | | - |
63 | | - |
64 | | - |
65 | | - String text="## AgentWeb 功能\n" + |
66 | | - "***\n\n" + |
67 | | - "1. 支持进度条以及自定义进度条\n" + |
68 | | - "2. 支持文件下载\n" + |
69 | | - "3. 支持文件下载断点续传\n" + |
70 | | - "4. 支持下载通知形式提示进度\n" + |
71 | | - "5. 简化 Javascript 通信 \n" + |
72 | | - "6. 支持 Android 4.4 Kitkat 以及其他版本文件上传\n" + |
73 | | - "7. 支持注入 Cookies\n" + |
74 | | - "8. 加强 Web 安全\n" + |
75 | | - "9. 支持全屏播放视频\n" + |
76 | | - "10. 兼容低版本 Js 安全通信\n" + |
77 | | - "11. 更省电 。\n" + |
78 | | - "12. 支持调起微信支付\n" + |
79 | | - "13. 支持调起支付宝(请参照sample)\n" + |
80 | | - "14. 默认支持定位"; |
81 | | - |
82 | | - markdownEditText.setText(text); |
83 | | - |
84 | | - updateMarkdownView(); |
85 | | - |
86 | | - markdownEditText.addTextChangedListener(new TextWatcher() { |
87 | | - |
88 | | - |
89 | | - |
90 | | - @Override |
91 | | - public void afterTextChanged(Editable s) { |
92 | | - |
93 | | - } |
94 | | - |
95 | | - @Override |
96 | | - public void beforeTextChanged(CharSequence s, int start, int count, int after) {} |
97 | | - |
98 | | - @Override |
99 | | - public void onTextChanged(CharSequence s, int start, int before, int count) { |
100 | | - updateMarkdownView(); |
101 | | - } |
102 | | - }); |
103 | | - |
104 | | - |
105 | | - initView(view); |
106 | | - |
107 | | - } |
108 | | - |
109 | | - |
110 | | - private void updateMarkdownView() { |
111 | | - mMarkdownWebView.loadMarkdown(markdownEditText.getText().toString()); |
112 | | - } |
| 27 | + private MarkdownView mMarkdownWebView; |
| 28 | + private EditText markdownEditText; |
| 29 | + |
| 30 | + public static final CustomWebViewFragment getInstance(Bundle bundle) { |
| 31 | + |
| 32 | + CustomWebViewFragment mCustomWebViewFragment = new CustomWebViewFragment(); |
| 33 | + if (bundle != null) { |
| 34 | + mCustomWebViewFragment.setArguments(bundle); |
| 35 | + } |
| 36 | + return mCustomWebViewFragment; |
| 37 | + } |
| 38 | + |
| 39 | + @Nullable |
| 40 | + @Override |
| 41 | + public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { |
| 42 | + return inflater.inflate(R.layout.markdown_view, container, false); |
| 43 | + } |
| 44 | + |
| 45 | + @Override |
| 46 | + public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { |
| 47 | + getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_UNSPECIFIED); |
| 48 | + //MarkdownView 是 WebView 的一个子类 |
| 49 | + mMarkdownWebView = new MarkdownView(getActivity()); |
| 50 | + markdownEditText = (EditText) view.findViewById(R.id.markdownText); |
| 51 | + |
| 52 | + LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0); |
| 53 | + lp.weight = 1f; |
| 54 | + mAgentWeb = AgentWeb.with(this)// |
| 55 | + .setAgentWebParent((ViewGroup) view, lp)// |
| 56 | + .closeIndicator()// |
| 57 | + .setWebViewClient(mWebViewClient) |
| 58 | + .setWebView(mMarkdownWebView) |
| 59 | + .setSecurityType(AgentWeb.SecurityType.STRICT_CHECK) |
| 60 | + .createAgentWeb()// |
| 61 | + .ready()// |
| 62 | + .go(null); |
| 63 | + |
| 64 | + |
| 65 | + String text = "## AgentWeb 功能\n" + |
| 66 | + "***\n\n" + |
| 67 | + "1. 支持进度条以及自定义进度条\n" + |
| 68 | + "2. 支持文件下载\n" + |
| 69 | + "3. 支持文件下载断点续传\n" + |
| 70 | + "4. 支持下载通知形式提示进度\n" + |
| 71 | + "5. 简化 Javascript 通信 \n" + |
| 72 | + "6. 支持 Android 4.4 Kitkat 以及其他版本文件上传\n" + |
| 73 | + "7. 支持注入 Cookies\n" + |
| 74 | + "8. 加强 Web 安全\n" + |
| 75 | + "9. 支持全屏播放视频\n" + |
| 76 | + "10. 兼容低版本 Js 安全通信\n" + |
| 77 | + "11. 更省电 。\n" + |
| 78 | + "12. 支持调起微信支付\n" + |
| 79 | + "13. 支持调起支付宝(请参照sample)\n" + |
| 80 | + "14. 默认支持定位"; |
| 81 | + |
| 82 | + markdownEditText.setText(text); |
| 83 | + |
| 84 | + updateMarkdownView(); |
| 85 | + |
| 86 | + markdownEditText.addTextChangedListener(new TextWatcher() { |
| 87 | + |
| 88 | + |
| 89 | + @Override |
| 90 | + public void afterTextChanged(Editable s) { |
| 91 | + |
| 92 | + } |
| 93 | + |
| 94 | + @Override |
| 95 | + public void beforeTextChanged(CharSequence s, int start, int count, int after) { |
| 96 | + } |
| 97 | + |
| 98 | + @Override |
| 99 | + public void onTextChanged(CharSequence s, int start, int before, int count) { |
| 100 | + updateMarkdownView(); |
| 101 | + } |
| 102 | + }); |
| 103 | + |
| 104 | + |
| 105 | + initView(view); |
| 106 | + |
| 107 | + } |
| 108 | + |
| 109 | + |
| 110 | + private void updateMarkdownView() { |
| 111 | + mMarkdownWebView.loadMarkdown(markdownEditText.getText().toString()); |
| 112 | + } |
113 | 113 | } |
0 commit comments