Project

General

Profile

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

magiccube / src / main / java / org / distorted / tutorials / TutorialWebView.java @ eaf87d1d

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.content.Context;
24
import android.webkit.WebView;
25
import android.webkit.WebViewClient;
26

    
27
///////////////////////////////////////////////////////////////////////////////////////////////////
28

    
29
public class TutorialWebView
30
{
31
    private String  mUrl;
32
    private Context mContext;
33
    private WebView mWebView;
34

    
35
///////////////////////////////////////////////////////////////////////////////////////////////////
36

    
37
    @SuppressLint("SetJavaScriptEnabled")
38
    public TutorialWebView(Context context, WebView webview)
39
      {
40
      mWebView = webview;
41
      mContext = context;
42
      mWebView.setBackgroundColor(0);
43
      mWebView.getSettings().setJavaScriptEnabled(true);
44

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

    
55
///////////////////////////////////////////////////////////////////////////////////////////////////
56

    
57
    public void load(String url)
58
      {
59
      mUrl = url;
60

    
61
      String data1 = "<html><body><iframe width=\"100%\" height=\"100%\" src=\"";
62
      String data2 = "\" frameborder=\"0\" allowfullscreen></iframe></body></html>";
63

    
64
      mWebView.loadData(data1+url+data2, "text/html", "UTF-8");
65
      }
66

    
67
///////////////////////////////////////////////////////////////////////////////////////////////////
68

    
69
    public void onPause()
70
      {
71
      mWebView.onPause();
72
      }
73

    
74
///////////////////////////////////////////////////////////////////////////////////////////////////
75

    
76
    public void onResume()
77
      {
78
      mWebView.onResume();
79
      }
80

    
81
///////////////////////////////////////////////////////////////////////////////////////////////////
82

    
83
    public void reload()
84
      {
85
      if (mUrl!=null)
86
        {
87
        load(mUrl);
88
        }
89
      }
90
}
(7-7/7)