Android Open Source - BluetoothSPP Message Adapter






From Project

Back to project page BluetoothSPP.

License

The source code is released under:

MIT License

If you think the Android project BluetoothSPP 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.outofjungle.bluetoothspp.app;
//from   w ww .j a v  a  2s .c  om
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 com.outofjungle.bluetoothspp.app.models.Message;
import com.outofjungle.bluetoothspp.app.models.Writer;

import java.util.ArrayList;

public class MessageAdapter extends ArrayAdapter<Message> {
  public MessageAdapter(Context context, ArrayList<Message> messages) {
    super(context, R.layout.message_item, messages);
  }

  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    if (convertView == null) {
      convertView = LayoutInflater.from(getContext()).inflate(R.layout.message_item, parent, false);
    }

    Message message = getItem(position);


    TextView writerName = (TextView) convertView.findViewById(R.id.writerName);
    TextView messageText = (TextView) convertView.findViewById(R.id.messageText);

    Enum writer = message.getWriter();
    if (Writer.ANDROID == writer) {
      writerName.setTextColor(0xFF04B404);
    } else if (Writer.ARDUINO == writer) {
      writerName.setTextColor(0xFF0000FF);
    }

    writerName.setText(writer.toString());
    messageText.setText(message.getText());

    return convertView;
  }
}




Java Source Code List

com.outofjungle.bluetoothspp.app.ConnectActivity.java
com.outofjungle.bluetoothspp.app.ConsoleActivity.java
com.outofjungle.bluetoothspp.app.DeviceAdapter.java
com.outofjungle.bluetoothspp.app.MessageAdapter.java
com.outofjungle.bluetoothspp.app.models.Message.java
com.outofjungle.bluetoothspp.app.models.Writer.java