Compare commits
No commits in common. "main" and "v0.1.0" have entirely different histories.
3
.gitignore
vendored
|
|
@ -18,6 +18,3 @@ android/.idea/
|
|||
*.iml
|
||||
|
||||
.DS_Store
|
||||
|
||||
# Example app keeps its Xcode project
|
||||
!example-app/ios/App/App.xcodeproj/
|
||||
|
|
|
|||
97
CHANGELOG.md
|
|
@ -1,104 +1,11 @@
|
|||
# Changelog
|
||||
|
||||
All notable changes to this project are documented in this file.
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to
|
||||
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
## 0.1.0 (2026-10-09)
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## [0.3.0] - 2026-10-10
|
||||
|
||||
Banners, native ads, impression-level revenue, segments, dynamic user id, placement capping and Capacitor 7 support.
|
||||
Fully backwards compatible with 0.2.x.
|
||||
|
||||
### Added (API)
|
||||
- `docs/design-0.3.md`: banner, native ad, impression data, placement, segment and dynamic user id design with the
|
||||
exact LevelPlay 9.6.1 Android / iOS mappings, overlay positioning, error codes, Capacitor 7 findings, test plan.
|
||||
- TypeScript API (`@since 0.3.0`): `getCapabilities`, `setSegment`, `setDynamicUserId`, `isPlacementCapped`,
|
||||
`getReward`, `createBanner` / `loadBanner` / `showBanner` / `hideBanner` / `setBannerLayout` / `destroyBanner`,
|
||||
`loadNativeAd` / `showNativeAd` / `setNativeAdRect` / `hideNativeAd` / `destroyNativeAd`; events `adInfoChanged`,
|
||||
`impressionData`, `banner*` and `nativeAd*`.
|
||||
- `AdInfo` gains optional `ab`, `segmentName`, `encryptedCPM`, `creativeId`, `conversionValue` (iOS) and `adSize`.
|
||||
- Web stubs for every new method.
|
||||
|
||||
### Added (Android)
|
||||
- Banners in a pass-through overlay above the WebView: presets, `ADAPTIVE` (width in dp = CSS px, recreated on
|
||||
rotation), `CUSTOM` sizes, top / bottom / center with offsets, safe area from the WebView's on-screen rect and the
|
||||
window insets, several banners by id, every `banner*` event.
|
||||
- Native ads with the plugin's `small` and `medium` templates (colours, corner radius, fonts) and `nativeAd*` events.
|
||||
- `impressionData` from per-ad listeners, queued (max 100) until the first JS listener; `adInfoChanged`;
|
||||
`getCapabilities`, `setSegment`, `setDynamicUserId`, `isPlacementCapped`, `getReward`.
|
||||
- `AdInfo` fields `ab`, `segmentName`, `encryptedCPM`, `creativeId`, `adSize` on Android.
|
||||
- JVM unit tests for the overlay geometry and argument validation (`bun run verify:android`).
|
||||
- `BannerSize` `CUSTOM` with `customSize`, `NativeAdTemplateStyle` fonts, banner ids in `LEVELPLAY_DEMO`.
|
||||
|
||||
### Added (iOS)
|
||||
- Banners in a pass-through overlay inside the WebView: presets, `ADAPTIVE` (width in pt = CSS px, recreated when the
|
||||
safe-area width changes), `CUSTOM` sizes, top / bottom / center with offsets, safe area, several banners by id, every
|
||||
`banner*` event.
|
||||
- Native ads with the plugin's `small` and `medium` templates built in code (`ISNativeAdView` binding; colours, corner
|
||||
radius, system or web-asset fonts) and `nativeAd*` events.
|
||||
- `impressionData` from per-ad delegates (with `conversionValue`), queued (max 100) until the first JS listener;
|
||||
native impressions synthesised; `adInfoChanged`; `getCapabilities`, `setSegment`, `setDynamicUserId`,
|
||||
`isPlacementCapped`, `getReward`; cleanup of banners and native ads when the plugin is released.
|
||||
- `AdInfo` fields `ab`, `segmentName`, `encryptedCPM`, `creativeId`, `conversionValue`, `adSize` on iOS.
|
||||
|
||||
### Added (tooling and docs)
|
||||
- `bun run test`: `bun test` for the web stub (unimplemented rejections vs no-ops), `LEVELPLAY_DEMO` and the exports,
|
||||
plus a compile-only check of the public API (`tsc -p test`); `verify` runs it.
|
||||
- `example-app/`: a minimal Capacitor 8 app (HTML + TypeScript, esbuild) with the demo ids and buttons for every
|
||||
format, segments and an impression log; Android and iOS (SPM) platforms committed. Not part of the npm package.
|
||||
- README: banners, native ads (style options), impression data, segments / user id / placements, error codes,
|
||||
limitations, example app, Capacitor 7.
|
||||
|
||||
### Changed
|
||||
- Capacitor 7 support: `peerDependencies` `@capacitor/core >=7.0.0`; `Package.swift` depends on `capacitor-swift-pm`
|
||||
`"7.0.0"..<"9.0.0"`; iOS deployment target 14.0 in `Package.swift` and the podspec (was 15.0); Android
|
||||
`minSdkVersion` fallback 23 (was 24). Checked by building a Capacitor 7.6.9 app for Android and the iOS simulator.
|
||||
|
||||
## [0.2.1] - 2026-10-10
|
||||
|
||||
### Changed
|
||||
- Author and copyright: CRTkafa (LICENSE, `package.json`, README, podspec).
|
||||
- `repository.url` is the plain repo address (npmjs.com shows it readable instead of `git+https://….git`).
|
||||
- Android Java package and Gradle namespace renamed to `fyi.crt.capacitor.levelplay`. Run `npx cap sync` after
|
||||
updating; no API or behaviour changes.
|
||||
|
||||
## [0.2.0] - 2026-10-10
|
||||
|
||||
First public release on npm. No behaviour changes to the native bridges since 0.1.0.
|
||||
|
||||
### Added
|
||||
- Complete README: compatibility table, iOS (SPM and CocoaPods) and Android setup, usage guide, mediation adapters
|
||||
(Gradle, Swift packages, local-package workaround for networks without an official Swift package), privacy and
|
||||
ATT guide, troubleshooting, FAQ.
|
||||
- API reference generated from the JSDoc in `src/definitions.ts` with `@capacitor/docgen` (`bun run docgen`, also
|
||||
part of `bun run build`); `dist/docs.json` ships with the package.
|
||||
- JSDoc with `@since` for every method, option, event and type.
|
||||
- `verify:android` script and a standalone Gradle setup (`android/settings.gradle`, Gradle wrapper 8.14.3) that builds
|
||||
the Android library against `@capacitor/android` (dev dependency).
|
||||
- `CONTRIBUTING.md`.
|
||||
|
||||
### Changed
|
||||
- `package.json`: description, author, `homepage`, `bugs`, `repository`, keywords,
|
||||
`engines` (Node 22+, as Capacitor 8), `files` (adds `CHANGELOG.md`).
|
||||
- Podspec: homepage from `package.json`, source is `https://git.crt.fyi/CRT/capacitor-levelplay.git` at tag
|
||||
`v<version>`.
|
||||
- `tsconfig.json`: no explicit `lib` (same defaults for `target: es2017`), so docgen resolves `Promise` types.
|
||||
|
||||
## [0.1.0] - 2026-10-09
|
||||
|
||||
### Added
|
||||
- Capacitor 8 plugin for Unity LevelPlay rewarded and interstitial ads (ad-unit API).
|
||||
- First release: Capacitor 8 plugin for Unity LevelPlay rewarded and interstitial ads (ad-unit API).
|
||||
- iOS: Swift Package Manager with the official LevelPlay-Swift-Package (SDK 9.6.1); podspec on `IronSourceSDK ~> 9.6.1`.
|
||||
- Android: `com.unity3d.ads-mediation:mediation-sdk:9.6.1` from Maven Central, Play services ids, consumer ProGuard rules.
|
||||
- API: `initialize`, `setConsent` (GDPR / CCPA / COPPA), `setMetaData`, iOS ATT, load / show / isReady per ad unit,
|
||||
`launchTestSuite`, `validateIntegration`, events `loaded` `loadFailed` `displayed` `displayFailed` `clicked`
|
||||
`closed` `rewarded`. Show calls resolve after close with `{ shown, rewarded, reward?, error? }`.
|
||||
- `LEVELPLAY_DEMO`: Unity's public demo app keys and ad unit ids.
|
||||
|
||||
[Unreleased]: https://git.crt.fyi/CRT/capacitor-levelplay/compare/v0.3.0...main
|
||||
[0.3.0]: https://git.crt.fyi/CRT/capacitor-levelplay/compare/v0.2.1...v0.3.0
|
||||
[0.2.1]: https://git.crt.fyi/CRT/capacitor-levelplay/compare/v0.2.0...v0.2.1
|
||||
[0.2.0]: https://git.crt.fyi/CRT/capacitor-levelplay/compare/v0.1.0...v0.2.0
|
||||
[0.1.0]: https://git.crt.fyi/CRT/capacitor-levelplay/releases/tag/v0.1.0
|
||||
|
|
|
|||
|
|
@ -1,30 +0,0 @@
|
|||
# Contributing
|
||||
|
||||
Thanks for helping. Bug reports, questions and feature requests go to the
|
||||
[issue tracker](https://git.crt.fyi/CRT/capacitor-levelplay/issues). For a bug, include the plugin version, the
|
||||
LevelPlay SDK and adapter versions, the platform and OS version, and the native log (Xcode console or
|
||||
`adb logcat | grep -E "LevelPlay|IronSource|IntegrationHelper"`).
|
||||
|
||||
## Development
|
||||
|
||||
Requirements: [Bun](https://bun.sh), Xcode 26+ for iOS, JDK 21 and the Android SDK for Android.
|
||||
|
||||
```sh
|
||||
bun install
|
||||
bun run build # docgen (README API section) + dist/
|
||||
bun run typecheck
|
||||
bun run verify:ios # xcodebuild the Swift package (iOS simulator)
|
||||
JAVA_HOME=$(/usr/libexec/java_home -v 21) bun run verify:android
|
||||
```
|
||||
|
||||
- The public API lives in `src/definitions.ts`. Document every method, option and event with JSDoc (`@since`), then
|
||||
run `bun run build` so the API section of `README.md` is regenerated. Do not edit between the `docgen` markers by hand.
|
||||
- Keep the Android (`android/src/main/java/...`) and iOS (`ios/Sources/...`) bridges in step: same method names, same
|
||||
result and event shapes.
|
||||
- `dist/` is committed so the package can be installed from git; rebuild it in the same commit as source changes.
|
||||
- Add an entry under `Unreleased` in `CHANGELOG.md`.
|
||||
|
||||
## Pull requests
|
||||
|
||||
Keep them focused, describe what changed and how you tested it (device or simulator, OS version, network). By
|
||||
contributing you agree that your work is released under the [MIT License](LICENSE).
|
||||
|
|
@ -1,21 +1,18 @@
|
|||
require 'json'
|
||||
|
||||
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
|
||||
repo = 'https://git.crt.fyi/CRT/capacitor-levelplay'
|
||||
|
||||
Pod::Spec.new do |s|
|
||||
s.name = 'CapacitorLevelplay'
|
||||
s.version = package['version']
|
||||
s.summary = 'Capacitor plugin for Unity LevelPlay rewarded and interstitial ads.'
|
||||
s.description = package['description']
|
||||
s.summary = package['description']
|
||||
s.license = package['license']
|
||||
s.homepage = package['homepage']
|
||||
s.homepage = package['repository']['url']
|
||||
s.author = package['author']
|
||||
s.source = { :git => "#{repo}.git", :tag => "v#{s.version}" }
|
||||
s.source = { :git => package['repository']['url'], :tag => 'v' + package['version'] }
|
||||
s.source_files = 'ios/Sources/**/*.{swift,h,m}'
|
||||
s.ios.deployment_target = '14.0'
|
||||
s.ios.deployment_target = '15.0'
|
||||
s.dependency 'Capacitor'
|
||||
# Unity LevelPlay SDK (ironSource), https://cocoapods.org/pods/IronSourceSDK
|
||||
s.dependency 'IronSourceSDK', '~> 9.6.1'
|
||||
s.frameworks = 'AppTrackingTransparency'
|
||||
s.swift_version = '5.9'
|
||||
|
|
|
|||
2
LICENSE
|
|
@ -1,6 +1,6 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2026 CRTkafa
|
||||
Copyright (c) 2026 VOX Games
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
|
|
|||
|
|
@ -3,14 +3,14 @@ import PackageDescription
|
|||
|
||||
let package = Package(
|
||||
name: "CapacitorLevelplay",
|
||||
platforms: [.iOS(.v14)],
|
||||
platforms: [.iOS(.v15)],
|
||||
products: [
|
||||
.library(
|
||||
name: "CapacitorLevelplay",
|
||||
targets: ["LevelPlayPlugin"])
|
||||
],
|
||||
dependencies: [
|
||||
.package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", "7.0.0"..<"9.0.0"),
|
||||
.package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "8.0.0"),
|
||||
// Official Unity LevelPlay SDK (binary xcframework + Ad Quality), https://github.com/ironsource-mobile/LevelPlay-Swift-Package
|
||||
.package(url: "https://github.com/ironsource-mobile/LevelPlay-Swift-Package.git", "9.6.1"..<"10.0.0")
|
||||
],
|
||||
|
|
|
|||
|
|
@ -22,10 +22,10 @@ buildscript {
|
|||
apply plugin: 'com.android.library'
|
||||
|
||||
android {
|
||||
namespace = "fyi.crt.capacitor.levelplay"
|
||||
namespace = "com.voxgames.capacitor.levelplay"
|
||||
compileSdk = project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 36
|
||||
defaultConfig {
|
||||
minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 23
|
||||
minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 24
|
||||
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 36
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
|
|
|
|||
|
|
@ -1,3 +0,0 @@
|
|||
# Standalone build of the plugin library (`bun run verify:android`). Not used by consuming apps.
|
||||
org.gradle.jvmargs=-Xmx1536m
|
||||
android.useAndroidX=true
|
||||
BIN
android/gradle/wrapper/gradle-wrapper.jar
vendored
|
|
@ -1,7 +0,0 @@
|
|||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-all.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
251
android/gradlew
vendored
|
|
@ -1,251 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
#
|
||||
# Copyright © 2015-2021 the original 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.
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# Gradle start up script for POSIX generated by Gradle.
|
||||
#
|
||||
# Important for running:
|
||||
#
|
||||
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
||||
# noncompliant, but you have some other compliant shell such as ksh or
|
||||
# bash, then to run this script, type that shell name before the whole
|
||||
# command line, like:
|
||||
#
|
||||
# ksh Gradle
|
||||
#
|
||||
# Busybox and similar reduced shells will NOT work, because this script
|
||||
# requires all of these POSIX shell features:
|
||||
# * functions;
|
||||
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
||||
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
||||
# * compound commands having a testable exit status, especially «case»;
|
||||
# * various built-in commands including «command», «set», and «ulimit».
|
||||
#
|
||||
# Important for patching:
|
||||
#
|
||||
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
||||
# by Bash, Ksh, etc; in particular arrays are avoided.
|
||||
#
|
||||
# The "traditional" practice of packing multiple parameters into a
|
||||
# space-separated string is a well documented source of bugs and security
|
||||
# problems, so this is (mostly) avoided, by progressively accumulating
|
||||
# options in "$@", and eventually passing that to Java.
|
||||
#
|
||||
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
||||
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
||||
# see the in-line comments for details.
|
||||
#
|
||||
# There are tweaks for specific operating systems such as AIX, CygWin,
|
||||
# Darwin, MinGW, and NonStop.
|
||||
#
|
||||
# (3) This script is generated from the Groovy template
|
||||
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# within the Gradle project.
|
||||
#
|
||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
|
||||
# Resolve links: $0 may be a link
|
||||
app_path=$0
|
||||
|
||||
# Need this for daisy-chained symlinks.
|
||||
while
|
||||
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
||||
[ -h "$app_path" ]
|
||||
do
|
||||
ls=$( ls -ld "$app_path" )
|
||||
link=${ls#*' -> '}
|
||||
case $link in #(
|
||||
/*) app_path=$link ;; #(
|
||||
*) app_path=$APP_HOME$link ;;
|
||||
esac
|
||||
done
|
||||
|
||||
# This is normally unused
|
||||
# shellcheck disable=SC2034
|
||||
APP_BASE_NAME=${0##*/}
|
||||
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD=maximum
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
} >&2
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
} >&2
|
||||
|
||||
# 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 ;; #(
|
||||
MSYS* | MINGW* ) msys=true ;; #(
|
||||
NONSTOP* ) nonstop=true ;;
|
||||
esac
|
||||
|
||||
CLASSPATH="\\\"\\\""
|
||||
|
||||
|
||||
# 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
|
||||
if ! command -v java >/dev/null 2>&1
|
||||
then
|
||||
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
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||
case $MAX_FD in #(
|
||||
max*)
|
||||
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC2039,SC3045
|
||||
MAX_FD=$( ulimit -H -n ) ||
|
||||
warn "Could not query maximum file descriptor limit"
|
||||
esac
|
||||
case $MAX_FD in #(
|
||||
'' | soft) :;; #(
|
||||
*)
|
||||
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC2039,SC3045
|
||||
ulimit -n "$MAX_FD" ||
|
||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||
esac
|
||||
fi
|
||||
|
||||
# Collect all arguments for the java command, stacking in reverse order:
|
||||
# * args from the command line
|
||||
# * the main class name
|
||||
# * -classpath
|
||||
# * -D...appname settings
|
||||
# * --module-path (only if needed)
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
||||
|
||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||
if "$cygwin" || "$msys" ; then
|
||||
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
||||
|
||||
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
for arg do
|
||||
if
|
||||
case $arg in #(
|
||||
-*) false ;; # don't mess with options #(
|
||||
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
||||
[ -e "$t" ] ;; #(
|
||||
*) false ;;
|
||||
esac
|
||||
then
|
||||
arg=$( cygpath --path --ignore --mixed "$arg" )
|
||||
fi
|
||||
# Roll the args list around exactly as many times as the number of
|
||||
# args, so each arg winds up back in the position where it started, but
|
||||
# possibly modified.
|
||||
#
|
||||
# NB: a `for` loop captures its iteration list before it begins, so
|
||||
# changing the positional parameters here affects neither the number of
|
||||
# iterations, nor the values presented in `arg`.
|
||||
shift # remove old arg
|
||||
set -- "$@" "$arg" # push replacement arg
|
||||
done
|
||||
fi
|
||||
|
||||
|
||||
# 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"'
|
||||
|
||||
# Collect all arguments for the java command:
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||
# and any embedded shellness will be escaped.
|
||||
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
||||
# treated as '${Hostname}' itself on the command line.
|
||||
|
||||
set -- \
|
||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||
-classpath "$CLASSPATH" \
|
||||
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
|
||||
"$@"
|
||||
|
||||
# Stop when "xargs" is not available.
|
||||
if ! command -v xargs >/dev/null 2>&1
|
||||
then
|
||||
die "xargs is not available"
|
||||
fi
|
||||
|
||||
# Use "xargs" to parse quoted args.
|
||||
#
|
||||
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||
#
|
||||
# In Bash we could simply go:
|
||||
#
|
||||
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
||||
# set -- "${ARGS[@]}" "$@"
|
||||
#
|
||||
# but POSIX shell has neither arrays nor command substitution, so instead we
|
||||
# post-process each arg (as a line of input to sed) to backslash-escape any
|
||||
# character that might be a shell metacharacter, then use eval to reverse
|
||||
# that process (while maintaining the separation between arguments), and wrap
|
||||
# the whole thing up as a single "set" statement.
|
||||
#
|
||||
# This will of course break if any of these variables contains a newline or
|
||||
# an unmatched quote.
|
||||
#
|
||||
|
||||
eval "set -- $(
|
||||
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
||||
xargs -n1 |
|
||||
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
||||
tr '\n' ' '
|
||||
)" '"$@"'
|
||||
|
||||
exec "$JAVACMD" "$@"
|
||||
94
android/gradlew.bat
vendored
|
|
@ -1,94 +0,0 @@
|
|||
@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
|
||||
@rem SPDX-License-Identifier: Apache-2.0
|
||||
@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=.
|
||||
@rem This is normally unused
|
||||
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% equ 0 goto execute
|
||||
|
||||
echo. 1>&2
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
|
||||
echo. 1>&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||
echo location of your Java installation. 1>&2
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo. 1>&2
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
|
||||
echo. 1>&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||
echo location of your Java installation. 1>&2
|
||||
|
||||
goto fail
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if %ERRORLEVEL% equ 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!
|
||||
set EXIT_CODE=%ERRORLEVEL%
|
||||
if %EXIT_CODE% equ 0 set EXIT_CODE=1
|
||||
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
|
||||
exit /b %EXIT_CODE%
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
2
android/proguard-rules.pro
vendored
|
|
@ -12,4 +12,4 @@
|
|||
-dontwarn com.iab.omid.**
|
||||
-keep class com.iab.omid.** {*;}
|
||||
-keepattributes JavascriptInterface
|
||||
-keep class fyi.crt.capacitor.levelplay.** { *; }
|
||||
-keep class com.voxgames.capacitor.levelplay.** { *; }
|
||||
|
|
|
|||
|
|
@ -1,4 +0,0 @@
|
|||
// Standalone build of the plugin library, used by `bun run verify:android` (needs `bun install` first).
|
||||
// Consuming apps do not use this file: `npx cap sync` includes the module from their own settings.
|
||||
include ':capacitor-android'
|
||||
project(':capacitor-android').projectDir = new File('../node_modules/@capacitor/android/capacitor')
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
package fyi.crt.capacitor.levelplay;
|
||||
package com.voxgames.capacitor.levelplay;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import androidx.annotation.NonNull;
|
||||
|
|
@ -19,34 +18,24 @@ import com.unity3d.mediation.LevelPlayInitError;
|
|||
import com.unity3d.mediation.LevelPlayInitListener;
|
||||
import com.unity3d.mediation.LevelPlayInitRequest;
|
||||
import com.unity3d.mediation.LevelPlayPrivacySettings;
|
||||
import com.unity3d.mediation.impression.LevelPlayImpressionDataListener;
|
||||
import com.unity3d.mediation.interstitial.LevelPlayInterstitialAd;
|
||||
import com.unity3d.mediation.interstitial.LevelPlayInterstitialAdListener;
|
||||
import com.unity3d.mediation.rewarded.LevelPlayReward;
|
||||
import com.unity3d.mediation.rewarded.LevelPlayRewardedAd;
|
||||
import com.unity3d.mediation.rewarded.LevelPlayRewardedAdListener;
|
||||
import com.unity3d.mediation.segment.LevelPlaySegment;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.json.JSONArray;
|
||||
|
||||
/**
|
||||
* Capacitor bridge for the Unity LevelPlay SDK (ad-unit API: LevelPlayRewardedAd / LevelPlayInterstitialAd /
|
||||
* LevelPlayBannerAdView, plus LevelPlayNativeAd). Every SDK call and every view operation runs on the main thread;
|
||||
* plugin state is only touched there.
|
||||
* Capacitor bridge for the Unity LevelPlay SDK (ad-unit API: LevelPlayRewardedAd / LevelPlayInterstitialAd).
|
||||
* Rewarded and interstitial only. Every SDK call runs on the main thread; plugin state is only touched there.
|
||||
*/
|
||||
@CapacitorPlugin(name = "LevelPlay")
|
||||
public class LevelPlayPlugin extends Plugin {
|
||||
|
||||
private static final long LATE_REWARD_GRACE_MS = 1000;
|
||||
/** Impressions kept while no JS impressionData listener exists (owner decision Q2); the oldest is dropped. */
|
||||
static final int IMPRESSION_QUEUE_CAP = 100;
|
||||
static final String EVENT_IMPRESSION = "impressionData";
|
||||
|
||||
private enum InitState {
|
||||
IDLE,
|
||||
|
|
@ -59,43 +48,6 @@ public class LevelPlayPlugin extends Plugin {
|
|||
private final List<PluginCall> pendingInits = new ArrayList<>();
|
||||
private final Map<String, RewardedHolder> rewarded = new HashMap<>();
|
||||
private final Map<String, InterstitialHolder> interstitials = new HashMap<>();
|
||||
private final ArrayDeque<JSObject> impressionQueue = new ArrayDeque<>();
|
||||
@Nullable
|
||||
private OverlayHost overlay;
|
||||
private final BannerManager banners = new BannerManager(new BannerManager.Host() {
|
||||
@Nullable
|
||||
@Override
|
||||
public Activity activity() {
|
||||
return getActivity();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public OverlayHost overlay() {
|
||||
return LevelPlayPlugin.this.overlay();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean initialized() {
|
||||
return initState == InitState.DONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void emit(String event, JSObject data) {
|
||||
notifyListeners(event, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LevelPlayImpressionDataListener impressionListener() {
|
||||
return impressionListener;
|
||||
}
|
||||
});
|
||||
|
||||
/** Attached to every rewarded, interstitial and banner object (per-ad listeners, owner decision Q1). */
|
||||
final LevelPlayImpressionDataListener impressionListener = data -> {
|
||||
JSObject o = Mappers.impression(data);
|
||||
main.post(() -> emitImpression(o));
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------------------------- init / settings
|
||||
|
||||
|
|
@ -315,303 +267,6 @@ public class LevelPlayPlugin extends Plugin {
|
|||
});
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------- 0.3.0: capabilities, user
|
||||
|
||||
@PluginMethod
|
||||
public void getCapabilities(PluginCall call) {
|
||||
JSObject r = new JSObject();
|
||||
r.put("banner", true);
|
||||
r.put("nativeAd", true);
|
||||
r.put("nativeAdTemplates", new JSONArray().put("small").put("medium"));
|
||||
r.put("impressionData", true);
|
||||
r.put("adInfoChanged", true);
|
||||
call.resolve(r);
|
||||
}
|
||||
|
||||
@PluginMethod
|
||||
public void setSegment(PluginCall call) {
|
||||
JSObject o = call.getData();
|
||||
LevelPlaySegment segment = new LevelPlaySegment();
|
||||
try {
|
||||
String name = o.getString("segmentName");
|
||||
if (name != null) segment.setSegmentName(name);
|
||||
Number level = number(o, "level");
|
||||
if (level != null) {
|
||||
if (level.doubleValue() != Math.rint(level.doubleValue())) throw CallError.invalid("level must be an integer");
|
||||
segment.setLevel(level.intValue());
|
||||
}
|
||||
if (o.has("isPaying")) {
|
||||
Object paying = o.opt("isPaying");
|
||||
if (!(paying instanceof Boolean)) throw CallError.invalid("isPaying must be a boolean");
|
||||
segment.setPaying((Boolean) paying);
|
||||
}
|
||||
Number created = number(o, "userCreationDate");
|
||||
if (created != null) segment.setUserCreationDate(created.longValue());
|
||||
Number iap = number(o, "iapTotal");
|
||||
if (iap != null) segment.setIapTotal(iap.doubleValue());
|
||||
JSObject custom = o.getJSObject("customParameters");
|
||||
if (custom == null && o.has("customParameters") && !o.isNull("customParameters")) {
|
||||
throw CallError.invalid("customParameters must be an object of strings");
|
||||
}
|
||||
if (custom != null) {
|
||||
Map<String, Object> params = new LinkedHashMap<>();
|
||||
Iterator<String> keys = custom.keys();
|
||||
while (keys.hasNext()) {
|
||||
String k = keys.next();
|
||||
params.put(k, custom.opt(k));
|
||||
}
|
||||
String err = OverlayMath.customParamsError(params);
|
||||
if (err != null) throw CallError.invalid(err);
|
||||
for (Map.Entry<String, Object> e : params.entrySet()) segment.setCustom(e.getKey(), (String) e.getValue());
|
||||
}
|
||||
} catch (CallError e) {
|
||||
reject(call, e);
|
||||
return;
|
||||
}
|
||||
main.post(() -> {
|
||||
LevelPlay.setSegment(segment);
|
||||
call.resolve();
|
||||
});
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static Number number(JSObject o, String key) throws CallError {
|
||||
if (!o.has(key) || o.isNull(key)) return null;
|
||||
Object v = o.opt(key);
|
||||
if (!(v instanceof Number)) throw CallError.invalid(key + " must be a number");
|
||||
double d = ((Number) v).doubleValue();
|
||||
if (Double.isNaN(d) || Double.isInfinite(d)) throw CallError.invalid(key + " must be finite");
|
||||
return (Number) v;
|
||||
}
|
||||
|
||||
@PluginMethod
|
||||
public void setDynamicUserId(PluginCall call) {
|
||||
String userId = call.getString("userId");
|
||||
if (userId == null || userId.isEmpty()) {
|
||||
call.reject("userId is required", "INVALID_ARGUMENT");
|
||||
return;
|
||||
}
|
||||
main.post(() -> {
|
||||
JSObject r = new JSObject();
|
||||
r.put("valid", LevelPlay.setDynamicUserId(userId));
|
||||
call.resolve(r);
|
||||
});
|
||||
}
|
||||
|
||||
@PluginMethod
|
||||
public void isPlacementCapped(PluginCall call) {
|
||||
String format = call.getString("format");
|
||||
String placement = call.getString("placementName");
|
||||
if (!"rewarded".equals(format) && !"interstitial".equals(format)) {
|
||||
call.reject("format must be 'rewarded' or 'interstitial'", "INVALID_ARGUMENT");
|
||||
return;
|
||||
}
|
||||
if (placement == null || placement.isEmpty()) {
|
||||
call.reject("placementName is required", "INVALID_ARGUMENT");
|
||||
return;
|
||||
}
|
||||
main.post(() -> {
|
||||
boolean capped = "interstitial".equals(format)
|
||||
? LevelPlayInterstitialAd.isPlacementCapped(placement)
|
||||
: LevelPlayRewardedAd.isPlacementCapped(placement);
|
||||
JSObject r = new JSObject();
|
||||
r.put("capped", capped);
|
||||
call.resolve(r);
|
||||
});
|
||||
}
|
||||
|
||||
@PluginMethod
|
||||
public void getReward(PluginCall call) {
|
||||
String adUnitId = requireAdUnit(call);
|
||||
if (adUnitId == null) return;
|
||||
String placement = call.getString("placementName");
|
||||
main.post(() -> {
|
||||
LevelPlayRewardedAd ad = rewardedHolder(adUnitId).ad;
|
||||
LevelPlayReward r = placement != null && !placement.isEmpty() ? ad.getReward(placement) : ad.getReward();
|
||||
call.resolve(Mappers.reward(r));
|
||||
});
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------- 0.3.0: banners
|
||||
|
||||
@PluginMethod
|
||||
public void createBanner(PluginCall call) {
|
||||
JSObject o = call.getData();
|
||||
onMain(call, () -> call.resolve(banners.create(o)));
|
||||
}
|
||||
|
||||
@PluginMethod
|
||||
public void loadBanner(PluginCall call) {
|
||||
String id = call.getString("bannerId");
|
||||
onMain(call, () -> {
|
||||
banners.load(id);
|
||||
call.resolve();
|
||||
});
|
||||
}
|
||||
|
||||
@PluginMethod
|
||||
public void showBanner(PluginCall call) {
|
||||
String id = call.getString("bannerId");
|
||||
onMain(call, () -> call.resolve(banners.show(id)));
|
||||
}
|
||||
|
||||
@PluginMethod
|
||||
public void hideBanner(PluginCall call) {
|
||||
String id = call.getString("bannerId");
|
||||
onMain(call, () -> {
|
||||
banners.hide(id);
|
||||
call.resolve();
|
||||
});
|
||||
}
|
||||
|
||||
@PluginMethod
|
||||
public void setBannerLayout(PluginCall call) {
|
||||
JSObject o = call.getData();
|
||||
onMain(call, () -> call.resolve(banners.setLayout(o)));
|
||||
}
|
||||
|
||||
@PluginMethod
|
||||
public void destroyBanner(PluginCall call) {
|
||||
String id = call.getString("bannerId");
|
||||
onMain(call, () -> {
|
||||
banners.destroy(id);
|
||||
call.resolve();
|
||||
});
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------- 0.3.0: native ads
|
||||
|
||||
private final NativeAdManager nativeAds = new NativeAdManager(new NativeAdManager.Host() {
|
||||
@Nullable
|
||||
@Override
|
||||
public Activity activity() {
|
||||
return getActivity();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public OverlayHost overlay() {
|
||||
return LevelPlayPlugin.this.overlay();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean initialized() {
|
||||
return initState == InitState.DONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void emit(String event, JSObject data) {
|
||||
notifyListeners(event, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void impression(JSObject data) {
|
||||
emitImpression(data);
|
||||
}
|
||||
});
|
||||
|
||||
@PluginMethod
|
||||
public void loadNativeAd(PluginCall call) {
|
||||
JSObject o = call.getData();
|
||||
onMain(call, () -> {
|
||||
nativeAds.load(o);
|
||||
call.resolve();
|
||||
});
|
||||
}
|
||||
|
||||
@PluginMethod
|
||||
public void showNativeAd(PluginCall call) {
|
||||
String id = call.getString("nativeAdId");
|
||||
JSObject rect = call.getObject("rect");
|
||||
onMain(call, () -> {
|
||||
nativeAds.show(id, rect);
|
||||
call.resolve();
|
||||
});
|
||||
}
|
||||
|
||||
@PluginMethod
|
||||
public void setNativeAdRect(PluginCall call) {
|
||||
String id = call.getString("nativeAdId");
|
||||
JSObject rect = call.getObject("rect");
|
||||
onMain(call, () -> {
|
||||
nativeAds.setRect(id, rect);
|
||||
call.resolve();
|
||||
});
|
||||
}
|
||||
|
||||
@PluginMethod
|
||||
public void hideNativeAd(PluginCall call) {
|
||||
String id = call.getString("nativeAdId");
|
||||
onMain(call, () -> {
|
||||
nativeAds.hide(id);
|
||||
call.resolve();
|
||||
});
|
||||
}
|
||||
|
||||
@PluginMethod
|
||||
public void destroyNativeAd(PluginCall call) {
|
||||
String id = call.getString("nativeAdId");
|
||||
onMain(call, () -> {
|
||||
nativeAds.destroy(id);
|
||||
call.resolve();
|
||||
});
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------- overlay, lifecycle
|
||||
|
||||
/** Main thread. The pass-through overlay above the WebView, attached on first use (design §6.2). */
|
||||
@Nullable
|
||||
private OverlayHost overlay() {
|
||||
if (overlay == null && bridge != null) overlay = OverlayHost.attach(bridge.getWebView(), this::onOverlayLayoutChanged);
|
||||
return overlay;
|
||||
}
|
||||
|
||||
private void onOverlayLayoutChanged() {
|
||||
if (overlay == null) return;
|
||||
banners.onLayoutChanged(overlay);
|
||||
nativeAds.onLayoutChanged(overlay);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleOnConfigurationChanged(Configuration newConfig) {
|
||||
super.handleOnConfigurationChanged(newConfig);
|
||||
main.post(() -> {
|
||||
if (overlay != null) overlay.postRelayout();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleOnDestroy() {
|
||||
super.handleOnDestroy();
|
||||
Runnable cleanup = () -> {
|
||||
banners.destroyAll();
|
||||
nativeAds.destroyAll();
|
||||
if (overlay != null) {
|
||||
overlay.detach();
|
||||
overlay = null;
|
||||
}
|
||||
};
|
||||
if (Looper.myLooper() == Looper.getMainLooper()) cleanup.run();
|
||||
else main.post(cleanup);
|
||||
}
|
||||
|
||||
private interface MainTask {
|
||||
void run() throws CallError;
|
||||
}
|
||||
|
||||
/** Runs on the main thread; a CallError rejects the call with its code. */
|
||||
private void onMain(PluginCall call, MainTask task) {
|
||||
main.post(() -> {
|
||||
try {
|
||||
task.run();
|
||||
} catch (CallError e) {
|
||||
reject(call, e);
|
||||
} catch (RuntimeException e) {
|
||||
call.reject(e.getMessage() != null ? e.getMessage() : e.toString(), "ERROR", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------- helpers
|
||||
|
||||
@Nullable
|
||||
|
|
@ -642,45 +297,35 @@ public class LevelPlayPlugin extends Plugin {
|
|||
}
|
||||
|
||||
private static JSObject info(@Nullable LevelPlayAdInfo i) {
|
||||
return Mappers.adInfo(i);
|
||||
JSObject o = new JSObject();
|
||||
if (i == null) return o;
|
||||
o.put("adId", i.getAdId());
|
||||
o.put("adUnitId", i.getAdUnitId());
|
||||
o.put("adUnitName", i.getAdUnitName());
|
||||
o.put("adFormat", i.getAdFormat());
|
||||
o.put("placementName", i.getPlacementName());
|
||||
o.put("adNetwork", i.getAdNetwork());
|
||||
o.put("instanceName", i.getInstanceName());
|
||||
o.put("instanceId", i.getInstanceId());
|
||||
o.put("country", i.getCountry());
|
||||
o.put("auctionId", i.getAuctionId());
|
||||
o.put("precision", i.getPrecision());
|
||||
o.put("revenue", i.getRevenue());
|
||||
return o;
|
||||
}
|
||||
|
||||
private static JSObject error(int code, String message) {
|
||||
return Mappers.error(code, message);
|
||||
JSObject e = new JSObject();
|
||||
e.put("code", code);
|
||||
e.put("message", message);
|
||||
return e;
|
||||
}
|
||||
|
||||
private static JSObject reward(LevelPlayReward r) {
|
||||
return Mappers.reward(r);
|
||||
}
|
||||
|
||||
static void reject(PluginCall call, CallError e) {
|
||||
call.reject(e.getMessage(), e.code);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------- impression data
|
||||
|
||||
/** Main thread. Sends directly when a JS listener exists, otherwise queues (capped). */
|
||||
private void emitImpression(JSObject o) {
|
||||
if (hasListeners(EVENT_IMPRESSION)) {
|
||||
notifyListeners(EVENT_IMPRESSION, o);
|
||||
return;
|
||||
}
|
||||
impressionQueue.addLast(o);
|
||||
while (impressionQueue.size() > IMPRESSION_QUEUE_CAP) impressionQueue.removeFirst();
|
||||
}
|
||||
|
||||
private void flushImpressions() {
|
||||
while (!impressionQueue.isEmpty() && hasListeners(EVENT_IMPRESSION)) {
|
||||
notifyListeners(EVENT_IMPRESSION, impressionQueue.removeFirst());
|
||||
}
|
||||
}
|
||||
|
||||
/** Same as Plugin.addListener, then flushes impressions queued before the first impressionData listener. */
|
||||
@Override
|
||||
@PluginMethod(returnType = PluginMethod.RETURN_NONE)
|
||||
public void addListener(PluginCall call) {
|
||||
super.addListener(call);
|
||||
if (EVENT_IMPRESSION.equals(call.getString("eventName"))) main.post(this::flushImpressions);
|
||||
JSObject o = new JSObject();
|
||||
o.put("name", r.getName());
|
||||
o.put("amount", r.getAmount());
|
||||
return o;
|
||||
}
|
||||
|
||||
private JSObject event(String format, String adUnitId, @Nullable LevelPlayAdInfo adInfo) {
|
||||
|
|
@ -706,7 +351,6 @@ public class LevelPlayPlugin extends Plugin {
|
|||
this.adUnitId = adUnitId;
|
||||
this.ad = new LevelPlayRewardedAd(adUnitId);
|
||||
this.ad.setListener(this);
|
||||
this.ad.setImpressionDataListener(impressionListener);
|
||||
}
|
||||
|
||||
void begin(PluginCall c) {
|
||||
|
|
@ -792,9 +436,7 @@ public class LevelPlayPlugin extends Plugin {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onAdInfoChanged(@NonNull LevelPlayAdInfo adInfo) {
|
||||
main.post(() -> notifyListeners("adInfoChanged", event("rewarded", adUnitId, adInfo)));
|
||||
}
|
||||
public void onAdInfoChanged(@NonNull LevelPlayAdInfo adInfo) {}
|
||||
}
|
||||
|
||||
private final class InterstitialHolder implements LevelPlayInterstitialAdListener {
|
||||
|
|
@ -809,7 +451,6 @@ public class LevelPlayPlugin extends Plugin {
|
|||
this.adUnitId = adUnitId;
|
||||
this.ad = new LevelPlayInterstitialAd(adUnitId);
|
||||
this.ad.setListener(this);
|
||||
this.ad.setImpressionDataListener(impressionListener);
|
||||
}
|
||||
|
||||
void begin(PluginCall c) {
|
||||
|
|
@ -879,8 +520,6 @@ public class LevelPlayPlugin extends Plugin {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onAdInfoChanged(@NonNull LevelPlayAdInfo adInfo) {
|
||||
main.post(() -> notifyListeners("adInfoChanged", event("interstitial", adUnitId, adInfo)));
|
||||
}
|
||||
public void onAdInfoChanged(@NonNull LevelPlayAdInfo adInfo) {}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,405 +0,0 @@
|
|||
package fyi.crt.capacitor.levelplay;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.view.View;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.getcapacitor.JSObject;
|
||||
import com.unity3d.mediation.LevelPlayAdError;
|
||||
import com.unity3d.mediation.LevelPlayAdInfo;
|
||||
import com.unity3d.mediation.LevelPlayAdSize;
|
||||
import com.unity3d.mediation.banner.LevelPlayBannerAdView;
|
||||
import com.unity3d.mediation.banner.LevelPlayBannerAdViewListener;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Banners (design §3, §6): LevelPlayBannerAdView instances keyed by bannerId, laid out in the OverlayHost.
|
||||
* Main thread only; SDK callbacks are re-posted to the main thread.
|
||||
*/
|
||||
final class BannerManager {
|
||||
|
||||
interface Host {
|
||||
@Nullable
|
||||
Activity activity();
|
||||
|
||||
/** The overlay, attached on first use; null when the WebView has no parent. */
|
||||
@Nullable
|
||||
OverlayHost overlay();
|
||||
|
||||
boolean initialized();
|
||||
|
||||
void emit(String event, JSObject data);
|
||||
|
||||
com.unity3d.mediation.impression.LevelPlayImpressionDataListener impressionListener();
|
||||
}
|
||||
|
||||
/** Owner decision Q4: adaptive banners follow safe-area width changes after the layout settled. */
|
||||
private static final long ADAPTIVE_RECREATE_DELAY_MS = 250;
|
||||
|
||||
private final Host host;
|
||||
private final Handler main = new Handler(Looper.getMainLooper());
|
||||
private final Map<String, Slot> slots = new LinkedHashMap<>();
|
||||
private final Runnable adaptiveCheck = this::recreateChangedAdaptive;
|
||||
|
||||
BannerManager(Host host) {
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
private static final class Slot {
|
||||
|
||||
final String bannerId;
|
||||
final String adUnitId;
|
||||
final String size;
|
||||
@Nullable
|
||||
final Integer fixedAdaptiveWidth;
|
||||
final int customWidth;
|
||||
final int customHeight;
|
||||
@Nullable
|
||||
final String placementName;
|
||||
@Nullable
|
||||
final Double bidFloor;
|
||||
String position = "bottom";
|
||||
double offsetX;
|
||||
double offsetY;
|
||||
boolean respectSafeArea = true;
|
||||
|
||||
LevelPlayBannerAdView view;
|
||||
LevelPlayAdSize adSize;
|
||||
/** CSS px width the adaptive size was computed for. */
|
||||
int adaptiveWidthUsed;
|
||||
boolean visible;
|
||||
boolean loadRequested;
|
||||
double[] frame = OverlayMath.rect(0, 0, 0, 0);
|
||||
|
||||
Slot(
|
||||
String bannerId,
|
||||
String adUnitId,
|
||||
String size,
|
||||
@Nullable Integer fixedAdaptiveWidth,
|
||||
int customWidth,
|
||||
int customHeight,
|
||||
@Nullable String placementName,
|
||||
@Nullable Double bidFloor
|
||||
) {
|
||||
this.bannerId = bannerId;
|
||||
this.adUnitId = adUnitId;
|
||||
this.size = size;
|
||||
this.fixedAdaptiveWidth = fixedAdaptiveWidth;
|
||||
this.customWidth = customWidth;
|
||||
this.customHeight = customHeight;
|
||||
this.placementName = placementName;
|
||||
this.bidFloor = bidFloor;
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------- API
|
||||
|
||||
JSObject create(JSObject o) throws CallError {
|
||||
String adUnitId = o.getString("adUnitId");
|
||||
if (adUnitId == null || adUnitId.isEmpty()) throw CallError.invalid("adUnitId is required");
|
||||
String bannerId = nonEmpty(o.getString("bannerId"), adUnitId);
|
||||
JSObject custom = o.getJSObject("customSize");
|
||||
String size = o.getString("size");
|
||||
if (size == null) size = custom != null ? "CUSTOM" : "ADAPTIVE";
|
||||
if (!OverlayMath.isBannerSize(size)) throw CallError.invalid("Unknown banner size '" + size + "'");
|
||||
int cw = 0, ch = 0;
|
||||
if ("CUSTOM".equals(size)) {
|
||||
if (custom == null) throw CallError.invalid("size CUSTOM needs customSize { width, height }");
|
||||
cw = positiveInt(custom, "customSize.width", "width");
|
||||
ch = positiveInt(custom, "customSize.height", "height");
|
||||
}
|
||||
Integer fixedWidth = null;
|
||||
if (o.has("adaptiveWidth") && !o.isNull("adaptiveWidth")) {
|
||||
fixedWidth = positiveInt(o, "adaptiveWidth", "adaptiveWidth");
|
||||
}
|
||||
Double bidFloor = null;
|
||||
if (o.has("bidFloor") && !o.isNull("bidFloor")) {
|
||||
Object v = o.opt("bidFloor");
|
||||
if (!(v instanceof Number) || ((Number) v).doubleValue() < 0) throw CallError.invalid("bidFloor must be a number >= 0");
|
||||
bidFloor = ((Number) v).doubleValue();
|
||||
}
|
||||
String placement = o.getString("placementName");
|
||||
if (placement != null && placement.isEmpty()) placement = null;
|
||||
|
||||
Slot s = new Slot(bannerId, adUnitId, size, fixedWidth, cw, ch, placement, bidFloor);
|
||||
applyLayout(s, o);
|
||||
|
||||
if (!host.initialized()) throw new CallError("NOT_INITIALIZED", "Call initialize() and wait for it before createBanner()");
|
||||
if (slots.containsKey(bannerId)) throw new CallError("ALREADY_EXISTS", "Banner '" + bannerId + "' already exists; destroy it first");
|
||||
Activity activity = host.activity();
|
||||
if (activity == null) throw new CallError("NO_ACTIVITY", "No activity to attach the banner to");
|
||||
OverlayHost overlay = host.overlay();
|
||||
if (overlay == null) throw new CallError("NO_ACTIVITY", "The WebView is not attached to a view hierarchy");
|
||||
|
||||
buildView(s, activity, overlay);
|
||||
slots.put(bannerId, s);
|
||||
relayout(s, overlay);
|
||||
return result(s);
|
||||
}
|
||||
|
||||
void load(String bannerId) throws CallError {
|
||||
Slot s = require(bannerId);
|
||||
s.loadRequested = true;
|
||||
s.view.loadAd();
|
||||
}
|
||||
|
||||
JSObject show(String bannerId) throws CallError {
|
||||
Slot s = require(bannerId);
|
||||
OverlayHost overlay = host.overlay();
|
||||
s.visible = true;
|
||||
s.view.setVisibility(View.VISIBLE);
|
||||
s.view.bringToFront();
|
||||
s.view.resumeAutoRefresh();
|
||||
if (overlay != null) relayout(s, overlay);
|
||||
return result(s);
|
||||
}
|
||||
|
||||
void hide(String bannerId) {
|
||||
Slot s = slots.get(bannerId);
|
||||
if (s == null) return;
|
||||
s.visible = false;
|
||||
s.view.setVisibility(View.GONE);
|
||||
s.view.pauseAutoRefresh();
|
||||
}
|
||||
|
||||
JSObject setLayout(JSObject o) throws CallError {
|
||||
Slot s = require(o.getString("bannerId"));
|
||||
applyLayout(s, o);
|
||||
OverlayHost overlay = host.overlay();
|
||||
if (overlay != null) relayout(s, overlay);
|
||||
return result(s);
|
||||
}
|
||||
|
||||
void destroy(String bannerId) {
|
||||
Slot s = slots.remove(bannerId);
|
||||
if (s != null) destroyView(s);
|
||||
}
|
||||
|
||||
void destroyAll() {
|
||||
main.removeCallbacks(adaptiveCheck);
|
||||
for (Slot s : new ArrayList<>(slots.values())) destroyView(s);
|
||||
slots.clear();
|
||||
}
|
||||
|
||||
boolean isEmpty() {
|
||||
return slots.isEmpty();
|
||||
}
|
||||
|
||||
/** Overlay layout pass: re-place every banner and schedule the adaptive width check (Q4). */
|
||||
void onLayoutChanged(OverlayHost overlay) {
|
||||
boolean adaptiveChanged = false;
|
||||
for (Slot s : slots.values()) {
|
||||
relayout(s, overlay);
|
||||
if (followsWidth(s) && currentAdaptiveWidth(s, overlay) != s.adaptiveWidthUsed) adaptiveChanged = true;
|
||||
}
|
||||
main.removeCallbacks(adaptiveCheck);
|
||||
if (adaptiveChanged) main.postDelayed(adaptiveCheck, ADAPTIVE_RECREATE_DELAY_MS);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------- internals
|
||||
|
||||
private Slot require(@Nullable String bannerId) throws CallError {
|
||||
if (bannerId == null || bannerId.isEmpty()) throw CallError.invalid("bannerId is required");
|
||||
Slot s = slots.get(bannerId);
|
||||
if (s == null) throw CallError.notFound("Banner", bannerId);
|
||||
return s;
|
||||
}
|
||||
|
||||
private static void applyLayout(Slot s, JSObject o) throws CallError {
|
||||
if (o.has("position") && !o.isNull("position")) {
|
||||
String p = o.getString("position");
|
||||
if (!OverlayMath.isPosition(p)) throw CallError.invalid("position must be 'top', 'bottom' or 'center'");
|
||||
s.position = p;
|
||||
}
|
||||
if (o.has("offsetX") && !o.isNull("offsetX")) s.offsetX = finite(o, "offsetX");
|
||||
if (o.has("offsetY") && !o.isNull("offsetY")) s.offsetY = finite(o, "offsetY");
|
||||
if (o.has("respectSafeArea") && !o.isNull("respectSafeArea")) {
|
||||
Object v = o.opt("respectSafeArea");
|
||||
if (!(v instanceof Boolean)) throw CallError.invalid("respectSafeArea must be a boolean");
|
||||
s.respectSafeArea = (Boolean) v;
|
||||
}
|
||||
}
|
||||
|
||||
private static double finite(JSObject o, String key) throws CallError {
|
||||
Object v = o.opt(key);
|
||||
if (!(v instanceof Number)) throw CallError.invalid(key + " must be a number");
|
||||
double d = ((Number) v).doubleValue();
|
||||
if (Double.isNaN(d) || Double.isInfinite(d)) throw CallError.invalid(key + " must be finite");
|
||||
return d;
|
||||
}
|
||||
|
||||
private static int positiveInt(JSObject o, String label, String key) throws CallError {
|
||||
Object v = o.opt(key);
|
||||
if (!(v instanceof Number)) throw CallError.invalid(label + " must be a positive number");
|
||||
double d = ((Number) v).doubleValue();
|
||||
if (!(d >= 1) || Double.isInfinite(d)) throw CallError.invalid(label + " must be a positive number");
|
||||
return (int) Math.round(d);
|
||||
}
|
||||
|
||||
private static String nonEmpty(@Nullable String v, String fallback) {
|
||||
return v == null || v.isEmpty() ? fallback : v;
|
||||
}
|
||||
|
||||
private static boolean followsWidth(Slot s) {
|
||||
return "ADAPTIVE".equals(s.size) && s.fixedAdaptiveWidth == null;
|
||||
}
|
||||
|
||||
private static double[] area(Slot s, OverlayHost overlay) {
|
||||
return s.respectSafeArea ? overlay.safeAreaCss() : overlay.webViewCss();
|
||||
}
|
||||
|
||||
private static int currentAdaptiveWidth(Slot s, OverlayHost overlay) {
|
||||
return (int) Math.floor(area(s, overlay)[2]);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private LevelPlayAdSize resolveSize(Slot s, Activity activity, OverlayHost overlay) {
|
||||
switch (s.size) {
|
||||
case "BANNER":
|
||||
return LevelPlayAdSize.BANNER;
|
||||
case "LARGE":
|
||||
return LevelPlayAdSize.LARGE;
|
||||
case "MEDIUM_RECTANGLE":
|
||||
return LevelPlayAdSize.MEDIUM_RECTANGLE;
|
||||
case "LEADERBOARD":
|
||||
return LevelPlayAdSize.LEADERBOARD;
|
||||
case "CUSTOM":
|
||||
return LevelPlayAdSize.createCustomSize(s.customWidth, s.customHeight);
|
||||
default: {
|
||||
// The SDK width unit is dp (bytecode of createAdaptiveAdSize, design §3.2), i.e. CSS px.
|
||||
int width = s.fixedAdaptiveWidth != null ? s.fixedAdaptiveWidth : currentAdaptiveWidth(s, overlay);
|
||||
s.adaptiveWidthUsed = width;
|
||||
return LevelPlayAdSize.createAdaptiveAdSize(activity, width > 0 ? width : null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void buildView(Slot s, Activity activity, OverlayHost overlay) throws CallError {
|
||||
LevelPlayAdSize size = resolveSize(s, activity, overlay);
|
||||
if (size == null) throw new CallError("NOT_INITIALIZED", "The SDK returned no adaptive size (initialize() not finished)");
|
||||
LevelPlayBannerAdView.Config.Builder b = new LevelPlayBannerAdView.Config.Builder().setAdSize(size);
|
||||
if (s.bidFloor != null) b.setBidFloor(s.bidFloor);
|
||||
if (s.placementName != null) b.setPlacementName(s.placementName);
|
||||
LevelPlayBannerAdView v = new LevelPlayBannerAdView(activity, s.adUnitId, b.build());
|
||||
v.setBannerListener(new Listener(s, v));
|
||||
v.setImpressionDataListener(host.impressionListener());
|
||||
v.setVisibility(s.visible ? View.VISIBLE : View.GONE);
|
||||
s.view = v;
|
||||
s.adSize = size;
|
||||
overlay.add(v);
|
||||
}
|
||||
|
||||
private void relayout(Slot s, OverlayHost overlay) {
|
||||
s.frame = OverlayMath.bannerFrame(area(s, overlay), s.adSize.getWidth(), s.adSize.getHeight(), s.position, s.offsetX, s.offsetY);
|
||||
overlay.place(s.view, s.frame);
|
||||
}
|
||||
|
||||
private void destroyView(Slot s) {
|
||||
OverlayHost overlay = host.overlay();
|
||||
s.view.destroy();
|
||||
if (overlay != null) overlay.remove(s.view);
|
||||
}
|
||||
|
||||
/** Q4: recreate adaptive banners whose safe-area width changed; keeps id, layout, visibility; reloads if loaded. */
|
||||
private void recreateChangedAdaptive() {
|
||||
Activity activity = host.activity();
|
||||
OverlayHost overlay = host.overlay();
|
||||
if (activity == null || overlay == null) return;
|
||||
for (Slot s : slots.values()) {
|
||||
if (!followsWidth(s) || currentAdaptiveWidth(s, overlay) == s.adaptiveWidthUsed) continue;
|
||||
if (currentAdaptiveWidth(s, overlay) <= 0) continue;
|
||||
destroyView(s);
|
||||
try {
|
||||
buildView(s, activity, overlay);
|
||||
} catch (CallError e) {
|
||||
continue;
|
||||
}
|
||||
relayout(s, overlay);
|
||||
if (s.loadRequested) s.view.loadAd();
|
||||
if (!s.visible) s.view.pauseAutoRefresh();
|
||||
}
|
||||
}
|
||||
|
||||
private JSObject result(Slot s) {
|
||||
JSObject r = new JSObject();
|
||||
r.put("bannerId", s.bannerId);
|
||||
r.put("adSize", Mappers.adSize(s.adSize));
|
||||
r.put("frame", Mappers.rect(s.frame));
|
||||
r.put("visible", s.visible);
|
||||
return r;
|
||||
}
|
||||
|
||||
private JSObject event(Slot s, @Nullable LevelPlayAdInfo info) {
|
||||
JSObject o = new JSObject();
|
||||
o.put("bannerId", s.bannerId);
|
||||
o.put("adUnitId", s.adUnitId);
|
||||
if (info != null) o.put("adInfo", Mappers.adInfo(info));
|
||||
o.put("frame", Mappers.rect(s.frame));
|
||||
return o;
|
||||
}
|
||||
|
||||
/** One listener per view: callbacks of a view that was replaced (Q4) or destroyed are dropped. */
|
||||
private final class Listener implements LevelPlayBannerAdViewListener {
|
||||
|
||||
private final Slot slot;
|
||||
private final LevelPlayBannerAdView view;
|
||||
|
||||
Listener(Slot slot, LevelPlayBannerAdView view) {
|
||||
this.slot = slot;
|
||||
this.view = view;
|
||||
}
|
||||
|
||||
private void post(String name, @Nullable LevelPlayAdInfo info, @Nullable LevelPlayAdError error) {
|
||||
main.post(() -> {
|
||||
if (slot.view != view || slots.get(slot.bannerId) != slot) return;
|
||||
JSObject o = event(slot, info);
|
||||
if (error != null) o.put("error", Mappers.error(error.getErrorCode(), error.getErrorMessage()));
|
||||
host.emit(name, o);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAdLoaded(@NonNull LevelPlayAdInfo adInfo) {
|
||||
post("bannerLoaded", adInfo, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAdLoadFailed(@NonNull LevelPlayAdError error) {
|
||||
post("bannerLoadFailed", null, error);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAdDisplayed(@NonNull LevelPlayAdInfo adInfo) {
|
||||
post("bannerDisplayed", adInfo, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAdDisplayFailed(@NonNull LevelPlayAdInfo adInfo, @NonNull LevelPlayAdError error) {
|
||||
post("bannerDisplayFailed", adInfo, error);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAdClicked(@NonNull LevelPlayAdInfo adInfo) {
|
||||
post("bannerClicked", adInfo, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAdExpanded(@NonNull LevelPlayAdInfo adInfo) {
|
||||
post("bannerExpanded", adInfo, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAdCollapsed(@NonNull LevelPlayAdInfo adInfo) {
|
||||
post("bannerCollapsed", adInfo, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAdLeftApplication(@NonNull LevelPlayAdInfo adInfo) {
|
||||
post("bannerLeftApplication", adInfo, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
package fyi.crt.capacitor.levelplay;
|
||||
|
||||
/** A promise rejection with one of the plugin's string codes (INVALID_ARGUMENT, NOT_FOUND ...). */
|
||||
final class CallError extends Exception {
|
||||
|
||||
final String code;
|
||||
|
||||
CallError(String code, String message) {
|
||||
super(message);
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
static CallError invalid(String message) {
|
||||
return new CallError("INVALID_ARGUMENT", message);
|
||||
}
|
||||
|
||||
static CallError notFound(String what, String id) {
|
||||
return new CallError("NOT_FOUND", what + " '" + id + "' not found");
|
||||
}
|
||||
}
|
||||
|
|
@ -1,117 +0,0 @@
|
|||
package fyi.crt.capacitor.levelplay;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import com.getcapacitor.JSObject;
|
||||
import com.ironsource.mediationsdk.adunit.adapter.utility.AdInfo;
|
||||
import com.unity3d.mediation.LevelPlayAdInfo;
|
||||
import com.unity3d.mediation.LevelPlayAdSize;
|
||||
import com.unity3d.mediation.impression.LevelPlayImpressionData;
|
||||
import com.unity3d.mediation.rewarded.LevelPlayReward;
|
||||
|
||||
/** SDK objects to the JSON shapes of src/definitions.ts. Null SDK values are omitted (JSONObject.put(k, null) removes k). */
|
||||
final class Mappers {
|
||||
|
||||
private Mappers() {}
|
||||
|
||||
static JSObject adInfo(@Nullable LevelPlayAdInfo i) {
|
||||
JSObject o = new JSObject();
|
||||
if (i == null) return o;
|
||||
o.put("adId", i.getAdId());
|
||||
o.put("adUnitId", i.getAdUnitId());
|
||||
o.put("adUnitName", i.getAdUnitName());
|
||||
o.put("adFormat", i.getAdFormat());
|
||||
o.put("placementName", i.getPlacementName());
|
||||
o.put("adNetwork", i.getAdNetwork());
|
||||
o.put("instanceName", i.getInstanceName());
|
||||
o.put("instanceId", i.getInstanceId());
|
||||
o.put("country", i.getCountry());
|
||||
o.put("auctionId", i.getAuctionId());
|
||||
o.put("precision", i.getPrecision());
|
||||
o.put("revenue", i.getRevenue());
|
||||
o.put("ab", i.getAb());
|
||||
o.put("segmentName", i.getSegmentName());
|
||||
o.put("encryptedCPM", i.getEncryptedCPM());
|
||||
o.put("creativeId", i.getCreativeId());
|
||||
LevelPlayAdSize size = i.getAdSize();
|
||||
if (size != null) o.put("adSize", adSize(size));
|
||||
return o;
|
||||
}
|
||||
|
||||
static JSObject adSize(LevelPlayAdSize s) {
|
||||
JSObject o = new JSObject();
|
||||
o.put("width", s.getWidth());
|
||||
o.put("height", s.getHeight());
|
||||
o.put("description", s.getDescription());
|
||||
o.put("isAdaptive", s.isAdaptive());
|
||||
return o;
|
||||
}
|
||||
|
||||
static JSObject impression(LevelPlayImpressionData d) {
|
||||
JSObject o = new JSObject();
|
||||
o.put("adFormat", d.getAdFormat());
|
||||
o.put("auctionId", d.getAuctionId());
|
||||
o.put("adUnitId", d.getMediationAdUnitId());
|
||||
o.put("adUnitName", d.getMediationAdUnitName());
|
||||
o.put("adNetwork", d.getAdNetwork());
|
||||
o.put("instanceName", d.getInstanceName());
|
||||
o.put("instanceId", d.getInstanceId());
|
||||
o.put("country", d.getCountry());
|
||||
o.put("placement", d.getPlacement());
|
||||
Double revenue = d.getRevenue();
|
||||
if (revenue != null) o.put("revenue", revenue.doubleValue());
|
||||
o.put("precision", d.getPrecision());
|
||||
o.put("ab", d.getAb());
|
||||
o.put("segmentName", d.getSegmentName());
|
||||
o.put("encryptedCPM", d.getEncryptedCPM());
|
||||
o.put("creativeId", d.getCreativeId());
|
||||
if (d.getAllData() != null) o.put("allData", d.getAllData());
|
||||
return o;
|
||||
}
|
||||
|
||||
/** Native ads use the older ironSource AdInfo (no ad unit, ad id or placement). */
|
||||
static JSObject nativeAdInfo(@Nullable AdInfo i) {
|
||||
JSObject o = new JSObject();
|
||||
if (i == null) return o;
|
||||
o.put("auctionId", i.getAuctionId());
|
||||
o.put("adNetwork", i.getAdNetwork());
|
||||
o.put("instanceName", i.getInstanceName());
|
||||
o.put("instanceId", i.getInstanceId());
|
||||
o.put("country", i.getCountry());
|
||||
o.put("revenue", i.getRevenue());
|
||||
o.put("precision", i.getPrecision());
|
||||
o.put("ab", i.getAb());
|
||||
o.put("segmentName", i.getSegmentName());
|
||||
o.put("encryptedCPM", i.getEncryptedCPM());
|
||||
return o;
|
||||
}
|
||||
|
||||
/** impressionData synthesised from a native ad impression (no per-ad impression listener for native ads in 9.6.1). */
|
||||
static JSObject nativeImpression(@Nullable AdInfo i) {
|
||||
JSObject o = nativeAdInfo(i);
|
||||
o.put("adFormat", "nativead");
|
||||
return o;
|
||||
}
|
||||
|
||||
static JSObject error(int code, @Nullable String message) {
|
||||
JSObject e = new JSObject();
|
||||
e.put("code", code);
|
||||
e.put("message", message != null ? message : "");
|
||||
return e;
|
||||
}
|
||||
|
||||
static JSObject reward(@Nullable LevelPlayReward r) {
|
||||
JSObject o = new JSObject();
|
||||
o.put("name", r != null && r.getName() != null ? r.getName() : "");
|
||||
o.put("amount", r != null ? r.getAmount() : 0);
|
||||
return o;
|
||||
}
|
||||
|
||||
static JSObject rect(double[] r) {
|
||||
JSObject o = new JSObject();
|
||||
o.put("x", r[0]);
|
||||
o.put("y", r[1]);
|
||||
o.put("width", r[2]);
|
||||
o.put("height", r[3]);
|
||||
return o;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,254 +0,0 @@
|
|||
package fyi.crt.capacitor.levelplay;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.view.View;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.getcapacitor.JSObject;
|
||||
import com.ironsource.mediationsdk.ads.nativead.LevelPlayNativeAd;
|
||||
import com.ironsource.mediationsdk.ads.nativead.LevelPlayNativeAdListener;
|
||||
import com.ironsource.mediationsdk.ads.nativead.NativeAdLayout;
|
||||
import com.ironsource.mediationsdk.adunit.adapter.utility.AdInfo;
|
||||
import com.ironsource.mediationsdk.logger.IronSourceError;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Native ads (design §4): one LevelPlayNativeAd per load and slot, rendered into the plugin's templates and placed in
|
||||
* the OverlayHost at a WebView-local CSS rect. Main thread only; SDK callbacks are re-posted to the main thread.
|
||||
*/
|
||||
final class NativeAdManager {
|
||||
|
||||
interface Host {
|
||||
@Nullable
|
||||
Activity activity();
|
||||
|
||||
@Nullable
|
||||
OverlayHost overlay();
|
||||
|
||||
boolean initialized();
|
||||
|
||||
void emit(String event, JSObject data);
|
||||
|
||||
/** impressionData synthesised from the native ad info (no per-ad impression listener for native ads). */
|
||||
void impression(JSObject data);
|
||||
}
|
||||
|
||||
private final Host host;
|
||||
private final Handler main = new Handler(Looper.getMainLooper());
|
||||
private final Map<String, Slot> slots = new LinkedHashMap<>();
|
||||
|
||||
NativeAdManager(Host host) {
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
private static final class Slot {
|
||||
|
||||
final String id;
|
||||
@Nullable
|
||||
final String placementName;
|
||||
final String template;
|
||||
final NativeAdStyle style;
|
||||
@Nullable
|
||||
LevelPlayNativeAd ad;
|
||||
boolean loaded;
|
||||
@Nullable
|
||||
NativeAdLayout view;
|
||||
@Nullable
|
||||
double[] rect;
|
||||
boolean visible;
|
||||
|
||||
Slot(String id, @Nullable String placementName, String template, NativeAdStyle style) {
|
||||
this.id = id;
|
||||
this.placementName = placementName;
|
||||
this.template = template;
|
||||
this.style = style;
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------- API
|
||||
|
||||
void load(JSObject o) throws CallError {
|
||||
String id = requireId(o.getString("nativeAdId"));
|
||||
String template = o.getString("template", "medium");
|
||||
if (!"small".equals(template) && !"medium".equals(template)) {
|
||||
throw new CallError("UNSUPPORTED", "Template '" + template + "' is not supported (small, medium)");
|
||||
}
|
||||
NativeAdStyle style = NativeAdStyle.parse(o.getJSObject("style"));
|
||||
String placement = o.getString("placementName");
|
||||
if (placement != null && placement.isEmpty()) placement = null;
|
||||
if (!host.initialized()) throw new CallError("NOT_INITIALIZED", "Call initialize() and wait for it before loadNativeAd()");
|
||||
Activity activity = host.activity();
|
||||
if (activity == null) throw new CallError("NO_ACTIVITY", "No activity to load the native ad with");
|
||||
|
||||
// "Destroy the ad object and create a new one for every new load" (Unity).
|
||||
Slot old = slots.remove(id);
|
||||
if (old != null) destroySlot(old);
|
||||
|
||||
Slot s = new Slot(id, placement, template, style);
|
||||
LevelPlayNativeAd.Builder b = new LevelPlayNativeAd.Builder().withActivity(activity).withListener(new Listener(s));
|
||||
if (placement != null) b.withPlacementName(placement);
|
||||
s.ad = b.build();
|
||||
slots.put(id, s);
|
||||
s.ad.loadAd();
|
||||
}
|
||||
|
||||
void show(String nativeAdId, @Nullable JSObject rect) throws CallError {
|
||||
Slot s = require(nativeAdId);
|
||||
double[] r = parseRect(rect);
|
||||
if (!s.loaded || s.ad == null) throw new CallError("NOT_LOADED", "Native ad '" + nativeAdId + "' is not loaded");
|
||||
OverlayHost overlay = host.overlay();
|
||||
Activity activity = host.activity();
|
||||
if (overlay == null || activity == null) throw new CallError("NO_ACTIVITY", "No activity / WebView to show the native ad in");
|
||||
if (s.view == null) {
|
||||
s.view = NativeAdTemplate.build(activity, s.template, s.style, s.ad);
|
||||
s.view.setVisibility(View.GONE);
|
||||
overlay.add(s.view);
|
||||
}
|
||||
s.rect = r;
|
||||
s.visible = true;
|
||||
place(s, overlay);
|
||||
s.view.setVisibility(View.VISIBLE);
|
||||
s.view.bringToFront();
|
||||
}
|
||||
|
||||
void setRect(String nativeAdId, @Nullable JSObject rect) throws CallError {
|
||||
Slot s = require(nativeAdId);
|
||||
s.rect = parseRect(rect);
|
||||
OverlayHost overlay = host.overlay();
|
||||
if (overlay != null && s.view != null) place(s, overlay);
|
||||
}
|
||||
|
||||
void hide(String nativeAdId) throws CallError {
|
||||
Slot s = require(nativeAdId);
|
||||
s.visible = false;
|
||||
if (s.view != null) s.view.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
void destroy(@Nullable String nativeAdId) {
|
||||
if (nativeAdId == null) return;
|
||||
Slot s = slots.remove(nativeAdId);
|
||||
if (s != null) destroySlot(s);
|
||||
}
|
||||
|
||||
void destroyAll() {
|
||||
for (Slot s : new ArrayList<>(slots.values())) destroySlot(s);
|
||||
slots.clear();
|
||||
}
|
||||
|
||||
void onLayoutChanged(OverlayHost overlay) {
|
||||
for (Slot s : slots.values()) if (s.view != null && s.rect != null) place(s, overlay);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------- internals
|
||||
|
||||
private static String requireId(@Nullable String id) throws CallError {
|
||||
if (id == null || id.isEmpty()) throw CallError.invalid("nativeAdId is required");
|
||||
return id;
|
||||
}
|
||||
|
||||
private Slot require(@Nullable String id) throws CallError {
|
||||
Slot s = slots.get(requireId(id));
|
||||
if (s == null) throw CallError.notFound("Native ad", id);
|
||||
return s;
|
||||
}
|
||||
|
||||
private static double[] parseRect(@Nullable JSObject r) throws CallError {
|
||||
if (r == null) throw CallError.invalid("rect { x, y, width, height } is required");
|
||||
double[] out = new double[4];
|
||||
String[] keys = { "x", "y", "width", "height" };
|
||||
for (int i = 0; i < 4; i++) {
|
||||
Object v = r.opt(keys[i]);
|
||||
if (!(v instanceof Number)) throw CallError.invalid("rect." + keys[i] + " must be a number");
|
||||
double d = ((Number) v).doubleValue();
|
||||
if (Double.isNaN(d) || Double.isInfinite(d)) throw CallError.invalid("rect." + keys[i] + " must be finite");
|
||||
out[i] = d;
|
||||
}
|
||||
if (out[2] < 0 || out[3] < 0) throw CallError.invalid("rect width and height must be >= 0");
|
||||
return out;
|
||||
}
|
||||
|
||||
/** Native rects are taken literally (the page laid them out), only clamped to the WebView (design §6.3). */
|
||||
private static void place(Slot s, OverlayHost overlay) {
|
||||
if (s.view == null || s.rect == null) return;
|
||||
overlay.place(s.view, OverlayMath.intersect(s.rect, overlay.webViewCss()));
|
||||
}
|
||||
|
||||
private void destroySlot(Slot s) {
|
||||
if (s.view != null) {
|
||||
OverlayHost overlay = host.overlay();
|
||||
if (overlay != null) overlay.remove(s.view);
|
||||
s.view = null;
|
||||
}
|
||||
if (s.ad != null) {
|
||||
s.ad.destroyAd();
|
||||
s.ad = null;
|
||||
}
|
||||
s.loaded = false;
|
||||
}
|
||||
|
||||
private JSObject event(Slot s, @Nullable AdInfo info) {
|
||||
JSObject o = new JSObject();
|
||||
o.put("nativeAdId", s.id);
|
||||
if (s.placementName != null) o.put("placementName", s.placementName);
|
||||
if (info != null) o.put("adInfo", Mappers.nativeAdInfo(info));
|
||||
return o;
|
||||
}
|
||||
|
||||
/** One listener per load; callbacks of an ad object that was replaced or destroyed are dropped. */
|
||||
private final class Listener implements LevelPlayNativeAdListener {
|
||||
|
||||
private final Slot slot;
|
||||
|
||||
Listener(Slot slot) {
|
||||
this.slot = slot;
|
||||
}
|
||||
|
||||
private boolean current(@Nullable LevelPlayNativeAd ad) {
|
||||
return slots.get(slot.id) == slot && slot.ad != null && slot.ad == ad;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAdLoaded(@NonNull LevelPlayNativeAd ad, @NonNull AdInfo adInfo) {
|
||||
main.post(() -> {
|
||||
if (!current(ad)) return;
|
||||
slot.loaded = true;
|
||||
host.emit("nativeAdLoaded", event(slot, adInfo));
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAdLoadFailed(@NonNull LevelPlayNativeAd ad, @NonNull IronSourceError error) {
|
||||
main.post(() -> {
|
||||
if (!current(ad)) return;
|
||||
// The failed ad object is destroyed; the slot stays (NOT_LOADED) until the next loadNativeAd().
|
||||
slot.ad.destroyAd();
|
||||
slot.ad = null;
|
||||
slot.loaded = false;
|
||||
JSObject o = event(slot, null);
|
||||
o.put("error", Mappers.error(error.getErrorCode(), error.getErrorMessage()));
|
||||
host.emit("nativeAdLoadFailed", o);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAdImpression(@NonNull LevelPlayNativeAd ad, @NonNull AdInfo adInfo) {
|
||||
main.post(() -> {
|
||||
if (!current(ad)) return;
|
||||
host.emit("nativeAdImpression", event(slot, adInfo));
|
||||
host.impression(Mappers.nativeImpression(adInfo));
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAdClicked(@NonNull LevelPlayNativeAd ad, @NonNull AdInfo adInfo) {
|
||||
main.post(() -> {
|
||||
if (!current(ad)) return;
|
||||
host.emit("nativeAdClicked", event(slot, adInfo));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,75 +0,0 @@
|
|||
package fyi.crt.capacitor.levelplay;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import com.getcapacitor.JSObject;
|
||||
|
||||
/** Parsed NativeAdTemplateStyle (src/definitions.ts). Colours are ARGB; sizes are CSS px (dp). */
|
||||
final class NativeAdStyle {
|
||||
|
||||
static final class Font {
|
||||
|
||||
@Nullable
|
||||
final String family;
|
||||
|
||||
@Nullable
|
||||
final Double size;
|
||||
|
||||
Font(@Nullable String family, @Nullable Double size) {
|
||||
this.family = family;
|
||||
this.size = size;
|
||||
}
|
||||
}
|
||||
|
||||
int backgroundColor = 0xFFFFFFFF;
|
||||
int titleColor = 0xFF202124;
|
||||
int bodyColor = 0xFF5F6368;
|
||||
int callToActionBackgroundColor = 0xFF1A73E8;
|
||||
int callToActionTextColor = 0xFFFFFFFF;
|
||||
double cornerRadius = 0;
|
||||
Font titleFont = new Font(null, null);
|
||||
Font bodyFont = new Font(null, null);
|
||||
Font callToActionFont = new Font(null, null);
|
||||
|
||||
static NativeAdStyle parse(@Nullable JSObject o) throws CallError {
|
||||
NativeAdStyle s = new NativeAdStyle();
|
||||
if (o == null) return s;
|
||||
s.backgroundColor = color(o, "backgroundColor", s.backgroundColor);
|
||||
s.titleColor = color(o, "titleColor", s.titleColor);
|
||||
s.bodyColor = color(o, "bodyColor", s.bodyColor);
|
||||
s.callToActionBackgroundColor = color(o, "callToActionBackgroundColor", s.callToActionBackgroundColor);
|
||||
s.callToActionTextColor = color(o, "callToActionTextColor", s.callToActionTextColor);
|
||||
if (o.has("cornerRadius") && !o.isNull("cornerRadius")) {
|
||||
Object v = o.opt("cornerRadius");
|
||||
if (!(v instanceof Number) || !(((Number) v).doubleValue() >= 0)) throw CallError.invalid("style.cornerRadius must be >= 0");
|
||||
s.cornerRadius = ((Number) v).doubleValue();
|
||||
}
|
||||
s.titleFont = font(o, "titleFont");
|
||||
s.bodyFont = font(o, "bodyFont");
|
||||
s.callToActionFont = font(o, "callToActionFont");
|
||||
return s;
|
||||
}
|
||||
|
||||
private static int color(JSObject o, String key, int fallback) throws CallError {
|
||||
if (!o.has(key) || o.isNull(key)) return fallback;
|
||||
Integer c = OverlayMath.parseColor(o.optString(key, null));
|
||||
if (c == null) throw CallError.invalid("style." + key + " must be #RRGGBB or #RRGGBBAA");
|
||||
return c;
|
||||
}
|
||||
|
||||
private static Font font(JSObject o, String key) throws CallError {
|
||||
if (!o.has(key) || o.isNull(key)) return new Font(null, null);
|
||||
JSObject f = o.getJSObject(key);
|
||||
if (f == null) throw CallError.invalid("style." + key + " must be an object { family?, size? }");
|
||||
String family = f.getString("family");
|
||||
if (family != null && family.trim().isEmpty()) family = null;
|
||||
Double size = null;
|
||||
if (f.has("size") && !f.isNull("size")) {
|
||||
Object v = f.opt("size");
|
||||
if (!(v instanceof Number) || !(((Number) v).doubleValue() > 0) || Double.isInfinite(((Number) v).doubleValue())) {
|
||||
throw CallError.invalid("style." + key + ".size must be a positive number");
|
||||
}
|
||||
size = ((Number) v).doubleValue();
|
||||
}
|
||||
return new Font(family, size);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,328 +0,0 @@
|
|||
package fyi.crt.capacitor.levelplay;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Typeface;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.GradientDrawable;
|
||||
import android.net.Uri;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.util.TypedValue;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.ironsource.mediationsdk.ads.nativead.LevelPlayMediaView;
|
||||
import com.ironsource.mediationsdk.ads.nativead.LevelPlayNativeAd;
|
||||
import com.ironsource.mediationsdk.ads.nativead.NativeAdLayout;
|
||||
import com.ironsource.mediationsdk.ads.nativead.interfaces.NativeAdDataInterface;
|
||||
import java.io.InputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
/**
|
||||
* The plugin's own native ad templates (the SDK ships none, design §4.1), built in code so every style value applies
|
||||
* directly. Both draw an "Ad" badge and keep the bottom-left corner free for the network's privacy / AdChoices icon.
|
||||
*
|
||||
* - small: [icon] [title / Ad + advertiser / body] [CTA], one row; fits rows from about 90 px tall.
|
||||
* - medium: [icon] [title / Ad + advertiser], body, media view (fills the rest), CTA aligned right.
|
||||
*/
|
||||
final class NativeAdTemplate {
|
||||
|
||||
private static final String TAG = "LevelPlay";
|
||||
private static final int BADGE_BG = 0xFFFFC107;
|
||||
private static final int BADGE_TEXT = 0xFF202124;
|
||||
private static final Map<String, Typeface> ASSET_FONTS = new HashMap<>();
|
||||
private static final ExecutorService IO = Executors.newSingleThreadExecutor();
|
||||
|
||||
private NativeAdTemplate() {}
|
||||
|
||||
/** The template's asset views, created and styled but not filled. */
|
||||
static final class Views {
|
||||
|
||||
final NativeAdLayout root;
|
||||
final TextView title;
|
||||
final TextView advertiser;
|
||||
final TextView body;
|
||||
final ImageView icon;
|
||||
final Button cta;
|
||||
|
||||
@Nullable
|
||||
final LevelPlayMediaView media;
|
||||
|
||||
Views(NativeAdLayout root, TextView title, TextView advertiser, TextView body, ImageView icon, Button cta, @Nullable LevelPlayMediaView media) {
|
||||
this.root = root;
|
||||
this.title = title;
|
||||
this.advertiser = advertiser;
|
||||
this.body = body;
|
||||
this.icon = icon;
|
||||
this.cta = cta;
|
||||
this.media = media;
|
||||
}
|
||||
}
|
||||
|
||||
/** Renders a loaded ad: create, fill from the ad's assets, hand the views to the SDK and register them. */
|
||||
static NativeAdLayout build(Context ctx, String template, NativeAdStyle style, LevelPlayNativeAd ad) {
|
||||
Views v = create(ctx, template, style);
|
||||
fill(v, ad.getTitle(), ad.getAdvertiser(), ad.getBody(), ad.getCallToAction(), ad.getIcon());
|
||||
v.root.setTitleView(v.title);
|
||||
v.root.setAdvertiserView(v.advertiser);
|
||||
v.root.setBodyView(v.body);
|
||||
v.root.setIconView(v.icon);
|
||||
v.root.setCallToActionView(v.cta);
|
||||
if (v.media != null) v.root.setMediaView(v.media);
|
||||
v.root.registerNativeAdViews(ad);
|
||||
return v.root;
|
||||
}
|
||||
|
||||
static Views create(Context ctx, String template, NativeAdStyle style) {
|
||||
boolean medium = "medium".equals(template);
|
||||
NativeAdLayout root = new NativeAdLayout(ctx);
|
||||
GradientDrawable bg = new GradientDrawable();
|
||||
bg.setColor(style.backgroundColor);
|
||||
bg.setCornerRadius(dp(ctx, style.cornerRadius));
|
||||
root.setBackground(bg);
|
||||
root.setClipToOutline(true);
|
||||
// The template consumes touches inside its bounds so taps between asset views do not reach the game.
|
||||
root.setClickable(true);
|
||||
|
||||
ImageView icon = new ImageView(ctx);
|
||||
icon.setScaleType(ImageView.ScaleType.CENTER_CROP);
|
||||
GradientDrawable iconBg = new GradientDrawable();
|
||||
iconBg.setCornerRadius(dp(ctx, 6));
|
||||
iconBg.setColor(0x14000000);
|
||||
icon.setBackground(iconBg);
|
||||
icon.setClipToOutline(true);
|
||||
|
||||
TextView title = text(ctx, style.titleColor, 15, style.titleFont, true);
|
||||
title.setMaxLines(medium ? 2 : 1);
|
||||
|
||||
TextView badge = text(ctx, BADGE_TEXT, 10, style.bodyFont, true);
|
||||
badge.setText(R.string.levelplay_native_ad_badge);
|
||||
badge.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
|
||||
GradientDrawable badgeBg = new GradientDrawable();
|
||||
badgeBg.setColor(BADGE_BG);
|
||||
badgeBg.setCornerRadius(dp(ctx, 3));
|
||||
badge.setBackground(badgeBg);
|
||||
int bp = (int) dp(ctx, 4);
|
||||
badge.setPadding(bp, 0, bp, 0);
|
||||
|
||||
TextView advertiser = text(ctx, style.bodyColor, 12, style.bodyFont, false);
|
||||
advertiser.setMaxLines(1);
|
||||
|
||||
TextView body = text(ctx, style.bodyColor, 12, style.bodyFont, false);
|
||||
body.setMaxLines(2);
|
||||
|
||||
Button cta = new Button(ctx);
|
||||
cta.setAllCaps(false);
|
||||
cta.setStateListAnimator(null);
|
||||
cta.setMinWidth(0);
|
||||
cta.setMinimumWidth(0);
|
||||
cta.setMinHeight(0);
|
||||
cta.setMinimumHeight(0);
|
||||
cta.setSingleLine(true);
|
||||
cta.setEllipsize(TextUtils.TruncateAt.END);
|
||||
cta.setTextColor(style.callToActionTextColor);
|
||||
applyFont(ctx, cta, style.callToActionFont, 13, true);
|
||||
GradientDrawable ctaBg = new GradientDrawable();
|
||||
ctaBg.setColor(style.callToActionBackgroundColor);
|
||||
ctaBg.setCornerRadius(dp(ctx, 6));
|
||||
cta.setBackground(ctaBg);
|
||||
int cp = (int) dp(ctx, 12);
|
||||
cta.setPadding(cp, 0, cp, 0);
|
||||
cta.setGravity(Gravity.CENTER);
|
||||
|
||||
// Badge + advertiser row.
|
||||
LinearLayout adRow = new LinearLayout(ctx);
|
||||
adRow.setOrientation(LinearLayout.HORIZONTAL);
|
||||
adRow.setGravity(Gravity.CENTER_VERTICAL);
|
||||
adRow.addView(badge, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
|
||||
LinearLayout.LayoutParams advLp = new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 1);
|
||||
advLp.leftMargin = (int) dp(ctx, 6);
|
||||
adRow.addView(advertiser, advLp);
|
||||
|
||||
LevelPlayMediaView media = null;
|
||||
int pad = (int) dp(ctx, medium ? 10 : 8);
|
||||
if (medium) {
|
||||
LinearLayout col = new LinearLayout(ctx);
|
||||
col.setOrientation(LinearLayout.VERTICAL);
|
||||
col.setPadding(pad, pad, pad, pad);
|
||||
|
||||
LinearLayout header = new LinearLayout(ctx);
|
||||
header.setOrientation(LinearLayout.HORIZONTAL);
|
||||
header.setGravity(Gravity.CENTER_VERTICAL);
|
||||
int is = (int) dp(ctx, 40);
|
||||
header.addView(icon, new LinearLayout.LayoutParams(is, is));
|
||||
LinearLayout texts = new LinearLayout(ctx);
|
||||
texts.setOrientation(LinearLayout.VERTICAL);
|
||||
texts.addView(title);
|
||||
texts.addView(adRow);
|
||||
LinearLayout.LayoutParams tLp = new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 1);
|
||||
tLp.leftMargin = (int) dp(ctx, 8);
|
||||
header.addView(texts, tLp);
|
||||
col.addView(header);
|
||||
|
||||
LinearLayout.LayoutParams bodyLp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
bodyLp.topMargin = (int) dp(ctx, 6);
|
||||
col.addView(body, bodyLp);
|
||||
|
||||
media = new LevelPlayMediaView(ctx);
|
||||
LinearLayout.LayoutParams mLp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, 1);
|
||||
mLp.topMargin = (int) dp(ctx, 8);
|
||||
col.addView(media, mLp);
|
||||
|
||||
// CTA on the right: the bottom-left corner stays free for the AdChoices icon.
|
||||
LinearLayout.LayoutParams ctaLp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, (int) dp(ctx, 36));
|
||||
ctaLp.topMargin = (int) dp(ctx, 8);
|
||||
ctaLp.gravity = Gravity.END;
|
||||
col.addView(cta, ctaLp);
|
||||
root.addView(col, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
||||
} else {
|
||||
LinearLayout row = new LinearLayout(ctx);
|
||||
row.setOrientation(LinearLayout.HORIZONTAL);
|
||||
row.setGravity(Gravity.CENTER_VERTICAL);
|
||||
row.setPadding(pad, pad, pad, pad);
|
||||
int is = (int) dp(ctx, 48);
|
||||
row.addView(icon, new LinearLayout.LayoutParams(is, is));
|
||||
LinearLayout texts = new LinearLayout(ctx);
|
||||
texts.setOrientation(LinearLayout.VERTICAL);
|
||||
texts.addView(title);
|
||||
texts.addView(adRow);
|
||||
texts.addView(body);
|
||||
LinearLayout.LayoutParams tLp = new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 1);
|
||||
tLp.leftMargin = (int) dp(ctx, 8);
|
||||
tLp.rightMargin = (int) dp(ctx, 8);
|
||||
row.addView(texts, tLp);
|
||||
row.addView(cta, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, (int) dp(ctx, 36)));
|
||||
root.addView(row, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
||||
}
|
||||
|
||||
return new Views(root, title, advertiser, body, icon, cta, media);
|
||||
}
|
||||
|
||||
static void fill(
|
||||
Views v,
|
||||
@Nullable String title,
|
||||
@Nullable String advertiser,
|
||||
@Nullable String body,
|
||||
@Nullable String callToAction,
|
||||
@Nullable NativeAdDataInterface.Image icon
|
||||
) {
|
||||
setOrHide(v.title, title);
|
||||
setOrHide(v.advertiser, advertiser);
|
||||
setOrHide(v.body, body);
|
||||
if (callToAction != null && !callToAction.isEmpty()) v.cta.setText(callToAction);
|
||||
else v.cta.setText(R.string.levelplay_native_ad_cta_fallback);
|
||||
bindIcon(v.icon, icon);
|
||||
}
|
||||
|
||||
private static TextView text(Context ctx, int color, double defaultSize, NativeAdStyle.Font font, boolean bold) {
|
||||
TextView t = new TextView(ctx);
|
||||
t.setTextColor(color);
|
||||
t.setEllipsize(TextUtils.TruncateAt.END);
|
||||
t.setIncludeFontPadding(false);
|
||||
applyFont(ctx, t, font, defaultSize, bold);
|
||||
return t;
|
||||
}
|
||||
|
||||
private static void applyFont(Context ctx, TextView t, NativeAdStyle.Font font, double defaultSize, boolean bold) {
|
||||
// CSS px = dp, and like WebView text it ignores the system font scale.
|
||||
t.setTextSize(TypedValue.COMPLEX_UNIT_DIP, (float) (font.size != null ? font.size : defaultSize));
|
||||
Typeface tf = typeface(ctx, font.family, bold);
|
||||
t.setTypeface(tf);
|
||||
}
|
||||
|
||||
/** System family name, or a .ttf / .otf file in the web assets (Capacitor copies the web dir to assets/public). */
|
||||
static Typeface typeface(Context ctx, @Nullable String family, boolean bold) {
|
||||
int style = bold ? Typeface.BOLD : Typeface.NORMAL;
|
||||
if (family == null) return Typeface.defaultFromStyle(style);
|
||||
String lower = family.toLowerCase(java.util.Locale.ROOT);
|
||||
if (lower.endsWith(".ttf") || lower.endsWith(".otf")) {
|
||||
String path = family;
|
||||
while (path.startsWith("/")) path = path.substring(1);
|
||||
if (path.startsWith("./")) path = path.substring(2);
|
||||
String asset = "public/" + path;
|
||||
synchronized (ASSET_FONTS) {
|
||||
Typeface cached = ASSET_FONTS.get(asset);
|
||||
if (cached != null) return cached;
|
||||
try {
|
||||
Typeface tf = Typeface.createFromAsset(ctx.getAssets(), asset);
|
||||
ASSET_FONTS.put(asset, tf);
|
||||
return tf;
|
||||
} catch (RuntimeException e) {
|
||||
Log.w(TAG, "Native ad font not found in assets: " + asset + "; using the system font");
|
||||
return Typeface.defaultFromStyle(style);
|
||||
}
|
||||
}
|
||||
}
|
||||
return Typeface.create(family, style);
|
||||
}
|
||||
|
||||
private static void setOrHide(TextView v, @Nullable String text) {
|
||||
if (text == null || text.trim().isEmpty()) {
|
||||
v.setText("");
|
||||
v.setVisibility(View.GONE);
|
||||
} else {
|
||||
v.setText(text);
|
||||
v.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
private static void bindIcon(ImageView icon, @Nullable NativeAdDataInterface.Image image) {
|
||||
if (image == null) {
|
||||
icon.setVisibility(View.GONE);
|
||||
return;
|
||||
}
|
||||
Drawable d = image.getDrawable();
|
||||
if (d != null) {
|
||||
icon.setImageDrawable(d);
|
||||
return;
|
||||
}
|
||||
Uri uri = image.getUri();
|
||||
if (uri == null || uri.getScheme() == null || !uri.getScheme().startsWith("http")) {
|
||||
icon.setVisibility(View.GONE);
|
||||
return;
|
||||
}
|
||||
// Some adapters only give a URL: fetch it off the main thread.
|
||||
Handler main = new Handler(Looper.getMainLooper());
|
||||
String url = uri.toString();
|
||||
IO.execute(() -> {
|
||||
Bitmap bmp = null;
|
||||
HttpURLConnection c = null;
|
||||
try {
|
||||
c = (HttpURLConnection) new URL(url).openConnection();
|
||||
c.setConnectTimeout(10000);
|
||||
c.setReadTimeout(10000);
|
||||
try (InputStream in = c.getInputStream()) {
|
||||
bmp = BitmapFactory.decodeStream(in);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.w(TAG, "Native ad icon download failed: " + e);
|
||||
} finally {
|
||||
if (c != null) c.disconnect();
|
||||
}
|
||||
Bitmap result = bmp;
|
||||
main.post(() -> {
|
||||
if (result != null) icon.setImageBitmap(result);
|
||||
else icon.setVisibility(View.GONE);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static float dp(Context ctx, double v) {
|
||||
return (float) (v * ctx.getResources().getDisplayMetrics().density);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,159 +0,0 @@
|
|||
package fyi.crt.capacitor.levelplay;
|
||||
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.FrameLayout;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.graphics.Insets;
|
||||
import androidx.core.view.ViewCompat;
|
||||
import androidx.core.view.WindowInsetsCompat;
|
||||
|
||||
/**
|
||||
* Plugin-owned, pass-through FrameLayout above the WebView (design §6.2). It is a sibling of the WebView in the
|
||||
* WebView's parent, added right after it so it draws on top. It is neither clickable nor focusable and has no touch
|
||||
* listener, so touches outside its (visible) children fall through to the WebView.
|
||||
*
|
||||
* Public geometry is CSS px relative to the WebView's top-left corner (1 CSS px = 1 dp in a Capacitor WebView).
|
||||
* Children are positioned with FrameLayout margins measured from the WebView's offset inside the host, so the host
|
||||
* does not need to share the WebView's bounds (Capacitor 8 may pad the parent; Capacitor 7 may set WebView margins).
|
||||
* Main thread only.
|
||||
*/
|
||||
final class OverlayHost {
|
||||
|
||||
interface Listener {
|
||||
/** The WebView or the host moved / resized, or the window insets changed. Called posted, never mid-layout. */
|
||||
void onOverlayLayoutChanged();
|
||||
}
|
||||
|
||||
final FrameLayout view;
|
||||
private final View webView;
|
||||
private final Listener listener;
|
||||
private final float density;
|
||||
private boolean relayoutPosted;
|
||||
private final View.OnLayoutChangeListener layoutListener = (v, l, t, r, b, ol, ot, or, ob) -> {
|
||||
if (l != ol || t != ot || r != or || b != ob) postRelayout();
|
||||
};
|
||||
private final Runnable relayout = () -> {
|
||||
relayoutPosted = false;
|
||||
listenerRelayout();
|
||||
};
|
||||
|
||||
private OverlayHost(View webView, ViewGroup parent, Listener listener) {
|
||||
this.webView = webView;
|
||||
this.listener = listener;
|
||||
this.density = webView.getResources().getDisplayMetrics().density;
|
||||
view = new FrameLayout(webView.getContext());
|
||||
view.setClickable(false);
|
||||
view.setFocusable(false);
|
||||
view.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_AUTO);
|
||||
view.setClipChildren(true);
|
||||
int index = parent.indexOfChild(webView) + 1;
|
||||
parent.addView(view, index, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
||||
webView.addOnLayoutChangeListener(layoutListener);
|
||||
view.addOnLayoutChangeListener(layoutListener);
|
||||
// Insets are only observed; returning them unconsumed keeps Capacitor's own handling on the WebView intact.
|
||||
ViewCompat.setOnApplyWindowInsetsListener(view, (v, insets) -> {
|
||||
postRelayout();
|
||||
return insets;
|
||||
});
|
||||
}
|
||||
|
||||
/** Attaches a host next to the WebView, or returns null when the WebView has no parent ViewGroup yet. */
|
||||
@Nullable
|
||||
static OverlayHost attach(@Nullable View webView, Listener listener) {
|
||||
if (webView == null || !(webView.getParent() instanceof ViewGroup)) return null;
|
||||
return new OverlayHost(webView, (ViewGroup) webView.getParent(), listener);
|
||||
}
|
||||
|
||||
void detach() {
|
||||
webView.removeOnLayoutChangeListener(layoutListener);
|
||||
view.removeOnLayoutChangeListener(layoutListener);
|
||||
ViewCompat.setOnApplyWindowInsetsListener(view, null);
|
||||
view.removeCallbacks(relayout);
|
||||
view.removeAllViews();
|
||||
if (view.getParent() instanceof ViewGroup) ((ViewGroup) view.getParent()).removeView(view);
|
||||
}
|
||||
|
||||
void postRelayout() {
|
||||
if (relayoutPosted) return;
|
||||
relayoutPosted = true;
|
||||
view.post(relayout);
|
||||
}
|
||||
|
||||
private void listenerRelayout() {
|
||||
listener.onOverlayLayoutChanged();
|
||||
}
|
||||
|
||||
float density() {
|
||||
return density;
|
||||
}
|
||||
|
||||
int toPx(double css) {
|
||||
return (int) Math.round(css * density);
|
||||
}
|
||||
|
||||
/** The WebView's own rect in CSS px (origin 0, 0). */
|
||||
double[] webViewCss() {
|
||||
return OverlayMath.rect(0, 0, webView.getWidth() / (double) density, webView.getHeight() / (double) density);
|
||||
}
|
||||
|
||||
/** WebView rect ∩ (window − system bars − display cutout), in WebView-local CSS px (design §6.3). */
|
||||
double[] safeAreaCss() {
|
||||
int[] loc = new int[2];
|
||||
webView.getLocationInWindow(loc);
|
||||
View root = webView.getRootView();
|
||||
int il = 0, it = 0, ir = 0, ib = 0;
|
||||
WindowInsetsCompat insets = ViewCompat.getRootWindowInsets(webView);
|
||||
if (insets != null) {
|
||||
Insets i = insets.getInsets(WindowInsetsCompat.Type.systemBars() | WindowInsetsCompat.Type.displayCutout());
|
||||
il = i.left;
|
||||
it = i.top;
|
||||
ir = i.right;
|
||||
ib = i.bottom;
|
||||
}
|
||||
return OverlayMath.safeAreaCss(
|
||||
loc[0],
|
||||
loc[1],
|
||||
webView.getWidth(),
|
||||
webView.getHeight(),
|
||||
root.getWidth(),
|
||||
root.getHeight(),
|
||||
il,
|
||||
it,
|
||||
ir,
|
||||
ib,
|
||||
density
|
||||
);
|
||||
}
|
||||
|
||||
/** Adds a child (hidden or not, as the caller set it) on top of the other overlay children. */
|
||||
void add(View child) {
|
||||
if (child.getParent() instanceof ViewGroup) ((ViewGroup) child.getParent()).removeView(child);
|
||||
view.addView(child, new FrameLayout.LayoutParams(0, 0));
|
||||
}
|
||||
|
||||
void remove(View child) {
|
||||
if (child.getParent() == view) view.removeView(child);
|
||||
}
|
||||
|
||||
/** Places a child at a WebView-local CSS rect. */
|
||||
void place(View child, double[] css) {
|
||||
int[] wv = new int[2];
|
||||
int[] host = new int[2];
|
||||
webView.getLocationInWindow(wv);
|
||||
view.getLocationInWindow(host);
|
||||
int left = wv[0] - host[0] + toPx(css[0]);
|
||||
int top = wv[1] - host[1] + toPx(css[1]);
|
||||
int w = Math.max(0, toPx(css[2]));
|
||||
int h = Math.max(0, toPx(css[3]));
|
||||
ViewGroup.LayoutParams raw = child.getLayoutParams();
|
||||
FrameLayout.LayoutParams lp = raw instanceof FrameLayout.LayoutParams ? (FrameLayout.LayoutParams) raw : new FrameLayout.LayoutParams(w, h);
|
||||
if (lp.width == w && lp.height == h && lp.leftMargin == left && lp.topMargin == top && raw == lp) return;
|
||||
lp.width = w;
|
||||
lp.height = h;
|
||||
lp.leftMargin = left;
|
||||
lp.topMargin = top;
|
||||
lp.gravity = android.view.Gravity.TOP | android.view.Gravity.LEFT;
|
||||
child.setLayoutParams(lp);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,120 +0,0 @@
|
|||
package fyi.crt.capacitor.levelplay;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Pure helpers (no Android, no SDK types) for overlay geometry and argument validation, unit tested on the JVM.
|
||||
* Rects are {@code double[]{x, y, width, height}}.
|
||||
*/
|
||||
final class OverlayMath {
|
||||
|
||||
/** LevelPlaySegment.setCustom limits read from the 9.6.1 bytecode: 1-32 chars, letters and digits, at most 5. */
|
||||
static final int MAX_CUSTOM_PARAMS = 5;
|
||||
static final int MAX_CUSTOM_LENGTH = 32;
|
||||
private static final Pattern ALNUM = Pattern.compile("^[a-zA-Z0-9]+$");
|
||||
private static final Pattern HEX_COLOR = Pattern.compile("^#([0-9a-fA-F]{6}|[0-9a-fA-F]{8})$");
|
||||
|
||||
private OverlayMath() {}
|
||||
|
||||
static double[] rect(double x, double y, double w, double h) {
|
||||
return new double[] { x, y, w, h };
|
||||
}
|
||||
|
||||
/** Intersection of two rects; an empty intersection has zero width / height at the clamped origin. */
|
||||
static double[] intersect(double[] a, double[] b) {
|
||||
double l = Math.max(a[0], b[0]);
|
||||
double t = Math.max(a[1], b[1]);
|
||||
double r = Math.min(a[0] + a[2], b[0] + b[2]);
|
||||
double btm = Math.min(a[1] + a[3], b[1] + b[3]);
|
||||
return rect(l, t, Math.max(0, r - l), Math.max(0, btm - t));
|
||||
}
|
||||
|
||||
/**
|
||||
* Safe area of the WebView in WebView-local CSS px: the WebView's on-screen rect (window px) intersected with the
|
||||
* window minus the system insets (window px), shifted to the WebView origin and divided by the density.
|
||||
*/
|
||||
static double[] safeAreaCss(
|
||||
int wvLeft,
|
||||
int wvTop,
|
||||
int wvWidth,
|
||||
int wvHeight,
|
||||
int windowWidth,
|
||||
int windowHeight,
|
||||
int insetLeft,
|
||||
int insetTop,
|
||||
int insetRight,
|
||||
int insetBottom,
|
||||
float density
|
||||
) {
|
||||
double[] web = rect(wvLeft, wvTop, wvWidth, wvHeight);
|
||||
double[] safe = rect(insetLeft, insetTop, windowWidth - insetLeft - insetRight, windowHeight - insetTop - insetBottom);
|
||||
double[] s = intersect(web, safe);
|
||||
return rect((s[0] - wvLeft) / density, (s[1] - wvTop) / density, s[2] / density, s[3] / density);
|
||||
}
|
||||
|
||||
/** Banner frame inside {@code area} (design §6.4): centred horizontally, anchored top / bottom / center. */
|
||||
static double[] bannerFrame(double[] area, double width, double height, String position, double offsetX, double offsetY) {
|
||||
double x = area[0] + (area[2] - width) / 2 + offsetX;
|
||||
double y;
|
||||
switch (position) {
|
||||
case "top":
|
||||
y = area[1] + offsetY;
|
||||
break;
|
||||
case "center":
|
||||
y = area[1] + (area[3] - height) / 2 + offsetY;
|
||||
break;
|
||||
default:
|
||||
y = area[1] + area[3] - height + offsetY;
|
||||
break;
|
||||
}
|
||||
return rect(x, y, width, height);
|
||||
}
|
||||
|
||||
static boolean isPosition(String p) {
|
||||
return "top".equals(p) || "bottom".equals(p) || "center".equals(p);
|
||||
}
|
||||
|
||||
static boolean isBannerSize(String s) {
|
||||
switch (s) {
|
||||
case "BANNER":
|
||||
case "LARGE":
|
||||
case "MEDIUM_RECTANGLE":
|
||||
case "LEADERBOARD":
|
||||
case "ADAPTIVE":
|
||||
case "CUSTOM":
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/** Error message for segment custom parameters that break the SDK limits, or null when they are fine. */
|
||||
static String customParamsError(Map<String, ?> params) {
|
||||
if (params.size() > MAX_CUSTOM_PARAMS) {
|
||||
return "customParameters: at most " + MAX_CUSTOM_PARAMS + " pairs (got " + params.size() + ")";
|
||||
}
|
||||
for (Map.Entry<String, ?> e : params.entrySet()) {
|
||||
String k = e.getKey();
|
||||
if (!validToken(k)) return "customParameters: key '" + k + "' must be 1-32 letters or digits";
|
||||
Object v = e.getValue();
|
||||
if (!(v instanceof String)) return "customParameters: value of '" + k + "' must be a string";
|
||||
if (!validToken((String) v)) return "customParameters: value of '" + k + "' must be 1-32 letters or digits";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static boolean validToken(String s) {
|
||||
return s != null && s.length() >= 1 && s.length() <= MAX_CUSTOM_LENGTH && ALNUM.matcher(s).matches();
|
||||
}
|
||||
|
||||
/** CSS {@code #RRGGBB} / {@code #RRGGBBAA} to Android ARGB, or null when malformed. */
|
||||
static Integer parseColor(String css) {
|
||||
if (css == null || !HEX_COLOR.matcher(css).matches()) return null;
|
||||
long v = Long.parseLong(css.substring(1), 16);
|
||||
if (css.length() == 7) return (int) (0xFF000000L | v);
|
||||
long rgb = v >>> 8;
|
||||
long a = v & 0xFF;
|
||||
return (int) ((a << 24) | rgb);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<!-- Native ad template texts. Apps can translate or replace them by defining the same names in their own res. -->
|
||||
<string name="levelplay_native_ad_badge">Ad</string>
|
||||
<string name="levelplay_native_ad_cta_fallback">Open</string>
|
||||
</resources>
|
||||
|
|
@ -1,102 +0,0 @@
|
|||
package fyi.crt.capacitor.levelplay;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import org.junit.Test;
|
||||
|
||||
public class OverlayMathTest {
|
||||
|
||||
private static final double EPS = 1e-9;
|
||||
|
||||
@Test
|
||||
public void intersectOverlapsAndEmpty() {
|
||||
assertArrayEquals(new double[] { 10, 20, 90, 80 }, OverlayMath.intersect(OverlayMath.rect(0, 0, 100, 100), OverlayMath.rect(10, 20, 200, 200)), EPS);
|
||||
double[] none = OverlayMath.intersect(OverlayMath.rect(0, 0, 10, 10), OverlayMath.rect(20, 20, 5, 5));
|
||||
assertEquals(0, none[2], EPS);
|
||||
assertEquals(0, none[3], EPS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void safeAreaEdgeToEdgeWebView() {
|
||||
// 1080 x 2400 window at density 2.625; WebView covers the window; status bar 63 px, nav bar 126 px.
|
||||
double[] s = OverlayMath.safeAreaCss(0, 0, 1080, 2400, 1080, 2400, 0, 63, 0, 126, 2.625f);
|
||||
assertArrayEquals(new double[] { 0, 24, 1080 / 2.625, (2400 - 63 - 126) / 2.625 }, s, EPS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void safeAreaWebViewAlreadyInset() {
|
||||
// Capacitor native insets handling: the WebView itself sits between the bars, so the safe area is all of it.
|
||||
double[] s = OverlayMath.safeAreaCss(0, 63, 1080, 2211, 1080, 2400, 0, 63, 0, 126, 2.625f);
|
||||
assertArrayEquals(new double[] { 0, 0, 1080 / 2.625, 2211 / 2.625 }, s, EPS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void safeAreaLandscapeCutout() {
|
||||
// Landscape with a 100 px cutout on the left and a 120 px nav bar on the right; density 2.
|
||||
double[] s = OverlayMath.safeAreaCss(0, 0, 2400, 1080, 2400, 1080, 100, 50, 120, 0, 2f);
|
||||
assertArrayEquals(new double[] { 50, 25, (2400 - 220) / 2.0, (1080 - 50) / 2.0 }, s, EPS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bannerFramePositions() {
|
||||
double[] area = OverlayMath.rect(0, 24, 411, 800);
|
||||
assertArrayEquals(new double[] { 45.5, 24, 320, 50 }, OverlayMath.bannerFrame(area, 320, 50, "top", 0, 0), EPS);
|
||||
assertArrayEquals(new double[] { 45.5, 774, 320, 50 }, OverlayMath.bannerFrame(area, 320, 50, "bottom", 0, 0), EPS);
|
||||
assertArrayEquals(new double[] { 45.5, 399, 320, 50 }, OverlayMath.bannerFrame(area, 320, 50, "center", 0, 0), EPS);
|
||||
assertArrayEquals(new double[] { 55.5, 764, 320, 50 }, OverlayMath.bannerFrame(area, 320, 50, "bottom", 10, -10), EPS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void positionsAndSizes() {
|
||||
assertTrue(OverlayMath.isPosition("top"));
|
||||
assertFalse(OverlayMath.isPosition("left"));
|
||||
assertTrue(OverlayMath.isBannerSize("CUSTOM"));
|
||||
assertTrue(OverlayMath.isBannerSize("ADAPTIVE"));
|
||||
assertFalse(OverlayMath.isBannerSize("SMART"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customParams() {
|
||||
Map<String, Object> ok = new LinkedHashMap<>();
|
||||
ok.put("tier", "gold");
|
||||
ok.put("ab1", "B");
|
||||
assertNull(OverlayMath.customParamsError(ok));
|
||||
|
||||
Map<String, Object> badChar = new LinkedHashMap<>();
|
||||
badChar.put("my-key", "x");
|
||||
assertNotNull(OverlayMath.customParamsError(badChar));
|
||||
|
||||
Map<String, Object> empty = new LinkedHashMap<>();
|
||||
empty.put("k", "");
|
||||
assertNotNull(OverlayMath.customParamsError(empty));
|
||||
|
||||
Map<String, Object> tooLong = new LinkedHashMap<>();
|
||||
tooLong.put("k", "123456789012345678901234567890123");
|
||||
assertNotNull(OverlayMath.customParamsError(tooLong));
|
||||
|
||||
Map<String, Object> notString = new LinkedHashMap<>();
|
||||
notString.put("k", 5);
|
||||
assertNotNull(OverlayMath.customParamsError(notString));
|
||||
|
||||
Map<String, Object> six = new LinkedHashMap<>();
|
||||
for (int i = 0; i < 6; i++) six.put("k" + i, "v");
|
||||
assertNotNull(OverlayMath.customParamsError(six));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void colors() {
|
||||
assertEquals(Integer.valueOf(0xFF112233), OverlayMath.parseColor("#112233"));
|
||||
assertEquals(Integer.valueOf(0x80112233), OverlayMath.parseColor("#11223380"));
|
||||
assertNull(OverlayMath.parseColor("112233"));
|
||||
assertNull(OverlayMath.parseColor("#12345"));
|
||||
assertNull(OverlayMath.parseColor("red"));
|
||||
assertNull(OverlayMath.parseColor(null));
|
||||
}
|
||||
}
|
||||
3704
dist/docs.json
vendored
1538
dist/esm/definitions.d.ts
vendored
2
dist/esm/definitions.js.map
vendored
3
dist/esm/demo.d.ts
vendored
|
|
@ -2,7 +2,6 @@
|
|||
* Public demo app keys and ad unit ids from Unity's official LevelPlay sample apps
|
||||
* (https://github.com/ironsource-mobile/Mediation-Demo-Apps: `Android/Kotlin/.../DemoActivity.kt` and
|
||||
* `iOS/Swift SPM/LevelPlayDemo/DemoViewController.swift`). They serve test ads and are safe for development only.
|
||||
* The sample apps have no native ad placement; native ads load with the default placement of the app key.
|
||||
* Replace them with your own ids from the LevelPlay dashboard before release.
|
||||
*/
|
||||
export declare const LEVELPLAY_DEMO: {
|
||||
|
|
@ -10,12 +9,10 @@ export declare const LEVELPLAY_DEMO: {
|
|||
readonly appKey: "25b63cf85";
|
||||
readonly rewarded: "syz3d8ekts22q0or";
|
||||
readonly interstitial: "h3xw38h9214adgxo";
|
||||
readonly banner: "4fpetq4lhe5lsw3e";
|
||||
};
|
||||
readonly ios: {
|
||||
readonly appKey: "8545d445";
|
||||
readonly rewarded: "qwouvdrkuwivay5q";
|
||||
readonly interstitial: "wmgt0712uuux8ju4";
|
||||
readonly banner: "iep3rxsyp9na3rw8";
|
||||
};
|
||||
};
|
||||
|
|
|
|||
3
dist/esm/demo.js
vendored
|
|
@ -2,7 +2,6 @@
|
|||
* Public demo app keys and ad unit ids from Unity's official LevelPlay sample apps
|
||||
* (https://github.com/ironsource-mobile/Mediation-Demo-Apps: `Android/Kotlin/.../DemoActivity.kt` and
|
||||
* `iOS/Swift SPM/LevelPlayDemo/DemoViewController.swift`). They serve test ads and are safe for development only.
|
||||
* The sample apps have no native ad placement; native ads load with the default placement of the app key.
|
||||
* Replace them with your own ids from the LevelPlay dashboard before release.
|
||||
*/
|
||||
export const LEVELPLAY_DEMO = {
|
||||
|
|
@ -10,13 +9,11 @@ export const LEVELPLAY_DEMO = {
|
|||
appKey: '25b63cf85',
|
||||
rewarded: 'syz3d8ekts22q0or',
|
||||
interstitial: 'h3xw38h9214adgxo',
|
||||
banner: '4fpetq4lhe5lsw3e',
|
||||
},
|
||||
ios: {
|
||||
appKey: '8545d445',
|
||||
rewarded: 'qwouvdrkuwivay5q',
|
||||
interstitial: 'wmgt0712uuux8ju4',
|
||||
banner: 'iep3rxsyp9na3rw8',
|
||||
},
|
||||
};
|
||||
//# sourceMappingURL=demo.js.map
|
||||
2
dist/esm/demo.js.map
vendored
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"demo.js","sourceRoot":"","sources":["../../src/demo.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,OAAO,EAAE;QACP,MAAM,EAAE,WAAW;QACnB,QAAQ,EAAE,kBAAkB;QAC5B,YAAY,EAAE,kBAAkB;QAChC,MAAM,EAAE,kBAAkB;KAC3B;IACD,GAAG,EAAE;QACH,MAAM,EAAE,UAAU;QAClB,QAAQ,EAAE,kBAAkB;QAC5B,YAAY,EAAE,kBAAkB;QAChC,MAAM,EAAE,kBAAkB;KAC3B;CACO,CAAC","sourcesContent":["/**\n * Public demo app keys and ad unit ids from Unity's official LevelPlay sample apps\n * (https://github.com/ironsource-mobile/Mediation-Demo-Apps: `Android/Kotlin/.../DemoActivity.kt` and\n * `iOS/Swift SPM/LevelPlayDemo/DemoViewController.swift`). They serve test ads and are safe for development only.\n * The sample apps have no native ad placement; native ads load with the default placement of the app key.\n * Replace them with your own ids from the LevelPlay dashboard before release.\n */\nexport const LEVELPLAY_DEMO = {\n android: {\n appKey: '25b63cf85',\n rewarded: 'syz3d8ekts22q0or',\n interstitial: 'h3xw38h9214adgxo',\n banner: '4fpetq4lhe5lsw3e',\n },\n ios: {\n appKey: '8545d445',\n rewarded: 'qwouvdrkuwivay5q',\n interstitial: 'wmgt0712uuux8ju4',\n banner: 'iep3rxsyp9na3rw8',\n },\n} as const;\n"]}
|
||||
{"version":3,"file":"demo.js","sourceRoot":"","sources":["../../src/demo.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,OAAO,EAAE;QACP,MAAM,EAAE,WAAW;QACnB,QAAQ,EAAE,kBAAkB;QAC5B,YAAY,EAAE,kBAAkB;KACjC;IACD,GAAG,EAAE;QACH,MAAM,EAAE,UAAU;QAClB,QAAQ,EAAE,kBAAkB;QAC5B,YAAY,EAAE,kBAAkB;KACjC;CACO,CAAC","sourcesContent":["/**\n * Public demo app keys and ad unit ids from Unity's official LevelPlay sample apps\n * (https://github.com/ironsource-mobile/Mediation-Demo-Apps: `Android/Kotlin/.../DemoActivity.kt` and\n * `iOS/Swift SPM/LevelPlayDemo/DemoViewController.swift`). They serve test ads and are safe for development only.\n * Replace them with your own ids from the LevelPlay dashboard before release.\n */\nexport const LEVELPLAY_DEMO = {\n android: {\n appKey: '25b63cf85',\n rewarded: 'syz3d8ekts22q0or',\n interstitial: 'h3xw38h9214adgxo',\n },\n ios: {\n appKey: '8545d445',\n rewarded: 'qwouvdrkuwivay5q',\n interstitial: 'wmgt0712uuux8ju4',\n },\n} as const;\n"]}
|
||||
22
dist/esm/web.d.ts
vendored
|
|
@ -1,12 +1,8 @@
|
|||
import { WebPlugin } from '@capacitor/core';
|
||||
import type { AdUnitOptions, BannerIdOptions, BannerResult, Capabilities, ConsentOptions, CreateBannerOptions, DynamicUserIdOptions, DynamicUserIdResult, GetRewardOptions, InitOptions, InitResult, IsReadyResult, LevelPlayPlugin, LoadNativeAdOptions, MetaDataOptions, NativeAdIdOptions, NativeAdRectOptions, PlacementCappedOptions, PlacementCappedResult, Reward, SegmentOptions, SetBannerLayoutOptions, ShowResult, TrackingResult } from './definitions';
|
||||
import type { AdUnitOptions, ConsentOptions, InitOptions, InitResult, IsReadyResult, LevelPlayPlugin, MetaDataOptions, ShowResult, TrackingResult } from './definitions';
|
||||
/**
|
||||
* Web stub. LevelPlay has no web SDK: init rejects with `unimplemented`, ads are never ready and every show resolves
|
||||
* as "not shown" so callers can treat the web like a no-fill platform without special casing.
|
||||
*
|
||||
* 0.3.0: `getCapabilities()` reports nothing supported. Setters, loads of things that cannot exist, hide and destroy
|
||||
* are no-ops; calls that would have to return a native view (`createBanner`, `showBanner`, `setBannerLayout`,
|
||||
* `loadNativeAd`, `showNativeAd`) reject as unimplemented, like `initialize`.
|
||||
*/
|
||||
export declare class LevelPlayWeb extends WebPlugin implements LevelPlayPlugin {
|
||||
private static readonly NO_FILL;
|
||||
|
|
@ -23,20 +19,4 @@ export declare class LevelPlayWeb extends WebPlugin implements LevelPlayPlugin {
|
|||
isReady(): Promise<IsReadyResult>;
|
||||
launchTestSuite(): Promise<void>;
|
||||
validateIntegration(): Promise<void>;
|
||||
getCapabilities(): Promise<Capabilities>;
|
||||
setSegment(_options: SegmentOptions): Promise<void>;
|
||||
setDynamicUserId(_options: DynamicUserIdOptions): Promise<DynamicUserIdResult>;
|
||||
isPlacementCapped(_options: PlacementCappedOptions): Promise<PlacementCappedResult>;
|
||||
getReward(_options: GetRewardOptions): Promise<Reward>;
|
||||
createBanner(_options: CreateBannerOptions): Promise<BannerResult>;
|
||||
loadBanner(_options: BannerIdOptions): Promise<void>;
|
||||
showBanner(_options: BannerIdOptions): Promise<BannerResult>;
|
||||
hideBanner(_options: BannerIdOptions): Promise<void>;
|
||||
setBannerLayout(_options: SetBannerLayoutOptions): Promise<BannerResult>;
|
||||
destroyBanner(_options: BannerIdOptions): Promise<void>;
|
||||
loadNativeAd(_options: LoadNativeAdOptions): Promise<void>;
|
||||
showNativeAd(_options: NativeAdRectOptions): Promise<void>;
|
||||
setNativeAdRect(_options: NativeAdRectOptions): Promise<void>;
|
||||
hideNativeAd(_options: NativeAdIdOptions): Promise<void>;
|
||||
destroyNativeAd(_options: NativeAdIdOptions): Promise<void>;
|
||||
}
|
||||
|
|
|
|||
52
dist/esm/web.js
vendored
|
|
@ -2,10 +2,6 @@ import { WebPlugin } from '@capacitor/core';
|
|||
/**
|
||||
* Web stub. LevelPlay has no web SDK: init rejects with `unimplemented`, ads are never ready and every show resolves
|
||||
* as "not shown" so callers can treat the web like a no-fill platform without special casing.
|
||||
*
|
||||
* 0.3.0: `getCapabilities()` reports nothing supported. Setters, loads of things that cannot exist, hide and destroy
|
||||
* are no-ops; calls that would have to return a native view (`createBanner`, `showBanner`, `setBannerLayout`,
|
||||
* `loadNativeAd`, `showNativeAd`) reject as unimplemented, like `initialize`.
|
||||
*/
|
||||
export class LevelPlayWeb extends WebPlugin {
|
||||
async initialize(_options) {
|
||||
|
|
@ -47,54 +43,6 @@ export class LevelPlayWeb extends WebPlugin {
|
|||
async validateIntegration() {
|
||||
/* nothing to validate */
|
||||
}
|
||||
async getCapabilities() {
|
||||
return { banner: false, nativeAd: false, nativeAdTemplates: [], impressionData: false, adInfoChanged: false };
|
||||
}
|
||||
async setSegment(_options) {
|
||||
/* nothing to forward */
|
||||
}
|
||||
async setDynamicUserId(_options) {
|
||||
return { valid: false };
|
||||
}
|
||||
async isPlacementCapped(_options) {
|
||||
return { capped: false };
|
||||
}
|
||||
async getReward(_options) {
|
||||
return { name: '', amount: 0 };
|
||||
}
|
||||
async createBanner(_options) {
|
||||
throw this.unimplemented('LevelPlay banners are not available on the web.');
|
||||
}
|
||||
async loadBanner(_options) {
|
||||
/* never fills */
|
||||
}
|
||||
async showBanner(_options) {
|
||||
throw this.unimplemented('LevelPlay banners are not available on the web.');
|
||||
}
|
||||
async hideBanner(_options) {
|
||||
/* nothing shown */
|
||||
}
|
||||
async setBannerLayout(_options) {
|
||||
throw this.unimplemented('LevelPlay banners are not available on the web.');
|
||||
}
|
||||
async destroyBanner(_options) {
|
||||
/* nothing to destroy */
|
||||
}
|
||||
async loadNativeAd(_options) {
|
||||
throw this.unimplemented('LevelPlay native ads are not available on the web.');
|
||||
}
|
||||
async showNativeAd(_options) {
|
||||
throw this.unimplemented('LevelPlay native ads are not available on the web.');
|
||||
}
|
||||
async setNativeAdRect(_options) {
|
||||
/* nothing shown */
|
||||
}
|
||||
async hideNativeAd(_options) {
|
||||
/* nothing shown */
|
||||
}
|
||||
async destroyNativeAd(_options) {
|
||||
/* nothing to destroy */
|
||||
}
|
||||
}
|
||||
LevelPlayWeb.NO_FILL = {
|
||||
shown: false,
|
||||
|
|
|
|||
2
dist/esm/web.js.map
vendored
55
dist/plugin.cjs.js
vendored
|
|
@ -6,7 +6,6 @@ var core = require('@capacitor/core');
|
|||
* Public demo app keys and ad unit ids from Unity's official LevelPlay sample apps
|
||||
* (https://github.com/ironsource-mobile/Mediation-Demo-Apps: `Android/Kotlin/.../DemoActivity.kt` and
|
||||
* `iOS/Swift SPM/LevelPlayDemo/DemoViewController.swift`). They serve test ads and are safe for development only.
|
||||
* The sample apps have no native ad placement; native ads load with the default placement of the app key.
|
||||
* Replace them with your own ids from the LevelPlay dashboard before release.
|
||||
*/
|
||||
const LEVELPLAY_DEMO = {
|
||||
|
|
@ -14,13 +13,11 @@ const LEVELPLAY_DEMO = {
|
|||
appKey: '25b63cf85',
|
||||
rewarded: 'syz3d8ekts22q0or',
|
||||
interstitial: 'h3xw38h9214adgxo',
|
||||
banner: '4fpetq4lhe5lsw3e',
|
||||
},
|
||||
ios: {
|
||||
appKey: '8545d445',
|
||||
rewarded: 'qwouvdrkuwivay5q',
|
||||
interstitial: 'wmgt0712uuux8ju4',
|
||||
banner: 'iep3rxsyp9na3rw8',
|
||||
},
|
||||
};
|
||||
|
||||
|
|
@ -31,10 +28,6 @@ const LevelPlay = core.registerPlugin('LevelPlay', {
|
|||
/**
|
||||
* Web stub. LevelPlay has no web SDK: init rejects with `unimplemented`, ads are never ready and every show resolves
|
||||
* as "not shown" so callers can treat the web like a no-fill platform without special casing.
|
||||
*
|
||||
* 0.3.0: `getCapabilities()` reports nothing supported. Setters, loads of things that cannot exist, hide and destroy
|
||||
* are no-ops; calls that would have to return a native view (`createBanner`, `showBanner`, `setBannerLayout`,
|
||||
* `loadNativeAd`, `showNativeAd`) reject as unimplemented, like `initialize`.
|
||||
*/
|
||||
class LevelPlayWeb extends core.WebPlugin {
|
||||
async initialize(_options) {
|
||||
|
|
@ -76,54 +69,6 @@ class LevelPlayWeb extends core.WebPlugin {
|
|||
async validateIntegration() {
|
||||
/* nothing to validate */
|
||||
}
|
||||
async getCapabilities() {
|
||||
return { banner: false, nativeAd: false, nativeAdTemplates: [], impressionData: false, adInfoChanged: false };
|
||||
}
|
||||
async setSegment(_options) {
|
||||
/* nothing to forward */
|
||||
}
|
||||
async setDynamicUserId(_options) {
|
||||
return { valid: false };
|
||||
}
|
||||
async isPlacementCapped(_options) {
|
||||
return { capped: false };
|
||||
}
|
||||
async getReward(_options) {
|
||||
return { name: '', amount: 0 };
|
||||
}
|
||||
async createBanner(_options) {
|
||||
throw this.unimplemented('LevelPlay banners are not available on the web.');
|
||||
}
|
||||
async loadBanner(_options) {
|
||||
/* never fills */
|
||||
}
|
||||
async showBanner(_options) {
|
||||
throw this.unimplemented('LevelPlay banners are not available on the web.');
|
||||
}
|
||||
async hideBanner(_options) {
|
||||
/* nothing shown */
|
||||
}
|
||||
async setBannerLayout(_options) {
|
||||
throw this.unimplemented('LevelPlay banners are not available on the web.');
|
||||
}
|
||||
async destroyBanner(_options) {
|
||||
/* nothing to destroy */
|
||||
}
|
||||
async loadNativeAd(_options) {
|
||||
throw this.unimplemented('LevelPlay native ads are not available on the web.');
|
||||
}
|
||||
async showNativeAd(_options) {
|
||||
throw this.unimplemented('LevelPlay native ads are not available on the web.');
|
||||
}
|
||||
async setNativeAdRect(_options) {
|
||||
/* nothing shown */
|
||||
}
|
||||
async hideNativeAd(_options) {
|
||||
/* nothing shown */
|
||||
}
|
||||
async destroyNativeAd(_options) {
|
||||
/* nothing to destroy */
|
||||
}
|
||||
}
|
||||
LevelPlayWeb.NO_FILL = {
|
||||
shown: false,
|
||||
|
|
|
|||
2
dist/plugin.cjs.js.map
vendored
55
dist/plugin.js
vendored
|
|
@ -5,7 +5,6 @@ var capacitorLevelPlay = (function (exports, core) {
|
|||
* Public demo app keys and ad unit ids from Unity's official LevelPlay sample apps
|
||||
* (https://github.com/ironsource-mobile/Mediation-Demo-Apps: `Android/Kotlin/.../DemoActivity.kt` and
|
||||
* `iOS/Swift SPM/LevelPlayDemo/DemoViewController.swift`). They serve test ads and are safe for development only.
|
||||
* The sample apps have no native ad placement; native ads load with the default placement of the app key.
|
||||
* Replace them with your own ids from the LevelPlay dashboard before release.
|
||||
*/
|
||||
const LEVELPLAY_DEMO = {
|
||||
|
|
@ -13,13 +12,11 @@ var capacitorLevelPlay = (function (exports, core) {
|
|||
appKey: '25b63cf85',
|
||||
rewarded: 'syz3d8ekts22q0or',
|
||||
interstitial: 'h3xw38h9214adgxo',
|
||||
banner: '4fpetq4lhe5lsw3e',
|
||||
},
|
||||
ios: {
|
||||
appKey: '8545d445',
|
||||
rewarded: 'qwouvdrkuwivay5q',
|
||||
interstitial: 'wmgt0712uuux8ju4',
|
||||
banner: 'iep3rxsyp9na3rw8',
|
||||
},
|
||||
};
|
||||
|
||||
|
|
@ -30,10 +27,6 @@ var capacitorLevelPlay = (function (exports, core) {
|
|||
/**
|
||||
* Web stub. LevelPlay has no web SDK: init rejects with `unimplemented`, ads are never ready and every show resolves
|
||||
* as "not shown" so callers can treat the web like a no-fill platform without special casing.
|
||||
*
|
||||
* 0.3.0: `getCapabilities()` reports nothing supported. Setters, loads of things that cannot exist, hide and destroy
|
||||
* are no-ops; calls that would have to return a native view (`createBanner`, `showBanner`, `setBannerLayout`,
|
||||
* `loadNativeAd`, `showNativeAd`) reject as unimplemented, like `initialize`.
|
||||
*/
|
||||
class LevelPlayWeb extends core.WebPlugin {
|
||||
async initialize(_options) {
|
||||
|
|
@ -75,54 +68,6 @@ var capacitorLevelPlay = (function (exports, core) {
|
|||
async validateIntegration() {
|
||||
/* nothing to validate */
|
||||
}
|
||||
async getCapabilities() {
|
||||
return { banner: false, nativeAd: false, nativeAdTemplates: [], impressionData: false, adInfoChanged: false };
|
||||
}
|
||||
async setSegment(_options) {
|
||||
/* nothing to forward */
|
||||
}
|
||||
async setDynamicUserId(_options) {
|
||||
return { valid: false };
|
||||
}
|
||||
async isPlacementCapped(_options) {
|
||||
return { capped: false };
|
||||
}
|
||||
async getReward(_options) {
|
||||
return { name: '', amount: 0 };
|
||||
}
|
||||
async createBanner(_options) {
|
||||
throw this.unimplemented('LevelPlay banners are not available on the web.');
|
||||
}
|
||||
async loadBanner(_options) {
|
||||
/* never fills */
|
||||
}
|
||||
async showBanner(_options) {
|
||||
throw this.unimplemented('LevelPlay banners are not available on the web.');
|
||||
}
|
||||
async hideBanner(_options) {
|
||||
/* nothing shown */
|
||||
}
|
||||
async setBannerLayout(_options) {
|
||||
throw this.unimplemented('LevelPlay banners are not available on the web.');
|
||||
}
|
||||
async destroyBanner(_options) {
|
||||
/* nothing to destroy */
|
||||
}
|
||||
async loadNativeAd(_options) {
|
||||
throw this.unimplemented('LevelPlay native ads are not available on the web.');
|
||||
}
|
||||
async showNativeAd(_options) {
|
||||
throw this.unimplemented('LevelPlay native ads are not available on the web.');
|
||||
}
|
||||
async setNativeAdRect(_options) {
|
||||
/* nothing shown */
|
||||
}
|
||||
async hideNativeAd(_options) {
|
||||
/* nothing shown */
|
||||
}
|
||||
async destroyNativeAd(_options) {
|
||||
/* nothing to destroy */
|
||||
}
|
||||
}
|
||||
LevelPlayWeb.NO_FILL = {
|
||||
shown: false,
|
||||
|
|
|
|||
2
dist/plugin.js.map
vendored
|
|
@ -1,590 +0,0 @@
|
|||
# capacitor-levelplay 0.3.0 · API design
|
||||
|
||||
Status: phase 3. `src/definitions.ts` and `src/web.ts` carry the new API; the Android bridge (phase 2, §15) and the
|
||||
iOS bridge (phase 3, §16) implement all of it. The owner's answers to the open questions are recorded in §14.
|
||||
|
||||
Scope (owner approved): banners, native ads (template overlay), impression-level revenue, `adInfoChanged`, placement
|
||||
capping and reward lookup, segments, dynamic user id, full backwards compatibility with 0.2.x, and a Capacitor 7
|
||||
compatibility study.
|
||||
|
||||
## 0. Sources and method
|
||||
|
||||
Every native name below was read from the SDK binaries of **LevelPlay 9.6.1**, not only from the docs:
|
||||
|
||||
- **Android**: `com.unity3d.ads-mediation:mediation-sdk:9.6.1` AAR from Maven Central, `classes.jar` listed with
|
||||
`javap -public` (JDK 21). The AAR manifest declares `minSdkVersion="19"`.
|
||||
- **iOS**: `IronSource.xcframework` (`CFBundleShortVersionString` 9.6.1, `MinimumOSVersion` 12.0) from the
|
||||
`LevelPlay-Swift-Package` SPM checkout, `ios-arm64/IronSource.framework/Headers/*.h`. `IronSource.h` defines
|
||||
`MEDIATION_SDK_VERSION = @"9.6.1"`. The framework ships no `.swiftinterface`; Swift names come from
|
||||
`NS_SWIFT_NAME` annotations and the ObjC importer.
|
||||
- Unity docs (behaviour, not names): `docs.unity.com/en-us/grow/levelplay/sdk/{android,ios}/banner-integration`,
|
||||
`.../android/native-ads-integration`, `.../flutter/native-ads-integration`.
|
||||
- Capacitor: `@capacitor/android` and `@capacitor/ios` 7.6.9 and 8.5.3 npm tarballs, diffed.
|
||||
|
||||
Notation: `A:` Android (package `com.unity3d.mediation` unless a full name is given), `I:` iOS (header file name).
|
||||
|
||||
## 1. Compatibility rules for 0.3.0
|
||||
|
||||
- No existing method, option, event or type is renamed or removed. `AdFormat` stays `'rewarded' | 'interstitial'`
|
||||
(widening it would break exhaustive `switch` statements in 0.2.x code), so banners and native ads get their own
|
||||
methods and their own event names (`banner*`, `nativeAd*`) instead of reusing `loaded`, `clicked` ...
|
||||
- `AdInfo` only gains optional fields. `LevelPlayEventName` only gains members.
|
||||
- Existing events keep their payloads; `adInfoChanged` and `impressionData` are new names.
|
||||
- Reject codes reuse the existing string style (`INVALID_ARGUMENT`, `NO_VIEW_CONTROLLER`).
|
||||
|
||||
## 2. Capabilities
|
||||
|
||||
`getCapabilities(): Promise<Capabilities>` → `{ banner, nativeAd, nativeAdTemplates, impressionData, adInfoChanged }`.
|
||||
|
||||
| | Android | iOS | Web |
|
||||
|---|---|---|---|
|
||||
| `banner` | true | true | false |
|
||||
| `nativeAd` | true | true | false |
|
||||
| `nativeAdTemplates` | `['small','medium']` | `['small','medium']` | `[]` |
|
||||
| `impressionData` | true | true | false |
|
||||
| `adInfoChanged` | true | true | false |
|
||||
|
||||
It is the honest switch the owner asked for: if a platform implementation ever has to drop a feature (for example
|
||||
templates do not pass review on one OS), the flag goes `false` and the methods reject `UNSUPPORTED`, without an API
|
||||
change.
|
||||
|
||||
## 3. Banners
|
||||
|
||||
### 3.1 TS API
|
||||
|
||||
```ts
|
||||
createBanner({ adUnitId, bannerId?, size?: 'BANNER'|'LARGE'|'MEDIUM_RECTANGLE'|'LEADERBOARD'|'ADAPTIVE'|'CUSTOM',
|
||||
customSize?: { width, height }, adaptiveWidth?, placementName?, bidFloor?, position?: 'top'|'bottom'|'center',
|
||||
offsetX?, offsetY?, respectSafeArea? }): Promise<BannerResult>
|
||||
loadBanner({ bannerId }): Promise<void>
|
||||
showBanner({ bannerId }): Promise<BannerResult>
|
||||
hideBanner({ bannerId }): Promise<void>
|
||||
setBannerLayout({ bannerId, position?, offsetX?, offsetY?, respectSafeArea? }): Promise<BannerResult>
|
||||
destroyBanner({ bannerId }): Promise<void>
|
||||
// BannerResult = { bannerId, adSize: { width, height, description?, isAdaptive? }, frame: Rect, visible }
|
||||
```
|
||||
|
||||
Defaults: `bannerId = adUnitId`, `size = 'ADAPTIVE'` (`'CUSTOM'` when only `customSize` is given), `position = 'bottom'`, offsets 0, `respectSafeArea = true`.
|
||||
Several banners can exist at once, keyed by `bannerId` (one ad unit may back several banners).
|
||||
|
||||
Typical flow: `createBanner` → `loadBanner` → `showBanner` (immediately, or on `bannerLoaded`) → `hideBanner` during
|
||||
gameplay → `showBanner` → `destroyBanner` when leaving the screen.
|
||||
|
||||
### 3.2 Native mapping
|
||||
|
||||
| Plugin | Android (`com.unity3d.mediation.banner`) | iOS |
|
||||
|---|---|---|
|
||||
| view class | `LevelPlayBannerAdView extends FrameLayout`, ctor `(Context, String adUnitId, LevelPlayBannerAdView.Config)` | `LPMBannerAdView : UIView`, `initWithAdUnitId:config:` (LPMBannerAdView.h) |
|
||||
| config | `LevelPlayBannerAdView.Config.Builder().setAdSize(LevelPlayAdSize).setBidFloor(double).setPlacementName(String).build()` | `LPMBannerAdViewConfigBuilder` `set(adSize:)`, `set(bidFloor:)` (NSNumber), `set(placementName:)`, `build()` |
|
||||
| `BANNER` | `LevelPlayAdSize.BANNER` | `LPMAdSize.bannerSize()` |
|
||||
| `LARGE` | `LevelPlayAdSize.LARGE` | `LPMAdSize.largeSize()` |
|
||||
| `MEDIUM_RECTANGLE` | `LevelPlayAdSize.MEDIUM_RECTANGLE` | `LPMAdSize.mediumRectangleSize()` |
|
||||
| `LEADERBOARD` | `LevelPlayAdSize.LEADERBOARD` | `LPMAdSize.leaderBoardSize()` |
|
||||
| `ADAPTIVE` | `LevelPlayAdSize.createAdaptiveAdSize(Context, Integer width)` | `LPMAdSize.createAdaptiveAdSize(withWidth: CGFloat)` (nullable: `nil` before init) |
|
||||
| `CUSTOM` (Q5) | `LevelPlayAdSize.createCustomSize(int width, int height)` (dp) | `LPMAdSize.customSizeWithWidth:height:` |
|
||||
| size readout | `getWidth()`, `getHeight()`, `getDescription()`, `isAdaptive()` | `width`, `height`, `sizeDescription`, `isAdaptive` |
|
||||
| listener | `setBannerListener(LevelPlayBannerAdViewListener)` | `setDelegate(LPMBannerAdViewDelegate)` |
|
||||
| impression data | `setImpressionDataListener(LevelPlayImpressionDataListener)` | `setImpressionDataDelegate:` |
|
||||
| load | `loadAd()` (Activity context from the ctor) | `loadAdWithViewController:` (`bridge.viewController`) |
|
||||
| show / hide | `setVisibility(VISIBLE/GONE)` + `resumeAutoRefresh()` / `pauseAutoRefresh()` | `isHidden` + `resumeAutoRefresh` / `pauseAutoRefresh` |
|
||||
| destroy | `destroy()` then remove from parent | `destroy` then `removeFromSuperview` |
|
||||
|
||||
The SDK has no show / hide API; visibility is the host view's job. Unity's docs say pause / resume only matter when a
|
||||
refresh interval is set on the dashboard, and that a resumed banner completes the remaining refresh time. Android's
|
||||
`IronSourceError.ERROR_BN_RELOAD_SKIP_INVISIBLE` shows the SDK itself skips refreshes of invisible banners; pausing
|
||||
explicitly makes that deterministic on both platforms.
|
||||
|
||||
Adaptive width units: the plugin passes CSS px. On Android 1 CSS px = 1 dp in a Capacitor WebView at default zoom,
|
||||
and the `Integer` width **is dp** (§14 Q3): in the bytecode, `createAdaptiveAdSize` (`com.ironsource.g1.a`) compares
|
||||
the width with the preset widths (320 / 728) and, for a `null` or negative width, falls back to
|
||||
`DisplayMetrics.widthPixels / density` rounded (`com.ironsource.e5`), i.e. the screen width in dp. Checked on the emulator (Pixel 9 Pro, density 3): an
|
||||
`ADAPTIVE` banner for 426 CSS px reports `adSize` 426 x 50 and its `LevelPlayBannerAdView` measures 1278 x 150 px.
|
||||
On iOS 1 CSS px = 1 pt.
|
||||
Both factories need a finished init (iOS returns `nil` before init, documented in LPMAdSize.h), so `createBanner`
|
||||
rejects `NOT_INITIALIZED` before `initialize()` resolved. Unity's docs also say to create banners only after init
|
||||
succeeded.
|
||||
|
||||
### 3.3 Banner events
|
||||
|
||||
| Event | Android `LevelPlayBannerAdViewListener` | iOS `LPMBannerAdViewDelegate` |
|
||||
|---|---|---|
|
||||
| `bannerLoaded` | `onAdLoaded(LevelPlayAdInfo)` | `didLoadAdWithAdInfo:` (required) |
|
||||
| `bannerLoadFailed` | `onAdLoadFailed(LevelPlayAdError)` | `didFailToLoadAdWithAdUnitId:error:` (required) |
|
||||
| `bannerDisplayed` | `onAdDisplayed` (default method) | `didDisplayAdWithAdInfo:` (optional) |
|
||||
| `bannerDisplayFailed` | `onAdDisplayFailed(LevelPlayAdInfo, LevelPlayAdError)` | `didFailToDisplayAdWithAdInfo:error:` |
|
||||
| `bannerClicked` | `onAdClicked` | `didClickAdWithAdInfo:` |
|
||||
| `bannerExpanded` | `onAdExpanded` | `didExpandAdWithAdInfo:` |
|
||||
| `bannerCollapsed` | `onAdCollapsed` | `didCollapseAdWithAdInfo:` |
|
||||
| `bannerLeftApplication` | `onAdLeftApplication` | `didLeaveAppWithAdInfo:` |
|
||||
|
||||
Payload: `BannerEvent { bannerId, adUnitId, adInfo?, frame? }`, plus `error` for the two failure events. All eight
|
||||
callbacks exist on both platforms in 9.6.1. There is **no** `adInfoChanged` callback for banners on either platform.
|
||||
|
||||
## 4. Native ads
|
||||
|
||||
### 4.1 What 9.6.1 has
|
||||
|
||||
- Android: `com.ironsource.mediationsdk.ads.nativead.LevelPlayNativeAd`, built with
|
||||
`new LevelPlayNativeAd.Builder().withPlacementName(String).withListener(LevelPlayNativeAdListener).withActivity(Activity).build()`;
|
||||
`loadAd()`, `destroyAd()`, asset getters `getTitle()`, `getAdvertiser()`, `getBody()`, `getCallToAction()`,
|
||||
`getIcon()` (`NativeAdDataInterface.Image`). Views: `NativeAdLayout extends FrameLayout` with `setTitleView`,
|
||||
`setAdvertiserView`, `setBodyView`, `setIconView`, `setCallToActionView`, `setMediaView(LevelPlayMediaView)`,
|
||||
`registerNativeAdViews(LevelPlayNativeAd)`. Listener (`LevelPlayNativeAdListener` = `NativeAdLoadListener` +
|
||||
`NativeAdInteractionListener`): `onAdLoaded(ad, AdInfo)`, `onAdLoadFailed(ad, IronSourceError)`,
|
||||
`onAdImpression(ad, AdInfo)`, `onAdClicked(ad, AdInfo)`. `AdInfo` is `com.ironsource.mediationsdk.adunit.adapter.utility.AdInfo`.
|
||||
- iOS: `LevelPlayNativeAd` (`initWithBuilder:`, `loadAd`, `destroyAd`, `setDelegate:`, asset properties `title`,
|
||||
`advertiser`, `body`, `callToAction`, `icon` (`ISNativeAdDataImage` with `image` / `url`)), `LevelPlayNativeAdBuilder`
|
||||
(`withViewController:`, `withPlacementName:`, `withDelegate:`, `build`), view `ISNativeAdView : UIView` with outlets
|
||||
`adAppIcon`, `adTitleView`, `adAdvertiserView`, `adBodyView`, `adMediaView` (`LevelPlayMediaView`),
|
||||
`adCallToActionView` and `registerNativeAdViews:`. Delegate `LevelPlayNativeAdDelegate` =
|
||||
`ISNativeAdLoadDelegate` (`didLoad:withAdInfo:`, `didFailToLoad:withError:`) + `ISNativeAdInteractionDelegate`
|
||||
(`didRecordImpression:withAdInfo:`, `didClick:withAdInfo:`), with `ISAdInfo`.
|
||||
|
||||
Findings that shape the API:
|
||||
|
||||
1. **No template views in the SDK on either platform.** There is no `LevelPlayNativeAdTemplate`, template type or
|
||||
template layout resource in the AAR (its `res/` has only `values/`) or in the iOS headers. Unity's Flutter and
|
||||
React Native wrappers ship their own XML (Android) and XIB (iOS) templates (`LevelPlayTemplateType.SMALL` /
|
||||
`MEDIUM`). This plugin does the same: it owns two programmatic layouts per platform, `small` (no media view) and
|
||||
`medium` (with `LevelPlayMediaView`). `nativeAdSupported` is therefore `true` on both platforms, with the
|
||||
rendering being the plugin's code.
|
||||
2. **Native ads have no ad unit id in 9.6.1.** Both builders take a placement name only. The API exposes
|
||||
`placementName`, not `adUnitId`, and says so.
|
||||
3. **One ad object per load.** Unity: "destroy the ad object and create a new one for every new load". So
|
||||
`loadNativeAd` replaces the slot's previous ad.
|
||||
4. **Native ad info is the old `AdInfo` / `ISAdInfo`** (auction id, network, instance, country, revenue, precision,
|
||||
ab, segment, encrypted CPM; iOS adds `conversion_value`). No ad unit, ad id or placement in it. Hence a separate
|
||||
`NativeAdInfo` type instead of reusing `AdInfo` (whose `adUnitId` is required).
|
||||
5. **No per-ad impression-data listener for native ads** (only banners, interstitials and rewarded have
|
||||
`setImpressionDataListener` / `setImpressionDataDelegate:`). See §5 for how `impressionData` still covers them.
|
||||
6. Policy from Unity's guide: the ad must be marked as an ad, and the privacy / AdChoices icon belongs in the bottom
|
||||
left. Both templates draw an "Ad" badge and leave the bottom-left corner free.
|
||||
|
||||
### 4.2 TS API
|
||||
|
||||
```ts
|
||||
loadNativeAd({ nativeAdId, placementName?, template?: 'small'|'medium', style?: NativeAdTemplateStyle }): Promise<void>
|
||||
showNativeAd({ nativeAdId, rect: { x, y, width, height } }): Promise<void>
|
||||
setNativeAdRect({ nativeAdId, rect }): Promise<void>
|
||||
hideNativeAd({ nativeAdId }): Promise<void>
|
||||
destroyNativeAd({ nativeAdId }): Promise<void>
|
||||
// events: nativeAdLoaded, nativeAdLoadFailed, nativeAdImpression, nativeAdClicked (NativeAdEvent / NativeAdErrorEvent)
|
||||
```
|
||||
|
||||
`style`: `backgroundColor`, `titleColor`, `bodyColor`, `callToActionBackgroundColor`, `callToActionTextColor`
|
||||
(`#RRGGBB[AA]`), `cornerRadius` (CSS px), and (Q6) `titleFont`, `bodyFont`, `callToActionFont` as
|
||||
`{ family?, size? }`: a system family name or a `.ttf` / `.otf` path inside the web assets (Android
|
||||
`Typeface.createFromAsset(assets, "public/" + path)`, iOS `CTFontManagerRegisterFontsForURL` on the file in the
|
||||
app's `public` folder), size in CSS px (dp / pt, not scaled by the system font size). Defaults are the system font.
|
||||
The CTA is a native button so the SDK can register it. Android builds the templates in code (no XML resources), so
|
||||
every style value applies without inflating.
|
||||
|
||||
Flow: `loadNativeAd` → `nativeAdLoaded` → measure a placeholder element (`getBoundingClientRect()`) →
|
||||
`showNativeAd({ rect })` → on layout change `setNativeAdRect` → `destroyNativeAd`, or `loadNativeAd` again for a new
|
||||
creative.
|
||||
|
||||
Mapping: build → `loadAd`; on show, inflate the template into a `NativeAdLayout` / `ISNativeAdView`, fill the
|
||||
asset views from the getters, call the `set*View` setters (Android) / assign the outlets (iOS) and
|
||||
`registerNativeAdViews`, then place it in the overlay (§6). `destroyNativeAd` → `destroyAd()` + remove view.
|
||||
|
||||
## 5. Impression-level revenue: `impressionData`
|
||||
|
||||
### 5.1 API
|
||||
|
||||
`addListener('impressionData', (d: ImpressionData) => ...)`. Payload fields map 1:1 to the SDK data classes:
|
||||
|
||||
| `ImpressionData` | Android `LevelPlayImpressionData` | iOS `LPMImpressionData` |
|
||||
|---|---|---|
|
||||
| `auctionId` | `getAuctionId()` | `auctionId` |
|
||||
| `adUnitId` | `getMediationAdUnitId()` | `mediationAdUnitId` |
|
||||
| `adUnitName` | `getMediationAdUnitName()` | `mediationAdUnitName` |
|
||||
| `adFormat` | `getAdFormat()` | `adFormat` |
|
||||
| `adNetwork` | `getAdNetwork()` | `adNetwork` |
|
||||
| `instanceName` | `getInstanceName()` | `instanceName` |
|
||||
| `instanceId` | `getInstanceId()` | `instanceId` |
|
||||
| `country` | `getCountry()` | `country` |
|
||||
| `placement` | `getPlacement()` | `placement` |
|
||||
| `revenue` | `getRevenue()` (`Double`, nullable) | `revenue` (`NSNumber`) |
|
||||
| `precision` | `getPrecision()` | `precision` |
|
||||
| `ab` | `getAb()` | `ab` |
|
||||
| `segmentName` | `getSegmentName()` | `segmentName` |
|
||||
| `encryptedCPM` | `getEncryptedCPM()` | `encryptedCpm` |
|
||||
| `creativeId` | `getCreativeId()` | `creativeId` |
|
||||
| `conversionValue` | not in the class | `conversionValue` (`NSNumber`) |
|
||||
| `allData` | `getAllData()` (`JSONObject`) | `allData` (`NSDictionary`) |
|
||||
|
||||
**Not available: `lifetimeRevenue`.** It is not a property of either 9.6.1 class, not one of the Android
|
||||
`IMPRESSION_DATA_KEY_*` constants (auctionId, adFormat, mediationAdUnitName, mediationAdUnitId, country, ab,
|
||||
segmentName, placement, adNetwork, instanceName, instanceId, revenue, precision, encryptedCPM, creativeId), and the
|
||||
string does not occur in the iOS binary. Apps that need lifetime revenue sum `revenue` themselves. If the server
|
||||
sends it anyway it shows up in `allData`. Observed in phase 2 (Android, demo app key): the server does send
|
||||
`allData.lifetimeRevenue` (per ad unit, cumulative in the session), so it is readable there; it stays out of the
|
||||
typed fields because the SDK classes do not promise it.
|
||||
|
||||
### 5.2 Registration
|
||||
|
||||
9.6.1 deprecates the global listener for publishers:
|
||||
- A: `LevelPlay.addImpressionDataListener` / `removeImpressionDataListener` carry `@kotlin.Deprecated("Publishers:
|
||||
use setImpressionDataListener() on each LevelPlayBannerAdView, LevelPlayInterstitialAd, or LevelPlayRewardedAd ...")`.
|
||||
- I: `+[LevelPlay addImpressionDataDelegate:]` is `DEPRECATED_MSG_ATTRIBUTE` with the same advice
|
||||
(`setImpressionDataDelegate:` on each `LPMBannerAdView`, `LPMInterstitialAd`, `LPMRewardedAd`).
|
||||
- `addImpressionLevelRevenueListener(listener, subscriberId)` is for approved third-party SDKs only (needs a
|
||||
subscriber id from Unity), not for apps.
|
||||
|
||||
Design (decided, Q1): the plugin attaches its own impression listener to **every** rewarded, interstitial
|
||||
and banner object it creates (the holders already exist per ad unit). The JS side can add the listener at any time,
|
||||
including before `initialize()`. Native ads have no per-ad listener, so on `onAdImpression` / `didRecordImpression:` the plugin
|
||||
emits an `impressionData` built from the native `AdInfo` (`adFormat: 'nativead'`, no ad unit / placement /
|
||||
creative fields). This avoids deprecated APIs and still covers every format.
|
||||
|
||||
Queue (decided, Q2): while no JS `impressionData` listener exists, impressions are kept in a plugin-owned FIFO
|
||||
queue capped at 100 (the oldest is dropped beyond that) and flushed, in order, when the first `impressionData`
|
||||
listener is added (Android overrides `Plugin.addListener`; Capacitor's own `retainUntilConsumed` is not used because
|
||||
its queue is unbounded). With a listener present they are sent directly.
|
||||
|
||||
## 6. Overlay positioning (banners and native ads)
|
||||
|
||||
### 6.1 Coordinate space
|
||||
|
||||
All public geometry is in **CSS px relative to the WebView viewport** (the space of `getBoundingClientRect()` on a
|
||||
non-scrolled page). Capacitor WebViews render at 1 CSS px = 1 dp (Android, default zoom / `initial-scale=1`) and
|
||||
1 CSS px = 1 pt (iOS). Pages that change the viewport scale break this; documented as unsupported.
|
||||
|
||||
### 6.2 Host view
|
||||
|
||||
- **Android**: a plugin-owned `FrameLayout` "overlay host" added to the WebView's parent (`(ViewGroup)
|
||||
bridge.getWebView().getParent()`, the Capacitor `CoordinatorLayout`) right after the WebView, so it draws above it.
|
||||
It is kept equal to the WebView's bounds with an `OnLayoutChangeListener` on the WebView. The host is not clickable
|
||||
and has no touch listener, so touches outside ad views fall through to the WebView below (Android dispatches to
|
||||
siblings in reverse z-order until one consumes). Ad views inside it consume their own touches.
|
||||
- **iOS**: a plugin-owned `UIView` subclass added to `bridge.viewController.view` above the WebView's content, frame
|
||||
and `autoresizingMask` following the WebView. In Capacitor `CAPBridgeViewController.loadView` sets
|
||||
`view = webView`, so that view *is* the `WKWebView`: the overlay is its last subview, above `WKScrollView`, and does
|
||||
not scroll. (The WebView's superview belongs to UIKit / the presentation and a full-screen modal can reinsert the
|
||||
WebView above a sibling there, so it is not used.) Its `hitTest(_:with:)` returns `nil` when the hit view is
|
||||
itself, so only ad subviews receive touches.
|
||||
- Full-screen ads (rewarded / interstitial / expanded banners / test suite) are presented as Activities / modal view
|
||||
controllers and therefore always cover the overlay.
|
||||
|
||||
### 6.3 Safe area
|
||||
|
||||
`safeRect = webViewRect ∩ (window bounds − system insets)`, converted into WebView-local CSS px.
|
||||
|
||||
- Android: insets from `ViewCompat.getRootWindowInsets(webView)` with
|
||||
`WindowInsetsCompat.Type.systemBars() | Type.displayCutout()`. Intersecting with the WebView's on-screen rect
|
||||
(`getLocationInWindow`) makes this correct in every Capacitor mode: Capacitor 7 `android.adjustMarginsForEdgeToEdge`
|
||||
(margins on the WebView), Capacitor 8 `SystemBars` `insetsHandling: 'native'` (padding on the WebView parent) or
|
||||
`'css'` (WebView edge to edge, insets only in CSS). Insets are re-read in the host's layout pass and via
|
||||
`ViewCompat.setOnApplyWindowInsetsListener` on the host (the host returns the insets unconsumed so it never steals
|
||||
them from Capacitor's own listener on the WebView).
|
||||
- iOS: `overlayHost.safeAreaInsets` (same frame as the WebView), updated in `safeAreaInsetsDidChange` /
|
||||
`layoutSubviews`.
|
||||
|
||||
`respectSafeArea: false` uses the raw WebView rect. Native ad rects are taken literally (the page already laid them
|
||||
out against `env(safe-area-inset-*)`), only clamped to the WebView rect.
|
||||
|
||||
### 6.4 Placement maths (banner)
|
||||
|
||||
```
|
||||
x = safe.x + (safe.width − bannerWidth) / 2 + offsetX
|
||||
y = top: safe.y + offsetY
|
||||
bottom: safe.y + safe.height − bannerHeight + offsetY
|
||||
center: safe.y + (safe.height − bannerHeight) / 2 + offsetY
|
||||
```
|
||||
|
||||
Recomputed on every host layout pass (rotation, split screen, multi-window, keyboard resizing the WebView, foldables).
|
||||
Adaptive banners (decided, Q4): when the banner was created without `adaptiveWidth` and the safe-area width changes
|
||||
(rotation, split screen, window resize), the plugin destroys the banner view and creates a new one with
|
||||
`createAdaptiveAdSize(newWidth)` after the layout settled (debounced 250 ms), keeping `bannerId`, layout, visibility
|
||||
and placement, and calls `loadAd()` again if the old view had been loaded. The new creative arrives as a normal
|
||||
`bannerLoaded` with the new `frame`. A fixed `adaptiveWidth` and the presets are never recreated.
|
||||
|
||||
### 6.5 WebView scroll and z-order
|
||||
|
||||
Overlays are fixed to the viewport; they do not scroll with page content. Games normally have no page scroll. For
|
||||
scrolling pages the app calls `setNativeAdRect` on scroll / resize (documented). Z-order inside the host: creation
|
||||
order; a later `showBanner` / `showNativeAd` brings that view to the front.
|
||||
|
||||
### 6.6 Lifecycle
|
||||
|
||||
On `handleOnDestroy` (Android) / plugin deinit the plugin destroys every banner and native ad. On app pause the SDK
|
||||
manages refresh itself; the plugin does not pause banners on `handleOnPause`.
|
||||
|
||||
## 7. `adInfoChanged`
|
||||
|
||||
`addListener('adInfoChanged', (e: AdEvent) => ...)`, same payload as `loaded`. Sources: A
|
||||
`LevelPlayRewardedAdListener.onAdInfoChanged` / `LevelPlayInterstitialAdListener.onAdInfoChanged` (default methods);
|
||||
I `LPMRewardedAdDelegate` / `LPMInterstitialAdDelegate` `didChangeAdInfo(_:)` (optional). The 0.2.x holders already
|
||||
implement these as empty bodies; phase 2 only emits. Banner listener / delegate have no such callback in 9.6.1;
|
||||
native ads neither.
|
||||
|
||||
## 8. Placements, capping and rewards
|
||||
|
||||
| Plugin | Android | iOS |
|
||||
|---|---|---|
|
||||
| `isPlacementCapped({ format: 'rewarded', placementName })` | `LevelPlayRewardedAd.isPlacementCapped(String)` (static) | `+[LPMRewardedAd isPlacementCapped:]` |
|
||||
| `isPlacementCapped({ format: 'interstitial', ... })` | `LevelPlayInterstitialAd.isPlacementCapped(String)` (static) | `+[LPMInterstitialAd isPlacementCapped:]` |
|
||||
| `getReward({ adUnitId, placementName? })` | `LevelPlayRewardedAd.getReward(String)` / `getReward()` (instance) | `-[LPMRewardedAd getRewardWithPlacementName:]` (`getReward(placementName:)`) |
|
||||
|
||||
`getReward` uses the plugin's per-ad-unit `LevelPlayRewardedAd` holder (created on demand, as `loadRewarded` does).
|
||||
iOS documents "an empty reward on failures (`name: ""` and `amount: 0`)"; the plugin returns the same shape on both
|
||||
platforms and the web.
|
||||
|
||||
Not in 9.6.1: the 7.x/8.x `IronSource.getRewardedVideoPlacementInfo` / `Placement` class (absent from
|
||||
`com.ironsource.mediationsdk.IronSource` and `IronSource.h`, which now only hold demand-only and ad-revenue APIs), and
|
||||
any capping API for banners or native ads. `ShowOptions.placementName` (0.1.0) already covers show-time placements.
|
||||
|
||||
## 9. Segments and dynamic user id
|
||||
|
||||
`setSegment(options)`:
|
||||
|
||||
| Field | Android `com.unity3d.mediation.segment.LevelPlaySegment` | iOS `LPMSegment` |
|
||||
|---|---|---|
|
||||
| `segmentName` | `setSegmentName(String)` | `segmentName` |
|
||||
| `level` | `setLevel(int)` | `level` (`int`) |
|
||||
| `isPaying` | `setPaying(boolean)` | `paying` |
|
||||
| `userCreationDate` (ms epoch) | `setUserCreationDate(long)` | `userCreationDate` (`NSDate`, `Date(timeIntervalSince1970: ms / 1000)`) |
|
||||
| `iapTotal` | `setIapTotal(double)` | `iapTotal` |
|
||||
| `customParameters` | `setCustom(String, String)` per pair | `setCustomValue:forKey:` per pair |
|
||||
| apply | `LevelPlay.setSegment(LevelPlaySegment)` | `+[LevelPlay setSegment:]` |
|
||||
|
||||
Custom-parameter limits read from the Android bytecode of `setCustom`: key and value must match `^[a-zA-Z0-9]*$`
|
||||
and be 1-32 characters; at most 5 pairs, the oldest is silently evicted on the 6th. The plugin validates the same
|
||||
rules on both platforms and rejects `INVALID_ARGUMENT` rather than dropping data silently. (The iOS header does not state the
|
||||
limits; phase 2 confirms iOS behaves the same.)
|
||||
|
||||
`setDynamicUserId({ userId })` → `{ valid }`: A `LevelPlay.setDynamicUserId(String): boolean`, I
|
||||
`+[LevelPlay setDynamicUserId:]` returning `BOOL`. There is no `IronSource.setDynamicUserId` in 9.6.1; the LevelPlay
|
||||
class is the only entry point.
|
||||
|
||||
## 10. Errors
|
||||
|
||||
Promise rejections (plugin codes, strings):
|
||||
|
||||
| Code | When |
|
||||
|---|---|
|
||||
| `INVALID_ARGUMENT` | missing / empty ids, bad size or position, bad segment custom parameters, negative rect size |
|
||||
| `NOT_INITIALIZED` | `createBanner`, `loadNativeAd` before `initialize()` resolved |
|
||||
| `ALREADY_EXISTS` | `createBanner` with a `bannerId` in use |
|
||||
| `NOT_FOUND` | `loadBanner`, `showBanner`, `setBannerLayout`, `showNativeAd`, `setNativeAdRect`, `hideNativeAd` with an unknown id (`hideBanner`, `destroy*` resolve instead) |
|
||||
| `NOT_LOADED` | `showNativeAd` before `nativeAdLoaded` |
|
||||
| `UNSUPPORTED` | capability is `false`, or a template not in `nativeAdTemplates` |
|
||||
| `NO_VIEW_CONTROLLER` (iOS) / `NO_ACTIVITY` (Android) | no host to attach or load into |
|
||||
| `UNIMPLEMENTED` | web stubs (Capacitor's `unimplemented()`), and any 0.3.0 method on a native build of phase 1 |
|
||||
|
||||
Ad errors in events (`AdError { code, message }`) pass the SDK code through: A `LevelPlayAdError.getErrorCode()` /
|
||||
`IronSourceError.getErrorCode()` (native), I `NSError.code`. Notable codes: 509 no fill; banner-specific Android
|
||||
constants `ERROR_BN_LOAD_NO_FILL`, `ERROR_BN_UNSUPPORTED_SIZE`, `ERROR_BN_RELOAD_SKIP_INVISIBLE`; native
|
||||
`ERROR_NT_LOAD_NO_FILL`, `ERROR_NT_LOAD_PLACEMENT_CAPPED`.
|
||||
|
||||
## 11. Web
|
||||
|
||||
`getCapabilities` all false; `setSegment` no-op; `setDynamicUserId` → `{ valid: false }`; `isPlacementCapped` →
|
||||
`{ capped: false }`; `getReward` → `{ name: '', amount: 0 }`; `loadBanner`, `hideBanner`, `destroyBanner`,
|
||||
`setNativeAdRect`, `hideNativeAd`, `destroyNativeAd` no-ops; `createBanner`, `showBanner`, `setBannerLayout`,
|
||||
`loadNativeAd`, `showNativeAd` reject `unimplemented` (they would have to return a frame or show a view; same rule as
|
||||
`initialize`).
|
||||
|
||||
## 12. Capacitor 7 compatibility (applied in 0.3.0, see §17)
|
||||
|
||||
Plugin-facing Java and Swift API is identical between 7.6.9 and 8.5.3 for everything this plugin uses:
|
||||
|
||||
- Android: the public members of `Plugin`, `PluginCall`, `Bridge` and `JSObject` diff to zero.
|
||||
`notifyListeners(String, JSObject, boolean)` exists in both.
|
||||
- iOS: `CAPPluginCall` (`.swift`, `.h`) identical; `CAPBridgeProtocol` in 8 only adds deprecations (`presentVC` /
|
||||
`dismissVC` → `bridge.viewController.present/dismiss`, which the plugin already uses); `CAPPlugin` in 8 adds
|
||||
`handleWKWebViewURLAuthenticationChallenge` (not used). `CAPBridgedPlugin` exists in both.
|
||||
|
||||
What must change to support `>=7.0.0` (phase 2 or later, not done now):
|
||||
|
||||
| Item | Today (Cap 8) | Needed for Cap 7 |
|
||||
|---|---|---|
|
||||
| `package.json` peer | `@capacitor/core >=8.0.0` | `>=7.0.0` |
|
||||
| `Package.swift` | `capacitor-swift-pm` `from: "8.0.0"` | `"7.0.0"..<"9.0.0"` (tags 7.0.0 ... 7.6.9 and 8.x exist) |
|
||||
| iOS deployment target | `.iOS(.v15)`, podspec `15.0` | `.v14` / `14.0` (Cap 7 default; `Capacitor.podspec` 7 = 14.0, 8 = 15.0). LevelPlay 9.6.1 needs 12.0, so 14 is fine. SPM refuses a package whose platform is higher than the app target. |
|
||||
| Android `minSdkVersion` default | 24 | 23 (Cap 7 default; LevelPlay AAR needs 19). Only the fallback; apps override from `variables.gradle`. |
|
||||
| Android `compileSdk` / `targetSdk` defaults | 36 | 35 in Cap 7 projects; overridden by the app, so no code change. |
|
||||
| AGP in plugin `buildscript` | `8.13.0` | Cap 7 apps use AGP 8.7.2. The plugin's `buildscript` classpath is only used by the standalone `verify:android` build, but a mismatched AGP in a subproject `buildscript` can trigger "multiple AGP versions"; phase 2 tests it in a Cap 7 app and, if needed, drops the plugin's `buildscript` classpath or keys it off `rootProject`. |
|
||||
| Java | 21 | 21 (same). |
|
||||
| Node / CLI | engines `>=22` | Cap 7 CLI runs on Node 20+; `engines` is advisory, can stay. |
|
||||
| SPM | default in Cap 8 projects | supported in Cap 7 (CapApp-SPM since Cap 6); CocoaPods podspec unchanged. |
|
||||
| LevelPlay SPM package | swift-tools 6.0 | needs Xcode 16+, which Cap 7 already requires. |
|
||||
|
||||
Behavioural difference that matters for overlays: edge-to-edge handling. Cap 7 uses
|
||||
`android.adjustMarginsForEdgeToEdge` (`CapConfig`, margins on `CapacitorWebView`; removed in 8). Cap 8 uses the core
|
||||
`SystemBars` plugin (`insetsHandling: 'css' | 'native' | 'disable'`, padding on the WebView's parent or CSS
|
||||
variables). The overlay design (§6.3) measures the WebView's real on-screen rect and intersects with window insets, so
|
||||
it is correct under every combination without reading either config.
|
||||
|
||||
## 13. Test plan
|
||||
|
||||
Automated (CI-able):
|
||||
- `bun run typecheck`, `bun run build` (docgen + rollup), `verify:ios`, `verify:android` on every change.
|
||||
- Android unit tests (JUnit, no device): pure helpers for placement maths (§6.4), safe-rect intersection, size
|
||||
preset parsing, segment validation, `ImpressionData` → `JSObject` mapping (constructed from a JSON fixture with
|
||||
`new LevelPlayImpressionData(JSONObject)`).
|
||||
- iOS: same helpers as plain Swift functions with XCTest (`swift test` cannot link the binary SDK on macOS; keep the
|
||||
helpers SDK-free).
|
||||
|
||||
Manual on devices (Unity demo app keys from `LEVELPLAY_DEMO` + test suite), Android 8 / 14 / 15 (edge to edge) and
|
||||
iOS 15 / 18 / 26, phone and tablet, portrait and landscape:
|
||||
1. Banner: every preset + adaptive; top / bottom / center with offsets; frame in `BannerResult` matches
|
||||
`document.elementFromPoint` checks; notch and home indicator respected; rotate while shown; hide during gameplay
|
||||
(no `bannerDisplayed` while hidden, refresh paused); two banners at once; destroy and recreate; click → `bannerClicked`
|
||||
and `bannerLeftApplication`; expanded creative → `bannerExpanded` / `bannerCollapsed`.
|
||||
2. Touch passthrough: game input works everywhere outside ad views, ads clickable inside; with keyboard open.
|
||||
3. Native: small and medium templates at several rects; "Ad" badge and AdChoices corner; impression only once visible;
|
||||
`setNativeAdRect` while shown; reload replaces the creative; destroy on screen change; no leaks across 50 loads
|
||||
(Android Studio profiler / Instruments).
|
||||
4. `impressionData` for rewarded, interstitial, banner, native; listener added before `initialize`; values match
|
||||
`adInfo.revenue`; `conversionValue` present on iOS only.
|
||||
5. `adInfoChanged` fires (needs a network that reloads; verify with test suite or logs).
|
||||
6. `isPlacementCapped` with a dashboard placement capped to 1 per session; `getReward` per placement vs ad unit.
|
||||
7. `setSegment` before init, segment name appears in `adInfo.segmentName` / `impressionData.segmentName`; invalid
|
||||
custom parameters reject.
|
||||
8. `setDynamicUserId` value reaches the S2S callback URL.
|
||||
9. Backwards compatibility: the 0.2.1 README quick start and CUT BLAST's integration run unchanged.
|
||||
10. Capacitor 7: a fresh Cap 7 app (SPM and CocoaPods; Android with `adjustMarginsForEdgeToEdge: 'auto'`) after the
|
||||
§12 changes.
|
||||
|
||||
## 14. Owner decisions (were open questions)
|
||||
|
||||
- **Q1 Impression data source. Decided:** per-ad listeners (`setImpressionDataListener` /
|
||||
`setImpressionDataDelegate:` on every rewarded, interstitial and banner object the plugin creates) plus native ad
|
||||
impressions synthesised from the native `AdInfo` (`adFormat: 'nativead'`). The deprecated global listener is not
|
||||
used.
|
||||
- **Q2 Retain impressions. Decided:** yes, with a plugin-owned queue capped at 100 impressions (oldest dropped),
|
||||
flushed in order on the first `addListener('impressionData')`. See §5.2.
|
||||
- **Q3 Android adaptive width unit. Decided / verified:** dp, from the SDK bytecode (§3.2); confirmed on the emulator (view measured 3 px per CSS px at density 3).
|
||||
CSS px are passed through unchanged.
|
||||
- **Q4 Adaptive banners and rotation. Decided:** automatic. Adaptive banners without a fixed `adaptiveWidth` are
|
||||
recreated and reloaded on a safe-area width change, keeping position, offsets, visibility and id. See §6.4.
|
||||
- **Q5 Custom banner sizes. Decided:** supported in addition to the presets: `size: 'CUSTOM'` with
|
||||
`customSize: { width, height }` (CSS px).
|
||||
- **Q6 Native template styling. Decided:** colours (background, title, body, CTA background and text), corner radius,
|
||||
and font family + size for title, body and CTA (`titleFont`, `bodyFont`, `callToActionFont`). See §4.2.
|
||||
- **Q7 Capacitor 7. Decided:** targeted for 0.3.0. Phase 7 verifies a Cap 7 app and applies the §12 package changes;
|
||||
until then the native code only uses APIs present in both Capacitor 7 and 8 (Android: `Plugin.addListener`,
|
||||
`notifyListeners`, `hasListeners`, `handleOnDestroy`, `handleOnConfigurationChanged`, `bridge.getWebView()`, all
|
||||
identical in 7.6.9 and 8.5.3).
|
||||
|
||||
## 15. Phase 2 notes (Android implementation)
|
||||
|
||||
Files (`android/src/main/java/fyi/crt/capacitor/levelplay/`): `LevelPlayPlugin` (bridge, impression queue, lifecycle),
|
||||
`OverlayHost` (§6.2), `BannerManager` (§3), `NativeAdManager` + `NativeAdTemplate` + `NativeAdStyle` (§4),
|
||||
`Mappers` (SDK objects to JSON), `OverlayMath` (pure geometry and validation, JVM unit tests in `android/src/test`),
|
||||
`CallError` (reject codes). `res/values/strings.xml` holds the two template texts (`levelplay_native_ad_badge` "Ad",
|
||||
`levelplay_native_ad_cta_fallback` "Open"), overridable by the app's own resources.
|
||||
|
||||
Implementation details that the sections above leave open:
|
||||
|
||||
- Every bridge call hops to the main thread; SDK listeners re-post to it. Unexpected runtime exceptions reject with
|
||||
code `ERROR`.
|
||||
- `createBanner` validates its arguments first (`INVALID_ARGUMENT`), then `NOT_INITIALIZED`, `ALREADY_EXISTS`,
|
||||
`NO_ACTIVITY` (also when the WebView has no parent view yet).
|
||||
- Overlay children are positioned with FrameLayout margins from the WebView's offset in the host
|
||||
(`getLocationInWindow` of both), so the host simply fills the WebView's parent. Relayouts are posted, never run
|
||||
inside a layout pass.
|
||||
- A hidden banner is `View.GONE` + `pauseAutoRefresh()`; `showBanner` is `VISIBLE` + `bringToFront()` +
|
||||
`resumeAutoRefresh()`.
|
||||
- Banner and native listeners are per view / per ad object; callbacks from a replaced (rotation) or destroyed
|
||||
object are dropped.
|
||||
- `loadAd()` on a banner view is one-shot in 9.6.1: a second call only logs "Banner load already called" and the SDK
|
||||
retries on its own refresh interval. Immediate retries are destroy + create + load (documented on `loadBanner`).
|
||||
- A native ad template consumes touches inside its bounds (taps between asset views do not reach the page).
|
||||
- Native template font files are read with `Typeface.createFromAsset(assets, "public/" + path)` and cached; a missing
|
||||
file logs a warning (tag `LevelPlay`) and uses the system font.
|
||||
|
||||
Emulator results (Pixel 9 Pro AVD, API 36, Capacitor 8.5.3 test app, Unity demo app key + Unity Ads adapter 5.14 /
|
||||
Unity Ads 4.21 in the app):
|
||||
|
||||
- Seen: init, `getCapabilities`, `setSegment` (valid, and `INVALID_ARGUMENT` for 6 pairs, a `-` in a key and a
|
||||
non-integer level), `setDynamicUserId` (`valid: true`), `isPlacementCapped`, `getReward` (`Virtual Item` x 1);
|
||||
adaptive / preset / `MEDIUM_RECTANGLE` / `CUSTOM` banners at top / bottom / center with offsets; hide / show /
|
||||
destroy (view visibility checked with `dumpsys activity top`); `ALREADY_EXISTS`, `NOT_FOUND`; touches beside a
|
||||
banner reach the page; safe area with Capacitor's default insets handling and with `insetsHandling: 'disable'`
|
||||
(edge to edge: top banner at y 52 = status bar, bottom banner ends 24 px above the WebView bottom = navigation
|
||||
bar; `respectSafeArea: false` gives y 0); rotation recreates a width-following adaptive banner (426 x 50 to
|
||||
900 x 50, reloaded; landscape with a display cutout: both banners at x 52, width 900, inside the safe area); a tap
|
||||
on a banner fires `bannerClicked` and opens the browser without reaching the page; rewarded load / show / reward / close; queued `impressionData` (banner, rewarded) flushed on
|
||||
the first listener; native ad error paths (`UNSUPPORTED`, `INVALID_ARGUMENT`, `NOT_LOADED`, `NOT_FOUND`,
|
||||
`nativeAdLoadFailed` 508).
|
||||
- Not seen with the public demo ids: a filled native ad (the demo app key has no native configuration: 508 "No Native
|
||||
Ad configurations found"), so `nativeAdLoaded` / `nativeAdImpression` / `nativeAdClicked` and the synthesised
|
||||
native `impressionData` are untested; the templates were rendered with sample assets through
|
||||
`NativeAdTemplate.create` / `fill` instead. `adInfoChanged` never fired. Interstitial: load and `displayed` seen, the close could not be
|
||||
driven through the ANR dialogs of the overloaded emulator. `segmentName` stayed empty in `adInfo`
|
||||
(no segments on the demo dashboard). Banner expand / collapse / left-application events (Unity Ads test banners did not report them).
|
||||
The emulator ran on an overloaded host (load average 30-40): system apps and the test app showed ANR dialogs
|
||||
around SDK init and Unity full-screen ads; the overlay was idle at those times (no frames rendered while idle,
|
||||
app CPU 2 %).
|
||||
|
||||
## 16. Phase 3 notes (iOS implementation)
|
||||
|
||||
Files (`ios/Sources/LevelPlayPlugin/`): `LevelPlayPlugin.swift` (bridge, holders, impression queue, overlay,
|
||||
cleanup), `OverlayHost.swift` (§6.2), `BannerManager.swift` (§3), `NativeAdManager.swift` + `NativeAdTemplate.swift` +
|
||||
`NativeAdStyle.swift` (§4), `Mappers.swift` (SDK objects to JSON), `OverlayMath.swift` (pure geometry and validation,
|
||||
same rules as Android), `CallError.swift` (reject codes and typed option reads).
|
||||
|
||||
Swift names the SDK actually imports as (the ObjC importer renames several of the §3 / §4 names):
|
||||
`LPMAdSize.banner()`, `.large()`, `.mediumRectangle()`, `.leaderBoard()`, `.customSize(withWidth:height:)`,
|
||||
`.createAdaptiveAdSize(withWidth:)`, `.createAdaptive()`; `LPMBannerAdView.loadAd(with:)`;
|
||||
`LevelPlayNativeAd.load()` / `.destroy()`; `LevelPlayNativeAdBuilder.build()` returns an optional. Delegate methods are
|
||||
declared with explicit `@objc(selector)` names so the optional callbacks are found whatever their Swift spelling.
|
||||
|
||||
Behaviour matches the Android bridge (same validation order, messages, codes and payloads) except:
|
||||
|
||||
- `NO_VIEW_CONTROLLER` instead of `NO_ACTIVITY`.
|
||||
- `loadBanner` passes `bridge.viewController` to `loadAdWithViewController:`; the native builder gets it via
|
||||
`withViewController:`.
|
||||
- Booleans and numbers are told apart (`CFBoolean`), so `isPaying: 1` or `offsetX: true` reject as on Android.
|
||||
- `setSegment` custom parameters are applied in key order (JS object order is not kept by the bridge).
|
||||
- Native template fonts: a `.ttf` / `.otf` path is resolved against `bridge.config.appLocation` (the app's `public`
|
||||
folder), registered once per process with `CTFontManagerRegisterFontsForURL` (`.process`) and used by PostScript
|
||||
name; a system family is looked up by name, then by family. Missing fonts log a warning (subsystem
|
||||
`fyi.crt.capacitor.levelplay`) and use the system font. Template texts `levelplay_native_ad_badge` ("Ad") and
|
||||
`levelplay_native_ad_cta_fallback` ("Open") come from the app's `Localizable.strings` when present.
|
||||
- The overlay logs each banner's frame (and every `showBanner`) and each shown native ad's frame at `notice` level
|
||||
(subsystem `fyi.crt.capacitor.levelplay`, category `LevelPlay`).
|
||||
- Cleanup runs in the plugin's `deinit` (Capacitor iOS has no `handleOnDestroy`); managers are created on first use
|
||||
so `deinit` never builds them.
|
||||
- The app needs the `-ObjC` linker flag (already a README requirement): without it `LevelPlay.setSegment` crashes with
|
||||
`+[ISSegment createFrom:]: unrecognized selector`, a category of the static SDK binary.
|
||||
|
||||
Simulator results (iPhone 17 simulator, iOS 26, Capacitor 8.5.2 Swift package, Unity demo app key, no extra
|
||||
adapters, ironSource Ads filled):
|
||||
|
||||
- Seen: `getCapabilities`; `setSegment` valid and `INVALID_ARGUMENT` for 6 pairs, a `-` in a key and level 1.5;
|
||||
`NOT_INITIALIZED` for `createBanner` before init; init; `setDynamicUserId` (`valid: true`); `isPlacementCapped`
|
||||
(and `INVALID_ARGUMENT` for format `banner`); `getReward` (`Virtual Item` x 1); adaptive banner at the bottom:
|
||||
`adSize` 402 x 50, frame `0,790 402x50` in a `402x874` WebView whose safe area is `0,62 402x778` (ends 34 pt above
|
||||
the bottom = home indicator); `ALREADY_EXISTS`, `NOT_FOUND`, `INVALID_ARGUMENT` for size `HUGE`;
|
||||
`bannerLoadFailed` 509 then `bannerLoaded` / `bannerDisplayed` on the SDK's retry; rewarded load / show /
|
||||
`displayed` / `rewarded`; `impressionData` for banner, native and rewarded queued before the first listener and
|
||||
flushed in order when it was added (`allData.lifetimeRevenue` present as on Android; `conversionValue` was `nil` in
|
||||
`LPMImpressionData` and `0` in `ISAdInfo` / `LPMAdInfo` with the demo key); native ad error paths (`UNSUPPORTED`,
|
||||
`NOT_LOADED`); a **filled** native ad (unlike Android's demo key): `nativeAdLoaded`, `showNativeAd` in the small
|
||||
template at `20,460 300x90` (icon 48 x 48, title "Demo App", "Ad" badge, body, CTA "INSTALL" 79 x 36 on the right,
|
||||
the network's privacy "i" at the bottom-left corner `0,69 21x21`), `nativeAdImpression` and the synthesised
|
||||
`impressionData` (`adFormat: 'nativead'`). The native `ISAdInfo` fields were all empty strings with the demo key.
|
||||
The medium template and a missing-advertiser / long-text case were checked with sample assets (view hierarchy
|
||||
logged: title truncated, media view filling the rest, CTA right-aligned, web-asset font applied).
|
||||
- Not seen: interstitial, close of the rewarded ad, rotation (adaptive recreation), `setBannerLayout`, banner
|
||||
click / expand / collapse / left-application, `nativeAdClicked`, `adInfoChanged`, Capacitor 7. Compiled only.
|
||||
|
||||
## 17. Capacitor 7 verification (phase 7)
|
||||
|
||||
Applied the §12 changes: peer `@capacitor/core >=7.0.0`; `Package.swift` `capacitor-swift-pm` `"7.0.0"..<"9.0.0"` and
|
||||
`.iOS(.v14)`; podspec `14.0`; Android `minSdkVersion` fallback 23. The plugin's `buildscript` AGP classpath (8.13.0)
|
||||
was left as is.
|
||||
|
||||
Compile check with a scratch copy of `example-app/` on Capacitor 7.6.9 (`@capacitor/core`, `cli`, `android`, `ios`),
|
||||
fresh `npx cap add android` and `npx cap add ios --packagemanager SPM`:
|
||||
|
||||
- Android `assembleDebug`: succeeds in the Cap 7 template (AGP 8.7.2, compileSdk 35, minSdk 23, JDK 21); no
|
||||
"multiple AGP versions" clash.
|
||||
- iOS simulator build (`CODE_SIGNING_ALLOWED=NO`): SPM resolves `capacitor-swift-pm` 7.x with the plugin's range and
|
||||
the build succeeds. The Cap 7 template's app target is iOS 14.0, which Xcode 27 rejects for any app ("supported
|
||||
deployment target versions is 15.0 to 27.0"); with the app target raised to 15.0 it builds. The plugin itself only
|
||||
uses iOS 14 APIs (`Logger`, ATT) but iOS 14 availability was not compiler-checked with Xcode 27.
|
||||
- Not run on a device or emulator with Capacitor 7.
|
||||
|
Before Width: | Height: | Size: 82 KiB |
|
Before Width: | Height: | Size: 83 KiB |
3
example-app/.gitignore
vendored
|
|
@ -1,3 +0,0 @@
|
|||
node_modules/
|
||||
www/
|
||||
package-lock.json
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
# capacitor-levelplay example
|
||||
|
||||
A minimal Capacitor 8 app for trying the plugin with Unity's public demo ids (`LEVELPLAY_DEMO`, test ads only). Plain
|
||||
HTML and TypeScript, bundled with esbuild; the plugin comes from the parent folder (`"capacitor-levelplay": "file:.."`).
|
||||
|
||||
Buttons: initialize, capabilities, segment, dynamic user id, rewarded and interstitial load / show, an adaptive banner
|
||||
at the top or bottom (hide, show, destroy), native ads in the `small` or `medium` template placed over a page
|
||||
placeholder, and a log panel that prints every event and each `impressionData` (format, network, revenue, precision).
|
||||
|
||||
## Run
|
||||
|
||||
Build the plugin once from the repository root, then the example:
|
||||
|
||||
```sh
|
||||
bun install && bun run build # in the repository root (plugin dist/)
|
||||
cd example-app
|
||||
npm install
|
||||
npm run sync # tsc + esbuild into www/, then npx cap sync
|
||||
npx cap run android # or: npx cap open android
|
||||
npx cap run ios # or: npx cap open ios
|
||||
```
|
||||
|
||||
Rebuild the plugin (`bun run build` in the root) and run `npm run sync` again after changing the plugin's TypeScript.
|
||||
Native plugin code is picked up directly from `../android` and `../ios` (Gradle project / Swift package path).
|
||||
|
||||
Requirements: JDK 21 and the Android SDK for Android; Xcode 26+ for iOS.
|
||||
|
||||
## What is already set up
|
||||
|
||||
The `android/` and `ios/` folders are committed (`npx cap add` output plus the plugin's setup steps):
|
||||
|
||||
- iOS `Info.plist`: `NSUserTrackingUsageDescription`, LevelPlay's `SKAdNetworkItems` id, `NSAllowsArbitraryLoads`.
|
||||
- iOS App target: `-ObjC` in **Other Linker Flags** (required by LevelPlay).
|
||||
- iOS uses Swift Package Manager (`CapApp-SPM`). `@capacitor/ios` is pinned to 8.5.2 because `capacitor-swift-pm`
|
||||
has no 8.5.3 tag at the time of writing (SPM fails with "no versions of 'capacitor-swift-pm' match 8.5.3").
|
||||
- Android needs nothing beyond `npx cap sync`; the plugin's manifest and Gradle file bring the SDK and permissions.
|
||||
|
||||
To recreate the platforms from scratch: delete `android/` and `ios/`, run `npx cap add android` and `npx cap add ios`,
|
||||
then repeat the iOS steps above (see the plugin README, "iOS setup").
|
||||
|
||||
## Notes
|
||||
|
||||
- Android includes the Unity Ads mediation adapter (`app/build.gradle`): Unity's demo Android banner unit only fills
|
||||
through Unity Ads, so without it banners fail with 1044 "no available ad to load". Everything else fills from
|
||||
ironSource Ads. Natives may not fill on Android with the demo key (508 "No Native Ad configurations found").
|
||||
- `loadBanner` is one-shot per banner object; to retry right away, destroy and create the banner again.
|
||||
- The web build (`npm run build`, open `www/index.html` through any static server) runs the plugin's web stub:
|
||||
init and banners reject as unimplemented and nothing ever fills.
|
||||
101
example-app/android/.gitignore
vendored
|
|
@ -1,101 +0,0 @@
|
|||
# Using Android gitignore template: https://github.com/github/gitignore/blob/HEAD/Android.gitignore
|
||||
|
||||
# Built application files
|
||||
*.apk
|
||||
*.aar
|
||||
*.ap_
|
||||
*.aab
|
||||
|
||||
# Files for the ART/Dalvik VM
|
||||
*.dex
|
||||
|
||||
# Java class files
|
||||
*.class
|
||||
|
||||
# Generated files
|
||||
bin/
|
||||
gen/
|
||||
out/
|
||||
# Uncomment the following line in case you need and you don't have the release build type files in your app
|
||||
# release/
|
||||
|
||||
# Gradle files
|
||||
.gradle/
|
||||
build/
|
||||
|
||||
# Local configuration file (sdk path, etc)
|
||||
local.properties
|
||||
|
||||
# Proguard folder generated by Eclipse
|
||||
proguard/
|
||||
|
||||
# Log Files
|
||||
*.log
|
||||
|
||||
# Android Studio Navigation editor temp files
|
||||
.navigation/
|
||||
|
||||
# Android Studio captures folder
|
||||
captures/
|
||||
|
||||
# IntelliJ
|
||||
*.iml
|
||||
.idea/workspace.xml
|
||||
.idea/tasks.xml
|
||||
.idea/gradle.xml
|
||||
.idea/assetWizardSettings.xml
|
||||
.idea/dictionaries
|
||||
.idea/libraries
|
||||
# Android Studio 3 in .gitignore file.
|
||||
.idea/caches
|
||||
.idea/modules.xml
|
||||
# Comment next line if keeping position of elements in Navigation Editor is relevant for you
|
||||
.idea/navEditor.xml
|
||||
|
||||
# Keystore files
|
||||
# Uncomment the following lines if you do not want to check your keystore files in.
|
||||
#*.jks
|
||||
#*.keystore
|
||||
|
||||
# External native build folder generated in Android Studio 2.2 and later
|
||||
.externalNativeBuild
|
||||
.cxx/
|
||||
|
||||
# Google Services (e.g. APIs or Firebase)
|
||||
# google-services.json
|
||||
|
||||
# Freeline
|
||||
freeline.py
|
||||
freeline/
|
||||
freeline_project_description.json
|
||||
|
||||
# fastlane
|
||||
fastlane/report.xml
|
||||
fastlane/Preview.html
|
||||
fastlane/screenshots
|
||||
fastlane/test_output
|
||||
fastlane/readme.md
|
||||
|
||||
# Version control
|
||||
vcs.xml
|
||||
|
||||
# lint
|
||||
lint/intermediates/
|
||||
lint/generated/
|
||||
lint/outputs/
|
||||
lint/tmp/
|
||||
# lint/reports/
|
||||
|
||||
# Android Profiling
|
||||
*.hprof
|
||||
|
||||
# Cordova plugins for Capacitor
|
||||
capacitor-cordova-android-plugins
|
||||
|
||||
# Copied web assets
|
||||
app/src/main/assets/public
|
||||
|
||||
# Generated Config files
|
||||
app/src/main/assets/capacitor.config.json
|
||||
app/src/main/assets/capacitor.plugins.json
|
||||
app/src/main/res/xml/config.xml
|
||||
2
example-app/android/app/.gitignore
vendored
|
|
@ -1,2 +0,0 @@
|
|||
/build/*
|
||||
!/build/.npmkeep
|
||||
|
|
@ -1,57 +0,0 @@
|
|||
apply plugin: 'com.android.application'
|
||||
|
||||
android {
|
||||
namespace = "fyi.crt.levelplay.example"
|
||||
compileSdk = rootProject.ext.compileSdkVersion
|
||||
defaultConfig {
|
||||
applicationId "fyi.crt.levelplay.example"
|
||||
minSdkVersion rootProject.ext.minSdkVersion
|
||||
targetSdkVersion rootProject.ext.targetSdkVersion
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
aaptOptions {
|
||||
// Files and dirs to omit from the packaged assets dir, modified to accommodate modern web apps.
|
||||
// Default: https://android.googlesource.com/platform/frameworks/base/+/282e181b58cf72b6ca770dc7ca5f91f135444502/tools/aapt/AaptAssets.cpp#61
|
||||
ignoreAssetsPattern = '!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~'
|
||||
}
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
flatDir{
|
||||
dirs '../capacitor-cordova-android-plugins/src/main/libs', 'libs'
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
||||
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
|
||||
implementation "androidx.coordinatorlayout:coordinatorlayout:$androidxCoordinatorLayoutVersion"
|
||||
implementation "androidx.core:core-splashscreen:$coreSplashScreenVersion"
|
||||
implementation project(':capacitor-android')
|
||||
// Unity Ads mediation adapter: Unity's demo Android banner unit only fills through Unity Ads
|
||||
implementation 'com.unity3d.ads-mediation:unityads-adapter:5.14.0'
|
||||
implementation 'com.unity3d.ads:unity-ads:4.21.0'
|
||||
testImplementation "junit:junit:$junitVersion"
|
||||
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
|
||||
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
|
||||
implementation project(':capacitor-cordova-android-plugins')
|
||||
}
|
||||
|
||||
apply from: 'capacitor.build.gradle'
|
||||
|
||||
try {
|
||||
def servicesJSON = file('google-services.json')
|
||||
if (servicesJSON.text) {
|
||||
apply plugin: 'com.google.gms.google-services'
|
||||
}
|
||||
} catch(Exception e) {
|
||||
logger.info("google-services.json not found, google-services plugin not applied. Push Notifications won't work")
|
||||
}
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
// DO NOT EDIT THIS FILE! IT IS GENERATED EACH TIME "capacitor update" IS RUN
|
||||
|
||||
android {
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_21
|
||||
targetCompatibility JavaVersion.VERSION_21
|
||||
}
|
||||
}
|
||||
|
||||
apply from: "../capacitor-cordova-android-plugins/cordova.variables.gradle"
|
||||
dependencies {
|
||||
implementation project(':capacitor-levelplay')
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (hasProperty('postBuildExtras')) {
|
||||
postBuildExtras()
|
||||
}
|
||||
21
example-app/android/app/proguard-rules.pro
vendored
|
|
@ -1,21 +0,0 @@
|
|||
# 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
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
package com.getcapacitor.myapp;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
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 <a href="http://d.android.com/tools/testing">Testing documentation</a>
|
||||
*/
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class ExampleInstrumentedTest {
|
||||
|
||||
@Test
|
||||
public void useAppContext() throws Exception {
|
||||
// Context of the app under test.
|
||||
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
|
||||
|
||||
assertEquals("com.getcapacitor.app", appContext.getPackageName());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,41 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
|
||||
<activity
|
||||
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode|navigation|density"
|
||||
android:name=".MainActivity"
|
||||
android:label="@string/title_activity_main"
|
||||
android:theme="@style/AppTheme.NoActionBarLaunch"
|
||||
android:launchMode="singleTask"
|
||||
android:exported="true">
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
|
||||
</activity>
|
||||
|
||||
<provider
|
||||
android:name="androidx.core.content.FileProvider"
|
||||
android:authorities="${applicationId}.fileprovider"
|
||||
android:exported="false"
|
||||
android:grantUriPermissions="true">
|
||||
<meta-data
|
||||
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||
android:resource="@xml/file_paths"></meta-data>
|
||||
</provider>
|
||||
</application>
|
||||
|
||||
<!-- Permissions -->
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
</manifest>
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
package fyi.crt.levelplay.example;
|
||||
|
||||
import com.getcapacitor.BridgeActivity;
|
||||
|
||||
public class MainActivity extends BridgeActivity {}
|
||||
|
Before Width: | Height: | Size: 7.5 KiB |
|
Before Width: | Height: | Size: 3.9 KiB |
|
Before Width: | Height: | Size: 9 KiB |
|
Before Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 17 KiB |
|
Before Width: | Height: | Size: 7.7 KiB |
|
Before Width: | Height: | Size: 4 KiB |
|
Before Width: | Height: | Size: 9.6 KiB |
|
Before Width: | Height: | Size: 13 KiB |
|
Before Width: | Height: | Size: 17 KiB |
|
|
@ -1,34 +0,0 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:aapt="http://schemas.android.com/aapt"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:viewportHeight="108"
|
||||
android:viewportWidth="108">
|
||||
<path
|
||||
android:fillType="evenOdd"
|
||||
android:pathData="M32,64C32,64 38.39,52.99 44.13,50.95C51.37,48.37 70.14,49.57 70.14,49.57L108.26,87.69L108,109.01L75.97,107.97L32,64Z"
|
||||
android:strokeColor="#00000000"
|
||||
android:strokeWidth="1">
|
||||
<aapt:attr name="android:fillColor">
|
||||
<gradient
|
||||
android:endX="78.5885"
|
||||
android:endY="90.9159"
|
||||
android:startX="48.7653"
|
||||
android:startY="61.0927"
|
||||
android:type="linear">
|
||||
<item
|
||||
android:color="#44000000"
|
||||
android:offset="0.0" />
|
||||
<item
|
||||
android:color="#00000000"
|
||||
android:offset="1.0" />
|
||||
</gradient>
|
||||
</aapt:attr>
|
||||
</path>
|
||||
<path
|
||||
android:fillColor="#FFFFFF"
|
||||
android:fillType="nonZero"
|
||||
android:pathData="M66.94,46.02L66.94,46.02C72.44,50.07 76,56.61 76,64L32,64C32,56.61 35.56,50.11 40.98,46.06L36.18,41.19C35.45,40.45 35.45,39.3 36.18,38.56C36.91,37.81 38.05,37.81 38.78,38.56L44.25,44.05C47.18,42.57 50.48,41.71 54,41.71C57.48,41.71 60.78,42.57 63.68,44.05L69.11,38.56C69.84,37.81 70.98,37.81 71.71,38.56C72.44,39.3 72.44,40.45 71.71,41.19L66.94,46.02ZM62.94,56.92C64.08,56.92 65,56.01 65,54.88C65,53.76 64.08,52.85 62.94,52.85C61.8,52.85 60.88,53.76 60.88,54.88C60.88,56.01 61.8,56.92 62.94,56.92ZM45.06,56.92C46.2,56.92 47.13,56.01 47.13,54.88C47.13,53.76 46.2,52.85 45.06,52.85C43.92,52.85 43,53.76 43,54.88C43,56.01 43.92,56.92 45.06,56.92Z"
|
||||
android:strokeColor="#00000000"
|
||||
android:strokeWidth="1" />
|
||||
</vector>
|
||||
|
|
@ -1,170 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:viewportHeight="108"
|
||||
android:viewportWidth="108">
|
||||
<path
|
||||
android:fillColor="#26A69A"
|
||||
android:pathData="M0,0h108v108h-108z" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M9,0L9,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,0L19,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M29,0L29,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M39,0L39,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M49,0L49,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M59,0L59,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M69,0L69,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M79,0L79,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M89,0L89,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M99,0L99,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,9L108,9"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,19L108,19"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,29L108,29"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,39L108,39"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,49L108,49"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,59L108,59"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,69L108,69"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,79L108,79"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,89L108,89"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,99L108,99"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,29L89,29"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,39L89,39"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,49L89,49"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,59L89,59"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,69L89,69"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,79L89,79"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M29,19L29,89"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M39,19L39,89"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M49,19L49,89"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M59,19L59,89"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M69,19L69,89"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M79,19L79,89"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
</vector>
|
||||
|
Before Width: | Height: | Size: 3.9 KiB |
|
|
@ -1,12 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".MainActivity">
|
||||
|
||||
<WebView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@color/ic_launcher_background"/>
|
||||
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
|
||||
</adaptive-icon>
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@color/ic_launcher_background"/>
|
||||
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
|
||||
</adaptive-icon>
|
||||
|
Before Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 3.4 KiB |
|
Before Width: | Height: | Size: 4.2 KiB |
|
Before Width: | Height: | Size: 1.8 KiB |
|
Before Width: | Height: | Size: 2.1 KiB |
|
Before Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 3.9 KiB |
|
Before Width: | Height: | Size: 4.9 KiB |
|
Before Width: | Height: | Size: 6.4 KiB |
|
Before Width: | Height: | Size: 6.5 KiB |
|
Before Width: | Height: | Size: 9.6 KiB |
|
Before Width: | Height: | Size: 10 KiB |
|
Before Width: | Height: | Size: 9.2 KiB |
|
Before Width: | Height: | Size: 15 KiB |
|
Before Width: | Height: | Size: 16 KiB |
|
|
@ -1,4 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="ic_launcher_background">#FFFFFF</color>
|
||||
</resources>
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<resources>
|
||||
<string name="app_name">LevelPlay Example</string>
|
||||
<string name="title_activity_main">LevelPlay Example</string>
|
||||
<string name="package_name">fyi.crt.levelplay.example</string>
|
||||
<string name="custom_url_scheme">fyi.crt.levelplay.example</string>
|
||||
</resources>
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<!-- Base application theme. -->
|
||||
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
|
||||
<!-- Customize your theme here. -->
|
||||
<item name="colorPrimary">@color/colorPrimary</item>
|
||||
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
|
||||
<item name="colorAccent">@color/colorAccent</item>
|
||||
</style>
|
||||
|
||||
<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.DayNight.NoActionBar">
|
||||
<item name="windowActionBar">false</item>
|
||||
<item name="windowNoTitle">true</item>
|
||||
<item name="android:background">@null</item>
|
||||
</style>
|
||||
|
||||
|
||||
<style name="AppTheme.NoActionBarLaunch" parent="Theme.SplashScreen">
|
||||
<item name="android:background">@drawable/splash</item>
|
||||
</style>
|
||||
</resources>
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<paths xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<external-path name="my_images" path="." />
|
||||
<cache-path name="my_cache_images" path="." />
|
||||
</paths>
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
package com.getcapacitor.myapp;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Example local unit test, which will execute on the development machine (host).
|
||||
*
|
||||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
|
||||
*/
|
||||
public class ExampleUnitTest {
|
||||
|
||||
@Test
|
||||
public void addition_isCorrect() throws Exception {
|
||||
assertEquals(4, 2 + 2);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
|
||||
buildscript {
|
||||
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:8.13.0'
|
||||
classpath 'com.google.gms:google-services:4.4.4'
|
||||
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
// in the individual module build.gradle files
|
||||
}
|
||||
}
|
||||
|
||||
apply from: "variables.gradle"
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
|
||||
task clean(type: Delete) {
|
||||
delete rootProject.buildDir
|
||||
}
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
// DO NOT EDIT THIS FILE! IT IS GENERATED EACH TIME "capacitor update" IS RUN
|
||||
include ':capacitor-android'
|
||||
project(':capacitor-android').projectDir = new File('../node_modules/@capacitor/android/capacitor')
|
||||
|
||||
include ':capacitor-levelplay'
|
||||
project(':capacitor-levelplay').projectDir = new File('../../android')
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
# 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=-Xmx1536m
|
||||
|
||||
# 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
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-all.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
251
example-app/android/gradlew
vendored
|
|
@ -1,251 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
#
|
||||
# Copyright © 2015-2021 the original 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.
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# Gradle start up script for POSIX generated by Gradle.
|
||||
#
|
||||
# Important for running:
|
||||
#
|
||||
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
||||
# noncompliant, but you have some other compliant shell such as ksh or
|
||||
# bash, then to run this script, type that shell name before the whole
|
||||
# command line, like:
|
||||
#
|
||||
# ksh Gradle
|
||||
#
|
||||
# Busybox and similar reduced shells will NOT work, because this script
|
||||
# requires all of these POSIX shell features:
|
||||
# * functions;
|
||||
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
||||
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
||||
# * compound commands having a testable exit status, especially «case»;
|
||||
# * various built-in commands including «command», «set», and «ulimit».
|
||||
#
|
||||
# Important for patching:
|
||||
#
|
||||
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
||||
# by Bash, Ksh, etc; in particular arrays are avoided.
|
||||
#
|
||||
# The "traditional" practice of packing multiple parameters into a
|
||||
# space-separated string is a well documented source of bugs and security
|
||||
# problems, so this is (mostly) avoided, by progressively accumulating
|
||||
# options in "$@", and eventually passing that to Java.
|
||||
#
|
||||
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
||||
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
||||
# see the in-line comments for details.
|
||||
#
|
||||
# There are tweaks for specific operating systems such as AIX, CygWin,
|
||||
# Darwin, MinGW, and NonStop.
|
||||
#
|
||||
# (3) This script is generated from the Groovy template
|
||||
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# within the Gradle project.
|
||||
#
|
||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
|
||||
# Resolve links: $0 may be a link
|
||||
app_path=$0
|
||||
|
||||
# Need this for daisy-chained symlinks.
|
||||
while
|
||||
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
||||
[ -h "$app_path" ]
|
||||
do
|
||||
ls=$( ls -ld "$app_path" )
|
||||
link=${ls#*' -> '}
|
||||
case $link in #(
|
||||
/*) app_path=$link ;; #(
|
||||
*) app_path=$APP_HOME$link ;;
|
||||
esac
|
||||
done
|
||||
|
||||
# This is normally unused
|
||||
# shellcheck disable=SC2034
|
||||
APP_BASE_NAME=${0##*/}
|
||||
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD=maximum
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
} >&2
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
} >&2
|
||||
|
||||
# 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 ;; #(
|
||||
MSYS* | MINGW* ) msys=true ;; #(
|
||||
NONSTOP* ) nonstop=true ;;
|
||||
esac
|
||||
|
||||
CLASSPATH="\\\"\\\""
|
||||
|
||||
|
||||
# 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
|
||||
if ! command -v java >/dev/null 2>&1
|
||||
then
|
||||
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
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||
case $MAX_FD in #(
|
||||
max*)
|
||||
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC2039,SC3045
|
||||
MAX_FD=$( ulimit -H -n ) ||
|
||||
warn "Could not query maximum file descriptor limit"
|
||||
esac
|
||||
case $MAX_FD in #(
|
||||
'' | soft) :;; #(
|
||||
*)
|
||||
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC2039,SC3045
|
||||
ulimit -n "$MAX_FD" ||
|
||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||
esac
|
||||
fi
|
||||
|
||||
# Collect all arguments for the java command, stacking in reverse order:
|
||||
# * args from the command line
|
||||
# * the main class name
|
||||
# * -classpath
|
||||
# * -D...appname settings
|
||||
# * --module-path (only if needed)
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
||||
|
||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||
if "$cygwin" || "$msys" ; then
|
||||
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
||||
|
||||
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
for arg do
|
||||
if
|
||||
case $arg in #(
|
||||
-*) false ;; # don't mess with options #(
|
||||
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
||||
[ -e "$t" ] ;; #(
|
||||
*) false ;;
|
||||
esac
|
||||
then
|
||||
arg=$( cygpath --path --ignore --mixed "$arg" )
|
||||
fi
|
||||
# Roll the args list around exactly as many times as the number of
|
||||
# args, so each arg winds up back in the position where it started, but
|
||||
# possibly modified.
|
||||
#
|
||||
# NB: a `for` loop captures its iteration list before it begins, so
|
||||
# changing the positional parameters here affects neither the number of
|
||||
# iterations, nor the values presented in `arg`.
|
||||
shift # remove old arg
|
||||
set -- "$@" "$arg" # push replacement arg
|
||||
done
|
||||
fi
|
||||
|
||||
|
||||
# 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"'
|
||||
|
||||
# Collect all arguments for the java command:
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||
# and any embedded shellness will be escaped.
|
||||
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
||||
# treated as '${Hostname}' itself on the command line.
|
||||
|
||||
set -- \
|
||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||
-classpath "$CLASSPATH" \
|
||||
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
|
||||
"$@"
|
||||
|
||||
# Stop when "xargs" is not available.
|
||||
if ! command -v xargs >/dev/null 2>&1
|
||||
then
|
||||
die "xargs is not available"
|
||||
fi
|
||||
|
||||
# Use "xargs" to parse quoted args.
|
||||
#
|
||||
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||
#
|
||||
# In Bash we could simply go:
|
||||
#
|
||||
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
||||
# set -- "${ARGS[@]}" "$@"
|
||||
#
|
||||
# but POSIX shell has neither arrays nor command substitution, so instead we
|
||||
# post-process each arg (as a line of input to sed) to backslash-escape any
|
||||
# character that might be a shell metacharacter, then use eval to reverse
|
||||
# that process (while maintaining the separation between arguments), and wrap
|
||||
# the whole thing up as a single "set" statement.
|
||||
#
|
||||
# This will of course break if any of these variables contains a newline or
|
||||
# an unmatched quote.
|
||||
#
|
||||
|
||||
eval "set -- $(
|
||||
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
||||
xargs -n1 |
|
||||
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
||||
tr '\n' ' '
|
||||
)" '"$@"'
|
||||
|
||||
exec "$JAVACMD" "$@"
|
||||
94
example-app/android/gradlew.bat
vendored
|
|
@ -1,94 +0,0 @@
|
|||
@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
|
||||
@rem SPDX-License-Identifier: Apache-2.0
|
||||
@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=.
|
||||
@rem This is normally unused
|
||||
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% equ 0 goto execute
|
||||
|
||||
echo. 1>&2
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
|
||||
echo. 1>&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||
echo location of your Java installation. 1>&2
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo. 1>&2
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
|
||||
echo. 1>&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||
echo location of your Java installation. 1>&2
|
||||
|
||||
goto fail
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if %ERRORLEVEL% equ 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!
|
||||
set EXIT_CODE=%ERRORLEVEL%
|
||||
if %EXIT_CODE% equ 0 set EXIT_CODE=1
|
||||
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
|
||||
exit /b %EXIT_CODE%
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
include ':app'
|
||||
include ':capacitor-cordova-android-plugins'
|
||||
project(':capacitor-cordova-android-plugins').projectDir = new File('./capacitor-cordova-android-plugins/')
|
||||
|
||||
apply from: 'capacitor.settings.gradle'
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
ext {
|
||||
minSdkVersion = 24
|
||||
compileSdkVersion = 36
|
||||
targetSdkVersion = 36
|
||||
androidxActivityVersion = '1.11.0'
|
||||
androidxAppCompatVersion = '1.7.1'
|
||||
androidxCoordinatorLayoutVersion = '1.3.0'
|
||||
androidxCoreVersion = '1.17.0'
|
||||
androidxFragmentVersion = '1.8.9'
|
||||
coreSplashScreenVersion = '1.2.0'
|
||||
androidxWebkitVersion = '1.14.0'
|
||||
junitVersion = '4.13.2'
|
||||
androidxJunitVersion = '1.3.0'
|
||||
androidxEspressoCoreVersion = '3.7.0'
|
||||
cordovaAndroidVersion = '14.0.1'
|
||||
}
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
{
|
||||
"appId": "fyi.crt.levelplay.example",
|
||||
"appName": "LevelPlay Example",
|
||||
"webDir": "www"
|
||||
}
|
||||
|
|
@ -1,54 +0,0 @@
|
|||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
|
||||
<title>LevelPlay Example</title>
|
||||
<link rel="stylesheet" href="style.css" />
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<h1>capacitor-levelplay</h1>
|
||||
<p id="status">Not initialized</p>
|
||||
|
||||
<section>
|
||||
<h2>SDK</h2>
|
||||
<button data-action="init">Initialize</button>
|
||||
<button data-action="capabilities">Capabilities</button>
|
||||
<button data-action="segment">Set segment</button>
|
||||
<button data-action="userId">Dynamic user id</button>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<h2>Full screen</h2>
|
||||
<button data-action="loadRewarded">Load rewarded</button>
|
||||
<button data-action="showRewarded">Show rewarded</button>
|
||||
<button data-action="loadInterstitial">Load interstitial</button>
|
||||
<button data-action="showInterstitial">Show interstitial</button>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<h2>Banner</h2>
|
||||
<button data-action="bannerTop">Top</button>
|
||||
<button data-action="bannerBottom">Bottom</button>
|
||||
<button data-action="bannerHide">Hide</button>
|
||||
<button data-action="bannerShow">Show</button>
|
||||
<button data-action="bannerDestroy">Destroy</button>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<h2>Native</h2>
|
||||
<button data-action="nativeSmall">Small</button>
|
||||
<button data-action="nativeMedium">Medium</button>
|
||||
<button data-action="nativeDestroy">Destroy</button>
|
||||
<div id="native-slot"></div>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<h2>Log <button data-action="clear">Clear</button></h2>
|
||||
<pre id="log"></pre>
|
||||
</section>
|
||||
</main>
|
||||
<script type="module" src="main.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
13
example-app/ios/.gitignore
vendored
|
|
@ -1,13 +0,0 @@
|
|||
App/build
|
||||
App/Pods
|
||||
App/output
|
||||
App/App/public
|
||||
DerivedData
|
||||
xcuserdata
|
||||
|
||||
# Cordova plugins for Capacitor
|
||||
capacitor-cordova-ios-plugins
|
||||
|
||||
# Generated Config files
|
||||
App/App/capacitor.config.json
|
||||
App/App/config.xml
|
||||