2010-03-08 15:36:36 -05:00
|
|
|
/*
|
2010-03-12 14:35:25 -05:00
|
|
|
Yaaic - Yet Another Android IRC Client
|
2010-03-08 15:36:36 -05:00
|
|
|
|
2010-03-13 10:52:20 -05:00
|
|
|
Copyright 2009-2010 Sebastian Kaspari
|
2010-03-08 15:36:36 -05:00
|
|
|
|
|
|
|
This file is part of Yaaic.
|
|
|
|
|
|
|
|
Yaaic 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 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Yaaic 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 Yaaic. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
package org.yaaic.view;
|
|
|
|
|
|
|
|
import org.yaaic.adapter.MessageListAdapter;
|
|
|
|
|
|
|
|
import android.content.Context;
|
2010-03-20 16:49:46 -04:00
|
|
|
import android.graphics.Canvas;
|
2010-03-08 15:36:36 -05:00
|
|
|
import android.view.MotionEvent;
|
2010-03-20 16:49:46 -04:00
|
|
|
import android.view.View;
|
|
|
|
import android.widget.Gallery;
|
2010-03-08 15:36:36 -05:00
|
|
|
import android.widget.ListView;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A customized ListView for Messages
|
|
|
|
*
|
|
|
|
* @author Sebastian Kaspari <sebastian@yaaic.org>
|
|
|
|
*/
|
|
|
|
public class MessageListView extends ListView
|
|
|
|
{
|
|
|
|
public static final String TAG = "Yaaic/MessageListView";
|
|
|
|
|
|
|
|
private boolean delegate = true;
|
2010-03-20 16:49:46 -04:00
|
|
|
private View parent;
|
|
|
|
private int parentWidth;
|
|
|
|
private int parentHeight;
|
2010-03-08 15:36:36 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new MessageListView
|
|
|
|
*
|
|
|
|
* @param context
|
|
|
|
*/
|
2010-03-20 16:49:46 -04:00
|
|
|
public MessageListView(Context context, View parent)
|
2010-03-08 15:36:36 -05:00
|
|
|
{
|
|
|
|
super(context);
|
2010-03-20 16:49:46 -04:00
|
|
|
|
|
|
|
this.parent = parent;
|
|
|
|
|
|
|
|
parentWidth = parent.getWidth();
|
|
|
|
parentHeight = parent.getHeight();
|
2010-03-08 15:36:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Should all touch events delegated?
|
|
|
|
*
|
|
|
|
* @param delegate If true all touch events will be delegated, otherwise the listview will handle them
|
|
|
|
*/
|
|
|
|
public void setDelegateTouchEvents(boolean delegate)
|
|
|
|
{
|
|
|
|
this.delegate = delegate;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle touch screen motion events
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public boolean onTouchEvent(MotionEvent event)
|
|
|
|
{
|
|
|
|
if (delegate) {
|
|
|
|
// We delegate the touch events to the underlying view
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return super.onTouchEvent(event);
|
|
|
|
}
|
|
|
|
}
|
2010-03-20 16:49:46 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* On draw
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
protected void onDraw(Canvas canvas)
|
|
|
|
{
|
|
|
|
if (parent.getWidth() != parentWidth || parent.getHeight() != parentHeight) {
|
|
|
|
// parent size changed, resizing this child too
|
|
|
|
|
|
|
|
parentWidth = parent.getWidth();
|
|
|
|
parentHeight = parent.getHeight();
|
|
|
|
|
|
|
|
this.setLayoutParams(new Gallery.LayoutParams(
|
|
|
|
parent.getWidth() / 100 * 85,
|
|
|
|
parent.getHeight()
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
super.onDraw(canvas);
|
|
|
|
}
|
2010-03-08 15:36:36 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the adapter of this MessageListView
|
|
|
|
* (Helper to avoid casting)
|
|
|
|
*
|
|
|
|
* @return The MessageListAdapter
|
|
|
|
*/
|
|
|
|
public MessageListAdapter getAdapter()
|
|
|
|
{
|
|
|
|
return (MessageListAdapter) super.getAdapter();
|
|
|
|
}
|
|
|
|
}
|