Android Open Source - EsTrains Train Adapter View






From Project

Back to project page EsTrains.

License

The source code is released under:

GNU General Public License

If you think the Android project EsTrains 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 es.trains.views;
/* w w  w . j  av  a  2  s .c  o m*/
import android.content.Context;
import android.text.Spannable;
import android.text.style.StyleSpan;
import android.view.LayoutInflater;
import android.widget.LinearLayout;
import android.widget.TextView;
import es.trains.R;
import es.trains.model.TrainItem;

/**
 *
 * @author Diego Pino <dpino@igalia.com>
 *
 */
public class TrainAdapterView extends LinearLayout {

    public TrainAdapterView(Context context, TrainItem train) {
        super(context);

        LayoutInflater inflater = (LayoutInflater) getContext()
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        inflater.inflate(R.layout.train_row, this);

        TextView departure = (TextView) findViewById(R.id.tvDeparture);
        departure.setText(train.getDeparture(), TextView.BufferType.SPANNABLE);
        setBold(departure);

        TextView arrive = (TextView) findViewById(R.id.tvArrive);
        arrive.setText(train.getArrive(), TextView.BufferType.SPANNABLE);
        setBold(arrive);

        TextView length = (TextView) findViewById(R.id.tvLength);
        length.setText(train.getLength());

        TextView code = (TextView) findViewById(R.id.tvCode);
        code.setText(getTrainModel(train.getCode()));
    }

    private String getTrainModel(String code) {
        int pos = code.indexOf(" ");
        if (pos >= 0) {
            return code.substring(pos, code.length());
        }
        return code;
    }

    private void setBold(TextView tv) {
        Spannable str = (Spannable) tv.getText();
        str.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0,
                str.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    }

}




Java Source Code List

es.trains.activities.ListTrainResults.java
es.trains.activities.SearchTimetable.java
es.trains.model.Timetable.java
es.trains.model.TrainItem.java
es.trains.provider.EsTrainProvider.java
es.trains.provider.Timetable.java
es.trains.provider.Train.java
es.trains.services.EsTrainXHR.java
es.trains.views.TrainAdapterView.java