Instantly share code, notes, and snippets.
Last active
September 13, 2018 18:37
-
Star
0
(0)
You must be signed in to star a gist -
Fork
0
(0)
You must be signed in to fork a gist
-
Save mjonesjr90/d8aa9e9fc14761084bb3ffe4f50e4e8f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
package com.reactlibrary; | |
import android.content.Intent; | |
import android.os.Bundle; | |
import android.support.v7.app.AppCompatActivity; | |
import android.util.Log; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import android.widget.LinearLayout; | |
import android.widget.LinearLayout.LayoutParams; | |
import android.widget.Toast; | |
import android.R; | |
import com.millennialmedia.AppInfo; | |
import com.millennialmedia.InlineAd; | |
import com.millennialmedia.MMException; | |
import com.millennialmedia.MMSDK; | |
public class BannerActivity extends AppCompatActivity { | |
private static final String TAG = "BannerActivity"; | |
private static String PLACEMENT_ID = "[YOUR_PLACEMENT_ID]"; | |
private InlineAd inlineAd; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
LinearLayout layout = new LinearLayout(this); | |
LinearLayout.LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); | |
layout.setLayoutParams(params); | |
layout.setOrientation(LinearLayout.HORIZONTAL); | |
layout.setId(7); | |
setContentView(layout); | |
final View adContainer = findViewById(7); | |
try { | |
inlineAd = InlineAd.createInstance(PLACEMENT_ID, (ViewGroup) adContainer); | |
inlineAd.setListener(new InlineAd.InlineListener() { | |
@Override | |
public void onRequestSucceeded(InlineAd inlineAd) { | |
runOnUiThread(new Runnable() { | |
@Override | |
public void run() { | |
adContainer.setVisibility(View.VISIBLE); | |
} | |
}); | |
Log.i(TAG, "Inline Ad loaded."); | |
} | |
@Override | |
public void onRequestFailed(InlineAd inlineAd, final InlineAd.InlineErrorStatus errorStatus) { | |
runOnUiThread(new Runnable() { | |
@Override | |
public void run() { | |
Toast.makeText(BannerActivity.this, "Request Failed Called: " + errorStatus.toString(), Toast.LENGTH_LONG).show(); | |
} | |
}); | |
Log.i(TAG, errorStatus.toString()); | |
finish(); | |
} | |
@Override | |
public void onClicked(InlineAd inlineAd) { | |
Log.i(TAG, "Inline Ad clicked."); | |
} | |
@Override | |
public void onResize(InlineAd inlineAd, int width, int height) { | |
Log.i(TAG, "Inline Ad starting resize."); | |
} | |
@Override | |
public void onResized(InlineAd inlineAd, int width, int height, boolean toOriginalSize) { | |
Log.i(TAG, "Inline Ad resized."); | |
} | |
@Override | |
public void onExpanded(InlineAd inlineAd) { | |
Log.i(TAG, "Inline Ad expanded."); | |
} | |
@Override | |
public void onCollapsed(InlineAd inlineAd) { | |
Log.i(TAG, "Inline Ad collapsed."); | |
} | |
@Override | |
public void onAdLeftApplication(InlineAd inlineAd) { | |
Log.i(TAG, "Inline Ad left application."); | |
} | |
}); | |
requestAd(); | |
} catch (MMException e) { | |
Log.e(TAG, "Error creating inline ad", e); | |
// abort loading ad | |
} | |
} | |
private void requestAd(){ | |
if (inlineAd != null) { | |
// set a refresh rate of 30 seconds that will be applied after the first request | |
inlineAd.setRefreshInterval(30000); | |
// The InlineAdMetadata instance is used to pass additional metadata to the server to | |
// improve ad selection | |
final InlineAd.InlineAdMetadata inlineAdMetadata = new InlineAd.InlineAdMetadata(). | |
setAdSize(InlineAd.AdSize.BANNER); | |
inlineAd.request(inlineAdMetadata); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment