Commit eb442e6243a2ae7d9fb7f32f33cd8c2df259ece6
1 parent
8e658a57
Exists in
master
refactoring do login
Showing
8 changed files
with
639 additions
and
613 deletions
Show diff stats
app/src/main/AndroidManifest.xml
... | ... | @@ -57,15 +57,6 @@ |
57 | 57 | android:value="com.monitorabrasil.participacidadao.view.MainActivity" /> |
58 | 58 | </activity> |
59 | 59 | <activity |
60 | - android:name="com.monitorabrasil.participacidadao.view.LoginActivity" | |
61 | - android:label="@string/title_activity_login" | |
62 | - android:parentActivityName="com.monitorabrasil.participacidadao.view.MainActivity" | |
63 | - android:windowSoftInputMode="adjustResize|stateVisible" > | |
64 | - <meta-data | |
65 | - android:name="android.support.PARENT_ACTIVITY" | |
66 | - android:value="com.monitorabrasil.participacidadao.view.MainActivity" /> | |
67 | - </activity> | |
68 | - <activity | |
69 | 60 | android:name="com.monitorabrasil.participacidadao.view.PoliticoFichaActivity" |
70 | 61 | android:label="@string/title_activity_politico_ficha" |
71 | 62 | android:parentActivityName="com.monitorabrasil.participacidadao.view.PoliticosActivity" > |
... | ... | @@ -86,7 +77,7 @@ |
86 | 77 | android:value="com.monitorabrasil.participacidadao.view.MainActivity" /> |
87 | 78 | </activity> |
88 | 79 | <activity |
89 | - android:name="com.monitorabrasil.participacidadao.view.Login2Activity" | |
80 | + android:name=".view.LoginActivity" | |
90 | 81 | android:label="@string/title_activity_login2" |
91 | 82 | android:parentActivityName="com.monitorabrasil.participacidadao.view.MainActivity" > |
92 | 83 | <meta-data | ... | ... |
app/src/main/java/com/monitorabrasil/participacidadao/actions/ActionsCreator.java
... | ... | @@ -3,7 +3,9 @@ package com.monitorabrasil.participacidadao.actions; |
3 | 3 | import com.monitorabrasil.participacidadao.dispatcher.Dispatcher; |
4 | 4 | import com.parse.LogInCallback; |
5 | 5 | import com.parse.LogOutCallback; |
6 | +import com.parse.ParseFile; | |
6 | 7 | import com.parse.ParseUser; |
8 | +import com.parse.ProgressCallback; | |
7 | 9 | import com.parse.SignUpCallback; |
8 | 10 | |
9 | 11 | /** |
... | ... | @@ -71,31 +73,38 @@ public class ActionsCreator { |
71 | 73 | } |
72 | 74 | |
73 | 75 | |
74 | - public void cadastrar(String nome, String password, String email) { | |
75 | - ParseUser user = new ParseUser(); | |
76 | - user.setUsername(email); | |
77 | - user.setPassword(password); | |
78 | - user.setEmail(email); | |
79 | - user.put("nome", nome); | |
80 | - | |
81 | - | |
82 | - user.signUpInBackground(new SignUpCallback() { | |
76 | + public void cadastrar(final String nome, final String password, final String email, final ParseFile mParseFile) { | |
77 | + mParseFile.saveInBackground(new ProgressCallback() { | |
83 | 78 | @Override |
84 | - public void done(com.parse.ParseException e) { | |
85 | - if (e == null) { | |
86 | - dispatcher.dispatch( | |
87 | - UserActions.USER_CADASTRO, | |
88 | - UserActions.KEY_TEXT, "sucesso" | |
89 | - ); | |
90 | - } else { | |
91 | - dispatcher.dispatch( | |
92 | - UserActions.USER_CADASTRO, | |
93 | - UserActions.KEY_TEXT, "erro" | |
94 | - ); | |
95 | - } | |
79 | + public void done(Integer integer) { | |
80 | + ParseUser user = new ParseUser(); | |
81 | + user.setUsername(email); | |
82 | + user.setPassword(password); | |
83 | + user.setEmail(email); | |
84 | + user.put("nome", nome); | |
85 | + user.put("foto", mParseFile); | |
86 | + user.signUpInBackground(new SignUpCallback() { | |
87 | + @Override | |
88 | + public void done(com.parse.ParseException e) { | |
89 | + if (e == null) { | |
90 | + dispatcher.dispatch( | |
91 | + UserActions.USER_CADASTRO, | |
92 | + UserActions.KEY_TEXT, "sucesso" | |
93 | + ); | |
94 | + } else { | |
95 | + dispatcher.dispatch( | |
96 | + UserActions.USER_CADASTRO, | |
97 | + UserActions.KEY_TEXT, "erro" | |
98 | + ); | |
99 | + } | |
100 | + } | |
101 | + | |
102 | + | |
103 | + }); | |
96 | 104 | } |
105 | + }); | |
106 | + | |
97 | 107 | |
98 | 108 | |
99 | - }); | |
100 | 109 | } |
101 | 110 | } | ... | ... |
app/src/main/java/com/monitorabrasil/participacidadao/view/Login2Activity.java
... | ... | @@ -1,503 +0,0 @@ |
1 | -package com.monitorabrasil.monitoralegislativo.view; | |
2 | - | |
3 | -import android.app.Activity; | |
4 | -import android.content.Intent; | |
5 | -import android.graphics.Bitmap; | |
6 | -import android.graphics.BitmapFactory; | |
7 | -import android.net.Uri; | |
8 | -import android.os.Bundle; | |
9 | -import android.support.design.widget.Snackbar; | |
10 | -import android.support.v7.app.AppCompatActivity; | |
11 | -import android.support.v7.widget.Toolbar; | |
12 | -import android.text.TextUtils; | |
13 | -import android.view.KeyEvent; | |
14 | -import android.view.View; | |
15 | -import android.view.View.OnClickListener; | |
16 | -import android.view.inputmethod.EditorInfo; | |
17 | -import android.widget.ArrayAdapter; | |
18 | -import android.widget.AutoCompleteTextView; | |
19 | -import android.widget.Button; | |
20 | -import android.widget.EditText; | |
21 | -import android.widget.ImageButton; | |
22 | -import android.widget.ImageView; | |
23 | -import android.widget.TextView; | |
24 | - | |
25 | -import com.monitorabrasil.monitoralegislativo.R; | |
26 | -import com.monitorabrasil.monitoralegislativo.actions.ActionsCreator; | |
27 | -import com.monitorabrasil.monitoralegislativo.actions.UserActions; | |
28 | -import com.monitorabrasil.monitoralegislativo.application.MyApp; | |
29 | -import com.monitorabrasil.monitoralegislativo.dispatcher.Dispatcher; | |
30 | -import com.monitorabrasil.monitoralegislativo.stores.UserStore; | |
31 | -import com.nostra13.universalimageloader.core.assist.FailReason; | |
32 | -import com.nostra13.universalimageloader.core.listener.ImageLoadingListener; | |
33 | -import com.parse.LogInCallback; | |
34 | -import com.parse.LogOutCallback; | |
35 | -import com.parse.ParseTwitterUtils; | |
36 | -import com.parse.ParseUser; | |
37 | -import com.parse.SignUpCallback; | |
38 | -import com.squareup.otto.Bus; | |
39 | -import com.squareup.otto.Subscribe; | |
40 | - | |
41 | -import java.io.FileNotFoundException; | |
42 | -import java.io.InputStream; | |
43 | -import java.util.List; | |
44 | - | |
45 | - | |
46 | - | |
47 | -/** | |
48 | - * A login screen that offers login via email/password. | |
49 | - */ | |
50 | -public class Login2Activity extends AppCompatActivity { | |
51 | - | |
52 | - | |
53 | - /** | |
54 | - * Keep track of the login task to ensure we can cancel it if requested. | |
55 | - */ | |
56 | - | |
57 | - | |
58 | - // UI references. | |
59 | - private AutoCompleteTextView mEmailView; | |
60 | - private EditText mPasswordView; | |
61 | - private EditText mNome; | |
62 | - private View mProgressView; | |
63 | - private View mLoginFormView; | |
64 | - private View mLogoutFormView; | |
65 | - private Button btnFazerCadastro; | |
66 | - private Button btnLogar; | |
67 | - private Button btnLogout; | |
68 | - private Button btnLoginTwitter; | |
69 | - private TextView lblNome; | |
70 | - private TextView lblEmail; | |
71 | - private ImageView foto; | |
72 | - private ParseUser currentUser; | |
73 | - private ImageButton btnFoto; | |
74 | - | |
75 | - private Dispatcher dispatcher; | |
76 | - private ActionsCreator actionsCreator; | |
77 | - private UserStore userStore; | |
78 | - | |
79 | - | |
80 | - private final int PICK_IMAGE=2; | |
81 | - | |
82 | - @Override | |
83 | - protected void onCreate(Bundle savedInstanceState) { | |
84 | - super.onCreate(savedInstanceState); | |
85 | - setContentView(R.layout.activity_login); | |
86 | - initDependencies(); | |
87 | - setupView(); | |
88 | - } | |
89 | - | |
90 | - private void initDependencies() { | |
91 | - dispatcher = Dispatcher.get(new Bus()); | |
92 | - actionsCreator = ActionsCreator.get(dispatcher); | |
93 | - userStore = UserStore.get(dispatcher); | |
94 | - } | |
95 | - | |
96 | - private void setupView() { | |
97 | - setupActionBar(); | |
98 | - mLoginFormView = findViewById(R.id.login_form); | |
99 | - mLogoutFormView = findViewById(R.id.logout_form); | |
100 | - mProgressView = findViewById(R.id.login_progress); | |
101 | - | |
102 | - btnFoto = (ImageButton) findViewById(R.id.btnFoto); | |
103 | - btnLogar = (Button) findViewById(R.id.email_sign_in_button); | |
104 | - btnLogout = (Button) findViewById(R.id.btnLogout); | |
105 | - | |
106 | - currentUser = ParseUser.getCurrentUser(); | |
107 | - | |
108 | - if (currentUser != null) { | |
109 | - montaFormLogout(); | |
110 | - | |
111 | - } else { | |
112 | - montaFormLogin(); | |
113 | - | |
114 | - } | |
115 | - | |
116 | - | |
117 | - | |
118 | - btnLogar.setOnClickListener(new OnClickListener() { | |
119 | - @Override | |
120 | - public void onClick(View view) { | |
121 | - showProgress(true, null); | |
122 | - logar(); | |
123 | - } | |
124 | - }); | |
125 | - | |
126 | - btnLogout.setOnClickListener(new OnClickListener() { | |
127 | - | |
128 | - @Override | |
129 | - public void onClick(View v) { | |
130 | - showProgress(true, null); | |
131 | - logout(); | |
132 | - | |
133 | - | |
134 | - } | |
135 | - }); | |
136 | - | |
137 | - btnFoto.setOnClickListener(new OnClickListener() { | |
138 | - @Override | |
139 | - public void onClick(View v) { | |
140 | - Intent getIntent = new Intent(Intent.ACTION_GET_CONTENT); | |
141 | - getIntent.setType("image/*"); | |
142 | - | |
143 | - Intent pickIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); | |
144 | - pickIntent.setType("image/*"); | |
145 | - | |
146 | - Intent chooserIntent = Intent.createChooser(getIntent, "Selecione uma foto"); | |
147 | - chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[]{pickIntent}); | |
148 | - | |
149 | - startActivityForResult(chooserIntent, PICK_IMAGE); | |
150 | - } | |
151 | - }); | |
152 | - | |
153 | - mNome = (EditText) findViewById(R.id.txtNome); | |
154 | - mNome.setVisibility(View.GONE); | |
155 | - | |
156 | - | |
157 | - | |
158 | - | |
159 | - | |
160 | - btnFazerCadastro = (Button) findViewById(R.id.fazer_cadastro); | |
161 | - btnFazerCadastro.setOnClickListener(new OnClickListener() { | |
162 | - @Override | |
163 | - public void onClick(View v) { | |
164 | - if (btnFazerCadastro.getText().toString().equals("Fazer Cadastro")) { | |
165 | - mNome.setVisibility(View.VISIBLE); | |
166 | - btnLogar.setVisibility(View.GONE); | |
167 | - btnLoginTwitter.setVisibility(View.GONE); | |
168 | - btnFazerCadastro.setText("Cadastrar"); | |
169 | - View view = mNome; | |
170 | - view.requestFocus(); | |
171 | - } else { | |
172 | - realizarCadastro(); | |
173 | - } | |
174 | - | |
175 | - } | |
176 | - }); | |
177 | - | |
178 | - btnLoginTwitter = (Button) findViewById(R.id.login_twitter); | |
179 | - btnLoginTwitter.setOnClickListener(new OnClickListener() { | |
180 | - @Override | |
181 | - public void onClick(View v) { | |
182 | - ParseTwitterUtils.logIn(v.getContext(), new LogInCallback() { | |
183 | - @Override | |
184 | - public void done(ParseUser parseUser, com.parse.ParseException e) { | |
185 | - if (parseUser == null) { | |
186 | - Snackbar.make(mLoginFormView, "Login cancelado ", Snackbar.LENGTH_LONG) | |
187 | - .setAction("Action", null).show(); | |
188 | - } else if (parseUser.isNew()) { | |
189 | - parseUser.put("nome", ParseTwitterUtils.getTwitter().getScreenName()); | |
190 | - parseUser.saveInBackground(); | |
191 | - montaFormLogout(); | |
192 | - } else { | |
193 | - montaFormLogout(); | |
194 | - } | |
195 | - } | |
196 | - }); | |
197 | - } | |
198 | - }); | |
199 | - | |
200 | - mEmailView = (AutoCompleteTextView) findViewById(R.id.email); | |
201 | - | |
202 | - | |
203 | - mPasswordView = (EditText) findViewById(R.id.password); | |
204 | - mPasswordView.setOnEditorActionListener(new TextView.OnEditorActionListener() { | |
205 | - @Override | |
206 | - public boolean onEditorAction(TextView textView, int id, KeyEvent keyEvent) { | |
207 | - if (id == R.id.login || id == EditorInfo.IME_NULL) { | |
208 | - attemptLogin(); | |
209 | - return true; | |
210 | - } | |
211 | - return false; | |
212 | - } | |
213 | - }); | |
214 | - | |
215 | - | |
216 | - | |
217 | - } | |
218 | - | |
219 | - | |
220 | - | |
221 | - private void verificaLogin() { | |
222 | - if(ParseUser.getCurrentUser()!=null){ | |
223 | - montaFormLogout(); | |
224 | - }else{ | |
225 | - montaFormLogin(); | |
226 | - } | |
227 | - } | |
228 | - | |
229 | - private void logout() { | |
230 | - | |
231 | - actionsCreator.logout(); | |
232 | - } | |
233 | - | |
234 | - private void montaFormLogin() { | |
235 | - mLogoutFormView.setVisibility(View.GONE); | |
236 | - mLoginFormView.setVisibility(View.VISIBLE); | |
237 | - } | |
238 | - | |
239 | - private void logar() { | |
240 | - if(validaCampos()){ | |
241 | - actionsCreator.logar(getInputUsuario(), getInputSenha()); | |
242 | - } | |
243 | - } | |
244 | - | |
245 | - private String getInputUsuario() { | |
246 | - return mEmailView.getText().toString(); | |
247 | - } | |
248 | - | |
249 | - private String getInputSenha() { | |
250 | - return mPasswordView.getText().toString(); | |
251 | - } | |
252 | - | |
253 | - private boolean validaCampos() { | |
254 | - return true; | |
255 | - } | |
256 | - | |
257 | - @Subscribe | |
258 | - public void onTodoStoreChange(UserStore.UserStoreChangeEvent event) { | |
259 | - switch (event.getEvento()){ | |
260 | - case UserActions.USER_CADASTRO: | |
261 | - if(event.getStatus().equals("erro")){ | |
262 | - showProgress(false, mLoginFormView); | |
263 | - Snackbar.make(mLoginFormView, "Houve um erro ao fazer seu cadastro ", Snackbar.LENGTH_LONG) | |
264 | - .setAction("Action", null).show(); | |
265 | - } | |
266 | - break; | |
267 | - } | |
268 | - updateUI(); | |
269 | - } | |
270 | - | |
271 | - @Override | |
272 | - protected void onResume() { | |
273 | - super.onResume(); | |
274 | - dispatcher.register(this); | |
275 | - dispatcher.register(userStore); | |
276 | - } | |
277 | - | |
278 | - @Override | |
279 | - protected void onPause() { | |
280 | - super.onPause(); | |
281 | - dispatcher.unregister(this); | |
282 | - dispatcher.unregister(userStore); | |
283 | - } | |
284 | - | |
285 | - | |
286 | - @Override | |
287 | - public void onActivityResult(int requestCode, int resultCode, Intent data) { | |
288 | - super.onActivityResult(requestCode, resultCode, data); | |
289 | - if (requestCode == PICK_IMAGE && resultCode == Activity.RESULT_OK) { | |
290 | - if (data == null) { | |
291 | - //Display an error | |
292 | - return; | |
293 | - } | |
294 | - try { | |
295 | - Uri selectedImage = data.getData(); | |
296 | - InputStream imageStream = getContentResolver().openInputStream(selectedImage); | |
297 | - Bitmap yourSelectedImage = BitmapFactory.decodeStream(imageStream); | |
298 | - btnFoto.setImageBitmap(yourSelectedImage); | |
299 | - } catch (FileNotFoundException e) { | |
300 | - e.printStackTrace(); | |
301 | - } | |
302 | - //Now you can do whatever you want with your inpustream, save it as file, upload to a server, decode a bitmap... | |
303 | - } | |
304 | - } | |
305 | - | |
306 | - private void showProgress(boolean b,View v) { | |
307 | - if(b){ | |
308 | - mProgressView.setVisibility(View.VISIBLE); | |
309 | - mLogoutFormView.setVisibility(View.GONE); | |
310 | - mLoginFormView.setVisibility(View.GONE); | |
311 | - }else{ | |
312 | - mProgressView.setVisibility(View.GONE); | |
313 | - v.setVisibility(View.VISIBLE); | |
314 | - } | |
315 | - } | |
316 | - | |
317 | - private void montaFormLogout() { | |
318 | - lblNome = (TextView)findViewById(R.id.lblNome); | |
319 | - lblEmail = (TextView)findViewById(R.id.lblEmail); | |
320 | - foto = (ImageView)findViewById(R.id.foto); | |
321 | - | |
322 | - mLoginFormView.setVisibility(View.GONE); | |
323 | - showProgress(false,mLogoutFormView); | |
324 | - | |
325 | - | |
326 | - } | |
327 | - | |
328 | - | |
329 | - private void realizarCadastro() { | |
330 | - | |
331 | - // Reset errors. | |
332 | - mEmailView.setError(null); | |
333 | - mPasswordView.setError(null); | |
334 | - mNome.setError(null); | |
335 | - | |
336 | - // Store values at the time of the login attempt. | |
337 | - String email = mEmailView.getText().toString(); | |
338 | - String password = mPasswordView.getText().toString(); | |
339 | - String nome =mNome.getText().toString(); | |
340 | - | |
341 | - boolean cancel = false; | |
342 | - View focusView = null; | |
343 | - | |
344 | - if (TextUtils.isEmpty(nome)) { | |
345 | - mNome.setError(getString(R.string.error_field_required)); | |
346 | - focusView = mNome; | |
347 | - cancel = true; | |
348 | - } | |
349 | - | |
350 | - // Check for a valid password, if the user entered one. | |
351 | - if (!TextUtils.isEmpty(password) && !isPasswordValid(password)) { | |
352 | - mPasswordView.setError(getString(R.string.error_invalid_password)); | |
353 | - focusView = mPasswordView; | |
354 | - cancel = true; | |
355 | - } | |
356 | - | |
357 | - // Check for a valid email address. | |
358 | - if (TextUtils.isEmpty(email)) { | |
359 | - mEmailView.setError(getString(R.string.error_field_required)); | |
360 | - focusView = mEmailView; | |
361 | - cancel = true; | |
362 | - } else if (!isEmailValid(email)) { | |
363 | - mEmailView.setError(getString(R.string.error_invalid_email)); | |
364 | - focusView = mEmailView; | |
365 | - cancel = true; | |
366 | - } | |
367 | - | |
368 | - if (cancel) { | |
369 | - // There was an error; don't attempt login and focus the first | |
370 | - // form field with an error. | |
371 | - focusView.requestFocus(); | |
372 | - } else { | |
373 | - // Show a progress spinner, and kick off a background task to | |
374 | - // perform the user login attempt. | |
375 | - showProgress(true, null); | |
376 | - | |
377 | - | |
378 | - actionsCreator.cadastrar(nome, password, email); | |
379 | - | |
380 | - | |
381 | - | |
382 | - | |
383 | - } | |
384 | - } | |
385 | - | |
386 | - | |
387 | - | |
388 | - /** | |
389 | - * Set up the {@link android.app.ActionBar}, if the API is available. | |
390 | - */ | |
391 | -// @TargetApi(Build.VERSION_CODES.HONEYCOMB) | |
392 | - private void setupActionBar() { | |
393 | - Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); | |
394 | - | |
395 | - // toolbar.setNavigationIcon(R.drawable.ic_good); | |
396 | - toolbar.setTitle("Login"); | |
397 | - | |
398 | - toolbar.setTitleTextColor(getResources().getColor(R.color.md_white_1000)); | |
399 | - toolbar.setSubtitleTextColor(getResources().getColor(R.color.md_white_1000)); | |
400 | - setSupportActionBar(toolbar); | |
401 | - getSupportActionBar().setDisplayHomeAsUpEnabled(true); | |
402 | - } | |
403 | - | |
404 | - /** | |
405 | - * Attempts to sign in or register the account specified by the login form. | |
406 | - * If there are form errors (invalid email, missing fields, etc.), the | |
407 | - * errors are presented and no actual login attempt is made. | |
408 | - */ | |
409 | - public void attemptLogin() { | |
410 | - | |
411 | - | |
412 | - // Reset errors. | |
413 | - mEmailView.setError(null); | |
414 | - mPasswordView.setError(null); | |
415 | - | |
416 | - // Store values at the time of the login attempt. | |
417 | - String email = mEmailView.getText().toString(); | |
418 | - String password = mPasswordView.getText().toString(); | |
419 | - | |
420 | - boolean cancel = false; | |
421 | - View focusView = null; | |
422 | - | |
423 | - // Check for a valid password, if the user entered one. | |
424 | - if (TextUtils.isEmpty(password) && !isPasswordValid(password)) { | |
425 | - mPasswordView.setError(getString(R.string.error_invalid_password)); | |
426 | - focusView = mPasswordView; | |
427 | - cancel = true; | |
428 | - } | |
429 | - | |
430 | - // Check for a valid email address. | |
431 | - if (TextUtils.isEmpty(email)) { | |
432 | - mEmailView.setError(getString(R.string.error_field_required)); | |
433 | - focusView = mEmailView; | |
434 | - cancel = true; | |
435 | - } else if (!isEmailValid(email)) { | |
436 | - mEmailView.setError(getString(R.string.error_invalid_email)); | |
437 | - focusView = mEmailView; | |
438 | - cancel = true; | |
439 | - } | |
440 | - | |
441 | - if (cancel) { | |
442 | - // There was an error; don't attempt login and focus the first | |
443 | - // form field with an error. | |
444 | - focusView.requestFocus(); | |
445 | - } else { | |
446 | - // Show a progress spinner, and kick off a background task to | |
447 | - // perform the user login attempt. | |
448 | - showProgress(true,null); | |
449 | - | |
450 | - //fazer o login aqui | |
451 | - fazerLogin(email, password); | |
452 | - | |
453 | - } | |
454 | - } | |
455 | - | |
456 | - private void fazerLogin(String email, String password) { | |
457 | - ParseUser.logInInBackground(email, password, new LogInCallback() { | |
458 | - | |
459 | - @Override | |
460 | - public void done(ParseUser parseUser, com.parse.ParseException e) { | |
461 | - if (parseUser != null) { | |
462 | - finish(); | |
463 | - } else { | |
464 | - mPasswordView.setError(getString(R.string.error_incorrect_password)); | |
465 | - mPasswordView.requestFocus(); | |
466 | - showProgress(false,mLoginFormView); | |
467 | - } | |
468 | - } | |
469 | - | |
470 | - | |
471 | - }); | |
472 | - } | |
473 | - | |
474 | - private boolean isEmailValid(String email) { | |
475 | - //TODO: Replace this with your own logic | |
476 | - return email.contains("@"); | |
477 | - } | |
478 | - | |
479 | - private boolean isPasswordValid(String password) { | |
480 | - //TODO: Replace this with your own logic | |
481 | - return password.length() > 4; | |
482 | - } | |
483 | - | |
484 | - | |
485 | - | |
486 | - private void updateUI() { | |
487 | - showProgress(false, mLoginFormView); | |
488 | - verificaLogin(); | |
489 | - } | |
490 | - | |
491 | - | |
492 | - private void addEmailsToAutoComplete(List<String> emailAddressCollection) { | |
493 | - //Create adapter to tell the AutoCompleteTextView what to show in its dropdown list. | |
494 | - ArrayAdapter<String> adapter = | |
495 | - new ArrayAdapter<String>(Login2Activity.this, | |
496 | - android.R.layout.simple_dropdown_item_1line, emailAddressCollection); | |
497 | - | |
498 | - mEmailView.setAdapter(adapter); | |
499 | - } | |
500 | - | |
501 | - | |
502 | -} | |
503 | - |
app/src/main/java/com/monitorabrasil/participacidadao/view/LoginActivity.java
0 → 100644
... | ... | @@ -0,0 +1,504 @@ |
1 | +package com.monitorabrasil.participacidadao.view; | |
2 | + | |
3 | +import android.app.Activity; | |
4 | +import android.content.Intent; | |
5 | +import android.graphics.Bitmap; | |
6 | +import android.graphics.BitmapFactory; | |
7 | +import android.graphics.drawable.BitmapDrawable; | |
8 | +import android.net.Uri; | |
9 | +import android.os.Bundle; | |
10 | +import android.support.design.widget.Snackbar; | |
11 | +import android.support.v7.app.AppCompatActivity; | |
12 | +import android.support.v7.widget.Toolbar; | |
13 | +import android.text.TextUtils; | |
14 | +import android.view.KeyEvent; | |
15 | +import android.view.View; | |
16 | +import android.view.View.OnClickListener; | |
17 | +import android.view.inputmethod.EditorInfo; | |
18 | +import android.widget.AutoCompleteTextView; | |
19 | +import android.widget.Button; | |
20 | +import android.widget.CompoundButton; | |
21 | +import android.widget.EditText; | |
22 | +import android.widget.ImageButton; | |
23 | +import android.widget.ImageView; | |
24 | +import android.widget.LinearLayout; | |
25 | +import android.widget.Switch; | |
26 | +import android.widget.TextView; | |
27 | + | |
28 | +import com.monitorabrasil.participacidadao.R; | |
29 | +import com.monitorabrasil.participacidadao.actions.ActionsCreator; | |
30 | +import com.monitorabrasil.participacidadao.actions.UserActions; | |
31 | +import com.monitorabrasil.participacidadao.dispatcher.Dispatcher; | |
32 | +import com.monitorabrasil.participacidadao.stores.UserStore; | |
33 | +import com.parse.ParseException; | |
34 | +import com.parse.ParseFile; | |
35 | +import com.parse.ParseTwitterUtils; | |
36 | +import com.parse.ParseUser; | |
37 | +import com.parse.SaveCallback; | |
38 | +import com.squareup.otto.Bus; | |
39 | +import com.squareup.otto.Subscribe; | |
40 | + | |
41 | +import java.io.ByteArrayOutputStream; | |
42 | +import java.io.FileNotFoundException; | |
43 | +import java.io.InputStream; | |
44 | + | |
45 | + | |
46 | + | |
47 | +/** | |
48 | + * Tela de login | |
49 | + */ | |
50 | +public class LoginActivity extends AppCompatActivity { | |
51 | + | |
52 | + private LinearLayout llTwitter; | |
53 | + | |
54 | + private AutoCompleteTextView mEmailView; | |
55 | + private EditText mPasswordView; | |
56 | + private EditText mNome; | |
57 | + private View mProgressView; | |
58 | + private Button btnFazerCadastro; | |
59 | + private Button btnLogar; | |
60 | + private Button btnLogout; | |
61 | + private Button btnSalvar; | |
62 | + private Switch mSwitchTwitter; | |
63 | + private ImageView foto; | |
64 | + private ParseUser currentUser; | |
65 | + private ImageButton btnFoto; | |
66 | + | |
67 | + private Dispatcher dispatcher; | |
68 | + private ActionsCreator actionsCreator; | |
69 | + private UserStore userStore; | |
70 | + | |
71 | + private LinearLayout form; | |
72 | + | |
73 | + | |
74 | + private final int PICK_IMAGE=2; | |
75 | + | |
76 | + @Override | |
77 | + protected void onCreate(Bundle savedInstanceState) { | |
78 | + super.onCreate(savedInstanceState); | |
79 | + setContentView(R.layout.activity_login); | |
80 | + initDependencies(); | |
81 | + setupView(); | |
82 | + } | |
83 | + | |
84 | + private void initDependencies() { | |
85 | + dispatcher = Dispatcher.get(new Bus()); | |
86 | + actionsCreator = ActionsCreator.get(dispatcher); | |
87 | + userStore = UserStore.get(dispatcher); | |
88 | + } | |
89 | + | |
90 | + private void setupView() { | |
91 | + setupActionBar(); | |
92 | + | |
93 | + llTwitter = (LinearLayout) findViewById(R.id.llTwitter); | |
94 | + form = (LinearLayout) findViewById(R.id.email_login_form); | |
95 | + | |
96 | + mSwitchTwitter = (Switch) findViewById(R.id.swTwitter); | |
97 | + | |
98 | + //progressView | |
99 | + mProgressView = findViewById(R.id.login_progress); | |
100 | + | |
101 | + //botoes | |
102 | + btnSalvar = (Button) findViewById(R.id.btnSalvar); | |
103 | + btnFoto = (ImageButton) findViewById(R.id.btnFoto); | |
104 | + btnLogar = (Button) findViewById(R.id.email_sign_in_button); | |
105 | + btnLogout = (Button) findViewById(R.id.btnLogout); | |
106 | + | |
107 | + //usuario atual | |
108 | + currentUser = ParseUser.getCurrentUser(); | |
109 | + | |
110 | + //verifica se esta logado | |
111 | + if (currentUser != null) { | |
112 | + montaFormLogout(); | |
113 | + } else { | |
114 | + montaFormLogin(); | |
115 | + } | |
116 | + | |
117 | + //evento: logar | |
118 | + btnLogar.setOnClickListener(new OnClickListener() { | |
119 | + @Override | |
120 | + public void onClick(View view) { | |
121 | + showProgress(true); | |
122 | + logar(); | |
123 | + } | |
124 | + }); | |
125 | + | |
126 | + //evento: logout | |
127 | + btnLogout.setOnClickListener(new OnClickListener() { | |
128 | + | |
129 | + @Override | |
130 | + public void onClick(View v) { | |
131 | + showProgress(true); | |
132 | + logout(); | |
133 | + | |
134 | + | |
135 | + } | |
136 | + }); | |
137 | + | |
138 | + //Botao para fazer o cadastro | |
139 | + btnFazerCadastro = (Button) findViewById(R.id.fazer_cadastro); | |
140 | + btnFazerCadastro.setOnClickListener(new OnClickListener() { | |
141 | + @Override | |
142 | + public void onClick(View v) { | |
143 | + if (btnFazerCadastro.getText().toString().equals("Fazer Cadastro")) { | |
144 | + mNome.setVisibility(View.VISIBLE); | |
145 | + btnLogar.setVisibility(View.GONE); | |
146 | + llTwitter.setVisibility(View.GONE); | |
147 | + btnFazerCadastro.setText("Cadastrar"); | |
148 | + View view = mNome; | |
149 | + view.requestFocus(); | |
150 | + } else { | |
151 | + if (validaCampos()) { | |
152 | + realizarCadastro(); | |
153 | + } | |
154 | + | |
155 | + } | |
156 | + | |
157 | + } | |
158 | + }); | |
159 | + | |
160 | + //evento: Busca foto para colocar no perfil | |
161 | + btnFoto.setOnClickListener(new OnClickListener() { | |
162 | + @Override | |
163 | + public void onClick(View v) { | |
164 | + Intent getIntent = new Intent(Intent.ACTION_GET_CONTENT); | |
165 | + getIntent.setType("image/*"); | |
166 | + | |
167 | + Intent pickIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); | |
168 | + pickIntent.setType("image/*"); | |
169 | + | |
170 | + Intent chooserIntent = Intent.createChooser(getIntent, "Selecione uma foto"); | |
171 | + chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[]{pickIntent}); | |
172 | + | |
173 | + startActivityForResult(chooserIntent, PICK_IMAGE); | |
174 | + } | |
175 | + }); | |
176 | + | |
177 | + | |
178 | + | |
179 | + mSwitchTwitter.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { | |
180 | + @Override | |
181 | + public void onCheckedChanged(CompoundButton compoundButton, boolean b) { | |
182 | + final ParseUser user = ParseUser.getCurrentUser(); | |
183 | + if (b) { | |
184 | + if (!ParseTwitterUtils.isLinked(user)) { | |
185 | + ParseTwitterUtils.link(user, getApplicationContext(), new SaveCallback() { | |
186 | + @Override | |
187 | + public void done(ParseException ex) { | |
188 | + if (ParseTwitterUtils.isLinked(user)) { | |
189 | + Snackbar.make(form, "Woohoo!! Conta adicionada!", Snackbar.LENGTH_LONG) | |
190 | + .setAction("Action", null).show(); | |
191 | + } | |
192 | + } | |
193 | + }); | |
194 | + } | |
195 | + } else { | |
196 | + ParseTwitterUtils.unlinkInBackground(user, new SaveCallback() { | |
197 | + @Override | |
198 | + public void done(ParseException ex) { | |
199 | + if (ex == null) { | |
200 | + if (ParseTwitterUtils.isLinked(user)) { | |
201 | + Snackbar.make(form, "Conta do Twitter removida", Snackbar.LENGTH_LONG) | |
202 | + .setAction("Action", null).show(); | |
203 | + } | |
204 | + } | |
205 | + } | |
206 | + }); | |
207 | + } | |
208 | + } | |
209 | + }); | |
210 | + | |
211 | + | |
212 | + //EditTextViews | |
213 | + mNome = (EditText) findViewById(R.id.txtNome); | |
214 | + mNome.setVisibility(View.GONE); | |
215 | + | |
216 | + mEmailView = (AutoCompleteTextView) findViewById(R.id.email); | |
217 | + | |
218 | + mPasswordView = (EditText) findViewById(R.id.password); | |
219 | + mPasswordView.setOnEditorActionListener(new TextView.OnEditorActionListener() { | |
220 | + @Override | |
221 | + public boolean onEditorAction(TextView textView, int id, KeyEvent keyEvent) { | |
222 | + if (id == R.id.login || id == EditorInfo.IME_NULL) { | |
223 | + attemptLogin(); | |
224 | + return true; | |
225 | + } | |
226 | + return false; | |
227 | + } | |
228 | + }); | |
229 | + } | |
230 | + | |
231 | + /** | |
232 | + * Verifica se esta logado | |
233 | + */ | |
234 | + private void verificaLogin() { | |
235 | + if(ParseUser.getCurrentUser()!=null){ | |
236 | + montaFormLogout(); | |
237 | + }else{ | |
238 | + montaFormLogin(); | |
239 | + } | |
240 | + } | |
241 | + | |
242 | + | |
243 | + /** | |
244 | + * Realiza o logout | |
245 | + */ | |
246 | + private void logout() { | |
247 | + | |
248 | + actionsCreator.logout(); | |
249 | + } | |
250 | + | |
251 | + /** | |
252 | + * Monta o form de login | |
253 | + */ | |
254 | + private void montaFormLogin() { | |
255 | + | |
256 | + mEmailView.setVisibility(View.VISIBLE); | |
257 | + mPasswordView.setVisibility(View.VISIBLE); | |
258 | + btnLogar.setVisibility(View.VISIBLE); | |
259 | + btnFazerCadastro.setVisibility(View.VISIBLE); | |
260 | + | |
261 | + mNome.setVisibility(View.GONE); | |
262 | + llTwitter.setVisibility(View.GONE); | |
263 | + btnFoto.setVisibility(View.INVISIBLE); | |
264 | + btnSalvar.setVisibility(View.GONE); | |
265 | + btnLogout.setVisibility(View.GONE); | |
266 | + } | |
267 | + | |
268 | + /** | |
269 | + * Monta o form para logout | |
270 | + */ | |
271 | + private void montaFormLogout() { | |
272 | + | |
273 | + mPasswordView.setVisibility(View.GONE); | |
274 | + btnLogar.setVisibility(View.GONE); | |
275 | + btnFazerCadastro.setVisibility(View.GONE); | |
276 | + | |
277 | + mEmailView.setVisibility(View.VISIBLE); | |
278 | + mNome.setVisibility(View.VISIBLE); | |
279 | + llTwitter.setVisibility(View.VISIBLE); | |
280 | + btnFoto.setVisibility(View.VISIBLE); | |
281 | + btnSalvar.setVisibility(View.VISIBLE); | |
282 | + btnLogout.setVisibility(View.VISIBLE); | |
283 | + showProgress(false); | |
284 | + | |
285 | + | |
286 | + } | |
287 | + | |
288 | + /** | |
289 | + * Realiza o login | |
290 | + */ | |
291 | + private void logar() { | |
292 | + if(validaCampos()){ | |
293 | + actionsCreator.logar(getInputUsuario(), getInputSenha()); | |
294 | + } | |
295 | + } | |
296 | + | |
297 | + private String getInputUsuario() { | |
298 | + return mEmailView.getText().toString(); | |
299 | + } | |
300 | + | |
301 | + private String getInputSenha() { | |
302 | + return mPasswordView.getText().toString(); | |
303 | + } | |
304 | + | |
305 | + /** | |
306 | + * Valida os campos do formulario (login e cadastro) | |
307 | + * @return | |
308 | + */ | |
309 | + private boolean validaCampos() { | |
310 | + // Reset errors. | |
311 | + mEmailView.setError(null); | |
312 | + mPasswordView.setError(null); | |
313 | + mNome.setError(null); | |
314 | + | |
315 | + boolean valido = true; | |
316 | + View focusView = null; | |
317 | + String email = mEmailView.getText().toString(); | |
318 | + String password = mPasswordView.getText().toString(); | |
319 | + String nome =mNome.getText().toString(); | |
320 | + | |
321 | + if (mNome.getVisibility() == View.VISIBLE){ | |
322 | + if (TextUtils.isEmpty(nome)) { | |
323 | + mNome.setError(getString(R.string.error_field_required)); | |
324 | + focusView = mNome; | |
325 | + valido = false; | |
326 | + } | |
327 | + } | |
328 | + | |
329 | + | |
330 | + // Checar senha foi preenchida | |
331 | + if (!TextUtils.isEmpty(password) && !isPasswordValid(password)) { | |
332 | + mPasswordView.setError(getString(R.string.error_invalid_password)); | |
333 | + focusView = mPasswordView; | |
334 | + valido = false; | |
335 | + } | |
336 | + | |
337 | + // checar se email eh valido | |
338 | + if (TextUtils.isEmpty(email)) { | |
339 | + mEmailView.setError(getString(R.string.error_field_required)); | |
340 | + focusView = mEmailView; | |
341 | + valido = false; | |
342 | + } else if (!isEmailValid(email)) { | |
343 | + mEmailView.setError(getString(R.string.error_invalid_email)); | |
344 | + focusView = mEmailView; | |
345 | + valido = false; | |
346 | + } | |
347 | + if(!valido){ | |
348 | + focusView.requestFocus(); | |
349 | + } | |
350 | + | |
351 | + return valido; | |
352 | + } | |
353 | + | |
354 | + | |
355 | + /** | |
356 | + * Atualiza a UI depois de uma action | |
357 | + * @param event | |
358 | + */ | |
359 | + @Subscribe | |
360 | + public void onTodoStoreChange(UserStore.UserStoreChangeEvent event) { | |
361 | + switch (event.getEvento()) { | |
362 | + case UserActions.USER_CADASTRO: | |
363 | + if(event.getStatus().equals("erro")){ | |
364 | + showProgress(false); | |
365 | + Snackbar.make(form, "Houve um erro ao fazer seu cadastro ", Snackbar.LENGTH_LONG) | |
366 | + .setAction("Action", null).show(); | |
367 | + } | |
368 | + break; | |
369 | + case UserActions.USER_LOGAR: | |
370 | + if(event.getStatus().equals("erro")){ | |
371 | + showProgress(false); | |
372 | + Snackbar.make(form, "Houve um erro ao fazer o login", Snackbar.LENGTH_LONG) | |
373 | + .setAction("Action", null).show(); | |
374 | + } | |
375 | + break; | |
376 | + } | |
377 | + updateUI(); | |
378 | + } | |
379 | + | |
380 | + @Override | |
381 | + protected void onResume() { | |
382 | + super.onResume(); | |
383 | + dispatcher.register(this); | |
384 | + dispatcher.register(userStore); | |
385 | + } | |
386 | + | |
387 | + @Override | |
388 | + protected void onPause() { | |
389 | + super.onPause(); | |
390 | + dispatcher.unregister(this); | |
391 | + dispatcher.unregister(userStore); | |
392 | + } | |
393 | + | |
394 | + | |
395 | + @Override | |
396 | + public void onActivityResult(int requestCode, int resultCode, Intent data) { | |
397 | + super.onActivityResult(requestCode, resultCode, data); | |
398 | + if (requestCode == PICK_IMAGE && resultCode == Activity.RESULT_OK) { | |
399 | + if (data == null) { | |
400 | + //Display an error | |
401 | + return; | |
402 | + } | |
403 | + try { | |
404 | + Uri selectedImage = data.getData(); | |
405 | + InputStream imageStream = getContentResolver().openInputStream(selectedImage); | |
406 | + Bitmap mImage = BitmapFactory.decodeStream(imageStream); | |
407 | + btnFoto.setImageBitmap(Bitmap.createScaledBitmap(mImage, 50, 50, false)); | |
408 | + } catch (FileNotFoundException e) { | |
409 | + e.printStackTrace(); | |
410 | + } | |
411 | + } | |
412 | + } | |
413 | + | |
414 | + private void showProgress(boolean b) { | |
415 | + if(b){ | |
416 | + mProgressView.setVisibility(View.VISIBLE); | |
417 | + | |
418 | + }else{ | |
419 | + mProgressView.setVisibility(View.GONE); | |
420 | + } | |
421 | + } | |
422 | + | |
423 | + | |
424 | + | |
425 | + | |
426 | + private void realizarCadastro() { | |
427 | + String email = mEmailView.getText().toString(); | |
428 | + String password = mPasswordView.getText().toString(); | |
429 | + String nome =mNome.getText().toString(); | |
430 | + //foto | |
431 | + Bitmap bitmap = ((BitmapDrawable)foto.getDrawable()).getBitmap(); | |
432 | + ByteArrayOutputStream stream = new ByteArrayOutputStream(); | |
433 | + bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream); | |
434 | + byte[] byteArray = stream.toByteArray(); | |
435 | + | |
436 | + //ParseFile | |
437 | + ParseFile mParseFile = new ParseFile("foto.png",byteArray); | |
438 | + | |
439 | + showProgress(true); | |
440 | + actionsCreator.cadastrar(nome, password, email,mParseFile); | |
441 | + } | |
442 | + | |
443 | + | |
444 | + | |
445 | + /** | |
446 | + * Set up the {@link android.app.ActionBar}, if the API is available. | |
447 | + */ | |
448 | +// @TargetApi(Build.VERSION_CODES.HONEYCOMB) | |
449 | + private void setupActionBar() { | |
450 | + Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); | |
451 | + | |
452 | + // toolbar.setNavigationIcon(R.drawable.ic_good); | |
453 | + toolbar.setTitle("Login"); | |
454 | + | |
455 | + toolbar.setTitleTextColor(getResources().getColor(R.color.md_white_1000)); | |
456 | + toolbar.setSubtitleTextColor(getResources().getColor(R.color.md_white_1000)); | |
457 | + setSupportActionBar(toolbar); | |
458 | + getSupportActionBar().setDisplayHomeAsUpEnabled(true); | |
459 | + } | |
460 | + | |
461 | + /** | |
462 | + * Realiza o login | |
463 | + */ | |
464 | + public void attemptLogin() { | |
465 | + showProgress(true); | |
466 | + logar(); | |
467 | + } | |
468 | + | |
469 | + | |
470 | + /** | |
471 | + * Verifica se o email eh valido | |
472 | + * @param email | |
473 | + * @return | |
474 | + */ | |
475 | + private boolean isEmailValid(String email) { | |
476 | + String ePattern = "^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$"; | |
477 | + java.util.regex.Pattern p = java.util.regex.Pattern.compile(ePattern); | |
478 | + java.util.regex.Matcher m = p.matcher(email); | |
479 | + return m.matches(); | |
480 | + } | |
481 | + | |
482 | + /** | |
483 | + * verifica se a senha eh valida | |
484 | + * @param password | |
485 | + * @return | |
486 | + */ | |
487 | + private boolean isPasswordValid(String password) { | |
488 | + return password.length() > 4; | |
489 | + } | |
490 | + | |
491 | + | |
492 | + /** | |
493 | + * Atualiza a UI | |
494 | + */ | |
495 | + private void updateUI() { | |
496 | + showProgress(false); | |
497 | + verificaLogin(); | |
498 | + } | |
499 | + | |
500 | + | |
501 | + | |
502 | + | |
503 | +} | |
504 | + | ... | ... |
app/src/main/java/com/monitorabrasil/participacidadao/view/MainActivity.java
... | ... | @@ -75,7 +75,7 @@ public class MainActivity extends AppCompatActivity implements HomeFragment.OnFr |
75 | 75 | .withOnAccountHeaderListener(new AccountHeader.OnAccountHeaderListener() { |
76 | 76 | @Override |
77 | 77 | public boolean onProfileChanged(View view, IProfile profile, boolean currentProfile) { |
78 | - startActivity(new Intent(getApplicationContext(), Login2Activity.class)); | |
78 | + startActivity(new Intent(getApplicationContext(), LoginActivity.class)); | |
79 | 79 | |
80 | 80 | return false; |
81 | 81 | } | ... | ... |
app/src/main/res/layout/activity_login.xml
1 | 1 | <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
2 | 2 | xmlns:tools="http://schemas.android.com/tools" |
3 | 3 | xmlns:app="http://schemas.android.com/apk/res-auto" |
4 | - xmlns:fab="http://schemas.android.com/apk/res-auto" | |
5 | 4 | android:layout_width="match_parent" |
6 | 5 | android:layout_height="match_parent" |
7 | 6 | android:background="@color/grey" |
... | ... | @@ -18,26 +17,40 @@ |
18 | 17 | android:layout_alignParentLeft="true" |
19 | 18 | android:background="?attr/colorPrimary" |
20 | 19 | app:popupTheme="@style/ThemeOverlay.AppCompat.Dark" /> |
21 | - | |
22 | 20 | <!-- Login progress --> |
23 | - <ProgressBar android:id="@+id/login_progress" style="?android:attr/progressBarStyleLarge" | |
24 | - android:layout_width="wrap_content" android:layout_height="wrap_content" | |
25 | - android:layout_marginBottom="8dp" android:visibility="gone" | |
26 | - android:layout_gravity="center_horizontal" /> | |
27 | 21 | |
28 | - <ScrollView android:id="@+id/login_form" android:layout_width="match_parent" | |
22 | + <ScrollView | |
23 | + android:layout_width="match_parent" | |
29 | 24 | android:layout_height="match_parent"> |
30 | 25 | |
31 | - <LinearLayout android:id="@+id/email_login_form" android:layout_width="match_parent" | |
32 | - android:layout_height="wrap_content" android:orientation="vertical"> | |
26 | + <LinearLayout | |
27 | + android:id="@+id/email_login_form" | |
28 | + android:layout_width="match_parent" | |
29 | + android:layout_height="wrap_content" | |
30 | + android:orientation="vertical" | |
31 | + android:paddingLeft="10dp" | |
32 | + android:paddingRight="10dp"> | |
33 | + <ProgressBar | |
34 | + android:id="@+id/login_progress" | |
35 | + style="?android:attr/progressBarStyleLarge" | |
36 | + android:layout_width="wrap_content" | |
37 | + android:layout_height="wrap_content" | |
38 | + android:layout_marginBottom="8dp" | |
39 | + android:visibility="gone" | |
40 | + android:layout_gravity="center_horizontal" /> | |
41 | + | |
42 | + <!--FOTO--> | |
33 | 43 | <ImageButton |
34 | 44 | android:layout_width="50dp" |
35 | 45 | android:paddingTop="5dp" |
36 | 46 | android:layout_height="50dp" |
37 | - android:visibility="gone" | |
47 | + android:visibility="visible" | |
38 | 48 | android:layout_gravity="center" |
39 | 49 | android:background="@drawable/person_1" |
40 | - android:id="@+id/btnFoto"/> | |
50 | + android:id="@+id/btnFoto" | |
51 | + android:layout_marginTop="10dp" /> | |
52 | + | |
53 | + <!--NOME - SOMENTE PARA CADASTRO NOVO OU QUANDO LOGADO--> | |
41 | 54 | <android.support.design.widget.TextInputLayout |
42 | 55 | android:layout_width="match_parent" |
43 | 56 | android:layout_height="wrap_content"> |
... | ... | @@ -48,85 +61,97 @@ |
48 | 61 | android:id="@+id/txtNome" /> |
49 | 62 | </android.support.design.widget.TextInputLayout> |
50 | 63 | |
64 | + <!--EMAIL--> | |
51 | 65 | <android.support.design.widget.TextInputLayout |
52 | 66 | android:layout_width="match_parent" |
53 | 67 | android:layout_height="wrap_content"> |
54 | - <AutoCompleteTextView android:id="@+id/email" android:layout_width="match_parent" | |
55 | - android:layout_height="wrap_content" android:hint="@string/prompt_email" | |
56 | - android:inputType="textEmailAddress" android:maxLines="1" | |
57 | - android:singleLine="true" /> | |
58 | - </android.support.design.widget.TextInputLayout> | |
68 | + <AutoCompleteTextView | |
69 | + android:id="@+id/email" | |
70 | + android:layout_width="match_parent" | |
71 | + android:layout_height="wrap_content" | |
72 | + android:hint="@string/prompt_email" | |
73 | + android:inputType="textEmailAddress" | |
74 | + android:maxLines="1" | |
75 | + android:singleLine="true" /> | |
76 | + </android.support.design.widget.TextInputLayout> | |
77 | + | |
78 | + <!--SENHA--> | |
59 | 79 | <android.support.design.widget.TextInputLayout |
60 | 80 | android:layout_width="match_parent" |
61 | 81 | android:layout_height="wrap_content"> |
62 | - <EditText android:id="@+id/password" android:layout_width="match_parent" | |
63 | - android:layout_height="wrap_content" android:hint="@string/prompt_password" | |
64 | - android:imeActionId="@+id/login" | |
65 | - android:imeActionLabel="@string/action_sign_in_short" | |
66 | - android:imeOptions="actionUnspecified" android:inputType="textPassword" | |
67 | - android:maxLines="1" android:singleLine="true" /> | |
82 | + <EditText | |
83 | + android:id="@+id/password" | |
84 | + android:layout_width="match_parent" | |
85 | + android:layout_height="wrap_content" | |
86 | + android:hint="@string/prompt_password" | |
87 | + android:imeActionLabel="@string/action_sign_in_short" | |
88 | + android:inputType="textPassword" | |
89 | + android:maxLines="1" | |
90 | + android:singleLine="true" /> | |
68 | 91 | </android.support.design.widget.TextInputLayout> |
69 | 92 | |
70 | - <Button android:id="@+id/email_sign_in_button" style="?android:textAppearanceSmall" | |
71 | - android:layout_width="match_parent" android:layout_height="wrap_content" | |
72 | - android:layout_marginTop="16dp" android:text="@string/action_sign_in" | |
73 | - android:textStyle="bold" /> | |
93 | + <!--LOGIN BUTTON--> | |
94 | + <LinearLayout | |
95 | + android:orientation="horizontal" | |
96 | + android:layout_width="match_parent" | |
97 | + android:layout_height="wrap_content" | |
98 | + android:layout_marginTop="4dp" | |
99 | + android:id="@+id/llTwitter"> | |
74 | 100 | |
75 | - <Button android:id="@+id/login_twitter" style="?android:textAppearanceSmall" | |
76 | - android:layout_width="match_parent" android:layout_height="wrap_content" | |
77 | - android:layout_marginTop="16dp" android:text="@string/login_twitter" | |
78 | - android:textStyle="bold" /> | |
101 | + <TextView | |
102 | + android:layout_width="wrap_content" | |
103 | + android:layout_height="wrap_content" | |
104 | + android:text="Twitter" | |
105 | + android:id="@+id/textView7" | |
106 | + android:textSize="16dp" /> | |
79 | 107 | |
80 | - <Button android:id="@+id/fazer_cadastro" style="?android:textAppearanceSmall" | |
81 | - android:layout_width="match_parent" android:layout_height="wrap_content" | |
82 | - android:layout_marginTop="16dp" android:text="@string/fazer_cadastro" | |
108 | + <Switch | |
109 | + android:layout_width="wrap_content" | |
110 | + android:layout_height="wrap_content" | |
111 | + android:id="@+id/swTwitter" | |
112 | + android:checked="false" | |
113 | + android:paddingLeft="10dp" /> | |
114 | + </LinearLayout> | |
115 | + | |
116 | + <Button | |
117 | + android:id="@+id/email_sign_in_button" | |
118 | + style="?android:textAppearanceSmall" | |
119 | + android:layout_width="match_parent" | |
120 | + android:layout_height="wrap_content" | |
121 | + android:layout_marginTop="16dp" | |
122 | + android:text="@string/action_sign_in" | |
123 | + android:textStyle="bold" /> | |
124 | + <!--TWITTER BUTTON--> | |
125 | + <!--CADASTRO BUTTON--> | |
126 | + <Button android:id="@+id/fazer_cadastro" | |
127 | + style="?android:textAppearanceSmall" | |
128 | + android:layout_width="match_parent" | |
129 | + android:layout_height="wrap_content" | |
130 | + android:layout_marginTop="16dp" | |
131 | + android:text="@string/fazer_cadastro" | |
132 | + android:textStyle="bold" /> | |
133 | + <!--ATUALIZAR BUTTON--> | |
134 | + <Button | |
135 | + style="?android:textAppearanceSmall" | |
136 | + android:id="@+id/btnSalvar" | |
137 | + android:layout_width="match_parent" | |
138 | + android:layout_height="wrap_content" | |
139 | + android:layout_marginTop="16dp" | |
140 | + android:text="Salvar" | |
141 | + android:textStyle="bold" /> | |
142 | + <!--LOGOUT BUTTON--> | |
143 | + <Button | |
144 | + style="?android:textAppearanceSmall" | |
145 | + android:id="@+id/btnLogout" | |
146 | + android:layout_width="match_parent" | |
147 | + android:layout_height="wrap_content" | |
148 | + android:layout_marginTop="8dp" | |
149 | + android:text="@string/logout" | |
83 | 150 | android:textStyle="bold" /> |
84 | - | |
85 | - | |
86 | 151 | |
87 | 152 | </LinearLayout> |
88 | - | |
89 | - | |
90 | 153 | </ScrollView> |
91 | - <ScrollView android:id="@+id/logout_form" android:layout_width="match_parent" | |
92 | - android:layout_height="match_parent"> | |
93 | - <LinearLayout android:id="@+id/email_logout_form" android:layout_width="match_parent" | |
94 | - android:layout_height="wrap_content" android:orientation="vertical"> | |
95 | - | |
96 | - <ImageView | |
97 | - android:layout_width="100dp" | |
98 | - android:layout_height="100dp" | |
99 | - android:id="@+id/foto" | |
100 | - android:layout_gravity="center_horizontal" | |
101 | - android:layout_marginTop="20dp" /> | |
102 | - | |
103 | - <TextView | |
104 | - android:layout_width="wrap_content" | |
105 | - android:layout_height="wrap_content" | |
106 | - android:textAppearance="?android:attr/textAppearanceMedium" | |
107 | - android:text="Medium Text" | |
108 | - android:id="@+id/lblNome" | |
109 | - android:layout_gravity="center_horizontal" /> | |
110 | - <TextView | |
111 | - android:layout_width="wrap_content" | |
112 | - android:layout_height="wrap_content" | |
113 | - android:textAppearance="?android:attr/textAppearanceMedium" | |
114 | - android:text="Medium Text" | |
115 | - android:id="@+id/lblEmail" | |
116 | - android:layout_gravity="center_horizontal" /> | |
117 | - <Button | |
118 | - style="?android:textAppearanceSmall" | |
119 | - android:id="@+id/btnLogout" | |
120 | - android:layout_width="match_parent" | |
121 | - android:layout_height="wrap_content" | |
122 | - android:layout_marginTop="16dp" | |
123 | - android:text="@string/logout" | |
124 | - android:textStyle="bold" /> | |
125 | - | |
126 | 154 | |
127 | 155 | |
128 | - </LinearLayout> | |
129 | - </ScrollView> | |
130 | - | |
131 | 156 | </LinearLayout> |
132 | 157 | ... | ... |
app/src/main/res/layout/activity_login2.xml
... | ... | @@ -6,7 +6,7 @@ |
6 | 6 | android:layout_height="match_parent" |
7 | 7 | android:background="@color/grey" |
8 | 8 | android:orientation="vertical" |
9 | - tools:context="com.monitorabrasil.participacidadao.view.Login2Activity" | |
9 | + tools:context="com.monitorabrasil.participacidadao.view.LoginActivity" | |
10 | 10 | android:paddingTop="8dp"> |
11 | 11 | |
12 | 12 | <android.support.v7.widget.Toolbar | ... | ... |
app/src/main/res/menu/menu_login2.xml
1 | 1 | <menu xmlns:android="http://schemas.android.com/apk/res/android" |
2 | 2 | xmlns:app="http://schemas.android.com/apk/res-auto" |
3 | 3 | xmlns:tools="http://schemas.android.com/tools" |
4 | - tools:context="com.monitorabrasil.participacidadao.view.Login2Activity"> | |
4 | + tools:context="com.monitorabrasil.participacidadao.view.LoginActivity"> | |
5 | 5 | <item android:id="@+id/action_settings" android:title="@string/action_settings" |
6 | 6 | android:orderInCategory="100" app:showAsAction="never" /> |
7 | 7 | </menu> | ... | ... |