Skip to content

Commit d0258e0

Browse files
author
Nilanchala Panigrahy
committed
Added WebView Example
1 parent 5261c73 commit d0258e0

81 files changed

Lines changed: 1166 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

WebViewExample/WebViewExample.sln

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 2012
4+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebViewExample", "WebViewExample\WebViewExample.csproj", "{99A14351-B275-4C63-B199-27BA2F26435C}"
5+
EndProject
6+
Global
7+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
8+
Debug|Any CPU = Debug|Any CPU
9+
Release|Any CPU = Release|Any CPU
10+
EndGlobalSection
11+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
12+
{99A14351-B275-4C63-B199-27BA2F26435C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
13+
{99A14351-B275-4C63-B199-27BA2F26435C}.Debug|Any CPU.Build.0 = Debug|Any CPU
14+
{99A14351-B275-4C63-B199-27BA2F26435C}.Release|Any CPU.ActiveCfg = Release|Any CPU
15+
{99A14351-B275-4C63-B199-27BA2F26435C}.Release|Any CPU.Build.0 = Release|Any CPU
16+
EndGlobalSection
17+
EndGlobal
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Properties StartupItem="WebViewExample/WebViewExample.csproj">
2+
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" PreferredExecutionTarget="Android.4d0042144a393065" />
3+
<MonoDevelop.Ide.Workbench ActiveDocument="WebViewExample/MainActivity.cs">
4+
<Files>
5+
<File FileName="WebViewExample/MainActivity.cs" Line="4" Column="4" />
6+
</Files>
7+
</MonoDevelop.Ide.Workbench>
8+
<MonoDevelop.Ide.DebuggingService.Breakpoints>
9+
<BreakpointStore />
10+
</MonoDevelop.Ide.DebuggingService.Breakpoints>
11+
<MonoDevelop.Ide.DebuggingService.PinnedWatches />
12+
<MonoDevelop.Ide.ItemProperties.WebViewExample MonoForAntroid.PreferredDevice="Nexus 4" />
13+
</Properties>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Any raw assets you want to be deployed with your application can be placed in
2+
this directory (and child directories) and given a Build Action of "AndroidAsset".
3+
4+
These files will be deployed with your package and will be accessible using Android's
5+
AssetManager, like this:
6+
7+
public class ReadAsset : Activity
8+
{
9+
protected override void OnCreate (Bundle bundle)
10+
{
11+
base.OnCreate (bundle);
12+
13+
InputStream input = Assets.Open ("my_asset.txt");
14+
}
15+
}
16+
17+
Additionally, some Android functions will automatically load asset files:
18+
19+
Typeface tf = Typeface.CreateFromAsset (Context.Assets, "fonts/samplefont.ttf");
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using System;
2+
3+
using Android.App;
4+
using Android.Content;
5+
using Android.Runtime;
6+
using Android.Views;
7+
using Android.Widget;
8+
using Android.OS;
9+
using Android.Webkit;
10+
11+
namespace WebViewExample
12+
{
13+
[Activity (Label = "WebViewExample", MainLauncher = true, Icon = "@drawable/icon")]
14+
public class MainActivity : Activity
15+
{
16+
protected override void OnCreate (Bundle bundle)
17+
{
18+
base.OnCreate (bundle);
19+
20+
// Set our view from the "main" layout resource
21+
SetContentView (Resource.Layout.Main);
22+
23+
WebView mWebView = FindViewById<WebView>(Resource.Id.webView);
24+
25+
mWebView.Settings.JavaScriptEnabled = true;
26+
27+
//
28+
mWebView.SetWebViewClient (new MyWebViewClient());
29+
30+
//Load url to be randered on WebView
31+
mWebView.LoadUrl("http://www.javatechig.com");
32+
}
33+
34+
public class MyWebViewClient : WebViewClient
35+
{
36+
public override bool ShouldOverrideUrlLoading (WebView view, string url)
37+
{
38+
view.LoadUrl (url);
39+
return true;
40+
}
41+
42+
public override void OnPageStarted (WebView view, string url, Android.Graphics.Bitmap favicon)
43+
{
44+
base.OnPageStarted (view, url, favicon);
45+
}
46+
47+
public override void OnPageFinished (WebView view, string url)
48+
{
49+
base.OnPageFinished (view, url);
50+
}
51+
52+
public override void OnReceivedError (WebView view, ClientError errorCode, string description, string failingUrl)
53+
{
54+
base.OnReceivedError (view, errorCode, description, failingUrl);
55+
}
56+
}
57+
}
58+
}
59+
60+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="WebViewExample.WebViewExample">
3+
<uses-sdk />
4+
<application android:label="WebViewExample">
5+
</application>
6+
<uses-permission android:name="android.permission.INTERNET" />
7+
</manifest>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using Android.App;
4+
5+
// Information about this assembly is defined by the following attributes.
6+
// Change them to the values specific to your project.
7+
8+
[assembly: AssemblyTitle ("WebViewExample")]
9+
[assembly: AssemblyDescription ("")]
10+
[assembly: AssemblyConfiguration ("")]
11+
[assembly: AssemblyCompany ("")]
12+
[assembly: AssemblyProduct ("")]
13+
[assembly: AssemblyCopyright ("nilanchalpanigrahy")]
14+
[assembly: AssemblyTrademark ("")]
15+
[assembly: AssemblyCulture ("")]
16+
17+
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
18+
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
19+
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
20+
21+
[assembly: AssemblyVersion ("1.0.0")]
22+
23+
// The following attributes are used to specify the signing key for the assembly,
24+
// if desired. See the Mono documentation for more information about signing.
25+
26+
//[assembly: AssemblyDelaySign(false)]
27+
//[assembly: AssemblyKeyFile("")]
28+
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
Images, layout descriptions, binary blobs and string dictionaries can be included
2+
in your application as resource files. Various Android APIs are designed to
3+
operate on the resource IDs instead of dealing with images, strings or binary blobs
4+
directly.
5+
6+
For example, a sample Android app that contains a user interface layout (main.axml),
7+
an internationalization string table (strings.xml) and some icons (drawable-XXX/icon.png)
8+
would keep its resources in the "Resources" directory of the application:
9+
10+
Resources/
11+
drawable/
12+
icon.png
13+
14+
layout/
15+
main.axml
16+
17+
values/
18+
strings.xml
19+
20+
In order to get the build system to recognize Android resources, set the build action to
21+
"AndroidResource". The native Android APIs do not operate directly with filenames, but
22+
instead operate on resource IDs. When you compile an Android application that uses resources,
23+
the build system will package the resources for distribution and generate a class called "R"
24+
(this is an Android convention) that contains the tokens for each one of the resources
25+
included. For example, for the above Resources layout, this is what the R class would expose:
26+
27+
public class R {
28+
public class drawable {
29+
public const int icon = 0x123;
30+
}
31+
32+
public class layout {
33+
public const int main = 0x456;
34+
}
35+
36+
public class strings {
37+
public const int first_string = 0xabc;
38+
public const int second_string = 0xbcd;
39+
}
40+
}
41+
42+
You would then use R.drawable.icon to reference the drawable/icon.png file, or R.layout.main
43+
to reference the layout/main.axml file, or R.strings.first_string to reference the first
44+
string in the dictionary file values/strings.xml.

WebViewExample/WebViewExample/Resources/Resource.designer.cs

Lines changed: 131 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
2.15 KB
Loading
1.38 KB
Loading

0 commit comments

Comments
 (0)