Android Open Source - Mamytas Timers Array Adapter






From Project

Back to project page Mamytas.

License

The source code is released under:

GNU General Public License

If you think the Android project Mamytas 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 mn.aug.restfulandroid.activity;
/*from   w  w  w . ja v  a  2 s  .c om*/
import android.animation.ValueAnimator;
import android.content.Context;
import android.graphics.Point;
import android.view.Display;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.ArrayAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;

import java.util.Date;
import java.util.List;

import mn.aug.restfulandroid.R;
import mn.aug.restfulandroid.rest.resource.Timer;
import mn.aug.restfulandroid.util.DateHelper;

public class TimersArrayAdapter extends ArrayAdapter<Timer> {
    private final Context context;
    private final List<Timer> timerList;
    private final int layout;
    private final OnTouchListener listener;

    public TimersArrayAdapter(Context context, int layout, List<Timer> timerList) {
        super(context, layout, timerList);
        this.listener = new OnTouchListener();
        this.context = context;
        this.timerList = timerList;
        this.layout=layout;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View rowView = inflater.inflate(layout, parent, false);
        TextView workUserName = (TextView) rowView.findViewById(R.id.workUserName);
        TextView workTimeSpent = (TextView) rowView.findViewById(R.id.workTimeSpent);
        TextView workDate = (TextView) rowView.findViewById(R.id.workFirstDate);
        workUserName.setText(timerList.get(position).getName()+": ");
        String time_min=String.valueOf((Long) (Long.parseLong(timerList.get(position).getTimer()) / 60000));
        workTimeSpent.setText(time_min + " min");
        Date date=new Date(Long.parseLong(timerList.get(position).getTimer_start()));
        String parsed_date = DateHelper.dateTimeFormat.format(date.getTime());
        workDate.setText("le " + parsed_date);
        workDate.setText("le " + parsed_date);
        //if(this.listener != null)
           // rowView.setOnTouchListener(this.listener);
        return rowView;
    }

    public class OnTouchListener implements View.OnTouchListener {
        int initialX = 20;
        RelativeLayout front;
        TextView backBtn;

        public boolean onTouch(View view, MotionEvent event) {
            WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
            Display display = wm.getDefaultDisplay();
            Point size = new Point();
            display.getSize(size);
            int width = size.x;
            int height = size.y;

            backBtn = (TextView) view.findViewById(R.id.delete);
            front = (RelativeLayout) view.findViewById(R.id.front);
            int X = (int) event.getRawX();
            int offset = X - initialX;
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                initialX = X;
                front.setTranslationX(0);
            }
            if (event.getAction() == MotionEvent.ACTION_MOVE) {
                front.setTranslationX(offset);

                if (offset < 0){
                    backBtn.setBackground(context.getResources().getDrawable(R.drawable.button_login_normal));
                    backBtn.setText("Editer");
                    backBtn.setGravity(Gravity.RIGHT);
                    //front.setBackgroundColor(0xffFF0000);
                }else{
                    backBtn.setBackground(context.getResources().getDrawable(R.drawable.button_stop_normal));
                    backBtn.setText("Retirer");
                    backBtn.setGravity(Gravity.LEFT);
                }
                if (offset > (int)width/2) {
                    backBtn.setBackground(context.getResources().getDrawable(R.drawable.button_stop_selected));
                } else if (offset < -(int)width/2) {
                    backBtn.setBackground(context.getResources().getDrawable(R.drawable.button_login_selected));
                }
            }
            if (event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL ) {
                ValueAnimator animator = null;
                if (offset > (int)width/2 && event.getAction() != MotionEvent.ACTION_CANCEL) { // On supprime loulou
                    animator = ValueAnimator.ofInt(offset, width);
                } else if (offset < -(int)width/2 && event.getAction() != MotionEvent.ACTION_CANCEL) { // On redirige vers la page d'dition
                    animator = ValueAnimator.ofInt(offset, -width);
                } else{// Animate back if no action was performed.
                    animator = ValueAnimator.ofInt(X - initialX, 0);
                }
                animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                    @Override
                    public void onAnimationUpdate(ValueAnimator valueAnimator) {
                        front.setTranslationX((Integer) valueAnimator.getAnimatedValue());
                    }
                });
                animator.setDuration(150);
                animator.start();
            }
            return true;
        }
    }
}




Java Source Code List

mn.aug.restfulandroid.activity.AboutActivity.java
mn.aug.restfulandroid.activity.LoginActivity.java
mn.aug.restfulandroid.activity.ProjectEditor.java
mn.aug.restfulandroid.activity.ProjectsActivity.java
mn.aug.restfulandroid.activity.ProjectsArrayAdapter.java
mn.aug.restfulandroid.activity.TaskActivity.java
mn.aug.restfulandroid.activity.TaskEditor.java
mn.aug.restfulandroid.activity.TasksActivity.java
mn.aug.restfulandroid.activity.TasksArrayAdapter.java
mn.aug.restfulandroid.activity.TimerServiceHelper.java
mn.aug.restfulandroid.activity.TimerService.java
mn.aug.restfulandroid.activity.TimersArrayAdapter.java
mn.aug.restfulandroid.activity.base.RESTfulActivity.java
mn.aug.restfulandroid.activity.base.RESTfulListActivity.java
mn.aug.restfulandroid.activity.base.UndoBarController.java
mn.aug.restfulandroid.provider.CommentsDBAccess.java
mn.aug.restfulandroid.provider.ListsDBAccess.java
mn.aug.restfulandroid.provider.OwnershipDBAccess.java
mn.aug.restfulandroid.provider.ProviderDbHelper.java
mn.aug.restfulandroid.provider.RemindersDBAccess.java
mn.aug.restfulandroid.provider.TasksDBAccess.java
mn.aug.restfulandroid.provider.UsersDBAccess.java
mn.aug.restfulandroid.rest.AbstractRestMethod.java
mn.aug.restfulandroid.rest.DeleteListRestMethod.java
mn.aug.restfulandroid.rest.DeleteTaskRestMethod.java
mn.aug.restfulandroid.rest.GetListsRestMethod.java
mn.aug.restfulandroid.rest.GetTasksRestMethod.java
mn.aug.restfulandroid.rest.GetTimersRestMethod.java
mn.aug.restfulandroid.rest.LoginRestMethod.java
mn.aug.restfulandroid.rest.PostListRestMethod.java
mn.aug.restfulandroid.rest.PostTaskRestMethod.java
mn.aug.restfulandroid.rest.PostTimerRestMethod.java
mn.aug.restfulandroid.rest.PutListRestMethod.java
mn.aug.restfulandroid.rest.PutTaskRestMethod.java
mn.aug.restfulandroid.rest.PutTimerRestMethod.java
mn.aug.restfulandroid.rest.Request.java
mn.aug.restfulandroid.rest.Response.java
mn.aug.restfulandroid.rest.RestClient.java
mn.aug.restfulandroid.rest.RestMethodFactory.java
mn.aug.restfulandroid.rest.RestMethodResult.java
mn.aug.restfulandroid.rest.RestMethod.java
mn.aug.restfulandroid.rest.ShareListRestMethod.java
mn.aug.restfulandroid.rest.resource.Comment.java
mn.aug.restfulandroid.rest.resource.Lists.java
mn.aug.restfulandroid.rest.resource.Listw.java
mn.aug.restfulandroid.rest.resource.Login.java
mn.aug.restfulandroid.rest.resource.Reminder.java
mn.aug.restfulandroid.rest.resource.Resource.java
mn.aug.restfulandroid.rest.resource.TaskList.java
mn.aug.restfulandroid.rest.resource.Task.java
mn.aug.restfulandroid.rest.resource.Tasks.java
mn.aug.restfulandroid.rest.resource.Timer.java
mn.aug.restfulandroid.rest.resource.Timers.java
mn.aug.restfulandroid.security.AuthorizationManager.java
mn.aug.restfulandroid.security.RequestSigner.java
mn.aug.restfulandroid.service.ListProcessor.java
mn.aug.restfulandroid.service.ListsProcessor.java
mn.aug.restfulandroid.service.LoginProcessor.java
mn.aug.restfulandroid.service.ProcessorCallback.java
mn.aug.restfulandroid.service.ShareProcessor.java
mn.aug.restfulandroid.service.TaskProcessor.java
mn.aug.restfulandroid.service.TasksProcessor.java
mn.aug.restfulandroid.service.TimersProcessor.java
mn.aug.restfulandroid.service.WunderlistServiceHelper.java
mn.aug.restfulandroid.service.WunderlistService.java
mn.aug.restfulandroid.util.DateHelper.java
mn.aug.restfulandroid.util.DatePickerFragment.java
mn.aug.restfulandroid.util.Logger.java
mn.aug.restfulandroid.util.TimePickerFragment.java