forked from uc-union/union-ads-sdk-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
9f04112
commit 176a11d
Showing
8 changed files
with
258 additions
and
42 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
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 |
---|---|---|
@@ -1,25 +1,53 @@ | ||
<manifest package="com.ucweb.union.ads.sample" | ||
xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<uses-permission android:name="android.permission.INTERNET"/> | ||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> | ||
<uses-permission | ||
android:name="android.permission.WRITE_EXTERNAL_STORAGE" | ||
android:maxSdkVersion="18"/> | ||
|
||
<application | ||
android:name=".UnionAdsSdkSampleApp" | ||
android:allowBackup="false" | ||
android:hardwareAccelerated="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:supportsRtl="true" > | ||
android:supportsRtl="true"> | ||
|
||
<activity android:name=".UnionAdsSdkSampleActivity" | ||
android:label="@string/app_name" > | ||
<activity | ||
android:name=".UnionAdsSdkSampleActivity" | ||
android:label="@string/app_name"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN"/> | ||
<category android:name="android.intent.category.LAUNCHER"/> | ||
</intent-filter> | ||
</activity> | ||
|
||
<!--Include the InterstitialAdActivity configChanges and theme for Facebook Ads SDK. --> | ||
<activity android:name="com.facebook.ads.InterstitialAdActivity" | ||
android:configChanges="keyboardHidden|orientation|screenSize"/> | ||
<activity | ||
android:name="com.facebook.ads.InterstitialAdActivity" | ||
android:configChanges="keyboardHidden|orientation|screenSize"/> | ||
<!--AdColony--> | ||
<activity | ||
android:name="com.jirbo.adcolony.AdColonyOverlay" | ||
android:configChanges="keyboardHidden|orientation|screenSize" | ||
android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen"/> | ||
|
||
<activity | ||
android:name="com.jirbo.adcolony.AdColonyFullscreen" | ||
android:configChanges="keyboardHidden|orientation|screenSize" | ||
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"/> | ||
|
||
<activity | ||
android:name="com.jirbo.adcolony.AdColonyBrowser" | ||
android:configChanges="keyboardHidden|orientation|screenSize" | ||
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"/> | ||
<!--Vungle--> | ||
<activity | ||
android:name="com.vungle.publisher.FullScreenAdActivity" | ||
android:configChanges="keyboardHidden|orientation|screenSize" | ||
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"/> | ||
</application> | ||
|
||
</manifest> |
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
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
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
160 changes: 160 additions & 0 deletions
160
app/src/main/java/com/ucweb/union/ads/sample/VideoFragment.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,160 @@ | ||
package com.ucweb.union.ads.sample; | ||
|
||
import android.os.Bundle; | ||
import android.support.annotation.Nullable; | ||
import android.support.v4.app.Fragment; | ||
import android.view.Gravity; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.Button; | ||
import android.widget.FrameLayout; | ||
import android.widget.LinearLayout; | ||
import android.widget.TextView; | ||
import android.widget.Toast; | ||
|
||
import com.ucweb.union.ads.AdError; | ||
import com.ucweb.union.ads.AdListener; | ||
import com.ucweb.union.ads.AdRequest; | ||
import com.ucweb.union.ads.InterstitialAd; | ||
import com.ucweb.union.ads.UnionAd; | ||
|
||
public class VideoFragment extends Fragment { | ||
private InterstitialAd mInterstitialAd; | ||
private FrameLayout mContentContainer; | ||
private LinearLayout mTopContainer; | ||
private Button mBtnLoad; | ||
private Button mBtnShow; | ||
private TextView mTvStatus; | ||
|
||
/** | ||
* You should use your own **PUB** in production | ||
*/ | ||
private static final String PUB = "ssr@debugvideo"; | ||
|
||
@Override | ||
public void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
|
||
mInterstitialAd = new InterstitialAd(getActivity()); | ||
mInterstitialAd.setAdListener(mAdListener); | ||
|
||
initView(); | ||
initAction(); | ||
} | ||
|
||
private void initView() { | ||
mBtnLoad = new Button(getActivity()); | ||
mBtnLoad.setText(getString(R.string.load)); | ||
|
||
mBtnShow = new Button(getActivity()); | ||
mBtnShow.setText(getString(R.string.show)); | ||
mBtnShow.setEnabled(false); | ||
|
||
mTvStatus = new TextView(getActivity()); | ||
mTvStatus.setGravity(Gravity.CENTER); | ||
|
||
mTopContainer = new LinearLayout(getActivity()); | ||
{ | ||
mTopContainer.setOrientation(LinearLayout.VERTICAL); | ||
mTopContainer.addView(mBtnLoad); | ||
mTopContainer.addView(mBtnShow); | ||
mTopContainer.addView(mTvStatus); | ||
} | ||
} | ||
|
||
private void initAction() { | ||
mBtnLoad.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
mBtnLoad.setEnabled(false); | ||
mBtnShow.setEnabled(false); | ||
mTvStatus.setText(getString(R.string.ad_start_loading)); | ||
|
||
AdRequest request = AdRequest.newBuilder().pub(PUB).build(); | ||
mInterstitialAd.loadAd(request); | ||
} | ||
}); | ||
|
||
mBtnShow.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
mBtnLoad.setEnabled(true); | ||
mBtnShow.setEnabled(false); | ||
|
||
mInterstitialAd.show(); | ||
} | ||
}); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public View onCreateView(LayoutInflater inflater, | ||
ViewGroup container, | ||
Bundle savedInstanceState) { | ||
mContentContainer = new FrameLayout(getActivity()); | ||
mContentContainer.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, | ||
ViewGroup.LayoutParams.MATCH_PARENT)); | ||
|
||
mContentContainer.addView(mTopContainer, | ||
new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, | ||
FrameLayout.LayoutParams.WRAP_CONTENT, | ||
Gravity.TOP)); | ||
|
||
return mContentContainer; | ||
} | ||
|
||
@Override | ||
public void onDestroyView() { | ||
mContentContainer.removeAllViews(); | ||
mContentContainer = null; | ||
super.onDestroyView(); | ||
} | ||
|
||
@Override | ||
public void onDestroy() { | ||
mTopContainer.removeAllViews(); | ||
mTopContainer = null; | ||
mInterstitialAd = null; | ||
super.onDestroy(); | ||
} | ||
|
||
private final AdListener mAdListener = new AdListener() { | ||
@Override | ||
public void onAdLoaded(UnionAd unionAd) { | ||
if (unionAd == mInterstitialAd) { | ||
mBtnShow.setEnabled(true); | ||
mTvStatus.setText(getString(R.string.ad_load_success)); | ||
mBtnShow.setVisibility(View.VISIBLE); | ||
} | ||
} | ||
|
||
@Override | ||
public void onAdClosed(UnionAd unionAd) { | ||
if (unionAd == mInterstitialAd) { | ||
mTvStatus.setText(getString(R.string.ad_closed)); | ||
} | ||
} | ||
|
||
@Override | ||
public void onAdShowed(UnionAd unionAd) { | ||
if (unionAd == mInterstitialAd) { | ||
mTvStatus.setText(getString(R.string.ad_showed)); | ||
} | ||
} | ||
|
||
@Override | ||
public void onAdClicked(UnionAd unionAd) { | ||
if (unionAd == mInterstitialAd) { | ||
Toast.makeText(getActivity(), getString(R.string.ad_clicked), Toast.LENGTH_SHORT).show(); | ||
} | ||
} | ||
|
||
@Override | ||
public void onAdError(UnionAd unionAd, AdError adError) { | ||
if (unionAd == mInterstitialAd) { | ||
mTvStatus.setText(getString(R.string.ad_load_error, adError.getErrorMessage())); | ||
} | ||
} | ||
}; | ||
} |
Oops, something went wrong.