Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ build/
*.apk
*.aar
*.zip
google-services.json
*/google-services.json
11 changes: 11 additions & 0 deletions admob/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

check.dependsOn 'assembleDebugAndroidTest'

android {
Expand All @@ -22,6 +25,10 @@ android {
}
}

sourceSets{
main.java.srcDirs += 'src/main/kotlin'
}

packagingOptions {
exclude 'LICENSE.txt'
}
Expand All @@ -41,6 +48,10 @@ dependencies {

androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
androidTestCompile 'com.android.support.test:runner:0.5'
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
}

apply plugin: 'com.google.gms.google-services'
repositories {
mavenCentral()
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class InterstitialAdTest {
private AdViewIdlingResource mAdResource;

@Rule
public ActivityTestRule<MainActivity> mActivityTestRule = new ActivityTestRule<>(MainActivity.class);
public ActivityTestRule<MainActivityKt> mActivityTestRule = new ActivityTestRule<>(MainActivityKt.class);

@Before
public void setUp() {
Expand Down
6 changes: 3 additions & 3 deletions admob/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:name=".MainActivityKt"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand All @@ -34,10 +34,10 @@
<activity
android:name=".SecondActivity"
android:label="@string/second_activity_title"
android:parentActivityName=".MainActivity" >
android:parentActivityName=".MainActivityKt" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
android:value=".MainActivityKt" />
</activity>
</application>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

public class MainActivity extends AppCompatActivity {

private static final String TAG = "MainActivity";
private static final String TAG = "MainActivityKt";

private AdView mAdView;
// [START_EXCLUDE]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package com.google.samples.quickstart.admobexample

import android.content.Intent
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.util.Log
import com.google.android.gms.ads.AdListener
import com.google.android.gms.ads.AdRequest
import com.google.android.gms.ads.AdView
import com.google.android.gms.ads.InterstitialAd

/**
* Created by soul on 2017. 7. 23..
*/
class MainActivityKt : AppCompatActivity() {

private val TAG : String = "MainActivityKt"

private val mAdView by lazy {
findViewById(R.id.adView) as AdView
}

private val mInterstitialAd by lazy {
InterstitialAd(this)
}

private val mLoadInterstitialButton by lazy {
findViewById(R.id.load_interstitial_button)
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

var adRequest: AdRequest = AdRequest.Builder().build()
mAdView.loadAd(adRequest)

mInterstitialAd.adUnitId = getString(R.string.interstitial_ad_unit_id)

mInterstitialAd.adListener = object : AdListener(){
override fun onAdClosed() {
requestNewInterstitial()
beginSecondActivity()
}

override fun onAdLoaded() {
if(mLoadInterstitialButton != null){
mLoadInterstitialButton.isEnabled = true
}
}

override fun onAdFailedToLoad(i: Int) {
Log.w(TAG, "onAdFailedToLoad:"+i)
}
}

// [END create_interstitial_ad_listener]

// [START display_interstitial_ad]
mLoadInterstitialButton.setOnClickListener {
if(mInterstitialAd.isLoaded){
mInterstitialAd.show()
}else{
beginSecondActivity()
}
}
// [END display_interstitial_ad]

// Disable button if an interstitial ad is not loaded yet.
mLoadInterstitialButton.isEnabled = mInterstitialAd.isLoaded

}

private fun requestNewInterstitial() {
var adRequest = AdRequest.Builder().build()
mInterstitialAd.loadAd(adRequest)
}

private fun beginSecondActivity() {
var intent :Intent = Intent(this, SecondActivity::class.java)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

anko 쓰면 엄청 편해집니다 ㅎㅎ
https://github.com/Kotlin/anko/wiki/Anko-Commons-%E2%80%93-Intents

startActivity(intent)
}

override fun onPause() {
if(mAdView != null){
mAdView.destroy()
}
super.onPause()
}

override fun onResume() {
super.onResume()
if(mAdView != null){
mAdView.resume()
}
if(!mInterstitialAd.isLoaded){
requestNewInterstitial()
}
}

override fun onDestroy() {
if(mAdView != null){
mAdView.destroy()
}
super.onDestroy()
}

fun getAdView() : AdView{
return mAdView
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.google.samples.quickstart.admobexample

import android.os.Bundle
import android.support.v7.app.AppCompatActivity

/**
* Created by soul on 2017. 7. 23..
*/
class SecondActivityKt : AppCompatActivity(){

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.second_activity)
}
}
2 changes: 1 addition & 1 deletion admob/app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Define the namespace and AdView layout that will show the banner.
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
tools:context=".MainActivityKt">

<ImageView
android:layout_width="wrap_content"
Expand Down
1 change: 0 additions & 1 deletion admob/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.google.gms:google-services:3.1.0'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Expand Down
15 changes: 13 additions & 2 deletions analytics/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
check.dependsOn 'assembleDebugAndroidTest'

android {
Expand All @@ -20,6 +22,10 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
}

configurations.all {
Expand All @@ -28,13 +34,18 @@ configurations.all {

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])


compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:support-v4:25.3.1'

compile 'com.google.firebase:firebase-analytics:11.0.1'

compile 'com.android.support.constraint:constraint-layout:1.0.2'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
androidTestCompile 'com.android.support.test:runner:0.5'
}

apply plugin: 'com.google.gms.google-services'
repositories {
mavenCentral()
}
11 changes: 6 additions & 5 deletions analytics/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.firebase.quickstart.analytics">
package="com.google.firebase.quickstart.analytics">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity
android:name="com.google.firebase.quickstart.analytics.MainActivity"
android:name=".MainActivityKt"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER"/>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,4 @@ public ImageInfo(int image, int title, int id) {
this.title = title;
this.id = id;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.google.firebase.quickstart.analytics

import android.os.Bundle
import android.support.v4.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView

/**
* Created by soul on 2017. 7. 23..
*/
class ImageFragmentKt : Fragment() {

var resId : Int = 0

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
if(arguments != null){
resId = arguments.getInt(ARG_PATTERN)
}
}

override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? {
var view :View = inflater!!.inflate(R.layout.fragment_main, null)
var imageView = view.findViewById(R.id.imageView) as ImageView
imageView.setImageResource(resId)

return view;
}

companion object {
private val ARG_PATTERN : String = "pattern"

fun newInstance(resId:Int) : ImageFragmentKt{
var fragment : ImageFragmentKt = ImageFragmentKt()
var args:Bundle = Bundle()
args.putInt(ARG_PATTERN, resId)
fragment.arguments = args
return fragment
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.google.firebase.quickstart.analytics

/**
* Created by soul on 2017. 7. 23..
*/
data class ImageInfoKt(
val image : Int,
val title : Int,
val id : Int
)
Loading