Android Open Source - ivotingverification Candidates List Adapter






From Project

Back to project page ivotingverification.

License

The source code is released under:

GNU General Public License

If you think the Android project ivotingverification 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

/**
 * Copyright (C) 2013 Eesti Vabariigi Valimiskomisjon 
 * (Estonian National Electoral Committee), www.vvk.ee
 *//w  w  w. j  av  a 2  s . c o  m
 * Written in 2013 by AS Finestmedia, www.finestmedia.ee
 * 
 * Vote-verification application for Estonian Internet voting system
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 **/
 
package ee.vvk.ivotingverification.adapter;

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.GradientDrawable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import ee.vvk.ivotingverification.R;
import ee.vvk.ivotingverification.model.Vote;
import ee.vvk.ivotingverification.model.Vote.Candidate;
import ee.vvk.ivotingverification.util.C;
import ee.vvk.ivotingverification.util.RegexMatcher;
import ee.vvk.ivotingverification.util.TriangleView;
import ee.vvk.ivotingverification.util.Util;

/**
 * Custom adapter.
 * 
 * @version 21.05.2013
 */
public class CandidatesListAdapter extends BaseAdapter {

  private List<Candidate> entries;
  private Vote vote;
  private LayoutInflater mInflater;
  private Context context;

  private static final String TAG = CandidatesListAdapter.class
      .getSimpleName();

  public CandidatesListAdapter(Context context, List<Candidate> entries,
      Vote vote) {
    mInflater = (LayoutInflater) context
        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    this.entries = entries;
    this.vote = vote;
    this.context = context;
  }

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

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

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

  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    final ViewHolder holder;
    if (convertView == null) {

      convertView = mInflater.inflate(R.layout.list_item_candidate, null);
      holder = new ViewHolder();
      convertView.setTag(holder);

      holder.candidateListItemContainer = (LinearLayout) convertView
          .findViewById(R.id.candidate_list_item_container);
      holder.electionTitleShadow = (View) convertView
          .findViewById(R.id.election_title_label_shadow);
      holder.candidateListItemDetails = (RelativeLayout) convertView
          .findViewById(R.id.candidate_list_item_details);
      holder.triangleLabel = (LinearLayout) convertView
          .findViewById(R.id.triangle_lbl);
      holder.electionTitle = (TextView) convertView
          .findViewById(R.id.election_title_label);
      holder.candidateName = (TextView) convertView
          .findViewById(R.id.candidate_name_text);
      holder.candidateParty = (TextView) convertView
          .findViewById(R.id.candidate_party_text);
    } else {
      holder = (ViewHolder) convertView.getTag();
    }

    GradientDrawable candidateListItemContainerD = (GradientDrawable) holder.candidateListItemContainer
        .getBackground();
    candidateListItemContainerD.setColor(Util
        .generateHexColorValue(C.lblOuterContainerBackground));

    holder.electionTitle.setTypeface(C.typeFace);
    holder.electionTitle.setTextColor(Util
        .generateHexColorValue(C.lblOuterContainerForeground));

    GradientDrawable candidateListItemDetailsD = (GradientDrawable) holder.candidateListItemDetails
        .getBackground();
    candidateListItemDetailsD.setColor(Util
        .generateHexColorValue(C.lblInnerContainerBackground));

    holder.electionTitleShadow.setBackgroundColor(Util
        .generateHexColorValue(C.lblOuterInnerContainerDivider));
    holder.candidateName.setTextColor(Util
        .generateHexColorValue(C.lblInnerContainerForeground));
    holder.candidateName.setTypeface(C.typeFace);
    holder.candidateParty.setTextColor(Util
        .generateHexColorValue(C.lblInnerContainerForeground));
    holder.candidateParty.setTypeface(C.typeFace);

    String tempNumber = "";
    if (!RegexMatcher.IsCandidateNumber(entries.get(position).number)) {
      if (Util.DEBUGGABLE) {
        Log.d(TAG, "Wrong candidate number");
      }
      Util.startErrorIntent((Activity) context,
          C.badServerResponseMessage, true);
    } else {
      tempNumber = entries.get(position).number.substring(
          entries.get(position).number.indexOf(".") + 1,
          entries.get(position).number.length());
    }

    TriangleView cv = new TriangleView(context,
        Util.generateHexColorValue(C.lblInnerContainerBackground),
        tempNumber);
    cv.setLayoutParams(new LinearLayout.LayoutParams(
        LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    holder.triangleLabel.addView(cv);

    if (C.elections != null) {
      if (C.elections.get(vote.electionNames[position]) != null) {
        holder.electionTitle.setText(C.elections
            .get(vote.electionNames[position]));
      } else {
        holder.electionTitle.setText(vote.electionNames[position]);
      }
    } else {
      holder.electionTitle.setText(vote.electionNames[position]);
    }

    if (!RegexMatcher.IsLessThan101UtfChars(entries.get(position).name)) {
      if (Util.DEBUGGABLE) {
        Log.d(TAG, "Wrong candidate name");
      }
      Util.startErrorIntent((Activity) context,
          C.badServerResponseMessage, true);
    } else {
      holder.candidateName.setText(entries.get(position).name);
    }
    holder.candidateParty.setText(entries.get(position).party);

    return convertView;
  }

  public static class ViewHolder {
    private LinearLayout candidateListItemContainer;
    private View electionTitleShadow;
    private RelativeLayout candidateListItemDetails;
    private LinearLayout triangleLabel;
    private TextView electionTitle;
    private TextView candidateName;
    private TextView candidateParty;
  }
}




Java Source Code List

ee.vvk.ivotingverification.BruteForceActivity.java
ee.vvk.ivotingverification.ErrorActivity.java
ee.vvk.ivotingverification.HelpActivity.java
ee.vvk.ivotingverification.MainActivity.java
ee.vvk.ivotingverification.QRScannerActivity.java
ee.vvk.ivotingverification.VoteActivity.java
ee.vvk.ivotingverification.VoteDownloadActivity.java
ee.vvk.ivotingverification.adapter.CandidatesListAdapter.java
ee.vvk.ivotingverification.dialog.LoadingSpinner.java
ee.vvk.ivotingverification.model.Vote.java
ee.vvk.ivotingverification.qr.AutoFocusCallback.java
ee.vvk.ivotingverification.qr.CameraConfigurationManager.java
ee.vvk.ivotingverification.qr.CameraManager.java
ee.vvk.ivotingverification.qr.CaptureActivityHandler.java
ee.vvk.ivotingverification.qr.DecodeFormatManager.java
ee.vvk.ivotingverification.qr.DecodeHandler.java
ee.vvk.ivotingverification.qr.DecodeThread.java
ee.vvk.ivotingverification.qr.FinishListener.java
ee.vvk.ivotingverification.qr.InactivityTimer.java
ee.vvk.ivotingverification.qr.Intents.java
ee.vvk.ivotingverification.qr.PlanarYUVLuminanceSource.java
ee.vvk.ivotingverification.qr.PreferencesActivity.java
ee.vvk.ivotingverification.qr.PreviewCallback.java
ee.vvk.ivotingverification.qr.ViewfinderResultPointCallback.java
ee.vvk.ivotingverification.qr.ViewfinderView.java
ee.vvk.ivotingverification.util.C.java
ee.vvk.ivotingverification.util.Crypto.java
ee.vvk.ivotingverification.util.CustomHttpsClient.java
ee.vvk.ivotingverification.util.HttpRequest.java
ee.vvk.ivotingverification.util.JSONParser.java
ee.vvk.ivotingverification.util.RegexMatcher.java
ee.vvk.ivotingverification.util.SecureRandomWrapper.java
ee.vvk.ivotingverification.util.TriangleView.java
ee.vvk.ivotingverification.util.Util.java