Ejemplo n.º 1
0
  private void flipPage(final boolean forward) {
    if (!current.isFirstPage()) flipStarted = true;

    this.previousDirection = this.forward;
    this.forward = forward;

    if (!forward) decreasePageNo();

    int nextPageIndex = forward ? currentPageIndex + 1 : currentPageIndex;
    System.out.println("debug flip");
    if (currentPageIndex == -1 && forward) { // we are first timer
      currentPageIndex++;
      container.addView(current, pageViewLayoutParamsFront);
      slideToNextPageAsynchronized();
    } else if (nextPageIndex > 0) {

      if (current.isLastPage() && forward) {
        finishActivity();
      }
      slideToNextPageAsynchronized();
    } else {
      if (pageIndexView.isHasUpdate()) {
        this.reload();
        return;
      } else {
        finishActivity();
      }
    }
    System.out.println("debug flip done");
  }
Ejemplo n.º 2
0
 @Override
 public boolean dispatchTouchEvent(MotionEvent event) {
   //// System.out.println("flipStarted" + flipStarted);
   if (flipStarted) return true;
   //        if (header.isSourceSelectMode()) {
   if (header.dispatchTouchEvent(event)) {
     return true;
   }
   //        if (pageIndexView.dispatchTouchEvent(event)) {
   //            return true;
   //        }
   //        }
   if (enlargedMode) {
     current.onTouchEvent(event);
   }
   switch (event.getAction()) {
     case MotionEvent.ACTION_UP:
       return current.dispatchTouchEvent(event);
     case MotionEvent.ACTION_MOVE:
       {
         if (!enlargedMode) onTouchEvent(event);
         else current.onTouchEvent(event);
       }
   }
   return super.dispatchTouchEvent(event);
 }
Ejemplo n.º 3
0
 private void switchViews(boolean forward) {
   if (forward) {
     if (previous != null) previous.releaseResource();
     WeiboPageView tmp = current;
     previous = current;
     current = next;
     next = tmp;
   } else {
     if (next != null) next.releaseResource();
     WeiboPageView tmp = current;
     next = current;
     current = previous;
     previous = tmp;
   }
 }
Ejemplo n.º 4
0
  private void renderNextPageIfNotRendered() {
    WeiboPageView renderingPageView;

    if (forward) {
      renderingPageView = next;
    } else {
      renderingPageView = previous;
    }
    if (renderingPageView.isRendered()) return;

    for (ArticleView v : renderingPageView.getWeiboViews()) {
      v.renderBeforeLayout();
    }
    renderingPageView.renderBeforeLayout();
    renderingPageView.setVisibility(View.VISIBLE);
  }
Ejemplo n.º 5
0
 @Override
 public void onBackPressed() {
   if (enlargedMode) current.closeEnlargedView();
   else {
     overridePendingTransition(android.R.anim.slide_in_left, R.anim.fade);
     PageActivity.this.finish();
   }
   return;
 }
Ejemplo n.º 6
0
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    //// System.out.println("flipStarted" + flipStarted);
    if (flipStarted) {
      return false;
    }
    //        if (header.isSourceSelectMode()) {
    //            header.onTouchEvent(event);
    //        }
    if (enlargedMode) {
      current.onTouchEvent(event);
    }

    switch (event.getAction()) {
      case MotionEvent.ACTION_MOVE:
        if (event.getHistorySize() > 0 && !flipStarted) {
          if (GestureUtil.flipRight(event)) {
            lastFlipDirection = ACTION_HORIZONTAL;
            flipPage(false);
          } else if (GestureUtil.flipUp(event)) {
            lastFlipDirection = ACTION_VERTICAL;
            flipPage(false);
          } else if (GestureUtil.flipLeft(event)) {
            lastFlipDirection = ACTION_HORIZONTAL;
            flipPage(true);
          } else if (GestureUtil.flipDown(event)) {
            lastFlipDirection = ACTION_VERTICAL;
            flipPage(true);
          }

        } else {
          //                    if (header.isSourceSelectMode())
          header.onTouchEvent(event);
          //                    pageIndexView.onTouchEvent(event);
        }
        break;
      default:
        break;
    }

    return true;
  }
Ejemplo n.º 7
0
  private void slideToNextPage() {
    System.out.println("debug slide to next");
    try {
      if (preparingWindow == null && !prepareFail)
        preparingWindow =
            forward ? slidingWindows.getNextWindow() : slidingWindows.getPreviousWindow();
      else {
        if (previousDirection != forward) {
          if (previousDirection) {
            if (currentPageIndex == 0) {
              finishActivity();
              return;
            }
            preparingWindow = slidingWindows.getPreviousWindow();
            preparingWindow = slidingWindows.getPreviousWindow();
          } else {
            preparingWindow = slidingWindows.getNextWindow();
            preparingWindow = slidingWindows.getNextWindow();
          }
        }
        if (next.isLastPage()) {
          handler.post(
              new Runnable() {
                public void run() {
                  showAnimation();
                }
              });
          return;
        }
        boolean preparingWindowReady = preparingWindow.isLoaded();
        if (!preparingWindowReady) {
          preparingWindow.registerOnLoadListener(PageActivity.this);
          handler.post(
              new Runnable() {
                public void run() {
                  current.showLoading();
                }
              });
          return;
        }
      }
      final com.goal98.flipdroid.model.Window nextWindow = preparingWindow;
      preparingWindow = null;
      if (nextWindow.isLoading()) {
        // Log.d("SLIDING", "register on load listener...");

        handler.post(
            new Runnable() {
              public void run() {
                nextWindow.registerOnLoadListener(PageActivity.this);
                current.showLoading();
              }
            });
        return;
      } else if (nextWindow.isSkip()) {
        // Log.d("SLIDING", "slide to next page...");
        current.setLoadingNext(false);
        slideToNextPage();
        return;
      } else {
        if (next.isLastPage()) {
          //// System.out.println("lastpage");
        } else {
          if (forward) next = nextWindow.get();
          else previous = nextWindow.get();
        }

        handler.post(
            new Runnable() {
              public void run() {
                if (forward) next.removeLoadingIfNecessary();
                else {
                  if (previous == null) return;
                  previous.removeLoadingIfNecessary();
                }
                showAnimation();
              }
            });
      }
    } catch (Exception e) {
      e.printStackTrace();
      next = pageViewFactory.createLastPage();
      handler.post(
          new Runnable() {
            public void run() {
              showAnimation();
            }
          });
    }
  }
Ejemplo n.º 8
0
  private void showAnimation() {

    enlargedMode = false;
    renderNextPageIfNotRendered();
    // Log.d("ANI", "start animation");
    container.removeAllViews();
    if (current.isFirstPage()) {
      next.setVisibility(View.VISIBLE);
      currentPageIndex++;
      container.addView(current, pageViewLayoutParamsBack);
      container.addView(next, pageViewLayoutParamsFront);
      current.startAnimation(fadeInPageView);
    } else if (isWeiboMode()
        || next.isLastPage()
        || next.getWrapperViews().size() < 2
        || lastFlipDirection == ACTION_HORIZONTAL) {

      Animation rotation = buildFlipHorizonalAnimation(forward);
      if (forward) next.setVisibility(View.VISIBLE);
      else previous.setVisibility(View.VISIBLE);
      if (forward) {
        currentPageIndex++;

        container.addView(current, pageViewLayoutParamsBack);
        container.addView(next, pageViewLayoutParamsFront);
        current.startAnimation(rotation);
      } else {

        container.addView(current, pageViewLayoutParamsFront);
        container.addView(previous, pageViewLayoutParamsBack);
        previous.startAnimation(rotation);
      }
    } else {
      if (forward) {
        currentPageIndex++;
        container.addView(next, pageViewLayoutParamsFront);
      } else {
        container.addView(previous, pageViewLayoutParamsFront);
      }
      container.addView(current, pageViewLayoutParamsBack);

      if (forward) {
        currentUpper = current.getWrapperViews().get(0);
        currentBottom = current.getWrapperViews().get(1);
        nextUpper = next.getWrapperViews().get(0);
        nextBottom = next.getWrapperViews().get(1);
        final Animation flipToNext =
            buildFlipAnimation(currentUpper, currentBottom, nextUpper, nextBottom, true);
        currentBottom.startAnimation(flipToNext);
      } else {
        currentUpper = current.getWrapperViews().get(0);
        currentBottom = current.getWrapperViews().get(1);
        nextUpper = previous.getWrapperViews().get(0);
        nextBottom = previous.getWrapperViews().get(1);

        final Animation flipToPrevious =
            buildFlipAnimation(currentUpper, currentBottom, nextUpper, nextBottom, false);
        currentUpper.startAnimation(flipToPrevious);
      }
    }
  }