1
0
mirror of https://github.com/moparisthebest/Yaaic synced 2024-11-22 17:02:21 -05:00

ConversationSwitcher: Draw one dot for each conversation with different colors depending on status

This commit is contained in:
Sebastian Kaspari 2010-05-12 10:28:37 +02:00
parent d3ef904fa2
commit 1e8eaf8a7d

View File

@ -20,6 +20,11 @@ along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
*/
package org.yaaic.view;
import java.util.Collection;
import org.yaaic.model.Conversation;
import org.yaaic.model.Server;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
@ -35,6 +40,9 @@ import android.view.View;
*/
public class ConversationSwitcher extends View
{
private static final boolean DEBUG_MODE = false;
private Server server;
private Paint paint;
/**
@ -49,6 +57,22 @@ public class ConversationSwitcher extends View
paint = new Paint();
}
/**
* Set the server whos conversations should be displayed
*
* @param server
*/
public void setServer(Server server)
{
this.server = server;
}
/**
* Measure the size of the view
*
* @param widthMeasureSpec
* @param heightMeasureSpec
*/
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
int width = MeasureSpec.getSize(widthMeasureSpec);
@ -63,16 +87,51 @@ public class ConversationSwitcher extends View
{
super.onDraw(canvas);
if (DEBUG_MODE) {
// Draw debug lines
paint.setColor(0xFFFF0000);
paint.setStyle(Paint.Style.STROKE);
canvas.drawRect(new Rect(0, 0, getWidth() - 1, getHeight() - 1), paint);
}
Log.d("Yaaic", "Circle at " + (getWidth() / 2) + " x " + (getHeight() / 2));
//Log.d("Yaaic", "Drawing...");
// Draw dots
paint.setColor(0xFFFFFFFF);
if (server == null) {
return;
}
int width = getWidth();
int height = getHeight();
Collection<Conversation> conversations = server.getConversations();
int circles = conversations.size();
int startX = width / 2 - circles * 14;
paint.setColor(0xFFDDDDDD);
paint.setStyle(Paint.Style.FILL);
canvas.drawCircle(getWidth() / 2, getHeight() / 2, 5, paint);
int i = 0;
for (Conversation conversation : conversations) {
switch (conversation.getStatus()) {
case Conversation.STATUS_DEFAULT:
paint.setColor(0xFF888888);
break;
case Conversation.STATUS_HIGHLIGHT:
paint.setColor(0xFFDD0000);
break;
case Conversation.STATUS_MESSAGE:
paint.setColor(0xFF00DD00);
break;
case Conversation.STATUS_SELECTED:
paint.setColor(0xFFFFFFFF);
break;
}
canvas.drawCircle(startX + 14 * i, height / 2, 5, paint);
i++;
}
}
}