2010-05-03 15:51:03 -04:00
|
|
|
/*
|
|
|
|
Yaaic - Yet Another Android IRC Client
|
|
|
|
|
2011-02-05 07:00:12 -05:00
|
|
|
Copyright 2009-2011 Sebastian Kaspari
|
2010-05-03 15:51:03 -04: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-05-03 15:51:03 -04:00
|
|
|
package org.yaaic.view;
|
|
|
|
|
2010-05-12 04:28:37 -04:00
|
|
|
import java.util.Collection;
|
|
|
|
|
|
|
|
import org.yaaic.model.Conversation;
|
|
|
|
import org.yaaic.model.Server;
|
|
|
|
|
2010-05-03 15:51:03 -04:00
|
|
|
import android.content.Context;
|
|
|
|
import android.graphics.Canvas;
|
2010-05-03 16:22:57 -04:00
|
|
|
import android.graphics.Paint;
|
|
|
|
import android.util.AttributeSet;
|
2010-05-03 15:51:03 -04:00
|
|
|
import android.view.View;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The ConversationSwitcher - The small funny dots at the top ;)
|
|
|
|
*
|
|
|
|
* @author Sebastian Kaspari <sebastian@yaaic.org>
|
|
|
|
*/
|
|
|
|
public class ConversationSwitcher extends View
|
|
|
|
{
|
2010-11-18 12:52:19 -05:00
|
|
|
private Server server;
|
2011-01-25 15:02:27 -05:00
|
|
|
private final Paint paint;
|
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
/**
|
|
|
|
* Create a new ConversationSwitcher
|
|
|
|
*
|
|
|
|
* @param context The Context the view is running in, through which it can access the current theme, resources, etc.
|
|
|
|
*/
|
|
|
|
public ConversationSwitcher(Context context, AttributeSet attributes)
|
|
|
|
{
|
|
|
|
super(context, attributes);
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
paint = new Paint();
|
|
|
|
paint.setStyle(Paint.Style.STROKE);
|
|
|
|
}
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
/**
|
|
|
|
* Set the server whos conversations should be displayed
|
|
|
|
*
|
|
|
|
* @param server
|
|
|
|
*/
|
|
|
|
public void setServer(Server server)
|
|
|
|
{
|
|
|
|
this.server = server;
|
|
|
|
}
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
/**
|
|
|
|
* Measure the size of the view
|
|
|
|
*
|
|
|
|
* @param widthMeasureSpec
|
|
|
|
* @param heightMeasureSpec
|
|
|
|
*/
|
2011-01-25 15:02:27 -05:00
|
|
|
@Override
|
2010-11-18 12:52:19 -05:00
|
|
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
|
|
|
|
{
|
|
|
|
setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), 16);
|
|
|
|
}
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
/**
|
|
|
|
* On draw
|
|
|
|
*/
|
2011-01-25 15:02:27 -05:00
|
|
|
@Override
|
2010-11-18 12:52:19 -05:00
|
|
|
protected void onDraw(Canvas canvas)
|
|
|
|
{
|
|
|
|
super.onDraw(canvas);
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
if (server == null) {
|
|
|
|
return;
|
|
|
|
}
|
2010-05-03 16:22:57 -04:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
Collection<Conversation> conversations = server.getConversations();
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
int i = 0;
|
|
|
|
int width = getWidth();
|
|
|
|
int height = getHeight();
|
|
|
|
int circles = conversations.size();
|
|
|
|
int startX = (width / 2) - (((circles + 1) / 2) * 12);
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
for (Conversation conversation : conversations) {
|
|
|
|
switch (conversation.getStatus()) {
|
|
|
|
case Conversation.STATUS_DEFAULT:
|
|
|
|
paint.setColor(0xFF888888);
|
|
|
|
break;
|
|
|
|
case Conversation.STATUS_HIGHLIGHT:
|
|
|
|
paint.setColor(0xFF880000);
|
|
|
|
break;
|
|
|
|
case Conversation.STATUS_MESSAGE:
|
|
|
|
paint.setColor(0xFF008800);
|
|
|
|
break;
|
|
|
|
case Conversation.STATUS_SELECTED:
|
|
|
|
paint.setColor(0xFFFFFFFF);
|
|
|
|
break;
|
|
|
|
}
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
canvas.drawCircle(startX + 12 * i, height / 2, 4, paint);
|
|
|
|
i++;
|
|
|
|
}
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
}
|
2010-05-03 15:51:03 -04:00
|
|
|
}
|