Example usage for android.widget TextView getCurrentTextColor

List of usage examples for android.widget TextView getCurrentTextColor

Introduction

In this page you can find the example usage for android.widget TextView getCurrentTextColor.

Prototype

@ColorInt
public final int getCurrentTextColor() 

Source Link

Document

Return the current color selected for normal text.

Usage

From source file:com.android.nsboc.ComposeFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (mItem != null) {
        switch (mItem.id + "") {
        case "1":
            mRootView = inflater.inflate(R.layout.form_unlicensed, container, false);
            break;
        case "2":
            mRootView = inflater.inflate(R.layout.form_salon, container, false);
            break;
        }//from w  w  w . ja  v  a 2  s .  co m
    }

    showCurrentDateInEditText();

    ToggleButton complianceToggle = (ToggleButton) mRootView.findViewById(R.id.compliance_toggle);
    if (complianceToggle != null) {
        final LinearLayout complianceContainer = (LinearLayout) mRootView
                .findViewById(R.id.compliance_container);

        complianceToggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (!isChecked) {
                    complianceContainer.setVisibility(View.VISIBLE);

                    final LinearLayout complianceLayout = (LinearLayout) View.inflate(getActivity(),
                            R.layout.compliance_layout, null);

                    Spinner violationTypeSpinner = (Spinner) complianceLayout
                            .findViewById(R.id.violation_type_spinner);
                    violationTypeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                        @Override
                        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                            switch (position) {
                            case 0:
                                complianceLayout.findViewById(R.id.type_citation_container)
                                        .setVisibility(View.VISIBLE);
                                break;
                            case 1:
                                complianceLayout.findViewById(R.id.type_citation_container)
                                        .setVisibility(View.GONE);
                                break;
                            }
                        }

                        @Override
                        public void onNothingSelected(AdapterView<?> parent) {
                        }
                    });

                    ToggleButton anotherToggle = (ToggleButton) complianceLayout
                            .findViewById(R.id.compliance_toggle);
                    anotherToggle.setOnCheckedChangeListener(getNextToggleListener(complianceLayout));

                    complianceContainer.addView(complianceLayout);
                } else {
                    complianceContainer.setVisibility(View.GONE);
                }
            }
        });
    }

    ToggleButton emailToggle = (ToggleButton) mRootView.findViewById(R.id.emailTo_toggle);
    if (emailToggle != null) {
        final LinearLayout emailLayout = (LinearLayout) mRootView.findViewById(R.id.emailTo_layout);

        emailToggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    emailLayout.setVisibility(View.VISIBLE);
                } else {
                    emailLayout.setVisibility(View.GONE);
                }
            }
        });
    }

    final TextView noticeTextView = (TextView) mRootView.findViewById(R.id.notice_textview);
    if (noticeTextView != null) {
        noticeTextView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (noticeTextView.getCurrentTextColor() == Color.BLACK) {
                    noticeTextView.setText(R.string.civil_citation_header);
                    noticeTextView.setTextColor(Color.parseColor("#17405e"));
                    noticeTextView.setText(Html.fromHtml("<u>" + noticeTextView.getText() + "</u>"));
                    mRootView.findViewById(R.id.civil_citation).requestFocus();
                } else {
                    noticeTextView.setText(R.string.civil_citation_notice);
                    noticeTextView.setMaxLines(Integer.MAX_VALUE);
                    noticeTextView.setTextColor(Color.BLACK);
                    noticeTextView.setText(
                            noticeTextView.getText().toString().replace("<u>", "").replace("</u>", ""));
                }
            }
        });
    }

    Spinner stateSpinner = (Spinner) mRootView.findViewById(R.id.state);
    if (stateSpinner != null) {
        stateSpinner.setSelection(27);
    }

    return mRootView;
}

From source file:com.gsbabil.antitaintdroid.UtilityFunctions.java

public int captureBitmapCache(String in) {
    TextView tv = (TextView) MyApp.context.findViewById(R.id.ocrTextview);
    String tvText = tv.getText().toString();
    float tvTextSize = tv.getTextSize();
    int tvColor = tv.getCurrentTextColor();
    Bitmap bitmap = null;/*from www  . j a  v a  2s.  c om*/

    tv.setTextSize(36);
    tv.setTextColor(Color.CYAN);
    tv.setTypeface(Typeface.SANS_SERIF);

    tv.setText(in);

    while (bitmap == null) {
        // http://stackoverflow.com/questions/2339429/android-view-getdrawingcache-returns-null-only-null
        tv.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
                MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
        tv.layout(0, 0, tv.getMeasuredWidth(), tv.getMeasuredHeight());

        tv.setDrawingCacheEnabled(true);
        tv.buildDrawingCache(true);
        bitmap = Bitmap.createBitmap(tv.getDrawingCache());
        tv.destroyDrawingCache();
        tv.setDrawingCacheEnabled(false);
    }

    FileOutputStream fos = null;
    int res = -1;
    try {
        fos = new FileOutputStream(currentDirectory() + "/files/" + MyApp.SCREENSHOT_FILENAME);
        if (fos != null) {
            bitmap.compress(Bitmap.CompressFormat.JPEG, 90, fos);
            fos.close();
            res = 0;
        }
    } catch (Throwable e) {
        Log.i(MyApp.TAG, e.getMessage().toString());
        res = -1;
    }

    tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, tvTextSize);
    tv.setTypeface(Typeface.MONOSPACE);
    tv.setText(tvText);
    tv.setTextColor(tvColor);
    return res;
}

From source file:taylorandtanner.gasscanmk1.OcrCaptureActivity.java

/**
 * onTap is called to speak the tapped TextBlock, if any, out loud.
 *
 * @param rawX - the raw position of the tap
 * @param rawY - the raw position of the tap.
 * @return true if the tap was on a TextBlock
 *///from w w w .  ja v a  2  s.c o  m
private boolean onTap(float rawX, float rawY) {
    OcrGraphic graphic = mGraphicOverlay.getGraphicAtLocation(rawX, rawY);

    TextBlock text = null;

    if (graphic != null) {
        text = graphic.getTextBlock();
        if (text != null && text.getValue() != null) {
            // Log.d(TAG, "text data is being spoken! " + text.getValue());
            //Speak the string.

            //  MainActivity obj = new MainActivity();
            //  TextView textView = obj.getTextView();
            int comparison = Color.RED;
            String storage = text.getValue();

            TextView t1 = (TextView) findViewById(R.id.forStation);
            TextView t2 = (TextView) findViewById(R.id.forPrice);
            TextView t3 = (TextView) findViewById(R.id.forGallons);
            TextView t4 = (TextView) findViewById(R.id.forPriceGal);
            TextView t5 = (TextView) findViewById(R.id.forMileage);

            if (t1.getCurrentTextColor() == comparison) {
                t1.setText(storage);
            } else if (t2.getCurrentTextColor() == comparison) {
                t2.setText(storage);
            } else if (t3.getCurrentTextColor() == comparison) {
                t3.setText(storage);
            } else if (t4.getCurrentTextColor() == comparison) {
                t4.setText(storage);
            } else if (t5.getCurrentTextColor() == comparison) {
                t5.setText(storage);
            }
            // storage = storage.replace("[^\\d.]", "");
            // TextView t1 = (TextView) findViewById(R.id.forStorage);
            // t1.setText(storage);

            /*String separated [] = storage.split("\\r?\\n");
                    
            TextView t2 = (TextView) findViewById(R.id.forMPG);
            t2.setText(separated[0]);
                    
            TextView t3 = (TextView) findViewById(R.id.forNet);
            t3.setText(separated[1]);
                    
            TextView t4 = (TextView) findViewById(R.id.forQTY);
            t4.setText(separated[2]);
                    
            TextView t5 = (TextView) findViewById(R.id.Total);
            t5.setText(separated[3]);*/

            final ReceiptEntry ocrEntry = new ReceiptEntry("1", "2", "3", "unassigned", "4");

            //

            /*mDrawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    //     Toast.makeText(MainActivity.this, "Time for an upgrade!", Toast.LENGTH_SHORT).show();
                    switch (position) {
                        case 0:
                            Intent myIntent = new Intent(view.getContext(), SignInActivity.class);
                            startActivityForResult(myIntent, 0);
                            break;
                        case 1:
                            myIntent = new Intent(view.getContext(), Settings.class);
                            startActivityForResult(myIntent, 0);
                            break;
                        case 2:
                            myIntent = new Intent(view.getContext(), ViewLogs.class);
                            startActivityForResult(myIntent, 0);
                            break;
                        case 3:
                            createBlankSlate();
                            break;
                        case 4:
                            myIntent = new Intent(view.getContext(), ReceiptForm.class);
                            startActivityForResult(myIntent, 0);
                            break;
                        default:
                            return;
                    }*/
            //trying to push string from one activity to another
            //   Intent i = new Intent(this, MainActivity.class);
            //   Bundle bundle = new Bundle();
            //     String check = "false";
            //    bundle.putString("one",storage);
            //  bundle.putBoolean("Check",false);
            //   i.putExtras(bundle);

        } else {
            Log.d(TAG, "text data is null");
        }
    } else {
        Log.d(TAG, "no text detected");
    }
    return text != null;
}

From source file:truckerboys.otto.utils.tabs.SlidingTabLayout.java

private void populateTabStrip() {

    Log.w("PAGER", "POPULATE TABS!");
    final PagerAdapter adapter = mViewPager.getAdapter();
    final View.OnClickListener tabClickListener = new TabClickListener();

    for (int i = 0; i < adapter.getCount(); i++) {
        View tabView = null;//from w w  w .j  a va 2s.com
        TextView tabTitleView = null;

        if (mTabViewLayoutId != 0) {
            // If there is a custom tab view layout id set, try and inflate it
            tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false);
            tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId);
        }

        if (tabView == null) {
            tabView = createDefaultTabView(getContext());
        }

        if (tabTitleView == null && TextView.class.isInstance(tabView)) {
            tabTitleView = (TextView) tabView;
        }

        tabTitleView.setText(adapter.getPageTitle(i));
        tabTitleView.setBackgroundColor(Color.TRANSPARENT);
        tabTitles.add(tabTitleView);
        tabTitleColor = tabTitleView.getCurrentTextColor();
        tabView.setOnClickListener(tabClickListener);

        mTabStrip.addView(tabView);
    }
}

From source file:com.google.android.apps.common.testing.accessibility.framework.uielement.ViewHierarchyElement.java

ViewHierarchyElement(int id, @Nullable ViewHierarchyElement parent, View fromView) {
    // Bookkeeping
    this.id = id;
    this.parentId = (parent != null) ? parent.getId() : null;

    // API 16+ properties
    this.scrollable = AT_16 ? fromView.isScrollContainer() : null;

    // API 11+ properties
    this.backgroundDrawableColor = (AT_11 && (fromView != null)
            && (fromView.getBackground() instanceof ColorDrawable))
                    ? ((ColorDrawable) fromView.getBackground()).getColor()
                    : null;//from w  ww .ja va 2s. com

    // Base properties
    this.visibleToUser = ViewAccessibilityUtils.isVisibleToUser(fromView);
    this.className = fromView.getClass().getName();
    this.accessibilityClassName = null;
    this.packageName = fromView.getContext().getPackageName();
    this.resourceName = (fromView.getId() != View.NO_ID)
            ? ViewAccessibilityUtils.getResourceNameForView(fromView)
            : null;
    this.contentDescription = SpannableString.valueOf(fromView.getContentDescription());
    this.enabled = fromView.isEnabled();
    if (fromView instanceof TextView) {
        TextView textView = (TextView) fromView;
        // Hint text takes precedence if no text is present.
        CharSequence text = textView.getText();
        if (TextUtils.isEmpty(text)) {
            text = textView.getHint();
        }
        this.text = SpannableString.valueOf(text);
        this.textSize = textView.getTextSize();
        this.textColor = textView.getCurrentTextColor();
        this.typefaceStyle = (textView.getTypeface() != null) ? textView.getTypeface().getStyle() : null;
    } else {
        this.text = null;
        this.textSize = null;
        this.textColor = null;
        this.typefaceStyle = null;
    }

    this.importantForAccessibility = ViewAccessibilityUtils.isImportantForAccessibility(fromView);
    this.clickable = fromView.isClickable();
    this.longClickable = fromView.isLongClickable();
    this.focusable = fromView.isFocusable();
    this.editable = ViewAccessibilityUtils.isViewEditable(fromView);
    this.canScrollForward = (ViewCompat.canScrollVertically(fromView, 1)
            || ViewCompat.canScrollHorizontally(fromView, 1));
    this.canScrollBackward = (ViewCompat.canScrollVertically(fromView, -1)
            || ViewCompat.canScrollHorizontally(fromView, -1));
    this.checkable = (fromView instanceof Checkable);
    this.checked = (fromView instanceof Checkable) ? ((Checkable) fromView).isChecked() : null;
    this.hasTouchDelegate = (fromView.getTouchDelegate() != null);

    // There may be subtle differences between the bounds from a View instance compared to that of
    // its AccessibilityNodeInfo. The latter uses a @hide getBoundsOnScreen method, which clips to
    // parent bounds.
    android.graphics.Rect tempRect = new android.graphics.Rect();
    if (fromView.getGlobalVisibleRect(tempRect)) {
        this.boundsInScreen = new Rect(tempRect);
    } else {
        this.boundsInScreen = null;
    }
    this.nonclippedHeight = fromView.getHeight();
    this.nonclippedWidth = fromView.getWidth();
}

From source file:org.mariotaku.twidere.adapter.ComposeAutoCompleteAdapter.java

@Override
public void bindView(final View view, final Context context, final Cursor cursor) {
    final TextView text1 = (TextView) view.findViewById(android.R.id.text1);
    final TextView text2 = (TextView) view.findViewById(android.R.id.text2);
    final ImageView icon = (ImageView) view.findViewById(android.R.id.icon);

    // Clear images in order to prevent images in recycled view shown.
    icon.setImageDrawable(null);/*from  w w  w .ja va 2s  .co m*/

    if (Suggestions.AutoComplete.TYPE_USERS.equals(cursor.getString(mTypeIdx))) {
        text1.setText(mUserColorNameManager.getUserNickname(cursor.getString(mExtraIdIdx),
                cursor.getString(mTitleIdx)));
        text2.setText(String.format("@%s", cursor.getString(mSummaryIdx)));
        if (mDisplayProfileImage) {
            final String profileImageUrl = cursor.getString(mIconIdx);
            mProfileImageLoader.displayProfileImage(icon, profileImageUrl);
        } else {
            mProfileImageLoader.cancelDisplayTask(icon);
        }

        icon.clearColorFilter();
    } else {
        text1.setText(String.format("#%s", cursor.getString(mTitleIdx)));
        text2.setText(R.string.hashtag);

        icon.setImageResource(R.drawable.ic_action_hashtag);
        icon.setColorFilter(text1.getCurrentTextColor(), Mode.SRC_ATOP);
    }
    icon.setVisibility(mDisplayProfileImage ? View.VISIBLE : View.GONE);
    super.bindView(view, context, cursor);
}

From source file:org.getlantern.firetweet.adapter.UserHashtagAutoCompleteAdapter.java

@Override
public void bindView(final View view, final Context context, final Cursor cursor) {
    if (isCursorClosed())
        return;/*ww  w. j  av  a 2 s .  c  om*/
    final TextView text1 = (TextView) view.findViewById(android.R.id.text1);
    final TextView text2 = (TextView) view.findViewById(android.R.id.text2);
    final ImageView icon = (ImageView) view.findViewById(android.R.id.icon);

    // Clear images in prder to prevent images in recycled view shown.
    icon.setImageDrawable(null);

    if (mScreenNameIdx != -1 && mNameIdx != -1 && mUserIdIdx != -1) {
        text1.setText(getUserNickname(context, cursor.getLong(mUserIdIdx), cursor.getString(mNameIdx)));
        text2.setText("@" + cursor.getString(mScreenNameIdx));
    } else {
        text1.setText("#" + cursor.getString(mNameIdx));
        text2.setText(R.string.hashtag);
    }
    icon.setVisibility(mDisplayProfileImage ? View.VISIBLE : View.GONE);
    if (mProfileImageUrlIdx != -1) {
        if (mDisplayProfileImage) {
            final String profileImageUrl = cursor.getString(mProfileImageUrlIdx);
            mProfileImageLoader.displayProfileImage(icon, profileImageUrl);
        } else {
            mProfileImageLoader.cancelDisplayTask(icon);
            //                icon.setImageResource(R.drawable.ic_profile_image_default);
        }
        icon.clearColorFilter();
    } else {
        icon.setImageResource(R.drawable.ic_action_hashtag);
        icon.setColorFilter(text1.getCurrentTextColor(), Mode.SRC_ATOP);
    }
    super.bindView(view, context, cursor);
}

From source file:org.mariotaku.twidere.adapter.UserHashtagAutoCompleteAdapter.java

@Override
public void bindView(final View view, final Context context, final Cursor cursor) {
    if (isCursorClosed())
        return;/*from   ww  w .  jav a2s.  co m*/
    final TextView text1 = (TextView) view.findViewById(android.R.id.text1);
    final TextView text2 = (TextView) view.findViewById(android.R.id.text2);
    final ShapedImageView icon = (ShapedImageView) view.findViewById(android.R.id.icon);

    // Clear images in order to prevent images in recycled view shown.
    icon.setImageDrawable(null);

    if (mScreenNameIdx != -1 && mNameIdx != -1 && mUserIdIdx != -1) {
        text1.setText(
                mUserColorNameManager.getUserNickname(cursor.getLong(mUserIdIdx), cursor.getString(mNameIdx)));
        text2.setText("@" + cursor.getString(mScreenNameIdx));
    } else {
        text1.setText("#" + cursor.getString(mNameIdx));
        text2.setText(R.string.hashtag);
    }
    icon.setVisibility(mDisplayProfileImage ? View.VISIBLE : View.GONE);
    if (mProfileImageUrlIdx != -1) {
        if (mDisplayProfileImage) {
            final String profileImageUrl = cursor.getString(mProfileImageUrlIdx);
            mProfileImageLoader.displayProfileImage(icon, profileImageUrl);
            icon.setStyle(mProfileImageStyle);
        } else {
            mProfileImageLoader.cancelDisplayTask(icon);
        }
        icon.clearColorFilter();
    } else {
        icon.setStyle(mProfileImageStyle);
        icon.setImageResource(R.drawable.ic_action_hashtag);
        icon.setColorFilter(text1.getCurrentTextColor(), Mode.SRC_ATOP);
    }
    super.bindView(view, context, cursor);
}

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 .  j  a  va2 s  . co  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();
        }
    };
}