Android Open Source - snakk-ads-android-sample-app Snakk Ad Activity






From Project

Back to project page snakk-ads-android-sample-app.

License

The source code is released under:

Copyright (c) 2012, Snakk! Media Group All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are m...

If you think the Android project snakk-ads-android-sample-app listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.snakk.advertising.internal;
/*from   w  w  w. ja va 2 s.co m*/
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.*;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;

public class SnakkAdActivity extends Activity {
    private static final String TAG = "Snakk";
    public static final String CONTENT_WRAPPER_EXTRA = "AdActivityContentWrapper";

    private InterstitialBaseView contentView = null;
    private AdActivityContentWrapper adActivityContentWrapper = null;
    private boolean isContentStarted = false;

    /**
     * Convenience method for firing off the SnakkAdActivity
     * @param context the calling context
     * @param wrapper the wrapper used to pass data to the activity
     */
    public static void startActivity(Context context, AdActivityContentWrapper wrapper) {
        startActivity(context, wrapper, null);
    }

    /**
     * Convenience method for firing off the SnakkAdActivity
     * @param context the calling context
     * @param wrapper the wrapper used to pass data to the activity
     */
    public static void startActivity(Context context, AdActivityContentWrapper wrapper,
                                     Bundle extras) {
        Intent i = new Intent(context, SnakkAdActivity.class);
        if (extras != null) {
            i.putExtras(extras);
        }
        Parcelable wrapperSharable = new Sharable<AdActivityContentWrapper>(
                wrapper, SnakkAdActivity.CONTENT_WRAPPER_EXTRA);
        i.putExtra(SnakkAdActivity.CONTENT_WRAPPER_EXTRA, wrapperSharable);
        context.startActivity(i);
    }

    /**
     * Used to programmatically close SnakkAdActivity... example usage includes a close
     * button, or when a video ad finishes playing.
     */
    public void close() {
        adActivityContentWrapper.stopContent();
        finish();
        adActivityContentWrapper.done();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
//        SnakkLog.d(TAG, "onCreate");
        super.onCreate(savedInstanceState);

        // defaults, override in AdActivityContentWrapper.getContentView(...)
        getWindow().requestFeature(Window.FEATURE_PROGRESS);
        getWindow().requestFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFeatureInt(Window.FEATURE_PROGRESS, Window.PROGRESS_VISIBILITY_ON);

        Bundle extras = getIntent().getExtras();
        Sharable<AdActivityContentWrapper> wrapperSharable = extras.getParcelable(CONTENT_WRAPPER_EXTRA);
        adActivityContentWrapper = wrapperSharable.obj();

        contentView = new InterstitialBaseView(this);
        contentView.setCloseButtonOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (adActivityContentWrapper.shouldClose()) {
                    close();
                }
            }
        });

        View wrapperView = adActivityContentWrapper.getContentView(this);
        ViewGroup.LayoutParams lp = adActivityContentWrapper.getContentLayoutParams();
        contentView.addView(wrapperView, lp);

        setContentView(contentView);
    }

    public void setCloseButtonVisible(boolean isVisible) {
        contentView.setCloseButtonVisible(isVisible);
    }

    @Override
    public void onBackPressed() {
        // don't call super, we'll handle in close(), if allowed
//        SnakkLog.d(TAG, "SnakkAdActivity.onBackPressed");
//        Log.d(TAG, "SnakkAdActivity.onBackPressed");
        if (adActivityContentWrapper.shouldClose()) {
            close();
        }
    }

    @Override
    public void onDetachedFromWindow() {
        super.onDetachedFromWindow();
//        SnakkLog.d(TAG, "onDetachedFromWindow");
    }

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
        if (hasFocus && !isContentStarted) {
            adActivityContentWrapper.startContent();
            isContentStarted = true;
        }
    }

    //TODO handle optional closing of this activity when user multitasks?
//    @Override
//    protected void onPause() {
//        super.onPause();
//        SnakkLog.d(TAG, "onPause");
//    }

    public void enableSystemUIAutoDimming() {
        if (Build.VERSION.SDK_INT >= 11) {
            // dim the lights on newer devices
            final Handler handler = new Handler(Looper.getMainLooper());
            final Runnable dimmingRunnable = new Runnable(){
                @Override
                public void run() {
//                    Log.d("SendDROID", "dimming");
                    SnakkAdActivity.this.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
                }
            };
            handler.post(dimmingRunnable);
            // re-dim a short time after user interacts w/ system UI
            getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
                @Override
                public void onSystemUiVisibilityChange(int visibility) {
//                    Log.d("SendDROID", "will dim in a moment...");
                    if (visibility == View.SYSTEM_UI_FLAG_VISIBLE) {
                        handler.postDelayed(dimmingRunnable, 2000);
                    }
                }
            });
        }
    }

    /**
     * if ad interaction causes external activity to be loaded (such as google play),
     * this is called after that activity completes... (e.g. user hits back).
     *
     * automatically close this SnakkAdActivity, returning control back to the
     * underlying app
     */
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
//        Log.d(TAG, "onActivityResult(" + requestCode + ", " + resultCode + ", " + data + ")");
        close();
    }
}




Java Source Code List

com.snakk.advertising.Config.java
com.snakk.advertising.SnakkAdPrompt.java
com.snakk.advertising.SnakkAdRequest.java
com.snakk.advertising.SnakkAdvertising.java
com.snakk.advertising.SnakkBannerAdView.java
com.snakk.advertising.SnakkInterstitialAd.java
com.snakk.advertising.SnakkVideoInterstitialAd.java
com.snakk.advertising.internal.AbstractStatefulAd.java
com.snakk.advertising.internal.AdActivityContentWrapper.java
com.snakk.advertising.internal.AdPromptImpl.java
com.snakk.advertising.internal.AdRequestImpl.java
com.snakk.advertising.internal.BasicWebView.java
com.snakk.advertising.internal.DeviceCapabilities.java
com.snakk.advertising.internal.InterstitialAdImpl.java
com.snakk.advertising.internal.InterstitialBaseView.java
com.snakk.advertising.internal.Sharable.java
com.snakk.advertising.internal.SnakkAdActivity.java
com.snakk.advertising.internal.VastPlayerView.java
com.snakk.advertising.internal.VideoInterstitialAdImpl.java
com.snakk.advertising.package-info.java
com.snakk.adview.AdFullscreenView.java
com.snakk.adview.AdInterstitialBaseView.java
com.snakk.adview.AdInterstitialView.java
com.snakk.adview.AdLog.java
com.snakk.adview.AdOfferWallView.java
com.snakk.adview.AdPrompt.java
com.snakk.adview.AdRequest.java
com.snakk.adview.AdVideoUnitView.java
com.snakk.adview.AdViewCore.java
com.snakk.adview.AdView.java
com.snakk.adview.AutoDetectedParametersSet.java
com.snakk.adview.Base64.java
com.snakk.adview.DeprecatedInterstitialBaseView.java
com.snakk.adview.IMraidCommand.java
com.snakk.adview.LockedOrientationDialog.java
com.snakk.adview.MraidCommand.java
com.snakk.adview.Mraid.java
com.snakk.adview.OldAdActivity.java
com.snakk.adview.Rotate3dAnimation.java
com.snakk.adview.Utils.java
com.snakk.adview.track.EventTracker.java
com.snakk.adview.track.InstallTracker.java
com.snakk.adview.package-info.java
com.snakk.core.SnakkLog.java
com.snakk.vastsdk.TVASTAdErrorEvent.java
com.snakk.vastsdk.TVASTAdErrorListener.java
com.snakk.vastsdk.TVASTAdError.java
com.snakk.vastsdk.TVASTAdType.java
com.snakk.vastsdk.TVASTAdView.java
com.snakk.vastsdk.TVASTAd.java
com.snakk.vastsdk.TVASTAdsLoader.java
com.snakk.vastsdk.TVASTAdsRequest.java
com.snakk.vastsdk.TVASTCompanionAdSlot.java
com.snakk.vastsdk.TVASTCompanionAd.java
com.snakk.vastsdk.TVASTCreative.java
com.snakk.vastsdk.TVASTLinearAd.java
com.snakk.vastsdk.TVASTLinearIcon.java
com.snakk.vastsdk.TVASTMediaFile.java
com.snakk.vastsdk.TVASTNonlinearAd.java
com.snakk.vastsdk.TVASTPostbackTask.java
com.snakk.vastsdk.TVASTUtils.java
com.snakk.vastsdk.TVASTVideoAdsManager.java
com.snakk.vastsdk.player.TVASTPlayer.java
com.snakk.vastsdk.player.TVASTSharable.java
com.snakk.vastsdk.player.TVASTTrackingVideoView.java
com.snakk.vastsdk.player.TVASTVideoProgressThread.java
com.snakkads.tabsswipe.BannerAdPromptFragment.java
com.snakkads.tabsswipe.BannerInterstitialFragment.java
com.snakkads.tabsswipe.BannerRichMediaFragment.java
com.snakkads.tabsswipe.BannerStandardMediaFragment.java
com.snakkads.tabsswipe.BannerVideoFragment.java
com.snakkads.tabsswipe.MainActivity.java
com.snakkads.tabsswipe.SplashScreen.java
com.snakkads.tabsswipe.adapter.TabsPagerAdapter.java
com.yourcompany.AdMobActivity.java
com.yourcompany.SampleActivity.java