Project

General

Profile

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

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

1
///////////////////////////////////////////////////////////////////////////////////////////////////
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.tutorials;
21

    
22
import android.annotation.SuppressLint;
23
import android.webkit.WebView;
24
import android.webkit.WebViewClient;
25

    
26
///////////////////////////////////////////////////////////////////////////////////////////////////
27

    
28
public class TutorialWebView
29
{
30
    private String mUrl;
31
    private final WebView mWebView;
32

    
33
///////////////////////////////////////////////////////////////////////////////////////////////////
34

    
35
    @SuppressLint("SetJavaScriptEnabled")
36
    public TutorialWebView(WebView webview)
37
      {
38
      mWebView = webview;
39
      mWebView.setBackgroundColor(0);
40
      mWebView.getSettings().setJavaScriptEnabled(true);
41

    
42
      mWebView.setWebViewClient(new WebViewClient()
43
        {
44
        @Override
45
        public boolean shouldOverrideUrlLoading(WebView view, String url)
46
          {
47
          return false;
48
          }
49
        });
50
      }
51

    
52
///////////////////////////////////////////////////////////////////////////////////////////////////
53

    
54
    public void load(String url)
55
      {
56
      mUrl = url;
57

    
58
      String data1 = "<html><body><iframe width=\"100%\" height=\"100%\" src=\"";
59
      String data2 = "\" frameborder=\"0\" allowfullscreen></iframe></body></html>";
60

    
61
      mWebView.loadData(data1+url+data2, "text/html", "UTF-8");
62
      }
63

    
64
///////////////////////////////////////////////////////////////////////////////////////////////////
65

    
66
    public void onPause()
67
      {
68
      mWebView.onPause();
69
      }
70

    
71
///////////////////////////////////////////////////////////////////////////////////////////////////
72

    
73
    public void onResume()
74
      {
75
      mWebView.onResume();
76
      }
77

    
78
///////////////////////////////////////////////////////////////////////////////////////////////////
79

    
80
    public void reload()
81
      {
82
      if (mUrl!=null)
83
        {
84
        load(mUrl);
85
        }
86
      }
87
}
(7-7/7)