Guest User

login

a guest
Mar 2nd, 2017
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.72 KB | None | 0 0
  1. package com.example.abraao.client_easypay;
  2.  
  3. import android.app.ProgressDialog;
  4. import android.content.Context;
  5. import android.content.Intent;
  6. import android.os.Environment;
  7. import android.support.v7.app.AppCompatActivity;
  8. import android.os.Bundle;
  9. import android.util.Log;
  10. import android.view.KeyEvent;
  11. import android.view.View;
  12. import android.view.inputmethod.EditorInfo;
  13. import android.widget.AutoCompleteTextView;
  14. import android.widget.Button;
  15. import android.widget.EditText;
  16. import android.widget.ProgressBar;
  17. import android.widget.TextView;
  18. import android.widget.Toast;
  19.  
  20. import com.google.gson.Gson;
  21. import com.google.gson.GsonBuilder;
  22.  
  23. import java.io.File;
  24. import java.io.FileOutputStream;
  25.  
  26. import retrofit2.Call;
  27. import retrofit2.Callback;
  28. import retrofit2.Response;
  29. import retrofit2.Retrofit;
  30. import retrofit2.converter.gson.GsonConverterFactory;
  31.  
  32. public class LoginActivity extends AppCompatActivity {
  33.  
  34. private static final String BASE_URL = "http://150.165.205.42/WcfServiceEasyPay/Service1.svc/";
  35. // private static final String BASE_URL = "http://192.168.1.104/WcfServiceEasyPay/Service1.svc/";
  36.  
  37. // UI references.
  38. private AutoCompleteTextView mEmailView;
  39. private EditText mPasswordView;
  40. private View mProgressView;
  41. private View mLoginFormView;
  42. private ProgressBar authProgressDialog;
  43.  
  44. String login = "", senha = "";
  45.  
  46.  
  47. @Override
  48. protected void onCreate(Bundle savedInstanceState) {
  49. super.onCreate(savedInstanceState);
  50. setContentView(R.layout.activity_login);
  51. // Set up the login form.
  52. mEmailView = (AutoCompleteTextView) findViewById(R.id.email);
  53. mPasswordView = (EditText) findViewById(R.id.password);
  54.  
  55. mEmailView.setText("111.222.333-44");
  56. mPasswordView.setText("11111");
  57.  
  58.  
  59. authProgressDialog = (ProgressBar) findViewById(R.id.progressBar);
  60. authProgressDialog.setVisibility(View.GONE);
  61.  
  62.  
  63. mPasswordView.setOnEditorActionListener(new TextView.OnEditorActionListener() {
  64. @Override
  65. public boolean onEditorAction(TextView textView, int id, KeyEvent keyEvent) {//Mostra a senha
  66. if (id == R.id.login || id == EditorInfo.IME_NULL) {
  67. return true;
  68. }
  69. return false;
  70. }
  71. });
  72.  
  73. Button mSignInButton = (Button) findViewById(R.id.sign_in_button);
  74. mSignInButton.setOnClickListener(new View.OnClickListener() {
  75. @Override
  76. public void onClick(View view) {
  77. authProgressDialog.setVisibility(View.VISIBLE);
  78. // Inflate the layout for this fragment
  79.  
  80.  
  81. Gson gson = new GsonBuilder().registerTypeAdapter(User.class, new UserDec()).create();
  82.  
  83. // mainButton.setBackgroundColor(getContext().getResources().getColor(R.color.colorAccent));
  84.  
  85.  
  86. Retrofit retrofit = new Retrofit.Builder()
  87. .baseUrl(BASE_URL)
  88. .addConverterFactory(GsonConverterFactory.create())
  89. .build();
  90. UserService userService = retrofit.create(UserService.class);
  91. /*final String cpf_cnpj = "111.852.849-58",
  92. password = "11111";*/
  93. Call<User> user = userService.getUser(mEmailView.getText().toString(), mPasswordView.getText().toString());
  94. user.enqueue(new Callback<User>() {
  95. String filename = "myfile.txt";
  96. FileOutputStream outputStream;
  97. @Override
  98. public void onResponse(Call<User> call, Response<User> response) {
  99. if (response.isSuccessful()) {
  100. User User = response.body();
  101.  
  102. Log.i("USER Login", User.getCpnjCpf() + ";" + User.getPassword());
  103. String strLogin = User.getSaldo().toString() + ";" + User.getName().toString() + ";" + User.getStatus().toString() + ";" + User.getCpnjCpf().toString();
  104. Log.i("USER Login", "----------------------------");
  105. if (!User.getCpnjCpf().isEmpty() && !User.getPassword().isEmpty())
  106. {
  107. try {
  108. FileWriteRead fileWriteRead = new FileWriteRead();
  109. fileWriteRead.SaveArchive(getApplicationContext(), strLogin);
  110. startActivity(new Intent(LoginActivity.this, MainActivity.class) );
  111. } catch (Exception e) {
  112. e.printStackTrace();
  113. }
  114. }
  115. } else {
  116. Toast.makeText(getApplicationContext(), "ERRO: " + response.code(), Toast.LENGTH_SHORT).show();
  117. authProgressDialog.setVisibility(View.GONE);
  118.  
  119. }
  120. }
  121.  
  122. @Override
  123. public void onFailure(Call<User> call, Throwable t) {
  124. authProgressDialog.setVisibility(View.GONE);
  125. }
  126. });
  127.  
  128.  
  129. }
  130. });
  131.  
  132. Button mRegisterButton = (Button) findViewById(R.id.register_button);
  133. mRegisterButton.setOnClickListener(new View.OnClickListener() {
  134. @Override
  135. public void onClick(View v) {
  136. // Toast.makeText(getApplicationContext(), "register", Toast.LENGTH_SHORT).show();
  137. startActivity(new Intent(LoginActivity.this, RegisterActivity.class));
  138.  
  139. }
  140. });
  141. }
  142. }
Add Comment
Please, Sign In to add comment