|
6 | 6 | import android.os.Build;
|
7 | 7 | import android.os.Bundle;
|
8 | 8 | import android.os.Parcelable;
|
9 |
| -import android.support.annotation.Nullable; |
| 9 | +import androidx.annotation.Nullable; |
10 | 10 | import android.util.AttributeSet;
|
11 | 11 | import android.util.Log;
|
12 | 12 | import android.view.LayoutInflater;
|
|
23 | 23 | import com.anychart.chart.common.listener.ListenersInterface;
|
24 | 24 | import com.anychart.core.Chart;
|
25 | 25 |
|
| 26 | +import java.nio.charset.StandardCharsets; |
| 27 | +import java.security.NoSuchAlgorithmException; |
| 28 | + |
26 | 29 | public final class AnyChartView extends FrameLayout {
|
27 | 30 |
|
28 | 31 | public interface JsListener {
|
@@ -100,6 +103,7 @@ private void init() {
|
100 | 103 |
|
101 | 104 | webView = view.findViewById(R.id.web_view);
|
102 | 105 | WebSettings webSettings = webView.getSettings();
|
| 106 | + webSettings.setDomStorageEnabled(true); |
103 | 107 | webSettings.setLoadsImagesAutomatically(true);
|
104 | 108 | webSettings.setJavaScriptEnabled(true);
|
105 | 109 | webSettings.setLoadWithOverviewMode(true);
|
@@ -154,12 +158,20 @@ public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request
|
154 | 158 | public void onPageFinished(WebView view, String url) {
|
155 | 159 | String resultJs = (isRestored)
|
156 | 160 | ? js.toString()
|
157 |
| - : js.append(chart.getJsBase()).append(".container(\"container\");") |
158 |
| - .append(chart.getJsBase()).append(".draw();") |
| 161 | + : js |
| 162 | + .append(androidCheck(licenceKey)) |
| 163 | + .append(chart.getJsBase()).append(".container(\"container\");") |
159 | 164 | .toString();
|
160 | 165 |
|
161 | 166 | webView.evaluateJavascript(
|
162 |
| - "anychart.licenseKey(\"" + licenceKey + "\");" + |
| 167 | + "anychart.theme({\n" + |
| 168 | + " chart: {\n" + |
| 169 | + " credits: {\n" + |
| 170 | + " logoSrc: 'https://static.anychart.com/logo-for-android.png',\n" + |
| 171 | + " text: 'AnyChart Trial Version'\n" + |
| 172 | + " }\n" + |
| 173 | + " }\n" + |
| 174 | + " });" + |
163 | 175 | "anychart.onDocumentReady(function () {\n" +
|
164 | 176 | resultJs +
|
165 | 177 | "});",
|
@@ -196,14 +208,14 @@ private void loadHtml() {
|
196 | 208 | " </style>\n" +
|
197 | 209 | "</head>\n" +
|
198 | 210 | "<body>\n" +
|
199 |
| - "<script src=\"file:///android_asset/anychart-bundle.min.js\"></script>" + |
| 211 | + "<script src=\"file:///android_asset/anychart-android.min.js\"></script>" + |
200 | 212 | scripts.toString() +
|
201 | 213 | "<link rel=\"stylesheet\" href=\"file:///android_asset/anychart-ui.min.css\"/>\n" +
|
202 | 214 | "<div id=\"container\"></div>\n" +
|
203 | 215 | "</body>\n" +
|
204 | 216 | "</html>";
|
205 |
| - |
206 |
| - webView.loadDataWithBaseURL("", htmlData, "text/html", "UTF-8", null); |
| 217 | + |
| 218 | + webView.loadDataWithBaseURL("https://www.google.com", htmlData, "text/html", "UTF-8", null); |
207 | 219 | }
|
208 | 220 |
|
209 | 221 | public void addScript(String url) {
|
@@ -277,4 +289,32 @@ public void setOnRenderedListener(OnRenderedListener onRenderedListener) {
|
277 | 289 | public void setDebug(boolean value) {
|
278 | 290 | this.isDebug = value;
|
279 | 291 | }
|
| 292 | + |
| 293 | + private String md5(String s) { |
| 294 | + try { |
| 295 | + java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5"); |
| 296 | + byte[] array = md.digest(s.getBytes(StandardCharsets.UTF_8)); |
| 297 | + StringBuilder sb = new StringBuilder(); |
| 298 | + for (int i = 0; i < array.length; ++i) { |
| 299 | + sb.append(Integer.toHexString((array[i] & 0xFF) | 0x100).substring(1,3)); |
| 300 | + } |
| 301 | + return sb.toString(); |
| 302 | + } catch (NoSuchAlgorithmException e) { |
| 303 | + } |
| 304 | + return ""; |
| 305 | + } |
| 306 | + |
| 307 | + private String androidCheck(String l) { |
| 308 | + if (l == null || l.isEmpty() || md5(l) == "0df80e76aeca7dc40e01e876dca3542b") { |
| 309 | + return "var btoa = window.btoa(JSON.stringify({\n" + |
| 310 | + " chartType: '" + chart.getJsBase() + "',\n" + |
| 311 | + " apkName: \"" + getContext().getPackageName() + "\"\n" + |
| 312 | + "}));" + |
| 313 | + chart.getJsBase() + ".credits({\n" + |
| 314 | + " logoSrc: 'https://static.anychart.com/logo-for-android.png?data=' + btoa,\n" + |
| 315 | + " text: 'AnyChart Trial Version'\n" + |
| 316 | + " });\n"; |
| 317 | + } |
| 318 | + return ""; |
| 319 | + } |
280 | 320 | }
|
0 commit comments