Example #1
0
  public boolean onTouch(View view, MotionEvent event) {

    boolean rs = _gestureDetector.onTouchEvent(event);

    int action = event.getAction();

    if (MotionEvent.ACTION_CANCEL == action || MotionEvent.ACTION_UP == action) {

      if (_gestureDirection != GestureDirectionNone) {

        final IViewController<T> leftViewController = getLeftViewController();
        final IViewController<T> rightViewController = getRightViewController();
        final IViewController<T> centerViewController = getCenterViewController();

        final ViewGroup contentView = getContentView();

        if (leftViewController != null && leftViewController.isViewAppeared()) {

          Animation anim = new Animation();

          anim.setDuration(300);

          if (_gestureDirection == GestureDirectionRight) {

            anim.setListener(
                new AnimatorListener() {

                  public void onAnimationStart(Animator animation) {}

                  public void onAnimationRepeat(Animator animation) {}

                  public void onAnimationEnd(Animator animation) {
                    onEnd();
                  }

                  public void onAnimationCancel(Animator animation) {
                    onEnd();
                  }

                  public void onEnd() {

                    if (rightViewController != null && !rightViewController.isViewAppeared()) {
                      rightViewController.viewRemoveForSuperView(true);
                    }

                    getViewControllerContext().setIdleTimerDisabled(false);
                    contentView.setEnabled(true);
                  }
                });

            if (centerViewController != null) {
              View v = centerViewController.getView();
              anim.translateTo(v, 0.0f, 0.0f);
            }

            if (leftViewController != null) {
              View v = leftViewController.getView();
              anim.alphaTo(v, 1.0f);
            }

            _topControllerDirection = TopControllerDirectionLeft;
          } else {

            anim.setListener(
                new AnimatorListener() {

                  public void onAnimationStart(Animator animation) {}

                  public void onAnimationRepeat(Animator animation) {}

                  public void onAnimationEnd(Animator animation) {
                    onEnd();
                  }

                  public void onAnimationCancel(Animator animation) {
                    onEnd();
                  }

                  public void onEnd() {

                    if (rightViewController != null && !rightViewController.isViewAppeared()) {
                      rightViewController.viewRemoveForSuperView(true);
                    }

                    if (leftViewController != null && !leftViewController.isViewAppeared()) {
                      leftViewController.viewRemoveForSuperView(true);
                    }

                    getViewControllerContext().setIdleTimerDisabled(false);
                    contentView.setEnabled(true);
                  }
                });
          }

          if (centerViewController != null) {
            View v = centerViewController.getView();
            anim.translateTo(v, 0.0f, 0.0f);
          }

          anim.submit();
          getViewControllerContext().setIdleTimerDisabled(true);
          contentView.setEnabled(false);

          _topControllerDirection = TopControllerDirectionCenter;

        } else if (rightViewController != null && rightViewController.isViewAppeared()) {

          Animation anim = new Animation();

          anim.setDuration(300);

          if (_gestureDirection == GestureDirectionLeft) {

            anim.setListener(
                new AnimatorListener() {

                  public void onAnimationStart(Animator animation) {}

                  public void onAnimationRepeat(Animator animation) {}

                  public void onAnimationEnd(Animator animation) {
                    onEnd();
                  }

                  public void onAnimationCancel(Animator animation) {
                    onEnd();
                  }

                  public void onEnd() {

                    if (leftViewController != null && !leftViewController.isViewAppeared()) {
                      leftViewController.viewRemoveForSuperView(true);
                    }

                    getViewControllerContext().setIdleTimerDisabled(false);
                    contentView.setEnabled(true);
                  }
                });

            if (centerViewController != null) {
              View v = centerViewController.getView();
              anim.translateTo(v, 0.0f, 0.0f);
            }

            if (rightViewController != null) {
              View v = rightViewController.getView();
              anim.alphaTo(v, 1.0f);
            }

            _topControllerDirection = TopControllerDirectionRight;
          } else {

            anim.setListener(
                new AnimatorListener() {

                  public void onAnimationStart(Animator animation) {}

                  public void onAnimationRepeat(Animator animation) {}

                  public void onAnimationEnd(Animator animation) {
                    onEnd();
                  }

                  public void onAnimationCancel(Animator animation) {
                    onEnd();
                  }

                  public void onEnd() {

                    if (rightViewController != null && !rightViewController.isViewAppeared()) {
                      rightViewController.viewRemoveForSuperView(true);
                    }

                    if (leftViewController != null && !leftViewController.isViewAppeared()) {
                      leftViewController.viewRemoveForSuperView(true);
                    }

                    getViewControllerContext().setIdleTimerDisabled(false);
                    contentView.setEnabled(true);
                  }
                });

            _topControllerDirection = TopControllerDirectionCenter;
          }

          if (centerViewController != null) {
            View v = centerViewController.getView();
            anim.translateTo(v, 0.0f, 0.0f);
          }

          anim.submit();
          getViewControllerContext().setIdleTimerDisabled(true);
          contentView.setEnabled(false);

        } else {

          Animation anim = new Animation();

          anim.setDuration(300);

          anim.setListener(
              new AnimatorListener() {

                public void onAnimationStart(Animator animation) {}

                public void onAnimationRepeat(Animator animation) {}

                public void onAnimationEnd(Animator animation) {
                  onEnd();
                }

                public void onAnimationCancel(Animator animation) {
                  onEnd();
                }

                public void onEnd() {

                  if (rightViewController != null && !rightViewController.isViewAppeared()) {
                    rightViewController.viewRemoveForSuperView(true);
                  }

                  if (leftViewController != null && !leftViewController.isViewAppeared()) {
                    leftViewController.viewRemoveForSuperView(true);
                  }

                  getViewControllerContext().setIdleTimerDisabled(false);
                  contentView.setEnabled(true);
                }
              });

          _topControllerDirection = TopControllerDirectionCenter;

          if (centerViewController != null) {
            View v = centerViewController.getView();
            anim.translateTo(v, 0.0f, 0.0f);
          }

          anim.submit();
          getViewControllerContext().setIdleTimerDisabled(true);
          contentView.setEnabled(false);
        }

        _gestureDirection = GestureDirectionNone;
        _gestureTouchX = 0;
      }
    }

    return rs;
  }
Example #2
0
  protected void setTopControllerDirection(int topControllerDirection, boolean animated) {

    if (getViewControllerContext().isIdleTimerDisabled() && animated && isViewAppeared()) {
      return;
    }

    if (_topControllerDirection != topControllerDirection) {

      getView();

      final ViewGroup contentView = getContentView();

      if (animated && isViewAppeared()) {

        switch (topControllerDirection) {
          case TopControllerDirectionCenter:
            {
              Animation anim = new Animation();

              anim.setDuration(300);
              anim.setListener(
                  new AnimatorListener() {

                    public void onEnd() {

                      IViewController<T> topController = getLeftViewController();

                      if (topController != null) {
                        if (topController.isViewAppeared()) {
                          topController.viewRemoveForSuperView(true);
                        }
                      }

                      topController = getRightViewController();

                      if (topController != null) {
                        if (topController.isViewAppeared()) {
                          topController.viewRemoveForSuperView(true);
                        }
                      }

                      contentView.setEnabled(true);
                      getViewControllerContext().setIdleTimerDisabled(false);
                    }

                    public void onAnimationStart(Animator animation) {}

                    public void onAnimationRepeat(Animator animation) {}

                    public void onAnimationEnd(Animator animation) {
                      onEnd();
                    }

                    public void onAnimationCancel(Animator animation) {
                      onEnd();
                    }
                  });

              IViewController<T> topController = getLeftViewController();

              if (topController != null) {
                if (topController.isViewAppeared()) {
                  anim.alpha(topController.getView(), 1.0f, AlphaValue);
                }
              }

              topController = getCenterViewController();

              if (topController != null) {

                View v = topController.getView();

                anim.translateTo(v, 0, 0);

                if (!topController.isViewAppeared()) {
                  topController.viewAppearToSuperView(contentView, animated);
                }
              }

              topController = getRightViewController();

              if (topController != null) {

                if (topController.isViewAppeared()) {
                  anim.alpha(topController.getView(), 1.0f, AlphaValue);
                }
              }
              contentView.setEnabled(false);
              getViewControllerContext().setIdleTimerDisabled(true);
              anim.submit();
            }
            break;
          case TopControllerDirectionLeft:
            {
              Animation anim = new Animation();

              anim.setDuration(300);
              anim.setListener(
                  new AnimatorListener() {

                    public void onEnd() {

                      IViewController<T> topController = getRightViewController();

                      if (topController != null) {
                        if (topController.isViewAppeared()) {
                          topController.viewRemoveForSuperView(true);
                        }
                      }

                      contentView.setEnabled(true);
                      getViewControllerContext().setIdleTimerDisabled(false);
                    }

                    public void onAnimationStart(Animator animation) {}

                    public void onAnimationRepeat(Animator animation) {}

                    public void onAnimationEnd(Animator animation) {
                      onEnd();
                    }

                    public void onAnimationCancel(Animator animation) {
                      onEnd();
                    }
                  });

              IViewController<T> topController = getLeftViewController();

              if (topController != null) {

                if (!topController.isViewAppeared()) {
                  topController.viewAppearToSuperView(getContentView(), animated, true);
                }

                anim.alpha(topController.getView(), AlphaValue, 1.0f);
              }

              topController = getCenterViewController();

              if (topController != null) {

                View v = topController.getView();

                anim.translateTo(v, contentView.getWidth() - FoldWidth, 0);

                if (!topController.isViewAppeared()) {
                  topController.viewAppearToSuperView(getContentView(), animated);
                }
              }

              topController = getRightViewController();

              if (topController != null) {

                if (topController.isViewAppeared()) {
                  anim.alpha(topController.getView(), 1.0f, AlphaValue);
                }
              }

              contentView.setEnabled(false);
              getViewControllerContext().setIdleTimerDisabled(true);
              anim.submit();
            }
            break;
          case TopControllerDirectionRight:
            {
              Animation anim = new Animation();

              anim.setDuration(300);
              anim.setListener(
                  new AnimatorListener() {

                    public void onEnd() {

                      IViewController<T> topController = getLeftViewController();

                      if (topController != null) {
                        if (topController.isViewAppeared()) {
                          topController.viewRemoveForSuperView(true);
                        }
                      }

                      contentView.setEnabled(true);
                      getViewControllerContext().setIdleTimerDisabled(false);
                    }

                    public void onAnimationStart(Animator animation) {}

                    public void onAnimationRepeat(Animator animation) {}

                    public void onAnimationEnd(Animator animation) {
                      onEnd();
                    }

                    public void onAnimationCancel(Animator animation) {
                      onEnd();
                    }
                  });

              IViewController<T> topController = getLeftViewController();

              if (topController != null) {
                if (topController.isViewAppeared()) {
                  anim.alpha(topController.getView(), 1.0f, AlphaValue);
                }
              }

              topController = getCenterViewController();

              if (topController != null) {

                View v = topController.getView();

                anim.translateTo(v, FoldWidth - contentView.getWidth(), 0);

                if (!topController.isViewAppeared()) {
                  topController.viewAppearToSuperView(contentView, animated);
                }
              }

              topController = getRightViewController();

              if (topController != null) {

                if (!topController.isViewAppeared()) {
                  topController.viewAppearToSuperView(contentView, animated, true);
                }

                anim.alpha(topController.getView(), AlphaValue, 1.0f);
              }

              contentView.setEnabled(false);
              getViewControllerContext().setIdleTimerDisabled(true);
              anim.submit();
            }
            break;
        }

      } else {

        switch (topControllerDirection) {
          case TopControllerDirectionCenter:
            {
              IViewController<T> topController = getLeftViewController();

              if (topController != null) {
                if (topController.isViewAppeared()) {
                  topController.viewRemoveForSuperView(animated);
                }
              }

              topController = getCenterViewController();

              if (topController != null) {

                View v = topController.getView();

                v.setX(0);

                if (isViewAppeared()) {
                  if (!topController.isViewAppeared()) {
                    topController.viewAppearToSuperView(contentView, animated);
                  }
                }
              }

              topController = getRightViewController();

              if (topController != null) {

                if (topController.isViewAppeared()) {
                  topController.viewRemoveForSuperView(animated);
                }
              }
            }
            break;
          case TopControllerDirectionLeft:
            {
              IViewController<T> topController = getLeftViewController();

              if (topController != null) {
                if (isViewAppeared()) {
                  if (!topController.isViewAppeared()) {
                    topController.viewAppearToSuperView(getContentView(), animated, true);
                  }
                }
              }

              topController = getCenterViewController();

              if (topController != null) {

                View v = topController.getView();

                v.setX(contentView.getWidth() - FoldWidth);

                if (isViewAppeared()) {
                  if (!topController.isViewAppeared()) {
                    topController.viewAppearToSuperView(getContentView(), animated);
                  }
                }
              }

              topController = getRightViewController();

              if (topController != null) {

                if (topController.isViewAppeared()) {
                  topController.viewRemoveForSuperView(animated);
                }
              }
            }
            break;
          case TopControllerDirectionRight:
            {
              IViewController<T> topController = getLeftViewController();

              if (topController != null) {
                if (topController.isViewAppeared()) {
                  topController.viewRemoveForSuperView(animated);
                }
              }

              topController = getCenterViewController();

              if (topController != null) {

                View v = topController.getView();

                v.setX(FoldWidth - contentView.getWidth());

                if (isViewAppeared()) {
                  if (!topController.isViewAppeared()) {
                    topController.viewAppearToSuperView(contentView, animated);
                  }
                }
              }

              topController = getRightViewController();

              if (topController != null) {

                if (isViewAppeared()) {
                  if (!topController.isViewAppeared()) {
                    topController.viewAppearToSuperView(contentView, animated, true);
                  }
                }
              }
            }
            break;
        }
      }

      _topControllerDirection = topControllerDirection;
    }
  }