case fromRight: viewSwiter.setInAnimation(animSlideInRight); viewSwiter.setOutAnimation(animSlideOutRight); break; case fromCenter: viewSwiter.setAnimation(scaleAnimation); break; case fromAlpha: viewSwiter.setAnimation(alphaAnimation); break; case none: viewSwiter.setInAnimation(null); viewSwiter.setOutAnimation(null); break; default: break; } } /** * 不在动画中,用于判断是否相应click * * @author haitian */ public boolean notAnimition() { return isClickEnabled; } /** * 初始化之后,将初始化完毕的MainDC呈现,作为最底层的DC,重复back()方法N次后显示此DC,quit()方法直接返回到此DC, * 要在acitvity中的setContentView()方法前设置 * * @author haitian */ public void setMainDC(BaseDC mainDC) { viewSwiter.removeAllViews(); viewSwiter.addView(mainDC, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); // viewSwiter.setAnimation(alphaAnimation); viewSwiter.setInAnimation(animSlideInLeft); viewSwiter.setOutAnimation(animSlideOutLeft); viewSwiter.setDisplayedChild(0); mainDC.onShow(); } public void setAnimaMainDC(BaseDC mainDC) { viewSwiter.removeAllViews(); viewSwiter.addView(mainDC, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); // viewSwiter.setAnimation(alphaAnimation); viewSwiter.setInAnimation(animSlideInRight); viewSwiter.setOutAnimation(animSlideOutRight); viewSwiter.setDisplayedChild(0); mainDC.onShow(); } public void setInitDC(BaseDC initDC) { viewSwiter.removeAllViews(); viewSwiter.addView(initDC, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); viewSwiter.setAnimation(scaleAnimation); viewSwiter.setDisplayedChild(0); initDC.onShow(); } /** * 用于设置到activity中 * * @author haitian */ public ViewAnimator getContentView() { if (viewSwiter.getCurrentView() instanceof BaseDC) { ((BaseDC) viewSwiter.getCurrentView()).checkOrientation(); } return viewSwiter; } /** * 判断正在显示的dc是否是某dc * * @author haitian */ public boolean isShowDC(BaseDC dc) { if (viewSwiter.getCurrentView() == dc) { return true; } else { return false; } } public BaseDC getNowDC() { if (viewSwiter.getCurrentView() instanceof BaseDC) { return (BaseDC) viewSwiter.getCurrentView(); } else { return null; } } public void makeScaleAnimation() { if (ScreenWidth == 320 && ScreenHeight == 600) { scaleAnimation = new ScaleAnimation(0.1f, 1.3f, 0.1f, 1.1f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); } else if (ScreenWidth == 320 && ScreenHeight == 800) { scaleAnimation = new ScaleAnimation(0.1f, 1.0f, 0.1f, 1.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); } else if (ScreenWidth == 320 && ScreenHeight == 480) { scaleAnimation = new ScaleAnimation(0.1f, 1.0f, 0.1f, 1.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); } else if (ScreenWidth == 320 && ScreenHeight == 854) { scaleAnimation = new ScaleAnimation(0.1f, 1.2f, 0.1f, 1.1f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); } else {// 未知屏幕则按默认 scaleAnimation = new ScaleAnimation(0.1f, 1.0f, 0.1f, 1.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); } scaleAnimation.setFillAfter(true); } private void setClickEnabled(boolean isCleckEnabled) { if (isCleckEnabled) { viewSwiter.postDelayed(new Runnable() { @Override public void run() { isClickEnabled = true; } }, 200); // isClickEnabled=true; // viewSwiter.setClickable(true); } else { isClickEnabled = false; // viewSwiter.setClickable(false); } } public boolean back() { LogInfo.LogOut("haitian", "viewSwiter.getChildCount() = " + viewSwiter.getChildCount()); if (viewSwiter.getChildCount() > 1) { final BaseDC toShow = (BaseDC) viewSwiter.getChildAt(viewSwiter.getChildCount() - 2); viewSwiter.setInAnimation(animSlideInRight); viewSwiter.setOutAnimation(animSlideOutRight); viewSwiter.setDisplayedChild(viewSwiter.getChildCount() - 2); viewSwiter.removeViewAt(viewSwiter.getChildCount() - 1); toShow.onShow(); return true; } else { return false; } } public void showDC(BaseDC dc, int type, BaseManager from, BaseManager to) { if (type == 0) { setStyle(AnimationStyle.none); } else if (type == 1) {// from left to right setStyle(AnimationStyle.fromLeft); } else if (type == 2) { setStyle(AnimationStyle.fromRight); } if (dc.getParent() != null) { if (dc.getParent() instanceof ViewGroup) { ((ViewGroup) (dc.getParent())).removeView(dc); } else { return; } } dc.invalidate(); viewSwiter.addView(dc, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); viewSwiter.setDisplayedChild(viewSwiter.getChildCount() - 1); // viewSwiter.setDisplayedChild(1); // viewSwiter.removeViewAt(0); dc.onShow(); fromManager = from; toManager = to;