Ejemplo n.º 1
0
  @Override
  public String loadURL(URL url, String basePath, boolean animated) {

    basePath = URL.stringAddPathComponent(basePath, getAlias());

    String alias = url.firstPathComponent(basePath);

    if (alias != null) {

      IViewController<T> topController = getCenterViewController();

      if (topController == null || !alias.equals(topController.getAlias())) {

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

        topController = getViewControllerContext().getViewController(url, basePath);

        if (topController != null) {

          topController.setParentController(this);

          View v = topController.getView();

          if (_topControllerDirection == TopControllerDirectionLeft) {
            v.setX(v.getWidth() - FoldWidth);
          } else if (_topControllerDirection == TopControllerDirectionRight) {
            v.setX(FoldWidth - v.getWidth());
          } else {
            v.setX(0);
          }

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

          setCenterViewController(topController);
        }
      }

      if (topController != null) {
        basePath = topController.loadURL(url, basePath, animated);
      }
    }

    return basePath;
  }
Ejemplo n.º 2
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;
  }
Ejemplo n.º 3
0
  public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {

    float dx = e2.getX() - _gestureTouchX;

    if (distanceX < 0.0f) {
      _gestureDirection = GestureDirectionRight;
    } else {
      _gestureDirection = GestureDirectionLeft;
    }

    ViewGroup contentView = getContentView();

    if (dx == 0.0f) {

      IViewController<T> controller = getCenterViewController();

      if (controller != null) {
        View v = controller.getView();
        v.setX(dx);
      }

      controller = getLeftViewController();

      if (controller != null) {

        if (controller.isViewAppeared()) {
          controller.viewRemoveForSuperView(false);
        }
      }

      controller = getRightViewController();

      if (controller != null) {

        if (controller.isViewAppeared()) {
          controller.viewRemoveForSuperView(false);
        }
      }
    } else if (dx < 0.0f) {

      IViewController<T> controller = getLeftViewController();

      if (controller != null) {

        if (controller.isViewAppeared()) {
          controller.viewRemoveForSuperView(false);
        }
      }

      controller = getRightViewController();

      if (controller != null) {

        if (!controller.isViewAppeared()) {
          controller.viewAppearToSuperView(contentView, false, true);
        }

        View v = controller.getView();

        float alpha = AlphaValue - (1.0f - AlphaValue) * dx / contentView.getWidth();

        v.setAlpha(alpha);

        controller = getCenterViewController();

        if (controller != null) {
          v = controller.getView();
          v.setX(dx);
        }
      } else {

        controller = getCenterViewController();

        if (controller != null) {
          View v = controller.getView();
          v.setX(0);
        }
      }

    } else {

      IViewController<T> controller = getRightViewController();

      if (controller != null) {

        if (controller.isViewAppeared()) {
          controller.viewRemoveForSuperView(false);
        }
      }

      controller = getLeftViewController();

      if (controller != null) {

        if (!controller.isViewAppeared()) {
          controller.viewAppearToSuperView(contentView, false, true);
        }

        View v = controller.getView();

        float alpha = AlphaValue - (1.0f - AlphaValue) * dx / contentView.getWidth();

        v.setAlpha(alpha);

        controller = getCenterViewController();

        if (controller != null) {
          v = controller.getView();
          v.setX(dx);
        }
      } else {

        controller = getCenterViewController();

        if (controller != null) {
          View v = controller.getView();
          v.setX(0);
        }
      }
    }

    return true;
  }
Ejemplo n.º 4
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;
    }
  }