Skip to content

Commit

Permalink
Merge pull request #16 from GreedyGame/8.8.17
Browse files Browse the repository at this point in the history
8.8.17
  • Loading branch information
arpchaudhary committed Jan 31, 2020
2 parents d8c6725 + f800fc1 commit 68d307d
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 131 deletions.
190 changes: 81 additions & 109 deletions app/app.iml

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@ dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'

implementation 'com.android.support:design:28.0.0'

implementation 'com.google.android.gms:play-services-ads:11.0.4'
// Must Include Depedencies for GreedyGame
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:palette-v7:28.0.0'

implementation 'com.google.android.gms:play-services-ads:17.2.1'

implementation 'com.greedygame:core:9.0'
implementation 'com.squareup.moshi:moshi-kotlin:1.8.0'
implementation 'com.greedygame:greedygame:8.8.17'

testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
Expand Down
23 changes: 19 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:networkSecurityConfig="@xml/network_security_config">
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-3940256099942544~3347511713"/>
<activity android:name=".MainActivity"
android:label="Native Ads">
<intent-filter>
Expand All @@ -23,13 +26,25 @@
</intent-filter>
</activity>
<activity
android:name="com.greedygame.android.core.campaign.uii.GreedyGameActivity"
android:name="com.greedygame.android.core.campaign.uii.web.GGWebActivity"
android:configChanges="keyboardHidden|orientation|screenSize|screenLayout|layoutDirection"
android:hardwareAccelerated="true"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:theme="@style/Theme.GGTransparent">
</activity>
android:theme="@style/Theme.GGTransparent"/>

<activity
android:name="com.greedygame.android.core.mediation.greedygame.GGS2SActivity"
android:configChanges="keyboardHidden|orientation|screenSize|screenLayout|layoutDirection"
android:hardwareAccelerated="true"
android:launchMode="singleTask"
android:theme="@style/Theme.GGTransparent"/>

<activity
android:name="com.greedygame.android.core.mediation.admob.GGAdMobActivity"
android:configChanges="keyboardHidden|orientation|screenSize|screenLayout|layoutDirection"
android:hardwareAccelerated="true"
android:launchMode="singleTask"
android:theme="@style/Theme.GGTransparent"/>

</application>

Expand Down
47 changes: 38 additions & 9 deletions app/src/main/java/com/greedygame/androidsample/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,31 +1,49 @@
package com.greedygame.androidsample

import android.content.Context
import android.graphics.BitmapFactory
import android.os.Bundle
import android.support.design.widget.Snackbar
import android.support.v7.app.AppCompatActivity
import com.greedygame.android.agent.AdListener
import com.greedygame.android.agent.GreedyGameAds
import android.widget.ImageView
import com.greedygame.android.agent.GreedyGameAgent

import com.greedygame.android.core.campaign.CampaignStateListener
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity(), AdListener {
class MainActivity : AppCompatActivity(), CampaignStateListener {
var greedyGameAgent:GreedyGameAgent?=null;
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val greedyGameAgent = GreedyGameAds.Builder(this)
.appId("00000010")
.addUnitId("slot-1000")
.addUnitId("slot-1001")

//GreedyGameAgent can be initiated with an Activity or a Context.
greedyGameAgent = GreedyGameAgent.Builder(this as Context)
.setGameId("66081223")
.addUnitId("float-4343")
.enableAdmob(true)
.withAdListener(this)
.withAgentListener(this)
.build()

showAd.setOnClickListener {
greedyGameAgent?.load()
greedyGameAgent?.init()
}
}

override fun onStart() {
super.onStart()
greedyGameAgent?.let {
if (it.isCampaignAvailable){
nativead.loadAd("float-4343")
}
}

}

override fun onAvailable(campaignId: String) {
Snackbar.make(findViewById(android.R.id.content), "Ad Available", Snackbar.LENGTH_SHORT).show()
//loadAd is an extension function on ImageView
nativead.loadAd("float-4343")
}

override fun onError(message: String) {
Expand All @@ -35,4 +53,15 @@ class MainActivity : AppCompatActivity(), AdListener {
override fun onUnavailable() {
Snackbar.make(findViewById(android.R.id.content), "Ad Unavailable", Snackbar.LENGTH_SHORT).show()
}

fun ImageView.loadAd(unitId:String){
val adPath = greedyGameAgent?.getPath(unitId)?:""
if(adPath.isNotEmpty()){
val bitmap = BitmapFactory.decodeFile(adPath)
this.setImageBitmap(bitmap)
this.setOnClickListener {
greedyGameAgent?.showUII(unitId)
}
}
}
}
5 changes: 2 additions & 3 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@
android:background="@color/colorPrimary"
tools:context=".MainActivity">

<com.greedygame.android.adview.NativeAdView
<ImageView
android:id="@+id/nativead"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_marginTop="40dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:unitId="slot-1000"/>
app:layout_constraintTop_toTopOf="parent" />

<android.support.v7.widget.AppCompatButton
android:id="@+id/showAd"
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/res/xml/network_security_config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@
<certificates src="user" />
</trust-anchors>
</debug-overrides>
<base-config cleartextTrafficPermitted="true"/>

</network-security-config>
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ allprojects {
repositories {
google()
jcenter()
maven {
url "https://dl.bintray.com/greedygame/maven"
}
}
}

Expand Down

0 comments on commit 68d307d

Please sign in to comment.