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
|
|
|
|
2011-02-05 07:00:12 -05:00
|
|
|
Copyright 2009-2011 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/>.
|
2011-01-25 15:02:27 -05:00
|
|
|
*/
|
2010-03-08 15:36:36 -05:00
|
|
|
package org.yaaic.view;
|
|
|
|
|
2011-05-29 20:49:46 -04:00
|
|
|
import org.yaaic.R;
|
2010-03-08 15:36:36 -05:00
|
|
|
import org.yaaic.adapter.MessageListAdapter;
|
2010-04-25 09:29:08 -04:00
|
|
|
import org.yaaic.listener.MessageClickListener;
|
2010-03-08 15:36:36 -05:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
/**
|
2011-01-25 15:02:27 -05:00
|
|
|
* A customized ListView for Messages
|
2010-03-08 15:36:36 -05:00
|
|
|
*
|
|
|
|
* @author Sebastian Kaspari <sebastian@yaaic.org>
|
|
|
|
*/
|
|
|
|
public class MessageListView extends ListView
|
|
|
|
{
|
2011-05-29 20:49:46 -04:00
|
|
|
private boolean switched = false;
|
2011-01-25 15:02:27 -05:00
|
|
|
private final View parent;
|
2010-11-18 12:52:19 -05:00
|
|
|
private int parentWidth;
|
|
|
|
private int parentHeight;
|
2011-05-29 20:49:46 -04:00
|
|
|
private int padding;
|
|
|
|
private int paddingWide;
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
/**
|
|
|
|
* Create a new MessageListView
|
|
|
|
*
|
|
|
|
* @param context
|
|
|
|
*/
|
|
|
|
public MessageListView(Context context, View parent)
|
|
|
|
{
|
|
|
|
super(context);
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
this.parent = parent;
|
2011-05-29 20:49:46 -04:00
|
|
|
setOnItemClickListener(MessageClickListener.getInstance());
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
parentWidth = parent.getWidth();
|
|
|
|
parentHeight = parent.getHeight();
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2011-05-29 20:49:46 -04:00
|
|
|
setDivider(null);
|
|
|
|
setLayoutParams(new Gallery.LayoutParams(
|
|
|
|
parentWidth*85/100,
|
|
|
|
parentHeight
|
|
|
|
));
|
|
|
|
|
|
|
|
setBackgroundResource(R.layout.rounded);
|
|
|
|
setCacheColorHint(0xee000000);
|
|
|
|
setVerticalFadingEdgeEnabled(false);
|
|
|
|
setScrollBarStyle(SCROLLBARS_OUTSIDE_INSET);
|
|
|
|
setTranscriptMode(TRANSCRIPT_MODE_ALWAYS_SCROLL);
|
|
|
|
|
|
|
|
// Scale padding by screen density
|
|
|
|
float density = context.getResources().getDisplayMetrics().density;
|
|
|
|
padding = (int)(5 * density);
|
|
|
|
paddingWide = (int)(12 * density);
|
|
|
|
setPadding(padding, padding, padding, padding);
|
2010-11-18 12:52:19 -05:00
|
|
|
}
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
/**
|
|
|
|
* Handle touch screen motion events
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public boolean onTouchEvent(MotionEvent event)
|
|
|
|
{
|
2011-05-29 20:49:46 -04:00
|
|
|
if (!switched) {
|
2011-01-25 15:02:27 -05:00
|
|
|
// We delegate the touch events to the underlying view
|
2010-11-18 12:52:19 -05:00
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return super.onTouchEvent(event);
|
|
|
|
}
|
|
|
|
}
|
2010-03-20 16:49:46 -04:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
/**
|
|
|
|
* On draw
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
protected void onDraw(Canvas canvas)
|
|
|
|
{
|
2011-05-29 20:49:46 -04:00
|
|
|
if (parent.getWidth() != parentWidth || parent.getHeight() != parentHeight) {
|
2010-11-18 12:52:19 -05:00
|
|
|
// parent size changed, resizing this child too
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
parentWidth = parent.getWidth();
|
|
|
|
parentHeight = parent.getHeight();
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2011-05-29 20:49:46 -04:00
|
|
|
if (!switched) {
|
|
|
|
setLayoutParams(new Gallery.LayoutParams(
|
|
|
|
parentWidth*85/100,
|
|
|
|
parentHeight
|
|
|
|
));
|
|
|
|
}
|
2010-11-18 12:52:19 -05:00
|
|
|
}
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
super.onDraw(canvas);
|
|
|
|
}
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
/**
|
|
|
|
* Get the adapter of this MessageListView
|
|
|
|
* (Helper to avoid casting)
|
|
|
|
*
|
|
|
|
* @return The MessageListAdapter
|
|
|
|
*/
|
2011-01-25 15:02:27 -05:00
|
|
|
@Override
|
2010-11-18 12:52:19 -05:00
|
|
|
public MessageListAdapter getAdapter()
|
|
|
|
{
|
|
|
|
return (MessageListAdapter) super.getAdapter();
|
|
|
|
}
|
2011-05-29 20:49:46 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set whether this conversation is switched (taking up all of deck's space
|
|
|
|
* and handling touch events itself)
|
|
|
|
*/
|
|
|
|
public void setSwitched(boolean switched)
|
|
|
|
{
|
|
|
|
this.switched = switched;
|
|
|
|
|
|
|
|
if (switched) {
|
|
|
|
setLayoutParams(new Gallery.LayoutParams(Gallery.LayoutParams.FILL_PARENT, Gallery.LayoutParams.FILL_PARENT));
|
|
|
|
setTranscriptMode(TRANSCRIPT_MODE_NORMAL);
|
|
|
|
setPadding(paddingWide, padding, paddingWide, padding);
|
|
|
|
} else {
|
|
|
|
setLayoutParams(new Gallery.LayoutParams(parentWidth*85/100, parentHeight));
|
|
|
|
setTranscriptMode(TRANSCRIPT_MODE_ALWAYS_SCROLL);
|
|
|
|
setPadding(padding, padding, padding, padding);
|
|
|
|
}
|
|
|
|
}
|
2010-03-08 15:36:36 -05:00
|
|
|
}
|