Android Open Source - HotSpot_Android Message List Adapter






From Project

Back to project page HotSpot_Android.

License

The source code is released under:

GNU General Public License

If you think the Android project HotSpot_Android 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

package com.ticknardif.hotspot;
/*from  www .j a v a2  s  .c  o  m*/
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import java.util.List;

public class MessageListAdapter extends ArrayAdapter<Message> {

    public MessageListAdapter(Context context, int textViewResourceId) {
        super(context, textViewResourceId);
    }

    public MessageListAdapter(Context context, int resource, List<Message> messages) {
        super(context, resource, messages);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        View view = convertView;

        if(view == null) {
            LayoutInflater vi;
            vi = LayoutInflater.from(getContext());
            view = vi.inflate(R.layout.message_list_item, null);
        }

        Message message = getItem(position);

        if (message != null) {
            TextView contentTV = (TextView) view.findViewById(R.id.message_content);

            // Set the message content in the TextView
            if(contentTV != null) {
                contentTV.setText(message.getMessage());
            }

            // Set the message sender name in the TextView
            TextView sender_nameTV = (TextView) view.findViewById(R.id.message_sender_name);

            if(sender_nameTV != null) {
                //Need Server to send User NickName
                sender_nameTV.setText(message.getDisplayName());
            }

            View wrapper = (View) view.findViewById(R.id.message_wrapper);

            int backgroundDrawableId = message.owned ? R.drawable.my_message_bg : R.drawable.other_message_bg;

            if(wrapper != null) {
                // Keep the padding that we set in the XML (overwriting the background overwrites this as well)
                int bottom = wrapper.getPaddingBottom();
                int top = wrapper.getPaddingTop();
                int left = wrapper.getPaddingLeft();
                int right = wrapper.getPaddingRight();

                // Set the background to our custom bg resource
                wrapper.setBackground(getContext().getResources().getDrawable(backgroundDrawableId));

                // Restore the padding
                wrapper.setPaddingRelative(left, top, right, bottom);
            }
        }

        return view;
    }
}




Java Source Code List

com.example.ticknardif.hotspot.ApplicationTest.java
com.example.ticknardif.hotspot.util.SystemUiHiderBase.java
com.example.ticknardif.hotspot.util.SystemUiHiderHoneycomb.java
com.example.ticknardif.hotspot.util.SystemUiHider.java
com.ticknardif.hotspot.AppStartActivity.java
com.ticknardif.hotspot.ChatroomActivity.java
com.ticknardif.hotspot.ChatroomListAdapter.java
com.ticknardif.hotspot.ChatroomOverlay.java
com.ticknardif.hotspot.Chatroom.java
com.ticknardif.hotspot.CreateAccountActivity.java
com.ticknardif.hotspot.CreateChatroomFragment.java
com.ticknardif.hotspot.GcmBroadcastReceiver.java
com.ticknardif.hotspot.GcmIntentService.java
com.ticknardif.hotspot.LoginActivity.java
com.ticknardif.hotspot.MainActivity.java
com.ticknardif.hotspot.MessageListAdapter.java
com.ticknardif.hotspot.Message.java
com.ticknardif.hotspot.WebService.java
com.ticknardif.hotspot.RESTresponses.ChatRoomCreationResponse.java
com.ticknardif.hotspot.RESTresponses.ChatroomResponse.java
com.ticknardif.hotspot.RESTresponses.ChatroomUserResponse.java
com.ticknardif.hotspot.RESTresponses.CreateChatroomResponse.java
com.ticknardif.hotspot.RESTresponses.GCMResponse.java
com.ticknardif.hotspot.RESTresponses.JoinChatroomResponse.java
com.ticknardif.hotspot.RESTresponses.LeaveChatroomResponse.java
com.ticknardif.hotspot.RESTresponses.LoginResponse.java
com.ticknardif.hotspot.RESTresponses.LogoutResponse.java
com.ticknardif.hotspot.RESTresponses.UpdateLocationResponse.java
com.ticknardif.hotspot.RESTresponses.UserResponse.java