HelloWorldKeas.java :  » Client » keas-api-client » com » keas » android » helloworld » Android Open Source

Android Open Source » Client » keas api client 
keas api client » com » keas » android » helloworld » HelloWorldKeas.java
package com.keas.android.helloworld;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.keas.droid.mobileapi.MobileApiClient;

public class HelloWorldKeas extends Activity {
    /** Called when the activity is first created. */
  EditText userNameInput;
  EditText userPasswordInput;
  Button signInButton;

  public String getUserName() {
    return userNameInput.getText().toString();
  }

  public String getPassword() {
    return userPasswordInput.getText().toString();
  }

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.sign_in);
    initializeViewVariables();
  }

  @Override
  protected void onPause() {
    super.onPause();
    finish();
  }

  private void initializeViewVariables() {
    userNameInput = (EditText) findViewById(R.id.UserNameInput);
    userPasswordInput = (EditText) findViewById(R.id.PasswordInput);
    signInButton = (Button) findViewById(R.id.SignInButton);
    
    signInButton.setOnClickListener(new OnClickListener(){
      @Override
      public void onClick(View arg0) {
        MobileApiClient keasClient = new MobileApiClient(getUserName(), getPassword());
        if(keasClient.login()){
          saveCredentials();                    
          launchSuccessIntent();
          Toast.makeText(HelloWorldKeas.this, "Login Success", Toast.LENGTH_LONG).show();
        } else {
          Toast.makeText(HelloWorldKeas.this, "Login Failure", Toast.LENGTH_LONG).show();
        }        
      }

      private void launchSuccessIntent() {
        Intent i = new Intent(HelloWorldKeas.this, KeasCarePlans.class);        
        startActivity(i);
      }

      private void saveCredentials() {
        SharedPreferences settings = getSharedPreferences("LoginCredentials", MODE_PRIVATE);
        SharedPreferences.Editor prefEditor = settings.edit();
        prefEditor.putString("UserName", getUserName());
        prefEditor.putString("Password", getPassword());
        prefEditor.commit();
      }      
    });
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.