diff --git a/DemoApp/DemoAppJava/.gitignore b/DemoApp/DemoAppJava/.gitignore new file mode 100644 index 0000000..d3881ac --- /dev/null +++ b/DemoApp/DemoAppJava/.gitignore @@ -0,0 +1,31 @@ +*.iml +.gradle +local.properties +.idea/caches +.idea/libraries +.idea/modules.xml +.idea/workspace.xml +.idea/navEditor.xml +.idea/assetWizardSettings.xml +.idea/gradle.xml +.idea/shelf/ +.idea/tasks.xml +.idea/.name +.idea/compiler.xml +.idea/copyright/profiles_settings.xml +.idea/encodings.xml +.idea/misc.xml +.idea/dictionaries +.idea/vcs.xml +.idea/jsLibraryMappings.xml +.idea/datasources.xml +.idea/dataSources.ids +.idea/sqlDataSources.xml +.idea/dynamic.xml +.idea/uiDesigner.xml +.idea/modules +.DS_Store +build +captures +.externalNativeBuild +.cxx diff --git a/DemoApp/DemoAppJava/.idea/codeStyles/Project.xml b/DemoApp/DemoAppJava/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..0d15693 --- /dev/null +++ b/DemoApp/DemoAppJava/.idea/codeStyles/Project.xml @@ -0,0 +1,134 @@ + + + + + + + + + + + +
+ + + + xmlns:android + + ^$ + + + +
+
+ + + + xmlns:.* + + ^$ + + + BY_NAME + +
+
+ + + + .*:id + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + .*:name + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + name + + ^$ + + + +
+
+ + + + style + + ^$ + + + +
+
+ + + + .* + + ^$ + + + BY_NAME + +
+
+ + + + .* + + http://schemas.android.com/apk/res/android + + + ANDROID_ATTRIBUTE_ORDER + +
+
+ + + + .* + + .* + + + BY_NAME + +
+
+
+
+
+
\ No newline at end of file diff --git a/DemoApp/DemoAppJava/.idea/jarRepositories.xml b/DemoApp/DemoAppJava/.idea/jarRepositories.xml new file mode 100644 index 0000000..2370474 --- /dev/null +++ b/DemoApp/DemoAppJava/.idea/jarRepositories.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/DemoApp/DemoAppJava/.idea/runConfigurations.xml b/DemoApp/DemoAppJava/.idea/runConfigurations.xml new file mode 100644 index 0000000..7f68460 --- /dev/null +++ b/DemoApp/DemoAppJava/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/DemoApp/DemoAppJava/app/.gitignore b/DemoApp/DemoAppJava/app/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/DemoApp/DemoAppJava/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/DemoApp/DemoAppJava/app/build.gradle b/DemoApp/DemoAppJava/app/build.gradle new file mode 100644 index 0000000..7b5fd82 --- /dev/null +++ b/DemoApp/DemoAppJava/app/build.gradle @@ -0,0 +1,55 @@ +plugins { + id("de.nanogiants.android-versioning") version "2.4.0" +} + +apply plugin: 'com.android.application' + +android { + compileSdkVersion 30 + buildToolsVersion "30.0.2" + + defaultConfig { + applicationId "co.optable.demoappjava" + minSdkVersion 16 + targetSdkVersion 29 + + // Here we get version code and version name from latest git release tags: + versionCode versioning.getVersionCode() + versionName versioning.getVersionName(false) + archivesBaseName = "optable-android-sdk-demo-java" + + multiDexEnabled true + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + +} + +dependencies { + implementation fileTree(dir: "libs", include: ["*.jar"]) + implementation 'androidx.appcompat:appcompat:1.2.0' + implementation 'com.google.android.material:material:1.2.1' + implementation 'androidx.constraintlayout:constraintlayout:2.0.2' + implementation 'androidx.vectordrawable:vectordrawable:1.1.0' + implementation 'androidx.navigation:navigation-fragment:2.3.0' + implementation 'androidx.navigation:navigation-ui:2.3.0' + implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0' + testImplementation 'junit:junit:4.12' + androidTestImplementation 'androidx.test.ext:junit:1.1.2' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' + + implementation 'com.google.android.gms:play-services-ads:19.3.0' + implementation "com.github.Optable:optable-android-sdk:2-issue-java-demo-SNAPSHOT" //+ versioning.getVersionName(false) +} \ No newline at end of file diff --git a/DemoApp/DemoAppJava/app/proguard-rules.pro b/DemoApp/DemoAppJava/app/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/DemoApp/DemoAppJava/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/DemoApp/DemoAppJava/app/src/androidTest/java/co/optable/demoappjava/ExampleInstrumentedTest.java b/DemoApp/DemoAppJava/app/src/androidTest/java/co/optable/demoappjava/ExampleInstrumentedTest.java new file mode 100644 index 0000000..7698b51 --- /dev/null +++ b/DemoApp/DemoAppJava/app/src/androidTest/java/co/optable/demoappjava/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package co.optable.demoappjava; + +import android.content.Context; + +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + assertEquals("co.optable.demoappjava", appContext.getPackageName()); + } +} \ No newline at end of file diff --git a/DemoApp/DemoAppJava/app/src/main/AndroidManifest.xml b/DemoApp/DemoAppJava/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..ab418f8 --- /dev/null +++ b/DemoApp/DemoAppJava/app/src/main/AndroidManifest.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/DemoApp/DemoAppJava/app/src/main/java/co/optable/demoappjava/MainActivity.java b/DemoApp/DemoAppJava/app/src/main/java/co/optable/demoappjava/MainActivity.java new file mode 100644 index 0000000..517e5ce --- /dev/null +++ b/DemoApp/DemoAppJava/app/src/main/java/co/optable/demoappjava/MainActivity.java @@ -0,0 +1,35 @@ +package co.optable.demoappjava; + +import android.os.Bundle; + +import com.google.android.material.bottomnavigation.BottomNavigationView; + +import androidx.appcompat.app.AppCompatActivity; +import androidx.navigation.NavController; +import androidx.navigation.Navigation; +import androidx.navigation.ui.AppBarConfiguration; +import androidx.navigation.ui.NavigationUI; +import co.optable.android_sdk.OptableSDK; + +public class MainActivity extends AppCompatActivity { + public static OptableSDK OPTABLE; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + MainActivity.OPTABLE = new OptableSDK(this.getApplicationContext(), "sandbox.optable.co", "android-sdk-demo"); + + BottomNavigationView navView = findViewById(R.id.nav_view); + NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment); + // Passing each menu ID as a set of Ids because each + // menu should be considered as top level destinations. + AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder( + R.id.navigation_identify, R.id.navigation_gambanner) + .build(); + NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration); + NavigationUI.setupWithNavController(navView, navController); + } + +} \ No newline at end of file diff --git a/DemoApp/DemoAppJava/app/src/main/java/co/optable/demoappjava/ui/GAMBanner/GAMBannerFragment.java b/DemoApp/DemoAppJava/app/src/main/java/co/optable/demoappjava/ui/GAMBanner/GAMBannerFragment.java new file mode 100644 index 0000000..6842c14 --- /dev/null +++ b/DemoApp/DemoAppJava/app/src/main/java/co/optable/demoappjava/ui/GAMBanner/GAMBannerFragment.java @@ -0,0 +1,77 @@ +package co.optable.demoappjava.ui.GAMBanner; + +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.fragment.app.Fragment; + +import com.google.android.gms.ads.doubleclick.PublisherAdRequest; +import com.google.android.gms.ads.doubleclick.PublisherAdView; + +import java.util.HashMap; + +import co.optable.android_sdk.OptableSDK; +import co.optable.demoappjava.MainActivity; +import co.optable.demoappjava.R; + +public class GAMBannerFragment extends Fragment { + private PublisherAdView mPublisherAdView; + private TextView targetingDataView; + + @Override + public View onCreateView(@NonNull LayoutInflater inflater, + ViewGroup container, Bundle savedInstanceState) { + View root = inflater.inflate(R.layout.fragment_gambanner, container, false); + mPublisherAdView = root.findViewById(R.id.publisherAdView); + targetingDataView = root.findViewById(R.id.targetingDataView); + + Button btn = root.findViewById(R.id.loadAdButton); + btn.setOnClickListener(view -> { + targetingDataView.setText(""); + + MainActivity.OPTABLE.targeting().observe(getViewLifecycleOwner(), result -> { + PublisherAdRequest.Builder adRequest = new PublisherAdRequest.Builder(); + final StringBuilder msg = new StringBuilder(); + msg.append(targetingDataView.getText().toString()); + + if (result.getStatus() == OptableSDK.Status.SUCCESS) { + msg.append("Loading GAM ad with targeting data:\n\n"); + result.getData().forEach((key, values) -> { + adRequest.addCustomTargeting(key, values); + msg.append(key.toString() + " = " + values.toString()); + }); + } else { + msg.append("OptableSDK Error: " + result.getMessage()); + } + + targetingDataView.setText(msg.toString()); + mPublisherAdView.loadAd(adRequest.build()); + }); + + HashMap eventProperties = new HashMap(); + eventProperties.put("exampleKey", "exampleValue"); + + MainActivity.OPTABLE + .witness("GAMBannerFragment.loadAdButtonClicked", eventProperties) + .observe(getViewLifecycleOwner(), result -> { + final StringBuilder msg = new StringBuilder(); + msg.append(targetingDataView.getText().toString()); + + if (result.getStatus() == OptableSDK.Status.SUCCESS) { + msg.append("\n\nSuccess calling witness API to log loadAdButtonClicked event.\n\n"); + } else { + msg.append("\n\nOptableSDK Error: " + result.getMessage() + "\n\n"); + } + + targetingDataView.setText(msg.toString()); + }); + }); + + return root; + } +} \ No newline at end of file diff --git a/DemoApp/DemoAppJava/app/src/main/java/co/optable/demoappjava/ui/Identify/IdentifyFragment.java b/DemoApp/DemoAppJava/app/src/main/java/co/optable/demoappjava/ui/Identify/IdentifyFragment.java new file mode 100644 index 0000000..85c689b --- /dev/null +++ b/DemoApp/DemoAppJava/app/src/main/java/co/optable/demoappjava/ui/Identify/IdentifyFragment.java @@ -0,0 +1,51 @@ +package co.optable.demoappjava.ui.Identify; + +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.EditText; +import android.widget.Switch; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.fragment.app.Fragment; + +import co.optable.android_sdk.OptableSDK; +import co.optable.demoappjava.MainActivity; +import co.optable.demoappjava.R; + +public class IdentifyFragment extends Fragment { + private TextView identifyView; + private EditText emailText; + private Switch gaidSwitch; + + @Override + public View onCreateView(@NonNull LayoutInflater inflater, + ViewGroup container, Bundle savedInstanceState) { + View root = inflater.inflate(R.layout.fragment_identify, container, false); + identifyView = root.findViewById(R.id.identifyView); + emailText = root.findViewById(R.id.editTextTextEmailAddress); + gaidSwitch = root.findViewById(R.id.gaidSwitch); + + Button btn = root.findViewById(R.id.identifyButton); + btn.setOnClickListener(view -> + MainActivity.OPTABLE + .identify(emailText.getText().toString(), gaidSwitch.isChecked()) + .observe(getViewLifecycleOwner(), result -> { + String msg = "Calling identify API... "; + + if (result.getStatus() == OptableSDK.Status.SUCCESS) { + msg += "Success"; + } else { + msg += "\n\nOptableSDK Error: " + result.getMessage(); + } + + identifyView.setText(msg); + }) + ); + + return root; + } +} diff --git a/DemoApp/DemoAppJava/app/src/main/res/drawable/ic_gambanner_black_24dp.xml b/DemoApp/DemoAppJava/app/src/main/res/drawable/ic_gambanner_black_24dp.xml new file mode 100644 index 0000000..46fc8de --- /dev/null +++ b/DemoApp/DemoAppJava/app/src/main/res/drawable/ic_gambanner_black_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/DemoApp/DemoAppJava/app/src/main/res/drawable/ic_identify_black.xml b/DemoApp/DemoAppJava/app/src/main/res/drawable/ic_identify_black.xml new file mode 100644 index 0000000..92fcf46 --- /dev/null +++ b/DemoApp/DemoAppJava/app/src/main/res/drawable/ic_identify_black.xml @@ -0,0 +1,14 @@ + + + + diff --git a/DemoApp/DemoAppJava/app/src/main/res/drawable/ic_launcher_background.xml b/DemoApp/DemoAppJava/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..07d5da9 --- /dev/null +++ b/DemoApp/DemoAppJava/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/DemoApp/DemoAppJava/app/src/main/res/drawable/ic_launcher_foreground.xml b/DemoApp/DemoAppJava/app/src/main/res/drawable/ic_launcher_foreground.xml new file mode 100644 index 0000000..2b068d1 --- /dev/null +++ b/DemoApp/DemoAppJava/app/src/main/res/drawable/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/DemoApp/DemoAppJava/app/src/main/res/layout/activity_main.xml b/DemoApp/DemoAppJava/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..38c0aa8 --- /dev/null +++ b/DemoApp/DemoAppJava/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,33 @@ + + + + + + + + \ No newline at end of file diff --git a/DemoApp/DemoAppJava/app/src/main/res/layout/fragment_gambanner.xml b/DemoApp/DemoAppJava/app/src/main/res/layout/fragment_gambanner.xml new file mode 100644 index 0000000..cd1a0f3 --- /dev/null +++ b/DemoApp/DemoAppJava/app/src/main/res/layout/fragment_gambanner.xml @@ -0,0 +1,40 @@ + + + + + +