forked from slymax/webview
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 290bcbb
Showing
24 changed files
with
534 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#built application files | ||
*.apk | ||
*.ap_ | ||
|
||
# files for the dex VM | ||
*.dex | ||
|
||
# Java class files | ||
*.class | ||
|
||
# generated files | ||
bin/ | ||
gen/ | ||
|
||
# Local configuration file (sdk path, etc) | ||
local.properties | ||
|
||
# Windows thumbnail db | ||
Thumbs.db | ||
|
||
# OSX files | ||
.DS_Store | ||
|
||
# Android Studio | ||
*.iml | ||
.idea | ||
#.idea/workspace.xml - remove # and delete .idea if it better suit your needs. | ||
.gradle | ||
build/ | ||
.navigation | ||
captures/ | ||
output.json | ||
|
||
#NDK | ||
obj/ | ||
.externalNativeBuild |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
This is a template project for Android Studio that allows you to create an android webview application in minutes. You can use it to create a simple app for your website or as a starting point for your HTML5 based android app. | ||
|
||
### Getting started | ||
|
||
[Download](https://github.com/slymax/webview/archive/master.zip) or clone this repository and import it into Android Studio. | ||
|
||
### Using a remote source | ||
|
||
If you want to create an app that displays the contents of a remote website | ||
|
||
1. uncomment lines **30** and **31** in `MainActivity.java` and replace `http://example.com` with your remote source | ||
|
||
``` | ||
mWebView.loadUrl("http://example.com"); | ||
mWebView.setWebViewClient(new MyWebViewClient()); | ||
``` | ||
|
||
2. open the `MyWebViewClient.java` file and replace `example.com` on line **12** with your custom hostname | ||
|
||
``` | ||
if (Uri.parse(url).getHost().endsWith("example.com")) { | ||
``` | ||
|
||
### Using a local source | ||
|
||
If you want to create a local HTML5 android app | ||
|
||
1. uncomment line **34** in `MainActivity.java` | ||
|
||
``` | ||
mWebView.loadUrl("file:///android_asset/index.html"); | ||
``` | ||
|
||
2. put all your files (including your `index.html`) in the `assets` directory |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 25 | ||
buildToolsVersion '27.0.3' | ||
|
||
defaultConfig { | ||
applicationId "com.example.app" | ||
minSdkVersion 21 | ||
targetSdkVersion 25 | ||
versionCode 1 | ||
versionName "1.0" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation fileTree(dir: 'libs', include: ['*.jar']) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Add project specific ProGuard rules here. | ||
# By default, the flags in this file are appended to flags specified | ||
# in /Applications/Utilities/sdk/tools/proguard/proguard-android.txt | ||
# You can edit the include path and order by changing the proguardFiles | ||
# directive in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# Add any project specific keep options here: | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest | ||
package="com.example.app" | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools"> | ||
<uses-permission android:name="android.permission.INTERNET" /> | ||
<application | ||
android:allowBackup="true" | ||
android:fullBackupContent="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:theme="@style/AppTheme" | ||
tools:ignore="GoogleAppIndexingWarning"> | ||
<activity | ||
android:name="com.example.app.MainActivity" | ||
android:label="@string/app_name" > | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | ||
</head> | ||
<body style="font-family: monospace"> | ||
REPLACE THIS FILE WITH YOUR OWN INDEX.HTML | ||
</body> | ||
</html> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.example.app; | ||
|
||
import android.app.Activity; | ||
import android.os.Bundle; | ||
import android.view.Menu; | ||
import android.view.MenuItem; | ||
import android.webkit.WebSettings; | ||
import android.webkit.WebView; | ||
import android.webkit.WebViewClient; | ||
|
||
public class MainActivity extends Activity { | ||
|
||
private WebView mWebView; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
|
||
mWebView = (WebView) findViewById(R.id.activity_main_webview); | ||
|
||
// Force links and redirects to open in the WebView instead of in a browser | ||
mWebView.setWebViewClient(new WebViewClient()); | ||
|
||
// Enable Javascript | ||
WebSettings webSettings = mWebView.getSettings(); | ||
webSettings.setJavaScriptEnabled(true); | ||
|
||
// REMOTE RESOURCE | ||
// mWebView.loadUrl("http://example.com"); | ||
// mWebView.setWebViewClient(new MyWebViewClient()); | ||
|
||
// LOCAL RESOURCE | ||
// mWebView.loadUrl("file:///android_asset/index.html"); | ||
} | ||
|
||
// Prevent the back-button from closing the app | ||
@Override | ||
public void onBackPressed() { | ||
if(mWebView.canGoBack()) { | ||
mWebView.goBack(); | ||
} else { | ||
super.onBackPressed(); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.example.app; | ||
|
||
import android.content.Intent; | ||
import android.net.Uri; | ||
import android.webkit.WebView; | ||
import android.webkit.WebViewClient; | ||
|
||
public class MyWebViewClient extends WebViewClient { | ||
|
||
@Override | ||
public boolean shouldOverrideUrlLoading(WebView view, String url) { | ||
if (Uri.parse(url).getHost().endsWith("example.com")) { | ||
return false; | ||
} | ||
|
||
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); | ||
view.getContext().startActivity(intent); | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context=".MainActivity"> | ||
|
||
<WebView | ||
android:id="@+id/activity_main_webview" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" /> | ||
|
||
</RelativeLayout> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
|
||
<string name="app_name">WebView App</string> | ||
|
||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<resources> | ||
|
||
<style name="AppTheme" parent="android:Theme.DeviceDefault.Light"> | ||
<item name="android:statusBarColor">@android:color/black</item> | ||
<item name="android:windowActionBar">false</item> | ||
<item name="android:windowNoTitle">true</item> | ||
</style> | ||
|
||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Top-level build file where you can add configuration options common to all sub-projects/modules. | ||
|
||
buildscript { | ||
repositories { | ||
jcenter() | ||
google() | ||
} | ||
dependencies { | ||
classpath 'com.android.tools.build:gradle:3.1.0' | ||
} | ||
} | ||
|
||
allprojects { | ||
repositories { | ||
jcenter() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Project-wide Gradle settings. | ||
|
||
# IDE (e.g. Android Studio) users: | ||
# Gradle settings configured through the IDE *will override* | ||
# any settings specified in this file. | ||
|
||
# For more details on how to configure your build environment visit | ||
# http://www.gradle.org/docs/current/userguide/build_environment.html | ||
|
||
# Specifies the JVM arguments used for the daemon process. | ||
# The setting is particularly useful for tweaking memory settings. | ||
# Default value: -Xmx10248m -XX:MaxPermSize=256m | ||
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 | ||
|
||
# When configured, Gradle will run in incubating parallel mode. | ||
# This option should only be used with decoupled projects. More details, visit | ||
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects | ||
# org.gradle.parallel=true |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#Wed Apr 04 22:50:28 CEST 2018 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip |
Oops, something went wrong.