Android Open Source - AndroidLapTimer Lap List Adapter






From Project

Back to project page AndroidLapTimer.

License

The source code is released under:

MIT License

If you think the Android project AndroidLapTimer 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.pimentoso.android.laptimer;
//from  w  ww  .ja  va2s  . c  om
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class LapListAdapter extends BaseAdapter {

  private final Context context;
  private final List<Map<String, String>> values;

  public LapListAdapter(Context context, ArrayList<Long> laps) {
    super();
    this.context = context;
    
    this.values = new ArrayList<Map<String,String>>();
    Map<String, String> currentItemMap = null;
    
    long bestTime = Long.MAX_VALUE;
    int bestIndex = 0;
    long worstTime = Long.MIN_VALUE;
    int worstIndex = 0;
    
    if (laps.size() > 0) {
      for (int i = 0; i < laps.size(); i++) {
        currentItemMap = new HashMap<String, String>();
        this.values.add(currentItemMap);
        long lap = laps.get(i);
        
        if (lap > worstTime) {
          worstTime = lap;
          worstIndex = i;
        }
        
        if (lap < bestTime) {
          bestTime = lap;
          bestIndex = i;
        }
  
        currentItemMap.put("num", "Lap " + (i+1));
        currentItemMap.put("time", Utils.convertTime(lap));
      }
      
      values.get(worstIndex).put("notice", "(worst)");
      values.get(bestIndex).put("notice", "(best)");
      
      Collections.reverse(values);
    }
  }

  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    
    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View rowView = inflater.inflate(R.layout.list_item_lap, parent, false);

    TextView numView = (TextView) rowView.findViewById(R.id.lap_num);
    TextView timeView = (TextView) rowView.findViewById(R.id.lap_time);
    TextView noticeView = (TextView) rowView.findViewById(R.id.lap_notice);

    String num = values.get(position).get("num");
    String time = values.get(position).get("time");
    String notice = values.get(position).get("notice");

    numView.setText(num);
    timeView.setText(time);
    noticeView.setText(notice);

    return rowView;
  }

  @Override
  public int getCount() {
    return values.size();
  }

  @Override
  public Object getItem(int pos) {
    return pos;
  }

  @Override
  public long getItemId(int pos) {
    return pos;
  }
}




Java Source Code List

com.pimentoso.android.laptimer.DefaultPreferences.java
com.pimentoso.android.laptimer.FPSCounter.java
com.pimentoso.android.laptimer.LapListAdapter.java
com.pimentoso.android.laptimer.SensitivityDialogActivity.java
com.pimentoso.android.laptimer.TimerActivity.java
com.pimentoso.android.laptimer.Utils.java