Skip to content

Commit

Permalink
initial commit of KWIZZAD Android SDK example app
Browse files Browse the repository at this point in the history
  • Loading branch information
gaylord-tvsmiles committed Jul 31, 2016
1 parent 2864313 commit f894c31
Show file tree
Hide file tree
Showing 18 changed files with 951 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,6 @@ captures/

# Keystore files
*.jks
/.DS_Store
/.idea
/example/.DS_Store
28 changes: 28 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
group = "com.kwizzad"
version = "0.1.0"

buildscript {
repositories {
jcenter()
mavenCentral()
mavenLocal()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

subprojects {
repositories {
jcenter()
mavenCentral()
maven() { url 'http://repo.kwizzad.com' }
}
}

task wrapper(type: Wrapper) {
gradleVersion = '2.14'
distributionUrl = "http://services.gradle.org/distributions/gradle-${gradleVersion}-all.zip"
}
56 changes: 56 additions & 0 deletions example/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
apply plugin: 'com.android.application'
apply plugin: 'me.tatarka.retrolambda'

buildscript {
repositories {
jcenter()
mavenCentral()
maven() { url 'http://repo.kwizzad.com' }
}
dependencies {
classpath 'me.tatarka:gradle-retrolambda:3.2.5'
}
}

retrolambda {
javaVersion JavaVersion.VERSION_1_7
}

android {
compileSdkVersion 23
buildToolsVersion "23.0.3"

defaultConfig {
applicationId "com.kwizzad.example"
minSdkVersion 15
targetSdkVersion 23
versionCode Integer.valueOf( System.env.BUILD_NUMBER ? System.env.BUILD_NUMBER : 1 )
versionName "0.1.0"
}

buildTypes {
debug {
minifyEnabled false
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.2.0'
compile 'com.android.support:design:23.2.0'
compile 'com.kwizzad.android:kwizzad-android:0.1.0@aar'
// KWIZZAD dependencies
compile 'com.squareup.okhttp3:okhttp:3.4.1'
compile 'io.reactivex:rxjava:1.1.7'
compile 'io.reactivex:rxandroid:1.2.1'
}
22 changes: 22 additions & 0 deletions example/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/msmoljan/Library/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 *;
#}

#kwizzad
-keep class com.google.android.gms.ads.identifier.* {*;}
-keep class com.kwizzad.* {*;}
-dontwarn java.lang.invoke.*
23 changes: 23 additions & 0 deletions example/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.kwizzad.example">

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application
android:name="com.kwizzad.example.ExampleApplication"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.kwizzad.example.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity android:name=".SimpleActivity"/>

</application>

</manifest>
24 changes: 24 additions & 0 deletions example/src/main/java/com/kwizzad/example/ExampleApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.kwizzad.example;

import android.app.Application;

import com.kwizzad.Configuration;
import com.kwizzad.Kwizzad;
import okhttp3.OkHttpClient;

public class ExampleApplication extends Application {

@Override
public void onCreate() {
super.onCreate();

Kwizzad.init(
new Configuration.Builder()
.applicationContext(this)
.apiKey("6137f9e8248c6099be8e22224b2dd3444a5c58da88b34cf864cc22a7ea8f5b7d")
.okHttpClient(new OkHttpClient())
.debug(true)
.build()
);
}
}
120 changes: 120 additions & 0 deletions example/src/main/java/com/kwizzad/example/MainActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
package com.kwizzad.example;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.Snackbar;
import android.support.design.widget.TextInputLayout;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;

import com.kwizzad.Kwizzad;
import com.kwizzad.log.QLog;
import com.kwizzad.model.PendingCallback;
import com.kwizzad.property.RxSubscriber;

import java.util.HashSet;
import java.util.Set;

public class MainActivity extends AppCompatActivity {

private Set<PendingCallback> shownCallbacks = new HashSet<>();
private TextInputLayout placementIdInput;
private View preloadButton;
private View simpleButton;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.a_main);

placementIdInput = (TextInputLayout) findViewById(R.id.placementId);

simpleButton = findViewById(R.id.simple);
if (simpleButton != null) {
simpleButton.setOnClickListener(v -> {
if (Kwizzad.initialized().get()) {
startActivity(SimpleActivity.createIntent(MainActivity.this, placementIdInput.getEditText().getText().toString()));
} else {
Log.e("KWIZZAD", "not initialized");
Snackbar.make(findViewById(R.id.coordinatorLayout), "kwizzad not initialized", Snackbar.LENGTH_INDEFINITE).show();
}
});
}

preloadButton = findViewById(R.id.preload);
if (preloadButton != null) {
preloadButton.setOnClickListener(v -> {
if (Kwizzad.initialized().get()) {
PreloadingDialogFragment.create(placementIdInput.getEditText().getText().toString())
.show(getSupportFragmentManager(), "preload");
} else {
Log.e("KWIZZAD", "not initialized");
Snackbar.make(findViewById(R.id.coordinatorLayout), "kwizzad not initialized", Snackbar.LENGTH_INDEFINITE).show();
}
});
}
}

@Override
protected void onResume() {
super.onResume();

Kwizzad.resume(this);

RxSubscriber.subscribe(this, Kwizzad.pendingCallbacks(), pendingCallbacks -> {
if (pendingCallbacks.size() > 0) {
QLog.d("should show callback " + pendingCallbacks);
// there are multiple callbacks possibly coming. its up to you if you want to show them all now
// or you want to show them some very different way.
// maybe its something like a notification for you
// thats what i will do here

// we dont wanna show this twice at least for the same session here
// you can handle that any way you want though
for (PendingCallback pendingCallback : pendingCallbacks) {
if (shownCallbacks.contains(pendingCallback) == false) {
QLog.d("showing callback " + pendingCallback);
showCallback(pendingCallback);

// just showing the first one
return;
}
}

return;
}
});
}

private void showCallback(final PendingCallback pendingCallback) {
shownCallbacks.add(pendingCallback);

new AlertDialog.Builder(this)
.setTitle("CALLBACK!")
.setMessage(pendingCallback.toString())
.setPositiveButton(android.R.string.ok,
(dialog, whichButton) -> {
Kwizzad.completeCallback(pendingCallback);
}
)
.setNegativeButton(android.R.string.cancel,
(dialog, whichButton) -> {
dialog.dismiss();
shownCallbacks.remove(pendingCallback);
}
)
.setOnDismissListener(dialog -> shownCallbacks.remove(pendingCallback))
.create()
.show();

}

@Override
protected void onPause() {
super.onPause();
RxSubscriber.unsubscribe(this);
}
}
Loading

0 comments on commit f894c31

Please sign in to comment.