Advertisement
Guest User

asdasd

a guest
Dec 22nd, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.99 KB | None | 0 0
  1. package ph.activelearning.quicktexter;
  2.  
  3. import android.app.Activity;
  4.  
  5. import android.content.Intent;
  6. import android.os.AsyncTask;
  7. import android.os.Bundle;
  8. import android.view.Menu;
  9. import android.view.MenuItem;
  10. import android.view.View;
  11. import android.widget.Button;
  12. import android.widget.EditText;
  13. import android.widget.Toast;
  14.  
  15. public class SignInActivity extends Activity
  16. implements View.OnClickListener {
  17.  
  18.  
  19. @Override
  20. protected void onCreate(Bundle savedInstanceState) {
  21. super.onCreate(savedInstanceState);
  22. setContentView(R.layout.activity_sign_in);
  23. Button signin =(Button) findViewById(R.id.signin);
  24. EditText username = (EditText)findViewById(R.id.username);
  25. signin.setOnClickListener(this);
  26. }
  27.  
  28. @Override
  29. public boolean onCreateOptionsMenu(Menu menu) {
  30. // Inflate the menu; this adds items to the action bar if it is present.
  31. getMenuInflater().inflate(R.menu.menu_sign_in, menu);
  32. return true;
  33. }
  34.  
  35. @Override
  36. public boolean onOptionsItemSelected(MenuItem item) {
  37. // Handle action bar item clicks here. The action bar will
  38. // automatically handle clicks on the Home/Up button, so long
  39. // as you specify a parent activity in AndroidManifest.xml.
  40. int id = item.getItemId();
  41.  
  42. //noinspection SimplifiableIfStatement
  43. if (id == R.id.action_settings) {
  44. return true;
  45. }
  46.  
  47. return super.onOptionsItemSelected(item);
  48. }
  49.  
  50. @Override
  51. public void onClick(View v) {
  52. // Toast.makeText(this, "It Works", Toast.LENGTH_SHORT).show();
  53. // Intent intent = new Intent(SignInActivity.this,DashboardActivity.class);
  54. // startActivity(intent);
  55. new AuthenticationTask().execute();
  56.  
  57. }
  58. class AuthenticationTask extends AsyncTask<Void,Void,Integer>{
  59. private Exception e;
  60. private String username;
  61. private String password;
  62. EditText usernametxt = (EditText)findViewById(R.id.username);
  63. EditText passtxt = (EditText)findViewById(R.id.pass);
  64.  
  65. protected void onPreExecute(){
  66. this.username = usernametxt.getText().toString();
  67. this.password = passtxt.getText().toString();
  68. }
  69. protected Integer doInBackground(Void... params){
  70. Authenticator a = new Authenticator();
  71. return a.getUserId(username,password);
  72. }
  73. protected void onPostExecute(Integer userId){
  74. if (userId !=-1){
  75. Intent gotoDashboard = new Intent(SignInActivity.this,DashboardActivity.class);
  76. startActivity(gotoDashboard);
  77. QuickTexterApp.getInstance().setUserId(userId);
  78. // Toast.makeText(SignInActivity.this, SuserId, Toast.LENGTH_SHORT).show();
  79. finish();
  80. }else{
  81. Toast.makeText(SignInActivity.this, "Invalid username or Password", Toast.LENGTH_SHORT).show();
  82. }
  83. }
  84. }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement