Android Open Source - passby Chat List Adapter






From Project

Back to project page passby.

License

The source code is released under:

Copyright 2014 Firebase, https://www.firebase.com/ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ?Software??...

If you think the Android project passby listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

//#CSIT6000B#  Rio He       20227977 yheas@connect.ust.hk
//#CSIT6000B#  Cedric Liang 20220395 zliangag@connect.ust.hk
//#CSIT6000B#  Kevin Wang   20225577 zwangbo@connect.ust.hk 
package com.firebase.androidchat;
/*w w  w. j a  v  a2s. c  om*/
import android.app.Activity;
import android.graphics.Color;
import android.view.View;
import android.widget.TextView;
import com.firebase.client.Query;

public class ChatListAdapter extends FirebaseListAdapter<Chat> {

    // The username for this client. We use this to indicate which messages originated from this user
    private String username;

    public ChatListAdapter(Query ref, Activity activity, int layout, String username) {
        super(ref, Chat.class, layout, activity);
        this.username = username;
    }

    @Override
    protected void populateView(View view, Chat chat) {
        // Map a Chat object to an entry in our listview
        String author = chat.getAuthor();
        TextView authorText = (TextView)view.findViewById(R.id.author);
        authorText.setText(author + ": ");
        // If the message was sent by this user, color it differently
        if (author.equals(username)) {
            authorText.setTextColor(Color.RED);
        } else {
            authorText.setTextColor(Color.BLUE);
        }
        ((TextView)view.findViewById(R.id.message)).setText(chat.getMessage());
    }
}




Java Source Code List

com.firebase.androidchat.ChatListAdapter.java
com.firebase.androidchat.Chat.java
com.firebase.androidchat.FirebaseListAdapter.java
com.firebase.androidchat.MainActivity.java
com.firebase.client.LaunchActivity.java
com.firebase.client.LocateActivity.java
com.firebase.client.SearchResultActivity.java
com.firebase.client.SettingActivity.java
com.firebase.database.DatabaseHelper.java
com.firebase.database.DatabaseManager.java
com.firebase.database.DatabaseTask.java
com.firebase.database.User.java