View Single Post
Old 01-27-2012, 07:51 AM   #15
Morkl
Connoisseur
Morkl can talk to the animals.Morkl can talk to the animals.Morkl can talk to the animals.Morkl can talk to the animals.Morkl can talk to the animals.Morkl can talk to the animals.Morkl can talk to the animals.Morkl can talk to the animals.Morkl can talk to the animals.Morkl can talk to the animals.Morkl can talk to the animals.
 
Posts: 80
Karma: 68347
Join Date: Oct 2009
Location: Sweden
Device: PRS-T1
Quote:
Originally Posted by bardo View Post
Thanks for providing sample code for android.view.View, I will try it out (still a way to go to set up the dev environment and start coding..)

Below is how Aardict (btw an amazing offline Wikipedia viewer including MathML!) actually does its page turn. Could the articleView.pageUp function work with your interface?

How to include this in the generic Aard Dicitonary code so that other non-Sony devices still work?

Thanks, Bardo

Code:
/* This file is part of Aard Dictionary for Android <http://aarddict.org>.
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 3
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License <http://www.gnu.org/licenses/gpl-3.0.txt>
 * for more details.
 * 
 * Copyright (C) 2010 Igor Tkach
*/

package aarddict.android;

import android.content.Context;
import android.util.AttributeSet;
import android.webkit.WebView;

class ArticleView extends WebView {

	interface ScrollListener {
		void onScroll(int l, int t, int oldl, int oldt);
	}
	
	private ScrollListener scrollListener;
	
	public ArticleView(Context context) {
		super(context);
	}

	public ArticleView(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	public ArticleView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
	}

	@Override
	protected void onScrollChanged(int l, int t, int oldl, int oldt) {
		super.onScrollChanged(l, t, oldl, oldt);
		if (scrollListener != null) {
			scrollListener.onScroll(l, t, oldl, oldt);			
		}
	}

	public void setOnScrollListener(ScrollListener l) {
		this.scrollListener = l;
	}
}
It should just be a matter of including the aforementioned methods and variable in the ArticleView class and keeping track of the update mode variable:

Code:
class ArticleView extends WebView {
	private int mUpdateMode = 3;
	
	public void setUpdateMode(int m) {
		this.mUpdateMode = m;
	}
	
	interface ScrollListener {
		void onScroll(int l, int t, int oldl, int oldt);
	}
	
	private ScrollListener scrollListener;
	
	public ArticleView(Context context) {
		super(context);
	}

	public ArticleView(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	public ArticleView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
	}

	@Override
	protected void onScrollChanged(int l, int t, int oldl, int oldt) {
		super.onScrollChanged(l, t, oldl, oldt);
		if (scrollListener != null) {
			scrollListener.onScroll(l, t, oldl, oldt);			
		}
	}

	public void setOnScrollListener(ScrollListener l) {
		this.scrollListener = l;
	}

	@Override
	public void invalidate() {
		super.invalidate(mUpdateMode);
	}

	@Override
	public void invalidate(int l, int t, int r, int b) {
		super.invalidate(l, t, r, b, mUpdateMode);
	}

	@Override
	public void invalidate(Rect dirty) {
		super.invalidate(dirty, mUpdateMode);
	}

	@Override
	public void invalidateDrawable(Drawable drawable) {
		super.invalidateDrawable(drawable, mUpdateMode);
	}

	@Override
	public void postInvalidate() {
		super.postInvalidate(mUpdateMode);
	}

	@Override
	public void postInvalidate(int left, int top, int right, int bottom) {
		super.postInvalidate(left, top, right, bottom, mUpdateMode);
	}

	@Override
	public void postInvalidateDelayed(long delayMilliseconds, int left,
			int top, int right, int bottom) {
		super.postInvalidateDelayed(delayMilliseconds, left, top, right, bottom, mUpdateMode);
	}

	@Override
	public void postInvalidateDelayed(long delayMilliseconds) {
		super.postInvalidateDelayed(delayMilliseconds, mUpdateMode);
	}

	@Override
	public void scrollBy(int x, int y) {
		super.scrollBy(x, y, mUpdateMode);
	}

	@Override
	public void scrollTo(int x, int y) {
		super.scrollTo(x, y, mUpdateMode);
	}
}
For it to work with other devices, I guess you would have to make sure the standard methods are called instead of the special ones when running on any other device, i.e. something like:

Code:
	@Override
	public void invalidate() {
		if (It's.A.Sony()) {
			super.invalidate(mUpdateMode);
		} else super.invalidate();
	}
I think the dalvik vm only breaks down if it tries to call a method that isn't defined; not when it is referenced but never accessed. Can't verify this right now though.
Morkl is offline   Reply With Quote