/TheElements/src/sand/falling/opengl/network/networklogin.java

http://thelements.googlecode.com/ · Java · 122 lines · 73 code · 23 blank · 26 comment · 8 complexity · 58485ac475b7af10ca3cec98284ab955 MD5 · raw file

  1. package sand.falling.opengl.network;
  2. import sand.falling.opengl.R;
  3. import android.app.Activity;
  4. import android.content.Intent;
  5. import android.os.Bundle;
  6. import android.view.View;
  7. import android.view.View.OnClickListener;
  8. import android.widget.Button;
  9. import android.widget.EditText;
  10. import android.widget.Toast;
  11. /**
  12. * Application Name: Generic Login Screen for the Android Platform (back end)
  13. * Description: This is a generic login screen which catches the username and
  14. * password values Created on: November 23, 2007 Created by: Pogz Ortile
  15. * Contact: pogz(at)redhat(dot)polarhome(dot)com Notes: The string values for
  16. * username and password are assigned to sUserName and sPassword respectively
  17. * You are free to distribute, modify, and wreck for all I care. GPL ya!
  18. * */
  19. public class networklogin extends Activity
  20. {
  21. /** Called when the activity is first created. */
  22. static public Button launch;
  23. static public Button register;
  24. static public Button network_engage;
  25. static public EditText usernameEditText;
  26. static public EditText passwordEditText;
  27. static public String sUserName;
  28. static public String sPassword;
  29. @Override
  30. public void onCreate(Bundle savedInstanceState)
  31. {
  32. super.onCreate(savedInstanceState);
  33. // load up the layout
  34. setContentView(R.layout.login_layout);
  35. // get the button resource in the xml file and assign it to a local
  36. // variable of type Button
  37. launch = (Button) findViewById(R.id.login_button2);
  38. register = (Button) findViewById(R.id.register_button);
  39. network_engage = (Button) findViewById(R.id.engage_test);
  40. // this gets the resources in the xml file and assigns it to a
  41. // local variable of type EditText
  42. usernameEditText = (EditText) findViewById(R.id.txt_username);
  43. passwordEditText = (EditText) findViewById(R.id.txt_password);
  44. // this is the action listener
  45. launch.setOnClickListener(new OnClickListener()
  46. {
  47. public void onClick(View viewParam)
  48. {
  49. // the getText() gets the current value of the text box
  50. // the toString() converts the value to String data type
  51. // then assigns it to a variable of type String
  52. sUserName = usernameEditText.getText().toString();
  53. sPassword = passwordEditText.getText().toString();
  54. if (usernameEditText == null || passwordEditText == null)
  55. {
  56. Toast.makeText(networklogin.this, "Couldn't find the 'txt_username' or 'txt_password'", Toast.LENGTH_SHORT).show();
  57. }
  58. else
  59. {
  60. // display the username and the password in string format
  61. Toast.makeText(networklogin.this, "username:" + sUserName + " password:" + sPassword, Toast.LENGTH_SHORT).show();
  62. }
  63. }
  64. }
  65. ); // end of launch.setOnclickListener
  66. register.setOnClickListener(new OnClickListener()
  67. {
  68. public void onClick(View viewParam)
  69. {
  70. // the getText() gets the current value of the text box
  71. // the toString() converts the value to String data type
  72. // then assigns it to a variable of type String
  73. sUserName = usernameEditText.getText().toString();
  74. sPassword = passwordEditText.getText().toString();
  75. // this just catches the error if the program cant locate the
  76. // GUI stuff
  77. if (usernameEditText == null || passwordEditText == null)
  78. {
  79. Toast.makeText(networklogin.this, "Couldn't find the 'txt_username' or 'txt_password'", Toast.LENGTH_SHORT).show();
  80. }
  81. else
  82. {
  83. // display the username and the password in string format
  84. Toast.makeText(networklogin.this, " Register Username:" + sUserName + " Password:" + sPassword, Toast.LENGTH_SHORT).show();
  85. }
  86. }
  87. }
  88. ); // end of register.setOnClickStuff
  89. network_engage.setOnClickListener(new OnClickListener()
  90. {
  91. public void onClick(View viewParam)
  92. {
  93. //Start the main app activity
  94. startActivity(new Intent(networklogin.this, networkengage.class));
  95. }
  96. }
  97. ); // end of register.setOnClickStuff
  98. }
  99. }