Android Open Source - Werewolf-Android-Client Main Activity






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.  ja  v  a 2 s  .  co  m*/
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends Activity {
  
  String username;
  String password;
  Context context;
  String TAG = "MainActivity";

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    
    context = getApplicationContext();
    
    Button loginButton = (Button)findViewById(R.id.loginButton);
    Button registerButton = (Button)findViewById(R.id.registerButton);
    
    loginButton.setOnClickListener(loginListener);
    registerButton.setOnClickListener(registerListener);
  }

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
  }
  
  View.OnClickListener loginListener = new View.OnClickListener() {
    @Override
    public void onClick(View v) {
      
      final EditText usernameText = (EditText) findViewById(R.id.usernameTextEdit);
      username = usernameText.getText().toString().trim();
      UsernameAndPassword.setUsername(username);
      Log.i(TAG, "Username is :"+username);
      
      final EditText passwordText = (EditText) findViewById(R.id.passwordTextEdit);
      password = passwordText.getText().toString().trim();
      UsernameAndPassword.setPassword(password);
      Log.i(TAG, "Password is :"+password);
      
      if (username.isEmpty()){
        Toast toast = Toast.makeText(context, "Please Enter a Username", Toast.LENGTH_LONG);
        toast.show();
      }
      else{
        if (password.isEmpty()){
          Toast toast = Toast.makeText(context, "Please Enter a Password", Toast.LENGTH_LONG);
          toast.show();
        }
        else{
          Intent validateIntent = new Intent(MainActivity.this,Validate.class);
          startActivityForResult(validateIntent, 0);
        }

      }

    }
  };
  
  View.OnClickListener registerListener = new View.OnClickListener() {
    @Override
    public void onClick(View v) {
      Intent registerIntent = new Intent(MainActivity.this,Register.class);
          startActivityForResult(registerIntent, 0);  
    }
  };

}




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