列表视图中的循环计数器

时间:2015-05-01 10:59:24

标签: android

实际上我必须在列表视图的每一行中实现github.com/diogobernardino/CircularCounter。单击它应该可以作为循环计数器工作。但在我的情况下,当我点击一行的圆形计数器时循环计数器被激活。我只想点击行循环计数器开始。 - 请帮我。我是android的新手。

适配器代码:

public class PStatusAdapter extends BaseAdapter implements Filterable,
    OnClickListener {

// TrackData Adapter for Saving the data on Server AND Display it on list
// View

private static final String debugTag = "ProjectStatusAdapter";

public PStatusAdapter() {
    super();
    // TODO Auto-generated constructor stub
}

public Activity activity;
ListView projectStatusList;
private LayoutInflater layoutInflater;
public int position;
ArrayList<CommentData> c_detail = new ArrayList<CommentData>();
private ArrayList<ProjectDataClass> projectDataAdapterList;
private ArrayList<ProjectDataClass> pdAList = new ArrayList<ProjectDataClass>();
CommentAdapter cAdapter;
ViewHolder holder = null;

LayoutInflater clayoutInflator;

private String[] colors;

private Handler handler = new Handler();
protected boolean _active = true;
protected int _splashTime = 5000;

int currV = 0;
boolean go = true, isMeterDESclicked = false, isMeterREQclicked = false,
        isMeterUATclicked = true, isMeterGOLIVEclicked = false,
        isMeterSCHClicked = false, isMeterEFFClicked = false,
        isMeterCostClicked = false;
// Animation
Animation animSideDown, animSlideUp;
Runnable r;

public PStatusAdapter(Activity activity, ListView tList,
        LayoutInflater layoutInflator,
        ArrayList<ProjectDataClass> projectDataClassList) {
    // TODO Auto-generated constructor stub
    this.activity = activity;
    this.projectStatusList = tList;
    this.layoutInflater = layoutInflator;
    this.projectDataAdapterList = projectDataClassList;
    this.clayoutInflator = LayoutInflater.from(activity);
    this.pdAList.addAll(projectDataClassList);
}

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

@Override
public boolean areAllItemsEnabled() {
    return true;
}

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

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

@Override
public View getView(int pos, View convertView, ViewGroup parent) {

    if (convertView == null) {
        // convertView = layoutInflater.inflate(R.layout.trackrow, parent,
        // false);

        convertView = layoutInflater.inflate(R.layout.project_list_row,
                parent, false);
        holder = new ViewHolder();
        holder.projectNameTv = (TextView) convertView
                .findViewById(R.id.projectnametextview);
        // holder.percentageCompleteTv = (TextView) convertView
        // .findViewById(R.id.percentagecompleteTextView);
        // holder.status = (ImageView) convertView
        // .findViewById(R.id.statustextview);
        holder.reqTv = (TextView) convertView.findViewById(R.id.txtREQ);
        holder.desTv = (TextView) convertView.findViewById(R.id.txtDES);
        holder.uatTv = (TextView) convertView.findViewById(R.id.txtUAT);
        holder.goLiveTv = (TextView) convertView
                .findViewById(R.id.txtGOLIVE);
        holder.schTv = (TextView) convertView.findViewById(R.id.txtSCH);
        holder.effortTv = (TextView) convertView
                .findViewById(R.id.txtEFFORT);
        holder.costTv = (TextView) convertView.findViewById(R.id.txtCOST);
        //
        holder.meterREQ1 = (CircularCounter) convertView
                .findViewById(R.id.meterREQ);
        holder.meterDES1 = (CircularCounter) convertView
                .findViewById(R.id.meterDES);
        holder.meterUAT1 = (CircularCounter) convertView
                .findViewById(R.id.meterUAT);
        holder.meterGOLIVE1 = (CircularCounter) convertView
                .findViewById(R.id.meterGOLIVE);
        holder.meterSCH1 = (CircularCounter) convertView
                .findViewById(R.id.meterSCH);
        holder.meterEFF1 = (CircularCounter) convertView
                .findViewById(R.id.meterEFFORT);
        holder.meterCOST = (CircularCounter) convertView
                .findViewById(R.id.meterCOST);
        fontStyle();

        convertView.setTag(holder);
        holder.meterREQ1.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
        holder = (ViewHolder) holder.meterREQ1.getTag();
    }

    position = pos;

    ProjectDataClass track = pdAList.get(pos);
    holder.projectStatusInstance = track;

    holder.projectNameTv.setText(track.getProjectName().toString());

    convertView.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            // Accessing a row of list view
            holder = (ViewHolder) v.getTag();
            String s = holder.projectStatusInstance.getProjectName()
                    .toString();
            Log.d(debugTag, "OnClick pressed." + s);
            Log.d(debugTag, "Position Click pressed." + position);
        }
    });
    holder.meterREQ1.setOnClickListener(this);
    r = new Runnable() {

    public void run() {
    if (currV == 60 && go && isMeterREQclicked) {
    go = false;
    r = null;
    // imgPoster.setVisibility(View.VISIBLE);
    // imgPoster.startAnimation(animSideDown);
    handler.postDelayed(new Runnable() {
        @Override
        public void run() {
            try {
                int waited = 0;
                while (_active && (waited < _splashTime)) {
                    if (_active) {
                        waited += 1000;
                    }
                }
            } finally {

                // imgPoster.startAnimation(animSlideUp);

            }
        }
    }, 5000);
    }
    if (currV == 60 && go && isMeterDESclicked) {
    go = false;
    r = null;
    // imgPoster1.setVisibility(View.VISIBLE);
    // imgPoster1.startAnimation(animSideDown);
    handler.postDelayed(new Runnable() {
        @Override
        public void run() {
            try {
                int waited = 0;
                while (_active && (waited < _splashTime)) {
                    if (_active) {
                        waited += 1000;
                    }
                }
            } finally {

                // imgPoster1.startAnimation(animSlideUp);

            }
        }
    }, 5000);

    }
    if (currV == 60 && go && isMeterUATclicked) {
    go = false;
    r = null;
    // imgPoster1.setVisibility(View.VISIBLE);
    // imgPoster1.startAnimation(animSideDown);
    handler.postDelayed(new Runnable() {
        @Override
        public void run() {
            try {
                int waited = 0;
                while (_active && (waited < _splashTime)) {
                    if (_active) {
                        waited += 1000;
                    }
                }
            } finally {

                // imgPoster1.startAnimation(animSlideUp);

            }
        }
    }, 5000);
    }
    if (currV == 60 && go && isMeterGOLIVEclicked) {
    go = false;
    r = null;
    // imgPoster1.setVisibility(View.VISIBLE);
    // imgPoster1.startAnimation(animSideDown);
    handler.postDelayed(new Runnable() {
        @Override
        public void run() {
            try {
                int waited = 0;
                while (_active && (waited < _splashTime)) {
                    if (_active) {
                        waited += 1000;
                    }
                }
            } finally {

                // imgPoster1.startAnimation(animSlideUp);

            }
        }
    }, 5000);
    }
    if (currV == 60 && go && isMeterSCHClicked) {
    go = false;
    r = null;
    // imgPoster1.setVisibility(View.VISIBLE);
    // imgPoster1.startAnimation(animSideDown);
    handler.postDelayed(new Runnable() {
        @Override
        public void run() {
            try {
                int waited = 0;
                while (_active && (waited < _splashTime)) {
                    if (_active) {
                        waited += 1000;
                    }
                }
            } finally {

                // imgPoster1.startAnimation(animSlideUp);

            }
        }
    }, 5000);
    }
    if (currV == 60 && go && isMeterEFFClicked) {
    go = false;
    r = null;
    // imgPoster1.setVisibility(View.VISIBLE);
    // imgPoster1.startAnimation(animSideDown);
    handler.postDelayed(new Runnable() {
        @Override
        public void run() {
            try {
                int waited = 0;
                while (_active && (waited < _splashTime)) {
                    if (_active) {
                        waited += 1000;
                    }
                }
            } finally {

                // imgPoster1.startAnimation(animSlideUp);

            }
        }
    }, 5000);
    }
    if (currV == 60 && go && isMeterCostClicked) {
    go = false;
    r = null;
    // imgPoster1.setVisibility(View.VISIBLE);
    // imgPoster1.startAnimation(animSideDown);
    handler.postDelayed(new Runnable() {
        @Override
        public void run() {
            try {
                int waited = 0;
                while (_active && (waited < _splashTime)) {
                    if (_active) {
                        waited += 1000;
                    }
                }
            } finally {

                // imgPoster1.startAnimation(animSlideUp);

            }
        }
    }, 5000);
    }

    else if (currV == -60 && !go)
    go = true;

    if (go)
    currV++;
    // else
    // currV = 0;
    // go=true;
    if (isMeterREQclicked) {
    holder = (ViewHolder) holder.meterREQ1.getTag();
    holder.meterREQ1.setValues(currV, currV * 2, currV * 3);

    } else if (isMeterDESclicked)
    holder.meterDES1.setValues(currV, currV * 2, currV * 3);
    if (isMeterUATclicked) {
    holder.meterUAT1.setValues(currV, currV * 2, currV * 3);

    } else if (isMeterGOLIVEclicked)
    holder.meterGOLIVE1.setValues(currV, currV * 2, currV * 3);
    if (isMeterSCHClicked) {
    holder.meterSCH1.setValues(currV, currV * 2, currV * 3);

    } else if (isMeterEFFClicked)
    holder.meterEFF1.setValues(currV, currV * 2, currV * 3);
    if (isMeterCostClicked) {
    holder.meterCOST.setValues(currV, currV * 2, currV * 3);

    }
    handler.postDelayed(this, 50);
    }
    };

    return convertView;
}

class ViewHolder {
    private CircularCounter meterDES1, meterREQ1, meterUAT1, meterGOLIVE1,
            meterSCH1, meterEFF1, meterCOST;

    TextView reqTv, desTv, uatTv, goLiveTv, schTv, effortTv, costTv;
    ProjectDataClass projectStatusInstance;
    ImageView status;
    TextView projectNameTv, percentageCompleteTv;

}

// Filter Class
public void filter(String charText) {
    charText = charText.toLowerCase(Locale.getDefault());
    pdAList.clear();
    if (charText.length() == 0) {
        pdAList.addAll(projectDataAdapterList);
    } else {
        for (ProjectDataClass wp : projectDataAdapterList) {
            // if (wp.getProjectName().contains(charText)) {
            Boolean bl = wp.getProjectName().toLowerCase(Locale.ENGLISH)
                    .contains(charText);
            if (bl) {
                pdAList.add(wp);

                // display in long period of time
                // Toast.makeText(activity, "Searching", Toast.LENGTH_LONG)
                // .show();
            }
        }
    }

    notifyDataSetChanged();
}

public String dateFormateInString(String dateInString) {

    String dateFormat = "dd/MM/yyyy";
    SimpleDateFormat sdf = new SimpleDateFormat(dateFormat, Locale.ENGLISH);
    Calendar cl = Calendar.getInstance();
    try {
        cl.setTime(sdf.parse(dateInString));
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    String newDate = sdf.format(cl.getTime());
    System.out.println(newDate);
    return newDate;

}

public String trailing_zero_remove(String decimalZeroText) {
    Double dNumber = (double) 0;
    try {
        dNumber = Double.parseDouble(decimalZeroText);
    } catch (NumberFormatException e) {
        dNumber = (double) 0;
    }

    BigDecimal bd = new BigDecimal(dNumber);

    bd = bd.setScale(2, RoundingMode.HALF_UP).stripTrailingZeros();
    String sb = bd.toString();
    return sb;
}

@Override
public Filter getFilter() {
    // TODO Auto-generated method stub
    return new Filter() {

        @Override
        protected FilterResults performFiltering(CharSequence constraint) {
            constraint = constraint.toString().toLowerCase();
            FilterResults result = new FilterResults();

            if (constraint != null && constraint.toString().length() > 0) {
                ArrayList<ProjectDataClass> pdAList1 = new ArrayList<ProjectDataClass>();
                for (ProjectDataClass item : projectDataAdapterList) {
                    if (item.getProjectName().toString().toLowerCase()
                            .contains(constraint)) {
                        pdAList1.add(item);
                    }
                }

                result.values = pdAList1;
                result.count = pdAList1.size();
            } else {
                result.values = projectDataAdapterList;
                result.count = projectDataAdapterList.size();
            }
            return result;

        }

        @SuppressWarnings("unchecked")
        @Override
        protected void publishResults(CharSequence constraint,
                FilterResults results) {
            pdAList.clear();
            for (ProjectDataClass item : (ArrayList<ProjectDataClass>) results.values) {
                pdAList.add(item);
            }
            notifyDataSetChanged();

        }

    };
}

@Override
public void onClick(View v) {
    // TODO Auto-generated method stub

    switch (v.getId()) {
    case R.id.meterREQ:
        isMeterREQclicked = true;
        isMeterDESclicked = false;
        isMeterUATclicked = false;
        isMeterGOLIVEclicked = false;
        isMeterSCHClicked = false;
        isMeterEFFClicked = false;
        isMeterCostClicked = false;
        holder = (ViewHolder) holder.meterREQ1.getTag();
        initial_anim(holder.meterDES1);

        handler.postDelayed(r, 500);
        if (currV == 60 && go == false) {
            currV = 0;
            go = true;

        } else {
            Toast.makeText(activity, "Onclick Meter", Toast.LENGTH_LONG)
                    .show();

        }

        break;

    case R.id.meterDES:
        isMeterREQclicked = false;
        isMeterDESclicked = true;
        isMeterUATclicked = false;
        isMeterGOLIVEclicked = false;
        isMeterSCHClicked = false;
        isMeterEFFClicked = false;
        isMeterCostClicked = false;
        Log.d(debugTag, "Position Click pressed." + position);
        if (currV == 60 && go == false) {
            currV = 0;
            go = true;

        }

        break;
    case R.id.meterUAT:
        isMeterREQclicked = false;
        isMeterDESclicked = false;
        isMeterUATclicked = true;
        isMeterGOLIVEclicked = false;
        isMeterSCHClicked = false;
        isMeterEFFClicked = false;
        isMeterCostClicked = false;
        Log.d(debugTag, "Position Click pressed." + position);
        if (currV == 60 && go == false) {
            currV = 0;
            go = true;

        }
        break;
    case R.id.meterGOLIVE:
        isMeterREQclicked = false;
        isMeterDESclicked = false;
        isMeterUATclicked = false;
        isMeterGOLIVEclicked = true;
        isMeterSCHClicked = false;
        isMeterEFFClicked = false;
        isMeterCostClicked = false;
        Log.d(debugTag, "Position Click pressed." + position);
        if (currV == 60 && go == false) {
            currV = 0;
            go = true;

        }

        break;
    case R.id.meterSCH:
        isMeterREQclicked = false;
        isMeterDESclicked = false;
        isMeterUATclicked = false;
        isMeterGOLIVEclicked = false;
        isMeterSCHClicked = true;
        isMeterEFFClicked = false;
        isMeterCostClicked = false;
        Log.d(debugTag, "Position Click pressed." + position);
        if (currV == 60 && go == false) {
            currV = 0;
            go = true;

        }
        break;
    case R.id.meterEFFORT:
        isMeterREQclicked = false;
        isMeterDESclicked = false;
        isMeterUATclicked = false;
        isMeterGOLIVEclicked = false;
        isMeterSCHClicked = false;
        isMeterEFFClicked = true;
        isMeterCostClicked = false;
        Log.d(debugTag, "Position Click pressed." + position);
        if (currV == 60 && go == false) {
            currV = 0;
            go = true;

        }
        break;
    case R.id.meterCOST:
        isMeterREQclicked = false;
        isMeterDESclicked = false;
        isMeterUATclicked = false;
        isMeterGOLIVEclicked = false;
        isMeterSCHClicked = false;
        isMeterEFFClicked = false;
        isMeterCostClicked = true;
        Log.d(debugTag, "Position Click pressed." + position);
        if (currV == 60 && go == false) {
            currV = 0;
            go = true;

        }

        break;
    }

}

private void fontStyle() {
    // TODO Auto-generated method stub

    holder.reqTv.setTypeface(Typeface.DEFAULT_BOLD);
    holder.reqTv.setTextColor(Color.rgb(7, 82, 108));
    holder.reqTv.setTextSize(17);
    holder.reqTv.setTypeface(TYPEFACE.Lexia_Std_Rg(activity));
    holder.desTv.setTypeface(Typeface.DEFAULT_BOLD);
    holder.desTv.setTextColor(Color.rgb(7, 82, 108));
    holder.desTv.setTextSize(17);
    holder.desTv.setTypeface(TYPEFACE.Lexia_Std_Rg(activity));
    holder.uatTv.setTypeface(Typeface.DEFAULT_BOLD);
    holder.uatTv.setTextColor(Color.rgb(7, 82, 108));
    holder.uatTv.setTextSize(17);
    holder.uatTv.setTypeface(TYPEFACE.Lexia_Std_Rg(activity));
    holder.goLiveTv.setTypeface(Typeface.DEFAULT_BOLD);
    holder.goLiveTv.setTextColor(Color.rgb(7, 82, 108));
    holder.goLiveTv.setTextSize(17);
    holder.goLiveTv.setTypeface(TYPEFACE.Lexia_Std_Rg(activity));
    holder.effortTv.setTypeface(Typeface.DEFAULT_BOLD);
    holder.effortTv.setTextColor(Color.rgb(7, 82, 108));
    holder.effortTv.setTextSize(17);
    holder.effortTv.setTypeface(TYPEFACE.Lexia_Std_Rg(activity));
    holder.schTv.setTypeface(Typeface.DEFAULT_BOLD);
    holder.schTv.setTextColor(Color.rgb(7, 82, 108));
    holder.schTv.setTextSize(17);
    holder.schTv.setTypeface(TYPEFACE.Lexia_Std_Rg(activity));
    holder.costTv.setTypeface(Typeface.DEFAULT_BOLD);
    holder.costTv.setTextColor(Color.rgb(7, 82, 108));
    holder.costTv.setTextSize(17);
    holder.costTv.setTypeface(TYPEFACE.Lexia_Std_Rg(activity));
}

public void initial_anim(CircularCounter cc) {
    colors = activity.getResources().getStringArray(R.array.colors);
    cc.setFirstWidth(activity.getResources().getDimension(R.dimen.first))
            .setFirstColor(Color.parseColor(colors[0]))

            .setSecondWidth(
                    activity.getResources().getDimension(R.dimen.second))
            .setSecondColor(Color.parseColor(colors[1]))

            .setThirdWidth(
                    activity.getResources().getDimension(R.dimen.third))
            .setThirdColor(Color.parseColor(colors[2]))

            .setBackgroundColor(-14606047);

}

}

0 个答案:

没有答案