Android Open Source - BerryTube Poll






From Project

Back to project page BerryTube.

License

The source code is released under:

GNU General Public License

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

/*
 * BerryTube Service/*ww  w . j  a v a 2 s  . co m*/
 * Copyright (C) 2012 Daniel Triendl <trellmor@trellmor.com>
 * 
 * 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 com.trellmor.berrytube;

import java.util.ArrayList;
import java.util.Arrays;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

/**
 * This class encapsulates a poll
 * 
 * @author Daniel Triendl
 */
public class Poll {
  private final ArrayList<String> mOptions = new ArrayList<>();
  private final ArrayList<Integer> mVotes = new ArrayList<>();
  private String mTitle;
  private String mCreator;
  private boolean mObscure;

  /**
   * Constructs a <code>Poll</code> from a <code>JSONObject<code>
   * 
   * @param poll <code>JSONObject<code> containing the poll data
   * @throws JSONException
   */
  public Poll(JSONObject poll) throws JSONException {
    mTitle = poll.getString("title");
    mCreator = poll.getString("title");
    mObscure = poll.getBoolean("obscure");
    
    JSONArray options = poll.getJSONArray("options");
    for (int i = 0; i < options.length(); i++) {
      mOptions.add(options.getString(i));
    }

    JSONArray votes = poll.getJSONArray("votes");
    for (int i = 0; i < votes.length(); i++) {
      mVotes.add(votes.optInt(i, -1));
    }
  }

  /**
   * Constructs a <code>Poll</code>
   * 
   * @param title Title of this poll 
   * @param options Array containing the options
   * @param votes Array containing the vote count
   * @param creator Poll creators nick
   * @param obscure Obscure votes
   */
  public Poll(String title, final String[] options, final int[] votes,
      String creator, boolean obscure) {
    mTitle = title;
    mCreator = creator;
    mObscure = obscure;

    mOptions.addAll(Arrays.asList(options));

    for (int i : votes) {
      mVotes.add(i);
    }
  }

  /**
   * Get the poll options
   * 
   * @return List of options
   */
  public ArrayList<String> getOptions() {
    return mOptions;
  }

  /**
   * Get the vote count
   * 
   * @return List of vote counts
   */
  public ArrayList<Integer> getVotes() {
    return mVotes;
  }

  /**
   * Get the poll title
   * 
   * @return Poll title
   */
  public String getTitle() {
    return mTitle;
  }

  /**
   * Get the poll creators nick
   * 
   * @return Username
   */
  public String getCreator() {
    return mCreator;
  }
  
  /**
   * Get vote obscure
   * 
   * @return Obscure
   */
  public boolean getObscure() {
    return mObscure;
  }

  /**
   * Update the vote count
   * 
   * @param votes Array of vote counts
   */
  public void update(final int[] votes) {
    mVotes.clear();

    for (int i : votes) {
      mVotes.add(i);
    }
  }
}




Java Source Code List

com.trellmor.berrytube.BerryTubeBinder.java
com.trellmor.berrytube.BerryTubeCallback.java
com.trellmor.berrytube.BerryTubeIOCallback.java
com.trellmor.berrytube.BerryTube.java
com.trellmor.berrytube.ChatMessage.java
com.trellmor.berrytube.ChatUser.java
com.trellmor.berrytube.Poll.java
com.trellmor.berrytubechat.BerryTubeUtils.java
com.trellmor.berrytubechat.ChatActivity.java
com.trellmor.berrytubechat.ChatMessageAdapter.java
com.trellmor.berrytubechat.ChatMessageFormatter.java
com.trellmor.berrytubechat.FlairGetter.java
com.trellmor.berrytubechat.MainActivity.java
com.trellmor.berrytubechat.SettingsActivity.java
com.trellmor.berrytubechat.SettingsFragment.java
com.trellmor.berrytubechat.SimpleCrypto.java