Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
theodorgreholmtrustly committed Oct 15, 2020
0 parents commit 0712015
Show file tree
Hide file tree
Showing 20 changed files with 687 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.DS_Store
.idea
14 changes: 14 additions & 0 deletions TrustlyAndroidSdk/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
2 changes: 2 additions & 0 deletions TrustlyAndroidSdk/Trustly-Android-Library/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/build
/local.properties
62 changes: 62 additions & 0 deletions TrustlyAndroidSdk/Trustly-Android-Library/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
apply plugin: 'com.android.library'

buildscript {
repositories {
google()
jcenter()
}
}

android {
compileSdkVersion 30
buildToolsVersion "30.0.2"

defaultConfig {
minSdkVersion 19
targetSdkVersion 30
versionCode 4
versionName "1.0.3"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}

dependencies {
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.browser:browser:1.0.0'
}

}

ext {
bintrayRepo = 'TrustlyAndroidSDK'
bintrayName = 'trustly.android.library'

publishedGroupId = 'trustly.android.library'
libraryName = 'TrustlyAndroidLibrary'
artifact = 'TrustlyAndroidLibrary'

libraryDescription = 'Trustly\'s SDK for native android apps.'

siteUrl = 'https://github.com/trustly/TrustlyAndroidSdk'
gitUrl = 'https://github.com/trustly/TrustlyAndroidSdk.git'

libraryVersion = '1.0.3'

developerId = 'Trustly'
developerName = 'Team Bulle'
developerEmail = '[email protected]'

licenseName = 'MIT License'
licenseUrl = 'https://opensource.org/licenses/mit-license.php'
allLicenses = ["MIT"]
}

apply from: 'publish.gradle'
Empty file.
21 changes: 21 additions & 0 deletions TrustlyAndroidSdk/Trustly-Android-Library/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# 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 *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
87 changes: 87 additions & 0 deletions TrustlyAndroidSdk/Trustly-Android-Library/publish.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
apply plugin: 'com.jfrog.bintray'
apply plugin: 'com.github.dcendents.android-maven'

version = libraryVersion
group = publishedGroupId // Maven Group ID for the artifact

install {
repositories.mavenInstaller {
// This generates POM.xml with proper parameters
pom {
project {
packaging 'aar'
groupId publishedGroupId
artifactId artifact

// Add your description here
name libraryName
description libraryDescription
url siteUrl

// Set your license
licenses {
license {
name licenseName
url licenseUrl
}
}
developers {
developer {
id developerId
name developerName
email developerEmail
}
}
scm {
connection gitUrl
developerConnection gitUrl
url siteUrl

}
}
}
}
}

task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
}

task javadoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
}

task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
artifacts {
archives javadocJar
archives sourcesJar
}

// Bintray
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())

bintray {
user = properties.getProperty("bintray.user")
key = properties.getProperty("bintray.apikey")

configurations = ['archives']
pkg {
repo = bintrayRepo
name = bintrayName
desc = libraryDescription
websiteUrl = siteUrl
vcsUrl = gitUrl
licenses = allLicenses
publish = true
publicDownloadNumbers = true
version {
desc = libraryDescription
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.trustlyAndroidLibrary">

<application android:label="@string/app_name">

</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016 Trustly Group AB
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package com.trustlyAndroidLibrary;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.webkit.JavascriptInterface;

public class TrustlyJavascriptInterface {

public static final String NAME = "TrustlyAndroid";

Activity activity;

public TrustlyJavascriptInterface(Activity a) {
activity = a;
}

/**
* Will open the URL, then return result
* @param String packageName
* @param String URIScheme
* @return boolean isOpened
*/
@JavascriptInterface
public boolean openURLScheme(String packageName, String URIScheme) {
if (isPackageInstalledAndEnabled(packageName, activity)) {
Intent intent = new Intent();
intent.setPackage(packageName);
intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.parse(URIScheme));
activity.startActivityForResult(intent, 0);
return true;
} else {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(URIScheme));
activity.startActivityForResult(intent, 0);
}
return false;
}

/**
* Helper function that will verify that URL can be opened, then return result
* @param String packageName
* @param Context context
* @return boolean canBeOpened
*/
private boolean isPackageInstalledAndEnabled(String packageName, Context context) {
PackageManager pm = context.getPackageManager();
try {
pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
ApplicationInfo ai = context.getPackageManager().getApplicationInfo(packageName,0);
return ai.enabled;
} catch (PackageManager.NameNotFoundException e) {}
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.trustlyAndroidLibrary;

import android.os.Message;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceRequest;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import androidx.browser.customtabs.CustomTabsIntent;

import java.lang.ref.WeakReference;

class TrustlyWebChromeClient extends WebChromeClient {
@Override
public boolean onCreateWindow(WebView view, boolean isDialog, boolean isUserGesture, Message resultMsg) {
WeakReference<WebView> tabView = new WeakReference<>(new WebView(view.getContext()));
WebView webview = tabView.get();
if (webview != null) {
webview.setWebViewClient(new Client());
WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj;
transport.setWebView(webview);
resultMsg.sendToTarget();

return true;
}
return false;
}

private static class Client extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
CustomTabsIntent customTab = builder.build();
customTab.launchUrl(view.getContext(), request.getUrl());
return true;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.trustlyAndroidLibrary;

import android.util.Log;
import android.view.ViewGroup;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import androidx.appcompat.app.AppCompatActivity;

public class TrustlyWebView extends WebView {

public TrustlyWebView(AppCompatActivity activity, String url) {
super(activity);

try {
// Enable javascript and DOM Storage
configWebSettings(this);

this.setWebViewClient(new WebViewClient());
this.setWebChromeClient(new TrustlyWebChromeClient());
// Add TrustlyJavascriptInterface
this.addJavascriptInterface(
new TrustlyJavascriptInterface(activity), TrustlyJavascriptInterface.NAME);

this.setLayoutParams(new LayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)));

this.loadUrl(url);
} catch (WebSettingsException e) {
Log.d("WebView", "configWebView: Could not config WebSettings");
} catch (Exception e) {
Log.d("WebView", "configWebView: Unknown Problem happened");
}
}

private void configWebSettings(WebView mainView) throws WebSettingsException {
try {
WebSettings webSettings = mainView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setDomStorageEnabled(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webSettings.setSupportMultipleWindows(true);
} catch (Exception e) {
throw new WebSettingsException(e.getMessage());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.trustlyAndroidLibrary;

public class WebSettingsException extends Exception {
public WebSettingsException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<resources>
<string name="app_name">TrustlyAndroidLibrary</string>
</resources>
Loading

0 comments on commit 0712015

Please sign in to comment.