Project

General

Profile

Download (3.54 KB) Statistics
| Branch: | Tag: | Revision:

magiccube / src / main / java / org / distorted / tutorials / TutorialWebView.java @ 8ab435b9

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 eaf87d1d Leszek Koltunski
package org.distorted.tutorials;
21 2971588c Leszek Koltunski
22
import android.annotation.SuppressLint;
23
import android.webkit.WebView;
24 8021e4bb Leszek Koltunski
import android.webkit.WebViewClient;
25 2971588c Leszek Koltunski
26
///////////////////////////////////////////////////////////////////////////////////////////////////
27
28
public class TutorialWebView
29
{
30 55e6be1d Leszek Koltunski
    private String mUrl;
31
    private final WebView mWebView;
32 2971588c Leszek Koltunski
33
///////////////////////////////////////////////////////////////////////////////////////////////////
34
35
    @SuppressLint("SetJavaScriptEnabled")
36 55e6be1d Leszek Koltunski
    public TutorialWebView(WebView webview)
37 2971588c Leszek Koltunski
      {
38
      mWebView = webview;
39
      mWebView.setBackgroundColor(0);
40
      mWebView.getSettings().setJavaScriptEnabled(true);
41 8021e4bb Leszek Koltunski
42
      mWebView.setWebViewClient(new WebViewClient()
43
        {
44
        @Override
45
        public boolean shouldOverrideUrlLoading(WebView view, String url)
46
          {
47
          return false;
48
          }
49
        });
50 2971588c Leszek Koltunski
      }
51
52
///////////////////////////////////////////////////////////////////////////////////////////////////
53
54
    public void load(String url)
55
      {
56
      mUrl = url;
57
58 8021e4bb Leszek Koltunski
      String data1 = "<html><body><iframe width=\"100%\" height=\"100%\" src=\"";
59
      String data2 = "\" frameborder=\"0\" allowfullscreen></iframe></body></html>";
60 2971588c Leszek Koltunski
61 8021e4bb Leszek Koltunski
      mWebView.loadData(data1+url+data2, "text/html", "UTF-8");
62 2971588c Leszek Koltunski
      }
63
64 5b4eaf7e Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
65
66
    public void onPause()
67
      {
68
      mWebView.onPause();
69
      }
70
71 0de39b8e Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
72
73
    public void onResume()
74
      {
75
      mWebView.onResume();
76
      }
77
78 2971588c Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
79
80
    public void reload()
81
      {
82
      if (mUrl!=null)
83
        {
84
        load(mUrl);
85
        }
86
      }
87
}