Android Open Source - activity-tracker Workout D A O Adapter






From Project

Back to project page activity-tracker.

License

The source code is released under:

MIT License

If you think the Android project activity-tracker 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 org.hopto.mjancola.adapter;
//  w  ww .  ja  v a 2  s .  co  m
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import org.hopto.mjancola.R;
import org.hopto.mjancola.model.LearningMode;
import org.hopto.mjancola.utility.Converter;
import org.hopto.mjancola.utility.WorkoutDAO;

import java.util.Calendar;

public class WorkoutDAOAdapter extends ArrayAdapter<WorkoutDAO>
{

    Context context;
    int     layoutResourceId;
    WorkoutDAO data[] = null;

    public WorkoutDAOAdapter( Context context, int layoutResourceId, WorkoutDAO[] data )
    {
        super( context, layoutResourceId, data );
        this.layoutResourceId = layoutResourceId;
        this.context = context;
        this.data = data;
    }

    @Override
    public View getView( int position, View convertView, ViewGroup parent )
    {
        View row = convertView;
        WorkoutDAOHolder holder = null;

        if(row == null)
        {
            LayoutInflater inflater = ((Activity)context).getLayoutInflater();
            row = inflater.inflate(layoutResourceId, parent, false);

            holder = new WorkoutDAOHolder();
            holder.imgIcon = (ImageView)row.findViewById(R.id.workout_icon);
            holder.type = (TextView)row.findViewById( R.id.workout_type);
            holder.date = (TextView)row.findViewById( R.id.workout_date );
            holder.duration = (TextView)row.findViewById( R.id.workout_duration );
            holder.distance = (TextView) row.findViewById( R.id.workout_distance);
            holder.startReason = (TextView) row.findViewById( R.id.workout_start_reason );
            holder.endReason = (TextView) row.findViewById( R.id.workout_end_reason );

            row.setTag(holder);
        }
        else
        {
            holder = (WorkoutDAOHolder)row.getTag();
        }

        WorkoutDAO workoutDAO = data[position];
        if (workoutDAO.getType().equals( LearningMode.WALK_NAME))
        {
            holder.imgIcon.setImageResource( R.drawable.hike_white_100 );
            holder.type.setText("");
        }
        else if (workoutDAO.getType().equals( LearningMode.RUN_NAME))
        {
            holder.imgIcon.setImageResource( R.drawable.run_white_100 );
            holder.type.setText("");
        }
        else if (workoutDAO.getType().equals( LearningMode.BIKE_NAME))
        {
            holder.imgIcon.setImageResource( R.drawable.bike_white_100 );
            holder.type.setText("");
        }
        else
        {
            holder.imgIcon.setImageResource( R.drawable.none_20);
            holder.type.setText(workoutDAO.getType());
        }
        //holder.imgIcon.setImageResource(some image);
        Calendar due = Calendar.getInstance();
        due.setTimeInMillis( workoutDAO.getStart() );
        holder.date.setText( due.getTime().toString() );
        String duration = Converter.formatDuration( workoutDAO.getDuration() );
        if (duration != null)
        {
            holder.duration.setText(duration);
        }

        holder.distance.setText( Converter.formatDistance( (workoutDAO.getDistance())/100 ) + " mi");
        holder.startReason.setText( workoutDAO.getStartReason() );
        holder.endReason.setText( workoutDAO.getEndReason() );


        return row;
    }

    static class WorkoutDAOHolder
    {
        ImageView imgIcon;
        TextView  type;
        TextView  date;
        TextView  distance;
        TextView  duration;
        TextView  startReason;
        TextView  endReason;
    }
}




Java Source Code List

org.hopto.mjancola.ActivityTrackerApplication.java
org.hopto.mjancola.activity.ActivityRecognitionActivity.java
org.hopto.mjancola.activity.ActivityTracker.java
org.hopto.mjancola.activity.DemoDetailsList.java
org.hopto.mjancola.activity.DemoDetails.java
org.hopto.mjancola.activity.EditWorkoutDAOActivity.java
org.hopto.mjancola.activity.FeatureView.java
org.hopto.mjancola.activity.LegalInfoActivity.java
org.hopto.mjancola.activity.ListWorkoutsActivity.java
org.hopto.mjancola.activity.MyLocationDemoActivity.java
org.hopto.mjancola.activity.SpeedActivity.java
org.hopto.mjancola.activity.UserSettingsActivity.java
org.hopto.mjancola.adapter.WorkoutDAOAdapter.java
org.hopto.mjancola.fragment.EditWorkoutDAOFragment.java
org.hopto.mjancola.model.DataPoint.java
org.hopto.mjancola.model.GenericMovement.java
org.hopto.mjancola.model.GenericWorkout.java
org.hopto.mjancola.model.LearningMode.java
org.hopto.mjancola.model.MyMovement.java
org.hopto.mjancola.model.WorkoutTotal.java
org.hopto.mjancola.model.WorkoutType.java
org.hopto.mjancola.model.Workout.java
org.hopto.mjancola.service.ActivityRecognitionService.java
org.hopto.mjancola.service.MovementListenerService.java
org.hopto.mjancola.service.MovementTrackerService.java
org.hopto.mjancola.utility.Converter.java
org.hopto.mjancola.utility.MySQLiteHelper.java
org.hopto.mjancola.utility.SettingsHelper.java
org.hopto.mjancola.utility.WorkoutDAO.java
org.hopto.mjancola.utility.WorkoutDataSource.java