Пример #1
0
  private void setOfferIconAsCreative(AppOffer appOffer) {
    if (appOffer == null) {
      return;
    }

    UnscaledBitmapLoader.ScreenDPI screenDPI =
        UnscaledBitmapLoader.ScreenDPI.DENSITY_XXXHDPI; // so we get big icon
    AppOffer.IconUrlSize iconUrlSize = GameWallImpl.getAppOfIconUrlSize(getResources());
    AssetsManagerSetBitmapTask task =
        new AssetsManagerSetBitmapTask(appOffer.getIconUrl(iconUrlSize), getContext()) {
          @Override
          public void bitmapLoadedPost(Bitmap bitmap) {
            if (ctaImage != null) {
              ctaImage.setImageBitmap(bitmap);
            }
          }
        };
    task.setParams(appOffer);
    task.setSourceImageDPI(screenDPI);
    AssetsManager.getInstance().runIconTask(task);
  }
Пример #2
0
  public void setup(
      AppOffer _appOffer,
      OnOfferClickListener _onOfferClickListener,
      OnVideoRewardGeneratedListener _onVideoRewardGeneratedListener,
      AppOfferWithResult _appOfferWithResult,
      final VideoComponentCallbacks _videoComponentCallbacks,
      ExoVideoPlayer.GameWallCallback _gameWallCallback,
      boolean _immersiveMode,
      boolean waitForVideoShow) {
    // TODO fetch fullscreen flag from server
    isFullscreen = false;
    this.immersiveMode = _immersiveMode;

    this.appOffer = _appOffer;
    this.onOfferClickListener = _onOfferClickListener;
    this.onVideoRewardGeneratedListener = _onVideoRewardGeneratedListener;
    this.appOfferWithResult = _appOfferWithResult;
    this.videoComponentCallbacks = _videoComponentCallbacks;
    this.gameWallCallback = _gameWallCallback;

    if (isFullscreen) { // TODO
      // LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
      //        ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
      // videoPartLayout.setLayoutParams(params);
    } else {
      WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
      Display display = wm.getDefaultDisplay();

      if (Utils.isPortrate(getContext())) {
        Logger.debug("placeForVideo", "width " + display.getWidth());

        // we calculate the available width for video (subtract padding or margins if necessary)
        placeForVideo = display.getWidth();

        LinearLayout.LayoutParams params =
            new LinearLayout.LayoutParams(
                placeForVideo, AnimFactory.getVideoViewHeight(placeForVideo));
        setLayoutParams(params);
      } else {
        Logger.debug("placeForVideo", "height " + display.getHeight());

        placeForVideo =
            display.getHeight()
                - getResources()
                    .getDimensionPixelSize(R.dimen.bee7_dialog_vertical_margin) // top margin
                - getResources()
                    .getDimensionPixelSize(R.dimen.bee7_dialog_vertical_margin) // bottom margin
                - getResources()
                    .getDimensionPixelSize(
                        R.dimen.bee7_ingamewall_video_margin_vertical) // top padding
                - getResources()
                    .getDimensionPixelSize(
                        R.dimen.bee7_ingamewall_video_margin_vertical) // bottom padding
                - getResources()
                    .getDimensionPixelSize(R.dimen.bee7_video_dialog_icon_size) // offer icon height
                - getResources()
                    .getDimensionPixelSize(
                        R.dimen.bee7_dialog_vertical_item_spacing) // spacing between items
                - getResources()
                    .getDimensionPixelSize(
                        R.dimen.bee7_dialog_dl_button_height) // download button height
                - getResources()
                    .getDimensionPixelSize(
                        R.dimen.bee7_dialog_vertical_item_spacing); // spacing between items

        LinearLayout.LayoutParams params =
            new LinearLayout.LayoutParams(
                AnimFactory.getVideoViewWidth(placeForVideo), placeForVideo);
        setLayoutParams(params);
      }
    }

    videoPlayerInterface =
        new ExoVideoPlayer(
            getContext(),
            appOffer.getVideoUrl(),
            0,
            false,
            true,
            waitForVideoShow,
            new VideoCallbackListener() {
              @TargetApi(Build.VERSION_CODES.HONEYCOMB)
              @Override
              public ViewGroup onSurfaceView(TextureView surfaceView) {
                ingamewallVideoLayout.removeAllViews();
                ingamewallVideoLayout.setAlpha(0.0f);
                ingamewallVideoLayout.addView(surfaceView);
                return ingamewallVideoLayout;
              }

              @Override
              public void onError(String e, boolean isVideoDisabled) {
                Logger.debug(
                    "ExoVideoPlayer", "onError: " + e + ", isVideoDisabled: " + isVideoDisabled);
                videoComponentCallbacks.onVideoFailedEvent(appOffer.getId(), e, isVideoDisabled);

                ctaImage.setVisibility(View.VISIBLE);
                ctaVisible = true;
                videoVisible = false;
                progressBar.setVisibility(View.GONE);

                if (!com.bee7.sdk.common.util.Utils.isOnline(getContext())) {
                  new DialogNoInternet(getContext(), immersiveMode).show();
                  onVideoEnd(0, false);
                  videoVisible = false;
                  return;
                }
              }

              @Override
              public void onVideoEnd(int videoPlayed, boolean error) {
                if (closeNoticeLayout.isShown()) {
                  closeNoticeLayout.setVisibility(View.GONE);
                  isCloseNoticeShown = false;
                }

                reportVideoWatchedEvent();

                if (appOffer != null
                    && !error
                    && onVideoRewardGeneratedListener != null
                    && videoPlayed
                        >= 90 // if video was watched more than 90%. I choose 90 instead of 100
                              // because I don't trust player position reporting on all devices.
                    // && !alreadyWatched
                    && (videoComponentCallbacks.getAppOffersModel().getVideoPrequaificationlType()
                            == AppOffersModel.VideoPrequalType.FULLSCREEN_REWARD
                        || videoComponentCallbacks
                                .getAppOffersModel()
                                .getVideoPrequaificationlType()
                            == AppOffersModel.VideoPrequalType.INLINE_REWARD)) {

                  onVideoRewardGeneratedListener.onVideoRewardGenerated(appOffer);
                }

                if (controlsHandler != null) {
                  controlsHandler.removeCallbacksAndMessages(null);
                }

                if (!error) {
                  if (isFullscreen) {
                    ingamewallCtaLayout.setVisibility(View.VISIBLE);
                  }
                  ctaImage.setVisibility(View.VISIBLE);
                  ingamewallVideoLayout.setVisibility(View.GONE);
                  controlsLayout.setVisibility(View.GONE);
                  ctaVisible = true;

                  if (videoComponentCallbacks != null) {
                    videoComponentCallbacks.onVideoEnd();
                  }

                  Animation videoViewHideAnim = AnimFactory.createAlphaHide(ingamewallVideoLayout);
                  videoViewHideAnim.setDuration(AnimFactory.ANIMATION_DURATION_LONG);

                  videoViewHideAnim.setAnimationListener(
                      new Animation.AnimationListener() {
                        @Override
                        public void onAnimationStart(Animation animation) {}

                        @Override
                        public void onAnimationEnd(Animation animation) {
                          if (ingamewallVideoLayout != null) {
                            ingamewallVideoLayout.setVisibility(View.GONE);
                            ingamewallVideoLayout.removeAllViews();
                          }
                          System.gc();
                        }

                        @Override
                        public void onAnimationRepeat(Animation animation) {}
                      });
                  videoVisible = false;
                  ingamewallVideoLayout.startAnimation(videoViewHideAnim);

                  if (videoPlayerInterface != null) {
                    videoPlayerInterface.onDestroy();
                  }
                  videoPlayerInterface = null;
                  if (controlsHandler != null) {
                    controlsHandler.removeCallbacksAndMessages(null);
                  }
                  controlsHandler = null;
                }

                setKeepScreenOn(false);
              }

              @Override
              public void onVideoStart() {
                showTimedControlsVisibility();

                reportVideoStartEvent();
                if (videoComponentCallbacks != null) {
                  videoComponentCallbacks.onVideoStart();
                }

                if (ingamewallCtaLayout != null) {
                  ingamewallCtaLayout.setVisibility(View.GONE);
                }

                if (!videoVisible) {
                  Animation videoViewHideAnim =
                      AnimFactory.createAlphaShow(ingamewallVideoLayout, false);
                  videoViewHideAnim.setDuration(AnimFactory.ANIMATION_DURATION_LONG);

                  videoViewHideAnim.setAnimationListener(
                      new Animation.AnimationListener() {
                        @TargetApi(Build.VERSION_CODES.HONEYCOMB)
                        @Override
                        public void onAnimationStart(Animation animation) {
                          if (ingamewallVideoLayout != null) {
                            ingamewallVideoLayout.setVisibility(View.VISIBLE);
                          }
                        }

                        @Override
                        public void onAnimationEnd(Animation animation) {}

                        @Override
                        public void onAnimationRepeat(Animation animation) {}
                      });
                  videoVisible = true;
                  ingamewallVideoLayout.startAnimation(videoViewHideAnim);
                }

                setKeepScreenOn(true);
              }

              @Override
              public void onBuffer(boolean buffering) {
                if (buffering) {
                  // show progress
                  progressBar.setVisibility(View.VISIBLE);
                } else {
                  // hide progress
                  progressBar.setVisibility(View.GONE);
                }
              }

              @Override
              public void onTimeToEndUpdate(long progress) {
                if (circleCounter != null) {
                  circleCounter.setText(String.valueOf(progress));
                }
              }

              @Override
              public void onProgress(long progress, long max) {
                // not used
              }
            },
            videoComponentCallbacks.getAppOffersModel().getVideoPrequalGlobalConfig(),
            gameWallCallback);

    if (!TextUtils.isEmpty(appOffer.getCreativeUrl())) {
      try {
        URL cUrl = new URL(appOffer.getCreativeUrl());

        AssetsManagerSetBitmapTask task =
            new AssetsManagerSetBitmapTask(cUrl, getContext()) {
              @Override
              public void bitmapLoadedPost(Bitmap bitmap) {
                if (bitmap != null && ctaImage != null) {
                  ctaImage.setImageBitmap(bitmap);
                } else {
                  setOfferIconAsCreative(appOffer);
                }
              }
            };
        task.setParams(appOffer);

        AssetsManager.getInstance()
            .runEndScreenTask(task, AnimFactory.getVideoViewHeight(placeForVideo), placeForVideo);
      } catch (Exception ignored) {
        setOfferIconAsCreative(appOffer);
      }
    } else {
      setOfferIconAsCreative(appOffer);
    }

    ingamewallVideoLayout.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            synchronized (GameWallView.lastClickSync) {
              // mis-clicking prevention, using threshold of 1000 ms
              if ((SystemClock.elapsedRealtime() - GameWallView.lastClickTimestamp) < 1000) {
                GameWallView.lastClickTimestamp = SystemClock.elapsedRealtime();
                return;
              }

              GameWallView.lastClickTimestamp = SystemClock.elapsedRealtime();

              if (onOfferClickListener != null) {
                onOfferClickListener.onOfferClick(
                    appOffer, appOfferWithResult, true, Publisher.AppOfferStartOrigin.DIALOG_VIDEO);
              }
            }
          }
        });
    closeNoticeLayout.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            closeNoticeLayout.setVisibility(View.GONE);
            isCloseNoticeShown = false;
            if (videoPlayerInterface != null) {
              if (videoPlayerInterface.isVideoAtEnd()) {
                videoPlayerInterface.seekToVideonEnd(3000);
              } else {
                videoPlayerInterface.resumeVideo();
              }
            }
          }
        });
    closeNoticeContinueWatching.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            closeNoticeLayout.setVisibility(View.GONE);
            isCloseNoticeShown = false;
            if (videoPlayerInterface != null) {
              if (videoPlayerInterface.isVideoAtEnd()) {
                videoPlayerInterface.seekToVideonEnd(3000);
              } else {
                videoPlayerInterface.resumeVideo();
              }
            }
          }
        });
    videoMute.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            if (videoPlayerInterface != null && videoPlayerInterface.toggleSound(true)) {
              videoMute.setImageDrawable(getResources().getDrawable(R.drawable.bee7_btn_sound_on));
              reportVideoMuteEvent(false);
            } else {
              videoMute.setImageDrawable(getResources().getDrawable(R.drawable.bee7_btn_sound_off));
              reportVideoMuteEvent(true);
            }
          }
        });
    ctaImage.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            if (onOfferClickListener != null) {
              synchronized (GameWallView.lastClickSync) {
                // mis-clicking prevention, using threshold of 1000 ms
                if ((SystemClock.elapsedRealtime() - GameWallView.lastClickTimestamp) < 1000) {
                  GameWallView.lastClickTimestamp = SystemClock.elapsedRealtime();
                  return;
                }

                GameWallView.lastClickTimestamp = SystemClock.elapsedRealtime();

                onOfferClickListener.onOfferClick(
                    appOffer,
                    appOfferWithResult,
                    true,
                    Publisher.AppOfferStartOrigin.DIALOG_VIDEO_IMG_BTN);
              }
            }
          }
        });
    if (videoClose != null) {
      videoClose.setOnClickListener(
          new OnClickListener() {
            @Override
            public void onClick(View v) {
              if (videoComponentCallbacks != null) {
                videoComponentCallbacks.onHide(videoClose);
              }
            }
          });
    }
    if (closeNoticeClose != null) {
      closeNoticeClose.setOnClickListener(
          new OnClickListener() {
            @Override
            public void onClick(View v) {
              if (videoComponentCallbacks != null) {
                videoComponentCallbacks.onHide(closeNoticeClose);
              }
            }
          });
    }
  }