コード例 #1
0
 /**
  * Dismisses an interstitial ad This method dismisses an interstitial ad and only if it is
  * currently presented.
  *
  * <p>After it interstitial ad requires "loading process" to be ready for displaying
  *
  * <p>As a result you'll receive onLoopMeInterstitialHide() notification
  */
 public void dismiss() {
   if (mAdState == AdState.SHOWING) {
     Logging.out(LOG_TAG, "Dismiss ad");
     broadcastDestroyIntent();
     stopExpirationTimer();
     if (mHandler != null) {
       mHandler.removeCallbacksAndMessages(null);
     }
   } else {
     Logging.out(LOG_TAG, "Can't dismiss ad, it's not displaying");
   }
 }
コード例 #2
0
  private void handleVideoMute(boolean mute) {
    Logging.out(LOG_TAG, "JS command: video mute " + mute, LogLevel.DEBUG);

    if (mVideoController != null) {
      mVideoController.muteVideo(mute);
    }
  }
コード例 #3
0
  void switchToNormalMode() {
    if (mDisplayMode == DisplayMode.NORMAL) {
      return;
    }
    if (mDisplayMode == DisplayMode.FULLSCREEN) {
      handleFullscreenMode(false);
    }
    Logging.out(LOG_TAG, "switchToNormalMode", LogLevel.DEBUG);
    mDisplayMode = DisplayMode.NORMAL;

    LoopMeBannerView initialView = ((LoopMeBanner) mAd).getBannerView();
    initialView.setVisibility(View.VISIBLE);

    if (mMinimizedView != null && mMinimizedView.getParent() != null) {
      ((ViewGroup) mMinimizedView.getParent()).removeView(mMinimizedView);
      rebuildView(initialView);
      mMinimizedView.removeAllViews();
    }

    mAdView.setOnTouchListener(
        new View.OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {
            return (event.getAction() == MotionEvent.ACTION_MOVE);
          }
        });
  }
コード例 #4
0
 /**
  * Shows insterstitial. Interstitial should be loaded and ready to be shown.
  *
  * <p>As a result you'll receive onLoopMeInterstitialShow() callback
  */
 public void show() {
   Logging.out(LOG_TAG, "Interstitial will present fullscreen ad. App key: " + getAppKey());
   if (isReady()) {
     if (mAdState != AdState.SHOWING) {
       mAdState = AdState.SHOWING;
       stopExpirationTimer();
       startAdActivity();
     } else {
       Logging.out(LOG_TAG, "Interstitial is already presented on the screen");
     }
   } else {
     mShowWhenAdNotReadyCounter++;
     Logging.out(
         LOG_TAG, "Interstitial is not ready (" + mShowWhenAdNotReadyCounter + " time(s))");
   }
 }
コード例 #5
0
  private void handleVideoLoad(String videoUrl) {
    Logging.out(LOG_TAG, "JS command: load video " + videoUrl, LogLevel.DEBUG);

    mIsVideoPresented = true;
    if (mVideoController != null) {
      mVideoController.loadVideoFile(videoUrl, mAd.getContext());
    }
  }
コード例 #6
0
 /**
  * Getting already initialized ad object or create new one with specified appKey Note: Returns
  * null if Android version under 4.0
  *
  * @param appKey - your app key
  * @param context - application context
  */
 public static LoopMeInterstitial getInstance(String appKey, Context context) {
   if (Build.VERSION.SDK_INT >= 14) {
     return LoopMeAdHolder.getInterstitial(appKey, context);
   } else {
     Logging.out(LOG_TAG, "Not supported Android version. Expected Android 4.0+");
     return null;
   }
 }
コード例 #7
0
 void preloadHtml(String html) {
   if (mAdView != null) {
     Logging.out(LOG_TAG, "loadDataWithBaseURL", LogLevel.DEBUG);
     mAdView.loadDataWithBaseURL(null, html, "text/html", "UTF-8", null);
   } else {
     mAd.onAdLoadFail(new LoopMeError("Html loading error"));
   }
 }
コード例 #8
0
  private void switchToFullScreenMode() {
    if (mDisplayMode != DisplayMode.FULLSCREEN) {
      Logging.out(LOG_TAG, "switch to fullscreen mode", LogLevel.DEBUG);
      mDisplayMode = DisplayMode.FULLSCREEN;

      startAdActivity();
    }
  }
コード例 #9
0
  /**
   * Creates new `LoopMeInterstitial` object with the given appKey
   *
   * @param context - application context
   * @param appKey - your app key
   * @throws IllegalArgumentException if any of parameters is null
   */
  LoopMeInterstitial(Context context, String appKey) {
    super(context, appKey);
    Logging.out(LOG_TAG, "Start creating interstitial with app key: " + appKey);

    mViewController = new ViewController(this);

    Utils.init(context);
    DebugController.init(context);
  }
コード例 #10
0
 /**
  * Triggered when interstitial ad failed to load ad content
  *
  * @param interstitial - interstitial object - the sender of message
  * @param error - error of unsuccesful ad loading attempt
  */
 void onLoopMeInterstitialLoadFail(LoopMeInterstitial interstitial, final LoopMeError error) {
   Logging.out(LOG_TAG, "Ad fails to load: " + error.getMessage());
   mIsReady = false;
   mAdState = AdState.NONE;
   stopFetcherTimer();
   if (mAdListener != null) {
     mAdListener.onLoopMeInterstitialLoadFail(LoopMeInterstitial.this, error);
   }
 }
コード例 #11
0
 /**
  * Triggered when the interstitial ad disappears on the screen
  *
  * @param interstitial - interstitial object the sender of message
  */
 void onLoopMeInterstitialHide(LoopMeInterstitial interstitial) {
   Logging.out(LOG_TAG, "Ad disappeared from screen");
   mIsReady = false;
   mAdState = AdState.NONE;
   releaseViewController(false);
   if (mAdListener != null) {
     mAdListener.onLoopMeInterstitialHide(this);
   }
 }
コード例 #12
0
 private void handleVideoStretch(boolean b) {
   Logging.out(LOG_TAG, "JS command: stretch video ", LogLevel.DEBUG);
   if (mVideoController != null) {
     if (b) {
       mVideoController.setStreachVideoParameter(VideoController.StretchOption.STRECH);
     } else {
       mVideoController.setStreachVideoParameter(VideoController.StretchOption.NO_STRETCH);
     }
   }
 }
コード例 #13
0
 /**
  * Triggered when the interstitial's loaded ad content is expired. Expiration happens when loaded
  * ad content wasn't displayed during some period of time, approximately one hour. Once the
  * interstitial is presented on the screen, the expiration is no longer tracked and interstitial
  * won't receive this message
  *
  * @param interstitial - interstitial object the sender of message
  */
 void onLoopMeInterstitialExpired(LoopMeInterstitial interstitial) {
   Logging.out(LOG_TAG, "Ads content expired");
   mExpirationTimer = null;
   mIsReady = false;
   mAdState = AdState.NONE;
   releaseViewController(false);
   if (mAdListener != null) {
     mAdListener.onLoopMeInterstitialExpired(this);
   }
 }
コード例 #14
0
  private void handleNonLoopMe(String url) {
    Logging.out(LOG_TAG, "Non Js command", LogLevel.DEBUG);
    Context context = mAd.getContext();
    if (Utils.isOnline(context)) {
      Intent intent = new Intent(context, AdBrowserActivity.class);
      intent.putExtra(EXTRA_URL, url);
      intent.putExtra(StaticParams.APPKEY_TAG, mAd.getAppKey());
      intent.putExtra(StaticParams.FORMAT_TAG, mAd.getAdFormat());
      intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

      mAd.onAdClicked();
      setWebViewState(WebviewState.HIDDEN);
      broadcastAdClickedIntent();

      context.startActivity(intent);
    } else {
      Logging.out(LOG_TAG, "No internet connection", LogLevel.DEBUG);
    }
  }
コード例 #15
0
  private void startAdActivity() {
    Logging.out(LOG_TAG, "Starting Ad Activity");
    LoopMeAdHolder.putAd(this);

    Intent intent = new Intent(getContext(), AdActivity.class);
    intent.putExtra(StaticParams.APPKEY_TAG, getAppKey());
    intent.putExtra(StaticParams.FORMAT_TAG, getAdFormat());
    intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    getContext().startActivity(intent);
  }
コード例 #16
0
  private void handleVideoPlay(final int time) {
    Logging.out(LOG_TAG, "JS command: play video " + time, LogLevel.DEBUG);

    if (mVideoController != null) {
      mVideoController.playVideo(time);
    }

    if (mDisplayMode == DisplayMode.MINIMIZED) {
      Utils.animateAppear(mMinimizedView);
    }
  }
コード例 #17
0
  /**
   * Triggered when the interstitial has successfully loaded the ad content
   *
   * @param interstitial - interstitial object the sender of message
   */
  public void onLoopMeInterstitialLoadSuccess(LoopMeInterstitial interstitial) {
    long currentTime = System.currentTimeMillis();
    long loadingTime = currentTime - mAdLoadingTimer;

    Logging.out(LOG_TAG, "Ad successfully loaded (" + loadingTime + "ms)");
    mIsReady = true;
    mAdState = AdState.NONE;
    stopFetcherTimer();
    if (mAdListener != null) {
      mAdListener.onLoopMeInterstitialLoadSuccess(LoopMeInterstitial.this);
    }
  }
コード例 #18
0
 private void initAppVersion(Context context) {
   if (context == null) {
     mAppVersion = "0.0";
     return;
   }
   try {
     mAppVersion =
         context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
   } catch (NameNotFoundException e) {
     Logging.out(LOG_TAG, "Can't get app version. Exception: " + e.getMessage(), LogLevel.ERROR);
     mAppVersion = "0.0";
   }
 }
コード例 #19
0
  @Override
  public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {

    Logging.out(LOG_TAG, "onSurfaceTextureAvailable", LogLevel.DEBUG);

    int viewWidth = 0;
    int viewHeight = 0;

    switch (mDisplayMode) {
      case DisplayMode.MINIMIZED:
        if (mMinimizedMode != null) {
          viewWidth = mMinimizedMode.getWidth();
          viewHeight = mMinimizedMode.getHeight();
        } else {
          Logging.out(LOG_TAG, "WARNING: MinimizedMode is null", LogLevel.ERROR);
        }
        break;

      case DisplayMode.NORMAL:
        viewWidth = mAd.detectWidth();
        viewHeight = mAd.detectHeight();
        break;

      case DisplayMode.FULLSCREEN:
        viewWidth = Utils.getScreenWidth();
        viewHeight = Utils.getScreenHeight();
        break;

      default:
        Logging.out(LOG_TAG, "Unknown display mode", LogLevel.ERROR);
        break;
    }

    if (mVideoController != null) {
      mVideoController.setSurface(mTextureView);
      mVideoController.resizeVideo(mTextureView, viewWidth, viewHeight);
    }
  }
コード例 #20
0
 void destroy(boolean interruptFile) {
   mBridgeListener = null;
   if (mVideoController != null) {
     mVideoController.destroy(interruptFile);
     mVideoController = null;
   }
   if (mAdView != null) {
     mAdView.stopLoading();
     mAdView.clearCache(true);
     mAdView = null;
     Logging.out(LOG_TAG, "AdView destroyed", LogLevel.DEBUG);
   }
   mMinimizedMode = null;
 }
コード例 #21
0
 public String getViewerToken() {
   String advId = mAdvertisingId;
   if (TextUtils.isEmpty(advId)) {
     mDntPresent = true;
     if (mLoopMeId == null) {
       String loopmeId = Long.toHexString(Double.doubleToLongBits(Math.random()));
       Logging.out(LOG_TAG, "LoopMe Id = " + loopmeId, LogLevel.DEBUG);
       mLoopMeId = loopmeId;
     }
     return mLoopMeId;
   } else {
     return advId;
   }
 }
コード例 #22
0
  void switchToMinimizedMode() {
    if (mDisplayMode == DisplayMode.MINIMIZED) {
      if (getCurrentVideoState() == VideoState.PAUSED) {
        setWebViewState(WebviewState.VISIBLE);
      }
      return;
    }
    Logging.out(LOG_TAG, "switchToMinimizedMode", LogLevel.DEBUG);
    mDisplayMode = DisplayMode.MINIMIZED;

    int width = mMinimizedMode.getWidth();
    int height = mMinimizedMode.getHeight();
    mMinimizedView = new LoopMeBannerView(mAdView.getContext(), width, height);

    rebuildView(mMinimizedView);
    addBordersToView(mMinimizedView);

    if (mAdView.getCurrentWebViewState() == WebviewState.HIDDEN) {
      mMinimizedView.setAlpha(0);
    }

    mMinimizedMode.getRootView().addView(mMinimizedView);
    configMinimizedViewLayoutParams(mMinimizedView);

    setWebViewState(WebviewState.VISIBLE);

    mAdView.setOnTouchListener(
        new SwipeListener(
            width,
            new SwipeListener.Listener() {
              @Override
              public void onSwipe(boolean toRight) {
                mAdView.setWebViewState(WebviewState.HIDDEN);

                Animation anim = AnimationUtils.makeOutAnimation(mAd.getContext(), toRight);
                anim.setDuration(200);
                mMinimizedView.startAnimation(anim);

                switchToNormalMode();
                mMinimizedMode = null;
              }
            }));
  }
コード例 #23
0
 private void handleLoadSuccess() {
   Logging.out(LOG_TAG, "JS command: load success", LogLevel.DEBUG);
   mAd.startExpirationTimer();
   mAd.onAdLoadSuccess();
 }
コード例 #24
0
 @Override
 public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
   Logging.out(LOG_TAG, "onSurfaceTextureDestroyed", LogLevel.DEBUG);
   return false;
 }
コード例 #25
0
 /**
  * Triggered when your application is about to go to the background, initiated by the SDK. This
  * may happen in various ways, f.e if user wants open the SDK's browser web page in native browser
  * or clicks on `mailto:` links...
  *
  * @param interstitial - interstitial object the sender of message
  */
 void onLoopMeInterstitialLeaveApp(LoopMeInterstitial interstitial) {
   Logging.out(LOG_TAG, "Leaving application");
   if (mAdListener != null) {
     mAdListener.onLoopMeInterstitialLeaveApp(this);
   }
 }
コード例 #26
0
 /**
  * Triggered only when interstitial's video was played until the end. It won't be sent if the
  * video was skipped or the interstitial was dissmissed during the displaying process
  *
  * @param interstitial - interstitial object - the sender of message
  */
 void onLoopMeInterstitialVideoDidReachEnd(LoopMeInterstitial interstitial) {
   Logging.out(LOG_TAG, "Video reach end");
   if (mAdListener != null) {
     mAdListener.onLoopMeInterstitialVideoDidReachEnd(this);
   }
 }
コード例 #27
0
 private void handleClose() {
   Logging.out(LOG_TAG, "JS command: close", LogLevel.DEBUG);
   mAd.dismiss();
 }
コード例 #28
0
 private void handleVideoPause(int time) {
   Logging.out(LOG_TAG, "JS command: pause video " + time, LogLevel.DEBUG);
   if (mVideoController != null) {
     mVideoController.pauseVideo(time);
   }
 }
コード例 #29
0
 void setGoogleAdvertisingId(String advId) {
   Logging.out(LOG_TAG, "Advertising Id = " + advId, LogLevel.DEBUG);
   mAdvertisingId = advId;
 }
コード例 #30
0
 private void handleLoadFail(String mess) {
   Logging.out(LOG_TAG, "JS command: load fail", LogLevel.DEBUG);
   loadFail(mAd, new LoopMeError("Failed to process ad"));
 }