Advertisement
Guest User

Untitled

a guest
Apr 5th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.38 KB | None | 0 0
  1. public class FitiquityTest extends ActivityInstrumentationTestCase2<LoginActivity> {
  2. LoginActivity mActivity;
  3. private EditText username;
  4. private EditText password;
  5. public FitiquityTest()
  6. {
  7. super("com.fitiquity.activity.LoginActivity",LoginActivity.class);
  8. }
  9.  
  10. @Override
  11. protected void setUp() throws Exception {
  12. super.setUp();
  13. mActivity = this.getActivity();
  14. username = (EditText) mActivity.findViewById(R.id.login_email_mobile_et);
  15. password = (EditText) mActivity.findViewById(R.id.login_password_et);
  16. }
  17.  
  18. @Test
  19. public void testPreconditions() {
  20. assertNotNull(username);
  21. assertNotNull(password);
  22. }
  23.  
  24. @Test
  25. public void testText() {
  26. assertEquals("hello",username.getText());
  27. assertEquals("hello123", password.getText());
  28. }
  29.  
  30. }
  31.  
  32. public class LoginActivity extends Activity implements View.OnClickListener {
  33. private ImageView imgAppLogo;
  34. private EditText login_email_mobile_et, login_password_et;
  35. private TextView login_sign_up, login_signin, login_forgot_password;
  36. private String inputType = "";
  37. private CircleProgress progressLoader;
  38. private Activity mActivity;
  39.  
  40. @Override
  41. protected void onCreate(Bundle savedInstanceState) {
  42. super.onCreate(savedInstanceState);
  43. setContentView(R.layout.activity_login);
  44. initView();
  45. playAnimation();
  46. }
  47.  
  48. private void initView() {
  49.  
  50. mActivity = LoginActivity.this;
  51.  
  52. login_email_mobile_et = (EditText) findViewById(R.id.login_email_mobile_et);
  53. login_password_et = (EditText) findViewById(R.id.login_password_et);
  54.  
  55. imgAppLogo = (ImageView) findViewById(R.id.login_app_logo);
  56.  
  57. login_sign_up = (TextView) findViewById(R.id.login_sign_up);
  58. login_sign_up.setOnClickListener(this);
  59.  
  60. login_signin = (TextView) findViewById(R.id.login_signin);
  61. login_signin.setOnClickListener(this);
  62.  
  63. login_forgot_password = (TextView) findViewById(R.id.login_forgot_password);
  64. login_forgot_password.setOnClickListener(this);
  65.  
  66. progressLoader = (CircleProgress) findViewById(R.id.progressLoader);
  67. }
  68.  
  69. private void playAnimation() {
  70. AnimatorSet animset = new AnimatorSet();
  71. animset.playTogether(FitiquityApplication.getInstance().slideAnimation(imgAppLogo,
  72. FitiquityApplication.getDisplay(LoginActivity.this).heightPixels, 0),
  73. FitiquityApplication.getInstance().fadeInAnimation(findViewById(R.id.login_top_shadow)));
  74. animset.start();
  75. }
  76.  
  77. @Override
  78. public void onClick(View v) {
  79. switch (v.getId()) {
  80. case R.id.login_sign_up:
  81. Intent mIntentR = new Intent(LoginActivity.this, RegeCreateActivity.class);
  82. startActivity(mIntentR);
  83. overridePendingTransition(0, 0);
  84. break;
  85.  
  86. case R.id.login_signin:
  87. String email = login_email_mobile_et.getText().toString().trim();
  88. String password = login_password_et.getText().toString().trim();
  89.  
  90. String dev_id = Settings.Secure.getString(mActivity.getContentResolver(),
  91. Settings.Secure.ANDROID_ID);
  92.  
  93. if (!TextUtils.isEmpty(email) && !TextUtils.isEmpty(password)) {
  94. if (password.length() > 4) {
  95. FitiquityUtils.HideKeyboard(LoginActivity.this, v);
  96. if (FitiquityUtils.isValidMail(email)) {
  97. inputType = WSTags.EMAIL;
  98. callWebLogin(email, password, inputType, dev_id, progressLoader);
  99. } else if (FitiquityUtils.isValidMobile(email)) {
  100. inputType = WSTags.PHONE;
  101. callWebLogin(email, password, inputType, dev_id, progressLoader);
  102. } else {
  103. FitiquityUtils.showToast(v, LoginActivity.this, mActivity.getString(R.string.validaiton_proper_email_mobile));
  104. }
  105. } else {
  106. FitiquityUtils.showToast(v, LoginActivity.this, mActivity.getString(R.string.password));
  107. }
  108. } else {
  109. FitiquityUtils.showToast(v, LoginActivity.this, mActivity.getString(R.string.validation_general_blank));
  110. }
  111. break;
  112.  
  113. case R.id.login_forgot_password:
  114. ForgotPasswordDialog mForgotPasswordDialog = new ForgotPasswordDialog(mActivity);
  115. mForgotPasswordDialog.show();
  116. break;
  117. }
  118. }
  119.  
  120. private void callWebLogin(String emailorMobileNo, String passowrd, String inputType,
  121. String device_id, CircleProgress mLoader) {
  122. if (FitiquityUtils.isOnline(mActivity)) {
  123. AsyncTaskLogin mLoginAsyncTask = new AsyncTaskLogin(mActivity, emailorMobileNo, passowrd, inputType,
  124. device_id, mLoader, new InterfaceWebserviceCallback<SetGetLogin>() {
  125. @Override
  126. public void webServiceDataRetrieveSuccess(SetGetLogin result) {
  127.  
  128. if (result.getResponseCode().equals(String.valueOf(WSTags.RESPONSE_SUCCESS))) {
  129. FitiquityApplication.getInstance().mPrefs.setsessionKey(result.getProfile().getSession_id());
  130. FitiquityApplication.getInstance().mPrefs.setUserID(result.getProfile().getUser_id());
  131.  
  132. if (result.getProfile().getIs_paid().equals(Constants.ON)) {
  133. Intent mIntentL = new Intent(LoginActivity.this, HomeActivity.class);
  134. mIntentL.putExtra(Constants.LOGIN_INFO, result.getProfile());
  135. mIntentL.putExtra(Constants.TYPE, Constants.LOGIN_TYPE);
  136. startActivity(mIntentL);
  137. overridePendingTransition(0, 0);
  138. } else {
  139. Intent mIntentL = new Intent(LoginActivity.this, RegeCreateActivity.class);
  140. startActivity(mIntentL);
  141. overridePendingTransition(0, 0);
  142. }
  143. } else {
  144. FitiquityUtils.showToast(((ViewGroup) findViewById(android.R.id.content)).getChildAt(0),
  145. mActivity, result.getResponseDetails());
  146. }
  147. }
  148.  
  149. @Override
  150. public void webServiceDataRetrieveFailed(SetGetLogin result) {
  151.  
  152. }
  153.  
  154. @Override
  155. public void webServiceInvalidAPIParameter(DataForWebServiceFailed result) {
  156.  
  157. }
  158.  
  159. @Override
  160. public void webServiceSessionFailed(DataForWebServiceFailed result) {
  161.  
  162. }
  163.  
  164. @Override
  165. public void webServiceGeneralServerError(DataForWebServiceFailed result) {
  166.  
  167. }
  168. });
  169.  
  170. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
  171. mLoginAsyncTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
  172. } else {
  173. mLoginAsyncTask.execute();
  174. }
  175. } else {
  176. FitiquityUtils.showToast((ViewGroup) ((ViewGroup) this
  177. .findViewById(android.R.id.content)).getChildAt(0), mActivity, getString(R.string.no_network));
  178. }
  179. }
  180. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement