This repository has been archived by the owner on Oct 15, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 267
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
735 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.gradle | ||
/local.properties | ||
/.idea/workspace.xml | ||
/.idea/libraries | ||
.DS_Store | ||
/build | ||
/captures |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 25 | ||
buildToolsVersion "25.0.2" | ||
|
||
defaultConfig { | ||
applicationId "com.google.ads.rewardedvideoexample" | ||
minSdkVersion 14 | ||
targetSdkVersion 25 | ||
versionCode 1 | ||
versionName "1.0" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
compile 'com.android.support:appcompat-v7:25.2.0' | ||
compile 'com.google.firebase:firebase-ads:10.2.0' | ||
} | ||
|
||
apply plugin: 'com.google.gms.google-services' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
{ | ||
"project_info": { | ||
"project_id": "this-is-a-sample", | ||
"project_number": "999999999999", | ||
"name": "AdMob Samples", | ||
"firebase_url": "https://this-is-a-sample-do-not-use.firebaseio.com", | ||
"storage_bucket": "this-is-a-sample-do-not-use.storage.firebase.com" | ||
}, | ||
"client": [ | ||
{ | ||
"client_info": { | ||
"mobilesdk_app_id": "1:999999999999:android:0000000000000000", | ||
"client_id": "android:com.google.ads.rewardedvideoexample", | ||
"client_type": 1, | ||
"android_client_info": { | ||
"package_name": "com.google.ads.rewardedvideoexample", | ||
"certificate_hash": [] | ||
} | ||
}, | ||
"oauth_client": [ | ||
{ | ||
"client_id": "this-is-a-sample-do-not-use.apps.googleusercontent.com", | ||
"client_type": 1, | ||
"android_info": { | ||
"package_name": "com.google.ads.rewardedvideoexample", | ||
"certificate_hash": "0000000000000000000000000000000000000000" | ||
} | ||
}, | ||
{ | ||
"client_id": "this-is-a-sample-do-not-use.apps.googleusercontent.com", | ||
"client_type": 3 | ||
} | ||
], | ||
"api_key": [ | ||
{ | ||
"current_key": "000000000000000000000000000000000000000" | ||
} | ||
], | ||
"services": { | ||
"analytics_service": { | ||
"status": 1 | ||
}, | ||
"cloud_messaging_service": { | ||
"status": 2, | ||
"apns_config": [] | ||
}, | ||
"appinvite_service": { | ||
"status": 2, | ||
"other_platform_oauth_client": [] | ||
}, | ||
"google_signin_service": { | ||
"status": 2 | ||
}, | ||
"ads_service": { | ||
"status": 2, | ||
"test_banner_ad_unit_id": "ca-app-pub-3940256099942544/6300978111", | ||
"test_interstitial_ad_unit_id": "ca-app-pub-3940256099942544/1033173712" | ||
} | ||
} | ||
} | ||
], | ||
"client_info": [], | ||
"ARTIFACT_VERSION": "1" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Add project specific ProGuard rules here. | ||
# By default, the flags in this file are appended to flags specified | ||
# in ${ANDROID_SDK_HOME}/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 *; | ||
#} |
35 changes: 35 additions & 0 deletions
35
admob/RewardedVideoExample/app/src/main/AndroidManifest.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.google.ads.rewardedvideoexample"> | ||
|
||
<uses-permission android:name="android.permission.INTERNET" /> | ||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:theme="@style/AppTheme"> | ||
|
||
<meta-data | ||
android:name="com.google.android.gms.version" | ||
android:value="@integer/google_play_services_version" /> | ||
|
||
<activity | ||
android:name=".MainActivity" | ||
android:configChanges="orientation|screenSize" | ||
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="com.google.android.gms.ads.AdActivity" | ||
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" | ||
android:theme="@android:style/Theme.Translucent" /> | ||
</application> | ||
|
||
</manifest> |
198 changes: 198 additions & 0 deletions
198
...ardedVideoExample/app/src/main/java/com/google/ads/rewardedvideoexample/MainActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,198 @@ | ||
package com.google.ads.rewardedvideoexample; | ||
|
||
import android.app.Activity; | ||
import android.os.Bundle; | ||
import android.os.CountDownTimer; | ||
import android.view.View; | ||
import android.widget.Button; | ||
import android.widget.TextView; | ||
import android.widget.Toast; | ||
|
||
import com.google.android.gms.ads.AdRequest; | ||
import com.google.android.gms.ads.MobileAds; | ||
import com.google.android.gms.ads.reward.RewardItem; | ||
import com.google.android.gms.ads.reward.RewardedVideoAd; | ||
import com.google.android.gms.ads.reward.RewardedVideoAdListener; | ||
|
||
/** | ||
* Main Activity. Inflates main activity xml and implements RewardedVideoAdListener. | ||
*/ | ||
public class MainActivity extends Activity implements RewardedVideoAdListener { | ||
private static final String AD_UNIT_ID = "ca-app-pub-3940256099942544/5224354917"; | ||
private static final String APP_ID = "ca-app-pub-3940256099942544~3347511713"; | ||
private static final long COUNTER_TIME = 10; | ||
private static final int GAME_OVER_REWARD = 1; | ||
|
||
private int mCoinCount; | ||
private TextView mCoinCountText; | ||
private CountDownTimer mCountDownTimer; | ||
private boolean mGameOver; | ||
private boolean mGamePaused; | ||
private RewardedVideoAd mRewardedVideoAd; | ||
private Button mRetryButton; | ||
private Button mShowVideoButton; | ||
private long mTimeRemaining; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
|
||
// Initialize the Mobile Ads SDK. | ||
MobileAds.initialize(this, APP_ID); | ||
|
||
mRewardedVideoAd = MobileAds.getRewardedVideoAdInstance(this); | ||
mRewardedVideoAd.setRewardedVideoAdListener(this); | ||
loadRewardedVideoAd(); | ||
|
||
// Create the "retry" button, which tries to show an interstitial between game plays. | ||
mRetryButton = ((Button) findViewById(R.id.retry_button)); | ||
mRetryButton.setVisibility(View.INVISIBLE); | ||
mRetryButton.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View view) { | ||
startGame(); | ||
} | ||
}); | ||
|
||
// Create the "show" button, which shows a rewarded video if one is loaded. | ||
mShowVideoButton = ((Button) findViewById(R.id.watch_video)); | ||
mShowVideoButton.setVisibility(View.INVISIBLE); | ||
mShowVideoButton.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View view) { | ||
showRewardedVideo(); | ||
} | ||
}); | ||
|
||
// Display current coin count to user. | ||
mCoinCountText = ((TextView) findViewById(R.id.coin_count_text)); | ||
mCoinCount = 0; | ||
mCoinCountText.setText("Coins: " + mCoinCount); | ||
|
||
startGame(); | ||
} | ||
|
||
@Override | ||
public void onPause() { | ||
super.onPause(); | ||
pauseGame(); | ||
mRewardedVideoAd.pause(this); | ||
} | ||
|
||
@Override | ||
public void onResume() { | ||
super.onResume(); | ||
if (!mGameOver && mGamePaused) { | ||
resumeGame(); | ||
} | ||
mRewardedVideoAd.resume(this); | ||
} | ||
|
||
private void pauseGame() { | ||
mCountDownTimer.cancel(); | ||
mGamePaused = true; | ||
} | ||
|
||
private void resumeGame() { | ||
createTimer(mTimeRemaining); | ||
mGamePaused = false; | ||
} | ||
|
||
private void loadRewardedVideoAd() { | ||
if (!mRewardedVideoAd.isLoaded()) { | ||
mRewardedVideoAd.loadAd(AD_UNIT_ID, new AdRequest.Builder().build()); | ||
} | ||
} | ||
|
||
private void addCoins(int coins) { | ||
mCoinCount = mCoinCount + coins; | ||
mCoinCountText.setText("Coins: " + mCoinCount); | ||
} | ||
|
||
private void startGame() { | ||
// Hide the retry button, load the ad, and start the timer. | ||
mRetryButton.setVisibility(View.INVISIBLE); | ||
mShowVideoButton.setVisibility(View.INVISIBLE); | ||
loadRewardedVideoAd(); | ||
createTimer(COUNTER_TIME); | ||
mGamePaused = false; | ||
mGameOver = false; | ||
} | ||
|
||
// Create the game timer, which counts down to the end of the level | ||
// and shows the "retry" button. | ||
private void createTimer(long time) { | ||
final TextView textView = ((TextView) findViewById(R.id.timer)); | ||
if (mCountDownTimer != null) { | ||
mCountDownTimer.cancel(); | ||
} | ||
mCountDownTimer = new CountDownTimer(time * 1000, 50) { | ||
@Override | ||
public void onTick(long millisUnitFinished) { | ||
mTimeRemaining = ((millisUnitFinished / 1000) + 1); | ||
textView.setText("seconds remaining: " + mTimeRemaining); | ||
} | ||
|
||
@Override | ||
public void onFinish() { | ||
if (mRewardedVideoAd.isLoaded()) { | ||
mShowVideoButton.setVisibility(View.VISIBLE); | ||
} | ||
textView.setText("You Lose!"); | ||
addCoins(GAME_OVER_REWARD); | ||
mRetryButton.setVisibility(View.VISIBLE); | ||
mGameOver = true; | ||
} | ||
}; | ||
mCountDownTimer.start(); | ||
} | ||
|
||
private void showRewardedVideo() { | ||
mShowVideoButton.setVisibility(View.INVISIBLE); | ||
if (mRewardedVideoAd.isLoaded()) { | ||
mRewardedVideoAd.show(); | ||
} | ||
} | ||
|
||
@Override | ||
public void onRewardedVideoAdLeftApplication() { | ||
Toast.makeText(this, "onRewardedVideoAdLeftApplication", Toast.LENGTH_SHORT).show(); | ||
} | ||
|
||
@Override | ||
public void onRewardedVideoAdClosed() { | ||
Toast.makeText(this, "onRewardedVideoAdClosed", Toast.LENGTH_SHORT).show(); | ||
// Preload the next video ad. | ||
loadRewardedVideoAd(); | ||
} | ||
|
||
@Override | ||
public void onRewardedVideoAdFailedToLoad(int errorCode) { | ||
Toast.makeText(this, "onRewardedVideoAdFailedToLoad", Toast.LENGTH_SHORT).show(); | ||
} | ||
|
||
@Override | ||
public void onRewardedVideoAdLoaded() { | ||
Toast.makeText(this, "onRewardedVideoAdLoaded", Toast.LENGTH_SHORT).show(); | ||
} | ||
|
||
@Override | ||
public void onRewardedVideoAdOpened() { | ||
Toast.makeText(this, "onRewardedVideoAdOpened", Toast.LENGTH_SHORT).show(); | ||
} | ||
|
||
@Override | ||
public void onRewarded(RewardItem reward) { | ||
Toast.makeText(this, | ||
String.format(" onRewarded! currency: %s amount: %d", reward.getType(), | ||
reward.getAmount()), | ||
Toast.LENGTH_SHORT).show(); | ||
addCoins(reward.getAmount()); | ||
} | ||
|
||
@Override | ||
public void onRewardedVideoStarted() { | ||
Toast.makeText(this, "onRewardedVideoStarted", Toast.LENGTH_SHORT).show(); | ||
} | ||
} |
Oops, something went wrong.