Statistics
| Branch: | Tag: | Revision:

checkey / src / info / guardianproject / checkey / WebViewActivity.java @ 71589712

History | View | Annotate | Download (1.79 KB)

1

    
2
package info.guardianproject.checkey;
3

    
4
import android.content.Intent;
5
import android.net.Uri;
6
import android.net.http.SslError;
7
import android.os.Bundle;
8
import android.support.v7.app.ActionBar;
9
import android.support.v7.app.ActionBarActivity;
10
import android.util.Log;
11
import android.view.Menu;
12
import android.view.MenuItem;
13
import android.webkit.SslErrorHandler;
14
import android.webkit.WebView;
15
import android.webkit.WebViewClient;
16

    
17
public class WebViewActivity extends ActionBarActivity {
18

    
19
    private Uri uri;
20

    
21
    @Override
22
    protected void onCreate(Bundle savedInstanceState) {
23
        super.onCreate(savedInstanceState);
24
        setContentView(R.layout.activity_webview);
25
        ActionBar actionBar = getSupportActionBar();
26
        actionBar.setDisplayHomeAsUpEnabled(true);
27

    
28
        Intent intent = getIntent();
29
        int resid = intent.getIntExtra(Intent.EXTRA_TITLE, 0);
30
        if (resid != 0)
31
            actionBar.setTitle(resid);
32

    
33
        WebView webView = (WebView) findViewById(R.id.webview);
34
        webView.setWebViewClient(new MyWebViewClient());
35
        uri = intent.getData();
36
        webView.loadUrl(uri.toString());
37
        Log.i("WebViewActivity", uri.toString());
38
    }
39

    
40
    private class MyWebViewClient extends WebViewClient {
41
        @Override
42
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
43
            Uri clickedUri = Uri.parse(url);
44
            String host = clickedUri.getHost();
45
            if (host.equals("www.virustotal.com") || host.equals("androidobservatory.org")) {
46
                // do not override; let my WebView load the page
47
                return false;
48
            }
49
            // otherwise launch another Activity to handle the link
50
            startActivity(new Intent(Intent.ACTION_VIEW, clickedUri));
51
            return true;
52
        }
53

    
54
    }
55
}