Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ph.activelearning.quicktexter;
- import android.app.Activity;
- import android.content.Intent;
- import android.os.AsyncTask;
- import android.os.Bundle;
- import android.view.Menu;
- import android.view.MenuItem;
- import android.view.View;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.Toast;
- public class SignInActivity extends Activity
- implements View.OnClickListener {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_sign_in);
- Button signin =(Button) findViewById(R.id.signin);
- EditText username = (EditText)findViewById(R.id.username);
- signin.setOnClickListener(this);
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- getMenuInflater().inflate(R.menu.menu_sign_in, menu);
- return true;
- }
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- // Handle action bar item clicks here. The action bar will
- // automatically handle clicks on the Home/Up button, so long
- // as you specify a parent activity in AndroidManifest.xml.
- int id = item.getItemId();
- //noinspection SimplifiableIfStatement
- if (id == R.id.action_settings) {
- return true;
- }
- return super.onOptionsItemSelected(item);
- }
- @Override
- public void onClick(View v) {
- // Toast.makeText(this, "It Works", Toast.LENGTH_SHORT).show();
- // Intent intent = new Intent(SignInActivity.this,DashboardActivity.class);
- // startActivity(intent);
- new AuthenticationTask().execute();
- }
- class AuthenticationTask extends AsyncTask<Void,Void,Integer>{
- private Exception e;
- private String username;
- private String password;
- EditText usernametxt = (EditText)findViewById(R.id.username);
- EditText passtxt = (EditText)findViewById(R.id.pass);
- protected void onPreExecute(){
- this.username = usernametxt.getText().toString();
- this.password = passtxt.getText().toString();
- }
- protected Integer doInBackground(Void... params){
- Authenticator a = new Authenticator();
- return a.getUserId(username,password);
- }
- protected void onPostExecute(Integer userId){
- if (userId !=-1){
- Intent gotoDashboard = new Intent(SignInActivity.this,DashboardActivity.class);
- startActivity(gotoDashboard);
- QuickTexterApp.getInstance().setUserId(userId);
- // Toast.makeText(SignInActivity.this, SuserId, Toast.LENGTH_SHORT).show();
- finish();
- }else{
- Toast.makeText(SignInActivity.this, "Invalid username or Password", Toast.LENGTH_SHORT).show();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement