@Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { if (!mIsFired) { mIsFired = true; Date date = DateUtils.getCalendar(year, monthOfYear, dayOfMonth); Calendar calendar = Calendar.getInstance(); calendar.setTime(date); Calendar currentCalendar = Calendar.getInstance(); if (currentCalendar.before(calendar)) { mWeddingDateEditText.setText( DateUtils.getDateText(DateUtils.DATE_FORMAT_WEDDING_DATE, date)); } else { ((MainActivity) getActivity()) .showMsgDlg(getString(R.string.str_invaild_wedding_date)); } Message message = new Message(); message.obj = UserAccountFragment.this; message.what = HANDLE_MSG_ID_WEDDING_DATE_CLEAR; sEventHandler.sendMessageDelayed(message, 300); } }
@Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { Calendar calendar = Calendar.getInstance(); String weddingDate = PlannerApplication.getUserProfile().getWeddingDate(); if (!PlannerApplication.isEmptyOrNull(weddingDate)) { try { calendar.setTime( DateUtils.getDate(DateUtils.DATE_FORMAT_WEDDING_DATE, weddingDate)); } catch (ParseException e) { getLogger().debug(e.getMessage()); } } mYear = calendar.get(Calendar.YEAR); mMonth = calendar.get(Calendar.MONTH); mDay = calendar.get(Calendar.DAY_OF_MONTH); PlannerEvent.Screen(PlannerEvent.EVENT_SCREEN_DATE_SELECTION_MENU); WeddingDatePickerDialog mWeddingDateDatePicker = new WeddingDatePickerDialog( getActivity(), mWeddingDateSetListener, mYear, mMonth, mDay); mWeddingDateDatePicker.setButton( DialogInterface.BUTTON_POSITIVE, getString(R.string.date_picker_done), mWeddingDateDatePicker); mWeddingDateDatePicker.setOnDismissListener( new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { mIsFired = false; Message message = new Message(); message.obj = UserAccountFragment.this; message.what = HANDLE_MSG_ID_WEDDING_DATE_CLEAR; sEventHandler.sendMessageDelayed(message, 300); } }); mWeddingDateDatePicker.setOnCancelListener( new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { Message message = new Message(); message.obj = UserAccountFragment.this; message.what = HANDLE_MSG_ID_WEDDING_DATE_CLEAR; sEventHandler.sendMessageDelayed(message, 300); } }); mWeddingDateDatePicker.show(); } }
private UserProfile getUpdateJson() { String firstname = mFirstnameEditText.getText().toString().trim(); String lastName = mLastnameEditText.getText().toString(); String fianceFirstName = mFianceFirstnameEditText.getText().toString().trim(); String fianceLastName = mFianceLastnameEditText.getText().toString(); String street = mHomeaddrEditText.getText().toString(); String homeCityAndState = mCityStateEditText.getText().toString(); String[] homeCSArray = parseLocation(homeCityAndState); String city = homeCSArray[0]; String state = homeCSArray[1]; String zip = mZipEditText.getText().toString(); String id = mUserProfile.getMemberId(); String phone = mPhoneEditText.getText().toString(); String budget = mWeddingbudgetEditText.getText().toString(); budget = PlannerApplication.isEmptyOrNull(budget) ? "0" : budget.replace("$", "").replace(",", ""); String weddingDate = mWeddingDateEditText.getText().toString(); String wedCityAndState = mWeddingLocationEditText.getText().toString(); String[] casArray = parseLocation(wedCityAndState); String wedCity = casArray[0]; String wedState = casArray[1]; mNewUser = new UserProfile(); mNewUser.setMemberId(mUserProfile.getMemberId()); mNewUser.setPath(mUserProfile.getPath()); mNewUser.setEmail(mUserProfile.getEmail()); mNewUser.setUsername(mUserProfile.getUsername()); mNewUser.setFirstName(firstname); mNewUser.setLastName(lastName); if (PlannerApplication.getInstance().getCouplePhotoModel() != null && !PlannerApplication.isEmptyOrNull( PlannerApplication.getInstance().getCouplePhotoModel().get_id())) { mNewUser.setCouplePhotoId(PlannerApplication.getInstance().getCouplePhotoModel().get_id()); if (!PlannerApplication.isEmptyOrNull( PlannerApplication.getUserProfile().getCouplePhotoUrl())) { String url = PlannerApplication.getUserProfile() .getCouplePhotoUrl() .substring( 0, PlannerApplication.getUserProfile().getCouplePhotoUrl().lastIndexOf("/") + 1); mNewUser.setCouplePhotoUrl( String.format( "%s%s", url, PlannerApplication.getInstance().getCouplePhotoModel().get_id())); } } else if (!PlannerApplication.isEmptyOrNull(mUserProfile.getCouplePhotoId())) { mNewUser.setCouplePhotoId(mUserProfile.getCouplePhotoId()); mNewUser.setCouplePhotoUrl(mUserProfile.getCouplePhotoUrl()); } mNewUser.setFianceFirstName(fianceFirstName); mNewUser.setFianceLastName(fianceLastName); mNewUser.setHomeAddr(street); mNewUser.setCityState( (TextUtils.isEmpty(city) || TextUtils.isEmpty(state)) ? "" : (city + ", " + (state.trim()))); mNewUser.setZipCode(PlannerApplication.setDefaultValueIfNeed(zip)); mNewUser.setPhoneNum(phone); mNewUser.setWeddingDate( (PlannerApplication.isEmptyOrNull(weddingDate)) ? getDefaultWeddingDate() : weddingDate); mNewUser.setWeddingBudget(budget); mNewUser.setWeddingLocation( (TextUtils.isEmpty(wedCity) || TextUtils.isEmpty(wedState)) ? "" : (wedCity + ", " + (wedState.trim()))); mNewUser.setToken(mUserProfile.getToken()); mNewUser.setSessionToken(mUserProfile.getSessionToken()); JSONObject rootJson = null; try { rootJson = new JSONObject(); JSONObject memberJson = new JSONObject(); memberJson.put("firstName", firstname); memberJson.put("lastName", lastName); memberJson.put("fianceFirstName", fianceFirstName); memberJson.put("fianceLastName", fianceLastName); JSONObject homeLocationJson = new JSONObject(); homeLocationJson.put("street", street); homeLocationJson.put("street2", ""); homeLocationJson.put("state", state == null ? "" : state.trim()); homeLocationJson.put("city", city); homeLocationJson.put("zip", zip); memberJson.put("homeLocation", homeLocationJson); memberJson.put("id", id); memberJson.put("phone", phone); memberJson.put("weddingBudget", budget.replaceAll(",", "")); if (!TextUtils.isEmpty(weddingDate)) { try { weddingDate = DateUtils.getDateText( DateUtils.DATE_FORMAT_WEDDING_DATE_API_POST, DateUtils.getDate(DateUtils.DATE_FORMAT_WEDDING_DATE, weddingDate)); } catch (ParseException pe) { getLogger().error(pe.getMessage()); } catch (IllegalArgumentException e) { getLogger().error(e.getMessage()); } } else { weddingDate = DateFormat.format(UPDATE_DATE_FORMAT, getDefaultWeddingDateToDate()).toString(); } memberJson.put("weddingDate", weddingDate); JSONObject wedLocationJson = new JSONObject(); wedLocationJson.put("city", wedCity); wedLocationJson.put("state", wedState == null ? "" : wedState.trim()); memberJson.put("weddingLocation", wedLocationJson); rootJson.put("member", memberJson); } catch (JSONException e) { getLogger().error(e.getMessage()); } mNewUser.setJsonToString(rootJson.toString()); return mNewUser; }