Commit 53d03926 authored by wanglei's avatar wanglei

...

parent 7096a17f
/* /*
* 文件名称: PGEventManage.java * 文件名称: PGEventManage.java
* *
* 编译器: android2.2 * 编译器: android2.2
* 时间: 下午7:00:11 * 时间: 下午7:00:11
*/ */
...@@ -9,7 +9,9 @@ package com.cherry.lib.doc.office.pg.control; ...@@ -9,7 +9,9 @@ package com.cherry.lib.doc.office.pg.control;
import com.cherry.lib.doc.office.common.ISlideShow; import com.cherry.lib.doc.office.common.ISlideShow;
import com.cherry.lib.doc.office.system.IControl; import com.cherry.lib.doc.office.system.IControl;
import com.cherry.lib.doc.office.system.beans.AEventManage; import com.cherry.lib.doc.office.system.beans.AEventManage;
import android.graphics.Rect; import android.graphics.Rect;
import android.util.Log;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
...@@ -25,134 +27,110 @@ import android.view.View; ...@@ -25,134 +27,110 @@ import android.view.View;
* <p> * <p>
* 负责人: ljj8494 * 负责人: ljj8494
* <p> * <p>
* 负责小组: * 负责小组:
* <p> * <p>
* <p> * <p>
*/ */
public class PGEventManage extends AEventManage public class PGEventManage extends AEventManage {
{
/** /**
* *
* @param spreadsheet
*/ */
public PGEventManage(Presentation presentation, IControl control) public PGEventManage(Presentation presentation, IControl control) {
{
super(presentation.getContext(), control); super(presentation.getContext(), control);
this.presentation = presentation; this.presentation = presentation;
presentation.setOnTouchListener(this); presentation.setOnTouchListener(this);
presentation.setLongClickable(true); presentation.setLongClickable(true);
} }
/** /**
* 触摸事件 * 触摸事件
*
*/ */
public boolean onTouch(View v, MotionEvent event) public boolean onTouch(View v, MotionEvent event) {
{ super.onTouch(v, event);
super.onTouch(v, event);
return false; return false;
} }
/** /**
*
* *
*/ */
public boolean onDoubleTap(MotionEvent e) public boolean onDoubleTap(MotionEvent e) {
{
super.onDoubleTap(e); super.onDoubleTap(e);
return true; return true;
} }
/** /**
*
* *
*/ */
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
{ super.onScroll(e1, e2, distanceX, distanceY);
super.onScroll(e1, e2, distanceX, distanceY);
return true; return true;
} }
/** /**
* Fling the scroll view * Fling the scroll view
* *
* @param velocityX X方向速率 * @param velocityX X方向速率
* @param velocityY Y方向速率 * @param velocityY Y方向速率
*/ */
public void fling(int velocityX, int velocityY) public void fling(int velocityX, int velocityY) {
{ if (presentation.isSlideShow()) {
if(presentation.isSlideShow()) if (Math.abs(velocityY) < 400 && Math.abs(velocityX) < 400) {
{
if (Math.abs(velocityY) < 400 && Math.abs(velocityX) < 400)
{
presentation.slideShow(ISlideShow.SlideShow_NextStep); presentation.slideShow(ISlideShow.SlideShow_NextStep);
return; return;
} }
super.fling(velocityX, velocityY); super.fling(velocityX, velocityY);
int currentIndex = presentation.getCurrentIndex(); int currentIndex = presentation.getCurrentIndex();
if (Math.abs(velocityY) > Math.abs(velocityX)) if (Math.abs(velocityY) > Math.abs(velocityX)) {
{
//vertical //vertical
if (velocityY < 0 && currentIndex >= 0) if (velocityY < 0 && currentIndex >= 0) {
{ //previous step
//previous step presentation.slideShow(ISlideShow.SlideShow_NextStep);
presentation.slideShow(ISlideShow.SlideShow_NextStep); } else if (velocityY > 0 && currentIndex <= presentation.getRealSlideCount() - 1) {
}
else if (velocityY > 0 && currentIndex <= presentation.getRealSlideCount() - 1)
{
//next step //next step
presentation.slideShow(ISlideShow.SlideShow_PreviousStep); presentation.slideShow(ISlideShow.SlideShow_PreviousStep);
} }
} } else {
else
{
// horizontal // horizontal
if (velocityX < 0 && currentIndex >= 0) if (velocityX < 0 && currentIndex >= 0) {
{
// previous Slide // previous Slide
presentation.slideShow(ISlideShow.SlideShow_PreviousSlide); presentation.slideShow(ISlideShow.SlideShow_PreviousSlide);
} } else if (velocityX > 0 && currentIndex < presentation.getRealSlideCount() - 1) {
else if (velocityX > 0 && currentIndex < presentation.getRealSlideCount() - 1)
{
// next Slide // next Slide
presentation.slideShow(ISlideShow.SlideShow_NextSlide); presentation.slideShow(ISlideShow.SlideShow_NextSlide);
} }
} }
} }
} }
/** /**
*
* *
*/ */
public boolean onSingleTapUp(MotionEvent e) public boolean onSingleTapUp(MotionEvent e) {
{ Log.e("PGEventManage", "onSingleTapUp");
control.getMainFrame().singleTap();
super.onSingleTapUp(e); super.onSingleTapUp(e);
if (e.getAction() == MotionEvent.ACTION_UP) if (e.getAction() == MotionEvent.ACTION_UP) {
{
Rect drawRect = presentation.getSlideDrawingRect(); Rect drawRect = presentation.getSlideDrawingRect();
if(presentation.isSlideShow() && drawRect.contains((int)e.getX(), (int)e.getY())) if (presentation.isSlideShow() && drawRect.contains((int) e.getX(), (int) e.getY())) {
{
//not click hyperlink, then go to next step //not click hyperlink, then go to next step
this.presentation.slideShow(ISlideShow.SlideShow_NextStep); this.presentation.slideShow(ISlideShow.SlideShow_NextStep);
} }
} }
return true; return true;
} }
/** /**
* *
*/ */
public void dispose() public void dispose() {
{
super.dispose(); super.dispose();
presentation = null; presentation = null;
} }
// Spreadsheet // Spreadsheet
private Presentation presentation; private Presentation presentation;
} }
...@@ -428,6 +428,12 @@ public class PGPrintMode extends FrameLayout implements IPageListViewListener { ...@@ -428,6 +428,12 @@ public class PGPrintMode extends FrameLayout implements IPageListViewListener {
return control.getMainFrame().getPageListViewMovingPosition(); return control.getMainFrame().getPageListViewMovingPosition();
} }
@Override
public void singleTab() {
Log.e("PGPrintMode", "singleTab");
control.getMainFrame().singleTap();
}
/** /**
* *
*/ */
......
/* /*
* 文件名称: PDFe.java * 文件名称: PDFe.java
* *
* 编译器: android2.2 * 编译器: android2.2
* 时间: 下午4:05:31 * 时间: 下午4:05:31
*/ */
...@@ -13,6 +13,7 @@ import com.cherry.lib.doc.office.constant.MainConstant; ...@@ -13,6 +13,7 @@ import com.cherry.lib.doc.office.constant.MainConstant;
import android.graphics.Point; import android.graphics.Point;
import android.graphics.Rect; import android.graphics.Rect;
import android.util.Log;
import android.view.GestureDetector; import android.view.GestureDetector;
import android.view.GestureDetector.OnDoubleTapListener; import android.view.GestureDetector.OnDoubleTapListener;
import android.view.GestureDetector.OnGestureListener; import android.view.GestureDetector.OnGestureListener;
...@@ -26,24 +27,21 @@ import android.widget.Toast; ...@@ -26,24 +27,21 @@ import android.widget.Toast;
public class APageListEventManage implements public class APageListEventManage implements
ScaleGestureDetector.OnScaleGestureListener, OnGestureListener,Runnable, ScaleGestureDetector.OnScaleGestureListener, OnGestureListener, Runnable,
OnTouchListener, OnDoubleTapListener, OnClickListener OnTouchListener, OnDoubleTapListener, OnClickListener {
{
private static final int MOVING_DIAGONALLY = 0; private static final int MOVING_DIAGONALLY = 0;
private static final int MOVING_LEFT = 1; private static final int MOVING_LEFT = 1;
private static final int MOVING_RIGHT = 2; private static final int MOVING_RIGHT = 2;
private static final int MOVING_UP = 3; private static final int MOVING_UP = 3;
private static final int MOVING_DOWN = 4; private static final int MOVING_DOWN = 4;
private static final float MAX_ZOOM = 3.0f; private static final float MAX_ZOOM = 3.0f;
/** /**
* *
* @param pdfListView
*/ */
public APageListEventManage(APageListView listView) public APageListEventManage(APageListView listView) {
{
this.listView = listView; this.listView = listView;
gesture = new GestureDetector(listView.getContext(), this); gesture = new GestureDetector(listView.getContext(), this);
mScroller = new Scroller(listView.getContext()); mScroller = new Scroller(listView.getContext());
...@@ -52,54 +50,41 @@ public class APageListEventManage implements ...@@ -52,54 +50,41 @@ public class APageListEventManage implements
} }
/** /**
*
* @see com.cherry.lib.doc.office.system.beans.AEventManage#zoom(android.view.MotionEvent)
* *
*/ */
protected boolean zoom(MotionEvent event) protected boolean zoom(MotionEvent event) {
{ return false;
return false;
} }
/** /**
* 触摸事件 * 触摸事件
*
*/ */
protected boolean processOnTouch(MotionEvent event) protected boolean processOnTouch(MotionEvent event) {
{
eventPointerCount = event.getPointerCount(); eventPointerCount = event.getPointerCount();
if (event.getActionMasked() == MotionEvent.ACTION_DOWN) if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
{
isOnFling = false; isOnFling = false;
isTouchEventIn = true; isTouchEventIn = true;
} }
if (mScaleGestureDetector != null) if (mScaleGestureDetector != null) {
{
mScaleGestureDetector.onTouchEvent(event); mScaleGestureDetector.onTouchEvent(event);
} }
if (!isScaling && gesture != null) if (!isScaling && gesture != null) {
{
gesture.onTouchEvent(event); gesture.onTouchEvent(event);
} }
if (event.getActionMasked() == MotionEvent.ACTION_UP) if (event.getActionMasked() == MotionEvent.ACTION_UP) {
{
isProcessOnScroll = true; isProcessOnScroll = true;
isTouchEventIn = false; isTouchEventIn = false;
APageListItem pageView = listView.getCurrentPageView(); APageListItem pageView = listView.getCurrentPageView();
if (pageView != null) if (pageView != null) {
{ if (mScroller.isFinished()) {
if (mScroller.isFinished())
{
// If, at the end of user interaction, there is no // If, at the end of user interaction, there is no
// current inertial scroll in operation then animate // current inertial scroll in operation then animate
// the view onto screen if necessary // the view onto screen if necessary
if (!isDoubleTap) if (!isDoubleTap) {
{
slideViewOntoScreen(pageView); slideViewOntoScreen(pageView);
} }
} }
if (mScroller.isFinished() && isOnScroll) if (mScroller.isFinished() && isOnScroll) {
{
// If still there is no inertial scroll in operation // If still there is no inertial scroll in operation
// then the layout is stable // then the layout is stable
listView.getPageListViewListener().setDrawPictrue(true); listView.getPageListViewListener().setDrawPictrue(true);
...@@ -109,101 +94,82 @@ public class APageListEventManage implements ...@@ -109,101 +94,82 @@ public class APageListEventManage implements
isDoubleTap = false; isDoubleTap = false;
isOnScroll = false; isOnScroll = false;
toast.cancel(); toast.cancel();
} }
//listView.requestLayout(); //listView.requestLayout();
return true; return true;
} }
/** /**
* 触摸事件 * 触摸事件
*
*/ */
public boolean onTouch(View v, MotionEvent event) public boolean onTouch(View v, MotionEvent event) {
{
listView.getPageListViewListener().onEventMethod(v, event, null, -1.0f, -1.0f, IPageListViewListener.ON_TOUCH); listView.getPageListViewListener().onEventMethod(v, event, null, -1.0f, -1.0f, IPageListViewListener.ON_TOUCH);
return false; return false;
} }
/** /**
* *
*/ */
public boolean onDown(MotionEvent e) public boolean onDown(MotionEvent e) {
{
mScroller.forceFinished(true); mScroller.forceFinished(true);
listView.getPageListViewListener().onEventMethod(listView, e, null, -1.0f, -1.0f, IPageListViewListener.ON_DOWN); listView.getPageListViewListener().onEventMethod(listView, e, null, -1.0f, -1.0f, IPageListViewListener.ON_DOWN);
return true; return true;
} }
/** /**
*
* @see com.cherry.lib.doc.office.system.beans.AEventManage#onFling(android.view.MotionEvent, android.view.MotionEvent, float, float) * @see com.cherry.lib.doc.office.system.beans.AEventManage#onFling(android.view.MotionEvent, android.view.MotionEvent, float, float)
*
*/ */
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
{
listView.getPageListViewListener().onEventMethod(listView, e1, e2, velocityX, velocityY, IPageListViewListener.ON_FLING); listView.getPageListViewListener().onEventMethod(listView, e1, e2, velocityX, velocityY, IPageListViewListener.ON_FLING);
if (!isProcessOnScroll || isDoubleTap) if (!isProcessOnScroll || isDoubleTap) {
{
return true; return true;
} }
View pageView = listView.getCurrentPageView(); View pageView = listView.getCurrentPageView();
if (pageView != null) if (pageView != null) {
{
Rect bounds = listView.getScrollBounds(pageView); Rect bounds = listView.getScrollBounds(pageView);
if(listView.getPageListViewListener().getPageListViewMovingPosition() == IPageListViewListener.Moving_Horizontal) if (listView.getPageListViewListener().getPageListViewMovingPosition() == IPageListViewListener.Moving_Horizontal) {
{ if (pageView.getWidth() <= listView.getWidth()
if (pageView.getWidth() <= listView.getWidth() || listView.getPageListViewListener().isChangePage()) {
|| listView.getPageListViewListener().isChangePage()) switch (directionOfTravel(velocityX, velocityY)) {
{ case MOVING_LEFT:
switch (directionOfTravel(velocityX, velocityY)) if (bounds.left >= 0) {
{ isOnFling = true;
case MOVING_LEFT: listView.nextPageView();
if (bounds.left >= 0) return true;
{ }
isOnFling = true; break;
listView.nextPageView(); case MOVING_RIGHT:
return true; if (bounds.right <= 0) {
} isOnFling = true;
break; listView.previousPageview();
case MOVING_RIGHT: return true;
if (bounds.right <= 0) }
{ break;
isOnFling = true;
listView.previousPageview();
return true;
}
break;
}
} }
} }
else } else {
{ if (pageView.getHeight() <= listView.getHeight()
if (pageView.getHeight() <= listView.getHeight() || listView.getPageListViewListener().isChangePage()) {
|| listView.getPageListViewListener().isChangePage()) switch (directionOfTravel(velocityX, velocityY)) {
{ case MOVING_UP:
switch (directionOfTravel(velocityX, velocityY)) if (bounds.top >= 0) {
{ isOnFling = true;
case MOVING_UP: listView.nextPageView();
if (bounds.top >= 0) return true;
{ }
isOnFling = true; break;
listView.nextPageView(); case MOVING_DOWN:
return true; if (bounds.bottom <= 0) {
} isOnFling = true;
break; listView.previousPageview();
case MOVING_DOWN: return true;
if (bounds.bottom <= 0) }
{ break;
isOnFling = true;
listView.previousPageview();
return true;
}
break;
}
} }
}
} }
mScrollerLastX = mScrollerLastY = 0; mScrollerLastX = mScrollerLastY = 0;
// If the page has been dragged out of bounds then we want to spring back // If the page has been dragged out of bounds then we want to spring back
// nicely. fling jumps back into bounds instantly, so we don't want to use // nicely. fling jumps back into bounds instantly, so we don't want to use
...@@ -218,46 +184,36 @@ public class APageListEventManage implements ...@@ -218,46 +184,36 @@ public class APageListEventManage implements
expandedBounds.inset(-100, -100); expandedBounds.inset(-100, -100);
if (withinBoundsInDirectionOfTravel(bounds, velocityX, velocityY) if (withinBoundsInDirectionOfTravel(bounds, velocityX, velocityY)
&& expandedBounds.contains(0, 0)) && expandedBounds.contains(0, 0)) {
{ mScroller.fling(0, 0, (int) velocityX, (int) velocityY, bounds.left, bounds.right,
mScroller.fling(0, 0, (int)velocityX, (int)velocityY, bounds.left, bounds.right, bounds.top, bounds.bottom);
bounds.top, bounds.bottom);
listView.post(this); listView.post(this);
} }
} }
return true; return true;
} }
/** /**
*
* *
*/ */
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
{
listView.getPageListViewListener().onEventMethod(listView, e1, e2, distanceX, distanceY, IPageListViewListener.ON_SCROLL); listView.getPageListViewListener().onEventMethod(listView, e1, e2, distanceX, distanceY, IPageListViewListener.ON_SCROLL);
if (isProcessOnScroll && !isDoubleTap) if (isProcessOnScroll && !isDoubleTap) {
{
listView.getPageListViewListener().setDrawPictrue(false); listView.getPageListViewListener().setDrawPictrue(false);
isOnScroll = true; isOnScroll = true;
mXScroll -= distanceX; mXScroll -= distanceX;
mYScroll -= distanceY; mYScroll -= distanceY;
if (!listView.getPageListViewListener().isChangePage()) if (!listView.getPageListViewListener().isChangePage()) {
{
APageListItem item = listView.getCurrentPageView(); APageListItem item = listView.getCurrentPageView();
if (item != null && item.getWidth() > listView.getWidth()) if (item != null && item.getWidth() > listView.getWidth()) {
{ if (distanceX > 0) {
if (distanceX > 0)
{
if (listView.getWidth() - mXScroll - item.getLeft() > item.getWidth() if (listView.getWidth() - mXScroll - item.getLeft() > item.getWidth()
&& item.getPageIndex() < listView.getPageCount() - 1) && item.getPageIndex() < listView.getPageCount() - 1) {
{
mXScroll = -(item.getWidth() - listView.getWidth() + item.getLeft()); mXScroll = -(item.getWidth() - listView.getWidth() + item.getLeft());
} }
} } else if (distanceX < 0) {
else if (distanceX < 0)
{
if (mXScroll + item.getLeft() > 0 if (mXScroll + item.getLeft() > 0
&& item.getPageIndex() != 0) && item.getPageIndex() != 0) {
{
mXScroll = 0; mXScroll = 0;
} }
} }
...@@ -267,34 +223,28 @@ public class APageListEventManage implements ...@@ -267,34 +223,28 @@ public class APageListEventManage implements
} }
return true; return true;
} }
/** /**
*
* @see android.view.ScaleGestureDetector.OnScaleGestureListener#onScale(android.view.ScaleGestureDetector) * @see android.view.ScaleGestureDetector.OnScaleGestureListener#onScale(android.view.ScaleGestureDetector)
*
*/ */
@ Override @Override
public boolean onScale(ScaleGestureDetector detector) public boolean onScale(ScaleGestureDetector detector) {
{ if (eventPointerCount <= 1 || !listView.getPageListViewListener().isTouchZoom()) {
if (eventPointerCount <= 1 || !listView.getPageListViewListener().isTouchZoom())
{
return true; return true;
} }
isTouchEventIn = true; isTouchEventIn = true;
float previousScale = listView.getZoom(); float previousScale = listView.getZoom();
float zoom = Math.min(Math.max(listView.getZoom() * detector.getScaleFactor(), listView.getFitZoom()), MAX_ZOOM); float zoom = Math.min(Math.max(listView.getZoom() * detector.getScaleFactor(), listView.getFitZoom()), MAX_ZOOM);
if ((int)(zoom * MainConstant.ZOOM_ROUND) != (int)(previousScale * MainConstant.ZOOM_ROUND)) if ((int) (zoom * MainConstant.ZOOM_ROUND) != (int) (previousScale * MainConstant.ZOOM_ROUND)) {
{
isOnScroll = true; isOnScroll = true;
float factor = zoom / previousScale; float factor = zoom / previousScale;
listView.setZoom(zoom, false); listView.setZoom(zoom, false);
APageListItem v = listView.getCurrentPageView(); APageListItem v = listView.getCurrentPageView();
if (v != null) if (v != null) {
{
// Work out the focus point relative to the view top left // Work out the focus point relative to the view top left
int viewFocusX = (int)detector.getFocusX() - (v.getLeft() + mXScroll); int viewFocusX = (int) detector.getFocusX() - (v.getLeft() + mXScroll);
int viewFocusY = (int)detector.getFocusY() - (v.getTop() + mYScroll); int viewFocusY = (int) detector.getFocusY() - (v.getTop() + mYScroll);
// Scroll to maintain the focus point // Scroll to maintain the focus point
mXScroll += viewFocusX - viewFocusX * factor; mXScroll += viewFocusX - viewFocusX * factor;
mYScroll += viewFocusY - viewFocusY * factor; mYScroll += viewFocusY - viewFocusY * factor;
...@@ -302,24 +252,19 @@ public class APageListEventManage implements ...@@ -302,24 +252,19 @@ public class APageListEventManage implements
} }
} }
// 提示 // 提示
if(listView.getPageListViewListener().isShowZoomingMsg()) if (listView.getPageListViewListener().isShowZoomingMsg()) {
{ toast.setText((int) Math.round(zoom * 100) + "%");
toast.setText((int)Math.round(zoom * 100) + "%");
toast.show(); toast.show();
} }
return true; return true;
} }
/** /**
*
* @see android.view.ScaleGestureDetector.OnScaleGestureListener#onScaleBegin(android.view.ScaleGestureDetector) * @see android.view.ScaleGestureDetector.OnScaleGestureListener#onScaleBegin(android.view.ScaleGestureDetector)
*
*/ */
@ Override @Override
public boolean onScaleBegin(ScaleGestureDetector detector) public boolean onScaleBegin(ScaleGestureDetector detector) {
{ if (eventPointerCount <= 1 || !listView.getPageListViewListener().isTouchZoom()) {
if (eventPointerCount <= 1 || !listView.getPageListViewListener().isTouchZoom())
{
return true; return true;
} }
isScaling = true; isScaling = true;
...@@ -327,71 +272,61 @@ public class APageListEventManage implements ...@@ -327,71 +272,61 @@ public class APageListEventManage implements
isProcessOnScroll = false; isProcessOnScroll = false;
return true; return true;
} }
/** /**
*
* @see android.view.ScaleGestureDetector.OnScaleGestureListener#onScaleEnd(android.view.ScaleGestureDetector) * @see android.view.ScaleGestureDetector.OnScaleGestureListener#onScaleEnd(android.view.ScaleGestureDetector)
*
*/ */
@ Override @Override
public void onScaleEnd(ScaleGestureDetector detector) public void onScaleEnd(ScaleGestureDetector detector) {
{ if (eventPointerCount <= 1 || !listView.getPageListViewListener().isTouchZoom()) {
if (eventPointerCount <= 1 || !listView.getPageListViewListener().isTouchZoom())
{
return; return;
} }
isScaling = false; isScaling = false;
} }
/** /**
*
* *
*/ */
public void onShowPress(MotionEvent e) public void onShowPress(MotionEvent e) {
{
listView.getPageListViewListener().onEventMethod(listView, e, null, -1.0f, -1.0f, IPageListViewListener.ON_SHOW_PRESS); listView.getPageListViewListener().onEventMethod(listView, e, null, -1.0f, -1.0f, IPageListViewListener.ON_SHOW_PRESS);
} }
/** /**
*
* *
*/ */
public boolean onSingleTapUp(MotionEvent e) public boolean onSingleTapUp(MotionEvent e) {
{ Log.e("APageListEventManage", "onSingleTapUp");
listView.getPageListViewListener().singleTab();
listView.getPageListViewListener().onEventMethod(listView, e, null, -1.0f, -1.0f, IPageListViewListener.ON_SINGLE_TAP_UP); listView.getPageListViewListener().onEventMethod(listView, e, null, -1.0f, -1.0f, IPageListViewListener.ON_SINGLE_TAP_UP);
return false; return false;
} }
/** /**
*
* *
*/ */
public void onLongPress(MotionEvent e) public void onLongPress(MotionEvent e) {
{
listView.getPageListViewListener().onEventMethod(listView, e, null, -1.0f, -1.0f, IPageListViewListener.ON_LONG_PRESS); listView.getPageListViewListener().onEventMethod(listView, e, null, -1.0f, -1.0f, IPageListViewListener.ON_LONG_PRESS);
} }
/** /**
* *
*/ */
public void onClick(View v) public void onClick(View v) {
{
listView.getPageListViewListener().onEventMethod(listView, null, null, -1.0f, -1.0f, IPageListViewListener.ON_CLICK); listView.getPageListViewListener().onEventMethod(listView, null, null, -1.0f, -1.0f, IPageListViewListener.ON_CLICK);
} }
/** /**
* *
*/ */
public boolean onSingleTapConfirmed(MotionEvent e) public boolean onSingleTapConfirmed(MotionEvent e) {
{
listView.getPageListViewListener().onEventMethod(listView, e, null, -1.0f, -1.0f, IPageListViewListener.ON_SINGLE_TAP_CONFIRMED); listView.getPageListViewListener().onEventMethod(listView, e, null, -1.0f, -1.0f, IPageListViewListener.ON_SINGLE_TAP_CONFIRMED);
return false; return false;
} }
/** /**
* *
*/ */
public boolean onDoubleTap(MotionEvent e) public boolean onDoubleTap(MotionEvent e) {
{
isProcessOnScroll = true; isProcessOnScroll = true;
isTouchEventIn = false; isTouchEventIn = false;
isDoubleTap = true; isDoubleTap = true;
...@@ -402,21 +337,18 @@ public class APageListEventManage implements ...@@ -402,21 +337,18 @@ public class APageListEventManage implements
/** /**
* *
*/ */
public boolean onDoubleTapEvent(MotionEvent e) public boolean onDoubleTapEvent(MotionEvent e) {
{
isTouchEventIn = false; isTouchEventIn = false;
isDoubleTap = true; isDoubleTap = true;
listView.getPageListViewListener().onEventMethod(listView, e, null, -1.0f, -1.0f, IPageListViewListener.ON_DOUBLE_TAP_EVENT); listView.getPageListViewListener().onEventMethod(listView, e, null, -1.0f, -1.0f, IPageListViewListener.ON_DOUBLE_TAP_EVENT);
return false; return false;
} }
/** /**
* *
*/ */
public void run() public void run() {
{ if (!mScroller.isFinished()) {
if (!mScroller.isFinished())
{
listView.getPageListViewListener().setDrawPictrue(false); listView.getPageListViewListener().setDrawPictrue(false);
mScroller.computeScrollOffset(); mScroller.computeScrollOffset();
int x = mScroller.getCurrX(); int x = mScroller.getCurrX();
...@@ -427,9 +359,7 @@ public class APageListEventManage implements ...@@ -427,9 +359,7 @@ public class APageListEventManage implements
mScrollerLastY = y; mScrollerLastY = y;
listView.requestLayout(); listView.requestLayout();
listView.post(this); listView.post(this);
} } else if (!isTouchEventIn) {
else if (!isTouchEventIn)
{
// End of an inertial scroll and the user is not interacting. // End of an inertial scroll and the user is not interacting.
// The layout is stable // The layout is stable
listView.postRepaint(listView.getCurrentPageView()); listView.postRepaint(listView.getCurrentPageView());
...@@ -437,105 +367,87 @@ public class APageListEventManage implements ...@@ -437,105 +367,87 @@ public class APageListEventManage implements
listView.getPageListViewListener().setDrawPictrue(true); listView.getPageListViewListener().setDrawPictrue(true);
} }
} }
/** /**
* *
* @param v
*/ */
protected void slideViewOntoScreen(APageListItem pageItem) protected void slideViewOntoScreen(APageListItem pageItem) {
{
Point corr = listView.getCorrection(listView.getScrollBounds(pageItem)); Point corr = listView.getCorrection(listView.getScrollBounds(pageItem));
if (corr.x != 0 || corr.y != 0) if (corr.x != 0 || corr.y != 0) {
{
mScrollerLastX = mScrollerLastY = 0; mScrollerLastX = mScrollerLastY = 0;
mScroller.startScroll(0, 0, corr.x, corr.y, 400); mScroller.startScroll(0, 0, corr.x, corr.y, 400);
listView.post(this); listView.post(this);
} }
listView.getPageListViewListener().resetSearchResult(pageItem); listView.getPageListViewListener().resetSearchResult(pageItem);
} }
/** /**
* @return Returns the mXScroll. * @return Returns the mXScroll.
*/ */
protected int getScrollX() protected int getScrollX() {
{
return mXScroll; return mXScroll;
} }
/** /**
* @return Returns the mYScroll. * @return Returns the mYScroll.
*/ */
protected int getScrollY() protected int getScrollY() {
{
return mYScroll; return mYScroll;
} }
/** /**
* *
*/ */
protected void setScrollAxisValue(int x, int y) protected void setScrollAxisValue(int x, int y) {
{
mXScroll = x; mXScroll = x;
mYScroll = y; mYScroll = y;
} }
/** /**
* *
*/ */
protected boolean isTouchEventIn() protected boolean isTouchEventIn() {
{
return this.isTouchEventIn; return this.isTouchEventIn;
} }
/** /**
* *
*/ */
protected boolean isScrollerFinished() protected boolean isScrollerFinished() {
{
return mScroller.isFinished(); return mScroller.isFinished();
} }
/** /**
* *
*/ */
protected boolean isOnFling() protected boolean isOnFling() {
{
return this.isOnFling; return this.isOnFling;
} }
/** /**
*
* @param vx * @param vx
* @param vy * @param vy
* @return * @return
*/ */
protected int directionOfTravel(float vx, float vy) protected int directionOfTravel(float vx, float vy) {
{ if (Math.abs(vx) > 2 * Math.abs(vy)) {
if (Math.abs(vx) > 2 * Math.abs(vy))
{
return (vx > 0) ? MOVING_RIGHT : MOVING_LEFT; return (vx > 0) ? MOVING_RIGHT : MOVING_LEFT;
} } else if (Math.abs(vy) > 2 * Math.abs(vx)) {
else if (Math.abs(vy) > 2 * Math.abs(vx))
{
return (vy > 0) ? MOVING_DOWN : MOVING_UP; return (vy > 0) ? MOVING_DOWN : MOVING_UP;
} } else {
else
{
return MOVING_DIAGONALLY; return MOVING_DIAGONALLY;
} }
} }
/** /**
*
* @param bounds * @param bounds
* @param vx * @param vx
* @param vy * @param vy
* @return * @return
*/ */
protected boolean withinBoundsInDirectionOfTravel(Rect bounds, float vx, float vy) protected boolean withinBoundsInDirectionOfTravel(Rect bounds, float vx, float vy) {
{ switch (directionOfTravel(vx, vy)) {
switch (directionOfTravel(vx, vy))
{
case MOVING_DIAGONALLY: case MOVING_DIAGONALLY:
return bounds.contains(0, 0); return bounds.contains(0, 0);
case MOVING_LEFT: case MOVING_LEFT:
...@@ -550,13 +462,12 @@ public class APageListEventManage implements ...@@ -550,13 +462,12 @@ public class APageListEventManage implements
throw new NoSuchElementException(); throw new NoSuchElementException();
} }
} }
/** /**
* *
*/ */
public void dispose() public void dispose() {
{
} }
private boolean isOnFling; private boolean isOnFling;
...@@ -567,7 +478,7 @@ public class APageListEventManage implements ...@@ -567,7 +478,7 @@ public class APageListEventManage implements
// Whether process onScroll event // Whether process onScroll event
private boolean isProcessOnScroll = true; private boolean isProcessOnScroll = true;
// Whether the user is touch event in // Whether the user is touch event in
private boolean isTouchEventIn; private boolean isTouchEventIn;
// Whether the user is currently pinch zooming // Whether the user is currently pinch zooming
private boolean isScaling; private boolean isScaling;
// x axis value of last time // x axis value of last time
......
/* /*
* 文件名称: PDFPageAdapterView.java * 文件名称: PDFPageAdapterView.java
* *
* 编译器: android2.2 * 编译器: android2.2
* 时间: 下午1:49:11 * 时间: 下午1:49:11
*/ */
...@@ -9,6 +9,7 @@ package com.cherry.lib.doc.office.system.beans.pagelist; ...@@ -9,6 +9,7 @@ package com.cherry.lib.doc.office.system.beans.pagelist;
import java.util.LinkedList; import java.util.LinkedList;
import com.cherry.lib.doc.office.constant.MainConstant; import com.cherry.lib.doc.office.constant.MainConstant;
import com.cherry.lib.doc.office.system.IControl;
import com.cherry.lib.doc.office.system.IMainFrame; import com.cherry.lib.doc.office.system.IMainFrame;
import android.content.Context; import android.content.Context;
...@@ -25,82 +26,69 @@ import android.view.ViewParent; ...@@ -25,82 +26,69 @@ import android.view.ViewParent;
import android.widget.Adapter; import android.widget.Adapter;
import android.widget.AdapterView; import android.widget.AdapterView;
public class APageListView extends AdapterView<Adapter> public class APageListView extends AdapterView<Adapter> {
{
private static final int GAP = 20; private static final int GAP = 20;
/** /**
*
* @param context * @param context
*/ */
public APageListView(Context context) public APageListView(Context context) {
{
super(context); super(context);
} }
/** /**
*
* *
*/ */
public APageListView(Context context, IPageListViewListener listener) public APageListView(Context context, IPageListViewListener listener) {
{
super(context); super(context);
this.pageListViewListener = listener; this.pageListViewListener = listener;
eventManage = new APageListEventManage(this); eventManage = new APageListEventManage(this);
pageAdapter = new APageListAdapter(this); pageAdapter = new APageListAdapter(this);
setLongClickable(true); setLongClickable(true);
this.post(new Runnable() this.post(new Runnable() {
{ @Override
@ Override public void run() {
public void run()
{
// get thumbnail, pageListViewListener = null; // get thumbnail, pageListViewListener = null;
if (pageListViewListener != null if (pageListViewListener != null
&& pageListViewListener.isInit()) && pageListViewListener.isInit()) {
{
init(); init();
} }
} }
}); });
} }
/** /**
* *
*/ */
public void init() public void init() {
{
isInit = true; isInit = true;
requestLayout(); requestLayout();
} }
/** /**
*
* *
*/ */
public void requestLayout() public void requestLayout() {
{ if (isDoRequestLayout) {
if (isDoRequestLayout)
{
super.requestLayout(); super.requestLayout();
} }
} }
/** /**
*
* *
*/ */
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
{
super.onMeasure(widthMeasureSpec, heightMeasureSpec); super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int n = getChildCount(); int n = getChildCount();
for (int i = 0; i < n; i++) for (int i = 0; i < n; i++) {
{
View view = getChildAt(i); View view = getChildAt(i);
if (view instanceof APageListItem) if (view instanceof APageListItem) {
{ APageListItem pv = (APageListItem) view;
APageListItem pv = (APageListItem)view; pv.measure(View.MeasureSpec.EXACTLY | (int) (pv.getPageWidth() * zoom),
pv.measure(View.MeasureSpec.EXACTLY | (int)(pv.getPageWidth() * zoom), View.MeasureSpec.EXACTLY | (int) (pv.getPageHeight() * zoom));
View.MeasureSpec.EXACTLY | (int)(pv.getPageHeight() * zoom));
} }
} }
} }
...@@ -110,111 +98,90 @@ public class APageListView extends AdapterView<Adapter> ...@@ -110,111 +98,90 @@ public class APageListView extends AdapterView<Adapter>
* you were just added to the view hierarchy, you're called with the old * you were just added to the view hierarchy, you're called with the old
* values of 0. * values of 0.
* *
* @param w Current width of this view. * @param w Current width of this view.
* @param h Current height of this view. * @param h Current height of this view.
* @param oldw Old width of this view. * @param oldw Old width of this view.
* @param oldh Old height of this view. * @param oldh Old height of this view.
*/ */
protected void onSizeChanged(int w, int h, int oldw, int oldh) protected void onSizeChanged(int w, int h, int oldw, int oldh) {
{
super.onSizeChanged(w, h, oldw, oldh); super.onSizeChanged(w, h, oldw, oldh);
if (isConfigurationChanged) if (isConfigurationChanged) {
{ float fitZoom = getFitZoom();
float fitZoom = getFitZoom(); if (zoom < fitZoom) {
if(zoom < fitZoom) setZoom(fitZoom, false);
{ isInit = false;
setZoom(fitZoom, false); postDelayed(new Runnable() {
isInit = false;
postDelayed(new Runnable()
{
/** /**
* *
*/ */
public void run() public void run() {
{ isInit = true;
isInit = true; isResetLayout = true;
isResetLayout = true;
requestLayout(); requestLayout();
} }
}, 1); }, 1);
pageListViewListener.changeZoom(); pageListViewListener.changeZoom();
} }
} }
} }
/** /**
* *
*/ */
public boolean onTouchEvent(MotionEvent event) public boolean onTouchEvent(MotionEvent event) {
{ APageListItem pageView = getCurrentPageView();
APageListItem pageView = getCurrentPageView(); if (pageView != null) {
if (pageView != null) if (pageView.getControl().getSysKit().getCalloutManager().getDrawingMode() != MainConstant.DRAWMODE_NORMAL) {
{ return false;
if (pageView.getControl().getSysKit().getCalloutManager().getDrawingMode() != MainConstant.DRAWMODE_NORMAL) }
{
return false; }
}
}
eventManage.processOnTouch(event); eventManage.processOnTouch(event);
pageListViewListener.onEventMethod(this, event, null, -1, -1, IMainFrame.ON_TOUCH); pageListViewListener.onEventMethod(this, event, null, -1, -1, IMainFrame.ON_TOUCH);
return true; return true;
} }
/** /**
*
* @see android.widget.AdapterView#onLayout(boolean, int, int, int, int) * @see android.widget.AdapterView#onLayout(boolean, int, int, int, int)
*
*/ */
@ Override @Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
{
super.onLayout(changed, left, top, right, bottom); super.onLayout(changed, left, top, right, bottom);
if (!isInit) if (!isInit) {
{
return; return;
}
if(pageListViewListener.getPageListViewMovingPosition() == IPageListViewListener.Moving_Horizontal)
{
layout_Horizontal();
} }
else
{ if (pageListViewListener.getPageListViewMovingPosition() == IPageListViewListener.Moving_Horizontal) {
layout_Vertical(); layout_Horizontal();
} else {
layout_Vertical();
} }
invalidate(); invalidate();
if (isConfigurationChanged) if (isConfigurationChanged) {
{
isConfigurationChanged = false; isConfigurationChanged = false;
APageListItem pageView = getCurrentPageView(); APageListItem pageView = getCurrentPageView();
if (pageView != null) if (pageView != null) {
{
postRepaint(pageView); postRepaint(pageView);
} }
} }
} }
private void layout_Horizontal() private void layout_Horizontal() {
{ APageListItem currentView = childViewsCache.get(currentIndex);
APageListItem currentView = childViewsCache.get(currentIndex);
Point cvOffset; Point cvOffset;
if (!isResetLayout) if (!isResetLayout) {
{
// Move to next or previous if current is sufficiently off center // Move to next or previous if current is sufficiently off center
if (currentView != null && Math.abs(currentView.getLeft()) < currentView.getWidth()) if (currentView != null && Math.abs(currentView.getLeft()) < currentView.getWidth()) {
{
cvOffset = getScreenSizeOffset(currentView); cvOffset = getScreenSizeOffset(currentView);
// next page // next page
if (currentView.getLeft() + currentView.getMeasuredWidth() if (currentView.getLeft() + currentView.getMeasuredWidth()
+ cvOffset.x + GAP / 2 + eventManage.getScrollX() < getWidth() / 2 + cvOffset.x + GAP / 2 + eventManage.getScrollX() < getWidth() / 2
&& currentIndex + 1 < pageAdapter.getCount() && currentIndex + 1 < pageAdapter.getCount()
&& !eventManage.isOnFling()) && !eventManage.isOnFling()) {
{
postUnRepaint(currentView); postUnRepaint(currentView);
post(eventManage); post(eventManage);
currentIndex++; currentIndex++;
...@@ -222,9 +189,8 @@ public class APageListView extends AdapterView<Adapter> ...@@ -222,9 +189,8 @@ public class APageListView extends AdapterView<Adapter>
} }
// previous page // previous page
else if (currentView.getLeft() - cvOffset.x - GAP / 2 + eventManage.getScrollX() >= getWidth() / 2 else if (currentView.getLeft() - cvOffset.x - GAP / 2 + eventManage.getScrollX() >= getWidth() / 2
&& currentIndex > 0 && currentIndex > 0
&& !eventManage.isOnFling()) && !eventManage.isOnFling()) {
{
postUnRepaint(currentView); postUnRepaint(currentView);
post(eventManage); post(eventManage);
currentIndex--; currentIndex--;
...@@ -235,39 +201,31 @@ public class APageListView extends AdapterView<Adapter> ...@@ -235,39 +201,31 @@ public class APageListView extends AdapterView<Adapter>
// Remove not needed children and hold them for reuse // Remove not needed children and hold them for reuse
int numChildren = childViewsCache.size(); int numChildren = childViewsCache.size();
int pIndexs[] = new int[numChildren]; int pIndexs[] = new int[numChildren];
for (int i = 0; i < numChildren; i++) for (int i = 0; i < numChildren; i++) {
{
pIndexs[i] = childViewsCache.keyAt(i); pIndexs[i] = childViewsCache.keyAt(i);
} }
for (int i = 0; i < numChildren; i++) for (int i = 0; i < numChildren; i++) {
{ if (pIndexs[i] < currentIndex - 1 || pIndexs[i] > currentIndex + 1) {
if ( pIndexs[i] < currentIndex - 1 || pIndexs[i] > currentIndex + 1) APageListItem pv = childViewsCache.get(pIndexs[i]);
{
APageListItem pv = childViewsCache.get( pIndexs[i]);
pv.releaseResources(); pv.releaseResources();
pageViewCache.add(pv); pageViewCache.add(pv);
removeViewInLayout(pv); removeViewInLayout(pv);
childViewsCache.remove(pIndexs[i]); childViewsCache.remove(pIndexs[i]);
} }
} }
} } else {
else
{
isResetLayout = false; isResetLayout = false;
boolean isRepaint = false; boolean isRepaint = false;
eventManage.setScrollAxisValue(0, 0); eventManage.setScrollAxisValue(0, 0);
// Remove not needed children and hold them for reuse // Remove not needed children and hold them for reuse
int numChildren = childViewsCache.size(); int numChildren = childViewsCache.size();
int pIndexs[] = new int[numChildren]; int pIndexs[] = new int[numChildren];
for (int i = 0; i < numChildren; i++) for (int i = 0; i < numChildren; i++) {
{
pIndexs[i] = childViewsCache.keyAt(i); pIndexs[i] = childViewsCache.keyAt(i);
} }
for (int i = 0; i < numChildren; i++) for (int i = 0; i < numChildren; i++) {
{ if (pIndexs[i] < currentIndex - 1 || pIndexs[i] > currentIndex + 1) {
if ( pIndexs[i] < currentIndex - 1 || pIndexs[i] > currentIndex + 1) APageListItem pv = childViewsCache.get(pIndexs[i]);
{
APageListItem pv = childViewsCache.get( pIndexs[i]);
pv.releaseResources(); pv.releaseResources();
pageViewCache.add(pv); pageViewCache.add(pv);
removeViewInLayout(pv); removeViewInLayout(pv);
...@@ -275,8 +233,7 @@ public class APageListView extends AdapterView<Adapter> ...@@ -275,8 +233,7 @@ public class APageListView extends AdapterView<Adapter>
isRepaint = pIndexs[i] == currentIndex; isRepaint = pIndexs[i] == currentIndex;
} }
} }
if ((int)(zoom * 100) != 100 || !isRepaint) if ((int) (zoom * 100) != 100 || !isRepaint) {
{
post(eventManage); post(eventManage);
} }
} }
...@@ -289,14 +246,11 @@ public class APageListView extends AdapterView<Adapter> ...@@ -289,14 +246,11 @@ public class APageListView extends AdapterView<Adapter>
// offset it to center within the screen area, and to keep // offset it to center within the screen area, and to keep
// the views spaced out // the views spaced out
cvOffset = getScreenSizeOffset(currentView); cvOffset = getScreenSizeOffset(currentView);
if (notPresent) if (notPresent) {
{
//Main item not already present. Just place it top left //Main item not already present. Just place it top left
cvLeft = cvOffset.x; cvLeft = cvOffset.x;
cvTop = cvOffset.y; cvTop = cvOffset.y;
} } else {
else
{
// Main item already present. Adjust by scroll offsets // Main item already present. Adjust by scroll offsets
cvLeft = currentView.getLeft() + eventManage.getScrollX(); cvLeft = currentView.getLeft() + eventManage.getScrollX();
cvTop = currentView.getTop() + eventManage.getScrollY(); cvTop = currentView.getTop() + eventManage.getScrollY();
...@@ -306,16 +260,13 @@ public class APageListView extends AdapterView<Adapter> ...@@ -306,16 +260,13 @@ public class APageListView extends AdapterView<Adapter>
cvRight = cvLeft + currentView.getMeasuredWidth(); cvRight = cvLeft + currentView.getMeasuredWidth();
cvBottom = cvTop + currentView.getMeasuredHeight(); cvBottom = cvTop + currentView.getMeasuredHeight();
if (!eventManage.isTouchEventIn() && eventManage.isScrollerFinished()) if (!eventManage.isTouchEventIn() && eventManage.isScrollerFinished()) {
{
Point corr = getCorrection(getScrollBounds(cvLeft, cvTop, cvRight, cvBottom)); Point corr = getCorrection(getScrollBounds(cvLeft, cvTop, cvRight, cvBottom));
cvRight += corr.x; cvRight += corr.x;
cvLeft += corr.x; cvLeft += corr.x;
cvTop += corr.y; cvTop += corr.y;
cvBottom += corr.y; cvBottom += corr.y;
} } else if (currentView.getMeasuredHeight() <= getHeight()) {
else if (currentView.getMeasuredHeight() <= getHeight())
{
// When the current view is as small as the screen in height, clamp // When the current view is as small as the screen in height, clamp
// it vertically // it vertically
Point corr = getCorrection(getScrollBounds(cvLeft, cvTop, cvRight, cvBottom)); Point corr = getCorrection(getScrollBounds(cvLeft, cvTop, cvRight, cvBottom));
...@@ -326,46 +277,40 @@ public class APageListView extends AdapterView<Adapter> ...@@ -326,46 +277,40 @@ public class APageListView extends AdapterView<Adapter>
currentView.layout(cvLeft, cvTop, cvRight, cvBottom); currentView.layout(cvLeft, cvTop, cvRight, cvBottom);
// previous page // previous page
if (currentIndex > 0) if (currentIndex > 0) {
{
View preView = createPageView(currentIndex - 1); View preView = createPageView(currentIndex - 1);
Point leftOffset = getScreenSizeOffset(preView); Point leftOffset = getScreenSizeOffset(preView);
int gap = leftOffset.x + GAP + cvOffset.x; int gap = leftOffset.x + GAP + cvOffset.x;
preView.layout(cvLeft - preView.getMeasuredWidth() - gap, preView.layout(cvLeft - preView.getMeasuredWidth() - gap,
(cvBottom + cvTop - preView.getMeasuredHeight()) / 2, cvLeft - gap, (cvBottom + cvTop - preView.getMeasuredHeight()) / 2, cvLeft - gap,
(cvBottom + cvTop + preView.getMeasuredHeight()) / 2); (cvBottom + cvTop + preView.getMeasuredHeight()) / 2);
} }
// next page // next page
if (currentIndex + 1 < pageAdapter.getCount()) if (currentIndex + 1 < pageAdapter.getCount()) {
{
View nextView = createPageView(currentIndex + 1); View nextView = createPageView(currentIndex + 1);
Point rightOffset = getScreenSizeOffset(nextView); Point rightOffset = getScreenSizeOffset(nextView);
int gap = cvOffset.x + GAP + rightOffset.x; int gap = cvOffset.x + GAP + rightOffset.x;
nextView.layout(cvRight + gap, nextView.layout(cvRight + gap,
(cvBottom + cvTop - nextView.getMeasuredHeight()) / 2, (cvBottom + cvTop - nextView.getMeasuredHeight()) / 2,
cvRight + nextView.getMeasuredWidth() + gap, cvRight + nextView.getMeasuredWidth() + gap,
(cvBottom + cvTop + nextView.getMeasuredHeight()) / 2); (cvBottom + cvTop + nextView.getMeasuredHeight()) / 2);
} }
} }
private void layout_Vertical() private void layout_Vertical() {
{ APageListItem currentView = childViewsCache.get(currentIndex);
APageListItem currentView = childViewsCache.get(currentIndex);
Point cvOffset; Point cvOffset;
if (!isResetLayout) if (!isResetLayout) {
{
// Move to next or previous if current is sufficiently off center // Move to next or previous if current is sufficiently off center
if (currentView != null /*&& Math.abs(currentView.getTop()) < currentView.getHeight()*/) if (currentView != null /*&& Math.abs(currentView.getTop()) < currentView.getHeight()*/) {
{
cvOffset = getScreenSizeOffset(currentView); cvOffset = getScreenSizeOffset(currentView);
// next page // next page
if (currentView.getTop() + currentView.getMeasuredHeight() if (currentView.getTop() + currentView.getMeasuredHeight()
+ cvOffset.y + GAP / 2 + eventManage.getScrollY() < getHeight() / 2 + cvOffset.y + GAP / 2 + eventManage.getScrollY() < getHeight() / 2
&& currentIndex + 1 < pageAdapter.getCount() && currentIndex + 1 < pageAdapter.getCount()
&& !eventManage.isOnFling()) && !eventManage.isOnFling()) {
{
postUnRepaint(currentView); postUnRepaint(currentView);
post(eventManage); post(eventManage);
currentIndex++; currentIndex++;
...@@ -373,52 +318,43 @@ public class APageListView extends AdapterView<Adapter> ...@@ -373,52 +318,43 @@ public class APageListView extends AdapterView<Adapter>
} }
// previous page // previous page
else if (currentView.getTop() - cvOffset.y - GAP / 2 + eventManage.getScrollY() >= getHeight() / 2 else if (currentView.getTop() - cvOffset.y - GAP / 2 + eventManage.getScrollY() >= getHeight() / 2
&& currentIndex > 0 && currentIndex > 0
&& !eventManage.isOnFling()) && !eventManage.isOnFling()) {
{
postUnRepaint(currentView); postUnRepaint(currentView);
post(eventManage); post(eventManage);
currentIndex--; currentIndex--;
Log.e("current --", String.valueOf(currentIndex)); Log.e("current --", String.valueOf(currentIndex));
} }
} }
// Remove not needed children and hold them for reuse // Remove not needed children and hold them for reuse
int numChildren = childViewsCache.size(); int numChildren = childViewsCache.size();
int pIndexs[] = new int[numChildren]; int pIndexs[] = new int[numChildren];
for (int i = 0; i < numChildren; i++) for (int i = 0; i < numChildren; i++) {
{
pIndexs[i] = childViewsCache.keyAt(i); pIndexs[i] = childViewsCache.keyAt(i);
} }
for (int i = 0; i < numChildren; i++) for (int i = 0; i < numChildren; i++) {
{ if (pIndexs[i] < currentIndex - 1 || pIndexs[i] > currentIndex + 1) {
if ( pIndexs[i] < currentIndex - 1 || pIndexs[i] > currentIndex + 1) APageListItem pv = childViewsCache.get(pIndexs[i]);
{
APageListItem pv = childViewsCache.get( pIndexs[i]);
pv.releaseResources(); pv.releaseResources();
pageViewCache.add(pv); pageViewCache.add(pv);
removeViewInLayout(pv); removeViewInLayout(pv);
childViewsCache.remove(pIndexs[i]); childViewsCache.remove(pIndexs[i]);
} }
} }
} } else {
else
{
isResetLayout = false; isResetLayout = false;
boolean isRepaint = false; boolean isRepaint = false;
eventManage.setScrollAxisValue(0, 0); eventManage.setScrollAxisValue(0, 0);
// Remove not needed children and hold them for reuse // Remove not needed children and hold them for reuse
int numChildren = childViewsCache.size(); int numChildren = childViewsCache.size();
int pIndexs[] = new int[numChildren]; int pIndexs[] = new int[numChildren];
for (int i = 0; i < numChildren; i++) for (int i = 0; i < numChildren; i++) {
{
pIndexs[i] = childViewsCache.keyAt(i); pIndexs[i] = childViewsCache.keyAt(i);
} }
for (int i = 0; i < numChildren; i++) for (int i = 0; i < numChildren; i++) {
{ if (pIndexs[i] < currentIndex - 1 || pIndexs[i] > currentIndex + 1) {
if ( pIndexs[i] < currentIndex - 1 || pIndexs[i] > currentIndex + 1) APageListItem pv = childViewsCache.get(pIndexs[i]);
{
APageListItem pv = childViewsCache.get( pIndexs[i]);
pv.releaseResources(); pv.releaseResources();
pageViewCache.add(pv); pageViewCache.add(pv);
removeViewInLayout(pv); removeViewInLayout(pv);
...@@ -426,9 +362,8 @@ public class APageListView extends AdapterView<Adapter> ...@@ -426,9 +362,8 @@ public class APageListView extends AdapterView<Adapter>
isRepaint = pIndexs[i] == currentIndex; isRepaint = pIndexs[i] == currentIndex;
} }
} }
if ((int)(zoom * 100) != 100 || !isRepaint) if ((int) (zoom * 100) != 100 || !isRepaint) {
{
post(eventManage); post(eventManage);
} }
} }
...@@ -441,14 +376,11 @@ public class APageListView extends AdapterView<Adapter> ...@@ -441,14 +376,11 @@ public class APageListView extends AdapterView<Adapter>
// offset it to center within the screen area, and to keep // offset it to center within the screen area, and to keep
// the views spaced out // the views spaced out
cvOffset = getScreenSizeOffset(currentView); cvOffset = getScreenSizeOffset(currentView);
if (notPresent) if (notPresent) {
{
//Main item not already present. Just place it top left //Main item not already present. Just place it top left
cvLeft = cvOffset.x; cvLeft = cvOffset.x;
cvTop = cvOffset.y; cvTop = cvOffset.y;
} } else {
else
{
// Main item already present. Adjust by scroll offsets // Main item already present. Adjust by scroll offsets
cvLeft = currentView.getLeft() + eventManage.getScrollX(); cvLeft = currentView.getLeft() + eventManage.getScrollX();
cvTop = currentView.getTop() + eventManage.getScrollY(); cvTop = currentView.getTop() + eventManage.getScrollY();
...@@ -458,16 +390,13 @@ public class APageListView extends AdapterView<Adapter> ...@@ -458,16 +390,13 @@ public class APageListView extends AdapterView<Adapter>
cvRight = cvLeft + currentView.getMeasuredWidth(); cvRight = cvLeft + currentView.getMeasuredWidth();
cvBottom = cvTop + currentView.getMeasuredHeight(); cvBottom = cvTop + currentView.getMeasuredHeight();
if (!eventManage.isTouchEventIn() && eventManage.isScrollerFinished()) if (!eventManage.isTouchEventIn() && eventManage.isScrollerFinished()) {
{
Point corr = getCorrection(getScrollBounds(cvLeft, cvTop, cvRight, cvBottom)); Point corr = getCorrection(getScrollBounds(cvLeft, cvTop, cvRight, cvBottom));
cvRight += corr.x; cvRight += corr.x;
cvLeft += corr.x; cvLeft += corr.x;
cvTop += corr.y; cvTop += corr.y;
cvBottom += corr.y; cvBottom += corr.y;
} } else if (currentView.getMeasuredWidth() <= getWidth()) {
else if (currentView.getMeasuredWidth() <= getWidth())
{
// When the current view is as small as the screen in height, clamp // When the current view is as small as the screen in height, clamp
// it vertically // it vertically
Point corr = getCorrection(getScrollBounds(cvLeft, cvTop, cvRight, cvBottom)); Point corr = getCorrection(getScrollBounds(cvLeft, cvTop, cvRight, cvBottom));
...@@ -478,62 +407,54 @@ public class APageListView extends AdapterView<Adapter> ...@@ -478,62 +407,54 @@ public class APageListView extends AdapterView<Adapter>
currentView.layout(cvLeft, cvTop, cvRight, cvBottom); currentView.layout(cvLeft, cvTop, cvRight, cvBottom);
// previous page // previous page
if (currentIndex > 0) if (currentIndex > 0) {
{
View preView = createPageView(currentIndex - 1); View preView = createPageView(currentIndex - 1);
Point leftOffset = getScreenSizeOffset(preView); Point leftOffset = getScreenSizeOffset(preView);
int gap = leftOffset.y + GAP + cvOffset.y; int gap = leftOffset.y + GAP + cvOffset.y;
preView.layout(cvLeft, preView.layout(cvLeft,
cvTop - gap - preView.getMeasuredHeight(), cvTop - gap - preView.getMeasuredHeight(),
cvRight, cvRight,
cvBottom - gap - preView.getMeasuredHeight()); cvBottom - gap - preView.getMeasuredHeight());
} }
// next page // next page
if (currentIndex + 1 < pageAdapter.getCount()) if (currentIndex + 1 < pageAdapter.getCount()) {
{
View nextView = createPageView(currentIndex + 1); View nextView = createPageView(currentIndex + 1);
Point rightOffset = getScreenSizeOffset(nextView); Point rightOffset = getScreenSizeOffset(nextView);
int gap = cvOffset.y + GAP + rightOffset.y; int gap = cvOffset.y + GAP + rightOffset.y;
nextView.layout(cvLeft, nextView.layout(cvLeft,
cvTop + gap + nextView.getMeasuredHeight(), cvTop + gap + nextView.getMeasuredHeight(),
cvRight, cvRight,
cvBottom + gap + nextView.getMeasuredHeight()); cvBottom + gap + nextView.getMeasuredHeight());
} }
} }
/** /**
*
* *
*/ */
public void onConfigurationChanged(Configuration newConfig) public void onConfigurationChanged(Configuration newConfig) {
{
super.onConfigurationChanged(newConfig); super.onConfigurationChanged(newConfig);
isConfigurationChanged = true; isConfigurationChanged = true;
} }
/** /**
* switch page for page index (base 0) * switch page for page index (base 0)
* *
* @param index * @param index
*/ */
public void showPDFPageForIndex(final int index) public void showPDFPageForIndex(final int index) {
{ if (index < 0 || index >= pageAdapter.getCount()) {
if (index < 0 || index >= pageAdapter.getCount())
{
return; return;
} }
currentIndex = index; currentIndex = index;
postDelayed(new Runnable() postDelayed(new Runnable() {
{
int gotoIndex = index; int gotoIndex = index;
/** /**
* *
*/ */
public void run() public void run() {
{ if (gotoIndex == currentIndex) {
if (gotoIndex == currentIndex)
{
isResetLayout = true; isResetLayout = true;
requestLayout(); requestLayout();
} }
...@@ -541,32 +462,25 @@ public class APageListView extends AdapterView<Adapter> ...@@ -541,32 +462,25 @@ public class APageListView extends AdapterView<Adapter>
}, 1); }, 1);
pageListViewListener.updateStutus(null); pageListViewListener.updateStutus(null);
} }
/** /**
* *
*/ */
public void nextPageView() public void nextPageView() {
{ if (currentIndex + 1 >= pageAdapter.getCount()) {
if (currentIndex + 1 >= pageAdapter.getCount())
{
return; return;
} }
APageListItem pageView = childViewsCache.get(currentIndex + 1); APageListItem pageView = childViewsCache.get(currentIndex + 1);
if (pageView != null) if (pageView != null) {
{
currentIndex++; currentIndex++;
eventManage.slideViewOntoScreen(pageView); eventManage.slideViewOntoScreen(pageView);
} } else {
else postDelayed(new Runnable() {
{
postDelayed(new Runnable()
{
/** /**
* *
*/ */
public void run() public void run() {
{ isResetLayout = true;
isResetLayout = true;
requestLayout(); requestLayout();
} }
}, 1); }, 1);
...@@ -575,104 +489,83 @@ public class APageListView extends AdapterView<Adapter> ...@@ -575,104 +489,83 @@ public class APageListView extends AdapterView<Adapter>
} }
/** /**
* *
*/ */
public void previousPageview() public void previousPageview() {
{ if (currentIndex == 0) {
if (currentIndex == 0)
{
return; return;
} }
APageListItem pageView = childViewsCache.get(currentIndex - 1); APageListItem pageView = childViewsCache.get(currentIndex - 1);
if (pageView != null) if (pageView != null) {
{
currentIndex--; currentIndex--;
eventManage.slideViewOntoScreen(pageView); eventManage.slideViewOntoScreen(pageView);
} }
} }
/** /**
* *
*/ */
public void exportImage(final APageListItem view, final Bitmap srcBitmap) public void exportImage(final APageListItem view, final Bitmap srcBitmap) {
{
if (view.getPageIndex() != currentIndex || eventManage.isTouchEventIn() if (view.getPageIndex() != currentIndex || eventManage.isTouchEventIn()
|| !eventManage.isScrollerFinished()) || !eventManage.isScrollerFinished()) {
{
return; return;
} }
pageListViewListener.exportImage(view, srcBitmap); pageListViewListener.exportImage(view, srcBitmap);
} }
/** /**
* * @param x is don't zoom
* @param x is don't zoom * @param y is don't zoom
* @param y is don't zoom
* @return * @return
*/ */
public boolean isPointVisibleOnScreen(int x, int y) public boolean isPointVisibleOnScreen(int x, int y) {
{ x = (int) (x * zoom);
x = (int)(x * zoom); y = (int) (y * zoom);
y = (int)(y * zoom);
APageListItem item = getCurrentPageView(); APageListItem item = getCurrentPageView();
if (item == null) if (item == null) {
{
return false; return false;
} }
int left = Math.max(item.getLeft(), 0) - item.getLeft(); int left = Math.max(item.getLeft(), 0) - item.getLeft();
int top = Math.max(item.getTop(), 0) - item.getTop(); int top = Math.max(item.getTop(), 0) - item.getTop();
return left < left + getWidth() && top < top + getHeight() return left < left + getWidth() && top < top + getHeight()
&& x >= left && x < left + getWidth() && y >= top && y < top + getHeight(); && x >= left && x < left + getWidth() && y >= top && y < top + getHeight();
} }
/** /**
* * @param x is don't zoom
* @param x is don't zoom * @param y is don't zoom
* @param y is don't zoom
* @return * @return
*/ */
public void setItemPointVisibleOnScreen(int x, int y) public void setItemPointVisibleOnScreen(int x, int y) {
{ if (x < 0 && y < 0) {
if (x < 0 && y < 0) return;
{
return ;
} }
APageListItem item = getCurrentPageView(); APageListItem item = getCurrentPageView();
if (item != null && !isPointVisibleOnScreen(x, y)) if (item != null && !isPointVisibleOnScreen(x, y)) {
{ x = (int) (x * zoom);
x = (int)(x * zoom); y = (int) (y * zoom);
y = (int)(y * zoom);
int cvLeft = 0, cvRight = 0, cvTop = 0, cvBottom = 0; int cvLeft = 0, cvRight = 0, cvTop = 0, cvBottom = 0;
if (x > 0) if (x > 0) {
{ if (x + getWidth() > item.getMeasuredWidth()) {
if (x + getWidth() > item.getMeasuredWidth())
{
cvLeft = -(item.getMeasuredWidth() - getWidth()); cvLeft = -(item.getMeasuredWidth() - getWidth());
} } else {
else cvLeft = -x;
{
cvLeft = -x;
} }
} }
if (y > 0) if (y > 0) {
{ if (y + getHeight() > item.getMeasuredHeight()) {
if (y + getHeight() > item.getMeasuredHeight())
{
cvTop = -(item.getMeasuredHeight() - getHeight()); cvTop = -(item.getMeasuredHeight() - getHeight());
} else {
cvTop = -y;
} }
else }
{
cvTop = -y;
}
}
// current page // current page
Point cvOffset = getScreenSizeOffset(item); Point cvOffset = getScreenSizeOffset(item);
cvRight = cvLeft + item.getMeasuredWidth(); cvRight = cvLeft + item.getMeasuredWidth();
cvBottom = cvTop + item.getMeasuredHeight(); cvBottom = cvTop + item.getMeasuredHeight();
if (item.getMeasuredHeight() <= getHeight()) if (item.getMeasuredHeight() <= getHeight()) {
{
Point corr = getCorrection(getScrollBounds(cvLeft, cvTop, cvRight, cvBottom)); Point corr = getCorrection(getScrollBounds(cvLeft, cvTop, cvRight, cvBottom));
cvTop += corr.y; cvTop += corr.y;
cvBottom += corr.y; cvBottom += corr.y;
...@@ -680,110 +573,90 @@ public class APageListView extends AdapterView<Adapter> ...@@ -680,110 +573,90 @@ public class APageListView extends AdapterView<Adapter>
item.layout(cvLeft, cvTop, cvRight, cvBottom); item.layout(cvLeft, cvTop, cvRight, cvBottom);
// previous page // previous page
if (currentIndex > 0) if (currentIndex > 0) {
{
View preView = childViewsCache.get(currentIndex - 1); View preView = childViewsCache.get(currentIndex - 1);
if (preView != null) if (preView != null) {
{
Point leftOffset = getScreenSizeOffset(preView); Point leftOffset = getScreenSizeOffset(preView);
int gap = leftOffset.x + GAP + cvOffset.x; int gap = leftOffset.x + GAP + cvOffset.x;
preView.layout(cvLeft - preView.getMeasuredWidth() - gap, preView.layout(cvLeft - preView.getMeasuredWidth() - gap,
(cvBottom + cvTop - preView.getMeasuredHeight()) / 2, cvLeft - gap, (cvBottom + cvTop - preView.getMeasuredHeight()) / 2, cvLeft - gap,
(cvBottom + cvTop + preView.getMeasuredHeight()) / 2); (cvBottom + cvTop + preView.getMeasuredHeight()) / 2);
} }
} }
// next page // next page
if (currentIndex + 1 < pageAdapter.getCount()) if (currentIndex + 1 < pageAdapter.getCount()) {
{
View nextView = childViewsCache.get(currentIndex + 1); View nextView = childViewsCache.get(currentIndex + 1);
if (nextView != null) if (nextView != null) {
{
Point rightOffset = getScreenSizeOffset(nextView); Point rightOffset = getScreenSizeOffset(nextView);
int gap = cvOffset.x + GAP + rightOffset.x; int gap = cvOffset.x + GAP + rightOffset.x;
nextView.layout(cvRight + gap, nextView.layout(cvRight + gap,
(cvBottom + cvTop - nextView.getMeasuredHeight()) / 2, (cvBottom + cvTop - nextView.getMeasuredHeight()) / 2,
cvRight + nextView.getMeasuredWidth() + gap, cvRight + nextView.getMeasuredWidth() + gap,
(cvBottom + cvTop + nextView.getMeasuredHeight()) / 2); (cvBottom + cvTop + nextView.getMeasuredHeight()) / 2);
} }
} }
postRepaint(item); postRepaint(item);
} }
} }
/** /**
* *
*/ */
public Object getModel() public Object getModel() {
{
return pageListViewListener.getModel(); return pageListViewListener.getModel();
} }
/** /**
*
* @return * @return
*/ */
public int getDisplayedPageIndex() public int getDisplayedPageIndex() {
{
return currentIndex; return currentIndex;
} }
/** /**
*
* *
*/ */
public void setZoom(float zoom, int pointX, int pointY) public void setZoom(float zoom, int pointX, int pointY) {
{
setZoom(zoom, pointX, pointY, true); setZoom(zoom, pointX, pointY, true);
} }
public void setZoom(float zoomValue, final boolean isRepaint) public void setZoom(float zoomValue, final boolean isRepaint) {
{
setZoom(zoomValue, Integer.MIN_VALUE, Integer.MIN_VALUE, isRepaint); setZoom(zoomValue, Integer.MIN_VALUE, Integer.MIN_VALUE, isRepaint);
} }
/** /**
*
* *
*/ */
public void setZoom(float zoomValue, int pointX, int pointY, final boolean isRepaint) public void setZoom(float zoomValue, int pointX, int pointY, final boolean isRepaint) {
{ if ((int) (zoomValue * MainConstant.ZOOM_ROUND) == (int) (this.zoom * MainConstant.ZOOM_ROUND)) {
if ((int)(zoomValue * MainConstant.ZOOM_ROUND) == (int)(this.zoom * MainConstant.ZOOM_ROUND))
{
return; return;
} }
isInitZoom = true; isInitZoom = true;
if(pointX == Integer.MIN_VALUE && pointY == Integer.MIN_VALUE) if (pointX == Integer.MIN_VALUE && pointY == Integer.MIN_VALUE) {
{
pointX = getWidth() / 2; pointX = getWidth() / 2;
pointY = getHeight() / 2; pointY = getHeight() / 2;
} }
float oldZoom = zoom; float oldZoom = zoom;
zoom = zoomValue; zoom = zoomValue;
pageListViewListener.changeZoom(); pageListViewListener.changeZoom();
post(new Runnable() post(new Runnable() {
{ @Override
@ Override public void run() {
public void run() if (isRepaint) {
{
if (isRepaint)
{
APageListItem pageView = getCurrentPageView(); APageListItem pageView = getCurrentPageView();
if (pageView != null) if (pageView != null) {
{
postRepaint(pageView); postRepaint(pageView);
} }
} }
} }
}); });
if (isRepaint) if (isRepaint) {
{
APageListItem v = getCurrentPageView(); APageListItem v = getCurrentPageView();
int left = 0; int left = 0;
int top = 0; int top = 0;
if (v != null) if (v != null) {
{
left = v.getLeft(); left = v.getLeft();
top = v.getTop(); top = v.getTop();
} }
...@@ -792,287 +665,233 @@ public class APageListView extends AdapterView<Adapter> ...@@ -792,287 +665,233 @@ public class APageListView extends AdapterView<Adapter>
int viewFocusX = pointX - (left + eventManage.getScrollX()); int viewFocusX = pointX - (left + eventManage.getScrollX());
int viewFocusY = pointY - (top + eventManage.getScrollY()); int viewFocusY = pointY - (top + eventManage.getScrollY());
// Scroll to maintain the focus point // Scroll to maintain the focus point
eventManage.setScrollAxisValue((int)(viewFocusX - viewFocusX * factor), eventManage.setScrollAxisValue((int) (viewFocusX - viewFocusX * factor),
(int)(viewFocusY - viewFocusY * factor)); (int) (viewFocusY - viewFocusY * factor));
requestLayout(); requestLayout();
} }
} }
/** /**
* set fit size for PPT,Word view mode, PDf * set fit size for PPT,Word view mode, PDf
* *
* @param value fit size mode * @param value fit size mode
* = 0, fit size of get minimum value of pageWidth / viewWidth and pageHeight / viewHeight; * = 0, fit size of get minimum value of pageWidth / viewWidth and pageHeight / viewHeight;
* = 1, fit size of pageWidth * = 1, fit size of pageWidth
* = 2, fit size of PageHeight * = 2, fit size of PageHeight
*/ */
public void setFitSize(int value) public void setFitSize(int value) {
{
setZoom(getFitZoom(value), true); setZoom(getFitZoom(value), true);
postInvalidate(); postInvalidate();
} }
/** /**
* get fit size statue * get fit size statue
* *
* @return fit size statue * @return fit size statue
* = 0, left/right and top/bottom don't alignment * = 0, left/right and top/bottom don't alignment
* = 1, top/bottom alignment * = 1, top/bottom alignment
* = 2, left/right alignment * = 2, left/right alignment
* = 3, left/right and top/bottom alignment * = 3, left/right and top/bottom alignment
*/ */
public int getFitSizeState() public int getFitSizeState() {
{
int state = 0; int state = 0;
APageListItem item = getCurrentPageView(); APageListItem item = getCurrentPageView();
if (item != null) if (item != null) {
{
int w = Math.abs(item.getWidth() - getWidth()); int w = Math.abs(item.getWidth() - getWidth());
int h = Math.abs(item.getHeight() - getHeight()); int h = Math.abs(item.getHeight() - getHeight());
// left/right and top/bottom alignment // left/right and top/bottom alignment
if (w < 2 && h < 2) if (w < 2 && h < 2) {
{
state = 3; state = 3;
} }
// left/right alignment // left/right alignment
else if (w < 2 && h >= 2) else if (w < 2 && h >= 2) {
{
state = 2; state = 2;
} }
// top/bottom alignment // top/bottom alignment
else if (w >= 2 && h < 2) else if (w >= 2 && h < 2) {
{
state = 1; state = 1;
} }
} }
return state; return state;
} }
/** /**
* *
*/ */
public float getZoom() public float getZoom() {
{
return zoom; return zoom;
} }
/** /**
* *
*/ */
public float getFitZoom() public float getFitZoom() {
{
return getFitZoom(0); return getFitZoom(0);
} }
/** /**
* *
*/ */
public float getFitZoom(int value) public float getFitZoom(int value) {
{ if (currentIndex < 0 || currentIndex >= pageListViewListener.getPageCount()) {
if (currentIndex < 0 || currentIndex >= pageListViewListener.getPageCount())
{
return 1.0f; return 1.0f;
} }
Rect rect = pageListViewListener.getPageSize(currentIndex); Rect rect = pageListViewListener.getPageSize(currentIndex);
int viewWidth = getWidth(); int viewWidth = getWidth();
int viewHeight = getHeight(); int viewHeight = getHeight();
ViewParent v = getParent(); ViewParent v = getParent();
while (viewWidth == 0 && v != null) while (viewWidth == 0 && v != null) {
{ if (v == null || !(v instanceof View)) {
if (v == null || !(v instanceof View))
{
break; break;
} }
viewWidth = ((View)v).getWidth(); viewWidth = ((View) v).getWidth();
viewHeight = ((View)v).getHeight(); viewHeight = ((View) v).getHeight();
v = v.getParent(); v = v.getParent();
} }
if (viewWidth == 0 || viewHeight == 0) if (viewWidth == 0 || viewHeight == 0) {
{
return 1.0f; return 1.0f;
} }
float maxZoom = MainConstant.MAXZOOM / MainConstant.STANDARD_RATE; float maxZoom = MainConstant.MAXZOOM / MainConstant.STANDARD_RATE;
if (value == 0) if (value == 0) {
{ if (!pageListViewListener.isIgnoreOriginalSize()) {
if(!pageListViewListener.isIgnoreOriginalSize()) return Math.min(Math.min(viewWidth / (float) rect.width(), viewHeight / (float) rect.height()), 1.0f);
{ } else {
return Math.min(Math.min(viewWidth / (float)rect.width(), viewHeight / (float)rect.height()), 1.0f); return Math.min(Math.min(viewWidth / (float) rect.width(), viewHeight / (float) rect.height()), maxZoom);
} }
else
{ } else if (value == 1) {
return Math.min(Math.min(viewWidth / (float)rect.width(), viewHeight / (float)rect.height()), maxZoom); return Math.min(viewWidth / (float) rect.width(), maxZoom);
} } else if (value == 2) {
return Math.min(viewHeight / (float) rect.height(), maxZoom);
}
else if (value == 1)
{
return Math.min(viewWidth / (float)rect.width(), maxZoom);
}
else if (value == 2)
{
return Math.min(viewHeight / (float)rect.height(), maxZoom);
} }
return 1.0f; return 1.0f;
} }
/** /**
* get current display page number (base 1) * get current display page number (base 1)
* *
* @return page number (base 1) * @return page number (base 1)
*/ */
public int getCurrentPageNumber() public int getCurrentPageNumber() {
{
return currentIndex + 1; return currentIndex + 1;
} }
/** /**
*
* @see android.widget.AdapterView#getAdapter() * @see android.widget.AdapterView#getAdapter()
*
*/ */
@ Override @Override
public Adapter getAdapter() public Adapter getAdapter() {
{
return pageAdapter; return pageAdapter;
} }
/** /**
*
* @see android.widget.AdapterView#setAdapter(android.widget.Adapter) * @see android.widget.AdapterView#setAdapter(android.widget.Adapter)
*
*/ */
@ Override @Override
public void setAdapter(Adapter adapter) public void setAdapter(Adapter adapter) {
{
this.pageAdapter = adapter; this.pageAdapter = adapter;
} }
/** /**
* * (non-Javadoc)
*(non-Javadoc)
* @see android.widget.AdapterView#getSelectedView()
* *
* @see android.widget.AdapterView#getSelectedView()
*/ */
@ Override @Override
public View getSelectedView() public View getSelectedView() {
{
return null; return null;
} }
/** /**
*
* @see android.widget.AdapterView#setSelection(int) * @see android.widget.AdapterView#setSelection(int)
*
*/ */
@ Override @Override
public void setSelection(int position) public void setSelection(int position) {
{
} }
/** /**
* *
* @param v
*/ */
protected void postUnRepaint(final APageListItem view) protected void postUnRepaint(final APageListItem view) {
{ if (view == null) {
if (view == null)
{
return; return;
} }
post(new Runnable() post(new Runnable() {
{ public void run() {
public void run()
{
view.removeRepaintImageView(); view.removeRepaintImageView();
} }
}); });
} }
/** /**
* *
* @param v
*/ */
public void postRepaint(final APageListItem view) public void postRepaint(final APageListItem view) {
{ if (view == null) {
if (view == null)
{
return; return;
} }
post(new Runnable() post(new Runnable() {
{ public void run() {
public void run()
{
view.addRepaintImageView(null); view.addRepaintImageView(null);
} }
}); });
} }
/** /**
*
* @param i
* @return * @return
*/ */
public APageListItem getCurrentPageView() public APageListItem getCurrentPageView() {
{ if (childViewsCache != null) {
if (childViewsCache != null)
{
return childViewsCache.get(currentIndex); return childViewsCache.get(currentIndex);
} }
return null; return null;
} }
/** /**
* *
*/ */
protected IPageListViewListener getPageListViewListener() protected IPageListViewListener getPageListViewListener() {
{
return this.pageListViewListener; return this.pageListViewListener;
} }
/** /**
*
* @param i
* @return * @return
*/ */
private APageListItem createPageView(int pageIndex) private APageListItem createPageView(int pageIndex) {
{
APageListItem pageView = childViewsCache.get(pageIndex); APageListItem pageView = childViewsCache.get(pageIndex);
if (pageView == null) if (pageView == null) {
{ pageView = (APageListItem) pageAdapter.getView(pageIndex,
pageView = (APageListItem)pageAdapter.getView(pageIndex, (pageViewCache.size() == 0 ? null : pageViewCache.removeFirst()), this);
(pageViewCache.size() == 0 ? null : pageViewCache.removeFirst()), this);
LayoutParams params = pageView.getLayoutParams(); LayoutParams params = pageView.getLayoutParams();
if (params == null) if (params == null) {
{
params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
} }
addViewInLayout(pageView, 0, params, true); addViewInLayout(pageView, 0, params, true);
// Record the view against it's adapter index // Record the view against it's adapter index
childViewsCache.append(pageIndex, pageView); childViewsCache.append(pageIndex, pageView);
// 计算page的size // 计算page的size
pageView.measure(View.MeasureSpec.EXACTLY | (int)(pageView.getPageWidth() * zoom), pageView.measure(View.MeasureSpec.EXACTLY | (int) (pageView.getPageWidth() * zoom),
View.MeasureSpec.EXACTLY | (int)(pageView.getPageHeight() * zoom)); View.MeasureSpec.EXACTLY | (int) (pageView.getPageHeight() * zoom));
} }
return pageView; return pageView;
} }
/** /**
*
* @param left * @param left
* @param top * @param top
* @param right * @param right
* @param bottom * @param bottom
* @return * @return
*/ */
protected Rect getScrollBounds(int left, int top, int right, int bottom) protected Rect getScrollBounds(int left, int top, int right, int bottom) {
{
int xmin = getWidth() - right; int xmin = getWidth() - right;
int xmax = -left; int xmax = -left;
int ymin = getHeight() - bottom; int ymin = getHeight() - bottom;
...@@ -1080,12 +899,10 @@ public class APageListView extends AdapterView<Adapter> ...@@ -1080,12 +899,10 @@ public class APageListView extends AdapterView<Adapter>
// In either dimension, if view smaller than screen then // In either dimension, if view smaller than screen then
// constrain it to be central // constrain it to be central
if (xmin > xmax) if (xmin > xmax) {
{
xmin = xmax = (xmin + xmax) / 2; xmin = xmax = (xmin + xmax) / 2;
} }
if (ymin > ymax) if (ymin > ymax) {
{
ymin = ymax = (ymin + ymax) / 2; ymin = ymax = (ymin + ymax) / 2;
} }
...@@ -1093,123 +910,104 @@ public class APageListView extends AdapterView<Adapter> ...@@ -1093,123 +910,104 @@ public class APageListView extends AdapterView<Adapter>
} }
/** /**
*
* @param v * @param v
* @return * @return
*/ */
protected Rect getScrollBounds(View v) protected Rect getScrollBounds(View v) {
{
// There can be scroll amounts not yet accounted for in // There can be scroll amounts not yet accounted for in
// onLayout, so add mXScroll and mYScroll to the current // onLayout, so add mXScroll and mYScroll to the current
// positions when calculating the bounds. // positions when calculating the bounds.
return getScrollBounds(v.getLeft() + eventManage.getScrollX(), return getScrollBounds(v.getLeft() + eventManage.getScrollX(),
v.getTop() + eventManage.getScrollY(), v.getTop() + eventManage.getScrollY(),
v.getLeft() + v.getMeasuredWidth() + eventManage.getScrollX(), v.getLeft() + v.getMeasuredWidth() + eventManage.getScrollX(),
v.getTop() + v.getMeasuredHeight() + eventManage.getScrollY()); v.getTop() + v.getMeasuredHeight() + eventManage.getScrollY());
} }
/** /**
*
* @param bounds * @param bounds
* @return * @return
*/ */
protected Point getCorrection(Rect bounds) protected Point getCorrection(Rect bounds) {
{ return new Point(Math.min(Math.max(0, bounds.left), bounds.right),
return new Point(Math.min(Math.max(0, bounds.left), bounds.right), Math.min(Math.max(0, bounds.top), bounds.bottom));
Math.min(Math.max(0, bounds.top), bounds.bottom));
} }
/** /**
*
* @param v * @param v
* @return * @return
*/ */
protected Point getScreenSizeOffset(View v) protected Point getScreenSizeOffset(View v) {
{ return new Point(Math.max((getWidth() - v.getMeasuredWidth()) / 2, 0),
return new Point(Math.max((getWidth() - v.getMeasuredWidth()) / 2, 0), Math.max((getHeight() - v.getMeasuredHeight()) / 2, 0));
Math.max((getHeight() - v.getMeasuredHeight()) / 2, 0));
} }
/** /**
* *
*/ */
public int getPageCount() public int getPageCount() {
{
return pageListViewListener.getPageCount(); return pageListViewListener.getPageCount();
} }
/** /**
* *
*/ */
protected APageListItem getPageListItem(int position, View convertView, ViewGroup parent) protected APageListItem getPageListItem(int position, View convertView, ViewGroup parent) {
{
return pageListViewListener.getPageListItem(position, convertView, parent); return pageListViewListener.getPageListItem(position, convertView, parent);
} }
/** /**
* *
*/ */
public boolean isInit() public boolean isInit() {
{
return this.isInit; return this.isInit;
} }
/** /**
* *
*/ */
public void setDoRequstLayout(boolean b) public void setDoRequstLayout(boolean b) {
{
this.isDoRequestLayout = b; this.isDoRequestLayout = b;
} }
public boolean isInitZoom() public boolean isInitZoom() {
{
return isInitZoom; return isInitZoom;
} }
public void setInitZoom(boolean isInitZoom) public void setInitZoom(boolean isInitZoom) {
{
this.isInitZoom = isInitZoom; this.isInitZoom = isInitZoom;
} }
/** /**
* *
*/ */
public void dispose() public void dispose() {
{
pageListViewListener = null; pageListViewListener = null;
if (eventManage != null) if (eventManage != null) {
{
eventManage.dispose(); eventManage.dispose();
eventManage = null; eventManage = null;
} }
if (pageAdapter instanceof APageListAdapter) if (pageAdapter instanceof APageListAdapter) {
{ ((APageListAdapter) pageAdapter).dispose();
((APageListAdapter)pageAdapter).dispose();
pageAdapter = null; pageAdapter = null;
} }
if (childViewsCache != null) if (childViewsCache != null) {
{
int size = childViewsCache.size(); int size = childViewsCache.size();
for (int i = 0; i < size; i++) for (int i = 0; i < size; i++) {
{
childViewsCache.valueAt(i).dispose(); childViewsCache.valueAt(i).dispose();
} }
childViewsCache.clear(); childViewsCache.clear();
childViewsCache = null; childViewsCache = null;
} }
if (pageViewCache != null) if (pageViewCache != null) {
{ for (APageListItem page : pageViewCache) {
for (APageListItem page : pageViewCache)
{
page.dispose(); page.dispose();
} }
pageViewCache.clear(); pageViewCache.clear();
pageViewCache = null; pageViewCache = null;
} }
} }
// //
private boolean isDoRequestLayout = true; private boolean isDoRequestLayout = true;
// //
...@@ -1223,7 +1021,7 @@ public class APageListView extends AdapterView<Adapter> ...@@ -1223,7 +1021,7 @@ public class APageListView extends AdapterView<Adapter>
// //
private float zoom = 1.0f; private float zoom = 1.0f;
// Adapter's index for the current view (base 0) // Adapter's index for the current view (base 0)
private int currentIndex; private int currentIndex;
// //
private IPageListViewListener pageListViewListener; private IPageListViewListener pageListViewListener;
// //
......
...@@ -161,4 +161,6 @@ public interface IPageListViewListener ...@@ -161,4 +161,6 @@ public interface IPageListViewListener
* page list view moving position * page list view moving position
*/ */
public int getPageListViewMovingPosition(); public int getPageListViewMovingPosition();
public void singleTab();
} }
...@@ -434,6 +434,11 @@ public class PrintWord extends FrameLayout implements IPageListViewListener { ...@@ -434,6 +434,11 @@ public class PrintWord extends FrameLayout implements IPageListViewListener {
return control.getMainFrame().getPageListViewMovingPosition(); return control.getMainFrame().getPageListViewMovingPosition();
} }
@Override
public void singleTab() {
}
/** /**
* *
*/ */
......
...@@ -39,7 +39,6 @@ import com.cherry.lib.doc.office.system.beans.AEventManage; ...@@ -39,7 +39,6 @@ import com.cherry.lib.doc.office.system.beans.AEventManage;
*/ */
public class WPEventManage extends AEventManage { public class WPEventManage extends AEventManage {
/** /**
* @param spreadsheet
*/ */
public WPEventManage(Word word, IControl control) { public WPEventManage(Word word, IControl control) {
super(word.getContext(), control); super(word.getContext(), control);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment