@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); getSupportActionBar().hide(); nameTxt = (EditText) findViewById(R.id.nameEdit); Button loginBtt = (Button) findViewById(R.id.loginButton); loginBtt.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { String sname = nameTxt.getText().toString().trim(); if (sname.equals("")) { Toast toast = Toast.makeText(LoginActivity.this, R.string.fill, Toast.LENGTH_LONG); toast.show(); return; } login(sname); } }); // check if there's a user already logged try { User user = CellMappingApp.getUser(); startMainActivity(); } catch (UnauthorizeException e) { CellMappingApp.logout(); Log.i(TAG_NAME, "session logout"); } }
private void login(final String sname) { // get phone guid final String guid = Utils.getDeviceUUID(LoginActivity.this); final String carrier = Utils.getCarrier(LoginActivity.this); User user = new User(sname, guid); dialog = ProgressDialog.show( LoginActivity.this, "", getResources().getString(R.string.loginin), true); dialog.setCancelable(true); CellMappingApp.getApiController() .login( LoginActivity.this, user, new LoginCallback() { @Override public void onSuccess(String sid) { dialog.dismiss(); User user = new User(sname, sid, guid); user.setCarrier(carrier); saveUser(user); } @Override public void onError(int error) { dialog.dismiss(); Utils.Toast(LoginActivity.this, error); } @Override public void onError(String message) {} }); }
private void saveUser(User user) { // create persistent user CellMappingApp.setUser(user); startMainActivity(); }