This commit is contained in:
Steven Bankhead 2019-10-07 15:27:32 -07:00
Родитель 23cc93d373
Коммит 1123097d27
355 изменённых файлов: 3870 добавлений и 1274 удалений

0
.editorconfig Executable file → Normal file
Просмотреть файл

8
.gitignore поставляемый Executable file → Normal file
Просмотреть файл

@ -5,10 +5,12 @@ local.properties
build
captures
testServerAddress.txt
app/app.iml
lib/lib.iml
app/bin
unity-ads/bin
javadoc
.settings
.project
.vscode
.classpath
.classpath
*.iml
fastlane/report.xml

70
.gitlab-ci.yml Normal file
Просмотреть файл

@ -0,0 +1,70 @@
variables:
stages:
- test
- build
- release
instrumentation-test:
stage: test
script:
- ./scripts/gitlab/setup.sh
- ./scripts/gitlab/instrumentation_test.sh
tags:
- ads_sdk_osx_worker
integration-test:
stage: test
script:
- ./scripts/gitlab/setup.sh
- ./scripts/gitlab/integration_test.sh
tags:
- ads_sdk_osx_worker
legacy-test:
stage: test
script:
- ./scripts/gitlab/setup.sh
- ./scripts/gitlab/legacy_test.sh
tags:
- ads_sdk_osx_worker
build-release:
stage: build
script:
- make zip
tags:
- ads_sdk_osx_worker
artifacts:
when: on_success
paths:
- unity-ads.aar.zip
internal-release:
only:
- /^feature/ci/
- /^release\/[0-9\.]*/
stage: release
script:
- echo "Running an internal release"
- ./scripts/gitlab/post-internal-github-release.sh
tags:
- ads_sdk_osx_worker
dependencies:
- build-release
when: manual
# # TODO
# public-release:
# only:
# - /^feature/ci/
# - /^release\/[0-9\.]*/
# stage: release
# script:
# - echo "Running a public release"
# - ./scripts/gitlab/post-public-github-release.sh
# tags:
# - ads_sdk_osx_worker
# dependencies:
# - build-release
# when: manual

1
.ruby-version Normal file
Просмотреть файл

@ -0,0 +1 @@
2.3.1

3
Gemfile Normal file
Просмотреть файл

@ -0,0 +1,3 @@
source "https://rubygems.org"
gem "fastlane"

159
Gemfile.lock Normal file
Просмотреть файл

@ -0,0 +1,159 @@
GEM
remote: https://rubygems.org/
specs:
CFPropertyList (3.0.1)
addressable (2.6.0)
public_suffix (>= 2.0.2, < 4.0)
atomos (0.1.3)
babosa (1.0.2)
claide (1.0.3)
colored (1.2)
colored2 (3.1.2)
commander-fastlane (4.4.6)
highline (~> 1.7.2)
declarative (0.0.10)
declarative-option (0.1.0)
digest-crc (0.4.1)
domain_name (0.5.20190701)
unf (>= 0.0.5, < 1.0.0)
dotenv (2.7.5)
emoji_regex (1.0.1)
excon (0.66.0)
faraday (0.15.4)
multipart-post (>= 1.2, < 3)
faraday-cookie_jar (0.0.6)
faraday (>= 0.7.4)
http-cookie (~> 1.0.0)
faraday_middleware (0.13.1)
faraday (>= 0.7.4, < 1.0)
fastimage (2.1.5)
fastlane (2.130.0)
CFPropertyList (>= 2.3, < 4.0.0)
addressable (>= 2.3, < 3.0.0)
babosa (>= 1.0.2, < 2.0.0)
bundler (>= 1.12.0, < 3.0.0)
colored
commander-fastlane (>= 4.4.6, < 5.0.0)
dotenv (>= 2.1.1, < 3.0.0)
emoji_regex (>= 0.1, < 2.0)
excon (>= 0.45.0, < 1.0.0)
faraday (~> 0.9)
faraday-cookie_jar (~> 0.0.6)
faraday_middleware (~> 0.9)
fastimage (>= 2.1.0, < 3.0.0)
gh_inspector (>= 1.1.2, < 2.0.0)
google-api-client (>= 0.21.2, < 0.24.0)
google-cloud-storage (>= 1.15.0, < 2.0.0)
highline (>= 1.7.2, < 2.0.0)
json (< 3.0.0)
jwt (~> 2.1.0)
mini_magick (>= 4.9.4, < 5.0.0)
multi_xml (~> 0.5)
multipart-post (~> 2.0.0)
plist (>= 3.1.0, < 4.0.0)
public_suffix (~> 2.0.0)
rubyzip (>= 1.2.2, < 2.0.0)
security (= 0.1.3)
simctl (~> 1.6.3)
slack-notifier (>= 2.0.0, < 3.0.0)
terminal-notifier (>= 2.0.0, < 3.0.0)
terminal-table (>= 1.4.5, < 2.0.0)
tty-screen (>= 0.6.3, < 1.0.0)
tty-spinner (>= 0.8.0, < 1.0.0)
word_wrap (~> 1.0.0)
xcodeproj (>= 1.8.1, < 2.0.0)
xcpretty (~> 0.3.0)
xcpretty-travis-formatter (>= 0.0.3)
gh_inspector (1.1.3)
google-api-client (0.23.9)
addressable (~> 2.5, >= 2.5.1)
googleauth (>= 0.5, < 0.7.0)
httpclient (>= 2.8.1, < 3.0)
mime-types (~> 3.0)
representable (~> 3.0)
retriable (>= 2.0, < 4.0)
signet (~> 0.9)
google-cloud-core (1.3.1)
google-cloud-env (~> 1.0)
google-cloud-env (1.2.1)
faraday (~> 0.11)
google-cloud-storage (1.16.0)
digest-crc (~> 0.4)
google-api-client (~> 0.23)
google-cloud-core (~> 1.2)
googleauth (>= 0.6.2, < 0.10.0)
googleauth (0.6.7)
faraday (~> 0.12)
jwt (>= 1.4, < 3.0)
memoist (~> 0.16)
multi_json (~> 1.11)
os (>= 0.9, < 2.0)
signet (~> 0.7)
highline (1.7.10)
http-cookie (1.0.3)
domain_name (~> 0.5)
httpclient (2.8.3)
json (2.2.0)
jwt (2.1.0)
memoist (0.16.0)
mime-types (3.2.2)
mime-types-data (~> 3.2015)
mime-types-data (3.2019.0331)
mini_magick (4.9.5)
multi_json (1.13.1)
multi_xml (0.6.0)
multipart-post (2.0.0)
nanaimo (0.2.6)
naturally (2.2.0)
os (1.0.1)
plist (3.5.0)
public_suffix (2.0.5)
representable (3.0.4)
declarative (< 0.1.0)
declarative-option (< 0.2.0)
uber (< 0.2.0)
retriable (3.1.2)
rouge (2.0.7)
rubyzip (1.2.3)
security (0.1.3)
signet (0.11.0)
addressable (~> 2.3)
faraday (~> 0.9)
jwt (>= 1.5, < 3.0)
multi_json (~> 1.10)
simctl (1.6.5)
CFPropertyList
naturally
slack-notifier (2.3.2)
terminal-notifier (2.0.0)
terminal-table (1.8.0)
unicode-display_width (~> 1.1, >= 1.1.1)
tty-cursor (0.7.0)
tty-screen (0.7.0)
tty-spinner (0.9.1)
tty-cursor (~> 0.7)
uber (0.1.0)
unf (0.1.4)
unf_ext
unf_ext (0.0.7.6)
unicode-display_width (1.6.0)
word_wrap (1.0.0)
xcodeproj (1.12.0)
CFPropertyList (>= 2.3.3, < 4.0)
atomos (~> 0.1.3)
claide (>= 1.0.2, < 2.0)
colored2 (~> 3.1)
nanaimo (~> 0.2.6)
xcpretty (0.3.0)
rouge (~> 2.0.7)
xcpretty-travis-formatter (1.0.0)
xcpretty (~> 0.2, >= 0.0.7)
PLATFORMS
ruby
DEPENDENCIES
fastlane
BUNDLED WITH
2.0.2

0
Jenkinsfile поставляемый Executable file → Normal file
Просмотреть файл

0
LICENSE Executable file → Normal file
Просмотреть файл

36
Makefile Executable file → Normal file
Просмотреть файл

@ -1,8 +1,8 @@
release:
./gradlew :lib:assembleRelease
./gradlew :unity-ads:assembleRelease
clean:
./gradlew :lib:clean
./gradlew :unity-ads:clean
test: test-hosted
@ -11,7 +11,7 @@ test-local: push-test-server-address exec-tests
test-unit-tests: push-test-server-address exec-unit-tests
build-test-apk: clean
./gradlew :lib:assembleAndroidTest --full-stacktrace
./gradlew :unity-ads:assembleAndroidTest --full-stacktrace
test-emulator: exec-tests
@ -23,11 +23,11 @@ exec-tests: exec-unit-tests exec-hybrid-tests
exec-unit-tests: clean
adb shell input keyevent 82
./gradlew :lib:connectedCheck --full-stacktrace -Pandroid.testInstrumentationRunnerArguments.class=com.unity3d.ads.test.UnitTestSuite
./gradlew :unity-ads:connectedCheck --full-stacktrace -Pandroid.testInstrumentationRunnerArguments.class=com.unity3d.ads.test.LegacyTestSuite
exec-hybrid-tests: clean
adb shell input keyevent 82
./gradlew :lib:connectedCheck --full-stacktrace -Pandroid.testInstrumentationRunnerArguments.class=com.unity3d.ads.test.HybridTestSuite
./gradlew :unity-ads:connectedCheck --full-stacktrace -Pandroid.testInstrumentationRunnerArguments.class=com.unity3d.ads.test.HybridTestSuite
push-test-server-address:
echo http://$(shell ifconfig |grep "inet" |grep -E -o "([0-9]{1,3}[\.]){3}[0-9]{1,3}" |grep -v -E "^0|^127" -m 1):8080 > testServerAddress.txt
@ -48,16 +48,30 @@ dismantle-adb-reverse:
adb reverse --remove-all
javadoc:
./gradlew :lib:javadoc
./gradlew :unity-ads:javadoc
zip: release
cp lib/build/outputs/aar/unity-ads-release.aar unity-ads.aar
zip -9r builds.zip unity-ads.aar
cp unity-ads/build/outputs/aar/unity-ads-release.aar unity-ads.aar
zip -9r unity-ads.aar.zip unity-ads.aar
rm unity-ads.aar
verify-release-build:
if [[ -f "unity-ads.aar.zip" ]]; then \
echo 'unity-ads.aar.zip exists'; \
else \
echo 'unity-ads.aar.zip does not exist'; \
exit 1; \
fi;
use-local-webview:
sed -i '' 's/return "https:\/\/config.unityads.unity3d.com\/webview\/" + getWebViewBranch() + "\/" + flavor + "\/config.json";/return "new-ip";/' "lib/src/main/java/com/unity3d/services/core/properties/SdkProperties.java"
sed -i '' 's/return ".*";/return "http:\/\/$(shell ifconfig |grep "inet" |grep -E -o "([0-9]{1,3}[\.]){3}[0-9]{1,3}" |grep -v -E "^0|^127" -m 1):8000\/build\/" + flavor + "\/config.json";/' "lib/src/main/java/com/unity3d/services/core/properties/SdkProperties.java"
sed -i '' 's/return "https:\/\/config.unityads.unity3d.com\/webview\/" + getWebViewBranch() + "\/" + flavor + "\/config.json";/return "new-ip";/' "unity-ads/src/main/java/com/unity3d/services/core/properties/SdkProperties.java"
sed -i '' 's/return ".*";/return "http:\/\/$(shell ifconfig |grep "inet" |grep -E -o "([0-9]{1,3}[\.]){3}[0-9]{1,3}" |grep -v -E "^0|^127" -m 1):8000\/build\/" + flavor + "\/config.json";/' "unity-ads/src/main/java/com/unity3d/services/core/properties/SdkProperties.java"
use-public-webview:
sed -i '' 's/return ".*";/return "https:\/\/config.unityads.unity3d.com\/webview\/" + getWebViewBranch() + "\/" + flavor + "\/config.json";/' "lib/src/main/java/com/unity3d/services/core/properties/SdkProperties.java"
sed -i '' 's/return ".*";/return "https:\/\/config.unityads.unity3d.com\/webview\/" + getWebViewBranch() + "\/" + flavor + "\/config.json";/' "unity-ads/src/main/java/com/unity3d/services/core/properties/SdkProperties.java"
create-android-26-emulator:
echo "no" | ${ANDROID_HOME}/tools/bin/avdmanager create avd --name "android-26-test" --package "system-images;android-26;google_apis;x86" --device "Nexus 6P" --tag google_apis --abi google_apis/x86 --force
start-android-26-emulator:
${ANDROID_HOME}/emulator/emulator -port 5556 -avd android-26-test -no-window -noaudio -no-boot-anim -memory 2048 -partition-size 1024 &

4
README.md Executable file → Normal file
Просмотреть файл

@ -1,6 +1,6 @@
# Unity Ads Android Release Repository
# Unity Ads 3 Android Release Repository
Welcome to the Unity Ads Android release repository.
Welcome to the Unity Ads 3 Android release repository.
## Binaries

0
app/.gitignore поставляемый Executable file → Normal file
Просмотреть файл

63
app/build.gradle Executable file → Normal file
Просмотреть файл

@ -1,42 +1,45 @@
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion '28.0.2'
compileSdkVersion 26
buildToolsVersion '28.0.2'
defaultConfig {
applicationId "com.unity3d.ads.example"
minSdkVersion 14
targetSdkVersion 26
versionCode = 3200
versionName = "3.2.0"
}
defaultConfig {
applicationId "com.unity3d.ads.example"
minSdkVersion 14
targetSdkVersion 26
versionCode = 3300
versionName = "3.3.0"
}
flavorDimensions "arEnabled"
productFlavors {
ar {
dimension "arEnabled"
flavorDimensions "arEnabled"
productFlavors {
ar {
dimension "arEnabled"
}
vanilla {
dimension "arEnabled"
}
}
vanilla {
dimension "arEnabled"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:26.1.0'
arImplementation 'com.google.ar:core:1.4.0'
implementation project(':lib')
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:design:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'android.arch.lifecycle:extensions:1.1.1'
arImplementation 'com.google.ar:core:1.4.0'
implementation project(':unity-ads')
}

0
app/proguard-rules.pro поставляемый Executable file → Normal file
Просмотреть файл

0
app/src/ar/AndroidManifest.xml Executable file → Normal file
Просмотреть файл

34
app/src/main/AndroidManifest.xml Executable file → Normal file
Просмотреть файл

@ -1,31 +1,47 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.unity3d.ads.example" >
package="com.unity3d.ads.example">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="UnityAds 3.0"
android:theme="@style/AppTheme" >
<meta-data android:name="com.google.ar.core" android:value="optional" />
android:theme="@style/AppTheme">
<activity
android:name="com.unity3d.ads.example.UnityAdsExample"
android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen"
android:label="UnityAds 3.0" >
android:name=".UnityAdsTestApp"
android:label="@string/title_activity_unity_ads_test_app"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.ar.core"
android:value="optional" />
<activity
android:name=".UnityAdsExample"
android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen"
android:label="UnityAds 3.0">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.unity3d.ads.example.UnityMonetizationExample"
android:name=".UnityMonetizationExample"
android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen"
android:label="UnityMonetization 3.0" >
android:label="UnityMonetization 3.0">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
</manifest>

Просмотреть файл

@ -24,6 +24,9 @@ import com.unity3d.services.core.misc.Utilities;
import com.unity3d.services.core.properties.SdkProperties;
import com.unity3d.services.core.webview.WebView;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
public class UnityAdsExample extends Activity {
final private String defaultGameId = "14851";
@ -36,7 +39,7 @@ public class UnityAdsExample extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.unityads_example_layout);
setContentView(R.layout.fragment_unity_ads);
final UnityAdsExample self = this;
final UnityAdsListener unityAdsListener = new UnityAdsListener();

Просмотреть файл

@ -0,0 +1,28 @@
package com.unity3d.ads.example;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import com.unity3d.ads.example.ui.main.SectionsPagerAdapter;
public class UnityAdsTestApp extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_unity_ads_test_app);
SectionsPagerAdapter sectionsPagerAdapter = new SectionsPagerAdapter(this, getSupportFragmentManager());
ViewPager viewPager = findViewById(R.id.view_pager);
viewPager.setAdapter(sectionsPagerAdapter);
TabLayout tabs = findViewById(R.id.tabs);
tabs.setupWithViewPager(viewPager);
}
}

Просмотреть файл

@ -21,7 +21,6 @@ import com.unity3d.ads.metadata.PlayerMetaData;
import com.unity3d.services.UnityServices;
import com.unity3d.services.banners.IUnityBannerListener;
import com.unity3d.services.banners.UnityBanners;
import com.unity3d.services.banners.view.BannerPosition;
import com.unity3d.services.core.log.DeviceLog;
import com.unity3d.services.core.properties.SdkProperties;
import com.unity3d.services.core.webview.WebView;
@ -62,7 +61,7 @@ public class UnityMonetizationExample extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.unityads_example_layout);
setContentView(R.layout.fragment_unity_ads);
final UnityMonetizationExample thisActivity = this;
final IUnityMonetizationListener unityMonetizationListener = new UnityMonetizationListener();
final IUnityBannerListener unityBannerListener = new UnityBannerListener();
@ -157,7 +156,6 @@ public class UnityMonetizationExample extends Activity {
@Override
public void onClick(View v) {
if (bannerView == null) {
UnityBanners.setBannerPosition(BannerPosition.BOTTOM_CENTER);
UnityBanners.loadBanner(thisActivity, bannerPlacementId);
} else {
UnityBanners.destroy();

Просмотреть файл

@ -0,0 +1,52 @@
package com.unity3d.ads.example.ui.main;
import android.content.Context;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import com.unity3d.ads.example.R;
/**
* A [FragmentPagerAdapter] that returns a fragment corresponding to
* one of the sections/tabs/pages.
*/
public class SectionsPagerAdapter extends FragmentPagerAdapter {
@StringRes
private static final int[] TAB_TITLES = new int[]{R.string.tab_text_1, R.string.tab_text_2, R.string.tab_text_3};
private final Context mContext;
public SectionsPagerAdapter(Context context, FragmentManager fm) {
super(fm);
mContext = context;
}
@Override
public Fragment getItem(int position) {
// getItem is called to instantiate the fragment for the given page.
// Return a UnityAdsFragment (defined as a static inner class below).
switch (position) {
case 0:
return UnityAdsFragment.newInstance(position);
case 1:
return UnityBannersFragment.newInstance(position);
default:
return UnityAdsFragment.newInstance(position);
}
}
@Nullable
@Override
public CharSequence getPageTitle(int position) {
return mContext.getResources().getString(TAB_TITLES[position]);
}
@Override
public int getCount() {
// Show 2 total pages.
return 2;
}
}

Просмотреть файл

@ -0,0 +1,238 @@
package com.unity3d.ads.example.ui.main;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.view.animation.AlphaAnimation;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.unity3d.ads.IUnityAdsListener;
import com.unity3d.ads.UnityAds;
import com.unity3d.ads.example.R;
import com.unity3d.ads.metadata.MediationMetaData;
import com.unity3d.ads.metadata.MetaData;
import com.unity3d.ads.metadata.PlayerMetaData;
import com.unity3d.services.core.log.DeviceLog;
import com.unity3d.services.core.misc.Utilities;
import com.unity3d.services.core.properties.SdkProperties;
import com.unity3d.services.core.webview.WebView;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
/**
* A placeholder fragment containing a simple view.
*/
public class UnityAdsFragment extends Fragment implements IUnityAdsListener {
private View root;
private EditText gameIdEdit;
private CheckBox testModeCheckBox;
private Button initializeButton;
private Button interstitialButton;
private Button incentivizedButton;
private TextView statusText;
private String interstitialPlacementId;
private String incentivizedPlacementId;
private int ordinal = 1;
final private String defaultGameId = "14851";
public static UnityAdsFragment newInstance(int index) {
UnityAdsFragment fragment = new UnityAdsFragment();
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(
@NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
this.root = inflater.inflate(R.layout.fragment_unity_ads, container, false);
this.gameIdEdit = root.findViewById(R.id.unityads_example_gameid_edit);
this.testModeCheckBox = root.findViewById(R.id.unityads_example_testmode_checkbox);
this.initializeButton = root.findViewById(R.id.unityads_example_initialize_button);
this.interstitialButton = root.findViewById(R.id.unityads_example_interstitial_button);
this.incentivizedButton = root.findViewById(R.id.unityads_example_incentivized_button);
this.statusText = root.findViewById(R.id.unityads_example_statustext);
enableButton(initializeButton);
disableButton(interstitialButton);
disableButton(incentivizedButton);
SharedPreferences preferences = getActivity().getSharedPreferences("Settings", Context.MODE_PRIVATE);
gameIdEdit.setText(preferences.getString("gameId", defaultGameId));
testModeCheckBox.setChecked( true);
if(Build.VERSION.SDK_INT >= 19) {
WebView.setWebContentsDebuggingEnabled(true);
}
UnityAds.addListener(this);
UnityAds.setDebugMode(true);
MediationMetaData mediationMetaData = new MediationMetaData(getActivity());
mediationMetaData.setName("mediationPartner");
mediationMetaData.setVersion("v12345");
mediationMetaData.commit();
MetaData debugMetaData = new MetaData(getActivity());
debugMetaData.set("test.debugOverlayEnabled", true);
debugMetaData.commit();
final UnityAdsFragment self = this;
this.initializeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String gameId = gameIdEdit.getText().toString();
if (gameId.isEmpty()) {
Toast.makeText(getActivity().getApplicationContext(), "Missing game id", Toast.LENGTH_SHORT).show();
return;
}
disableButton(initializeButton);
gameIdEdit.setEnabled(false);
testModeCheckBox.setEnabled(false);
statusText.setText("Initializing...");
UnityAds.initialize(getActivity(), gameId, self, testModeCheckBox.isChecked());
// store entered gameid in app settings
SharedPreferences preferences = getActivity().getSharedPreferences("Settings", Context.MODE_PRIVATE);
SharedPreferences.Editor preferencesEdit = preferences.edit();
preferencesEdit.putString("gameId", gameId);
preferencesEdit.commit();
}
});
this.interstitialButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
disableButton(interstitialButton);
PlayerMetaData playerMetaData = new PlayerMetaData(getActivity());
playerMetaData.setServerId("rikshot");
playerMetaData.commit();
MediationMetaData ordinalMetaData = new MediationMetaData(getActivity());
ordinalMetaData.setOrdinal(ordinal++);
ordinalMetaData.commit();
UnityAds.show(getActivity(), interstitialPlacementId);
}
});
this.incentivizedButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
disableButton(incentivizedButton);
PlayerMetaData playerMetaData = new PlayerMetaData(getActivity());
playerMetaData.setServerId("rikshot");
playerMetaData.commit();
MediationMetaData ordinalMetaData = new MediationMetaData(getActivity());
ordinalMetaData.setOrdinal(ordinal++);
ordinalMetaData.commit();
UnityAds.show(getActivity(), incentivizedPlacementId);
}
});
return root;
}
private void enableButton (Button btn) {
btn.setEnabled(true);
float alpha = 1f;
AlphaAnimation alphaUp = new AlphaAnimation(alpha, alpha);
alphaUp.setFillAfter(true);
btn.startAnimation(alphaUp);
}
private void disableButton (Button btn) {
float alpha = 0.45f;
btn.setEnabled(false);
AlphaAnimation alphaUp = new AlphaAnimation(alpha, alpha);
alphaUp.setFillAfter(true);
btn.startAnimation(alphaUp);
}
/* LISTENER */
@Override
public void onUnityAdsReady(final String zoneId) {
TextView statusText = this.statusText;
final Button interstitialButton = this.interstitialButton;
final Button incentivizedButton = this.incentivizedButton;
statusText.setText("");
DeviceLog.debug("onUnityAdsReady: " + zoneId);
Utilities.runOnUiThread(new Runnable() {
@Override
public void run() {
// look for various default placement ids over time
switch (zoneId) {
case "video":
case "defaultZone":
case "defaultVideoAndPictureZone":
interstitialPlacementId = zoneId;
enableButton(interstitialButton);
break;
case "rewardedVideo":
case "rewardedVideoZone":
case "incentivizedZone":
incentivizedPlacementId = zoneId;
enableButton(incentivizedButton);
break;
}
}
});
toast("Ready", zoneId);
}
@Override
public void onUnityAdsStart(String zoneId) {
DeviceLog.debug("onUnityAdsStart: " + zoneId);
toast("Start", zoneId);
}
@Override
public void onUnityAdsFinish(String zoneId, UnityAds.FinishState result) {
DeviceLog.debug("onUnityAdsFinish: " + zoneId + " - " + result);
toast("Finish", zoneId + " " + result);
}
@Override
public void onUnityAdsError(UnityAds.UnityAdsError error, String message) {
DeviceLog.debug("onUnityAdsError: " + error + " - " + message);
toast("Error", error + " " + message);
TextView statusText = this.statusText;
statusText.setText(error + " - " + message);
}
private void toast(String callback, String msg) {
if (getContext() != null) {
Toast.makeText(getContext(), callback + ": " + msg, Toast.LENGTH_SHORT).show();
}
}
}

Просмотреть файл

@ -0,0 +1,168 @@
package com.unity3d.ads.example.ui.main;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AlphaAnimation;
import android.widget.Button;
import android.widget.LinearLayout;
import com.unity3d.ads.example.R;
import com.unity3d.services.banners.BannerErrorInfo;
import com.unity3d.services.banners.IUnityBannerListener;
import com.unity3d.services.banners.BannerView;
import com.unity3d.services.banners.UnityBannerSize;
import com.unity3d.services.banners.UnityBanners;
import com.unity3d.services.banners.view.BannerPosition;
import com.unity3d.services.core.misc.Utilities;
import com.unity3d.services.core.misc.ViewUtilities;
public class UnityBannersFragment extends Fragment implements IUnityBannerListener {
private Button topBannerButton;
private Button unityBannerAdOldButton;
private LinearLayout topBannerContainer;
private BannerView topBannerAdView;
private BannerView topBannerView;
private boolean unityBannerOldShowing = false;
private BannerView.IListener bannerAdViewListener;
public static UnityBannersFragment newInstance(int index) {
UnityBannersFragment fragment = new UnityBannersFragment();
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.bannerAdViewListener = this.createBannerListener();
}
@Override
public View onCreateView(
@NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.fragment_unity_banners, container, false);
this.topBannerButton = root.findViewById(R.id.top_banner_button);
this.unityBannerAdOldButton = root.findViewById(R.id.unity_banner_ad_old_button);
this.topBannerContainer = root.findViewById(R.id.top_banner_container);
this.enableButton(topBannerButton);
this.enableButton(unityBannerAdOldButton);
final UnityBannersFragment self = this;
this.topBannerButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (self.topBannerView != null) {
self.topBannerContainer.removeView(self.topBannerView);
self.topBannerView.destroy();
self.topBannerView = null;
self.topBannerButton.setText(R.string.show_top_banner);
} else {
int widthInDp = Math.round(ViewUtilities.dpFromPx(self.getContext(), self.topBannerContainer.getWidth()));
int heightInDp = Math.round(ViewUtilities.dpFromPx(self.getContext(), self.topBannerContainer.getHeight()));
UnityBannerSize unityBannerSize = new UnityBannerSize(widthInDp, heightInDp);
self.topBannerView = new BannerView(self.getActivity(), "bannerads", unityBannerSize);
self.topBannerView.setListener(self.bannerAdViewListener);
self.topBannerView.load();
self.topBannerButton.setText(R.string.hide_top_banner);
self.topBannerContainer.addView(self.topBannerView);
}
}
});
this.unityBannerAdOldButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (self.unityBannerOldShowing) {
UnityBanners.destroy();
self.unityBannerAdOldButton.setText(R.string.show_old_banner);
self.unityBannerOldShowing = false;
} else {
self.unityBannerOldShowing = true;
self.unityBannerAdOldButton.setText(R.string.hide_old_banner);
UnityBanners.setBannerPosition(BannerPosition.BOTTOM_CENTER);
UnityBanners.setBannerListener(self);
UnityBanners.loadBanner(getActivity(), "bannerads");
}
}
});
return root;
}
private void enableButton (Button btn) {
btn.setEnabled(true);
float alpha = 1f;
AlphaAnimation alphaUp = new AlphaAnimation(alpha, alpha);
alphaUp.setFillAfter(true);
btn.startAnimation(alphaUp);
}
private BannerView.IListener createBannerListener() {
final UnityBannersFragment self = this;
return new BannerView.Listener() {
@Override
public void onBannerFailedToLoad(BannerView bannerAdView, BannerErrorInfo errorInfo) {
if (self.topBannerView != null && self.topBannerView == bannerAdView) {
self.topBannerContainer.removeView(self.topBannerView);
self.topBannerView.destroy();
self.topBannerView = null;
self.topBannerButton.setText(R.string.show_top_banner);
}
}
@Override
public void onBannerLoaded(BannerView bannerAdView) {
Log.d("UnityAdsExample", "onBannerLoded is called for: " + bannerAdView.getPlacementId());
}
@Override
public void onBannerClick(BannerView bannerAdView) {
Log.d("UnityAdsExample", "onBannerClick is called for: " + bannerAdView.getPlacementId());
}
@Override
public void onBannerLeftApplication(BannerView bannerAdView) {
Log.d("UnityAdsExample", "onBannerLeftApplication is called for: " + bannerAdView.getPlacementId());
}
};
}
public void onUnityBannerLoaded(String placementId, final View view) {
final UnityBannersFragment self = this;
Utilities.runOnUiThread(new Runnable() {
@Override
public void run() {
if (view.getParent() == null) {
self.getActivity().addContentView(view, view.getLayoutParams());
}
}
});
}
public void onUnityBannerUnloaded(String placementId) {
}
public void onUnityBannerShow(String placementId) {
}
public void onUnityBannerClick(String placementId) {
}
public void onUnityBannerHide(String placementId) {
}
public void onUnityBannerError(String message) {
Log.e("BANNER ERROR", message);
}
}

0
app/src/main/res/drawable/circle_button.xml Executable file → Normal file
Просмотреть файл

Просмотреть файл

До

Ширина:  |  Высота:  |  Размер: 559 KiB

После

Ширина:  |  Высота:  |  Размер: 559 KiB

0
app/src/main/res/drawable/native_promo_button.png Executable file → Normal file
Просмотреть файл

До

Ширина:  |  Высота:  |  Размер: 9.6 KiB

После

Ширина:  |  Высота:  |  Размер: 9.6 KiB

Просмотреть файл

0
app/src/main/res/drawable/unityads_logo.png Executable file → Normal file
Просмотреть файл

До

Ширина:  |  Высота:  |  Размер: 6.5 KiB

После

Ширина:  |  Высота:  |  Размер: 6.5 KiB

Просмотреть файл

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.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=".UnityAdsTestApp">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:minHeight="?actionBarSize"
android:padding="@dimen/appbar_padding"
android:text="@string/app_name"
android:textAppearance="@style/TextAppearance.Widget.AppCompat.Toolbar.Title" />
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>

Просмотреть файл

Просмотреть файл

@ -0,0 +1,57 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/unityads_example_background"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:orientation="vertical"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:paddingStart="15dp"
android:paddingTop="25dp"
android:gravity="center_horizontal">
<LinearLayout
android:id="@+id/top_banner_container"
android:layout_height="70dp"
android:layout_width="match_parent"
android:orientation="vertical"
android:gravity="center_horizontal"
></LinearLayout>
<LinearLayout
android:id="@+id/unity_banner_ad_refresh_container"
android:layout_height="70dp"
android:layout_width="match_parent"
android:orientation="vertical"
android:gravity="center_horizontal"
></LinearLayout>
<Button
android:id="@+id/top_banner_button"
android:layout_height="45dp"
android:layout_width="match_parent"
android:layout_marginBottom="15dp"
android:background="#FF2196F3"
android:text="@string/show_top_banner"
android:textColor="@android:color/white"
android:visibility="visible" />
<Button
android:id="@+id/unity_banner_ad_old_button"
android:layout_height="45dp"
android:layout_width="match_parent"
android:layout_marginBottom="15dp"
android:background="#FF2196F3"
android:text="@string/show_old_banner"
android:textColor="@android:color/white"
android:visibility="visible" />
</LinearLayout>
</RelativeLayout>

Просмотреть файл

0
app/src/main/res/mipmap-hdpi/ic_launcher.png Executable file → Normal file
Просмотреть файл

До

Ширина:  |  Высота:  |  Размер: 8.3 KiB

После

Ширина:  |  Высота:  |  Размер: 8.3 KiB

0
app/src/main/res/mipmap-mdpi/ic_launcher.png Executable file → Normal file
Просмотреть файл

До

Ширина:  |  Высота:  |  Размер: 4.6 KiB

После

Ширина:  |  Высота:  |  Размер: 4.6 KiB

0
app/src/main/res/mipmap-xhdpi/ic_launcher.png Executable file → Normal file
Просмотреть файл

До

Ширина:  |  Высота:  |  Размер: 13 KiB

После

Ширина:  |  Высота:  |  Размер: 13 KiB

0
app/src/main/res/mipmap-xxhdpi/ic_launcher.png Executable file → Normal file
Просмотреть файл

До

Ширина:  |  Высота:  |  Размер: 25 KiB

После

Ширина:  |  Высота:  |  Размер: 25 KiB

0
app/src/main/res/mipmap-xxxhdpi/ic_launcher.png Executable file → Normal file
Просмотреть файл

До

Ширина:  |  Высота:  |  Размер: 35 KiB

После

Ширина:  |  Высота:  |  Размер: 35 KiB

Просмотреть файл

@ -0,0 +1,6 @@
<resources>
<!-- Example customization of dimensions originally defined in res/values/dimens.xml
(such as screen margins) for screens with more than 820dp of available width. This
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
<dimen name="activity_horizontal_margin">64dp</dimen>
</resources>

Просмотреть файл

@ -0,0 +1,8 @@
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
<dimen name="appbar_padding">16dp</dimen>
<dimen name="fab_margin">16dp</dimen>
<dimen name="appbar_padding_top">8dp</dimen>
</resources>

18
app/src/main/res/values/strings.xml Executable file → Normal file
Просмотреть файл

@ -4,4 +4,22 @@
<string name="unityads_example_interstitial_text">Interstitial</string>
<string name="unityads_example_incentivized_text">Incentivized</string>
<string name="unityads_example_banner_text">Banner</string>
<string name="title_activity_unity_ads_test_app">UnityAdsTestApp</string>
<string name="tab_text_1">Ads</string>
<string name="tab_text_2">Banners</string>
<string name="tab_text_3">Load</string>
<string name="app_name">Unity Ads Test App</string>
<string name="show_top_banner">Show Top Banner</string>
<string name="hide_top_banner">Hide Top Banner</string>
<string name="show_bottom_banner">Show Bottom Banner</string>
<string name="hide_bottom_banner">Hide Bottom Banner</string>
<string name="show_refresh_banner">Show Refresh Banner</string>
<string name="hide_refresh_banner">Hide Refresh Banner</string>
<string name="show_old_banner">Show Old Banner</string>
<string name="hide_old_banner">Hide Old Banner</string>
<string name="load_text">Load</string>
<string name="show_text">Show</string>
<!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string>
</resources>

9
app/src/main/res/values/styles.xml Executable file → Normal file
Просмотреть файл

@ -5,4 +5,13 @@
<!-- Customize your theme here. -->
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources>

30
build.gradle Executable file → Normal file
Просмотреть файл

@ -1,22 +1,22 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.4'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
}
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.4'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
}
}
allprojects {
repositories {
jcenter()
google()
}
repositories {
google()
jcenter()
}
}

2
fastlane/Appfile Normal file
Просмотреть файл

@ -0,0 +1,2 @@
json_key_file("") # Path to the json secret file - Follow https://docs.fastlane.tools/actions/supply/#setup to get one
package_name("com.unity3d.ads") # e.g. com.krausefx.app

44
fastlane/Fastfile Normal file
Просмотреть файл

@ -0,0 +1,44 @@
# This file contains the fastlane.tools configuration
# You can find the documentation at https://docs.fastlane.tools
#
# For a list of all available actions, check out
#
# https://docs.fastlane.tools/actions
#
# For a list of all available plugins, check out
#
# https://docs.fastlane.tools/plugins/available-plugins
#
# Uncomment the line if you want fastlane to automatically update itself
# update_fastlane
default_platform(:android)
platform :android do
desc "Runs all of the instrumentation tests"
lane :instrumentation_test do
gradle(
task: "connectedDebugAndroidTest",
flags: "-i -Pandroid.testInstrumentationRunnerArguments.class=com.unity3d.ads.test.InstrumentationTestSuite"
)
end
desc "Runs all of the instrumentation tests"
lane :legacy_test do
gradle(
task: "connectedDebugAndroidTest",
flags: "-i -Pandroid.testInstrumentationRunnerArguments.class=com.unity3d.ads.test.LegacyTestSuite"
)
end
desc "Runs all of the integration tests"
lane :integration_test do
gradle(
task: "connectedDebugAndroidTest",
flags: "-i -Pandroid.testInstrumentationRunnerArguments.class=com.unity3d.ads.test.IntegrationTestSuite"
)
end
end

39
fastlane/README.md Normal file
Просмотреть файл

@ -0,0 +1,39 @@
fastlane documentation
================
# Installation
Make sure you have the latest version of the Xcode command line tools installed:
```
xcode-select --install
```
Install _fastlane_ using
```
[sudo] gem install fastlane -NV
```
or alternatively using `brew cask install fastlane`
# Available Actions
## Android
### android instrumentation_test
```
fastlane android instrumentation_test
```
Runs all of the instrumentation tests
### android legacy_test
```
fastlane android legacy_test
```
Runs all of the instrumentation tests
### android integration_test
```
fastlane android integration_test
```
Runs all of the integration tests
----
This README.md is auto-generated and will be re-generated every time [fastlane](https://fastlane.tools) is run.
More information about fastlane can be found on [fastlane.tools](https://fastlane.tools).
The documentation of fastlane can be found on [docs.fastlane.tools](https://docs.fastlane.tools).

0
gradle.properties Executable file → Normal file
Просмотреть файл

0
gradle/wrapper/gradle-wrapper.jar поставляемый Executable file → Normal file
Просмотреть файл

0
gradle/wrapper/gradle-wrapper.properties поставляемый Executable file → Normal file
Просмотреть файл

0
gradlew.bat поставляемый Executable file → Normal file
Просмотреть файл

Просмотреть файл

@ -1,55 +0,0 @@
package com.unity3d.ads.test;
import com.unity3d.ads.test.unit.*;
import com.unity3d.ads.test.unit.services.ads.load.LoadBridgeTest;
import com.unity3d.ads.test.unit.services.ads.load.LoadModuleTest;
import com.unity3d.ads.test.unit.services.core.configuration.InitializationNotificationCenterTest;
import com.unity3d.services.ads.properties.AdsPropertiesTests;
import com.unity3d.services.analytics.UnityAnalyticsTest;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
@RunWith(Suite.class)
@Suite.SuiteClasses({
AdUnitActivityTest.class,
AdvertisingIdentifierTest.class,
BroadcastTest.class,
CacheTest.class,
ClientPropertiesTest.class,
ConnectivityTest.class,
DeviceTest.class,
EventIdTest.class,
EnvironmentCheckTest.class,
EventIdTest.class,
InitializeThreadTest.class,
InvocationTest.class,
MetaDataTest.class,
NativeCallbackTest.class,
PackageManagerTest.class,
PlacementTest.class,
PublicApiTest.class,
RequestTest.class,
SdkPropertiesTest.class,
StorageDiskTest.class,
StorageGeneralTest.class,
StorageMemoryTest.class,
VideoViewTest.class,
WebViewAppTest.class,
WebViewBridgeInterfaceTest.class,
WebViewBridgeTest.class,
WebViewCallbackTest.class,
LifecycleListenerTest.class,
VolumeChangeTest.class,
UtilitiesTest.class,
WebPlayerTest.class,
PreferencesTest.class,
WebRequestThreadPoolTest.class,
UnityAnalyticsTest.class,
AdsPropertiesTests.class,
InitializationNotificationCenterTest.class,
LoadModuleTest.class,
LoadBridgeTest.class
})
public class UnitTestSuite {}

Просмотреть файл

@ -1,57 +0,0 @@
package com.unity3d.services.ads.adunit;
import android.os.Bundle;
import android.view.View;
import com.unity3d.services.ads.webplayer.WebPlayer;
import com.unity3d.services.core.misc.ViewUtilities;
public class WebPlayerHandler implements IAdUnitViewHandler {
private WebPlayer _webPlayer;
public boolean create(AdUnitActivity activity) {
if (_webPlayer == null) {
_webPlayer = new WebPlayer(activity, "webplayer", com.unity3d.services.ads.api.WebPlayer.getWebSettings(), com.unity3d.services.ads.api.WebPlayer.getWebPlayerSettings());
_webPlayer.setEventSettings(com.unity3d.services.ads.api.WebPlayer.getWebPlayerEventSettings());
}
return true;
}
public boolean destroy() {
if (_webPlayer != null) {
ViewUtilities.removeViewFromParent(_webPlayer);
_webPlayer.destroy();
}
_webPlayer = null;
return true;
}
public View getView() {
return _webPlayer;
}
public void onCreate(AdUnitActivity activity, Bundle savedInstanceState) {
this.create(activity);
}
public void onStart(AdUnitActivity activity) {
}
public void onStop(AdUnitActivity activity) {
}
public void onResume(AdUnitActivity activity) {
}
public void onPause(AdUnitActivity activity) {
}
public void onDestroy(AdUnitActivity activity) {
if (activity.isFinishing()) {
destroy();
}
}
}

Просмотреть файл

@ -1,206 +0,0 @@
package com.unity3d.services.ads.api;
import android.view.View;
import com.unity3d.services.ads.adunit.IAdUnitViewHandler;
import com.unity3d.services.banners.view.BannerView;
import com.unity3d.services.core.log.DeviceLog;
import com.unity3d.services.ads.webplayer.WebPlayerError;
import com.unity3d.services.core.webview.bridge.WebViewCallback;
import com.unity3d.services.core.webview.bridge.WebViewExposed;
import org.json.JSONArray;
import org.json.JSONObject;
import java.util.Iterator;
import java.util.Map;
import static com.unity3d.services.core.misc.Utilities.runOnUiThread;
public class WebPlayer {
private static JSONObject _webSettings = null;
private static JSONObject _webPlayerSettings = null;
private static JSONObject _webPlayerEventSettings = null;
public static JSONObject getWebPlayerSettings () {
return _webPlayerSettings;
}
public static JSONObject getWebSettings () {
return _webSettings;
}
public static JSONObject getWebPlayerEventSettings () {
return _webPlayerEventSettings;
}
@WebViewExposed
public static void setUrl (final String url, String viewId, final WebViewCallback callback) {
final com.unity3d.services.ads.webplayer.WebPlayer webPlayer = getWebPlayer(viewId);
if (webPlayer != null) {
runOnUiThread(new Runnable() {
@Override
public void run() {
webPlayer.loadUrl(url);
}
});
callback.invoke();
} else {
callback.error(WebPlayerError.WEBPLAYER_NULL);
}
}
@WebViewExposed
public static void setData (final String data, final String mimeType, final String encoding, String viewId, final WebViewCallback callback) {
final com.unity3d.services.ads.webplayer.WebPlayer webPlayer = getWebPlayer(viewId);
if (webPlayer != null) {
runOnUiThread(new Runnable() {
@Override
public void run() {
webPlayer.loadData(data, mimeType, encoding);
}
});
callback.invoke();
} else {
callback.error(WebPlayerError.WEBPLAYER_NULL);
}
}
@WebViewExposed
public static void setDataWithUrl (final String baseUrl, final String data, final String mimeType, final String encoding, String viewId, final WebViewCallback callback) {
final com.unity3d.services.ads.webplayer.WebPlayer webPlayer = getWebPlayer(viewId);
if (webPlayer != null) {
runOnUiThread(new Runnable() {
@Override
public void run() {
webPlayer.loadDataWithBaseURL(baseUrl, data, mimeType, encoding, null);
}
});
callback.invoke();
} else {
callback.error(WebPlayerError.WEBPLAYER_NULL);
}
}
@WebViewExposed
public static void setSettings (final JSONObject webSettings, final JSONObject webPlayerSettings, String viewId, final WebViewCallback callback) {
switch (viewId) {
case "bannerplayer":
runOnUiThread(new Runnable() {
@Override
public void run() {
com.unity3d.services.ads.webplayer.WebPlayer webPlayer = getBannerWebPlayer();
if (webPlayer != null) {
webPlayer.setSettings(webSettings, webPlayerSettings);
} else {
BannerView.setWebPlayerSettings(webSettings, webPlayerSettings);
}
}
});
break;
case "webplayer":
_webSettings = webSettings;
_webPlayerSettings = webPlayerSettings;
break;
}
callback.invoke();
}
@WebViewExposed
public static void setEventSettings (final JSONObject settings, String viewId, final WebViewCallback callback) {
if (viewId.equals("webplayer")) {
_webPlayerEventSettings = settings;
} else {
runOnUiThread(new Runnable() {
@Override
public void run() {
com.unity3d.services.ads.webplayer.WebPlayer webPlayer = getBannerWebPlayer();
if (webPlayer != null) {
webPlayer.setEventSettings(settings);
} else {
BannerView.setWebPlayerEventSettings(settings);
}
}
});
}
callback.invoke();
}
@WebViewExposed
public static void clearSettings (final WebViewCallback callback) {
_webSettings = null;
_webPlayerSettings = null;
_webPlayerEventSettings = null;
callback.invoke();
}
@WebViewExposed
public static void getErroredSettings (String viewId, final WebViewCallback callback) {
com.unity3d.services.ads.webplayer.WebPlayer webPlayer = getWebPlayer(viewId);
if (webPlayer != null) {
Map<String, String> errors = webPlayer.getErroredSettings();
JSONObject retObj = new JSONObject();
try {
Iterator errorIterator = errors.entrySet().iterator();
while (errorIterator.hasNext()) {
Map.Entry pair = (Map.Entry)errorIterator.next();
retObj.put((String)pair.getKey(), pair.getValue());
}
} catch (Exception e) {
DeviceLog.exception("Error forming JSON object", e);
}
callback.invoke(retObj);
callback.invoke();
} else {
callback.error(WebPlayerError.WEBPLAYER_NULL);
}
}
@WebViewExposed
public static void sendEvent(final JSONArray parameters, String viewId, final WebViewCallback callback) {
com.unity3d.services.ads.webplayer.WebPlayer webPlayer = getWebPlayer(viewId);
if (webPlayer != null) {
webPlayer.sendEvent(parameters);
callback.invoke();
} else {
callback.error(WebPlayerError.WEBPLAYER_NULL);
}
}
private static com.unity3d.services.ads.webplayer.WebPlayer getWebPlayer(String viewId) {
switch (viewId) {
case "webplayer":
return getAdUnitWebPlayer();
case "bannerplayer":
return getBannerWebPlayer();
default:
return null;
}
}
private static com.unity3d.services.ads.webplayer.WebPlayer getAdUnitWebPlayer() {
if (AdUnit.getAdUnitActivity() != null) {
IAdUnitViewHandler viewHandler = AdUnit.getAdUnitActivity().getViewHandler("webplayer");
if (viewHandler != null) {
View view = viewHandler.getView();
if (view != null) {
return (com.unity3d.services.ads.webplayer.WebPlayer)view;
}
}
}
return null;
}
private static com.unity3d.services.ads.webplayer.WebPlayer getBannerWebPlayer() {
if (BannerView.getInstance() == null) {
return null;
}
return BannerView.getInstance().getWebPlayer();
}
}

Просмотреть файл

@ -1,28 +0,0 @@
package com.unity3d.services.banners;
import android.os.ConditionVariable;
import com.unity3d.services.ads.properties.AdsProperties;
import com.unity3d.services.core.webview.WebViewApp;
import com.unity3d.services.core.webview.bridge.CallbackStatus;
import java.lang.reflect.Method;
public class BannerHide {
private static ConditionVariable _waitHideStatus;
public static synchronized boolean hide() throws NoSuchMethodException {
Method showCallback = BannerHide.class.getMethod("showCallback", CallbackStatus.class);
_waitHideStatus = new ConditionVariable();
WebViewApp.getCurrentApp().invokeMethod("webview", "hideBanner", showCallback);
boolean success = _waitHideStatus.block(AdsProperties.getShowTimeout());
_waitHideStatus = null;
return success;
}
public static void showCallback(CallbackStatus status) {
if (_waitHideStatus != null && status.equals(CallbackStatus.OK)) {
_waitHideStatus.open();
}
}
}

Просмотреть файл

@ -1,28 +0,0 @@
package com.unity3d.services.banners;
import android.os.ConditionVariable;
import com.unity3d.services.ads.properties.AdsProperties;
import com.unity3d.services.core.webview.WebViewApp;
import com.unity3d.services.core.webview.bridge.CallbackStatus;
import java.lang.reflect.Method;
public class BannerShow {
private static ConditionVariable _waitShowStatus;
public static synchronized boolean show(String placementId) throws NoSuchMethodException {
Method showCallback = BannerShow.class.getMethod("showCallback", CallbackStatus.class);
_waitShowStatus = new ConditionVariable();
WebViewApp.getCurrentApp().invokeMethod("webview", "showBanner", showCallback, placementId);
boolean success = _waitShowStatus.block(AdsProperties.getShowTimeout());
_waitShowStatus = null;
return success;
}
public static void showCallback(CallbackStatus status) {
if (_waitShowStatus != null && status.equals(CallbackStatus.OK)) {
_waitShowStatus.open();
}
}
}

Просмотреть файл

@ -1,102 +0,0 @@
package com.unity3d.services.banners;
import android.app.Activity;
import com.unity3d.ads.UnityAds;
import com.unity3d.services.ads.placement.Placement;
import com.unity3d.services.banners.view.BannerPosition;
import com.unity3d.services.core.log.DeviceLog;
import com.unity3d.services.core.misc.Utilities;
import com.unity3d.services.core.properties.ClientProperties;
import com.unity3d.services.ads.properties.AdsProperties;
/**
* Created by andrewkonecny on 4/26/18.
*/
public final class UnityBanners {
public static void loadBanner(Activity activity) {
loadBanner(activity, Placement.getDefaultBannerPlacement());
}
public static void loadBanner(final Activity activity, final String placementId) {
DeviceLog.entered();
if (!UnityAds.isSupported()) {
sendError("Unity Ads is not supported on this device.");
}
if (!UnityAds.isInitialized()) {
sendError("UnityAds is not initialized.");
return;
}
if (!UnityAds.isReady(placementId)) {
sendError("Banner placement " + placementId + " is not ready");
return;
}
new Thread(new Runnable() {
@Override
public void run() {
try {
ClientProperties.setActivity(activity);
if (!BannerShow.show(placementId)) {
sendError("Could not show banner in time");
}
} catch (Exception e) {
sendError(e.getMessage());
}
}
}).start();
}
public static void destroy() {
new Thread(new Runnable() {
@Override
public void run() {
try {
if (!BannerHide.hide()) {
sendError(("Could not hide banner in time"));
}
} catch (Exception e) {
sendError(e.getMessage());
}
}
}).start();
}
public static void setBannerPosition(BannerPosition position) {
ClientProperties.setBannerDefaultPosition(position);
}
/**
* Change listener for IUnityAdsListener callbacks
*
* @param listener New listener for IUnityAdsListener callbacks
*/
public static void setBannerListener(IUnityBannerListener listener) {
AdsProperties.setBannerListener(listener);
}
/**
* Get current listener for IUnityAdsListener callbacks
*
* @return Current listener for IUnityAdsListener callbacks
*/
public static IUnityBannerListener getBannerListener() {
return AdsProperties.getBannerListener();
}
private static void sendError(final String message) {
Utilities.runOnUiThread(new Runnable() {
@Override
public void run() {
IUnityBannerListener listener = getBannerListener();
if (listener != null) {
listener.onUnityBannerError(message);
}
}
});
}
}

Просмотреть файл

@ -1,136 +0,0 @@
package com.unity3d.services.banners.api;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.RelativeLayout;
import com.unity3d.services.banners.view.BannerEvent;
import com.unity3d.services.banners.view.BannerPosition;
import com.unity3d.services.banners.properties.BannerProperties;
import com.unity3d.services.banners.view.BannerView;
import com.unity3d.services.core.log.DeviceLog;
import com.unity3d.services.core.misc.Utilities;
import com.unity3d.services.core.properties.ClientProperties;
import com.unity3d.services.core.webview.WebViewApp;
import com.unity3d.services.core.webview.WebViewEventCategory;
import com.unity3d.services.core.webview.bridge.WebViewCallback;
import com.unity3d.services.core.webview.bridge.WebViewExposed;
import org.json.JSONArray;
import org.json.JSONException;
import java.util.Arrays;
import java.util.List;
public class Banner {
@WebViewExposed
public static void load(final JSONArray viewsArray, final String style, final Integer width, final Integer height, final WebViewCallback callback) {
Utilities.runOnUiThread(new Runnable() {
@Override
public synchronized void run() {
BannerView view = BannerView.getOrCreateInstance();
BannerPosition position = ClientProperties.getbannerDefaultPosition();
if (position == null) {
position = BannerPosition.fromString(style);
}
view.setBannerDimensions(width, height, position);
view.setViews(getArrayFromJSONArray(viewsArray));
WebViewApp app = WebViewApp.getCurrentApp();
if (app != null) {
app.sendEvent(WebViewEventCategory.BANNER, BannerEvent.BANNER_LOADED);
}
}
});
callback.invoke();
}
@WebViewExposed
public static void destroy(WebViewCallback callback) {
Utilities.runOnUiThread(new Runnable() {
@Override
public synchronized void run() {
BannerView view = BannerView.getInstance();
if (view != null) {
view.destroy();
if (BannerProperties.getBannerParent() != null) {
ViewParent parent = BannerProperties.getBannerParent().getParent();
if (parent != null && parent instanceof ViewGroup) {
((ViewGroup) parent).removeView(BannerProperties.getBannerParent());
}
}
BannerProperties.setBannerParent(null);
WebViewApp app = WebViewApp.getCurrentApp();
if (app != null) {
app.sendEvent(WebViewEventCategory.BANNER, BannerEvent.BANNER_DESTROYED);
}
}
}
});
callback.invoke();
}
@WebViewExposed
public static void setViewFrame(final String viewName, final Integer x, final Integer y, final Integer width, final Integer height, WebViewCallback callback) {
Utilities.runOnUiThread(new Runnable() {
@Override
public void run() {
BannerView view = BannerView.getInstance();
if (view != null) {
view.setViewFrame(viewName, x, y, width, height);
}
}
});
callback.invoke();
}
@WebViewExposed
public static void setViews(final JSONArray views, WebViewCallback callback) {
Utilities.runOnUiThread(new Runnable() {
@Override
public void run() {
BannerView view = BannerView.getInstance();
if (view != null) {
view.setViews(getArrayFromJSONArray(views));
}
}
});
callback.invoke();
}
@WebViewExposed
public static void setBannerFrame(final String style, final Integer width, final Integer height, WebViewCallback callback) {
Utilities.runOnUiThread(new Runnable() {
@Override
public void run() {
BannerView view = BannerView.getInstance();
if (view != null) {
BannerPosition position = ClientProperties.getbannerDefaultPosition();
if ( position == null) {
position = BannerPosition.fromString(style);
}
view.setBannerDimensions(width, height, position);
view.setLayoutParams(view.getLayoutParams());
}
}
});
callback.invoke();
}
private static List<String> getArrayFromJSONArray(JSONArray arr) {
String[] out = new String[arr.length()];
for (int i = 0; i < out.length; i++) {
try {
out[i] = arr.getString(i);
} catch (JSONException e) {
DeviceLog.warning("Exception converting JSON Array to String Array: %s", e);
}
}
return Arrays.asList(out);
}
}

Просмотреть файл

@ -1,95 +0,0 @@
package com.unity3d.services.banners.api;
import com.unity3d.services.banners.UnityBanners;
import com.unity3d.services.banners.properties.BannerProperties;
import com.unity3d.services.banners.view.BannerView;
import com.unity3d.services.core.misc.Utilities;
import com.unity3d.services.core.webview.bridge.WebViewCallback;
import com.unity3d.services.core.webview.bridge.WebViewExposed;
public class BannerListener {
@WebViewExposed
public static void sendShowEvent(final String placementId, WebViewCallback callback) {
Utilities.runOnUiThread(new Runnable() {
@Override
public void run() {
if (UnityBanners.getBannerListener() != null) {
UnityBanners.getBannerListener().onUnityBannerShow(placementId);
}
}
});
callback.invoke();
}
@WebViewExposed
public static void sendClickEvent(final String placementId, WebViewCallback callback) {
Utilities.runOnUiThread(new Runnable() {
@Override
public void run() {
if (UnityBanners.getBannerListener() != null) {
UnityBanners.getBannerListener().onUnityBannerClick(placementId);
}
}
});
callback.invoke();
}
@WebViewExposed
public static void sendHideEvent(final String placementId, WebViewCallback callback) {
Utilities.runOnUiThread(new Runnable() {
@Override
public void run() {
if (UnityBanners.getBannerListener() != null) {
UnityBanners.getBannerListener().onUnityBannerHide(placementId);
}
}
});
callback.invoke();
}
@WebViewExposed
public static void sendErrorEvent(final String message, WebViewCallback callback) {
Utilities.runOnUiThread(new Runnable() {
@Override
public void run() {
if (UnityBanners.getBannerListener() != null) {
UnityBanners.getBannerListener().onUnityBannerError(message);
}
}
});
callback.invoke();
}
@WebViewExposed
public static void sendLoadEvent(final String placementId, WebViewCallback callback) {
Utilities.runOnUiThread(new Runnable() {
@Override
public void run() {
if (UnityBanners.getBannerListener() != null) {
UnityBanners.getBannerListener().onUnityBannerLoaded(placementId, BannerView.getInstance());
}
}
});
callback.invoke();
}
@WebViewExposed
public static void sendUnloadEvent(final String placementId, WebViewCallback callback) {
Utilities.runOnUiThread(new Runnable() {
@Override
public void run() {
if (UnityBanners.getBannerListener() != null) {
UnityBanners.getBannerListener().onUnityBannerUnloaded(placementId);
}
}
});
callback.invoke();
}
}

Просмотреть файл

@ -1,15 +0,0 @@
package com.unity3d.services.banners.properties;
import android.view.View;
public class BannerProperties {
private static View bannerParent;
public static View getBannerParent() {
return bannerParent;
}
public static void setBannerParent(View bannerParent) {
BannerProperties.bannerParent = bannerParent;
}
}

Просмотреть файл

@ -1,10 +0,0 @@
package com.unity3d.services.banners.view;
public enum BannerEvent {
BANNER_VISIBILITY_CHANGED,
BANNER_RESIZED,
BANNER_LOADED,
BANNER_DESTROYED,
BANNER_ATTACHED,
BANNER_DETACHED
}

Просмотреть файл

@ -1,250 +0,0 @@
package com.unity3d.services.banners.view;
import android.content.Context;
import android.graphics.Rect;
import android.os.Build;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.RelativeLayout;
import com.unity3d.services.core.log.DeviceLog;
import com.unity3d.services.core.misc.ViewUtilities;
import com.unity3d.services.core.properties.ClientProperties;
import com.unity3d.services.ads.webplayer.WebPlayer;
import com.unity3d.services.core.webview.WebViewApp;
import com.unity3d.services.core.webview.WebViewEventCategory;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
public class BannerView extends RelativeLayout {
private static final String VIEW_BANNER_PLAYER = "bannerplayer";
private static final String VIEW_WEB_VIEW = "webview";
private static final String VIEW_BANNER = "banner";
private static JSONObject _webSettings = new JSONObject();
private static JSONObject _webPlayerSettings = new JSONObject();
private static JSONObject _webPlayerEventSettings = new JSONObject();
private static BannerView _instance;
private List<String> _views;
private WebPlayer _webPlayer;
private int _lastVisibility = -1;
private int width;
private int height;
private BannerPosition position;
public BannerView(Context context) {
super(context);
_webPlayer = new WebPlayer(context, VIEW_BANNER_PLAYER, _webSettings, _webPlayerSettings);
_webPlayer.setEventSettings(_webPlayerEventSettings);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
addOnLayoutChangeListener(new OnLayoutChangeListener() {
@Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
BannerView.this.onLayoutChange(v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom);
}
});
}
}
public static void setWebPlayerEventSettings(JSONObject webPlayerEventSettings) {
_webPlayerEventSettings = webPlayerEventSettings;
}
public static void setWebPlayerSettings(JSONObject webSettings, JSONObject webPlayerSettings) {
_webSettings = webSettings;
_webPlayerSettings = webPlayerSettings;
}
public void destroy() {
removeAllViews();
ViewParent parent = getParent();
if (parent != null && parent instanceof ViewGroup) {
((ViewGroup) parent).removeView(this);
}
if (this._webPlayer != null) {
this._webPlayer.destroy();
}
this._webPlayer = null;
BannerView._instance = null;
}
public static BannerView getOrCreateInstance() {
if (_instance == null) {
_instance = new BannerView(ClientProperties.getApplicationContext());
}
return _instance;
}
public static BannerView getInstance() {
return _instance;
}
public void setViews(List<String> views) {
List<String> viewsToAdd = new ArrayList<>(views);
List<String> viewsToRemove = new ArrayList<>();
if (this._views != null) {
viewsToRemove.addAll(this._views);
viewsToRemove.removeAll(views);
viewsToAdd.removeAll(this._views);
}
this._views = views;
for (String view : viewsToRemove) {
this.removeView(view);
}
for (String view : viewsToAdd) {
this.addView(view);
}
}
private void removeView(String viewName) {
View view = getViewForName(viewName);
if (view != null) {
ViewUtilities.removeViewFromParent(view);
}
switch (viewName) {
case VIEW_BANNER_PLAYER:
this._webPlayer = null;
break;
}
}
private void addView(String viewName) {
View view = getViewForName(viewName);
if (view != null) {
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
addView(view, params);
} else {
DeviceLog.warning("No view defined for viewName: %s", viewName);
}
}
public WebPlayer getWebPlayer() {
return _webPlayer;
}
@Override
public void setLayoutParams(ViewGroup.LayoutParams params) {
if (params != null) {
params.width = this.width;
params.height = this.height;
super.setLayoutParams(LayoutParamsHelper.updateLayoutParamsForPosition(params, position));
}
}
public void setViewFrame(String viewName, Integer x, Integer y, Integer width, Integer height) {
View view = getViewForName(viewName);
if (view == null) {
return;
}
if (view == this) {
DeviceLog.warning("Not setting viewFrame for banner, use `setLayoutParams` instead.");
} else {
RelativeLayout.LayoutParams params = new LayoutParams(width, height);
params.setMargins(x, y, 0, 0);
view.setLayoutParams(params);
}
}
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
WebViewApp app = WebViewApp.getCurrentApp();
if (app != null) {
app.sendEvent(WebViewEventCategory.BANNER, BannerEvent.BANNER_ATTACHED);
}
}
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
WebViewApp app = WebViewApp.getCurrentApp();
if (app != null) {
app.sendEvent(WebViewEventCategory.BANNER, BannerEvent.BANNER_DETACHED );
}
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
// Old values are both zero if just added to hierarchy
if (!(oldw == 0 && oldh == 0)) {
int left = getLeft();
int right = getRight();
float alpha = 1.0f;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
alpha = getAlpha();
}
WebViewApp.getCurrentApp().sendEvent(WebViewEventCategory.BANNER, BannerEvent.BANNER_RESIZED, left, right, w, h, alpha);
// Given our current rect, check that we are still able to be seen in the parent.
Rect rect = new Rect();
getHitRect(rect);
if (((View) getParent()).getLocalVisibleRect(rect)) {
onVisibilityChanged(this, View.GONE);
}
}
}
@Override
protected void onVisibilityChanged(View changedView, int visibility) {
if (changedView == this) {
if (_lastVisibility == -1) {
_lastVisibility = visibility;
} else {
if (visibility != View.VISIBLE && _lastVisibility == View.VISIBLE) {
WebViewApp.getCurrentApp().sendEvent(WebViewEventCategory.BANNER, BannerEvent.BANNER_VISIBILITY_CHANGED, visibility);
}
_lastVisibility = visibility;
}
}
}
private View getViewForName(String name) {
if (name.equals(VIEW_BANNER_PLAYER)) {
return _webPlayer;
} else if (name.equals(VIEW_WEB_VIEW)) {
return WebViewApp.getCurrentApp().getWebView();
} else if (name.equals(VIEW_BANNER)) {
return this;
}
return null;
}
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
float alpha = 1.0f;
if (Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
alpha = getAlpha();
}
WebViewApp.getCurrentApp().sendEvent(WebViewEventCategory.BANNER, BannerEvent.BANNER_RESIZED, left, top, right, bottom, alpha);
if (getParent() != null) {
// Given our current rect, check that we are still able to be seen in the parent.
Rect rect = new Rect();
getHitRect(rect);
if (getParent() instanceof View) {
if (!((View) getParent()).getLocalVisibleRect(rect)) {
onVisibilityChanged(this, View.GONE);
}
}
}
}
@Override
public void setAlpha(float alpha) {
super.setAlpha(alpha);
// Re-trigger layout change for sending alpha value.
onLayoutChange(this, getLeft(), getTop(), getRight(), getBottom(), getLeft(), getTop(), getRight(), getBottom());
}
public void setBannerDimensions(int width, int height, BannerPosition position) {
this.width = width;
this.height = height;
this.position = position;
}
}

Просмотреть файл

@ -1,26 +0,0 @@
package com.unity3d.services.banners.view;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;
class LayoutParamsHelper {
static ViewGroup.LayoutParams updateLayoutParamsForPosition(ViewGroup.LayoutParams params, BannerPosition position) {
if (params instanceof FrameLayout.LayoutParams) {
return updateFrameLayoutParamsForPosition((FrameLayout.LayoutParams)params, position);
} else if (params instanceof RelativeLayout.LayoutParams) {
return updateRelativeLayoutParamsForPosition((RelativeLayout.LayoutParams)params, position);
} else {
return params;
}
}
private static ViewGroup.LayoutParams updateRelativeLayoutParamsForPosition(RelativeLayout.LayoutParams params, BannerPosition position) {
return position.addLayoutRules(params);
}
private static ViewGroup.LayoutParams updateFrameLayoutParamsForPosition(FrameLayout.LayoutParams params, BannerPosition position) {
params.gravity = position.getGravity();
return params;
}
}

0
scripts/extra.groovy Executable file → Normal file
Просмотреть файл

Просмотреть файл

@ -0,0 +1,29 @@
set -o xtrace
echo "no" | ${ANDROID_HOME}/tools/bin/avdmanager create avd --name "android-26-test" --package "system-images;android-26;google_apis;x86" --device "Nexus 6P" --tag google_apis --abi google_apis/x86 --force
${ANDROID_HOME}/emulator/emulator -port 5556 -avd android-26-test -no-window -noaudio -no-boot-anim -memory 2048 -partition-size 1024 2>&1 &
echo $! > emulator_PID
# Wait for Android to finish booting
BOOTCOMPLETE_WAIT_CMD="$ANDROID_HOME/platform-tools/adb wait-for-device shell getprop dev.bootcomplete"
BOOT_COMPLETED_WAIT_CMD="$ANDROID_HOME/platform-tools/adb wait-for-device shell getprop sys.boot_completed"
BOOT_ANIM_WAIT_CMD="$ANDROID_HOME/platform-tools/adb wait-for-device shell getprop init.svc.bootanim"
until [[ $( $BOOTCOMPLETE_WAIT_CMD | grep -m 1 1 ) && $( $BOOT_COMPLETED_WAIT_CMD | grep -m 1 1 ) && $( $BOOT_ANIM_WAIT_CMD | grep -m 1 stopped ) ]]; do
echo "Waiting for emulator..."
sleep 1
done
# Unlock the Lock Screen
$ANDROID_HOME/platform-tools/adb shell input keyevent 82
# Run instrumentation test
bundle exec fastlane instrumentation_test
TEST_EXIT=$?
# Stop the background processes
kill $(head -n 1 emulator_PID)
rm -rf emulator_PID
exit $TEST_EXIT

Просмотреть файл

@ -0,0 +1,29 @@
set -o xtrace
echo "no" | ${ANDROID_HOME}/tools/bin/avdmanager create avd --name "android-26-test" --package "system-images;android-26;google_apis;x86" --device "Nexus 6P" --tag google_apis --abi google_apis/x86 --force
${ANDROID_HOME}/emulator/emulator -port 5556 -avd android-26-test -no-window -noaudio -no-boot-anim -memory 2048 -partition-size 1024 2>&1 &
echo $! > emulator_PID
# Wait for Android to finish booting
BOOTCOMPLETE_WAIT_CMD="$ANDROID_HOME/platform-tools/adb wait-for-device shell getprop dev.bootcomplete"
BOOT_COMPLETED_WAIT_CMD="$ANDROID_HOME/platform-tools/adb wait-for-device shell getprop sys.boot_completed"
BOOT_ANIM_WAIT_CMD="$ANDROID_HOME/platform-tools/adb wait-for-device shell getprop init.svc.bootanim"
until [[ $( $BOOTCOMPLETE_WAIT_CMD | grep -m 1 1 ) && $( $BOOT_COMPLETED_WAIT_CMD | grep -m 1 1 ) && $( $BOOT_ANIM_WAIT_CMD | grep -m 1 stopped ) ]]; do
echo "Waiting for emulator..."
sleep 1
done
# Unlock the Lock Screen
$ANDROID_HOME/platform-tools/adb shell input keyevent 82
# Run integration test
bundle exec fastlane integration_test
TEST_EXIT=$?
# Stop the background processes
kill $(head -n 1 emulator_PID)
rm -rf emulator_PID
exit $TEST_EXIT

30
scripts/gitlab/legacy_test.sh Executable file
Просмотреть файл

@ -0,0 +1,30 @@
#!/usr/bin/env bash
set -m
echo "no" | ${ANDROID_HOME}/tools/bin/avdmanager create avd --name "android-26-test" --package "system-images;android-26;google_apis;x86" --device "Nexus 6P" --tag google_apis --abi google_apis/x86 --force
${ANDROID_HOME}/emulator/emulator -port 5556 -avd android-26-test -no-window -noaudio -no-boot-anim -memory 2048 -partition-size 1024 2>&1 &
echo $! > emulator_PID
# Wait for Android to finish booting
BOOTCOMPLETE_WAIT_CMD="$ANDROID_HOME/platform-tools/adb wait-for-device shell getprop dev.bootcomplete"
BOOT_COMPLETED_WAIT_CMD="$ANDROID_HOME/platform-tools/adb wait-for-device shell getprop sys.boot_completed"
BOOT_ANIM_WAIT_CMD="$ANDROID_HOME/platform-tools/adb wait-for-device shell getprop init.svc.bootanim"
until [[ $( $BOOTCOMPLETE_WAIT_CMD | grep -m 1 1 ) && $( $BOOT_COMPLETED_WAIT_CMD | grep -m 1 1 ) && $( $BOOT_ANIM_WAIT_CMD | grep -m 1 stopped ) ]]; do
echo "Waiting for emulator..."
sleep 1
done
# Unlock the Lock Screen
$ANDROID_HOME/platform-tools/adb shell input keyevent 82
# Run instrumentation test
bundle exec fastlane legacy_test
TEST_EXIT=$?
# Stop the background processes
kill $(head -n 1 emulator_PID)
rm -rf emulator_PID
exit $TEST_EXIT

Просмотреть файл

@ -0,0 +1,37 @@
set -o xtrace
CURRENT_COMMIT_ID=${CI_COMMIT_SHA};
echo "CURRENT_COMMIT_ID=$CURRENT_COMMIT_ID";
echo "CI_COMMIT_REF_NAME=$CI_COMMIT_REF_NAME";
[[ $CI_COMMIT_REF_NAME =~ ^release\/([0-9\.]*)$ ]];
RELEASE_VERSION=${BASH_REMATCH[1]};
if [[ ! $RELEASE_VERSION ]]; then
[[ $CI_COMMIT_REF_NAME =~ ^feature\/ci$ ]];
RELEASE_VERSION=${BASH_REMATCH[0]};
fi
echo "RELEASE_VERSION=$RELEASE_VERSION";
make verify-release-build;
if [[ $CURRENT_COMMIT_ID && $RELEASE_VERSION && $GITHUB_PERSONAL_ACCESS_TOKEN ]]; then
CREATE_RELEASE_RESPONSE=$(curl -X POST --fail \
-H "Authorization: token $GITHUB_PERSONAL_ACCESS_TOKEN" \
-d "{ \"tag_name\": \"${RELEASE_VERSION}\", \"target_commitish\": \"${CURRENT_COMMIT_ID}\", \"name\": \"Unity Ads ${RELEASE_VERSION}\", \"body\": \"Unity Ads ${RELEASE_VERSION}\", \"draft\": true }" \
"https://api.github.com/repos/Applifier/unity-ads-android/releases");
UPLOAD_URL=$(echo "$CREATE_RELEASE_RESPONSE" | jq -r '.upload_url' | cut -f1 -d"{")
if [[ UPLOAD_URL && UPLOAD_URL != null ]]; then
echo "UPLOAD_URL=$UPLOAD_URL";
curl -X POST --fail \
-H "Authorization: token $GITHUB_PERSONAL_ACCESS_TOKEN" \
-H "Content-Type: application/zip" \
--data-binary @unity-ads.aar.zip \
"$UPLOAD_URL?name=unity-ads.aar.zip&label=unity-ads.aar.zip";
else
echo "UPLOAD_URL not found";
exit 1;
fi
else
echo "CURRENT_COMMIT_ID or RELEASE_VERSION or GITHUB_PERSONAL_ACCESS_TOKEN not found";
exit 1;
fi

Просмотреть файл

@ -0,0 +1,38 @@
set -o xtrace
CURRENT_COMMIT_ID=${CI_COMMIT_SHA};
echo "CURRENT_COMMIT_ID=$CURRENT_COMMIT_ID";
# TODO get correct REF from public repo
echo "CI_COMMIT_REF_NAME=$CI_COMMIT_REF_NAME";
[[ $CI_COMMIT_REF_NAME =~ ^release\/([0-9\.]*)$ ]];
RELEASE_VERSION=${BASH_REMATCH[1]};
if [[ ! $RELEASE_VERSION ]]; then
[[ $CI_COMMIT_REF_NAME =~ ^feature\/ci$ ]];
RELEASE_VERSION=${BASH_REMATCH[0]};
fi
echo "RELEASE_VERSION=$RELEASE_VERSION";
make verify-release-build;
if [[ $CURRENT_COMMIT_ID && $RELEASE_VERSION && $GITHUB_PERSONAL_ACCESS_TOKEN ]]; then
CREATE_RELEASE_RESPONSE=$(curl -X POST --fail \
-H "Authorization: token $GITHUB_PERSONAL_ACCESS_TOKEN" \
-d "{ \"tag_name\": \"${RELEASE_VERSION}\", \"target_commitish\": \"${CURRENT_COMMIT_ID}\", \"name\": \"Unity Ads ${RELEASE_VERSION}\", \"body\": \"Unity Ads ${RELEASE_VERSION}\", \"draft\": true }" \
"https://api.github.com/repos/Unity-Technologies/unity-ads-android/releases");
UPLOAD_URL=$(echo "$CREATE_RELEASE_RESPONSE" | jq -r '.upload_url' | cut -f1 -d"{")
if [[ UPLOAD_URL && UPLOAD_URL != null ]]; then
echo "UPLOAD_URL=$UPLOAD_URL";
curl -X POST --fail \
-H "Authorization: token $GITHUB_PERSONAL_ACCESS_TOKEN" \
-H "Content-Type: application/zip" \
--data-binary @unity-ads.aar.zip \
"$UPLOAD_URL?name=unity-ads.aar.zip&label=unity-ads.aar.zip";
else
echo "UPLOAD_URL not found";
exit 1;
fi
else
echo "CURRENT_COMMIT_ID or RELEASE_VERSION or GITHUB_PERSONAL_ACCESS_TOKEN not found";
exit 1;
fi

29
scripts/gitlab/setup.sh Executable file
Просмотреть файл

@ -0,0 +1,29 @@
set -o xtrace
brew update
brew install rbenv
if ! grep -q 'export PATH="$HOME/.rbenv/bin:$PATH"' ~/.bash_profile; then
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
fi
if ! grep -q 'eval "$(rbenv init -)"' ~/.bash_profile; then
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
fi
RUBY_VERSION=$(cat .ruby-version)
source ~/.bash_profile
echo < cat .ruby-version
echo n | rbenv install $RUBY_VERSION
rbenv shell $RUBY_VERSION
gem install bundler
bundle install
echo y | $ANDROID_HOME/tools/bin/sdkmanager --update
echo y | $ANDROID_HOME/tools/bin/sdkmanager "platforms;android-26" \
"build-tools;28.0.2" \
"extras;google;m2repository" \
"extras;android;m2repository" \
"extras;google;google_play_services" \
"sources;android-26" \
"platform-tools" \
"emulator" \
"tools" \
"system-images;android-26;google_apis;x86"

2
settings.gradle Executable file → Normal file
Просмотреть файл

@ -1 +1 @@
include ':app', ':lib'
include ':app', ':unity-ads'

Просмотреть файл

@ -1,19 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id="unity-ads-android" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="java-gradle" name="Java-Gradle">
<configuration>
<option name="BUILD_FOLDER_PATH" value="$MODULE_DIR$/build" />
<option name="BUILDABLE" value="false" />
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

0
lib/.gitignore → unity-ads/.gitignore поставляемый Executable file → Normal file
Просмотреть файл

6
lib/build.gradle → unity-ads/build.gradle Executable file → Normal file
Просмотреть файл

@ -16,7 +16,7 @@ ext {
siteUrl = 'https://github.com/Unity-Technologies/unity-ads-android'
gitUrl = 'https://github.com/Unity-Technologies/unity-ads-android.git'
libraryVersion = '3.0.3'
libraryVersion = '3.3.0'
developerId = 'sbankhead'
developerName = 'Steven Bankhead'
@ -50,8 +50,8 @@ android {
All SDK with version numbers with last two digits >= 50 will be treated
as China SDK for filtering in the backend.
*/
versionCode = 3200
versionName = "3.2.0"
versionCode = 3300
versionName = "3.3.0"
setProperty("archivesBaseName", "unity-ads")

Просмотреть файл

0
lib/proguard-rules.pro → unity-ads/proguard-rules.pro поставляемый Executable file → Normal file
Просмотреть файл

Просмотреть файл

@ -15,13 +15,23 @@
android:hardwareAccelerated="true" />
<activity
android:name="com.unity3d.ads.test.unit.LifecycleListenerTestActivity"
android:name="com.unity3d.ads.test.legacy.LifecycleListenerTestActivity"
android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:hardwareAccelerated="true" />
<activity
android:name="com.unity3d.ads.test.unit.LifecycleListenerTestBaseActivity"
android:name="com.unity3d.ads.test.legacy.LifecycleListenerTestBaseActivity"
android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:hardwareAccelerated="true" />
<activity
android:name="com.unity3d.ads.test.legacy.TestActivity"
android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:hardwareAccelerated="true" />
<activity
android:name="com.unity3d.ads.test.instrumentation.InstrumentationTestActivity"
android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:hardwareAccelerated="true" />

Просмотреть файл

@ -1,7 +1,7 @@
package com.unity3d.services.ads.properties;
package com.unity3d.ads.properties;
import com.unity3d.ads.IUnityAdsListener;
import com.unity3d.services.ads.mocks.UnityAdsListenerMock;
import com.unity3d.ads.test.instrumentation.services.ads.mocks.UnityAdsListenerMock;
import org.junit.Before;
import org.junit.Test;
@ -11,6 +11,7 @@ import java.util.Set;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
public class AdsPropertiesTests {
@ -55,4 +56,21 @@ public class AdsPropertiesTests {
assertFalse(listeners.contains(listener));
}
@Test
public void testRemoveDuringIteration() {
UnityAdsListenerMock listener1 = new UnityAdsListenerMock();
AdsProperties.addListener(listener1);
UnityAdsListenerMock listener2 = new UnityAdsListenerMock();
AdsProperties.addListener(listener2);
Set<IUnityAdsListener> listeners = AdsProperties.getListeners();
try {
for (IUnityAdsListener listener : listeners) {
AdsProperties.removeListener(listener);
}
assertTrue(true);
} catch (Exception e) {
fail("An exception should not be thrown");
}
}
}

Просмотреть файл

@ -0,0 +1,28 @@
package com.unity3d.ads.test;
import com.unity3d.ads.test.instrumentation.services.ads.load.LoadModuleTest;
import com.unity3d.ads.test.instrumentation.services.ads.webplayer.WebPlayerViewCacheTest;
import com.unity3d.ads.test.instrumentation.services.ads.webplayer.WebPlayerViewSettingsCacheTest;
import com.unity3d.ads.test.instrumentation.services.banners.BannerViewCacheTests;
import com.unity3d.ads.test.instrumentation.services.core.configuration.InitializationNotificationCenterTest;
import com.unity3d.ads.properties.AdsPropertiesTests;
import com.unity3d.services.analytics.AcquisitionTypeTest;
import com.unity3d.services.analytics.UnityAnalyticsTest;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
@RunWith(Suite.class)
@Suite.SuiteClasses({
UnityAnalyticsTest.class,
AcquisitionTypeTest.class,
AdsPropertiesTests.class,
InitializationNotificationCenterTest.class,
LoadModuleTest.class,
// LoadBridgeTest.class,
WebPlayerViewSettingsCacheTest.class,
WebPlayerViewCacheTest.class,
BannerViewCacheTests.class
})
public class InstrumentationTestSuite {}

Просмотреть файл

@ -0,0 +1,13 @@
package com.unity3d.ads.test;
import com.unity3d.ads.test.integration.banner.BannerIntegrationTest;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
@RunWith(Suite.class)
@Suite.SuiteClasses({
BannerIntegrationTest.class
})
public class IntegrationTestSuite {
}

Просмотреть файл

@ -0,0 +1,76 @@
package com.unity3d.ads.test;
import com.unity3d.ads.test.legacy.AdUnitActivityTest;
import com.unity3d.ads.test.legacy.AdvertisingIdentifierTest;
import com.unity3d.ads.test.legacy.BroadcastTest;
import com.unity3d.ads.test.legacy.CacheTest;
import com.unity3d.ads.test.legacy.ClientPropertiesTest;
import com.unity3d.ads.test.legacy.ConnectivityTest;
import com.unity3d.ads.test.legacy.DeviceTest;
import com.unity3d.ads.test.legacy.EnvironmentCheckTest;
import com.unity3d.ads.test.legacy.EventIdTest;
import com.unity3d.ads.test.legacy.InitializeThreadTest;
import com.unity3d.ads.test.legacy.InvocationTest;
import com.unity3d.ads.test.legacy.LifecycleListenerTest;
import com.unity3d.ads.test.legacy.MetaDataTest;
import com.unity3d.ads.test.legacy.NativeCallbackTest;
import com.unity3d.ads.test.legacy.PackageManagerTest;
import com.unity3d.ads.test.legacy.PlacementTest;
import com.unity3d.ads.test.legacy.PreferencesTest;
import com.unity3d.ads.test.legacy.PublicApiTest;
import com.unity3d.ads.test.legacy.RequestTest;
import com.unity3d.ads.test.legacy.SdkPropertiesTest;
import com.unity3d.ads.test.legacy.StorageDiskTest;
import com.unity3d.ads.test.legacy.StorageGeneralTest;
import com.unity3d.ads.test.legacy.StorageMemoryTest;
import com.unity3d.ads.test.legacy.UtilitiesTest;
import com.unity3d.ads.test.legacy.VideoViewTest;
import com.unity3d.ads.test.legacy.VolumeChangeTest;
import com.unity3d.ads.test.legacy.WebPlayerViewTest;
import com.unity3d.ads.test.legacy.WebRequestThreadPoolTest;
import com.unity3d.ads.test.legacy.WebViewAppTest;
import com.unity3d.ads.test.legacy.WebViewBridgeInterfaceTest;
import com.unity3d.ads.test.legacy.WebViewBridgeTest;
import com.unity3d.ads.test.legacy.WebViewCallbackTest;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
@RunWith(Suite.class)
@Suite.SuiteClasses({
AdUnitActivityTest.class,
AdvertisingIdentifierTest.class,
BroadcastTest.class,
CacheTest.class,
ClientPropertiesTest.class,
ConnectivityTest.class,
DeviceTest.class,
EventIdTest.class,
EnvironmentCheckTest.class,
EventIdTest.class,
InitializeThreadTest.class,
InvocationTest.class,
MetaDataTest.class,
NativeCallbackTest.class,
PackageManagerTest.class,
PlacementTest.class,
PublicApiTest.class,
RequestTest.class,
SdkPropertiesTest.class,
StorageDiskTest.class,
StorageGeneralTest.class,
StorageMemoryTest.class,
VideoViewTest.class,
WebViewAppTest.class,
WebViewBridgeInterfaceTest.class,
WebViewBridgeTest.class,
WebViewCallbackTest.class,
LifecycleListenerTest.class,
VolumeChangeTest.class,
UtilitiesTest.class,
WebPlayerViewTest.class,
PreferencesTest.class,
WebRequestThreadPoolTest.class
})
public class LegacyTestSuite {}

Просмотреть файл

@ -12,7 +12,7 @@ import java.util.Arrays;
public class TestUtilities {
private static String testServerAddress = "http://10.0.2.2:8080";
private static String testServerAddress = "http://unity-ads-test-server.unityads.unity3d.com";
private static String convertStreamToString(InputStream is) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(is));

Просмотреть файл

@ -0,0 +1,12 @@
package com.unity3d.ads.test.instrumentation;
import android.app.Activity;
import android.os.Bundle;
public class InstrumentationTestActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
}

Просмотреть файл

@ -1,4 +1,4 @@
package com.unity3d.ads.test.unit.services.ads.load;
package com.unity3d.ads.test.instrumentation.services.ads.load;
import com.unity3d.services.ads.load.ILoadBridge;

Просмотреть файл

@ -1,4 +1,6 @@
package com.unity3d.ads.test.unit.services.ads.load;
package com.unity3d.ads.test.instrumentation.services.ads.load;
import android.support.test.runner.AndroidJUnit4;
import com.unity3d.services.ads.load.LoadBridge;
import com.unity3d.services.core.webview.WebViewApp;
@ -8,6 +10,7 @@ import org.json.JSONObject;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import java.util.LinkedHashMap;
@ -19,12 +22,14 @@ import static org.mockito.Mockito.verify;
import static org.junit.Assert.assertEquals;
@RunWith(AndroidJUnit4.class)
public class LoadBridgeTest {
private WebViewApp webViewApp;
private LoadBridge loadBridge;
@Before
public void before() {
// TODO mock webview correctly
webViewApp = mock(WebViewApp.class);
WebViewApp.setCurrentApp(webViewApp);

Просмотреть файл

@ -1,4 +1,6 @@
package com.unity3d.ads.test.unit.services.ads.load;
package com.unity3d.ads.test.instrumentation.services.ads.load;
import android.support.test.runner.AndroidJUnit4;
import com.unity3d.services.ads.load.ILoadBridge;
import com.unity3d.services.ads.load.LoadModule;
@ -9,6 +11,7 @@ import com.unity3d.services.core.properties.SdkProperties;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
@ -22,6 +25,7 @@ import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@RunWith(AndroidJUnit4.class)
public class LoadModuleTest {
private ILoadBridge loadBridge;

Просмотреть файл

@ -1,4 +1,4 @@
package com.unity3d.services.ads.mocks;
package com.unity3d.ads.test.instrumentation.services.ads.mocks;
import com.unity3d.ads.IUnityAdsListener;
import com.unity3d.ads.UnityAds;

Просмотреть файл

@ -0,0 +1,63 @@
package com.unity3d.ads.test.instrumentation.services.ads.webplayer;
import android.app.Activity;
import android.support.test.annotation.UiThreadTest;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import com.unity3d.ads.test.legacy.TestActivity;
import com.unity3d.services.ads.webplayer.WebPlayerView;
import com.unity3d.services.ads.webplayer.WebPlayerViewCache;
import org.json.JSONObject;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
@RunWith(AndroidJUnit4.class)
public class WebPlayerViewCacheTest {
@Rule
public ActivityTestRule<TestActivity> activityTestRule = new ActivityTestRule<>(TestActivity.class);
private WebPlayerViewCache webPlayerViewCache;
@Before
public void before() {
webPlayerViewCache = new WebPlayerViewCache();
}
@Test
@UiThreadTest
public void testAddWebPlayer() {
final Activity activity = activityTestRule.getActivity();
String viewId = "webplayer";
WebPlayerView expectedWebPlayerView = new WebPlayerView(activity, viewId, new JSONObject(), new JSONObject());
webPlayerViewCache.addWebPlayer(viewId, expectedWebPlayerView);
WebPlayerView actualWebPlayerView = webPlayerViewCache.getWebPlayer(viewId);
assertEquals(expectedWebPlayerView, actualWebPlayerView);
}
@Test
@UiThreadTest
public void testRemoveWebPlayer() {
final Activity activity = activityTestRule.getActivity();
String viewId = "webplayer";
WebPlayerView expectedWebPlayerView = new WebPlayerView(activity, viewId, new JSONObject(), new JSONObject());
webPlayerViewCache.addWebPlayer(viewId, expectedWebPlayerView);
webPlayerViewCache.removeWebPlayer(viewId);
WebPlayerView actualWebPlayerView = webPlayerViewCache.getWebPlayer(viewId);
assertNull(actualWebPlayerView);
}
@Test
public void testGetWebPlayerWhenViewIdNotFound() {
WebPlayerView webPlayerView = webPlayerViewCache.getWebPlayer("webplayer");
assertNull(webPlayerView);
}
}

Просмотреть файл

@ -0,0 +1,126 @@
package com.unity3d.ads.test.instrumentation.services.ads.webplayer;
import com.unity3d.services.ads.webplayer.WebPlayerSettingsCache;
import org.json.JSONObject;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
public class WebPlayerViewSettingsCacheTest {
private WebPlayerSettingsCache webPlayerSettingsCache;
@Before
public void before() {
webPlayerSettingsCache = new WebPlayerSettingsCache();
}
//================================================================================
// WebSettings
//================================================================================
@Test
public void testAddWebSettings() throws Exception {
String viewId = "view1";
JSONObject expectedSettings = new JSONObject();
expectedSettings.put("myValue", 1);
webPlayerSettingsCache.addWebSettings(viewId, expectedSettings);
JSONObject actualSettings = webPlayerSettingsCache.getWebSettings(viewId);
assertEquals(expectedSettings, actualSettings);
assertEquals(expectedSettings.toString(), actualSettings.toString());
}
@Test
public void testRemoveWebSettings() throws Exception {
String viewId = "view1";
JSONObject expectedSettings = new JSONObject();
expectedSettings.put("myValue", 1);
webPlayerSettingsCache.addWebSettings(viewId, expectedSettings);
webPlayerSettingsCache.removeWebSettings(viewId);
JSONObject actualSettings = webPlayerSettingsCache.getWebSettings(viewId);
assertNotEquals(expectedSettings, actualSettings);
assertNotEquals(expectedSettings.toString(), actualSettings.toString());
}
@Test
public void testGetWebSettingsWhenViewIdNotFound() {
JSONObject emptySettings = webPlayerSettingsCache.getWebSettings("noView");
assertEquals(new JSONObject().toString(), emptySettings.toString());
}
//================================================================================
// WebPlayerSettings
//================================================================================
@Test
public void testAddWebPlayerSettings() throws Exception {
String viewId = "view1";
JSONObject expectedSettings = new JSONObject();
expectedSettings.put("myValue", 1);
webPlayerSettingsCache.addWebPlayerSettings(viewId, expectedSettings);
JSONObject actualSettings = webPlayerSettingsCache.getWebPlayerSettings(viewId);
assertEquals(expectedSettings, actualSettings);
assertEquals(expectedSettings.toString(), actualSettings.toString());
}
@Test
public void testRemoveWebPlayerSettings() throws Exception {
String viewId = "view1";
JSONObject expectedSettings = new JSONObject();
expectedSettings.put("myValue", 1);
webPlayerSettingsCache.addWebPlayerSettings(viewId, expectedSettings);
webPlayerSettingsCache.removeWebPlayerSettings(viewId);
JSONObject actualSettings = webPlayerSettingsCache.getWebPlayerSettings(viewId);
assertNotEquals(expectedSettings, actualSettings);
assertNotEquals(expectedSettings.toString(), actualSettings.toString());
}
@Test
public void testGetWebPlayerSettingsWhenViewIdNotFound() {
JSONObject emptySettings = webPlayerSettingsCache.getWebPlayerSettings("noView");
assertEquals(new JSONObject().toString(), emptySettings.toString());
}
//================================================================================
// WebPlayerEventSettings
//================================================================================
@Test
public void testAddWebPlayerEventSettings() throws Exception {
String viewId = "view1";
JSONObject expectedSettings = new JSONObject();
expectedSettings.put("myValue", 1);
webPlayerSettingsCache.addWebPlayerEventSettings(viewId, expectedSettings);
JSONObject actualSettings = webPlayerSettingsCache.getWebPlayerEventSettings(viewId);
assertEquals(expectedSettings, actualSettings);
assertEquals(expectedSettings.toString(), actualSettings.toString());
}
@Test
public void testRemoveWebPlayerEventSettings() throws Exception {
String viewId = "view1";
JSONObject expectedSettings = new JSONObject();
expectedSettings.put("myValue", 1);
webPlayerSettingsCache.addWebPlayerEventSettings(viewId, expectedSettings);
webPlayerSettingsCache.removeWebPlayerEventSettings(viewId);
JSONObject actualSettings = webPlayerSettingsCache.getWebPlayerEventSettings(viewId);
assertNotEquals(expectedSettings, actualSettings);
assertNotEquals(expectedSettings.toString(), actualSettings.toString());
}
@Test
public void testGetWebPlayerEventSettingsWhenViewIdNotFound() {
JSONObject emptySettings = webPlayerSettingsCache.getWebPlayerEventSettings("noView");
assertEquals(new JSONObject().toString(), emptySettings.toString());
}
}

Просмотреть файл

@ -0,0 +1,132 @@
package com.unity3d.ads.test.instrumentation.services.banners;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import com.unity3d.ads.test.instrumentation.InstrumentationTestActivity;
import com.unity3d.services.banners.BannerErrorCode;
import com.unity3d.services.banners.BannerErrorInfo;
import com.unity3d.services.banners.BannerView;
import com.unity3d.services.banners.UnityBannerSize;
import com.unity3d.services.banners.BannerViewCache;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.util.concurrent.Semaphore;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
@RunWith(AndroidJUnit4.class)
public class BannerViewCacheTests {
@Rule
public final ActivityTestRule<InstrumentationTestActivity> _activityRule = new ActivityTestRule<>(InstrumentationTestActivity.class);
@Test
public void testAddBannerView() {
BannerViewCache bannerViewCache = new BannerViewCache();
BannerView bannerView = new BannerView(_activityRule.getActivity(), "test", new UnityBannerSize(320, 50));
String bannerAdId = bannerViewCache.addBannerView(bannerView);
BannerView storedBannerView = bannerViewCache.getBannerView(bannerAdId);
assertEquals(bannerView, storedBannerView);
}
@Test
public void testMultipleAddBannerView() {
BannerViewCache bannerViewCache = new BannerViewCache();
BannerView bannerView = new BannerView(_activityRule.getActivity(), "test", new UnityBannerSize(320, 50));
BannerView bannerView2 = new BannerView(_activityRule.getActivity(), "test", new UnityBannerSize(320, 50));
String bannerAdId = bannerViewCache.addBannerView(bannerView);
String bannerAdId2 = bannerViewCache.addBannerView(bannerView2);
BannerView storedBannerView = bannerViewCache.getBannerView(bannerAdId);
assertEquals(bannerView, storedBannerView);
BannerView storedBannerView2 = bannerViewCache.getBannerView(bannerAdId2);
assertEquals(bannerView2, storedBannerView2);
}
@Test
public void testRemoveBannerView() {
BannerViewCache bannerViewCache = new BannerViewCache();
BannerView bannerView = new BannerView(_activityRule.getActivity(), "test", new UnityBannerSize(320, 50));
BannerView bannerView2 = new BannerView(_activityRule.getActivity(), "test", new UnityBannerSize(320, 50));
String bannerAdId = bannerViewCache.addBannerView(bannerView);
bannerViewCache.addBannerView(bannerView2);
bannerViewCache.removeBannerView(bannerAdId);
BannerView storedBannerView = bannerViewCache.getBannerView(bannerAdId);
assertNull(storedBannerView);
}
@Test
public void testTriggerBannerLoadEvent() throws InterruptedException {
BannerViewCache bannerViewCache = new BannerViewCache();
final BannerView bannerView = new BannerView(_activityRule.getActivity(), "test", new UnityBannerSize(320, 50));
String bannerAdId = bannerViewCache.addBannerView(bannerView);
final Semaphore _loadedSemaphore = new Semaphore(0);
bannerView.setListener(new BannerView.Listener() {
@Override
public void onBannerLoaded(BannerView bannerAdView) {
assertEquals(bannerView, bannerAdView);
_loadedSemaphore.release();
}
});
bannerViewCache.triggerBannerLoadEvent(bannerAdId);
_loadedSemaphore.acquire();
}
@Test
public void testTriggerBannerClickEvent() throws InterruptedException {
BannerViewCache bannerViewCache = new BannerViewCache();
final BannerView bannerView = new BannerView(_activityRule.getActivity(), "test", new UnityBannerSize(320, 50));
String bannerAdId = bannerViewCache.addBannerView(bannerView);
final Semaphore _clickSemaphore = new Semaphore(0);
bannerView.setListener(new BannerView.Listener() {
@Override
public void onBannerClick(BannerView bannerAdView) {
assertEquals(bannerView, bannerAdView);
_clickSemaphore.release();
}
});
bannerViewCache.triggerBannerClickEvent(bannerAdId);
_clickSemaphore.acquire();
}
@Test
public void testTriggerBannerErrorEvent() throws InterruptedException {
BannerViewCache bannerViewCache = new BannerViewCache();
final BannerView bannerView = new BannerView(_activityRule.getActivity(), "test", new UnityBannerSize(320, 50));
final BannerErrorInfo bannerErrorInfo = new BannerErrorInfo("test error", BannerErrorCode.NATIVE_ERROR);
String bannerAdId = bannerViewCache.addBannerView(bannerView);
final Semaphore _errorSemaphore = new Semaphore(0);
bannerView.setListener(new BannerView.Listener() {
@Override
public void onBannerFailedToLoad(BannerView bannerAdView, BannerErrorInfo _bannerErrorInfo) {
assertEquals(bannerView, bannerAdView);
assertEquals(bannerErrorInfo, _bannerErrorInfo);
_errorSemaphore.release();
}
});
bannerViewCache.triggerBannerErrorEvent(bannerAdId, bannerErrorInfo);
_errorSemaphore.acquire();
}
@Test
public void testTriggerBannerLeftApplicationEvent() throws InterruptedException {
BannerViewCache bannerViewCache = new BannerViewCache();
final BannerView bannerView = new BannerView(_activityRule.getActivity(), "test", new UnityBannerSize(320, 50));
String bannerAdId = bannerViewCache.addBannerView(bannerView);
final Semaphore _leftApplicationSemaphore = new Semaphore(0);
bannerView.setListener(new BannerView.Listener() {
@Override
public void onBannerLeftApplication(BannerView bannerAdView) {
assertEquals(bannerView, bannerAdView);
_leftApplicationSemaphore.release();
}
});
bannerViewCache.triggerBannerLeftApplicationEvent(bannerAdId);
_leftApplicationSemaphore.acquire();
}
}

Просмотреть файл

@ -1,22 +1,22 @@
package com.unity3d.ads.test.unit.services.core.configuration;
package com.unity3d.ads.test.instrumentation.services.core.configuration;
import com.unity3d.services.core.configuration.IInitializationListener;
import com.unity3d.services.core.configuration.InitializationNotificationCenter;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import android.support.test.InstrumentationRegistry;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import android.support.test.runner.AndroidJUnit4;
import static org.junit.Assert.assertEquals;
@RunWith(AndroidJUnit4.class)
public class InitializationNotificationCenterTest {
private InitializationNotificationCenter initializationNotificationCenter;

Просмотреть файл

@ -0,0 +1,188 @@
package com.unity3d.ads.test.integration.banner;
import android.support.test.rule.ActivityTestRule;
import android.view.View;
import com.unity3d.ads.IUnityAdsListener;
import com.unity3d.ads.UnityAds;
import com.unity3d.ads.test.hybrid.HybridTestActivity;
import com.unity3d.services.banners.BannerErrorInfo;
import com.unity3d.services.banners.BannerView;
import com.unity3d.services.banners.IUnityBannerListener;
import com.unity3d.services.banners.UnityBannerSize;
import com.unity3d.services.banners.UnityBanners;
import com.unity3d.services.banners.view.BannerPosition;
import com.unity3d.services.core.configuration.IInitializationListener;
import com.unity3d.services.core.configuration.InitializationNotificationCenter;
import com.unity3d.services.core.misc.Utilities;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import java.util.concurrent.Semaphore;
import static junit.framework.Assert.*;
public class BannerIntegrationTest {
@ClassRule
public static final ActivityTestRule<HybridTestActivity> _activityRule = new ActivityTestRule<>(HybridTestActivity.class);
BannerView callbackbannerView;
View oldBannerView;
BannerView bannerView;
static IInitializationListener initializationListener;
@BeforeClass
public static void setUpOnce() throws InterruptedException {
final Semaphore initializeSemaphore = new Semaphore(0);
initializationListener = new IInitializationListener() {
@Override
public void onSdkInitialized() {
InitializationNotificationCenter.getInstance().removeListener(initializationListener);
initializeSemaphore.release();
}
@Override
public void onSdkInitializationFailed(String message, int code) {
InitializationNotificationCenter.getInstance().removeListener(initializationListener);
fail("Failed to initialize");
initializeSemaphore.release();
}
};
InitializationNotificationCenter.getInstance().addListener(initializationListener);
UnityAds.initialize(_activityRule.getActivity(), "14851", null, true, true);
initializeSemaphore.acquire();
}
@Test(timeout = 100000)
public void LegacyBannerTest() throws InterruptedException {
final Semaphore _loadedSemaphore = new Semaphore(0);
final Semaphore _shownSemaphore = new Semaphore(0);
final UnityBannerListener listener = new UnityBannerListener() {
@Override
public void onUnityBannerLoaded(String placementId, View view)
{
oldBannerView = view;
_loadedSemaphore.release();
Utilities.runOnUiThread(new Runnable() {
@Override
public void run() {
if (oldBannerView.getParent() == null) {
_activityRule.getActivity().addContentView(oldBannerView, oldBannerView.getLayoutParams());
_shownSemaphore.release();
}
}
});
}
@Override
public void onUnityBannerClick(String placementId) {
}
@Override
public void onUnityBannerError(String message) {
_loadedSemaphore.release();
_shownSemaphore.release();
fail("Banner error encountered " + message);
}
};
UnityBanners.setBannerListener(listener);
UnityBanners.setBannerPosition(BannerPosition.BOTTOM_CENTER);
Utilities.runOnUiThread(new Runnable() {
@Override
public void run() {
UnityBanners.loadBanner(_activityRule.getActivity(), "bannerads");
}
});
_loadedSemaphore.acquire();
assertNotNull(oldBannerView);
_shownSemaphore.acquire();
Utilities.runOnUiThread(new Runnable() {
@Override
public void run() {
UnityBanners.destroy();
}
});
oldBannerView = null;
}
@Test(timeout = 100000)
public void BannerTest() throws InterruptedException {
// There may be a timing issue with this test where webview has not finished initializing fully
// Even though webview tells native it is initialized
UnityBannerSize unityBannerSize = new UnityBannerSize(320, 50);
bannerView = new BannerView(_activityRule.getActivity(), "bannerads", unityBannerSize);
final Semaphore _loadedSemaphore = new Semaphore(0);
final Semaphore _clickSemaphore = new Semaphore(0);
bannerView.setListener(new BannerView.IListener() {
public void onBannerLoaded(BannerView bannerAdView) {
callbackbannerView = bannerAdView;
_loadedSemaphore.release();
}
public void onBannerClick(BannerView bannerAdView) {
callbackbannerView = bannerAdView;
_clickSemaphore.release();
}
public void onBannerFailedToLoad(BannerView bannerAdView, BannerErrorInfo bannerErrorInfo) {
_loadedSemaphore.release();
_clickSemaphore.release();
fail("Banner error encountered " + bannerErrorInfo.errorMessage);
}
public void onBannerLeftApplication(BannerView bannerView) {
}
});
bannerView.load();
_loadedSemaphore.acquire();
assertEquals(bannerView, callbackbannerView);
Utilities.runOnUiThread(new Runnable() {
@Override
public void run() {
if (bannerView.getParent() == null) {
_activityRule.getActivity().addContentView(bannerView, bannerView.getLayoutParams());
}
}
});
}
private class UnityBannerListener implements IUnityBannerListener {
@Override
public void onUnityBannerLoaded(String placementId, View view) {
}
@Override
public void onUnityBannerUnloaded(String placementId) {
}
@Override
public void onUnityBannerShow(String placementId) {
}
@Override
public void onUnityBannerClick(String placementId) {
}
@Override
public void onUnityBannerHide(String placementId) {
}
@Override
public void onUnityBannerError(String message) {
}
}
}

Просмотреть файл

@ -1,4 +1,4 @@
package com.unity3d.ads.test.unit;
package com.unity3d.ads.test.legacy;
import android.app.Activity;
import android.os.ConditionVariable;

Просмотреть файл

@ -1,4 +1,4 @@
package com.unity3d.ads.test.unit;
package com.unity3d.ads.test.legacy;
import android.app.Activity;
import android.content.Intent;

Просмотреть файл

@ -1,4 +1,4 @@
package com.unity3d.ads.test.unit;
package com.unity3d.ads.test.legacy;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;

Просмотреть файл

@ -1,4 +1,4 @@
package com.unity3d.ads.test.unit;
package com.unity3d.ads.test.legacy;
import android.content.Intent;
import android.net.Uri;

Просмотреть файл

@ -1,4 +1,4 @@
package com.unity3d.ads.test.unit;
package com.unity3d.ads.test.legacy;
import android.os.ConditionVariable;
import android.support.test.InstrumentationRegistry;

Просмотреть файл

@ -1,4 +1,4 @@
package com.unity3d.ads.test.unit;
package com.unity3d.ads.test.legacy;
import android.app.Activity;
import android.os.ConditionVariable;
@ -9,7 +9,7 @@ import android.support.test.runner.AndroidJUnit4;
import com.unity3d.ads.IUnityAdsListener;
import com.unity3d.ads.UnityAds;
import com.unity3d.services.ads.properties.AdsProperties;
import com.unity3d.ads.properties.AdsProperties;
import com.unity3d.services.core.properties.ClientProperties;
import org.junit.Before;
@ -19,7 +19,6 @@ import org.junit.runner.RunWith;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import static org.junit.Assert.*;

Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше