Commit 53d03926 authored by wanglei's avatar wanglei

...

parent 7096a17f
......@@ -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.system.IControl;
import com.cherry.lib.doc.office.system.beans.AEventManage;
import android.graphics.Rect;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
......@@ -29,14 +31,11 @@ import android.view.View;
* <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);
this.presentation = presentation;
presentation.setOnTouchListener(this);
......@@ -45,32 +44,25 @@ public class PGEventManage extends AEventManage
/**
* 触摸事件
*
*/
public boolean onTouch(View v, MotionEvent event)
{
public boolean onTouch(View v, MotionEvent event) {
super.onTouch(v, event);
return false;
}
/**
*
*
*/
public boolean onDoubleTap(MotionEvent e)
{
public boolean onDoubleTap(MotionEvent e) {
super.onDoubleTap(e);
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);
return true;
}
......@@ -81,12 +73,9 @@ public class PGEventManage extends AEventManage
* @param velocityX X方向速率
* @param velocityY Y方向速率
*/
public void fling(int velocityX, int velocityY)
{
if(presentation.isSlideShow())
{
if (Math.abs(velocityY) < 400 && Math.abs(velocityX) < 400)
{
public void fling(int velocityX, int velocityY) {
if (presentation.isSlideShow()) {
if (Math.abs(velocityY) < 400 && Math.abs(velocityX) < 400) {
presentation.slideShow(ISlideShow.SlideShow_NextStep);
return;
}
......@@ -94,30 +83,21 @@ public class PGEventManage extends AEventManage
super.fling(velocityX, velocityY);
int currentIndex = presentation.getCurrentIndex();
if (Math.abs(velocityY) > Math.abs(velocityX))
{
if (Math.abs(velocityY) > Math.abs(velocityX)) {
//vertical
if (velocityY < 0 && currentIndex >= 0)
{
if (velocityY < 0 && currentIndex >= 0) {
//previous step
presentation.slideShow(ISlideShow.SlideShow_NextStep);
}
else if (velocityY > 0 && currentIndex <= presentation.getRealSlideCount() - 1)
{
} else if (velocityY > 0 && currentIndex <= presentation.getRealSlideCount() - 1) {
//next step
presentation.slideShow(ISlideShow.SlideShow_PreviousStep);
}
}
else
{
} else {
// horizontal
if (velocityX < 0 && currentIndex >= 0)
{
if (velocityX < 0 && currentIndex >= 0) {
// previous Slide
presentation.slideShow(ISlideShow.SlideShow_PreviousSlide);
}
else if (velocityX > 0 && currentIndex < presentation.getRealSlideCount() - 1)
{
} else if (velocityX > 0 && currentIndex < presentation.getRealSlideCount() - 1) {
// next Slide
presentation.slideShow(ISlideShow.SlideShow_NextSlide);
}
......@@ -127,17 +107,15 @@ public class PGEventManage extends AEventManage
}
/**
*
*
*/
public boolean onSingleTapUp(MotionEvent e)
{
public boolean onSingleTapUp(MotionEvent e) {
Log.e("PGEventManage", "onSingleTapUp");
control.getMainFrame().singleTap();
super.onSingleTapUp(e);
if (e.getAction() == MotionEvent.ACTION_UP)
{
if (e.getAction() == MotionEvent.ACTION_UP) {
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
this.presentation.slideShow(ISlideShow.SlideShow_NextStep);
}
......@@ -148,11 +126,11 @@ public class PGEventManage extends AEventManage
/**
*
*/
public void dispose()
{
public void dispose() {
super.dispose();
presentation = null;
}
// Spreadsheet
private Presentation presentation;
}
......@@ -428,6 +428,12 @@ public class PGPrintMode extends FrameLayout implements IPageListViewListener {
return control.getMainFrame().getPageListViewMovingPosition();
}
@Override
public void singleTab() {
Log.e("PGPrintMode", "singleTab");
control.getMainFrame().singleTap();
}
/**
*
*/
......
......@@ -13,6 +13,7 @@ import com.cherry.lib.doc.office.constant.MainConstant;
import android.graphics.Point;
import android.graphics.Rect;
import android.util.Log;
import android.view.GestureDetector;
import android.view.GestureDetector.OnDoubleTapListener;
import android.view.GestureDetector.OnGestureListener;
......@@ -26,9 +27,8 @@ import android.widget.Toast;
public class APageListEventManage implements
ScaleGestureDetector.OnScaleGestureListener, OnGestureListener,Runnable,
OnTouchListener, OnDoubleTapListener, OnClickListener
{
ScaleGestureDetector.OnScaleGestureListener, OnGestureListener, Runnable,
OnTouchListener, OnDoubleTapListener, OnClickListener {
private static final int MOVING_DIAGONALLY = 0;
private static final int MOVING_LEFT = 1;
......@@ -40,10 +40,8 @@ public class APageListEventManage implements
/**
*
* @param pdfListView
*/
public APageListEventManage(APageListView listView)
{
public APageListEventManage(APageListView listView) {
this.listView = listView;
gesture = new GestureDetector(listView.getContext(), this);
mScroller = new Scroller(listView.getContext());
......@@ -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;
}
/**
* 触摸事件
*
*/
protected boolean processOnTouch(MotionEvent event)
{
protected boolean processOnTouch(MotionEvent event) {
eventPointerCount = event.getPointerCount();
if (event.getActionMasked() == MotionEvent.ACTION_DOWN)
{
if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
isOnFling = false;
isTouchEventIn = true;
}
if (mScaleGestureDetector != null)
{
if (mScaleGestureDetector != null) {
mScaleGestureDetector.onTouchEvent(event);
}
if (!isScaling && gesture != null)
{
if (!isScaling && gesture != null) {
gesture.onTouchEvent(event);
}
if (event.getActionMasked() == MotionEvent.ACTION_UP)
{
if (event.getActionMasked() == MotionEvent.ACTION_UP) {
isProcessOnScroll = true;
isTouchEventIn = false;
APageListItem pageView = listView.getCurrentPageView();
if (pageView != null)
{
if (mScroller.isFinished())
{
if (pageView != null) {
if (mScroller.isFinished()) {
// If, at the end of user interaction, there is no
// current inertial scroll in operation then animate
// the view onto screen if necessary
if (!isDoubleTap)
{
if (!isDoubleTap) {
slideViewOntoScreen(pageView);
}
}
if (mScroller.isFinished() && isOnScroll)
{
if (mScroller.isFinished() && isOnScroll) {
// If still there is no inertial scroll in operation
// then the layout is stable
listView.getPageListViewListener().setDrawPictrue(true);
......@@ -117,10 +102,8 @@ public class APageListEventManage implements
/**
* 触摸事件
*
*/
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);
return false;
}
......@@ -128,47 +111,36 @@ public class APageListEventManage implements
/**
*
*/
public boolean onDown(MotionEvent e)
{
public boolean onDown(MotionEvent e) {
mScroller.forceFinished(true);
listView.getPageListViewListener().onEventMethod(listView, e, null, -1.0f, -1.0f, IPageListViewListener.ON_DOWN);
return true;
}
/**
*
* @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);
if (!isProcessOnScroll || isDoubleTap)
{
if (!isProcessOnScroll || isDoubleTap) {
return true;
}
View pageView = listView.getCurrentPageView();
if (pageView != null)
{
if (pageView != null) {
Rect bounds = listView.getScrollBounds(pageView);
if(listView.getPageListViewListener().getPageListViewMovingPosition() == IPageListViewListener.Moving_Horizontal)
{
if (listView.getPageListViewListener().getPageListViewMovingPosition() == IPageListViewListener.Moving_Horizontal) {
if (pageView.getWidth() <= listView.getWidth()
|| listView.getPageListViewListener().isChangePage())
{
switch (directionOfTravel(velocityX, velocityY))
{
|| listView.getPageListViewListener().isChangePage()) {
switch (directionOfTravel(velocityX, velocityY)) {
case MOVING_LEFT:
if (bounds.left >= 0)
{
if (bounds.left >= 0) {
isOnFling = true;
listView.nextPageView();
return true;
}
break;
case MOVING_RIGHT:
if (bounds.right <= 0)
{
if (bounds.right <= 0) {
isOnFling = true;
listView.previousPageview();
return true;
......@@ -176,25 +148,19 @@ public class APageListEventManage implements
break;
}
}
}
else
{
} else {
if (pageView.getHeight() <= listView.getHeight()
|| listView.getPageListViewListener().isChangePage())
{
switch (directionOfTravel(velocityX, velocityY))
{
|| listView.getPageListViewListener().isChangePage()) {
switch (directionOfTravel(velocityX, velocityY)) {
case MOVING_UP:
if (bounds.top >= 0)
{
if (bounds.top >= 0) {
isOnFling = true;
listView.nextPageView();
return true;
}
break;
case MOVING_DOWN:
if (bounds.bottom <= 0)
{
if (bounds.bottom <= 0) {
isOnFling = true;
listView.previousPageview();
return true;
......@@ -218,46 +184,36 @@ public class APageListEventManage implements
expandedBounds.inset(-100, -100);
if (withinBoundsInDirectionOfTravel(bounds, velocityX, velocityY)
&& expandedBounds.contains(0, 0))
{
mScroller.fling(0, 0, (int)velocityX, (int)velocityY, bounds.left, bounds.right,
&& expandedBounds.contains(0, 0)) {
mScroller.fling(0, 0, (int) velocityX, (int) velocityY, bounds.left, bounds.right,
bounds.top, bounds.bottom);
listView.post(this);
}
}
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);
if (isProcessOnScroll && !isDoubleTap)
{
if (isProcessOnScroll && !isDoubleTap) {
listView.getPageListViewListener().setDrawPictrue(false);
isOnScroll = true;
mXScroll -= distanceX;
mYScroll -= distanceY;
if (!listView.getPageListViewListener().isChangePage())
{
if (!listView.getPageListViewListener().isChangePage()) {
APageListItem item = listView.getCurrentPageView();
if (item != null && item.getWidth() > listView.getWidth())
{
if (distanceX > 0)
{
if (item != null && item.getWidth() > listView.getWidth()) {
if (distanceX > 0) {
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());
}
}
else if (distanceX < 0)
{
} else if (distanceX < 0) {
if (mXScroll + item.getLeft() > 0
&& item.getPageIndex() != 0)
{
&& item.getPageIndex() != 0) {
mXScroll = 0;
}
}
......@@ -269,32 +225,26 @@ public class APageListEventManage implements
}
/**
*
* @see android.view.ScaleGestureDetector.OnScaleGestureListener#onScale(android.view.ScaleGestureDetector)
*
*/
@ Override
public boolean onScale(ScaleGestureDetector detector)
{
if (eventPointerCount <= 1 || !listView.getPageListViewListener().isTouchZoom())
{
@Override
public boolean onScale(ScaleGestureDetector detector) {
if (eventPointerCount <= 1 || !listView.getPageListViewListener().isTouchZoom()) {
return true;
}
isTouchEventIn = true;
float previousScale = listView.getZoom();
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;
float factor = zoom / previousScale;
listView.setZoom(zoom, false);
APageListItem v = listView.getCurrentPageView();
if (v != null)
{
if (v != null) {
// Work out the focus point relative to the view top left
int viewFocusX = (int)detector.getFocusX() - (v.getLeft() + mXScroll);
int viewFocusY = (int)detector.getFocusY() - (v.getTop() + mYScroll);
int viewFocusX = (int) detector.getFocusX() - (v.getLeft() + mXScroll);
int viewFocusY = (int) detector.getFocusY() - (v.getTop() + mYScroll);
// Scroll to maintain the focus point
mXScroll += viewFocusX - viewFocusX * factor;
mYScroll += viewFocusY - viewFocusY * factor;
......@@ -302,24 +252,19 @@ public class APageListEventManage implements
}
}
// 提示
if(listView.getPageListViewListener().isShowZoomingMsg())
{
toast.setText((int)Math.round(zoom * 100) + "%");
if (listView.getPageListViewListener().isShowZoomingMsg()) {
toast.setText((int) Math.round(zoom * 100) + "%");
toast.show();
}
return true;
}
/**
*
* @see android.view.ScaleGestureDetector.OnScaleGestureListener#onScaleBegin(android.view.ScaleGestureDetector)
*
*/
@ Override
public boolean onScaleBegin(ScaleGestureDetector detector)
{
if (eventPointerCount <= 1 || !listView.getPageListViewListener().isTouchZoom())
{
@Override
public boolean onScaleBegin(ScaleGestureDetector detector) {
if (eventPointerCount <= 1 || !listView.getPageListViewListener().isTouchZoom()) {
return true;
}
isScaling = true;
......@@ -327,62 +272,53 @@ public class APageListEventManage implements
isProcessOnScroll = false;
return true;
}
/**
*
* @see android.view.ScaleGestureDetector.OnScaleGestureListener#onScaleEnd(android.view.ScaleGestureDetector)
*
*/
@ Override
public void onScaleEnd(ScaleGestureDetector detector)
{
if (eventPointerCount <= 1 || !listView.getPageListViewListener().isTouchZoom())
{
@Override
public void onScaleEnd(ScaleGestureDetector detector) {
if (eventPointerCount <= 1 || !listView.getPageListViewListener().isTouchZoom()) {
return;
}
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);
}
/**
*
*
*/
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);
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);
}
/**
*
*/
public void onClick(View v)
{
public void onClick(View v) {
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);
return false;
}
......@@ -390,8 +326,7 @@ public class APageListEventManage implements
/**
*
*/
public boolean onDoubleTap(MotionEvent e)
{
public boolean onDoubleTap(MotionEvent e) {
isProcessOnScroll = true;
isTouchEventIn = false;
isDoubleTap = true;
......@@ -402,8 +337,7 @@ public class APageListEventManage implements
/**
*
*/
public boolean onDoubleTapEvent(MotionEvent e)
{
public boolean onDoubleTapEvent(MotionEvent e) {
isTouchEventIn = false;
isDoubleTap = true;
listView.getPageListViewListener().onEventMethod(listView, e, null, -1.0f, -1.0f, IPageListViewListener.ON_DOUBLE_TAP_EVENT);
......@@ -413,10 +347,8 @@ public class APageListEventManage implements
/**
*
*/
public void run()
{
if (!mScroller.isFinished())
{
public void run() {
if (!mScroller.isFinished()) {
listView.getPageListViewListener().setDrawPictrue(false);
mScroller.computeScrollOffset();
int x = mScroller.getCurrX();
......@@ -427,9 +359,7 @@ public class APageListEventManage implements
mScrollerLastY = y;
listView.requestLayout();
listView.post(this);
}
else if (!isTouchEventIn)
{
} else if (!isTouchEventIn) {
// End of an inertial scroll and the user is not interacting.
// The layout is stable
listView.postRepaint(listView.getCurrentPageView());
......@@ -440,13 +370,10 @@ public class APageListEventManage implements
/**
*
* @param v
*/
protected void slideViewOntoScreen(APageListItem pageItem)
{
protected void slideViewOntoScreen(APageListItem 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;
mScroller.startScroll(0, 0, corr.x, corr.y, 400);
listView.post(this);
......@@ -458,23 +385,21 @@ public class APageListEventManage implements
/**
* @return Returns the mXScroll.
*/
protected int getScrollX()
{
protected int getScrollX() {
return mXScroll;
}
/**
* @return Returns the mYScroll.
*/
protected int getScrollY()
{
protected int getScrollY() {
return mYScroll;
}
/**
*
*/
protected void setScrollAxisValue(int x, int y)
{
protected void setScrollAxisValue(int x, int y) {
mXScroll = x;
mYScroll = y;
}
......@@ -482,60 +407,47 @@ public class APageListEventManage implements
/**
*
*/
protected boolean isTouchEventIn()
{
protected boolean isTouchEventIn() {
return this.isTouchEventIn;
}
/**
*
*/
protected boolean isScrollerFinished()
{
protected boolean isScrollerFinished() {
return mScroller.isFinished();
}
/**
*
*/
protected boolean isOnFling()
{
protected boolean isOnFling() {
return this.isOnFling;
}
/**
*
* @param vx
* @param vy
* @return
*/
protected int directionOfTravel(float vx, float vy)
{
if (Math.abs(vx) > 2 * Math.abs(vy))
{
protected int directionOfTravel(float vx, float vy) {
if (Math.abs(vx) > 2 * Math.abs(vy)) {
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;
}
else
{
} else {
return MOVING_DIAGONALLY;
}
}
/**
*
* @param bounds
* @param vx
* @param vy
* @return
*/
protected boolean withinBoundsInDirectionOfTravel(Rect bounds, float vx, float vy)
{
switch (directionOfTravel(vx, vy))
{
protected boolean withinBoundsInDirectionOfTravel(Rect bounds, float vx, float vy) {
switch (directionOfTravel(vx, vy)) {
case MOVING_DIAGONALLY:
return bounds.contains(0, 0);
case MOVING_LEFT:
......@@ -554,8 +466,7 @@ public class APageListEventManage implements
/**
*
*/
public void dispose()
{
public void dispose() {
}
......
......@@ -9,6 +9,7 @@ package com.cherry.lib.doc.office.system.beans.pagelist;
import java.util.LinkedList;
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 android.content.Context;
......@@ -25,39 +26,34 @@ import android.view.ViewParent;
import android.widget.Adapter;
import android.widget.AdapterView;
public class APageListView extends AdapterView<Adapter>
{
public class APageListView extends AdapterView<Adapter> {
private static final int GAP = 20;
/**
*
* @param context
*/
public APageListView(Context context)
{
public APageListView(Context context) {
super(context);
}
/**
*
*
*/
public APageListView(Context context, IPageListViewListener listener)
{
public APageListView(Context context, IPageListViewListener listener) {
super(context);
this.pageListViewListener = listener;
eventManage = new APageListEventManage(this);
pageAdapter = new APageListAdapter(this);
setLongClickable(true);
this.post(new Runnable()
{
@ Override
public void run()
{
this.post(new Runnable() {
@Override
public void run() {
// get thumbnail, pageListViewListener = null;
if (pageListViewListener != null
&& pageListViewListener.isInit())
{
&& pageListViewListener.isInit()) {
init();
}
}
......@@ -67,40 +63,32 @@ public class APageListView extends AdapterView<Adapter>
/**
*
*/
public void init()
{
public void init() {
isInit = true;
requestLayout();
}
/**
*
*
*/
public void requestLayout()
{
if (isDoRequestLayout)
{
public void requestLayout() {
if (isDoRequestLayout) {
super.requestLayout();
}
}
/**
*
*
*/
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int n = getChildCount();
for (int i = 0; i < n; i++)
{
for (int i = 0; i < n; i++) {
View view = getChildAt(i);
if (view instanceof APageListItem)
{
APageListItem pv = (APageListItem)view;
pv.measure(View.MeasureSpec.EXACTLY | (int)(pv.getPageWidth() * zoom),
View.MeasureSpec.EXACTLY | (int)(pv.getPageHeight() * zoom));
if (view instanceof APageListItem) {
APageListItem pv = (APageListItem) view;
pv.measure(View.MeasureSpec.EXACTLY | (int) (pv.getPageWidth() * zoom),
View.MeasureSpec.EXACTLY | (int) (pv.getPageHeight() * zoom));
}
}
}
......@@ -115,24 +103,19 @@ public class APageListView extends AdapterView<Adapter>
* @param oldw Old width 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);
if (isConfigurationChanged)
{
if (isConfigurationChanged) {
float fitZoom = getFitZoom();
if(zoom < fitZoom)
{
if (zoom < fitZoom) {
setZoom(fitZoom, false);
isInit = false;
postDelayed(new Runnable()
{
postDelayed(new Runnable() {
/**
*
*/
public void run()
{
public void run() {
isInit = true;
isResetLayout = true;
requestLayout();
......@@ -147,13 +130,10 @@ public class APageListView extends AdapterView<Adapter>
/**
*
*/
public boolean onTouchEvent(MotionEvent event)
{
public boolean onTouchEvent(MotionEvent event) {
APageListItem pageView = getCurrentPageView();
if (pageView != null)
{
if (pageView.getControl().getSysKit().getCalloutManager().getDrawingMode() != MainConstant.DRAWMODE_NORMAL)
{
if (pageView != null) {
if (pageView.getControl().getSysKit().getCalloutManager().getDrawingMode() != MainConstant.DRAWMODE_NORMAL) {
return false;
}
......@@ -164,57 +144,44 @@ public class APageListView extends AdapterView<Adapter>
}
/**
*
* @see android.widget.AdapterView#onLayout(boolean, int, int, int, int)
*
*/
@ Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom)
{
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
if (!isInit)
{
if (!isInit) {
return;
}
if(pageListViewListener.getPageListViewMovingPosition() == IPageListViewListener.Moving_Horizontal)
{
if (pageListViewListener.getPageListViewMovingPosition() == IPageListViewListener.Moving_Horizontal) {
layout_Horizontal();
}
else
{
} else {
layout_Vertical();
}
invalidate();
if (isConfigurationChanged)
{
if (isConfigurationChanged) {
isConfigurationChanged = false;
APageListItem pageView = getCurrentPageView();
if (pageView != null)
{
if (pageView != null) {
postRepaint(pageView);
}
}
}
private void layout_Horizontal()
{
private void layout_Horizontal() {
APageListItem currentView = childViewsCache.get(currentIndex);
Point cvOffset;
if (!isResetLayout)
{
if (!isResetLayout) {
// 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);
// next page
if (currentView.getLeft() + currentView.getMeasuredWidth()
+ cvOffset.x + GAP / 2 + eventManage.getScrollX() < getWidth() / 2
&& currentIndex + 1 < pageAdapter.getCount()
&& !eventManage.isOnFling())
{
&& !eventManage.isOnFling()) {
postUnRepaint(currentView);
post(eventManage);
currentIndex++;
......@@ -223,8 +190,7 @@ public class APageListView extends AdapterView<Adapter>
// previous page
else if (currentView.getLeft() - cvOffset.x - GAP / 2 + eventManage.getScrollX() >= getWidth() / 2
&& currentIndex > 0
&& !eventManage.isOnFling())
{
&& !eventManage.isOnFling()) {
postUnRepaint(currentView);
post(eventManage);
currentIndex--;
......@@ -235,39 +201,31 @@ public class APageListView extends AdapterView<Adapter>
// Remove not needed children and hold them for reuse
int numChildren = childViewsCache.size();
int pIndexs[] = new int[numChildren];
for (int i = 0; i < numChildren; i++)
{
for (int i = 0; i < numChildren; i++) {
pIndexs[i] = childViewsCache.keyAt(i);
}
for (int i = 0; i < numChildren; i++)
{
if ( pIndexs[i] < currentIndex - 1 || pIndexs[i] > currentIndex + 1)
{
APageListItem pv = childViewsCache.get( pIndexs[i]);
for (int i = 0; i < numChildren; i++) {
if (pIndexs[i] < currentIndex - 1 || pIndexs[i] > currentIndex + 1) {
APageListItem pv = childViewsCache.get(pIndexs[i]);
pv.releaseResources();
pageViewCache.add(pv);
removeViewInLayout(pv);
childViewsCache.remove(pIndexs[i]);
}
}
}
else
{
} else {
isResetLayout = false;
boolean isRepaint = false;
eventManage.setScrollAxisValue(0, 0);
// Remove not needed children and hold them for reuse
int numChildren = childViewsCache.size();
int pIndexs[] = new int[numChildren];
for (int i = 0; i < numChildren; i++)
{
for (int i = 0; i < numChildren; i++) {
pIndexs[i] = childViewsCache.keyAt(i);
}
for (int i = 0; i < numChildren; i++)
{
if ( pIndexs[i] < currentIndex - 1 || pIndexs[i] > currentIndex + 1)
{
APageListItem pv = childViewsCache.get( pIndexs[i]);
for (int i = 0; i < numChildren; i++) {
if (pIndexs[i] < currentIndex - 1 || pIndexs[i] > currentIndex + 1) {
APageListItem pv = childViewsCache.get(pIndexs[i]);
pv.releaseResources();
pageViewCache.add(pv);
removeViewInLayout(pv);
......@@ -275,8 +233,7 @@ public class APageListView extends AdapterView<Adapter>
isRepaint = pIndexs[i] == currentIndex;
}
}
if ((int)(zoom * 100) != 100 || !isRepaint)
{
if ((int) (zoom * 100) != 100 || !isRepaint) {
post(eventManage);
}
}
......@@ -289,14 +246,11 @@ public class APageListView extends AdapterView<Adapter>
// offset it to center within the screen area, and to keep
// the views spaced out
cvOffset = getScreenSizeOffset(currentView);
if (notPresent)
{
if (notPresent) {
//Main item not already present. Just place it top left
cvLeft = cvOffset.x;
cvTop = cvOffset.y;
}
else
{
} else {
// Main item already present. Adjust by scroll offsets
cvLeft = currentView.getLeft() + eventManage.getScrollX();
cvTop = currentView.getTop() + eventManage.getScrollY();
......@@ -306,16 +260,13 @@ public class APageListView extends AdapterView<Adapter>
cvRight = cvLeft + currentView.getMeasuredWidth();
cvBottom = cvTop + currentView.getMeasuredHeight();
if (!eventManage.isTouchEventIn() && eventManage.isScrollerFinished())
{
if (!eventManage.isTouchEventIn() && eventManage.isScrollerFinished()) {
Point corr = getCorrection(getScrollBounds(cvLeft, cvTop, cvRight, cvBottom));
cvRight += corr.x;
cvLeft += corr.x;
cvTop += 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
// it vertically
Point corr = getCorrection(getScrollBounds(cvLeft, cvTop, cvRight, cvBottom));
......@@ -326,8 +277,7 @@ public class APageListView extends AdapterView<Adapter>
currentView.layout(cvLeft, cvTop, cvRight, cvBottom);
// previous page
if (currentIndex > 0)
{
if (currentIndex > 0) {
View preView = createPageView(currentIndex - 1);
Point leftOffset = getScreenSizeOffset(preView);
int gap = leftOffset.x + GAP + cvOffset.x;
......@@ -337,8 +287,7 @@ public class APageListView extends AdapterView<Adapter>
(cvBottom + cvTop + preView.getMeasuredHeight()) / 2);
}
// next page
if (currentIndex + 1 < pageAdapter.getCount())
{
if (currentIndex + 1 < pageAdapter.getCount()) {
View nextView = createPageView(currentIndex + 1);
Point rightOffset = getScreenSizeOffset(nextView);
int gap = cvOffset.x + GAP + rightOffset.x;
......@@ -350,22 +299,18 @@ public class APageListView extends AdapterView<Adapter>
}
}
private void layout_Vertical()
{
private void layout_Vertical() {
APageListItem currentView = childViewsCache.get(currentIndex);
Point cvOffset;
if (!isResetLayout)
{
if (!isResetLayout) {
// 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);
// next page
if (currentView.getTop() + currentView.getMeasuredHeight()
+ cvOffset.y + GAP / 2 + eventManage.getScrollY() < getHeight() / 2
&& currentIndex + 1 < pageAdapter.getCount()
&& !eventManage.isOnFling())
{
&& !eventManage.isOnFling()) {
postUnRepaint(currentView);
post(eventManage);
currentIndex++;
......@@ -374,8 +319,7 @@ public class APageListView extends AdapterView<Adapter>
// previous page
else if (currentView.getTop() - cvOffset.y - GAP / 2 + eventManage.getScrollY() >= getHeight() / 2
&& currentIndex > 0
&& !eventManage.isOnFling())
{
&& !eventManage.isOnFling()) {
postUnRepaint(currentView);
post(eventManage);
currentIndex--;
......@@ -386,39 +330,31 @@ public class APageListView extends AdapterView<Adapter>
// Remove not needed children and hold them for reuse
int numChildren = childViewsCache.size();
int pIndexs[] = new int[numChildren];
for (int i = 0; i < numChildren; i++)
{
for (int i = 0; i < numChildren; i++) {
pIndexs[i] = childViewsCache.keyAt(i);
}
for (int i = 0; i < numChildren; i++)
{
if ( pIndexs[i] < currentIndex - 1 || pIndexs[i] > currentIndex + 1)
{
APageListItem pv = childViewsCache.get( pIndexs[i]);
for (int i = 0; i < numChildren; i++) {
if (pIndexs[i] < currentIndex - 1 || pIndexs[i] > currentIndex + 1) {
APageListItem pv = childViewsCache.get(pIndexs[i]);
pv.releaseResources();
pageViewCache.add(pv);
removeViewInLayout(pv);
childViewsCache.remove(pIndexs[i]);
}
}
}
else
{
} else {
isResetLayout = false;
boolean isRepaint = false;
eventManage.setScrollAxisValue(0, 0);
// Remove not needed children and hold them for reuse
int numChildren = childViewsCache.size();
int pIndexs[] = new int[numChildren];
for (int i = 0; i < numChildren; i++)
{
for (int i = 0; i < numChildren; i++) {
pIndexs[i] = childViewsCache.keyAt(i);
}
for (int i = 0; i < numChildren; i++)
{
if ( pIndexs[i] < currentIndex - 1 || pIndexs[i] > currentIndex + 1)
{
APageListItem pv = childViewsCache.get( pIndexs[i]);
for (int i = 0; i < numChildren; i++) {
if (pIndexs[i] < currentIndex - 1 || pIndexs[i] > currentIndex + 1) {
APageListItem pv = childViewsCache.get(pIndexs[i]);
pv.releaseResources();
pageViewCache.add(pv);
removeViewInLayout(pv);
......@@ -427,8 +363,7 @@ public class APageListView extends AdapterView<Adapter>
}
}
if ((int)(zoom * 100) != 100 || !isRepaint)
{
if ((int) (zoom * 100) != 100 || !isRepaint) {
post(eventManage);
}
}
......@@ -441,14 +376,11 @@ public class APageListView extends AdapterView<Adapter>
// offset it to center within the screen area, and to keep
// the views spaced out
cvOffset = getScreenSizeOffset(currentView);
if (notPresent)
{
if (notPresent) {
//Main item not already present. Just place it top left
cvLeft = cvOffset.x;
cvTop = cvOffset.y;
}
else
{
} else {
// Main item already present. Adjust by scroll offsets
cvLeft = currentView.getLeft() + eventManage.getScrollX();
cvTop = currentView.getTop() + eventManage.getScrollY();
......@@ -458,16 +390,13 @@ public class APageListView extends AdapterView<Adapter>
cvRight = cvLeft + currentView.getMeasuredWidth();
cvBottom = cvTop + currentView.getMeasuredHeight();
if (!eventManage.isTouchEventIn() && eventManage.isScrollerFinished())
{
if (!eventManage.isTouchEventIn() && eventManage.isScrollerFinished()) {
Point corr = getCorrection(getScrollBounds(cvLeft, cvTop, cvRight, cvBottom));
cvRight += corr.x;
cvLeft += corr.x;
cvTop += 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
// it vertically
Point corr = getCorrection(getScrollBounds(cvLeft, cvTop, cvRight, cvBottom));
......@@ -478,8 +407,7 @@ public class APageListView extends AdapterView<Adapter>
currentView.layout(cvLeft, cvTop, cvRight, cvBottom);
// previous page
if (currentIndex > 0)
{
if (currentIndex > 0) {
View preView = createPageView(currentIndex - 1);
Point leftOffset = getScreenSizeOffset(preView);
int gap = leftOffset.y + GAP + cvOffset.y;
......@@ -489,8 +417,7 @@ public class APageListView extends AdapterView<Adapter>
cvBottom - gap - preView.getMeasuredHeight());
}
// next page
if (currentIndex + 1 < pageAdapter.getCount())
{
if (currentIndex + 1 < pageAdapter.getCount()) {
View nextView = createPageView(currentIndex + 1);
Point rightOffset = getScreenSizeOffset(nextView);
int gap = cvOffset.y + GAP + rightOffset.y;
......@@ -502,11 +429,9 @@ public class APageListView extends AdapterView<Adapter>
}
/**
*
*
*/
public void onConfigurationChanged(Configuration newConfig)
{
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
isConfigurationChanged = true;
}
......@@ -516,24 +441,20 @@ public class APageListView extends AdapterView<Adapter>
*
* @param index
*/
public void showPDFPageForIndex(final int index)
{
if (index < 0 || index >= pageAdapter.getCount())
{
public void showPDFPageForIndex(final int index) {
if (index < 0 || index >= pageAdapter.getCount()) {
return;
}
currentIndex = index;
postDelayed(new Runnable()
{
postDelayed(new Runnable() {
int gotoIndex = index;
/**
*
*/
public void run()
{
if (gotoIndex == currentIndex)
{
public void run() {
if (gotoIndex == currentIndex) {
isResetLayout = true;
requestLayout();
}
......@@ -545,27 +466,20 @@ public class APageListView extends AdapterView<Adapter>
/**
*
*/
public void nextPageView()
{
if (currentIndex + 1 >= pageAdapter.getCount())
{
public void nextPageView() {
if (currentIndex + 1 >= pageAdapter.getCount()) {
return;
}
APageListItem pageView = childViewsCache.get(currentIndex + 1);
if (pageView != null)
{
if (pageView != null) {
currentIndex++;
eventManage.slideViewOntoScreen(pageView);
}
else
{
postDelayed(new Runnable()
{
} else {
postDelayed(new Runnable() {
/**
*
*/
public void run()
{
public void run() {
isResetLayout = true;
requestLayout();
}
......@@ -577,15 +491,12 @@ public class APageListView extends AdapterView<Adapter>
/**
*
*/
public void previousPageview()
{
if (currentIndex == 0)
{
public void previousPageview() {
if (currentIndex == 0) {
return;
}
APageListItem pageView = childViewsCache.get(currentIndex - 1);
if (pageView != null)
{
if (pageView != null) {
currentIndex--;
eventManage.slideViewOntoScreen(pageView);
}
......@@ -594,29 +505,24 @@ public class APageListView extends AdapterView<Adapter>
/**
*
*/
public void exportImage(final APageListItem view, final Bitmap srcBitmap)
{
public void exportImage(final APageListItem view, final Bitmap srcBitmap) {
if (view.getPageIndex() != currentIndex || eventManage.isTouchEventIn()
|| !eventManage.isScrollerFinished())
{
|| !eventManage.isScrollerFinished()) {
return;
}
pageListViewListener.exportImage(view, srcBitmap);
}
/**
*
* @param x is don't zoom
* @param y is don't zoom
* @return
*/
public boolean isPointVisibleOnScreen(int x, int y)
{
x = (int)(x * zoom);
y = (int)(y * zoom);
public boolean isPointVisibleOnScreen(int x, int y) {
x = (int) (x * zoom);
y = (int) (y * zoom);
APageListItem item = getCurrentPageView();
if (item == null)
{
if (item == null) {
return false;
}
int left = Math.max(item.getLeft(), 0) - item.getLeft();
......@@ -627,42 +533,30 @@ public class APageListView extends AdapterView<Adapter>
}
/**
*
* @param x is don't zoom
* @param y is don't zoom
* @return
*/
public void setItemPointVisibleOnScreen(int x, int y)
{
if (x < 0 && y < 0)
{
return ;
public void setItemPointVisibleOnScreen(int x, int y) {
if (x < 0 && y < 0) {
return;
}
APageListItem item = getCurrentPageView();
if (item != null && !isPointVisibleOnScreen(x, y))
{
x = (int)(x * zoom);
y = (int)(y * zoom);
if (item != null && !isPointVisibleOnScreen(x, y)) {
x = (int) (x * zoom);
y = (int) (y * zoom);
int cvLeft = 0, cvRight = 0, cvTop = 0, cvBottom = 0;
if (x > 0)
{
if (x + getWidth() > item.getMeasuredWidth())
{
if (x > 0) {
if (x + getWidth() > item.getMeasuredWidth()) {
cvLeft = -(item.getMeasuredWidth() - getWidth());
}
else
{
} else {
cvLeft = -x;
}
}
if (y > 0)
{
if (y + getHeight() > item.getMeasuredHeight())
{
if (y > 0) {
if (y + getHeight() > item.getMeasuredHeight()) {
cvTop = -(item.getMeasuredHeight() - getHeight());
}
else
{
} else {
cvTop = -y;
}
}
......@@ -671,8 +565,7 @@ public class APageListView extends AdapterView<Adapter>
Point cvOffset = getScreenSizeOffset(item);
cvRight = cvLeft + item.getMeasuredWidth();
cvBottom = cvTop + item.getMeasuredHeight();
if (item.getMeasuredHeight() <= getHeight())
{
if (item.getMeasuredHeight() <= getHeight()) {
Point corr = getCorrection(getScrollBounds(cvLeft, cvTop, cvRight, cvBottom));
cvTop += corr.y;
cvBottom += corr.y;
......@@ -680,11 +573,9 @@ public class APageListView extends AdapterView<Adapter>
item.layout(cvLeft, cvTop, cvRight, cvBottom);
// previous page
if (currentIndex > 0)
{
if (currentIndex > 0) {
View preView = childViewsCache.get(currentIndex - 1);
if (preView != null)
{
if (preView != null) {
Point leftOffset = getScreenSizeOffset(preView);
int gap = leftOffset.x + GAP + cvOffset.x;
......@@ -694,11 +585,9 @@ public class APageListView extends AdapterView<Adapter>
}
}
// next page
if (currentIndex + 1 < pageAdapter.getCount())
{
if (currentIndex + 1 < pageAdapter.getCount()) {
View nextView = childViewsCache.get(currentIndex + 1);
if (nextView != null)
{
if (nextView != null) {
Point rightOffset = getScreenSizeOffset(nextView);
int gap = cvOffset.x + GAP + rightOffset.x;
......@@ -715,75 +604,59 @@ public class APageListView extends AdapterView<Adapter>
/**
*
*/
public Object getModel()
{
public Object getModel() {
return pageListViewListener.getModel();
}
/**
*
* @return
*/
public int getDisplayedPageIndex()
{
public int getDisplayedPageIndex() {
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);
}
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);
}
/**
*
*
*/
public void setZoom(float zoomValue, int pointX, int pointY, final boolean isRepaint)
{
if ((int)(zoomValue * MainConstant.ZOOM_ROUND) == (int)(this.zoom * MainConstant.ZOOM_ROUND))
{
public void setZoom(float zoomValue, int pointX, int pointY, final boolean isRepaint) {
if ((int) (zoomValue * MainConstant.ZOOM_ROUND) == (int) (this.zoom * MainConstant.ZOOM_ROUND)) {
return;
}
isInitZoom = true;
if(pointX == Integer.MIN_VALUE && pointY == Integer.MIN_VALUE)
{
if (pointX == Integer.MIN_VALUE && pointY == Integer.MIN_VALUE) {
pointX = getWidth() / 2;
pointY = getHeight() / 2;
}
float oldZoom = zoom;
zoom = zoomValue;
pageListViewListener.changeZoom();
post(new Runnable()
{
@ Override
public void run()
{
if (isRepaint)
{
post(new Runnable() {
@Override
public void run() {
if (isRepaint) {
APageListItem pageView = getCurrentPageView();
if (pageView != null)
{
if (pageView != null) {
postRepaint(pageView);
}
}
}
});
if (isRepaint)
{
if (isRepaint) {
APageListItem v = getCurrentPageView();
int left = 0;
int top = 0;
if (v != null)
{
if (v != null) {
left = v.getLeft();
top = v.getTop();
}
......@@ -792,8 +665,8 @@ public class APageListView extends AdapterView<Adapter>
int viewFocusX = pointX - (left + eventManage.getScrollX());
int viewFocusY = pointY - (top + eventManage.getScrollY());
// Scroll to maintain the focus point
eventManage.setScrollAxisValue((int)(viewFocusX - viewFocusX * factor),
(int)(viewFocusY - viewFocusY * factor));
eventManage.setScrollAxisValue((int) (viewFocusX - viewFocusX * factor),
(int) (viewFocusY - viewFocusY * factor));
requestLayout();
}
......@@ -808,8 +681,7 @@ public class APageListView extends AdapterView<Adapter>
* = 1, fit size of pageWidth
* = 2, fit size of PageHeight
*/
public void setFitSize(int value)
{
public void setFitSize(int value) {
setZoom(getFitZoom(value), true);
postInvalidate();
}
......@@ -823,27 +695,22 @@ public class APageListView extends AdapterView<Adapter>
* = 2, left/right alignment
* = 3, left/right and top/bottom alignment
*/
public int getFitSizeState()
{
public int getFitSizeState() {
int state = 0;
APageListItem item = getCurrentPageView();
if (item != null)
{
if (item != null) {
int w = Math.abs(item.getWidth() - getWidth());
int h = Math.abs(item.getHeight() - getHeight());
// left/right and top/bottom alignment
if (w < 2 && h < 2)
{
if (w < 2 && h < 2) {
state = 3;
}
// left/right alignment
else if (w < 2 && h >= 2)
{
else if (w < 2 && h >= 2) {
state = 2;
}
// top/bottom alignment
else if (w >= 2 && h < 2)
{
else if (w >= 2 && h < 2) {
state = 1;
}
}
......@@ -853,141 +720,110 @@ public class APageListView extends AdapterView<Adapter>
/**
*
*/
public float getZoom()
{
public float getZoom() {
return zoom;
}
/**
*
*/
public float getFitZoom()
{
public float getFitZoom() {
return getFitZoom(0);
}
/**
*
*/
public float getFitZoom(int value)
{
if (currentIndex < 0 || currentIndex >= pageListViewListener.getPageCount())
{
public float getFitZoom(int value) {
if (currentIndex < 0 || currentIndex >= pageListViewListener.getPageCount()) {
return 1.0f;
}
Rect rect = pageListViewListener.getPageSize(currentIndex);
int viewWidth = getWidth();
int viewHeight = getHeight();
ViewParent v = getParent();
while (viewWidth == 0 && v != null)
{
if (v == null || !(v instanceof View))
{
while (viewWidth == 0 && v != null) {
if (v == null || !(v instanceof View)) {
break;
}
viewWidth = ((View)v).getWidth();
viewHeight = ((View)v).getHeight();
viewWidth = ((View) v).getWidth();
viewHeight = ((View) v).getHeight();
v = v.getParent();
}
if (viewWidth == 0 || viewHeight == 0)
{
if (viewWidth == 0 || viewHeight == 0) {
return 1.0f;
}
float maxZoom = MainConstant.MAXZOOM / MainConstant.STANDARD_RATE;
if (value == 0)
{
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()), maxZoom);
if (value == 0) {
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()), 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);
} 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;
}
/**
* get current display page number (base 1)
*
* @return page number (base 1)
*/
public int getCurrentPageNumber()
{
public int getCurrentPageNumber() {
return currentIndex + 1;
}
/**
*
* @see android.widget.AdapterView#getAdapter()
*
*/
@ Override
public Adapter getAdapter()
{
@Override
public Adapter getAdapter() {
return pageAdapter;
}
/**
*
* @see android.widget.AdapterView#setAdapter(android.widget.Adapter)
*
*/
@ Override
public void setAdapter(Adapter adapter)
{
@Override
public void setAdapter(Adapter adapter) {
this.pageAdapter = adapter;
}
/**
* (non-Javadoc)
*
*(non-Javadoc)
* @see android.widget.AdapterView#getSelectedView()
*
*/
@ Override
public View getSelectedView()
{
@Override
public View getSelectedView() {
return null;
}
/**
*
* @see android.widget.AdapterView#setSelection(int)
*
*/
@ Override
public void setSelection(int position)
{
@Override
public void setSelection(int position) {
}
/**
*
* @param v
*/
protected void postUnRepaint(final APageListItem view)
{
if (view == null)
{
protected void postUnRepaint(final APageListItem view) {
if (view == null) {
return;
}
post(new Runnable()
{
public void run()
{
post(new Runnable() {
public void run() {
view.removeRepaintImageView();
}
});
......@@ -996,32 +832,23 @@ public class APageListView extends AdapterView<Adapter>
/**
*
* @param v
*/
public void postRepaint(final APageListItem view)
{
if (view == null)
{
public void postRepaint(final APageListItem view) {
if (view == null) {
return;
}
post(new Runnable()
{
public void run()
{
post(new Runnable() {
public void run() {
view.addRepaintImageView(null);
}
});
}
/**
*
* @param i
* @return
*/
public APageListItem getCurrentPageView()
{
if (childViewsCache != null)
{
public APageListItem getCurrentPageView() {
if (childViewsCache != null) {
return childViewsCache.get(currentIndex);
}
return null;
......@@ -1031,48 +858,40 @@ public class APageListView extends AdapterView<Adapter>
/**
*
*/
protected IPageListViewListener getPageListViewListener()
{
protected IPageListViewListener getPageListViewListener() {
return this.pageListViewListener;
}
/**
*
* @param i
* @return
*/
private APageListItem createPageView(int pageIndex)
{
private APageListItem createPageView(int pageIndex) {
APageListItem pageView = childViewsCache.get(pageIndex);
if (pageView == null)
{
pageView = (APageListItem)pageAdapter.getView(pageIndex,
if (pageView == null) {
pageView = (APageListItem) pageAdapter.getView(pageIndex,
(pageViewCache.size() == 0 ? null : pageViewCache.removeFirst()), this);
LayoutParams params = pageView.getLayoutParams();
if (params == null)
{
if (params == null) {
params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
}
addViewInLayout(pageView, 0, params, true);
// Record the view against it's adapter index
childViewsCache.append(pageIndex, pageView);
// 计算page的size
pageView.measure(View.MeasureSpec.EXACTLY | (int)(pageView.getPageWidth() * zoom),
View.MeasureSpec.EXACTLY | (int)(pageView.getPageHeight() * zoom));
pageView.measure(View.MeasureSpec.EXACTLY | (int) (pageView.getPageWidth() * zoom),
View.MeasureSpec.EXACTLY | (int) (pageView.getPageHeight() * zoom));
}
return pageView;
}
/**
*
* @param left
* @param top
* @param right
* @param bottom
* @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 xmax = -left;
int ymin = getHeight() - bottom;
......@@ -1080,12 +899,10 @@ public class APageListView extends AdapterView<Adapter>
// In either dimension, if view smaller than screen then
// constrain it to be central
if (xmin > xmax)
{
if (xmin > xmax) {
xmin = xmax = (xmin + xmax) / 2;
}
if (ymin > ymax)
{
if (ymin > ymax) {
ymin = ymax = (ymin + ymax) / 2;
}
......@@ -1093,12 +910,10 @@ public class APageListView extends AdapterView<Adapter>
}
/**
*
* @param v
* @return
*/
protected Rect getScrollBounds(View v)
{
protected Rect getScrollBounds(View v) {
// There can be scroll amounts not yet accounted for in
// onLayout, so add mXScroll and mYScroll to the current
// positions when calculating the bounds.
......@@ -1109,24 +924,20 @@ public class APageListView extends AdapterView<Adapter>
}
/**
*
* @param bounds
* @return
*/
protected Point getCorrection(Rect bounds)
{
protected Point getCorrection(Rect bounds) {
return new Point(Math.min(Math.max(0, bounds.left), bounds.right),
Math.min(Math.max(0, bounds.top), bounds.bottom));
}
/**
*
* @param v
* @return
*/
protected Point getScreenSizeOffset(View v)
{
protected Point getScreenSizeOffset(View v) {
return new Point(Math.max((getWidth() - v.getMeasuredWidth()) / 2, 0),
Math.max((getHeight() - v.getMeasuredHeight()) / 2, 0));
}
......@@ -1134,75 +945,62 @@ public class APageListView extends AdapterView<Adapter>
/**
*
*/
public int getPageCount()
{
public int 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);
}
/**
*
*/
public boolean isInit()
{
public boolean isInit() {
return this.isInit;
}
/**
*
*/
public void setDoRequstLayout(boolean b)
{
public void setDoRequstLayout(boolean b) {
this.isDoRequestLayout = b;
}
public boolean isInitZoom()
{
public boolean isInitZoom() {
return isInitZoom;
}
public void setInitZoom(boolean isInitZoom)
{
public void setInitZoom(boolean isInitZoom) {
this.isInitZoom = isInitZoom;
}
/**
*
*/
public void dispose()
{
public void dispose() {
pageListViewListener = null;
if (eventManage != null)
{
if (eventManage != null) {
eventManage.dispose();
eventManage = null;
}
if (pageAdapter instanceof APageListAdapter)
{
((APageListAdapter)pageAdapter).dispose();
if (pageAdapter instanceof APageListAdapter) {
((APageListAdapter) pageAdapter).dispose();
pageAdapter = null;
}
if (childViewsCache != null)
{
if (childViewsCache != null) {
int size = childViewsCache.size();
for (int i = 0; i < size; i++)
{
for (int i = 0; i < size; i++) {
childViewsCache.valueAt(i).dispose();
}
childViewsCache.clear();
childViewsCache = null;
}
if (pageViewCache != null)
{
for (APageListItem page : pageViewCache)
{
if (pageViewCache != null) {
for (APageListItem page : pageViewCache) {
page.dispose();
}
pageViewCache.clear();
......
......@@ -161,4 +161,6 @@ public interface IPageListViewListener
* page list view moving position
*/
public int getPageListViewMovingPosition();
public void singleTab();
}
......@@ -434,6 +434,11 @@ public class PrintWord extends FrameLayout implements IPageListViewListener {
return control.getMainFrame().getPageListViewMovingPosition();
}
@Override
public void singleTab() {
}
/**
*
*/
......
......@@ -39,7 +39,6 @@ import com.cherry.lib.doc.office.system.beans.AEventManage;
*/
public class WPEventManage extends AEventManage {
/**
* @param spreadsheet
*/
public WPEventManage(Word word, IControl 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