/*
* Copyright (c) 2004-2009 XMLVM --- An XML-based Programming Language
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* 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 for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 675 Mass
* Ave, Cambridge, MA 02139, USA.
*
* For more information, visit the XMLVM Home Page at http://www.xmlvm.org
*/
package android.widget;
import java.util.Set;
import org.xmlvm.iphone.UIEvent;
import org.xmlvm.iphone.UITouch;
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
public class ImageButton extends ImageView {
public ImageButton(Context c) {
super(c);
}
public ImageButton(Context c, AttributeSet attrs) {
super(c, attrs);
}
@Override
public void setOnClickListener(OnClickListener listener) {
final OnClickListener theListener = listener;
this.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP) {
theListener.onClick(ImageButton.this);
return true;
}
return false;
}
});
}
@Override
protected boolean processTouchesEvent(int action, Set<UITouch> touches, UIEvent event) {
if (action == MotionEvent.ACTION_DOWN) {
xmlvmSetDrawableState(PRESSED_STATE_SET);
} else if (action == MotionEvent.ACTION_UP) {
xmlvmSetDrawableState(EMPTY_STATE_SET);
}
return super.processTouchesEvent(action, touches, event);
}
}