Android Open Source - Werewolf-Android-Client Vote






From Project

Back to project page Werewolf-Android-Client.

License

The source code is released under:

Copyright (c) 2013, Timothy Cohen All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: ...

If you think the Android project Werewolf-Android-Client 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 edu.wm.werewolf_client;
//  w w w  . j a  va2 s  .  com
import java.io.IOException;
import java.io.UnsupportedEncodingException;

import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.auth.BasicScheme;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicHeader;

import android.util.Log;

public class Vote {
  
  static String TAG = "Vote";
  String username = UsernameAndPassword.getUsername();
  String password = UsernameAndPassword.getPassword();
  
  public Vote(){
    super();
  }
  
  public void vote(String victim){
  
  try {
      //tacohen note: login should be something like: /users/login?username=admin&lat=31&lng=30&password=123
    String uri = "http://powerful-depths-2851.herokuapp.com/players/vote?voterId="+username.trim()+"&voteId="+victim.trim();
      HttpClient client = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost(uri);
        httpPost.addHeader(BasicScheme.authenticate(
        new UsernamePasswordCredentials(username, password),
        "UTF-8", false));
        httpPost.setHeader(new BasicHeader("Content-type", "application/json"));
        HttpResponse response = client.execute(httpPost);
        Log.i(TAG, "URI is: "+httpPost.getURI());
        StatusLine statusLine = response.getStatusLine();
        Log.i(TAG, "HTTP response code was: "+statusLine.toString());
        if (statusLine.toString().equals("HTTP/1.1 200 OK")){
          Log.i(TAG, "Voted OK");
        }
        else{
          Log.e(TAG, "HTTP problem!");
        }
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

}
}




Java Source Code List

edu.wm.werewolf_client.DayTab.java
edu.wm.werewolf_client.FindLocation.java
edu.wm.werewolf_client.GetAllAlive.java
edu.wm.werewolf_client.GetKills.java
edu.wm.werewolf_client.IsNight.java
edu.wm.werewolf_client.KillAttempt.java
edu.wm.werewolf_client.Locate.java
edu.wm.werewolf_client.MainActivity.java
edu.wm.werewolf_client.MainInterface.java
edu.wm.werewolf_client.NightTab.java
edu.wm.werewolf_client.ObatainLocation.java
edu.wm.werewolf_client.Play.java
edu.wm.werewolf_client.Player.java
edu.wm.werewolf_client.Register.java
edu.wm.werewolf_client.Stats.java
edu.wm.werewolf_client.UserTab.java
edu.wm.werewolf_client.UsernameAndPassword.java
edu.wm.werewolf_client.Validate.java
edu.wm.werewolf_client.Vote.java
edu.wm.werewolf_client.isWerewolf.java