@Override public void handleMessage(Message msg) { super.handleMessage(msg); final MainFragment theFragment = mFragment.get(); JSONObject response = MyApplication.updateResponse; try { MyApplication.updateResponse = null; // Dialog materialDialog = new Dialog(theFragment.getActivity(), // "新版本下载", "版本号:" // + response.getString("version") + "\n更新说明: " // + response.getString("description")); // materialDialog.setOnAcceptButtonClickListener(new // View.OnClickListener() { // // @Override // public void onClick(View v) { // Intent intent = new Intent(); // intent.setAction("android.intent.action.VIEW"); // Uri content_url = Uri.parse(ApiUrl.BABIETA_DOWNLOAD); // intent.setData(content_url); // theFragment.startActivity(intent); // } // }); // materialDialog.addCancelButton("取消", new // View.OnClickListener() { // // @Override // public void onClick(View v) { // // } // }); // materialDialog.show(); SnackBar snackbar = new SnackBar( theFragment.getActivity(), "检测到新版本\n版本号:" + response.getString("version") + "\n更新说明: " + response.getString("description"), "下载", new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(); intent.setAction("android.intent.action.VIEW"); Uri content_url = Uri.parse(ApiUrl.BABIETA_DOWNLOAD); intent.setData(content_url); theFragment.startActivity(intent); } }); snackbar.setDismissTimer(5000); snackbar.show(); } catch (JSONException e) { e.printStackTrace(); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); AutologinValidator(); if (!isConnected()) { SnackBar snackBar = new SnackBar(LoginActivity.this, "You don't have internet connection"); snackBar.show(); } signIn = (TextView) findViewById(R.id.sigInTextView); signUp = (TextView) findViewById(R.id.signUpTextView); name = (EditText) findViewById(R.id.nameEditText); email = (EditText) findViewById(R.id.emailEditText); password = (EditText) findViewById(R.id.passwordEditText); register = (ButtonRectangle) findViewById(R.id.registerButton); progress = (ProgressBarCircularIndeterminate) findViewById(R.id.progressBarCircularIndeterminate); progress.setVisibility(View.INVISIBLE); register.setVisibility(View.INVISIBLE); signUp.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { name.setFocusable(true); signUp.setTextColor(Color.WHITE); signIn.setTextColor(Color.GRAY); name.setVisibility(View.VISIBLE); register.setVisibility(View.VISIBLE); btnIngresar.setVisibility(View.INVISIBLE); name.requestFocus(); } }); signIn.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { signIn.setTextColor(Color.WHITE); signUp.setTextColor(Color.GRAY); name.setVisibility(View.INVISIBLE); register.setVisibility(View.INVISIBLE); btnIngresar.setVisibility(View.VISIBLE); } }); btnIngresar = (ButtonRectangle) findViewById(R.id.loginButton); btnIngresar.setEnabled(true); btnIngresar.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { userGet = new UserGet( new AsyncResponseUser() { @Override public void getUserRest(String response) { statusCode = response; try { btnIngresar.setEnabled(false); JSONObject jsonObject = new JSONObject(statusCode); id = jsonObject.get("id").toString(); userName = jsonObject.get("name").toString(); sqliteEmail = jsonObject.getString("mail").toString(); sqlitePassword = jsonObject.getString("password").toString(); progress.setVisibility(View.VISIBLE); } catch (JSONException e) { e.printStackTrace(); Toast.makeText( getBaseContext(), "Failure in login. Try again.", Toast.LENGTH_SHORT) .show(); btnIngresar.setEnabled(true); progress.setEnabled(false); } finally { System.out.println("Entro a finally"); if ("".equals(statusCode)) { statusCode = "0"; System.out.println("Entro a if"); } } } }); userGet.execute( url + "/user" + "?mail=" + email.getText().toString() + "&password="******"Respuesta---- " + statusCode); if ("0".equals(statusCode) || statusCode == null) { try { throw new SocketTimeoutException(); } catch (SocketTimeoutException e) { SnackBar snackBar = new SnackBar(LoginActivity.this, "Server is down!"); snackBar.show(); } } else { if ("404".equals(statusCode) || "500".equals(statusCode)) { Toast.makeText( getApplicationContext(), "Email or password are incorrect.", Toast.LENGTH_LONG) .show(); } else { Cursor cursor; cursor = sqLiteDatabase.query( "usuario", new String[] {"_id"}, "_id=?", new String[] {id.toString()}, null, null, null); if (cursor.moveToFirst()) { do { try { ContentValues contentValues = new ContentValues(); contentValues.put("session", true); sqLiteDatabase.update( "usuario", contentValues, "_id=" + Integer.valueOf(id), null); Log.i("Login", "User updated to true"); break; } catch (NumberFormatException e) { e.printStackTrace(); Log.e("Login", "User updated to true FAILED"); } } while (cursor.moveToNext()); } else { try { ContentValues contentValues = new ContentValues(); contentValues.put("_id", Integer.valueOf(id)); contentValues.put("nombre", userName); contentValues.put("email", sqliteEmail); contentValues.put("contrasena", sqlitePassword); contentValues.put("session", true); sqLiteDatabase.insert("usuario", null, contentValues); Log.i("Login", "User inserted"); } catch (NumberFormatException e) { e.printStackTrace(); Log.e("Login", "User inserted FAILED"); } } cursor.close(); try { Intent intent = new Intent(LoginActivity.this, MeasureActivity.class); intent.putExtra("id", Integer.valueOf(id)); intent.putExtra("mail", email.getText().toString()); intent.putExtra("name", userName); startActivity(intent); finish(); } catch (NumberFormatException e) { e.printStackTrace(); } } } } }, 4500); } }); register.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { try { new HttpAsyncTask().execute(url + "/user"); signIn.setTextColor(Color.WHITE); signUp.setTextColor(Color.GRAY); name.setVisibility(View.INVISIBLE); register.setVisibility(View.INVISIBLE); btnIngresar.setVisibility(View.VISIBLE); } catch (Exception e) { e.printStackTrace(); } } }); }