Project

General

Profile

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

magiccube / src / main / java / org / distorted / tutorial / TutorialWebView.java @ 6a77a59b

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.tutorial;
21

    
22
import android.annotation.SuppressLint;
23
import android.content.Context;
24
import android.content.res.Resources;
25
import android.webkit.WebView;
26
import android.webkit.WebViewClient;
27

    
28
import org.distorted.main.R;
29

    
30
import java.io.BufferedReader;
31
import java.io.InputStream;
32
import java.io.InputStreamReader;
33

    
34
///////////////////////////////////////////////////////////////////////////////////////////////////
35

    
36
public class TutorialWebView
37
{
38
    private String  mUrl;
39
    private Context mContext;
40
    private WebView mWebView;
41

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

    
44
    @SuppressLint("SetJavaScriptEnabled")
45
    public TutorialWebView(Context context, WebView webview)
46
      {
47
      mWebView = webview;
48
      mContext = context;
49
      mWebView.setBackgroundColor(0);
50
      mWebView.getSettings().setJavaScriptEnabled(true);
51

    
52
      mWebView.setWebViewClient(new WebViewClient()
53
        {
54
        @Override
55
        public boolean shouldOverrideUrlLoading(WebView view, String url)
56
          {
57
          return false;
58
          }
59
        });
60
      }
61

    
62
///////////////////////////////////////////////////////////////////////////////////////////////////
63

    
64
    public void load(String url)
65
      {
66
      mUrl = url;
67

    
68
      String data1 = "<html><body><iframe width=\"100%\" height=\"100%\" src=\"";
69
      String data2 = "\" frameborder=\"0\" allowfullscreen></iframe></body></html>";
70

    
71
      mWebView.loadData(data1+url+data2, "text/html", "UTF-8");
72
      }
73

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

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

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

    
83
    public void onResume()
84
      {
85
      mWebView.onResume();
86
      }
87

    
88
///////////////////////////////////////////////////////////////////////////////////////////////////
89

    
90
    public void reload()
91
      {
92
      if (mUrl!=null)
93
        {
94
        load(mUrl);
95
        }
96
      }
97
}
(7-7/7)