diff --git a/fiamui-app/README.md b/fiamui-app/README.md deleted file mode 100644 index 9f911ad06c6..00000000000 --- a/fiamui-app/README.md +++ /dev/null @@ -1,21 +0,0 @@ -# FIAMUI-App SDK -This module contains a test-app for Firebase In-App Messaging's Display SDK -(see the firebase-inappmessaging-display module). - -[Firebase In-App Messaging](https://firebase.google.com/docs/in-app-messaging/) helps you engage -users who are actively using your app by sending them targeted and contextual messages that nudge -them to complete key in-app actions - like beating a game level, buying an item, or subscribing to -content. - -The FIAM Display SDK gives you more control over your in-app messages you send, allowing you to -customize typeface, colors, transitions, corner radii, and more. - -## Running Tests -Unit tests: -`../gradlew :fiamui-app:test` - -Integration tests, requiring a running and connected device (emulator or real): -`../gradlew :fiamui-app:connectedAndroidTest` - -The best way to test is via the fiamui-app in this repo - you can run the test, or use -Firebase Test Lab to run a series of UI tests. See fiamui-app/scripts for more details \ No newline at end of file diff --git a/fiamui-app/fiamui-app.gradle b/fiamui-app/fiamui-app.gradle deleted file mode 100644 index ea2b12728f5..00000000000 --- a/fiamui-app/fiamui-app.gradle +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright 2018 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -apply plugin: "com.android.application" -apply plugin: com.google.firebase.gradle.plugins.ci.device.FirebaseTestLabPlugin - -android { - compileSdkVersion project.targetSdkVersion - testBuildType 'release' - - defaultConfig { - applicationId "com.example.firebase.fiamui" - minSdkVersion 16 - targetSdkVersion project.targetSdkVersion - versionCode 1 - versionName "1.0" - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" - multiDexEnabled true - } - - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" - signingConfig debug.signingConfig - } - } - - testOptions { - animationsDisabled = true - } - - lintOptions { - warning 'InvalidPackage' - warning 'GradleCompatible' - } - - // TODO: Would be nice if we could test on 1_7 - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 - } -} - -dependencies { - implementation project(path: ":firebase-inappmessaging-display") - implementation project(path: ":firebase-inappmessaging") - implementation 'com.google.guava:guava:24.1-jre-android' - implementation ("com.google.firebase:firebase-analytics:17.4.0") { - exclude group: "com.google.firebase", module: "firebase-common" - exclude group: "com.google.firebase", module: "firebase-components" - exclude group: "com.google.firebase", module: "firebase-installations-interop" - exclude group: "com.google.firebase", module: "firebase-installations" - } - implementation "com.android.installreferrer:installreferrer:1.1.2" - implementation 'com.google.android.material:material:1.1.0' - implementation 'androidx.appcompat:appcompat:1.1.0' - implementation 'androidx.annotation:annotation:1.1.0' - implementation 'androidx.media:media:1.1.0' - implementation 'androidx.legacy:legacy-support-v4:1.0.0' - implementation "com.google.code.findbugs:jsr305:3.0.2" - implementation "com.squareup.okio:okio:2.2.2" - implementation "com.squareup.okhttp:okhttp:2.7.5" - implementation "com.google.auto.value:auto-value-annotations:1.6.6" - implementation "com.google.android.gms:play-services-basement:17.2.1" - - // The following dependencies are not required to use the FIAM UI library. - // They are used to make some aspects of the demo app implementation simpler for - // demonstrative purposes, and you may find them useful in your own apps; YMMV. - implementation 'me.priyesh:chroma:1.0.2' - implementation "com.jakewharton:butterknife:10.1.0" - annotationProcessor "com.jakewharton:butterknife-compiler:10.1.0" - - androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' - androidTestImplementation 'androidx.test:rules:1.2.0' -} diff --git a/fiamui-app/proguard-rules.pro b/fiamui-app/proguard-rules.pro deleted file mode 100644 index 34421dce4fb..00000000000 --- a/fiamui-app/proguard-rules.pro +++ /dev/null @@ -1,28 +0,0 @@ -# Add project specific ProGuard rules here. -# By default, the flags in this file are appended to flags specified -# in /usr/local/google/home/ashwinraghav/Android/Sdk/tools/proguard/proguard-android.txt -# You can edit the include path and order by changing the proguardFiles -# directive in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# Add any project specific keep options here: - -# 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 - --keep class **$$ViewInjector { *; } --keep class **$$ViewBinder { *; } \ No newline at end of file diff --git a/fiamui-app/scripts/run-test-lab.sh b/fiamui-app/scripts/run-test-lab.sh deleted file mode 100644 index 38429acc08d..00000000000 --- a/fiamui-app/scripts/run-test-lab.sh +++ /dev/null @@ -1,60 +0,0 @@ -#!/bin/bash -# -# Copyright 2018 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# First, you need to create a project, and bucket to use for the FTL runs. - -############################################################ -## Note, running this will incur any FTL-related charges. ## -## We do require manual setting of the script arguments ## -## to ensure you've read this notice. ## -############################################################ - -PROJECT_NAME = {{add your project id here}} -BUCKET_NAME = {{add your bucket name here}} - -# Assemble the app -./gradlew :fiamui-app:assembleDebug :fiamui-app:assembleDebugAndroidTest - -# Choose the project -gcloud config set project $PROJECT_ID - -# Show the storage bucket -echo "Tests launching!" - -# Run the tests on the following devices -# * Pixel 2, API 27 - good for testing the ideal case -# * OnePlus, API 22 - popular problematic phone model -# * Nexus 7, API 19 - small tablet screen, outdated API -# * Galaxy S7E, API 23 - popular high-end phone model, samsung exposure -# * Low Res Phone, API 23 - capture very low-res cases -# * Moto X, API 19 - popular old phone model, low API -gcloud firebase test android run \ - --type instrumentation \ - --results-bucket=$BUCKET_NAME \ - --app fiamui-app/build/outputs/apk/debug/fiamui-app-debug.apk \ - --test fiamui-app/build/outputs/apk/androidTest/debug/fiamui-app-debug-androidTest.apk \ - --device model=Pixel2,version=27,locale=en,orientation=portrait \ - --device model=Pixel2,version=27,locale=en,orientation=landscape \ - --device model=A0001,version=22,locale=en,orientation=portrait \ - --device model=A0001,version=22,locale=en,orientation=landscape \ - --device model=Nexus7,version=19,locale=en,orientation=portrait \ - --device model=Nexus7,version=19,locale=en,orientation=landscape \ - --device model=hero2lte,version=23,locale=en,orientation=portrait \ - --device model=hero2lte,version=23,locale=en,orientation=landscape \ - --device model=NexusLowRes,version=23,locale=en,orientation=portrait \ - --device model=NexusLowRes,version=23,locale=en,orientation=landscape \ - --device model=victara,version=19,locale=en,orientation=portrait \ - --device model=victara,version=19,locale=en,orientation=landscape \ No newline at end of file diff --git a/fiamui-app/src/androidTest/AndroidManifest.xml b/fiamui-app/src/androidTest/AndroidManifest.xml deleted file mode 100644 index e023e74a98c..00000000000 --- a/fiamui-app/src/androidTest/AndroidManifest.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/fiamui-app/src/androidTest/java/com/example/firebase/fiamui/BannerTest.java b/fiamui-app/src/androidTest/java/com/example/firebase/fiamui/BannerTest.java deleted file mode 100644 index 91e91d4e1fa..00000000000 --- a/fiamui-app/src/androidTest/java/com/example/firebase/fiamui/BannerTest.java +++ /dev/null @@ -1,97 +0,0 @@ -// Copyright 2018 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package com.example.firebase.fiamui; - -import static androidx.test.espresso.Espresso.onView; -import static androidx.test.espresso.action.ViewActions.click; -import static androidx.test.espresso.action.ViewActions.scrollTo; -import static androidx.test.espresso.action.ViewActions.swipeLeft; -import static androidx.test.espresso.assertion.ViewAssertions.matches; -import static androidx.test.espresso.matcher.RootMatchers.withDecorView; -import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; -import static androidx.test.espresso.matcher.ViewMatchers.withId; -import static androidx.test.espresso.matcher.ViewMatchers.withText; -import static com.example.firebase.fiamui.TestConstants.*; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.not; - -import androidx.annotation.IdRes; -import androidx.annotation.NonNull; -import androidx.test.espresso.Root; -import androidx.test.espresso.ViewInteraction; -import androidx.test.filters.MediumTest; -import androidx.test.rule.ActivityTestRule; -import androidx.test.runner.AndroidJUnit4; -import org.hamcrest.Matcher; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TestName; -import org.junit.runner.RunWith; - -@MediumTest -@RunWith(AndroidJUnit4.class) -public class BannerTest { - - @Rule - public ActivityTestRule mActivityRule = new ActivityTestRule<>(MainActivity.class); - - @Rule public TestName name = new TestName(); - - private Matcher rootMatcher; - - @Before - public void setUp() { - rootMatcher = withDecorView(not(is(mActivityRule.getActivity().getWindow().getDecorView()))); - } - - @After - public void tearDown() { - ScreenShotter.takeScreenshot(name.getMethodName()); - close(); - } - - @Test - public void testBanner() { - open(); - - getView(R.id.banner_root).check(matches(isDisplayed())); - getView(R.id.banner_title).check(matches(withText(TITLE_TEXT_NORMAL))); - getView(R.id.banner_body).check(matches(withText(BODY_TEXT_NORMAL))); - } - - private void open() { - onView(withId(R.id.banner_fiam)).perform(scrollTo()).perform(click()); - onView(withId(R.id.start)).perform(scrollTo()).perform(click()); - } - - private void close() { - getView(R.id.banner_content_root).perform(swipeLeft()); - - // Need to sleep for a second to give the swipe animation time to finish so - // the banner does not interfere with the next test. - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - @NonNull - private ViewInteraction getView(@IdRes int id) { - return onView(withId(id)).inRoot(rootMatcher); - } -} diff --git a/fiamui-app/src/androidTest/java/com/example/firebase/fiamui/CardTest.java b/fiamui-app/src/androidTest/java/com/example/firebase/fiamui/CardTest.java deleted file mode 100644 index 06799d0d5b2..00000000000 --- a/fiamui-app/src/androidTest/java/com/example/firebase/fiamui/CardTest.java +++ /dev/null @@ -1,280 +0,0 @@ -// Copyright 2018 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package com.example.firebase.fiamui; - -import static androidx.test.espresso.Espresso.onView; -import static androidx.test.espresso.action.ViewActions.clearText; -import static androidx.test.espresso.action.ViewActions.click; -import static androidx.test.espresso.action.ViewActions.replaceText; -import static androidx.test.espresso.action.ViewActions.scrollTo; -import static androidx.test.espresso.assertion.ViewAssertions.matches; -import static androidx.test.espresso.matcher.RootMatchers.withDecorView; -import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; -import static androidx.test.espresso.matcher.ViewMatchers.isRoot; -import static androidx.test.espresso.matcher.ViewMatchers.withId; -import static androidx.test.espresso.matcher.ViewMatchers.withText; -import static com.example.firebase.fiamui.TestConstants.BODY_OPT_LONG; -import static com.example.firebase.fiamui.TestConstants.BODY_OPT_NONE; -import static com.example.firebase.fiamui.TestConstants.BODY_OPT_NORMAL; -import static com.example.firebase.fiamui.TestConstants.BODY_TEXT_LONG; -import static com.example.firebase.fiamui.TestConstants.BODY_TEXT_NORMAL; -import static com.example.firebase.fiamui.TestConstants.BUTTON_TEXT_CANCEL; -import static com.example.firebase.fiamui.TestConstants.BUTTON_TEXT_NONE; -import static com.example.firebase.fiamui.TestConstants.BUTTON_TEXT_NORMAL; -import static com.example.firebase.fiamui.TestConstants.TITLE_TEXT_NORMAL; -import static com.example.firebase.fiamui.TestConstants.TITLE_TEXT_SHORT; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.not; - -import androidx.annotation.IdRes; -import androidx.annotation.NonNull; -import androidx.annotation.StringRes; -import androidx.test.espresso.Root; -import androidx.test.espresso.ViewInteraction; -import androidx.test.espresso.action.ViewActions; -import androidx.test.filters.MediumTest; -import androidx.test.rule.ActivityTestRule; -import androidx.test.runner.AndroidJUnit4; -import org.hamcrest.Matcher; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TestName; -import org.junit.runner.RunWith; - -@MediumTest -@RunWith(AndroidJUnit4.class) -public class CardTest { - - @Rule - public ActivityTestRule mActivityRule = new ActivityTestRule<>(MainActivity.class); - - @Rule public TestName name = new TestName(); - - private Matcher rootMatcher; - - @Before - public void setUp() { - rootMatcher = withDecorView(not(is(mActivityRule.getActivity().getWindow().getDecorView()))); - - // Set defaults - setTitle(TITLE_TEXT_NORMAL); - selectBody(BODY_OPT_NORMAL); - setPortraitImageSize(600, 400); // Ideal 3:2 aspect ratio - setLandscapeImageSize(800, 800); // Ideal 1:1 aspect ratio - setButton(BUTTON_TEXT_NORMAL, R.id.action_button_text); - setButton(BUTTON_TEXT_CANCEL, R.id.secondary_action_button_text); - } - - @After - public void tearDown() { - ScreenShotter.takeScreenshot(name.getMethodName()); - - // If we are NOT in test lab, add a 2s delay after each test. This - // makes bench testing easier since you can eyeball the results as they run. - if (!TestUtils.isInTestLab(mActivityRule.getActivity())) { - try { - Thread.sleep(2000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - close(); - } - - @Test - public void testCard() { - open(); - - getView(R.id.card_root).check(matches(isDisplayed())); - getView(R.id.message_title).check(matches(withText(TITLE_TEXT_NORMAL))); - getView(R.id.image_view).check(matches(isDisplayed())); - getView(R.id.message_body).check(matches(withText(BODY_TEXT_NORMAL))); - getView(R.id.primary_button).check(matches(withText(BUTTON_TEXT_NORMAL))); - getView(R.id.secondary_button).check(matches(withText(BUTTON_TEXT_CANCEL))); - } - - @Test - public void testCard_LongBody() { - selectBody(BODY_OPT_LONG); - open(); - - getView(R.id.card_root).check(matches(isDisplayed())); - getView(R.id.message_title).check(matches(withText(TITLE_TEXT_NORMAL))); - getView(R.id.image_view).check(matches(isDisplayed())); - getView(R.id.message_body).check(matches(withText(BODY_TEXT_LONG))); - getView(R.id.primary_button).check(matches(withText(BUTTON_TEXT_NORMAL))); - getView(R.id.secondary_button).check(matches(withText(BUTTON_TEXT_CANCEL))); - } - - @Test - public void testCard_NoBody() { - selectBody(BODY_OPT_NONE); - open(); - - getView(R.id.card_root).check(matches(isDisplayed())); - getView(R.id.message_title).check(matches(withText(TITLE_TEXT_NORMAL))); - getView(R.id.image_view).check(matches(isDisplayed())); - getView(R.id.message_body).check(matches(not(isDisplayed()))); - getView(R.id.primary_button).check(matches(withText(BUTTON_TEXT_NORMAL))); - getView(R.id.secondary_button).check(matches(withText(BUTTON_TEXT_CANCEL))); - } - - @Test - public void testCard_ShortTitle() { - setTitle(TITLE_TEXT_SHORT); - open(); - - getView(R.id.card_root).check(matches(isDisplayed())); - getView(R.id.message_title).check(matches(withText(TITLE_TEXT_SHORT))); - getView(R.id.image_view).check(matches(isDisplayed())); - getView(R.id.message_body).check(matches(withText(BODY_TEXT_NORMAL))); - getView(R.id.primary_button).check(matches(withText(BUTTON_TEXT_NORMAL))); - getView(R.id.secondary_button).check(matches(withText(BUTTON_TEXT_CANCEL))); - } - - @Test - public void testCard_ShortTitleNoBody() { - setTitle(TITLE_TEXT_SHORT); - selectBody(BODY_OPT_NONE); - open(); - - getView(R.id.card_root).check(matches(isDisplayed())); - getView(R.id.message_title).check(matches(withText(TITLE_TEXT_SHORT))); - getView(R.id.image_view).check(matches(isDisplayed())); - getView(R.id.message_body).check(matches(not(isDisplayed()))); - getView(R.id.primary_button).check(matches(withText(BUTTON_TEXT_NORMAL))); - getView(R.id.secondary_button).check(matches(withText(BUTTON_TEXT_CANCEL))); - } - - @Test - public void testCard_OneButton() { - setButton(BUTTON_TEXT_NONE, R.id.secondary_action_button_text); - open(); - - getView(R.id.card_root).check(matches(isDisplayed())); - getView(R.id.message_title).check(matches(withText(TITLE_TEXT_NORMAL))); - getView(R.id.image_view).check(matches(isDisplayed())); - getView(R.id.message_body).check(matches(withText(BODY_TEXT_NORMAL))); - getView(R.id.primary_button).check(matches(withText(BUTTON_TEXT_NORMAL))); - getView(R.id.secondary_button).check(matches(not(isDisplayed()))); - } - - @Test - public void testCard_TinyImage() { - setPortraitImageSize(50, 50); - open(); - - getView(R.id.card_root).check(matches(isDisplayed())); - getView(R.id.message_title).check(matches(withText(TITLE_TEXT_NORMAL))); - getView(R.id.image_view).check(matches(isDisplayed())); - getView(R.id.message_body).check(matches(withText(BODY_TEXT_NORMAL))); - getView(R.id.primary_button).check(matches(withText(BUTTON_TEXT_NORMAL))); - getView(R.id.secondary_button).check(matches(withText(BUTTON_TEXT_CANCEL))); - } - - @Test - public void testCard_WideImage() { - setPortraitImageSize(600, 400); - open(); - - getView(R.id.card_root).check(matches(isDisplayed())); - getView(R.id.message_title).check(matches(withText(TITLE_TEXT_NORMAL))); - getView(R.id.image_view).check(matches(isDisplayed())); - getView(R.id.message_body).check(matches(withText(BODY_TEXT_NORMAL))); - getView(R.id.primary_button).check(matches(withText(BUTTON_TEXT_NORMAL))); - getView(R.id.secondary_button).check(matches(withText(BUTTON_TEXT_CANCEL))); - } - - @Test - public void testCard_MissingLandscapeImage() { - setPortraitImageSize(600, 400); - setLandscapeImageSize(0, 0); - open(); - - getView(R.id.card_root).check(matches(isDisplayed())); - getView(R.id.message_title).check(matches(withText(TITLE_TEXT_NORMAL))); - getView(R.id.image_view).check(matches(isDisplayed())); - getView(R.id.message_body).check(matches(withText(BODY_TEXT_NORMAL))); - getView(R.id.primary_button).check(matches(withText(BUTTON_TEXT_NORMAL))); - getView(R.id.secondary_button).check(matches(withText(BUTTON_TEXT_CANCEL))); - } - - @Test - public void testCard_MissingPortraitImage() { - setPortraitImageSize(0, 0); - setLandscapeImageSize(800, 800); - open(); - - getView(R.id.card_root).check(matches(isDisplayed())); - getView(R.id.message_title).check(matches(withText(TITLE_TEXT_NORMAL))); - getView(R.id.image_view).check(matches(isDisplayed())); - getView(R.id.message_body).check(matches(withText(BODY_TEXT_NORMAL))); - getView(R.id.primary_button).check(matches(withText(BUTTON_TEXT_NORMAL))); - getView(R.id.secondary_button).check(matches(withText(BUTTON_TEXT_CANCEL))); - } - - @NonNull - private ViewInteraction getView(@IdRes int id) { - return onView(withId(id)).inRoot(rootMatcher); - } - - private void selectBody(@IdRes int radioButtonId) { - onView(withId(radioButtonId)).perform(scrollTo()).perform(click()); - } - - private void setTitle(@StringRes int titleRes) { - if (titleRes >= 0) { - String title = mActivityRule.getActivity().getString(titleRes); - onView(withId(R.id.message_title)).perform(scrollTo()).perform(replaceText(title)); - } else { - onView(withId(R.id.message_title)).perform(scrollTo()).perform(clearText()); - } - } - - private void setButton(@StringRes int buttonRes, @IdRes int textId) { - if (buttonRes >= 0) { - String buttonString = mActivityRule.getActivity().getString(buttonRes); - onView(withId(textId)).perform(scrollTo()).perform(replaceText(buttonString)); - } else { - onView(withId(textId)).perform(scrollTo()).perform(clearText()); - } - } - - private void setPortraitImageSize(int w, int h) { - onView(withId(R.id.image_width)).perform(scrollTo()).perform(replaceText(Integer.toString(w))); - onView(withId(R.id.image_height)).perform(scrollTo()).perform(replaceText(Integer.toString(h))); - } - - private void setLandscapeImageSize(int w, int h) { - onView(withId(R.id.landscape_image_width)) - .perform(scrollTo()) - .perform(replaceText(Integer.toString(w))); - onView(withId(R.id.landscape_image_height)) - .perform(scrollTo()) - .perform(replaceText(Integer.toString(h))); - } - - private void open() { - onView(withId(R.id.card_fiam)).perform(scrollTo()).perform(click()); - onView(withId(R.id.start)).perform(scrollTo()).perform(click()); - } - - private void close() { - onView(isRoot()).perform(ViewActions.pressBack()); - } -} diff --git a/fiamui-app/src/androidTest/java/com/example/firebase/fiamui/ImageTest.java b/fiamui-app/src/androidTest/java/com/example/firebase/fiamui/ImageTest.java deleted file mode 100644 index c2c680e748f..00000000000 --- a/fiamui-app/src/androidTest/java/com/example/firebase/fiamui/ImageTest.java +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright 2018 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package com.example.firebase.fiamui; - -import static androidx.test.espresso.Espresso.onView; -import static androidx.test.espresso.action.ViewActions.click; -import static androidx.test.espresso.action.ViewActions.scrollTo; -import static androidx.test.espresso.assertion.ViewAssertions.matches; -import static androidx.test.espresso.matcher.RootMatchers.withDecorView; -import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; -import static androidx.test.espresso.matcher.ViewMatchers.withId; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.not; - -import androidx.annotation.IdRes; -import androidx.annotation.NonNull; -import androidx.test.espresso.Root; -import androidx.test.espresso.ViewInteraction; -import androidx.test.filters.MediumTest; -import androidx.test.rule.ActivityTestRule; -import androidx.test.runner.AndroidJUnit4; -import org.hamcrest.Matcher; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TestName; -import org.junit.runner.RunWith; - -@MediumTest -@RunWith(AndroidJUnit4.class) -public class ImageTest { - - @Rule - public ActivityTestRule mActivityRule = new ActivityTestRule<>(MainActivity.class); - - @Rule public TestName name = new TestName(); - - private Matcher rootMatcher; - - @Before - public void setUp() { - rootMatcher = withDecorView(not(is(mActivityRule.getActivity().getWindow().getDecorView()))); - } - - @After - public void tearDown() { - ScreenShotter.takeScreenshot(name.getMethodName()); - close(); - } - - @Test - public void testImage() { - open(); - - getView(R.id.image_root).check(matches(isDisplayed())); - } - - @NonNull - private ViewInteraction getView(@IdRes int id) { - return onView(withId(id)).inRoot(rootMatcher); - } - - private void open() { - onView(withId(R.id.image_fiam)).perform(scrollTo()).perform(click()); - onView(withId(R.id.start)).perform(scrollTo()).perform(click()); - } - - private void close() { - getView(R.id.collapse_button).perform(click()); - } -} diff --git a/fiamui-app/src/androidTest/java/com/example/firebase/fiamui/ModalTest.java b/fiamui-app/src/androidTest/java/com/example/firebase/fiamui/ModalTest.java deleted file mode 100644 index e2884ff86a6..00000000000 --- a/fiamui-app/src/androidTest/java/com/example/firebase/fiamui/ModalTest.java +++ /dev/null @@ -1,281 +0,0 @@ -// Copyright 2018 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package com.example.firebase.fiamui; - -import static androidx.test.espresso.Espresso.onView; -import static androidx.test.espresso.action.ViewActions.clearText; -import static androidx.test.espresso.action.ViewActions.click; -import static androidx.test.espresso.action.ViewActions.replaceText; -import static androidx.test.espresso.action.ViewActions.scrollTo; -import static androidx.test.espresso.assertion.ViewAssertions.matches; -import static androidx.test.espresso.matcher.RootMatchers.withDecorView; -import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; -import static androidx.test.espresso.matcher.ViewMatchers.withId; -import static androidx.test.espresso.matcher.ViewMatchers.withText; -import static com.example.firebase.fiamui.TestConstants.BODY_OPT_LONG; -import static com.example.firebase.fiamui.TestConstants.BODY_OPT_NONE; -import static com.example.firebase.fiamui.TestConstants.BODY_OPT_NORMAL; -import static com.example.firebase.fiamui.TestConstants.BODY_TEXT_LONG; -import static com.example.firebase.fiamui.TestConstants.BODY_TEXT_NORMAL; -import static com.example.firebase.fiamui.TestConstants.BUTTON_TEXT_NONE; -import static com.example.firebase.fiamui.TestConstants.BUTTON_TEXT_NORMAL; -import static com.example.firebase.fiamui.TestConstants.TITLE_TEXT_NONE; -import static com.example.firebase.fiamui.TestConstants.TITLE_TEXT_NORMAL; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.not; - -import androidx.annotation.IdRes; -import androidx.annotation.NonNull; -import androidx.annotation.StringRes; -import androidx.test.espresso.Root; -import androidx.test.espresso.ViewInteraction; -import androidx.test.filters.MediumTest; -import androidx.test.rule.ActivityTestRule; -import androidx.test.runner.AndroidJUnit4; -import org.hamcrest.Matcher; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TestName; -import org.junit.runner.RunWith; - -@MediumTest -@RunWith(AndroidJUnit4.class) -public class ModalTest { - - @Rule - public ActivityTestRule mActivityRule = new ActivityTestRule<>(MainActivity.class); - - @Rule public TestName name = new TestName(); - - private Matcher rootMatcher; - - @Before - public void setUp() { - rootMatcher = withDecorView(not(is(mActivityRule.getActivity().getWindow().getDecorView()))); - - // Set defaults - setTitle(TITLE_TEXT_NORMAL); - selectBody(BODY_OPT_NORMAL); - setImageSize(800, 800); - } - - @After - public void tearDown() { - ScreenShotter.takeScreenshot(name.getMethodName()); - - // If we are NOT in test lab, add a 2s delay after each test. This - // makes bench testing easier since you can eyeball the results as they run. - if (!TestUtils.isInTestLab(mActivityRule.getActivity())) { - try { - Thread.sleep(2000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - close(); - } - - @Test - public void testModal() { - open(); - - getView(R.id.modal_root).check(matches(isDisplayed())); - getView(R.id.message_title).check(matches(withText(TITLE_TEXT_NORMAL))); - getView(R.id.image_view).check(matches(isDisplayed())); - getView(R.id.message_body).check(matches(withText(BODY_TEXT_NORMAL))); - getView(R.id.button).check(matches(withText(BUTTON_TEXT_NORMAL))); - } - - @Test - public void testModal_LongBody() { - selectBody(BODY_OPT_LONG); - open(); - - getView(R.id.modal_root).check(matches(isDisplayed())); - getView(R.id.message_title).check(matches(withText(TITLE_TEXT_NORMAL))); - getView(R.id.image_view).check(matches(isDisplayed())); - getView(R.id.message_body).check(matches(withText(BODY_TEXT_LONG))); - getView(R.id.button).check(matches(withText(BUTTON_TEXT_NORMAL))); - } - - @Test - public void testModal_NoBody() { - selectBody(BODY_OPT_NONE); - open(); - - getView(R.id.modal_root).check(matches(isDisplayed())); - getView(R.id.message_title).check(matches(withText(TITLE_TEXT_NORMAL))); - getView(R.id.image_view).check(matches(isDisplayed())); - getView(R.id.message_body).check(matches(not(isDisplayed()))); - getView(R.id.button).check(matches(withText(BUTTON_TEXT_NORMAL))); - } - - @Test - public void testModal_NoTitle() { - setTitle(TITLE_TEXT_NONE); - open(); - - getView(R.id.modal_root).check(matches(isDisplayed())); - getView(R.id.message_title).check(matches(not(isDisplayed()))); - getView(R.id.image_view).check(matches(isDisplayed())); - getView(R.id.message_body).check(matches(withText(BODY_TEXT_NORMAL))); - getView(R.id.button).check(matches(withText(BUTTON_TEXT_NORMAL))); - } - - @Test - public void testModal_NoImage() { - setImageSize(0, 0); - open(); - - getView(R.id.modal_root).check(matches(isDisplayed())); - getView(R.id.message_title).check(matches(isDisplayed())); - getView(R.id.image_view).check(matches(not(isDisplayed()))); - getView(R.id.message_body).check(matches(withText(BODY_TEXT_NORMAL))); - getView(R.id.button).check(matches(withText(BUTTON_TEXT_NORMAL))); - } - - @Test - public void testModal_NoImage_NoButton() { - setImageSize(0, 0); - setButton(BUTTON_TEXT_NONE); - open(); - - getView(R.id.modal_root).check(matches(isDisplayed())); - getView(R.id.message_title).check(matches(isDisplayed())); - getView(R.id.image_view).check(matches(not(isDisplayed()))); - getView(R.id.message_body).check(matches(withText(BODY_TEXT_NORMAL))); - getView(R.id.button).check(matches(not(isDisplayed()))); - } - - @Test - public void testModal_NoButton() { - setButton(BUTTON_TEXT_NONE); - open(); - - getView(R.id.modal_root).check(matches(isDisplayed())); - getView(R.id.message_title).check(matches(withText(TITLE_TEXT_NORMAL))); - getView(R.id.image_view).check(matches(isDisplayed())); - getView(R.id.message_body).check(matches(withText(BODY_TEXT_NORMAL))); - getView(R.id.button).check(matches(not(isDisplayed()))); - } - - @Test - public void testModal_NoTitleNoBody() { - setTitle(TITLE_TEXT_NONE); - selectBody(BODY_OPT_NONE); - open(); - - getView(R.id.modal_root).check(matches(isDisplayed())); - getView(R.id.message_title).check(matches(not(isDisplayed()))); - getView(R.id.image_view).check(matches(isDisplayed())); - getView(R.id.message_body).check(matches(not(isDisplayed()))); - getView(R.id.button).check(matches(withText(BUTTON_TEXT_NORMAL))); - } - - @Test - public void testModal_TinyImage() { - setImageSize(50, 50); - open(); - - getView(R.id.modal_root).check(matches(isDisplayed())); - getView(R.id.message_title).check(matches(withText(TITLE_TEXT_NORMAL))); - getView(R.id.image_view).check(matches(isDisplayed())); - getView(R.id.message_body).check(matches(withText(BODY_TEXT_NORMAL))); - getView(R.id.button).check(matches(withText(BUTTON_TEXT_NORMAL))); - } - - @Test - public void testModal_TallImage_LongBody() { - setImageSize(100, 1200); - selectBody(BODY_OPT_LONG); - open(); - - getView(R.id.modal_root).check(matches(isDisplayed())); - getView(R.id.message_title).check(matches(withText(TITLE_TEXT_NORMAL))); - getView(R.id.image_view).check(matches(isDisplayed())); - getView(R.id.message_body).check(matches(withText(BODY_TEXT_LONG))); - getView(R.id.button).check(matches(withText(BUTTON_TEXT_NORMAL))); - } - - @Test - public void testModal_WideImage() { - setImageSize(1500, 500); - open(); - - getView(R.id.modal_root).check(matches(isDisplayed())); - getView(R.id.message_title).check(matches(withText(TITLE_TEXT_NORMAL))); - getView(R.id.image_view).check(matches(isDisplayed())); - getView(R.id.message_body).check(matches(withText(BODY_TEXT_NORMAL))); - getView(R.id.button).check(matches(withText(BUTTON_TEXT_NORMAL))); - } - - @Test - public void testModal_TallImage() { - setImageSize(500, 1500); - open(); - - getView(R.id.modal_root).check(matches(isDisplayed())); - getView(R.id.message_title).check(matches(withText(TITLE_TEXT_NORMAL))); - getView(R.id.image_view).check(matches(isDisplayed())); - getView(R.id.message_body).check(matches(withText(BODY_TEXT_NORMAL))); - getView(R.id.button).check(matches(withText(BUTTON_TEXT_NORMAL))); - } - - @NonNull - private ViewInteraction getView(@IdRes int id) { - return onView(withId(id)).inRoot(rootMatcher); - } - - private void selectBody(@IdRes int radioButtonId) { - onView(withId(radioButtonId)).perform(scrollTo()).perform(click()); - } - - private void setTitle(@StringRes int titleRes) { - if (titleRes >= 0) { - String title = mActivityRule.getActivity().getString(titleRes); - onView(withId(R.id.message_title)).perform(scrollTo()).perform(replaceText(title)); - } else { - onView(withId(R.id.message_title)).perform(scrollTo()).perform(clearText()); - } - } - - private void setButton(@StringRes int buttonRes) { - if (buttonRes >= 0) { - String buttonString = mActivityRule.getActivity().getString(buttonRes); - onView(withId(R.id.action_button_text)) - .perform(scrollTo()) - .perform(replaceText(buttonString)); - } else { - onView(withId(R.id.action_button_text)).perform(scrollTo()).perform(clearText()); - } - } - - private void setImageSize(int w, int h) { - onView(withId(R.id.image_width)).perform(scrollTo()).perform(replaceText(Integer.toString(w))); - onView(withId(R.id.image_height)).perform(scrollTo()).perform(replaceText(Integer.toString(h))); - } - - private void open() { - onView(withId(R.id.modal_fiam)).perform(scrollTo()).perform(click()); - onView(withId(R.id.start)).perform(scrollTo()).perform(click()); - } - - private void close() { - getView(R.id.collapse_button).perform(click()); - } -} diff --git a/fiamui-app/src/androidTest/java/com/example/firebase/fiamui/ScreenShotter.java b/fiamui-app/src/androidTest/java/com/example/firebase/fiamui/ScreenShotter.java deleted file mode 100644 index 8e070029bb5..00000000000 --- a/fiamui-app/src/androidTest/java/com/example/firebase/fiamui/ScreenShotter.java +++ /dev/null @@ -1,147 +0,0 @@ -// Copyright 2018 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package com.example.firebase.fiamui; - -import android.graphics.Bitmap; -import android.util.Log; -import androidx.test.runner.screenshot.ScreenCapture; -import androidx.test.runner.screenshot.Screenshot; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.lang.reflect.Method; -import java.util.concurrent.atomic.AtomicInteger; -import org.junit.Test; - -/** A set of utility methods used to take screenshots from tests on an android virtual device. */ -public class ScreenShotter { - private static final String FILE_NAME_DELIMITER = "-"; - private static final String IMAGE_TYPE = "jpg"; - private static final String LOG_TAG = "cloud_screenshotter"; - private static final String SCREENSHOT_PATH = "/sdcard/screenshots/"; - private static String lastClassName = ""; - private static String lastMethodName = ""; - private static AtomicInteger counter = new AtomicInteger(0); - - /** - * Immediately take a screenshot with the given name. - * - * @param name The name of the screenshot - */ - public static void takeScreenshot(String name) { - String fileName = getScreenshotFileName(name); - try { - takeScreenshotInternal(fileName); - } catch (Exception e) { - Log.e(LOG_TAG, "Exception taking screenshot: " + e.toString()); - } - } - - /** - * Take a screenshot on a device and save it as the specified file name. - * - * @param fileName name of file in which to save the screenshot. - */ - private static void takeScreenshotInternal(final String fileName) { - - ScreenCapture capture = Screenshot.capture(); - Bitmap bitmap = capture.getBitmap(); - File imageFolder = new File(SCREENSHOT_PATH); - imageFolder.mkdirs(); - - File imageFile = new File(imageFolder, fileName + "." + IMAGE_TYPE); - OutputStream out = null; - - try { - out = new FileOutputStream(imageFile); - bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out); - out.flush(); - } catch (IOException e) { - Log.e(LOG_TAG, "Exception taking screenshot: " + e.toString()); - } finally { - try { - if (out != null) { - out.close(); - } - } catch (IOException e) { - Log.e(LOG_TAG, "There was an error closing the FileOutputStream " + e.toString()); - } - } - } - - /** - * Construct a screenshot file name from the specified screenshot name - * - * @param screenshotName name for this screenshot - * @return screenshot file name with the following format --- - */ - private static String getScreenshotFileName(String screenshotName) { - for (StackTraceElement element : Thread.currentThread().getStackTrace()) { - String elementClassName = element.getClassName(); - String elementMethodName = element.getMethodName(); - if (elementMethodName.startsWith("test") - || isJUnit4Test(elementClassName, elementMethodName)) { - if (!elementClassName.equals(lastClassName) || !elementMethodName.equals(lastMethodName)) { - counter = new AtomicInteger(0); - } - lastClassName = elementClassName; - lastMethodName = elementMethodName; - String filename = - elementClassName - + FILE_NAME_DELIMITER - + elementMethodName - + FILE_NAME_DELIMITER - + screenshotName - + FILE_NAME_DELIMITER - + counter.incrementAndGet(); - - return filename; - } - } - - lastClassName = ""; - lastMethodName = ""; - return "UnknownTestClass" - + FILE_NAME_DELIMITER - + "unknownTestMethod" - + FILE_NAME_DELIMITER - + screenshotName - + FILE_NAME_DELIMITER - + counter.incrementAndGet(); - } - - private static boolean isJUnit4Test(String elementClassName, String elementMethodName) { - try { - Class clazz = Class.forName(elementClassName); - for (Method method : clazz.getMethods()) { - if (method.getName().equals(elementMethodName) - && method.getAnnotation(Test.class) != null) { - return true; - } - } - for (Method method : clazz.getDeclaredMethods()) { - if (method.getName().equals(elementMethodName) - && method.getAnnotation(Test.class) != null) { - return true; - } - } - } catch (ClassNotFoundException e) { - return false; - } - return false; - } -} diff --git a/fiamui-app/src/androidTest/java/com/example/firebase/fiamui/TestConstants.java b/fiamui-app/src/androidTest/java/com/example/firebase/fiamui/TestConstants.java deleted file mode 100644 index 90e16d6b517..00000000000 --- a/fiamui-app/src/androidTest/java/com/example/firebase/fiamui/TestConstants.java +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2018 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package com.example.firebase.fiamui; - -import androidx.annotation.IdRes; -import androidx.annotation.StringRes; - -public class TestConstants { - - // Title text IDs - @StringRes public static final int TITLE_TEXT_NONE = -1; - @StringRes public static final int TITLE_TEXT_SHORT = R.string.short_message_title; - @StringRes public static final int TITLE_TEXT_NORMAL = R.string.default_message_title; - - // Body text IDs - @StringRes public static final int BODY_TEXT_NORMAL = R.string.body_text_normal; - @StringRes public static final int BODY_TEXT_LONG = R.string.body_text_long; - - // Button text IDs - @StringRes public static final int BUTTON_TEXT_NORMAL = R.string.view_wishlist; - @StringRes public static final int BUTTON_TEXT_CANCEL = R.string.button_text_cancel; - @StringRes public static final int BUTTON_TEXT_NONE = -1; - - // Body radio button IDs - @IdRes public static final int BODY_OPT_NORMAL = R.id.normal_body_text; - @IdRes public static final int BODY_OPT_LONG = R.id.long_body_text; - @IdRes public static final int BODY_OPT_NONE = R.id.no_body_text; -} diff --git a/fiamui-app/src/androidTest/java/com/example/firebase/fiamui/TestUtils.java b/fiamui-app/src/androidTest/java/com/example/firebase/fiamui/TestUtils.java deleted file mode 100644 index 97884e19349..00000000000 --- a/fiamui-app/src/androidTest/java/com/example/firebase/fiamui/TestUtils.java +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2018 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package com.example.firebase.fiamui; - -import android.content.Context; -import android.provider.Settings; - -public class TestUtils { - - public static boolean isInTestLab(Context context) { - String testLabSetting = - Settings.System.getString(context.getContentResolver(), "firebase.test.lab"); - return ("true".equals(testLabSetting)); - } -} diff --git a/fiamui-app/src/main/AndroidManifest.xml b/fiamui-app/src/main/AndroidManifest.xml deleted file mode 100644 index 82a655f86f6..00000000000 --- a/fiamui-app/src/main/AndroidManifest.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/fiamui-app/src/main/java/com/example/firebase/fiamui/MainActivity.java b/fiamui-app/src/main/java/com/example/firebase/fiamui/MainActivity.java deleted file mode 100644 index 25f8d5f3fd8..00000000000 --- a/fiamui-app/src/main/java/com/example/firebase/fiamui/MainActivity.java +++ /dev/null @@ -1,353 +0,0 @@ -// Copyright 2018 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package com.example.firebase.fiamui; - -import android.graphics.drawable.ColorDrawable; -import android.os.Bundle; -import android.text.TextUtils; -import android.view.View; -import android.widget.Button; -import android.widget.RadioButton; -import androidx.annotation.Nullable; -import androidx.annotation.StringRes; -import androidx.appcompat.app.AppCompatActivity; -import butterknife.BindView; -import butterknife.ButterKnife; -import butterknife.OnClick; -import com.google.android.material.textfield.TextInputEditText; -import com.google.common.collect.ImmutableMap; -import com.google.firebase.analytics.FirebaseAnalytics; -import com.google.firebase.inappmessaging.display.FirebaseInAppMessagingDisplay; -import com.google.firebase.inappmessaging.model.*; -import me.priyesh.chroma.ChromaDialog; -import me.priyesh.chroma.ColorMode; -import me.priyesh.chroma.ColorSelectListener; - -public class MainActivity extends AppCompatActivity { - - @BindView(R.id.start) - Button mStart; - - @BindView(R.id.modal_fiam) - RadioButton useModalFiam; - - @BindView(R.id.banner_fiam) - RadioButton useBannerFiam; - - @BindView(R.id.image_fiam) - RadioButton useImageFiam; - - @BindView(R.id.card_fiam) - RadioButton useCardFiam; - - @BindView(R.id.long_body_text) - RadioButton useLongBodyText; - - @BindView(R.id.normal_body_text) - RadioButton useNormalBodyText; - - @BindView(R.id.no_body_text) - RadioButton useNoBodyText; - - @BindView(R.id.message_title) - TextInputEditText messageTitle; - - @BindView(R.id.image_width) - TextInputEditText imageWidth; - - @BindView(R.id.image_height) - TextInputEditText imageHeight; - - @BindView(R.id.landscape_image_width) - TextInputEditText landscapeImageWidth; - - @BindView(R.id.landscape_image_height) - TextInputEditText landscapeImageHeight; - - @BindView(R.id.action_button_text) - TextInputEditText actionButtonText; - - @BindView(R.id.action_button_url) - TextInputEditText actionButtonUrl; - - @BindView(R.id.secondary_action_button_text) - TextInputEditText secondaryActionButtonText; - - @BindView(R.id.fiam_ttl) - TextInputEditText fiamTTL; - - @BindView(R.id.color_body_bg_container) - View colorBodyBgContainer; - - @BindView(R.id.color_body_bg_preview) - View colorBodyBgPreview; - - @BindView(R.id.color_body_text_container) - View colorBodyTextContainer; - - @BindView(R.id.color_body_text_preview) - View colorBodyTextPreview; - - @BindView(R.id.color_button_bg_container) - View colorButtonBgContainer; - - @BindView(R.id.color_button_bg_preview) - View colorButtonBgPreview; - - @BindView(R.id.color_button_text_container) - View colorButtonTextContainer; - - @BindView(R.id.color_button_text_preview) - View colorButtonTextPreview; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main); - - ButterKnife.bind(this); - - FirebaseAnalytics analytics = FirebaseAnalytics.getInstance(this); - Bundle bundle = new Bundle(); - bundle.putString(FirebaseAnalytics.Param.ITEM_ID, "id"); - bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, "name"); - bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, "image"); - analytics.logEvent(FirebaseAnalytics.Event.SELECT_CONTENT, bundle); - - bindColorPicker(colorBodyBgContainer, colorBodyBgPreview); - bindColorPicker(colorBodyTextContainer, colorBodyTextPreview); - bindColorPicker(colorButtonBgContainer, colorButtonBgPreview); - bindColorPicker(colorButtonTextContainer, colorButtonTextPreview); - } - - @OnClick(R.id.start) - public void onStartClick(View v) { - String buttonBackgroundColorString = getBackgroundColorString(colorButtonBgPreview); - String buttonTextColorString = getBackgroundColorString(colorButtonTextPreview); - String bodyTextColorString = getBackgroundColorString(colorBodyTextPreview); - String bodyBackgroundColorString = getBackgroundColorString(colorBodyBgPreview); - - String bodyText = getString(getSelectedBodyText()); - - String imageUrlString = makeImageUrl(imageWidth, imageHeight); - ImageData imageData = - imageUrlString != null ? ImageData.builder().setImageUrl(imageUrlString).build() : null; - - String landscapeUrlString = makeImageUrl(landscapeImageWidth, landscapeImageHeight); - ImageData landscapeImageData = - landscapeUrlString != null - ? ImageData.builder().setImageUrl(landscapeUrlString).build() - : null; - - String actionButtonTextString = actionButtonText.getText().toString(); - String actionButtonUrlString = actionButtonUrl.getText().toString(); - String secondaryActionButtonTextString = secondaryActionButtonText.getText().toString(); - - CampaignMetadata campaignMetadata = new CampaignMetadata("test_campaign", "name", true); - ImmutableMap data = ImmutableMap.of("up", "dog"); - - if (useImageFiam.isChecked()) { - ImageOnlyMessage.Builder builder = ImageOnlyMessage.builder(); - Action action = Action.builder().setActionUrl(actionButtonUrlString).build(); - - ImageOnlyMessage message = - builder.setImageData(imageData).setAction(action).build(campaignMetadata, data); - - FirebaseInAppMessagingDisplay.getInstance() - .testMessage(this, message, new NoOpDisplayCallbacks()); - } else if (useBannerFiam.isChecked()) { - BannerMessage.Builder builder = BannerMessage.builder(); - Text body = Text.builder().setText(bodyText).setHexColor(bodyTextColorString).build(); - Action action = Action.builder().setActionUrl(actionButtonUrlString).build(); - Text title = - Text.builder() - .setText(messageTitle.getText().toString()) - .setHexColor(bodyTextColorString) - .build(); - - BannerMessage message = - builder - .setBackgroundHexColor(bodyBackgroundColorString) - .setTitle(title) - .setBody(body) - .setImageData(imageData) - .setAction(action) - .build(campaignMetadata, data); - - FirebaseInAppMessagingDisplay.getInstance() - .testMessage(this, message, new NoOpDisplayCallbacks()); - } else if (useCardFiam.isChecked()) { - // Setup builder - CardMessage.Builder builder = CardMessage.builder(); - - // Main text - Text title = - Text.builder() - .setText(messageTitle.getText().toString()) - .setHexColor(bodyTextColorString) - .build(); - Text body = Text.builder().setText(bodyText).setHexColor(bodyTextColorString).build(); - - // Primary button text - Action primaryAction; - if (TextUtils.isEmpty(actionButtonTextString)) { - primaryAction = null; - } else { - Text primaryButtonText = - Text.builder() - .setText(actionButtonTextString) - .setHexColor(buttonTextColorString) - .build(); - com.google.firebase.inappmessaging.model.Button primaryActionButton = - com.google.firebase.inappmessaging.model.Button.builder() - .setText(primaryButtonText) - .setButtonHexColor(buttonBackgroundColorString) - .build(); - primaryAction = - Action.builder() - .setActionUrl(actionButtonUrlString) - .setButton(primaryActionButton) - .build(); - } - - // Secondary button text - Action secondaryAction; - if (TextUtils.isEmpty(secondaryActionButtonTextString)) { - secondaryAction = null; - } else { - Text secondaryButtonText = - Text.builder() - .setText(secondaryActionButtonTextString) - .setHexColor(buttonTextColorString) - .build(); - com.google.firebase.inappmessaging.model.Button secondaryActionButton = - com.google.firebase.inappmessaging.model.Button.builder() - .setText(secondaryButtonText) - .setButtonHexColor(buttonBackgroundColorString) - .build(); - secondaryAction = - Action.builder() - .setActionUrl(actionButtonUrlString) - .setButton(secondaryActionButton) - .build(); - } - - CardMessage message = - builder - .setBackgroundHexColor(bodyBackgroundColorString) - .setTitle(title) - .setBody(body) - .setPortraitImageData(imageData) - .setLandscapeImageData(landscapeImageData) - .setPrimaryAction(primaryAction) - .setSecondaryAction(secondaryAction) - .build(campaignMetadata, data); - - FirebaseInAppMessagingDisplay.getInstance() - .testMessage(this, message, new NoOpDisplayCallbacks()); - - } else { - ModalMessage.Builder builder = ModalMessage.builder(); - - Text title = - Text.builder() - .setText(messageTitle.getText().toString()) - .setHexColor(bodyTextColorString) - .build(); - Text body = Text.builder().setText(bodyText).setHexColor(bodyTextColorString).build(); - - Action modalAction; - if (TextUtils.isEmpty(actionButtonTextString)) { - modalAction = null; - } else { - Text buttonText = - Text.builder() - .setText(actionButtonTextString) - .setHexColor(buttonTextColorString) - .build(); - com.google.firebase.inappmessaging.model.Button actionButton = - com.google.firebase.inappmessaging.model.Button.builder() - .setText(buttonText) - .setButtonHexColor(buttonBackgroundColorString) - .build(); - modalAction = - Action.builder().setActionUrl(actionButtonUrlString).setButton(actionButton).build(); - } - - ModalMessage message = - builder - .setBackgroundHexColor(bodyBackgroundColorString) - .setTitle(title) - .setBody(body) - .setImageData(imageData) - .setAction(modalAction) - .build(campaignMetadata, data); - - FirebaseInAppMessagingDisplay.getInstance() - .testMessage(this, message, new NoOpDisplayCallbacks()); - } - } - - @StringRes - private int getSelectedBodyText() { - if (useLongBodyText.isChecked()) { - return R.string.body_text_long; - } - - if (useNoBodyText.isChecked()) { - return R.string.no_body_text; - } - - return R.string.body_text_normal; - } - - private int getBackgroundColor(View view) { - ColorDrawable drawable = (ColorDrawable) view.getBackground(); - return drawable.getColor(); - } - - private String getBackgroundColorString(View view) { - return String.format("#%06X", (0xFFFFFF & getBackgroundColor(view))); - } - - @Nullable - private String makeImageUrl(TextInputEditText imageWidth, TextInputEditText imageHeight) { - String w = imageWidth.getText().toString(); - String h = imageHeight.getText().toString(); - - return "0".equals(w) && "0".equals(h) ? null : "https://unsplash.it/" + w + "/" + h; - } - - private void bindColorPicker(View container, final View preview) { - container.setOnClickListener( - new View.OnClickListener() { - @Override - public void onClick(View view) { - new ChromaDialog.Builder() - .initialColor(getBackgroundColor(preview)) - .colorMode(ColorMode.RGB) - .onColorSelected( - new ColorSelectListener() { - @Override - public void onColorSelected(int i) { - preview.setBackgroundColor(i); - } - }) - .create() - .show(getSupportFragmentManager(), "ChromaDialog"); - } - }); - } -} diff --git a/fiamui-app/src/main/java/com/example/firebase/fiamui/NoOpDisplayCallbacks.java b/fiamui-app/src/main/java/com/example/firebase/fiamui/NoOpDisplayCallbacks.java deleted file mode 100644 index 4a5db4d3cf3..00000000000 --- a/fiamui-app/src/main/java/com/example/firebase/fiamui/NoOpDisplayCallbacks.java +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright 2018 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package com.example.firebase.fiamui; - -import com.google.android.gms.tasks.Task; -import com.google.android.gms.tasks.TaskCompletionSource; -import com.google.firebase.inappmessaging.FirebaseInAppMessagingDisplayCallbacks; -import com.google.firebase.inappmessaging.model.Action; - -public class NoOpDisplayCallbacks implements FirebaseInAppMessagingDisplayCallbacks { - @Override - public Task impressionDetected() { - return new TaskCompletionSource().getTask(); - } - - @Override - public Task messageDismissed(InAppMessagingDismissType dismissType) { - return new TaskCompletionSource().getTask(); - } - - @Deprecated - public Task messageClicked() { - return new TaskCompletionSource().getTask(); - } - - @Override - public Task messageClicked(Action action) { - return new TaskCompletionSource().getTask(); - } - - @Override - public Task displayErrorEncountered(InAppMessagingErrorReason inAppMessagingErrorReason) { - return new TaskCompletionSource().getTask(); - } -} diff --git a/fiamui-app/src/main/java/com/example/firebase/fiamui/SampleApplication.java b/fiamui-app/src/main/java/com/example/firebase/fiamui/SampleApplication.java deleted file mode 100644 index e010872a949..00000000000 --- a/fiamui-app/src/main/java/com/example/firebase/fiamui/SampleApplication.java +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright 2018 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package com.example.firebase.fiamui; - -import androidx.multidex.MultiDexApplication; - -public class SampleApplication extends MultiDexApplication { - @Override - public void onCreate() { - super.onCreate(); - } -} diff --git a/fiamui-app/src/main/java/com/example/firebase/fiamui/TestActivity.java b/fiamui-app/src/main/java/com/example/firebase/fiamui/TestActivity.java deleted file mode 100644 index ca41ac570a8..00000000000 --- a/fiamui-app/src/main/java/com/example/firebase/fiamui/TestActivity.java +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2018 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package com.example.firebase.fiamui; - -import android.os.Bundle; -import androidx.appcompat.app.AppCompatActivity; - -public class TestActivity extends AppCompatActivity { - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - } -} diff --git a/fiamui-app/src/main/res/layout/activity_main.xml b/fiamui-app/src/main/res/layout/activity_main.xml deleted file mode 100644 index 2acb390c824..00000000000 --- a/fiamui-app/src/main/res/layout/activity_main.xml +++ /dev/null @@ -1,335 +0,0 @@ - - - - - - - - - -