| 1 | package aarddict.android; |
| 2 | |
| 3 | import android.content.Context; |
| 4 | import android.graphics.Canvas; |
| 5 | import android.util.AttributeSet; |
| 6 | |
| 7 | public class EinkArticleView extends ArticleView { |
| 8 | |
| 9 | public EinkArticleView(Context context) { |
| 10 | super(context); |
| 11 | } |
| 12 | public EinkArticleView(Context context, AttributeSet attrs) { |
| 13 | super(context, attrs); |
| 14 | } |
| 15 | public EinkArticleView(Context context, AttributeSet attrs, int defStyle) { |
| 16 | super(context, attrs, defStyle); |
| 17 | } |
| 18 | |
| 19 | private ArticleView articleView; |
| 20 | public static int HSCROLL_SIZE; |
| 21 | |
| 22 | @Override |
| 23 | protected void onDraw (Canvas canvas) { |
| 24 | N2EpdController.setGL16Mode(0); // partial refresh |
| 25 | super.onDraw(canvas); |
| 26 | } |
| 27 | |
| 28 | public void onSizeChanged(int w, int h, int ow, int oh) { |
| 29 | super.onSizeChanged(w, h, ow, oh); |
| 30 | |
| 31 | articleView = (ArticleView)findViewById(R.id.EinkArticleView); |
| 32 | HSCROLL_SIZE = articleView.getHeight() - 20; |
| 33 | } |
| 34 | |
| 35 | public boolean pageUp(boolean top) { |
| 36 | int cury = articleView.getScrollY(); |
| 37 | if (cury == 0) { return false; } |
| 38 | int newy = cury - HSCROLL_SIZE; |
| 39 | if (newy < 0) { |
| 40 | newy = 0; |
| 41 | } |
| 42 | articleView.scrollTo(0, newy); |
| 43 | return true; |
| 44 | } |
| 45 | |
| 46 | public boolean pageDown(boolean bottom) { |
| 47 | int cury = articleView.getScrollY(); |
| 48 | int hmax = 0; |
| 49 | if (HSCROLL_SIZE < articleView.getContentHeight() ) |
| 50 | hmax = (int) (articleView.getContentHeight() * articleView.getScale()) - HSCROLL_SIZE; |
| 51 | if (cury == hmax) { return false; } |
| 52 | int newy = cury + HSCROLL_SIZE; |
| 53 | if (newy > hmax) { |
| 54 | newy = hmax; |
| 55 | } |
| 56 | if (cury != newy) { |
| 57 | articleView.scrollTo(0, newy); |
| 58 | } |
| 59 | return true; |
| 60 | } |
| 61 | } |