List of usage examples for android.widget LinearLayout getParent
public final ViewParent getParent()
From source file:fiskinfoo.no.sintef.fiskinfoo.Implementation.UtilityOnClickListeners.java
public OnClickListener getToolEntryEditDialogOnClickListener(final Activity activity, final FragmentManager fragmentManager, final GpsLocationTracker locationTracker, final ToolEntry toolEntry, final User user) { return new OnClickListener() { @Override/*from w ww .ja va2 s. c o m*/ public void onClick(final View editButton) { final DialogInterface dialogInterface = new UtilityDialogs(); final Dialog dialog = dialogInterface.getDialog(editButton.getContext(), R.layout.dialog_register_new_tool, R.string.edit_tool); ((Button) dialog.findViewById(R.id.dialog_register_tool_create_tool_button)) .setText(editButton.getContext().getString(R.string.save)); final Button updateButton = (Button) dialog .findViewById(R.id.dialog_register_tool_create_tool_button); final Button cancelButton = (Button) dialog.findViewById(R.id.dialog_register_tool_cancel_button); final LinearLayout fieldContainer = (LinearLayout) dialog .findViewById(R.id.dialog_register_tool_main_container); final DatePickerRow setupDateRow = new DatePickerRow(editButton.getContext(), editButton.getContext().getString(R.string.tool_set_date_colon), fragmentManager); final TimePickerRow setupTimeRow = new TimePickerRow(editButton.getContext(), editButton.getContext().getString(R.string.tool_set_time_colon), fragmentManager, false); final CoordinatesRow coordinatesRow = new CoordinatesRow(activity, locationTracker); final SpinnerRow toolRow = new SpinnerRow(editButton.getContext(), editButton.getContext().getString(R.string.tool_type), ToolType.getValues()); final CheckBoxRow toolRemovedRow = new CheckBoxRow(editButton.getContext(), editButton.getContext().getString(R.string.tool_removed_row_text), true); final EditTextRow commentRow = new EditTextRow(editButton.getContext(), editButton.getContext().getString(R.string.comment_field_header), editButton.getContext().getString(R.string.comment_field_hint)); final EditTextRow contactPersonNameRow = new EditTextRow(editButton.getContext(), editButton.getContext().getString(R.string.contact_person_name), editButton.getContext().getString(R.string.contact_person_name)); final EditTextRow contactPersonPhoneRow = new EditTextRow(editButton.getContext(), editButton.getContext().getString(R.string.contact_person_phone), editButton.getContext().getString(R.string.contact_person_phone)); final EditTextRow contactPersonEmailRow = new EditTextRow(editButton.getContext(), editButton.getContext().getString(R.string.contact_person_email), editButton.getContext().getString(R.string.contact_person_email)); final EditTextRow vesselNameRow = new EditTextRow(editButton.getContext(), editButton.getContext().getString(R.string.vessel_name), editButton.getContext().getString(R.string.vessel_name)); final EditTextRow vesselPhoneNumberRow = new EditTextRow(editButton.getContext(), editButton.getContext().getString(R.string.vessel_phone_number), editButton.getContext().getString(R.string.vessel_phone_number)); final EditTextRow vesselIrcsNumberRow = new EditTextRow(editButton.getContext(), editButton.getContext().getString(R.string.ircs_number), editButton.getContext().getString(R.string.ircs_number)); final EditTextRow vesselMmsiNumberRow = new EditTextRow(editButton.getContext(), editButton.getContext().getString(R.string.mmsi_number), editButton.getContext().getString(R.string.mmsi_number)); final EditTextRow vesselImoNumberRow = new EditTextRow(editButton.getContext(), editButton.getContext().getString(R.string.imo_number), editButton.getContext().getString(R.string.imo_number)); final EditTextRow vesselRegistrationNumberRow = new EditTextRow(editButton.getContext(), editButton.getContext().getString(R.string.registration_number), editButton.getContext().getString(R.string.registration_number)); final ErrorRow errorRow = new ErrorRow(editButton.getContext(), editButton.getContext().getString(R.string.error_minimum_identification_factors_not_met), false); final SimpleDateFormat sdfMilliSeconds = new SimpleDateFormat( editButton.getContext().getString(R.string.datetime_format_yyyy_mm_dd_t_hh_mm_ss_sss), Locale.getDefault()); final SimpleDateFormat sdf = new SimpleDateFormat( editButton.getContext().getString(R.string.datetime_format_yyyy_mm_dd_t_hh_mm_ss), Locale.getDefault()); View.OnClickListener deleteButtonRowOnClickListener = new OnClickListener() { @Override public void onClick(View v) { String confirmationText; switch (toolEntry.getToolStatus()) { case STATUS_RECEIVED: case STATUS_SENT_UNCONFIRMED: confirmationText = v.getContext() .getString(R.string.confirm_registered_tool_deletion_text); break; case STATUS_UNSENT: case STATUS_UNREPORTED: confirmationText = v.getContext().getString(R.string.confirm_tool_deletion_text); break; case STATUS_REMOVED_UNCONFIRMED: confirmationText = v.getContext() .getString(R.string.confirm_registered_tool_with_local_changes_deletion_text); break; default: confirmationText = v.getContext() .getString(R.string.confirm_tool_deletion_text_general); break; } final Dialog deleteToolDialog = dialogInterface.getConfirmationDialog(v.getContext(), v.getContext().getString(R.string.delete_tool), confirmationText, v.getContext().getString(R.string.delete)); Button confirmToolDeletionButton = (Button) deleteToolDialog .findViewById(R.id.dialog_bottom_confirm_bottom); confirmToolDeletionButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { View parentView = (View) ((editButton.getParent()).getParent()); ((LinearLayout) parentView).removeView(((View) (editButton.getParent()))); Toast.makeText(v.getContext(), v.getContext().getString(R.string.tool_deleted), Toast.LENGTH_LONG).show(); user.getToolLog().removeTool(toolEntry.getSetupDate(), toolEntry.getToolLogId()); user.writeToSharedPref(v.getContext()); deleteToolDialog.dismiss(); dialog.dismiss(); } }); deleteToolDialog.show(); } }; View.OnClickListener archiveToolOnClickListener = new OnClickListener() { @Override public void onClick(View v) { String confirmationText; switch (toolEntry.getToolStatus()) { case STATUS_RECEIVED: confirmationText = v.getContext().getString(R.string.confirm_registered_tool_archiving); break; case STATUS_UNSENT: if (!toolEntry.getId().isEmpty()) { confirmationText = v.getContext().getString(R.string.confirm_tool_archiving_text); } else { confirmationText = v.getContext().getString( R.string.confirm_registered_tool_with_local_changes_archiving_text); } break; default: confirmationText = v.getContext() .getString(R.string.confirm_tool_archiving_text_general); break; } final Dialog archiveDialog = dialogInterface.getConfirmationDialog(v.getContext(), v.getContext().getString(R.string.archive_tool), confirmationText, v.getContext().getString(R.string.archive)); Button confirmToolArchiveButton = (Button) archiveDialog .findViewById(R.id.dialog_bottom_confirm_bottom); confirmToolArchiveButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { View parentView = (View) ((editButton.getParent()).getParent()).getParent(); ((LinearLayout) parentView) .removeView(((View) (editButton.getParent()).getParent())); Toast.makeText(v.getContext(), v.getContext().getString(R.string.tool_archived), Toast.LENGTH_LONG).show(); toolEntry.setToolStatus(ToolEntryStatus.STATUS_REMOVED); user.writeToSharedPref(v.getContext()); archiveDialog.dismiss(); dialog.dismiss(); } }); archiveDialog.show(); } }; ActionRow archiveRow = new ActionRow(editButton.getContext(), editButton.getContext().getString(R.string.archive_tool), R.drawable.ic_archive_black_24dp, archiveToolOnClickListener); ActionRow deleteRow = new ActionRow(editButton.getContext(), editButton.getContext().getString(R.string.delete_tool), R.drawable.ic_delete_black_24dp, deleteButtonRowOnClickListener); commentRow.setInputType(InputType.TYPE_CLASS_TEXT); commentRow.setHelpText(editButton.getContext().getString(R.string.comment_help_description)); vesselNameRow.setInputType(InputType.TYPE_CLASS_TEXT); contactPersonPhoneRow .setHelpText(editButton.getContext().getString(R.string.vessel_name_help_description)); vesselPhoneNumberRow.setInputType(InputType.TYPE_CLASS_PHONE); vesselIrcsNumberRow.setInputType(InputType.TYPE_CLASS_TEXT); vesselIrcsNumberRow.setInputFilters(new InputFilter[] { new InputFilter.LengthFilter( editButton.getContext().getResources().getInteger(R.integer.input_length_ircs)), new InputFilter.AllCaps() }); vesselIrcsNumberRow.setHelpText(editButton.getContext().getString(R.string.ircs_help_description)); vesselMmsiNumberRow.setInputType(InputType.TYPE_CLASS_NUMBER); vesselMmsiNumberRow.setInputFilters(new InputFilter[] { new InputFilter.LengthFilter( editButton.getContext().getResources().getInteger(R.integer.input_length_mmsi)) }); vesselMmsiNumberRow.setHelpText(editButton.getContext().getString(R.string.mmsi_help_description)); vesselImoNumberRow.setInputType(InputType.TYPE_CLASS_NUMBER); vesselImoNumberRow.setInputFilters(new InputFilter[] { new InputFilter.LengthFilter( editButton.getContext().getResources().getInteger(R.integer.input_length_imo)) }); vesselImoNumberRow.setHelpText(editButton.getContext().getString(R.string.imo_help_description)); vesselRegistrationNumberRow.setInputType(InputType.TYPE_CLASS_TEXT); vesselRegistrationNumberRow.setInputFilters(new InputFilter[] { new InputFilter.LengthFilter(editButton.getContext().getResources() .getInteger(R.integer.input_length_registration_number)), new InputFilter.AllCaps() }); vesselRegistrationNumberRow.setHelpText( editButton.getContext().getString(R.string.registration_number_help_description)); contactPersonNameRow.setInputType(InputType.TYPE_TEXT_VARIATION_PERSON_NAME); contactPersonPhoneRow.setInputType(InputType.TYPE_CLASS_PHONE); contactPersonEmailRow.setInputType(InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS); contactPersonNameRow.setHelpText( editButton.getContext().getString(R.string.contact_person_name_help_description)); contactPersonPhoneRow.setHelpText( editButton.getContext().getString(R.string.contact_person_phone_help_description)); contactPersonEmailRow.setHelpText( editButton.getContext().getString(R.string.contact_person_email_help_description)); coordinatesRow.setCoordinates(activity, toolEntry.getCoordinates()); setupDateRow.setEnabled(false); /* Should these fields be editable after tools are reported? */ // vesselRegistrationNumberRow.setEnabled(toolEntry.getToolStatus() == ToolEntryStatus.STATUS_UNREPORTED); // vesselImoNumberRow.setEnabled(toolEntry.getToolStatus() == ToolEntryStatus.STATUS_UNREPORTED); // vesselMmsiNumberRow.setEnabled(toolEntry.getToolStatus() == ToolEntryStatus.STATUS_UNREPORTED); // vesselNameRow.setEnabled(toolEntry.getToolStatus() == ToolEntryStatus.STATUS_UNREPORTED); // vesselIrcsNumberRow.setEnabled(toolEntry.getToolStatus() == ToolEntryStatus.STATUS_UNREPORTED); ArrayAdapter<String> currentAdapter = toolRow.getAdapter(); toolRow.setSelectedSpinnerItem(currentAdapter.getPosition(toolEntry.getToolType().toString())); toolRemovedRow.setChecked(!toolEntry.getRemovedTime().isEmpty()); commentRow.setText(toolEntry.getComment()); contactPersonNameRow.setText(toolEntry.getContactPersonName()); contactPersonPhoneRow .setText(!toolEntry.getContactPersonPhone().equals("") ? toolEntry.getContactPersonPhone() : toolEntry.getVesselPhone()); contactPersonEmailRow .setText(!toolEntry.getContactPersonEmail().equals("") ? toolEntry.getContactPersonEmail() : toolEntry.getVesselEmail()); vesselNameRow.setText(toolEntry.getVesselName()); vesselPhoneNumberRow.setText(toolEntry.getVesselPhone()); vesselIrcsNumberRow.setText(toolEntry.getIRCS()); vesselMmsiNumberRow.setText(toolEntry.getMMSI()); vesselImoNumberRow.setText(toolEntry.getIMO()); vesselRegistrationNumberRow.setText(toolEntry.getRegNum()); sdf.setTimeZone(TimeZone.getTimeZone("UTC")); Date setupDate = null; String toolSetupDateTime; try { setupDate = sdf.parse(toolEntry.getSetupDateTime()); } catch (ParseException e) { e.printStackTrace(); } sdfMilliSeconds.setTimeZone(TimeZone.getDefault()); toolSetupDateTime = sdfMilliSeconds.format(setupDate); setupDateRow.setDate(toolSetupDateTime.substring(0, 10)); setupTimeRow.setTime(toolSetupDateTime.substring(toolEntry.getSetupDateTime().indexOf('T') + 1, toolEntry.getSetupDateTime().indexOf('T') + 6)); fieldContainer.addView(coordinatesRow.getView()); fieldContainer.addView(setupDateRow.getView()); fieldContainer.addView(setupTimeRow.getView()); fieldContainer.addView(toolRow.getView()); fieldContainer.addView(toolRemovedRow.getView()); fieldContainer.addView(commentRow.getView()); fieldContainer.addView(contactPersonNameRow.getView()); fieldContainer.addView(contactPersonPhoneRow.getView()); fieldContainer.addView(contactPersonEmailRow.getView()); fieldContainer.addView(vesselNameRow.getView()); fieldContainer.addView(vesselPhoneNumberRow.getView()); fieldContainer.addView(vesselIrcsNumberRow.getView()); fieldContainer.addView(vesselMmsiNumberRow.getView()); fieldContainer.addView(vesselImoNumberRow.getView()); fieldContainer.addView(vesselRegistrationNumberRow.getView()); fieldContainer.addView(errorRow.getView()); if (toolEntry.getToolStatus() != ToolEntryStatus.STATUS_UNREPORTED) { fieldContainer.addView(archiveRow.getView()); } fieldContainer.addView(deleteRow.getView()); updateButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View updateButton) { List<Point> coordinates = coordinatesRow.getCoordinates(); ToolType toolType = ToolType.createFromValue(toolRow.getCurrentSpinnerItem()); boolean toolRemoved = toolRemovedRow.isChecked(); String vesselName = vesselNameRow.getFieldText(); String vesselPhoneNumber = vesselPhoneNumberRow.getFieldText(); String toolSetupDate = setupDateRow.getDate(); String toolSetupTime = setupTimeRow.getTime(); String toolSetupDateTime; String commentString = commentRow.getFieldText(); String vesselIrcsNumber = vesselIrcsNumberRow.getFieldText(); String vesselMmsiNumber = vesselMmsiNumberRow.getFieldText(); String vesselImoNumber = vesselImoNumberRow.getFieldText(); String registrationNumber = vesselRegistrationNumberRow.getFieldText(); String contactPersonName = contactPersonNameRow.getFieldText(); String contactPersonPhone = contactPersonPhoneRow.getFieldText(); String contactPersonEmail = contactPersonEmailRow.getFieldText(); FiskInfoUtility utility = new FiskInfoUtility(); boolean validated; boolean edited = false; boolean ircsValidated; boolean mmsiValidated; boolean imoValidated; boolean regNumValidated; boolean minimumIdentificationFactorsMet; validated = coordinates != null; if (!validated) { return; } validated = utility.validateName(contactPersonNameRow.getFieldText().trim()); contactPersonNameRow.setError(validated ? null : updateButton.getContext().getString(R.string.error_invalid_name)); if (!validated) { ((ScrollView) fieldContainer.getParent()).post(new Runnable() { @Override public void run() { ((ScrollView) fieldContainer.getParent()).scrollTo(0, contactPersonNameRow.getView().getBottom()); contactPersonNameRow.requestFocus(); } }); return; } validated = utility.validatePhoneNumber(contactPersonPhoneRow.getFieldText().trim()); contactPersonPhoneRow.setError(validated ? null : updateButton.getContext().getString(R.string.error_invalid_phone_number)); if (!validated) { ((ScrollView) fieldContainer.getParent()).post(new Runnable() { @Override public void run() { ((ScrollView) fieldContainer.getParent()).scrollTo(0, contactPersonPhoneRow.getView().getBottom()); contactPersonPhoneRow.requestFocus(); } }); return; } validated = utility.isEmailValid(contactPersonEmailRow.getFieldText().trim()); contactPersonEmailRow.setError(validated ? null : updateButton.getContext().getString(R.string.error_invalid_email)); if (!validated) { ((ScrollView) fieldContainer.getParent()).post(new Runnable() { @Override public void run() { ((ScrollView) fieldContainer.getParent()).scrollTo(0, contactPersonEmailRow.getView().getBottom()); contactPersonEmailRow.requestFocus(); } }); return; } validated = vesselNameRow.getFieldText().trim() != null && !vesselNameRow.getFieldText().isEmpty(); vesselNameRow.setError(validated ? null : updateButton.getContext().getString(R.string.error_invalid_vessel_name)); if (!validated) { ((ScrollView) fieldContainer.getParent()).post(new Runnable() { @Override public void run() { ((ScrollView) fieldContainer.getParent()).scrollTo(0, vesselNameRow.getView().getBottom()); vesselNameRow.requestFocus(); } }); return; } validated = vesselPhoneNumberRow.getFieldText().trim() != null && !vesselPhoneNumberRow.getFieldText().isEmpty(); vesselPhoneNumberRow.setError(validated ? null : updateButton.getContext().getString(R.string.error_invalid_phone_number)); if (!validated) { ((ScrollView) fieldContainer.getParent()).post(new Runnable() { @Override public void run() { ((ScrollView) fieldContainer.getParent()).scrollTo(0, vesselPhoneNumberRow.getView().getBottom()); vesselPhoneNumberRow.requestFocus(); } }); return; } validated = (ircsValidated = utility.validateIRCS(vesselIrcsNumber)) || vesselIrcsNumber.isEmpty(); vesselIrcsNumberRow.setError(validated ? null : updateButton.getContext().getString(R.string.error_invalid_ircs)); if (!validated) { ((ScrollView) fieldContainer.getParent()).post(new Runnable() { @Override public void run() { ((ScrollView) fieldContainer.getParent()).scrollTo(0, vesselIrcsNumberRow.getView().getBottom()); vesselIrcsNumberRow.requestFocus(); } }); return; } validated = (mmsiValidated = utility.validateMMSI(vesselMmsiNumber)) || vesselMmsiNumber.isEmpty(); vesselMmsiNumberRow.setError(validated ? null : updateButton.getContext().getString(R.string.error_invalid_mmsi)); if (!validated) { ((ScrollView) fieldContainer.getParent()).post(new Runnable() { @Override public void run() { ((ScrollView) fieldContainer.getParent()).scrollTo(0, vesselMmsiNumberRow.getView().getBottom()); vesselMmsiNumberRow.requestFocus(); } }); return; } validated = (imoValidated = utility.validateIMO(vesselImoNumber)) || vesselImoNumber.isEmpty(); vesselImoNumberRow.setError( validated ? null : updateButton.getContext().getString(R.string.error_invalid_imo)); if (!validated) { ((ScrollView) fieldContainer.getParent()).post(new Runnable() { @Override public void run() { ((ScrollView) fieldContainer.getParent()).scrollTo(0, vesselImoNumberRow.getView().getBottom()); vesselImoNumberRow.requestFocus(); } }); return; } validated = (regNumValidated = utility.validateRegistrationNumber(registrationNumber)) || registrationNumber.isEmpty(); vesselRegistrationNumberRow.setError(validated ? null : editButton.getContext().getString(R.string.error_invalid_registration_number)); if (!validated) { ((ScrollView) fieldContainer.getParent().getParent()).post(new Runnable() { @Override public void run() { ((ScrollView) fieldContainer.getParent().getParent()).scrollTo(0, vesselRegistrationNumberRow.getView().getBottom()); vesselRegistrationNumberRow.requestFocus(); } }); return; } sdf.setTimeZone(TimeZone.getDefault()); Date setupDate = null; String setupDateString = toolSetupDate + "T" + toolSetupTime + ":00Z"; try { setupDate = sdf.parse(setupDateString); } catch (ParseException e) { e.printStackTrace(); } sdfMilliSeconds.setTimeZone(TimeZone.getTimeZone("UTC")); setupDateString = sdfMilliSeconds.format(setupDate); toolSetupDateTime = setupDateString.substring(0, setupDateString.indexOf('.')).concat("Z"); minimumIdentificationFactorsMet = !vesselName.isEmpty() && (ircsValidated || mmsiValidated || imoValidated || regNumValidated); if ((coordinates != null && coordinates.size() != toolEntry.getCoordinates().size()) || toolType != toolEntry.getToolType() || (toolRemoved) == (toolEntry.getRemovedTime().isEmpty()) || (vesselName != null && !vesselName.equals(toolEntry.getVesselName())) || (vesselPhoneNumber != null && !vesselPhoneNumber.equals(toolEntry.getVesselPhone())) || (toolSetupDateTime != null && !toolSetupDateTime.equals(toolEntry.getSetupDateTime())) || (vesselIrcsNumber != null && !vesselIrcsNumber.equals(toolEntry.getIRCS())) || (vesselMmsiNumber != null && !vesselMmsiNumber.equals(toolEntry.getMMSI())) || (vesselImoNumber != null && !vesselImoNumber.equals(toolEntry.getIMO())) || (registrationNumber != null && !registrationNumber.equals(toolEntry.getRegNum())) || (contactPersonName != null && !contactPersonName.equals(toolEntry.getContactPersonName())) || (contactPersonPhone != null && !contactPersonPhone.equals(toolEntry.getContactPersonPhone())) || (contactPersonEmail != null && !contactPersonEmail.equals(toolEntry.getContactPersonEmail())) || (commentString != null && !commentString.equals(toolEntry.getComment()))) { edited = true; } else { List<Point> points = toolEntry.getCoordinates(); for (int i = 0; i < coordinates.size(); i++) { if (coordinates.get(i).getLatitude() != points.get(i).getLatitude() || coordinates.get(i).getLongitude() != points.get(i).getLongitude()) { edited = true; break; } } } if (edited) { if (!minimumIdentificationFactorsMet) { errorRow.setVisibility(!minimumIdentificationFactorsMet); return; } Date lastChangedDate = new Date(); Date previousSetupDate = null; SimpleDateFormat sdfSetupCompare = new SimpleDateFormat("yyyyMMdd", Locale.getDefault()); String lastChangedDateString = sdfMilliSeconds.format(lastChangedDate).concat("Z"); sdfSetupCompare.setTimeZone(TimeZone.getTimeZone("UTC")); try { previousSetupDate = sdf.parse(toolEntry.getSetupDateTime() .substring(0, toolEntry.getSetupDateTime().length() - 1).concat(".000")); } catch (ParseException e) { e.printStackTrace(); } if (!sdfSetupCompare.format(previousSetupDate) .equals(sdfSetupCompare.format(setupDate))) { // TODO: setup date is changed, tool needs to be moved in log so the app does not crash when trying to delete tool. // user.getToolLog().removeTool(toolEntry.getSetupDate(), toolEntry.getToolLogId()); // user.getToolLog().addTool(toolEntry, toolEntry.getSetupDateTime().substring(0, 10)); // user.writeToSharedPref(editButton.getContext()); } ToolEntryStatus toolStatus = (toolRemoved ? ToolEntryStatus.STATUS_REMOVED_UNCONFIRMED : (toolEntry.getToolStatus() == ToolEntryStatus.STATUS_UNREPORTED ? ToolEntryStatus.STATUS_UNREPORTED : ToolEntryStatus.STATUS_UNSENT)); toolEntry.setToolStatus(toolStatus); toolEntry.setCoordinates(coordinates); toolEntry.setToolType(toolType); toolEntry.setVesselName(vesselName); toolEntry.setVesselPhone(vesselPhoneNumber); toolEntry.setSetupDateTime(toolSetupDateTime); toolEntry.setRemovedTime(toolRemoved ? lastChangedDateString : null); toolEntry.setComment(commentString); toolEntry.setIRCS(vesselIrcsNumber); toolEntry.setMMSI(vesselMmsiNumber); toolEntry.setIMO(vesselImoNumber); toolEntry.setRegNum(registrationNumber); toolEntry.setLastChangedDateTime(lastChangedDateString); toolEntry.setLastChangedBySource(lastChangedDateString); toolEntry.setContactPersonName(contactPersonName); toolEntry.setContactPersonPhone(contactPersonPhone); toolEntry.setContactPersonEmail(contactPersonEmail); try { ImageView notificationView = (ImageView) ((View) editButton.getParent()) .findViewById(R.id.tool_log_row_reported_image_view); if (notificationView != null) { notificationView.setVisibility(View.VISIBLE); notificationView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Toast.makeText(v.getContext(), R.string.notification_tool_unreported_changes, Toast.LENGTH_LONG).show(); } }); } TextView dateTimeTextView = (TextView) ((View) editButton.getParent()) .findViewById(R.id.tool_log_row_latest_date_text_view); TextView toolTypeTextView = (TextView) ((View) editButton.getParent()) .findViewById(R.id.tool_log_row_tool_type_text_view); TextView positionTextView = (TextView) ((View) editButton.getParent()) .findViewById(R.id.tool_log_row_tool_position_text_view); StringBuilder sb = new StringBuilder(); sb.append(FiskInfoUtility .decimalToDMS((toolEntry.getCoordinates().get(0).getLatitude()))); sb.append(", "); sb.append(FiskInfoUtility .decimalToDMS((toolEntry.getCoordinates().get(0).getLongitude()))); String coordinateString = sb.toString(); coordinateString = toolEntry.getCoordinates().size() < 2 ? coordinateString : coordinateString + "\n.."; sdfMilliSeconds.setTimeZone(TimeZone.getTimeZone("GMT+1")); setupDateString = sdfMilliSeconds.format(setupDate); dateTimeTextView.setText(setupDateString.substring(0, 16).replace("T", " ")); toolTypeTextView.setText(toolEntry.getToolType().toString()); positionTextView.setText(coordinateString); Date toolDate; Date currentDate = new Date(); try { toolDate = sdf.parse(toolEntry.getSetupDateTime() .substring(0, toolEntry.getSetupDateTime().length() - 1) .concat(".000")); long diff = currentDate.getTime() - toolDate.getTime(); double days = diff / updateButton.getContext().getResources() .getInteger(R.integer.milliseconds_in_a_day); if (days > 14) { dateTimeTextView.setTextColor(ContextCompat .getColor(updateButton.getContext(), (R.color.error_red))); } else { dateTimeTextView.setTextColor(toolTypeTextView.getCurrentTextColor()); } } catch (ParseException e) { e.printStackTrace(); return; } } catch (ClassCastException e) { e.printStackTrace(); } user.writeToSharedPref(updateButton.getContext()); } else { Toast.makeText(editButton.getContext(), R.string.no_changes_made, Toast.LENGTH_LONG) .show(); } dialog.dismiss(); } }); cancelButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); } }); dialog.show(); } }; }