Example #1
0
  /** @param loading should be {@link WXRefreshView} */
  public void setFooterView(WXComponent loading) {
    setLoadmoreEnable(true);
    if (swipeLayout != null) {
      if (swipeLayout.getFooterView() != null) {
        swipeLayout.setLoadingHeight((int) loading.getDomObject().getLayoutHeight());

        String colorStr =
            (String) loading.getDomObject().getStyles().get(Constants.Name.BACKGROUND_COLOR);
        String bgColor = WXUtils.getString(colorStr, null);

        if (bgColor != null) {
          if (!TextUtils.isEmpty(bgColor)) {
            int colorInt = WXResourceUtils.getColor(bgColor);
            if (!(colorInt == Color.TRANSPARENT)) {
              swipeLayout.setLoadingBgColor(colorInt);
            }
          }
        }
        swipeLayout.getFooterView().setRefreshView(loading.getHostView());
      }
    }
  }
Example #2
0
  @Override
  protected void initView() {
    FrameLayout videoRoot = new FrameLayout(mContext);
    videoRoot.setBackgroundColor(WXResourceUtils.getColor("#ee000000"));

    mVideoView = new WXVideoView(mContext);
    FrameLayout.LayoutParams videoLayoutParams =
        new FrameLayout.LayoutParams(
            FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
    videoLayoutParams.gravity = Gravity.CENTER;
    mVideoView.setLayoutParams(videoLayoutParams);
    videoRoot.addView(mVideoView);

    mProgressBar = new ProgressBar(mContext);
    FrameLayout.LayoutParams pLayoutParams =
        new FrameLayout.LayoutParams(
            FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
    mProgressBar.setLayoutParams(pLayoutParams);
    pLayoutParams.gravity = Gravity.CENTER;
    videoRoot.addView(mProgressBar);

    final MediaController controller = new MediaController(mContext);

    controller.setAnchorView(videoRoot);

    mVideoView.setOnErrorListener(
        new MediaPlayer.OnErrorListener() {

          @Override
          public boolean onError(MediaPlayer mp, int what, int extra) {
            if (WXEnvironment.isApkDebugable()) {
              WXLogUtils.d("Video", "onError:" + what);
            }
            mProgressBar.setVisibility(View.GONE);
            mPrepared = false;
            mError = true;

            if (mDomObj.event != null && mDomObj.event.contains(WXEventType.VIDEO_FAIL)) {
              WXSDKManager.getInstance().fireEvent(mInstanceId, getRef(), WXEventType.VIDEO_FAIL);
            }
            return true;
          }
        });

    mVideoView.setOnPreparedListener(
        new MediaPlayer.OnPreparedListener() {

          @Override
          public void onPrepared(MediaPlayer mediaPlayer) {
            if (WXEnvironment.isApkDebugable()) {
              WXLogUtils.d("Video", "onPrepared");
            }
            mProgressBar.setVisibility(View.GONE);
            mPrepared = true;
            if (mAutoPlay) {
              mVideoView.start();
            }
            mVideoView.seekTo(5);
            if (!mStopped) {
              controller.show(3);
            } else {
              controller.hide();
            }
            mStopped = false;
          }
        });

    mVideoView.setOnCompletionListener(
        new MediaPlayer.OnCompletionListener() {

          @Override
          public void onCompletion(MediaPlayer mediaPlayer) {
            if (WXEnvironment.isApkDebugable()) {
              WXLogUtils.d("Video", "onCompletion");
            }
            if (mDomObj.event != null && mDomObj.event.contains(WXEventType.VIDEO_FINISH)) {
              WXSDKManager.getInstance().fireEvent(mInstanceId, getRef(), WXEventType.VIDEO_FINISH);
            }
          }
        });

    mVideoView.setOnVideoPauseListener(
        new WXVideoView.VideoPlayListener() {

          @Override
          public void onPause() {
            if (WXEnvironment.isApkDebugable()) {
              WXLogUtils.d("Video", "onPause");
            }
            if (mDomObj.event != null && mDomObj.event.contains(WXEventType.VIDEO_PAUSE)) {
              WXSDKManager.getInstance().fireEvent(mInstanceId, getRef(), WXEventType.VIDEO_PAUSE);
            }
          }

          @Override
          public void onStart() {
            if (WXEnvironment.isApkDebugable()) {
              WXLogUtils.d("Video", "onStart");
            }

            if (mDomObj.event != null && mDomObj.event.contains(WXEventType.VIDEO_START)) {
              WXSDKManager.getInstance().fireEvent(mInstanceId, getRef(), WXEventType.VIDEO_START);
            }
          }
        });

    mVideoView.setMediaController(controller);
    controller.setMediaPlayer(mVideoView);

    mHost = videoRoot;
  }