Project

General

Profile

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

magiccube / src / main / java / org / distorted / tutorials / TutorialWebView.java @ 2cf21fdc

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is proprietary software licensed under an EULA which you should have received      //
7
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html        //
8
///////////////////////////////////////////////////////////////////////////////////////////////////
9

    
10
package org.distorted.tutorials;
11

    
12
import android.annotation.SuppressLint;
13
import android.webkit.WebView;
14
import android.webkit.WebViewClient;
15

    
16
///////////////////////////////////////////////////////////////////////////////////////////////////
17

    
18
public class TutorialWebView
19
{
20
    private String mUrl;
21
    private final WebView mWebView;
22

    
23
///////////////////////////////////////////////////////////////////////////////////////////////////
24

    
25
    @SuppressLint("SetJavaScriptEnabled")
26
    public TutorialWebView(WebView webview)
27
      {
28
      mWebView = webview;
29
      mWebView.setBackgroundColor(0);
30
      mWebView.getSettings().setJavaScriptEnabled(true);
31

    
32
      mWebView.setWebViewClient(new WebViewClient()
33
        {
34
        @Override
35
        public boolean shouldOverrideUrlLoading(WebView view, String url)
36
          {
37
          return false;
38
          }
39
        });
40
      }
41

    
42
///////////////////////////////////////////////////////////////////////////////////////////////////
43

    
44
    public void load(String url)
45
      {
46
      mUrl = url;
47

    
48
      String data1 = "<html><body><iframe width=\"100%\" height=\"100%\" src=\"";
49
      String data2 = "\" frameborder=\"0\" allowfullscreen></iframe></body></html>";
50

    
51
      mWebView.loadData(data1+url+data2, "text/html", "UTF-8");
52
      }
53

    
54
///////////////////////////////////////////////////////////////////////////////////////////////////
55

    
56
    public void onPause()
57
      {
58
      mWebView.onPause();
59
      }
60

    
61
///////////////////////////////////////////////////////////////////////////////////////////////////
62

    
63
    public void onResume()
64
      {
65
      mWebView.onResume();
66
      }
67

    
68
///////////////////////////////////////////////////////////////////////////////////////////////////
69

    
70
    public void reload()
71
      {
72
      if (mUrl!=null)
73
        {
74
        load(mUrl);
75
        }
76
      }
77
}
(6-6/6)