package com.my.app;
import net.daum.adam.publisher.AdInterstitial;
import net.daum.adam.publisher.AdView;
import net.daum.adam.publisher.impl.AdError;
import android.app.NativeActivity;
import android.content.res.Configuration;
import android.graphics.PixelFormat;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.RelativeLayout;
import com.unity3d.player.UnityPlayer;
public class UnityPlayerNativeActivity extends NativeActivity
{
protected UnityPlayer mUnityPlayer; // don't change the name of this variable; referenced from native code
// Adam Plugin field
final String mBannerID = "TestClientId"; // Banner Client ID
final String mInterstitialID = "InterstitialTestClientId"; // Intersitial Client ID
private static final String LOGTAG = "Adam";
private RelativeLayout relativeLayout = null;
private AdView adView = null;
AdInterstitial mAdInterstitial = null;
// UnityPlayer.init() should be called before attaching the view to a layout - it will load the native code.
// UnityPlayer.quit() should be the last thing called - it will unload the native code.
protected void onCreate (Bundle savedInstanceState)
{
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
getWindow().takeSurface(null);
setTheme(android.R.style.Theme_NoTitleBar_Fullscreen);
getWindow().setFormat(PixelFormat.RGB_565);
mUnityPlayer = new UnityPlayer(this);
if (mUnityPlayer.getSettings ().getBoolean ("hide_status_bar", true))
getWindow ().setFlags (WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
int glesMode = mUnityPlayer.getSettings().getInt("gles_mode", 1);
boolean trueColor8888 = false;
mUnityPlayer.init(glesMode, trueColor8888);
View playerView = mUnityPlayer.getView();
//Adam
relativeLayout = new RelativeLayout(this);
initAdam();
initInterstitial();
relativeLayout.addView(adView);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
addContentView(playerView, params);
addContentView(relativeLayout, params);
adView.setLayoutParams(params);
setContentView(playerView);
addContentView(relativeLayout, params);
playerView.requestFocus();
}
public void LoadInterstitial()
{
mAdInterstitial.loadAd();
}
public void initInterstitial()
{
mAdInterstitial = new AdInterstitial(this);
mAdInterstitial.setClientId("8ec8Z0kT14572d5fa2c");
mAdInterstitial.setOnAdLoadedListener(new AdView.OnAdLoadedListener() {
public void OnAdLoaded() {
Log.i("MSGAdam", "광고가 로딩되었습니다.");
}
});
mAdInterstitial.setOnAdFailedListener(new AdView.OnAdFailedListener()
{
public void OnAdFailed(AdError error, String errorMessage) {
Log.i("MSGAdam", errorMessage);
}
});
}
public void initAdam()
{
adView = new AdView(this);
adView.setOnAdClickedListener(new AdView.OnAdClickedListener() {
public void OnAdClicked() {
Log.i(LOGTAG, "광고를 클릭했습니다.");
}
});
adView.setOnAdFailedListener(new AdView.OnAdFailedListener() {
public void OnAdFailed(AdError arg0, String arg1) {
Log.w(LOGTAG, arg1);
}
});
adView.setOnAdLoadedListener(new AdView.OnAdLoadedListener() {
public void OnAdLoaded() {
Log.i(LOGTAG, "광고가 정상적으로 로딩되었습니다.");
}
});
adView.setOnAdWillLoadListener(new AdView.OnAdWillLoadListener() {
public void OnAdWillLoad(String arg1) {
Log.i(LOGTAG, "광고를 불러옵니다. : " + arg1);
}
});
adView.setOnAdClosedListener(new AdView.OnAdClosedListener() {
public void OnAdClosed() {
Log.i(LOGTAG, "광고를 닫았습니다.");
}
});
adView.setClientId(mBannerID);
adView.setRequestInterval(30); // default 60 , 배너 갱신 간격
adView.setAnimationType(AdView.AnimationType.NONE);
adView.setVisibility(0);
}
protected void onDestroy ()
{
mUnityPlayer.quit();
super.onDestroy();
}
// onPause()/onResume() must be sent to UnityPlayer to enable pause and resource recreation on resume.
protected void onPause()
{
super.onPause();
mUnityPlayer.pause();
}
protected void onResume()
{
super.onResume();
mUnityPlayer.resume();
}
public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
mUnityPlayer.configurationChanged(newConfig);
}
public void onWindowFocusChanged(boolean hasFocus)
{
super.onWindowFocusChanged(hasFocus);
mUnityPlayer.windowFocusChanged(hasFocus);
}
public boolean dispatchKeyEvent(KeyEvent event)
{
if (event.getAction() == KeyEvent.ACTION_MULTIPLE)
return mUnityPlayer.onKeyMultiple(event.getKeyCode(), event.getRepeatCount(), event);
return super.dispatchKeyEvent(event);
}
}
2014년 4월 24일 목요일
Posted by ColaLib on 오후 8:24 with No comments
Categories: Java
피드 구독하기:
댓글 (Atom)
0 개의 댓글:
댓글 쓰기