1 |
2971588c
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// Copyright 2020 Leszek Koltunski //
|
3 |
|
|
// //
|
4 |
|
|
// This file is part of Magic Cube. //
|
5 |
|
|
// //
|
6 |
|
|
// Magic Cube is free software: you can redistribute it and/or modify //
|
7 |
|
|
// it under the terms of the GNU General Public License as published by //
|
8 |
|
|
// the Free Software Foundation, either version 2 of the License, or //
|
9 |
|
|
// (at your option) any later version. //
|
10 |
|
|
// //
|
11 |
|
|
// Magic Cube is distributed in the hope that it will be useful, //
|
12 |
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
13 |
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
14 |
|
|
// GNU General Public License for more details. //
|
15 |
|
|
// //
|
16 |
|
|
// You should have received a copy of the GNU General Public License //
|
17 |
|
|
// along with Magic Cube. If not, see <http://www.gnu.org/licenses/>. //
|
18 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
19 |
|
|
|
20 |
|
|
package org.distorted.tutorial;
|
21 |
|
|
|
22 |
|
|
import android.annotation.SuppressLint;
|
23 |
|
|
import android.content.Context;
|
24 |
|
|
import android.content.res.Resources;
|
25 |
|
|
import android.webkit.WebView;
|
26 |
|
|
|
27 |
|
|
import org.distorted.main.R;
|
28 |
|
|
|
29 |
|
|
import java.io.BufferedReader;
|
30 |
|
|
import java.io.InputStream;
|
31 |
|
|
import java.io.InputStreamReader;
|
32 |
|
|
|
33 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
34 |
|
|
|
35 |
|
|
public class TutorialWebView
|
36 |
|
|
{
|
37 |
|
|
private String mUrl;
|
38 |
|
|
private Context mContext;
|
39 |
|
|
private WebView mWebView;
|
40 |
|
|
|
41 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
42 |
|
|
|
43 |
|
|
@SuppressLint("SetJavaScriptEnabled")
|
44 |
|
|
public TutorialWebView(Context context, WebView webview)
|
45 |
|
|
{
|
46 |
|
|
mWebView = webview;
|
47 |
|
|
mContext = context;
|
48 |
|
|
mWebView.setBackgroundColor(0);
|
49 |
|
|
mWebView.getSettings().setJavaScriptEnabled(true);
|
50 |
|
|
}
|
51 |
|
|
|
52 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
53 |
|
|
|
54 |
|
|
public void load(String url)
|
55 |
|
|
{
|
56 |
|
|
mUrl = url;
|
57 |
|
|
String data = readFromfile(mContext);
|
58 |
|
|
data = data.replace("%1", url);
|
59 |
|
|
mWebView.loadData(data, "text/html", "UTF-8");
|
60 |
|
|
}
|
61 |
|
|
|
62 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
63 |
|
|
|
64 |
|
|
public String readFromfile(Context context)
|
65 |
|
|
{
|
66 |
|
|
StringBuilder returnString = new StringBuilder();
|
67 |
|
|
InputStream fIn = null;
|
68 |
|
|
InputStreamReader isr = null;
|
69 |
|
|
BufferedReader input = null;
|
70 |
|
|
|
71 |
|
|
try
|
72 |
|
|
{
|
73 |
|
|
Resources res = context.getResources();
|
74 |
|
|
fIn = res.openRawResource(R.raw.webvideo);
|
75 |
|
|
isr = new InputStreamReader(fIn);
|
76 |
|
|
input = new BufferedReader(isr);
|
77 |
|
|
String line;
|
78 |
|
|
|
79 |
|
|
while ((line = input.readLine()) != null)
|
80 |
|
|
{
|
81 |
|
|
returnString.append(line);
|
82 |
|
|
}
|
83 |
|
|
}
|
84 |
|
|
catch (Exception e)
|
85 |
|
|
{
|
86 |
|
|
e.getMessage();
|
87 |
|
|
}
|
88 |
|
|
finally
|
89 |
|
|
{
|
90 |
|
|
try
|
91 |
|
|
{
|
92 |
|
|
if (isr != null) isr.close();
|
93 |
|
|
if (fIn != null) fIn.close();
|
94 |
|
|
if (input != null) input.close();
|
95 |
|
|
}
|
96 |
|
|
catch (Exception e2)
|
97 |
|
|
{
|
98 |
|
|
e2.getMessage();
|
99 |
|
|
}
|
100 |
|
|
}
|
101 |
|
|
|
102 |
|
|
return returnString.toString();
|
103 |
|
|
}
|
104 |
|
|
|
105 |
5b4eaf7e
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
106 |
|
|
|
107 |
|
|
public void onPause()
|
108 |
|
|
{
|
109 |
|
|
mWebView.onPause();
|
110 |
|
|
}
|
111 |
|
|
|
112 |
2971588c
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
113 |
|
|
|
114 |
|
|
public void reload()
|
115 |
|
|
{
|
116 |
|
|
if (mUrl!=null)
|
117 |
|
|
{
|
118 |
|
|
load(mUrl);
|
119 |
|
|
}
|
120 |
|
|
}
|
121 |
|
|
}
|