SHOW:
|
|
- or go back to the newest paste.
1 | package com.CheckInventory; | |
2 | ||
3 | import android.app.Activity; | |
4 | import android.os.Bundle; | |
5 | import android.view.KeyEvent; | |
6 | import android.view.WindowManager; | |
7 | import android.webkit.WebChromeClient; | |
8 | import android.webkit.WebSettings; | |
9 | import android.webkit.WebStorage; | |
10 | import android.webkit.WebView; | |
11 | import android.webkit.WebViewClient; | |
12 | import android.widget.Toast; | |
13 | ||
14 | @SuppressWarnings("unused") | |
15 | public class CheckInventoryActivity extends Activity { | |
16 | WebView webview; | |
17 | String username; | |
18 | /** Called when the activity is first created. */ | |
19 | @Override | |
20 | public void onCreate(Bundle savedInstanceState) { | |
21 | super.onCreate(savedInstanceState); | |
22 | getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); | |
23 | setContentView(R.layout.main); | |
24 | webview = (WebView) findViewById(R.id.webview); | |
25 | WebView webView = (WebView) findViewById(R.id.webview); | |
26 | ||
27 | // here we go | |
28 | myWebClient client = new myWebClient(); | |
29 | webView.setWebViewClient(client); | |
30 | // ---------- | |
31 | ||
32 | webView.setBackgroundColor(0); | |
33 | webView.setBackgroundResource(R.drawable.myimage); | |
34 | webView.addJavascriptInterface(new JavaScriptInterface(this), "Android"); | |
35 | WebSettings webSettings = webview.getSettings(); | |
36 | webSettings.setLoadWithOverviewMode(true); | |
37 | ||
38 | webview.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); | |
39 | ||
40 | webSettings.setJavaScriptEnabled(true); | |
41 | webSettings.setJavaScriptCanOpenWindowsAutomatically(true); | |
42 | webSettings.setDatabasePath("/data/data/"+this.getPackageName()+"/databases/"); | |
43 | webSettings.setDomStorageEnabled(true); | |
44 | webview.setWebChromeClient(new WebChromeClient()); | |
45 | webview.loadUrl("http://192.168.0.124/android"); | |
46 | webview.setWebViewClient(new HelloWebViewClient()); | |
47 | ||
48 | } | |
49 | private class HelloWebViewClient extends WebViewClient { | |
50 | @Override | |
51 | public boolean shouldOverrideUrlLoading(WebView view, String url) { | |
52 | view.loadUrl(url); | |
53 | return true; | |
54 | } | |
55 | } | |
56 | ||
57 | ||
58 | @Override | |
59 | public boolean onKeyDown (int keyCode, KeyEvent event) { | |
60 | if((keyCode == KeyEvent.KEYCODE_BACK) && webview.canGoBack()){ | |
61 | //webview.goBack(); | |
62 | return true; | |
63 | } | |
64 | return super.onKeyDown(keyCode, event); | |
65 | } | |
66 | ||
67 | ||
68 | // Here our WebViewClient class | |
69 | public class myWebClient extends WebViewClient { | |
70 | ||
71 | @Override | |
72 | public void onReceivedError(WebView view, int errorCode, | |
73 | String description, String failingUrl) { | |
74 | - | Toast.makeText(view.getContext(), "Your Internet Connection May not be active Or " + description , Toast.LENGTH_LONG).show(); |
74 | + | Toast.makeText(CheckInventoryActivity.this, "Your Internet Connection May not be active Or " + description , Toast.LENGTH_LONG).show(); |
75 | super.onReceivedError(view, errorCode, description, failingUrl); | |
76 | } | |
77 | ||
78 | } | |
79 | ||
80 | } |