diff --git a/.gitignore b/.gitignore index 56cc642..e0e88fe 100644 --- a/.gitignore +++ b/.gitignore @@ -38,6 +38,7 @@ captures/ # IntelliJ *.iml +.idea .idea/workspace.xml .idea/tasks.xml .idea/gradle.xml diff --git a/README.md b/README.md index e633d24..151d47f 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,142 @@ # SquatchAndroid + +[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) +[![](https://jitpack.io/v/saasquatch/squatch-android.svg)](https://jitpack.io/#saasquatch/squatch-android) + Helper library for loading SaaSquatch widgets in Android WebView + +## Adding SaaSquatch Java SDK to your project + +SaaSquatch Java SDK is hosted on JitPack. + +Add JitPack repository: + +```gradle +allprojects { + repositories { + ... + maven { url 'https://jitpack.io' } + } +} +``` + +Add the dependency: + +```gradle +dependencies { + implementation 'com.github.saasquatch:squatch-android:0.0.1' +} +``` + +For more information and other built tools, [please refer to the JitPack page](https://jitpack.io/#saasquatch/squatch-android). + +This library relies on [SaaSquatch Java SDK](https://github.com/saasquatch/saasquatch-java-sdk), which has transitive dependencies including [RxJava 3](https://github.com/ReactiveX/RxJava), [Gson](https://github.com/google/gson), and [Apache HttpClient 5](https://hc.apache.org/httpcomponents-client-5.0.x/index.html). This library also has [RxAndroid](https://github.com/ReactiveX/RxAndroid) as a transitive dependency. **It is recommended that you explicitly import the transitive dependencies if you intend to use them**, since we may upgrade or switch to other libraries in the future. You do NOT, however, need to explicitly include [SaaSquatch Java SDK](https://github.com/saasquatch/saasquatch-java-sdk), as it is exposed in public interfaces in this library. + +## Using the SDK + +This library is a wrapper of [SaaSquatch Java SDK](https://github.com/saasquatch/saasquatch-java-sdk) with Android specific features, specifically loading widgets into a WebView. In fact, The `SquatchAndroid` interface has a method called `getSaaSquatchClient()`, which you can use to retrieve the underlying `SaaSquatchClient`. Depending on your use case, [SaaSquatch Java SDK](https://github.com/saasquatch/saasquatch-java-sdk) may be what you need. + +The entry point of the SDK is `SquatchAndroid`. To create a `SquatchAndroid` for your tenant with default options, use: + +```java +SquatchAndroid.createForTenant("yourTenantAlias"); +``` + +It is recommended that you keep a singleton `SquatchAndroid` for all your requests instead of creating a new `SquatchAndroid` for every request. `SquatchAndroid` implements `Closeable`, and it's a good idea to call `close()` to release resources when you are done with it. + +`SquatchAndroid` returns [Reactive Streams](https://www.reactive-streams.org/) interfaces. Assuming you are using RxJava, then a typical API call made with this SDK would look something like this: + +```java +Flowable.fromPublisher(squatchAndroid.widgetUpsert( + WidgetUpsertInput.newBuilder() + .setUserInputWithUserJwt(userJwt) + .setWidgetType(WidgetType.ofProgramWidget("referral-program", "referrerWidget")) + .build(), + null, AndroidRenderWidgetOptions.ofWebView(webView))) + .onErrorComplete() // or provide your own error handling + .subscribe(); +``` + +In the code above, a widget upsert is performed asynchronously with the given `userJwt`, and the resulting widget is loaded into the given `webView` with the Android main thread. + +## More Code Samples + +Widget upsert while setting a user's `customFields` + +```java +final Map userInput = new HashMap<>(); +userInput.put("id", "a"); +userInput.put("accountId", "a"); +final Map customFields = new HashMap<>(); +customFields.put("birthday", "--12-25"); +userInput.put("customFields", customFields); +Flowable.fromPublisher(squatchAndroid.widgetUpsert( + WidgetUpsertInput.newBuilder() + .setUserInput(userInput) + .build(), + RequestOptions.newBuilder() + .setAuthMethod(AuthMethod.ofJwt(userJwt)) + .build(), + AndroidRenderWidgetOptions.ofWebView(webView))) + .onErrorComplete() // or provide your own error handling + .subscribe(); +``` + +Rendering a widget for a user + +```java +Flowable.fromPublisher(squatchAndroid.renderWidget( + RenderWidgetInput.newBuilder() + .setUserWithUserJwt(userJwt) + .setWidgetType(WidgetType.ofProgramWidget("referral-program", "referrerWidget")) + .build(), + null, AndroidRenderWidgetOptions.ofWebView(webView))) + .onErrorComplete() // or provide your own error handling + .subscribe(); +``` + +Logging an event for a user (using the underlying `SaaSquatchClient`) + +```java +final Map fields = new HashMap<>(); +fields.put("currency", "CAD"); +Flowable.fromPublisher(squatchAndroid.getSaaSquatchClient().logUserEvent( + UserEventInput.newBuilder() + .setAccountId("a") + .setUserId("a") + .addEvents(UserEventDataInput.newBuilder() + .setKey("purchase") + .setFields(fields) + .build()) + .build(), + RequestOptions.newBuilder() + .setAuthMethod(AuthMethod.ofJwt(userJwt)) + .build())) + // This is necessary so the main thread does not start the IO operation + .subscribeOn(Schedulers.io()) + .onErrorComplete() // or provide your own error handling + .subscribe(); +``` + +## License + +Unless explicitly stated otherwise all files in this repository are licensed under the Apache +License 2.0. + +License boilerplate: + +``` +Copyright 2021 ReferralSaaSquatch.com Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +``` diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..9ac94df --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,37 @@ +apply plugin: 'com.android.library' + +android { + compileSdkVersion 30 + buildToolsVersion "30.0.3" + + defaultConfig { + minSdkVersion 19 + targetSdkVersion 30 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } +} + +dependencies { + implementation fileTree(dir: "libs", include: ["*.jar"]) + implementation 'androidx.appcompat:appcompat:1.2.0' + testImplementation 'junit:junit:4.13.2' + androidTestImplementation 'androidx.test.ext:junit:1.1.2' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' + api 'com.github.saasquatch:saasquatch-java-sdk:0.0.1' + implementation 'io.reactivex.rxjava3:rxandroid:3.0.0' +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..f1b4245 --- /dev/null +++ b/app/proguard-rules.pro @@ -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 diff --git a/app/src/androidTest/java/com/saasquatch/android/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/saasquatch/android/ExampleInstrumentedTest.java new file mode 100644 index 0000000..6929a5e --- /dev/null +++ b/app/src/androidTest/java/com/saasquatch/android/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.saasquatch.android; + +import static org.junit.Assert.assertEquals; + +import android.content.Context; +import androidx.test.ext.junit.runners.AndroidJUnit4; +import androidx.test.platform.app.InstrumentationRegistry; +import org.junit.Test; +import org.junit.runner.RunWith; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + assertEquals("com.saasquatch.android", appContext.getPackageName()); + } + +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..3d5ae0a --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,8 @@ + + + + + diff --git a/app/src/main/java/com/saasquatch/android/SquatchAndroid.java b/app/src/main/java/com/saasquatch/android/SquatchAndroid.java new file mode 100644 index 0000000..9461f37 --- /dev/null +++ b/app/src/main/java/com/saasquatch/android/SquatchAndroid.java @@ -0,0 +1,60 @@ +package com.saasquatch.android; + +import android.webkit.WebView; +import com.saasquatch.android.input.AndroidRenderWidgetOptions; +import com.saasquatch.sdk.RequestOptions; +import com.saasquatch.sdk.SaaSquatchClient; +import com.saasquatch.sdk.input.RenderWidgetInput; +import com.saasquatch.sdk.input.WidgetUpsertInput; +import com.saasquatch.sdk.output.JsonObjectApiResponse; +import com.saasquatch.sdk.output.TextApiResponse; +import java.io.Closeable; +import java.util.Objects; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import org.reactivestreams.Publisher; + +/** + * Wrapper for {@link SaaSquatchClient} that contains Android specific features. + * + * @author sli + */ +public interface SquatchAndroid extends Closeable { + + /** + * @return A {@link SquatchAndroid} instance that wraps the given {@link SaaSquatchClient}. + */ + static SquatchAndroid create(@Nonnull SaaSquatchClient saasquatchClient) { + return new SquatchAndroidImpl(Objects.requireNonNull(saasquatchClient)); + } + + /** + * @return A {@link SquatchAndroid} instance using the given tenant alias with default options. + */ + static SquatchAndroid createForTenant(@Nonnull String tenantAlias) { + return create(SaaSquatchClient.createForTenant(tenantAlias)); + } + + /** + * @return The underlying {@link SaaSquatchClient}. + */ + @Nonnull + SaaSquatchClient getSaaSquatchClient(); + + /** + * Wrapper for {@link SaaSquatchClient#renderWidget(RenderWidgetInput, RequestOptions)} that loads + * the result widget HTML into a {@link WebView}. + */ + Publisher renderWidget(@Nonnull RenderWidgetInput renderWidgetInput, + @Nullable RequestOptions requestOptions, + @Nonnull AndroidRenderWidgetOptions androidRenderWidgetOptions); + + /** + * Wrapper for {@link SaaSquatchClient#widgetUpsert(WidgetUpsertInput, RequestOptions)} that loads + * the result widget HTML into a {@link WebView}. + */ + Publisher widgetUpsert(@Nonnull WidgetUpsertInput widgetUpsertInput, + @Nullable RequestOptions requestOptions, + @Nonnull AndroidRenderWidgetOptions androidRenderWidgetOptions); + +} diff --git a/app/src/main/java/com/saasquatch/android/SquatchAndroidImpl.java b/app/src/main/java/com/saasquatch/android/SquatchAndroidImpl.java new file mode 100644 index 0000000..ef0f54d --- /dev/null +++ b/app/src/main/java/com/saasquatch/android/SquatchAndroidImpl.java @@ -0,0 +1,139 @@ +package com.saasquatch.android; + +import static java.nio.charset.StandardCharsets.UTF_8; + +import android.annotation.SuppressLint; +import android.util.Base64; +import android.webkit.WebSettings; +import android.webkit.WebView; +import com.saasquatch.android.input.AndroidRenderWidgetOptions; +import com.saasquatch.sdk.RequestOptions; +import com.saasquatch.sdk.SaaSquatchClient; +import com.saasquatch.sdk.exceptions.SaaSquatchApiException; +import com.saasquatch.sdk.input.RenderWidgetInput; +import com.saasquatch.sdk.input.WidgetUpsertInput; +import com.saasquatch.sdk.models.WidgetUpsertResult; +import com.saasquatch.sdk.output.ApiError; +import com.saasquatch.sdk.output.JsonObjectApiResponse; +import com.saasquatch.sdk.output.TextApiResponse; +import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers; +import io.reactivex.rxjava3.core.Flowable; +import io.reactivex.rxjava3.core.FlowableTransformer; +import io.reactivex.rxjava3.schedulers.Schedulers; +import java.io.IOException; +import java.text.MessageFormat; +import java.util.Locale; +import java.util.Objects; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import org.reactivestreams.Publisher; + +final class SquatchAndroidImpl implements SquatchAndroid { + + private final SaaSquatchClient saasquatchClient; + + SquatchAndroidImpl(@Nonnull SaaSquatchClient saasquatchClient) { + this.saasquatchClient = saasquatchClient; + } + + @Override + public void close() throws IOException { + saasquatchClient.close(); + } + + @Nonnull + @Override + public SaaSquatchClient getSaaSquatchClient() { + return saasquatchClient; + } + + @Override + public Publisher renderWidget(@Nonnull RenderWidgetInput renderWidgetInput, + @Nullable RequestOptions requestOptions, + @Nonnull AndroidRenderWidgetOptions androidRenderWidgetOptions) { + Objects.requireNonNull(androidRenderWidgetOptions, "androidRenderWidgetOptions"); + return Flowable.fromPublisher(saasquatchClient.renderWidget(renderWidgetInput, requestOptions)) + .compose(publisherCommon(androidRenderWidgetOptions)) + .doOnNext(apiResponse -> { + loadHtmlToWebView(androidRenderWidgetOptions, apiResponse.getData()); + }); + } + + @Override + public Publisher widgetUpsert(@Nonnull WidgetUpsertInput widgetUpsertInput, + @Nullable RequestOptions requestOptions, + @Nonnull AndroidRenderWidgetOptions androidRenderWidgetOptions) { + Objects.requireNonNull(androidRenderWidgetOptions, "androidRenderWidgetOptions"); + return Flowable.fromPublisher(saasquatchClient.widgetUpsert(widgetUpsertInput, requestOptions)) + .compose(publisherCommon(androidRenderWidgetOptions)) + .doOnNext(apiResponse -> { + final WidgetUpsertResult widgetUpsertResult = + apiResponse.toModel(WidgetUpsertResult.class); + loadHtmlToWebView(androidRenderWidgetOptions, widgetUpsertResult.getTemplate()); + }); + } + + private FlowableTransformer publisherCommon( + @Nonnull AndroidRenderWidgetOptions androidRenderWidgetOptions) { + return p -> p.subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .doOnError(t -> loadErrorHtmlToWebView(androidRenderWidgetOptions, t)); + } + + @SuppressLint("SetJavaScriptEnabled") + private void loadHtmlToWebView(@Nonnull AndroidRenderWidgetOptions androidRenderWidgetOptions, + @Nonnull String htmlString) { + final WebView webView = androidRenderWidgetOptions.getWebView(); + final WebSettings webSettings = webView.getSettings(); + webSettings.setJavaScriptEnabled(true); + webSettings.setDomStorageEnabled(true); + SquatchJavascriptInterface.applyToWebView(webView); + final String htmlBase64 = Base64.encodeToString(htmlString.getBytes(UTF_8), Base64.DEFAULT); + webView.loadData(htmlBase64, "text/html", "base64"); + } + + private void loadErrorHtmlToWebView( + @Nonnull AndroidRenderWidgetOptions androidRenderWidgetOptions, Throwable throwable) { + int count = 0; + String rsCode = null; + do { + if (throwable instanceof SaaSquatchApiException) { + final ApiError apiError = ((SaaSquatchApiException) throwable).getApiError(); + rsCode = apiError.getRsCode(); + break; + } + } while ((throwable = throwable.getCause()) != null && count++ < 100); + final String htmlString = new MessageFormat(ERR_HTML_TEMPLATE, Locale.ROOT) + .format(new Object[]{rsCode}); + loadHtmlToWebView(androidRenderWidgetOptions, htmlString); + } + + private static final String ERR_HTML_TEMPLATE = "" + + "\n" + + "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + "
\n" + + "
\n" + + "
\n" + + " \n" + + "
\n" + + "

Our referral program is temporarily unavailable.

\n" + + "
\n" + + "

Please reload the page or check back later.

\n" + + "

If the persists please contact our support team.

\n" + + "
\n" + + "
\n" + + "
Error Code: {0}
\n" + + "
\n" + + "
\n" + + " \n" + + ""; + +} diff --git a/app/src/main/java/com/saasquatch/android/SquatchJavascriptInterface.java b/app/src/main/java/com/saasquatch/android/SquatchJavascriptInterface.java new file mode 100644 index 0000000..8fa0246 --- /dev/null +++ b/app/src/main/java/com/saasquatch/android/SquatchJavascriptInterface.java @@ -0,0 +1,82 @@ +package com.saasquatch.android; + +import android.content.Context; +import android.content.Intent; +import android.content.pm.ResolveInfo; +import android.net.Uri; +import android.webkit.JavascriptInterface; +import android.webkit.WebView; +import android.widget.Toast; +import java.util.List; +import java.util.Objects; +import javax.annotation.Nonnull; + +/** + * Javascript interface with utility methods for SaaSquatch widgets. + * + * @see WebView#addJavascriptInterface(Object, String) + */ +public final class SquatchJavascriptInterface { + + public static final String JAVASCRIPT_INTERFACE_NAME = "SquatchAndroid"; + + private final Context mContext; + + private SquatchJavascriptInterface(Context mContext) { + this.mContext = mContext; + } + + /** + * Share on Facebook with browser fallback + */ + @JavascriptInterface + public void shareOnFacebook(@Nonnull String shareLink, @Nonnull String messageLink) { + Objects.requireNonNull(shareLink); + Objects.requireNonNull(messageLink); + final Intent fbIntent = new Intent(Intent.ACTION_SEND) + .setType("text/plain") + .putExtra(Intent.EXTRA_TEXT, shareLink) + .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + // See if official Facebook app is found + // From https://stackoverflow.com/questions/7545254/android-and-facebook-share-intent + final List resolveInfoList = mContext.getPackageManager() + .queryIntentActivities(fbIntent, 0); + for (ResolveInfo resolveInfo : resolveInfoList) { + if (resolveInfo.activityInfo.packageName.toLowerCase().startsWith("com.facebook.katana")) { + fbIntent.setPackage(resolveInfo.activityInfo.packageName); + mContext.startActivity(fbIntent); + return; + } + } + // As fallback to a browser + final Intent fallbackIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(messageLink)) + .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + mContext.startActivity(fallbackIntent); + } + + /** + * Show a toast from the web page + */ + @JavascriptInterface + public void showToast(@Nonnull String toast) { + Objects.requireNonNull(toast); + Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show(); + } + + /** + * Default factory method for {@link SquatchJavascriptInterface}. + * + * @see SquatchJavascriptInterface#JAVASCRIPT_INTERFACE_NAME + */ + public static SquatchJavascriptInterface create(@Nonnull Context mContext) { + return new SquatchJavascriptInterface(Objects.requireNonNull(mContext)); + } + + /** + * Apply {@link SquatchJavascriptInterface} to a given {@link WebView}. + */ + public static void applyToWebView(@Nonnull WebView webView) { + webView.addJavascriptInterface(create(webView.getContext()), JAVASCRIPT_INTERFACE_NAME); + } + +} diff --git a/app/src/main/java/com/saasquatch/android/input/AndroidRenderWidgetOptions.java b/app/src/main/java/com/saasquatch/android/input/AndroidRenderWidgetOptions.java new file mode 100644 index 0000000..7b589bc --- /dev/null +++ b/app/src/main/java/com/saasquatch/android/input/AndroidRenderWidgetOptions.java @@ -0,0 +1,44 @@ +package com.saasquatch.android.input; + +import android.webkit.WebView; +import java.util.Objects; +import javax.annotation.Nonnull; + +public final class AndroidRenderWidgetOptions { + + private final WebView webView; + + private AndroidRenderWidgetOptions(WebView webView) { + this.webView = webView; + } + + public WebView getWebView() { + return webView; + } + + public static Builder newBuilder() { + return new Builder(); + } + + public static AndroidRenderWidgetOptions ofWebView(@Nonnull WebView webView) { + return newBuilder().setWebView(webView).build(); + } + + public static final class Builder { + + private WebView webView; + + private Builder() {} + + public Builder setWebView(@Nonnull WebView webView) { + this.webView = Objects.requireNonNull(webView, "webView"); + return this; + } + + public AndroidRenderWidgetOptions build() { + return new AndroidRenderWidgetOptions(Objects.requireNonNull(webView, "webView")); + } + + } + +} diff --git a/app/src/test/java/com/saasquatch/android/ExampleUnitTest.java b/app/src/test/java/com/saasquatch/android/ExampleUnitTest.java new file mode 100644 index 0000000..9469978 --- /dev/null +++ b/app/src/test/java/com/saasquatch/android/ExampleUnitTest.java @@ -0,0 +1,17 @@ +package com.saasquatch.android; + +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Example local unit test, which will execute on the development machine (host). + * + * @see Testing documentation + */ +public class ExampleUnitTest { + @Test + public void addition_isCorrect() { + assertEquals(4, 2 + 2); + } +} diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..61350a9 --- /dev/null +++ b/build.gradle @@ -0,0 +1,25 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. +buildscript { + repositories { + google() + jcenter() + } + dependencies { + classpath "com.android.tools.build:gradle:4.0.2" + + // NOTE: Do not place your application dependencies here; they belong + // in the individual module build.gradle files + } +} + +allprojects { + repositories { + google() + jcenter() + maven { url 'https://jitpack.io' } + } +} + +task clean(type: Delete) { + delete rootProject.buildDir +} diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..2f26404 --- /dev/null +++ b/gradle.properties @@ -0,0 +1,19 @@ +# 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. +org.gradle.jvmargs=-Xmx2048m +# 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 +# AndroidX package structure to make it clearer which packages are bundled with the +# Android operating system, and which are packaged with your app"s APK +# https://developer.android.com/topic/libraries/support-library/androidx-rn +android.useAndroidX=true +# Automatically convert third-party libraries to use AndroidX +android.enableJetifier=true diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..e708b1c Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..2a56324 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.2-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100644 index 0000000..4f906e0 --- /dev/null +++ b/gradlew @@ -0,0 +1,185 @@ +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=`expr $i + 1` + done + case $i in + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=`save "$@"` + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..107acd3 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..27ffb43 --- /dev/null +++ b/settings.gradle @@ -0,0 +1,2 @@ +include ':app' +rootProject.name = "SquatchAndroid"