Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class FitiquityTest extends ActivityInstrumentationTestCase2<LoginActivity> {
- LoginActivity mActivity;
- private EditText username;
- private EditText password;
- public FitiquityTest()
- {
- super("com.fitiquity.activity.LoginActivity",LoginActivity.class);
- }
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- mActivity = this.getActivity();
- username = (EditText) mActivity.findViewById(R.id.login_email_mobile_et);
- password = (EditText) mActivity.findViewById(R.id.login_password_et);
- }
- @Test
- public void testPreconditions() {
- assertNotNull(username);
- assertNotNull(password);
- }
- @Test
- public void testText() {
- assertEquals("hello",username.getText());
- assertEquals("hello123", password.getText());
- }
- }
- public class LoginActivity extends Activity implements View.OnClickListener {
- private ImageView imgAppLogo;
- private EditText login_email_mobile_et, login_password_et;
- private TextView login_sign_up, login_signin, login_forgot_password;
- private String inputType = "";
- private CircleProgress progressLoader;
- private Activity mActivity;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_login);
- initView();
- playAnimation();
- }
- private void initView() {
- mActivity = LoginActivity.this;
- login_email_mobile_et = (EditText) findViewById(R.id.login_email_mobile_et);
- login_password_et = (EditText) findViewById(R.id.login_password_et);
- imgAppLogo = (ImageView) findViewById(R.id.login_app_logo);
- login_sign_up = (TextView) findViewById(R.id.login_sign_up);
- login_sign_up.setOnClickListener(this);
- login_signin = (TextView) findViewById(R.id.login_signin);
- login_signin.setOnClickListener(this);
- login_forgot_password = (TextView) findViewById(R.id.login_forgot_password);
- login_forgot_password.setOnClickListener(this);
- progressLoader = (CircleProgress) findViewById(R.id.progressLoader);
- }
- private void playAnimation() {
- AnimatorSet animset = new AnimatorSet();
- animset.playTogether(FitiquityApplication.getInstance().slideAnimation(imgAppLogo,
- FitiquityApplication.getDisplay(LoginActivity.this).heightPixels, 0),
- FitiquityApplication.getInstance().fadeInAnimation(findViewById(R.id.login_top_shadow)));
- animset.start();
- }
- @Override
- public void onClick(View v) {
- switch (v.getId()) {
- case R.id.login_sign_up:
- Intent mIntentR = new Intent(LoginActivity.this, RegeCreateActivity.class);
- startActivity(mIntentR);
- overridePendingTransition(0, 0);
- break;
- case R.id.login_signin:
- String email = login_email_mobile_et.getText().toString().trim();
- String password = login_password_et.getText().toString().trim();
- String dev_id = Settings.Secure.getString(mActivity.getContentResolver(),
- Settings.Secure.ANDROID_ID);
- if (!TextUtils.isEmpty(email) && !TextUtils.isEmpty(password)) {
- if (password.length() > 4) {
- FitiquityUtils.HideKeyboard(LoginActivity.this, v);
- if (FitiquityUtils.isValidMail(email)) {
- inputType = WSTags.EMAIL;
- callWebLogin(email, password, inputType, dev_id, progressLoader);
- } else if (FitiquityUtils.isValidMobile(email)) {
- inputType = WSTags.PHONE;
- callWebLogin(email, password, inputType, dev_id, progressLoader);
- } else {
- FitiquityUtils.showToast(v, LoginActivity.this, mActivity.getString(R.string.validaiton_proper_email_mobile));
- }
- } else {
- FitiquityUtils.showToast(v, LoginActivity.this, mActivity.getString(R.string.password));
- }
- } else {
- FitiquityUtils.showToast(v, LoginActivity.this, mActivity.getString(R.string.validation_general_blank));
- }
- break;
- case R.id.login_forgot_password:
- ForgotPasswordDialog mForgotPasswordDialog = new ForgotPasswordDialog(mActivity);
- mForgotPasswordDialog.show();
- break;
- }
- }
- private void callWebLogin(String emailorMobileNo, String passowrd, String inputType,
- String device_id, CircleProgress mLoader) {
- if (FitiquityUtils.isOnline(mActivity)) {
- AsyncTaskLogin mLoginAsyncTask = new AsyncTaskLogin(mActivity, emailorMobileNo, passowrd, inputType,
- device_id, mLoader, new InterfaceWebserviceCallback<SetGetLogin>() {
- @Override
- public void webServiceDataRetrieveSuccess(SetGetLogin result) {
- if (result.getResponseCode().equals(String.valueOf(WSTags.RESPONSE_SUCCESS))) {
- FitiquityApplication.getInstance().mPrefs.setsessionKey(result.getProfile().getSession_id());
- FitiquityApplication.getInstance().mPrefs.setUserID(result.getProfile().getUser_id());
- if (result.getProfile().getIs_paid().equals(Constants.ON)) {
- Intent mIntentL = new Intent(LoginActivity.this, HomeActivity.class);
- mIntentL.putExtra(Constants.LOGIN_INFO, result.getProfile());
- mIntentL.putExtra(Constants.TYPE, Constants.LOGIN_TYPE);
- startActivity(mIntentL);
- overridePendingTransition(0, 0);
- } else {
- Intent mIntentL = new Intent(LoginActivity.this, RegeCreateActivity.class);
- startActivity(mIntentL);
- overridePendingTransition(0, 0);
- }
- } else {
- FitiquityUtils.showToast(((ViewGroup) findViewById(android.R.id.content)).getChildAt(0),
- mActivity, result.getResponseDetails());
- }
- }
- @Override
- public void webServiceDataRetrieveFailed(SetGetLogin result) {
- }
- @Override
- public void webServiceInvalidAPIParameter(DataForWebServiceFailed result) {
- }
- @Override
- public void webServiceSessionFailed(DataForWebServiceFailed result) {
- }
- @Override
- public void webServiceGeneralServerError(DataForWebServiceFailed result) {
- }
- });
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
- mLoginAsyncTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
- } else {
- mLoginAsyncTask.execute();
- }
- } else {
- FitiquityUtils.showToast((ViewGroup) ((ViewGroup) this
- .findViewById(android.R.id.content)).getChildAt(0), mActivity, getString(R.string.no_network));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement