Example usage for android.text InputType TYPE_CLASS_TEXT

List of usage examples for android.text InputType TYPE_CLASS_TEXT

Introduction

In this page you can find the example usage for android.text InputType TYPE_CLASS_TEXT.

Prototype

int TYPE_CLASS_TEXT

To view the source code for android.text InputType TYPE_CLASS_TEXT.

Click Source Link

Document

Class for normal text.

Usage

From source file:com.maskyn.fileeditorpro.activity.MainActivity.java

void aPreferenceValueWasChanged(List<PreferenceChangeType> types) {

    if (types.contains(PreferenceChangeType.THEME_CHANGE)) {
        ThemeUtils.setWindowsBackground(this);
        AccessoryView accessoryView = (AccessoryView) findViewById(R.id.accessoryView);
        accessoryView.updateTextColors();
    }/*from   ww w . j a v  a  2 s.  c  om*/

    if (types.contains(PreferenceChangeType.WRAP_CONTENT)) {
        if (PreferenceHelper.getWrapContent(this)) {
            horizontalScroll.removeView(mEditor);
            verticalScroll.removeView(horizontalScroll);
            verticalScroll.addView(mEditor);
        } else {
            verticalScroll.removeView(mEditor);
            verticalScroll.addView(horizontalScroll);
            horizontalScroll.addView(mEditor);
        }
    } else if (types.contains(PreferenceChangeType.LINE_NUMERS)) {
        mEditor.disableTextChangedListener();
        mEditor.replaceTextKeepCursor(null);
        mEditor.enableTextChangedListener();
        mEditor.updatePadding();
    } else if (types.contains(PreferenceChangeType.SYNTAX)) {
        mEditor.disableTextChangedListener();
        mEditor.replaceTextKeepCursor(mEditor.getText().toString());
        mEditor.enableTextChangedListener();
    } else if (types.contains(PreferenceChangeType.MONOSPACE)) {
        if (PreferenceHelper.getUseMonospace(this))
            mEditor.setTypeface(Typeface.MONOSPACE);
        else
            mEditor.setTypeface(Typeface.DEFAULT);
    } else if (types.contains(PreferenceChangeType.THEME_CHANGE)) {
        if (PreferenceHelper.getLightTheme(this)) {
            mEditor.setTextColor(getResources().getColor(R.color.textColorInverted));
        } else {
            mEditor.setTextColor(getResources().getColor(R.color.textColor));
        }
    } else if (types.contains(PreferenceChangeType.TEXT_SUGGESTIONS)
            || types.contains(PreferenceChangeType.READ_ONLY)) {
        if (PreferenceHelper.getReadOnly(this)) {
            mEditor.setReadOnly(true);
        } else {
            mEditor.setReadOnly(false);
            if (PreferenceHelper.getSuggestionActive(this)) {
                mEditor.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE
                        | InputType.TYPE_TEXT_FLAG_IME_MULTI_LINE);
            } else {
                mEditor.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE
                        | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS
                        | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD
                        | InputType.TYPE_TEXT_FLAG_IME_MULTI_LINE);
            }
        }
        // sometimes it becomes monospace after setting the input type
        if (PreferenceHelper.getUseMonospace(this))
            mEditor.setTypeface(Typeface.MONOSPACE);
        else
            mEditor.setTypeface(Typeface.DEFAULT);
    } else if (types.contains(PreferenceChangeType.FONT_SIZE)) {
        mEditor.updatePadding();
        mEditor.setTextSize(PreferenceHelper.getFontSize(this));
    } else if (types.contains(PreferenceChangeType.ACCESSORY_VIEW)) {
        HorizontalScrollView parentAccessoryView = (HorizontalScrollView) findViewById(
                R.id.parent_accessory_view);
        ViewUtils.setVisible(parentAccessoryView, PreferenceHelper.getUseAccessoryView(this));
        mEditor.updatePadding();
    } else if (types.contains(PreferenceChangeType.ENCODING)) {
        String oldEncoding, newEncoding;
        oldEncoding = currentEncoding;
        newEncoding = PreferenceHelper.getEncoding(this);
        try {
            final byte[] oldText = mEditor.getText().toString().getBytes(oldEncoding);
            mEditor.disableTextChangedListener();
            mEditor.replaceTextKeepCursor(new String(oldText, newEncoding));
            mEditor.enableTextChangedListener();
            currentEncoding = newEncoding;
        } catch (UnsupportedEncodingException ignored) {
            try {
                final byte[] oldText = mEditor.getText().toString().getBytes(oldEncoding);
                mEditor.disableTextChangedListener();
                mEditor.replaceTextKeepCursor(new String(oldText, "UTF-16"));
                mEditor.enableTextChangedListener();
            } catch (UnsupportedEncodingException ignored2) {
            }
        }
    }
}

From source file:kr.wdream.ui.Components.PasscodeView.java

public void onShow() {
    Log.d("PassCodeView", "onShow");
    Activity parentActivity = (Activity) getContext();
    if (UserConfig.passcodeType == 1) {
        Log.d("PassCodeView", "passcodeType = 1");
        if (passwordEditText != null) {
            Log.d("PassCodeView", "EditText not null");
            passwordEditText.requestFocus();
            AndroidUtilities.showKeyboard(passwordEditText);
        }// ww  w. ja  va 2 s  .  c  om
    } else {
        Log.d("PassCodeView", "passcodeType not 1");
        if (parentActivity != null) {
            Log.d("PassCodeView", "parentActivity not null");
            View currentFocus = parentActivity.getCurrentFocus();
            if (currentFocus != null) {
                Log.d("PassCodeView", "current focus not null");
                currentFocus.clearFocus();
                AndroidUtilities.hideKeyboard(((Activity) getContext()).getCurrentFocus());
            }
        }
    }
    checkFingerprint();
    if (getVisibility() == View.VISIBLE) {
        return;
    }
    setAlpha(1.0f);
    setTranslationY(0);
    SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig",
            Activity.MODE_PRIVATE);
    int selectedBackground = preferences.getInt("selectedBackground", 1000001);
    if (selectedBackground == 1000001) {
        backgroundFrameLayout.setBackgroundColor(0xff517c9e);
    } else {
        backgroundDrawable = ApplicationLoader.getCachedWallpaper();
        if (backgroundDrawable != null) {
            backgroundFrameLayout.setBackgroundColor(0xbf000000);
        } else {
            backgroundFrameLayout.setBackgroundColor(0xff517c9e);
        }
    }

    passcodeTextView.setText(
            LocaleController.getString("EnterYourPasscode", kr.wdream.storyshop.R.string.EnterYourPasscode));

    if (UserConfig.passcodeType == 0) {
        //InputFilter[] filterArray = new InputFilter[1];
        //filterArray[0] = new InputFilter.LengthFilter(4);
        //passwordEditText.setFilters(filterArray);
        //passwordEditText.setInputType(InputType.TYPE_CLASS_PHONE);
        //passwordEditText.setFocusable(false);
        //passwordEditText.setFocusableInTouchMode(false);
        numbersFrameLayout.setVisibility(VISIBLE);
        passwordEditText.setVisibility(GONE);
        passwordEditText2.setVisibility(VISIBLE);
        checkImage.setVisibility(GONE);
    } else if (UserConfig.passcodeType == 1) {
        passwordEditText.setFilters(new InputFilter[0]);
        passwordEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
        numbersFrameLayout.setVisibility(GONE);
        passwordEditText.setFocusable(true);
        passwordEditText.setFocusableInTouchMode(true);
        passwordEditText.setVisibility(VISIBLE);
        passwordEditText2.setVisibility(GONE);
        checkImage.setVisibility(VISIBLE);
    }
    setVisibility(VISIBLE);
    passwordEditText.setTransformationMethod(PasswordTransformationMethod.getInstance());
    passwordEditText.setText("");
    passwordEditText2.eraseAllCharacters(false);

    setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return true;
        }
    });
}

From source file:ir.besteveryeverapp.ui.Components.PasscodeView.java

public void onShow() {
    Activity parentActivity = (Activity) getContext();
    if (UserConfig.passcodeType == 1) {
        if (passwordEditText != null) {
            passwordEditText.requestFocus();
            AndroidUtilities.showKeyboard(passwordEditText);
        }// w  w w  . ja v  a 2 s.c  o  m
    } else {
        if (parentActivity != null) {
            View currentFocus = parentActivity.getCurrentFocus();
            if (currentFocus != null) {
                currentFocus.clearFocus();
                AndroidUtilities.hideKeyboard(((Activity) getContext()).getCurrentFocus());
            }
        }
    }
    checkFingerprint();
    if (getVisibility() == View.VISIBLE) {
        return;
    }
    setAlpha(1.0f);
    setTranslationY(0);
    SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig",
            Activity.MODE_PRIVATE);
    int selectedBackground = preferences.getInt("selectedBackground", 1000001);
    if (selectedBackground == 1000001) {
        backgroundFrameLayout.setBackgroundColor(0xff517c9e);
    } else {
        backgroundDrawable = ApplicationLoader.getCachedWallpaper();
        if (backgroundDrawable != null) {
            backgroundFrameLayout.setBackgroundColor(0xbf000000);
        } else {
            backgroundFrameLayout.setBackgroundColor(0xff517c9e);
        }
    }

    passcodeTextView.setText(LocaleController.getString("EnterYourPasscode", R.string.EnterYourPasscode));

    if (UserConfig.passcodeType == 0) {
        //InputFilter[] filterArray = new InputFilter[1];
        //filterArray[0] = new InputFilter.LengthFilter(4);
        //passwordEditText.setFilters(filterArray);
        //passwordEditText.setInputType(InputType.TYPE_CLASS_PHONE);
        //passwordEditText.setFocusable(false);
        //passwordEditText.setFocusableInTouchMode(false);
        numbersFrameLayout.setVisibility(VISIBLE);
        passwordEditText.setVisibility(GONE);
        passwordEditText2.setVisibility(VISIBLE);
        checkImage.setVisibility(GONE);
    } else if (UserConfig.passcodeType == 1) {
        passwordEditText.setFilters(new InputFilter[0]);
        passwordEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
        numbersFrameLayout.setVisibility(GONE);
        passwordEditText.setFocusable(true);
        passwordEditText.setFocusableInTouchMode(true);
        passwordEditText.setVisibility(VISIBLE);
        passwordEditText2.setVisibility(GONE);
        checkImage.setVisibility(VISIBLE);
    }
    setVisibility(VISIBLE);
    passwordEditText.setTransformationMethod(PasswordTransformationMethod.getInstance());
    passwordEditText.setText("");
    passwordEditText2.eraseAllCharacters(false);

    setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return true;
        }
    });
}

From source file:org.protocoderrunner.apprunner.api.PUI.java

@ProtocoderScript
@APIMethod(description = "Shows an input dialog", example = "")
@APIParam(params = { "title", "function(text)" })
public void popupInput(String title, final inputDialogCB callbackfn) {
    AlertDialog.Builder builder = new AlertDialog.Builder(a.get());
    builder.setTitle(title);//  w  ww.j a v  a2  s  .co m

    final EditText input = new EditText(a.get());

    input.setInputType(InputType.TYPE_CLASS_TEXT);
    builder.setView(input);

    // Set up the buttons
    builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            String text = input.getText().toString();
            callbackfn.event(text);
        }
    });
    builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
        }
    });

    builder.show();
}

From source file:org.telegram.ui.Components.PasscodeView.java

public void onShow() {
    Activity parentActivity = (Activity) getContext();
    if (UserConfig.passcodeType == 1) {
        if (passwordEditText != null) {
            passwordEditText.requestFocus();
            AndroidUtilities.showKeyboard(passwordEditText);
        }/*w w w  . j ava  2s .  com*/
    } else {
        if (parentActivity != null) {
            View currentFocus = parentActivity.getCurrentFocus();
            if (currentFocus != null) {
                currentFocus.clearFocus();
                AndroidUtilities.hideKeyboard(((Activity) getContext()).getCurrentFocus());
            }
        }
    }
    checkFingerprint();
    if (getVisibility() == View.VISIBLE) {
        return;
    }
    if (Build.VERSION.SDK_INT >= 14) {
        ViewProxy.setAlpha(this, 1.0f);
        ViewProxy.setTranslationY(this, 0);
        this.clearAnimation();
    }
    SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig",
            Activity.MODE_PRIVATE);
    int selectedBackground = preferences.getInt("selectedBackground", 1000001);
    if (selectedBackground == 1000001) {
        backgroundFrameLayout.setBackgroundColor(0xffff8542);
    } else {
        backgroundDrawable = ApplicationLoader.getCachedWallpaper();
        if (backgroundDrawable != null) {
            backgroundFrameLayout.setBackgroundColor(0xbf000000);
        } else {
            backgroundFrameLayout.setBackgroundColor(0xffff8542);
        }
    }

    passcodeTextView.setText(LocaleController.getString("EnterYourPasscode", R.string.EnterYourPasscode));

    if (UserConfig.passcodeType == 0) {
        //InputFilter[] filterArray = new InputFilter[1];
        //filterArray[0] = new InputFilter.LengthFilter(4);
        //passwordEditText.setFilters(filterArray);
        //passwordEditText.setInputType(InputType.TYPE_CLASS_PHONE);
        //passwordEditText.setFocusable(false);
        //passwordEditText.setFocusableInTouchMode(false);
        numbersFrameLayout.setVisibility(VISIBLE);
        passwordEditText.setVisibility(GONE);
        passwordEditText2.setVisibility(VISIBLE);
        checkImage.setVisibility(GONE);
    } else if (UserConfig.passcodeType == 1) {
        passwordEditText.setFilters(new InputFilter[0]);
        passwordEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
        numbersFrameLayout.setVisibility(GONE);
        passwordEditText.setFocusable(true);
        passwordEditText.setFocusableInTouchMode(true);
        passwordEditText.setVisibility(VISIBLE);
        passwordEditText2.setVisibility(GONE);
        checkImage.setVisibility(VISIBLE);
    }
    setVisibility(VISIBLE);
    passwordEditText.setTransformationMethod(PasswordTransformationMethod.getInstance());
    passwordEditText.setText("");
    passwordEditText2.eraseAllCharacters(false);

    setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return true;
        }
    });
}

From source file:com.goftagram.telegram.ui.Components.PasscodeView.java

public void onShow() {
    Activity parentActivity = (Activity) getContext();
    if (UserConfig.passcodeType == 1) {
        if (passwordEditText != null) {
            passwordEditText.requestFocus();
            AndroidUtilities.showKeyboard(passwordEditText);
        }//from w w  w.  j a va  2 s  .c  o m
    } else {
        if (parentActivity != null) {
            View currentFocus = parentActivity.getCurrentFocus();
            if (currentFocus != null) {
                currentFocus.clearFocus();
                AndroidUtilities.hideKeyboard(((Activity) getContext()).getCurrentFocus());
            }
        }
    }
    checkFingerprint();
    if (getVisibility() == View.VISIBLE) {
        return;
    }
    if (Build.VERSION.SDK_INT >= 14) {
        ViewProxy.setAlpha(this, 1.0f);
        ViewProxy.setTranslationY(this, 0);
        this.clearAnimation();
    }
    SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig",
            Activity.MODE_PRIVATE);
    int selectedBackground = preferences.getInt("selectedBackground", 1000001);
    if (selectedBackground == 1000001) {
        backgroundFrameLayout.setBackgroundColor(0xff517c9e);
    } else {
        backgroundDrawable = ApplicationLoader.getCachedWallpaper();
        if (backgroundDrawable != null) {
            backgroundFrameLayout.setBackgroundColor(0xbf000000);
        } else {
            backgroundFrameLayout.setBackgroundColor(0xff517c9e);
        }
    }

    passcodeTextView.setText(LocaleController.getString("EnterYourPasscode", R.string.EnterYourPasscode));

    if (UserConfig.passcodeType == 0) {
        //InputFilter[] filterArray = new InputFilter[1];
        //filterArray[0] = new InputFilter.LengthFilter(4);
        //passwordEditText.setFilters(filterArray);
        //passwordEditText.setInputType(InputType.TYPE_CLASS_PHONE);
        //passwordEditText.setFocusable(false);
        //passwordEditText.setFocusableInTouchMode(false);
        numbersFrameLayout.setVisibility(VISIBLE);
        passwordEditText.setVisibility(GONE);
        passwordEditText2.setVisibility(VISIBLE);
        checkImage.setVisibility(GONE);
    } else if (UserConfig.passcodeType == 1) {
        passwordEditText.setFilters(new InputFilter[0]);
        passwordEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
        numbersFrameLayout.setVisibility(GONE);
        passwordEditText.setFocusable(true);
        passwordEditText.setFocusableInTouchMode(true);
        passwordEditText.setVisibility(VISIBLE);
        passwordEditText2.setVisibility(GONE);
        checkImage.setVisibility(VISIBLE);
    }
    setVisibility(VISIBLE);
    passwordEditText.setTransformationMethod(PasswordTransformationMethod.getInstance());
    passwordEditText.setText("");
    passwordEditText2.eraseAllCharacters(false);

    setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return true;
        }
    });
}

From source file:com.keylesspalace.tusky.ComposeActivity.java

private void makeCaptionDialog(QueuedMedia item) {
    LinearLayout dialogLayout = new LinearLayout(this);
    int padding = Utils.dpToPx(this, 8);
    dialogLayout.setPadding(padding, padding, padding, padding);

    dialogLayout.setOrientation(LinearLayout.VERTICAL);
    ImageView imageView = new ImageView(this);

    DisplayMetrics displayMetrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);

    Picasso.with(this).load(item.uri).resize(displayMetrics.widthPixels, displayMetrics.heightPixels)
            .onlyScaleDown().into(imageView);

    int margin = Utils.dpToPx(this, 4);
    dialogLayout.addView(imageView);//  w w w.  jav a 2s.  c  o  m
    ((LinearLayout.LayoutParams) imageView.getLayoutParams()).weight = 1;
    imageView.getLayoutParams().height = 0;
    ((LinearLayout.LayoutParams) imageView.getLayoutParams()).setMargins(0, margin, 0, 0);

    EditText input = new EditText(this);
    input.setHint(R.string.hint_describe_for_visually_impaired);
    dialogLayout.addView(input);
    ((LinearLayout.LayoutParams) input.getLayoutParams()).setMargins(margin, margin, margin, margin);
    input.setLines(1);
    input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
    input.setText(item.description);

    DialogInterface.OnClickListener okListener = (dialog, which) -> {
        mastodonApi.updateMedia(item.id, input.getText().toString()).enqueue(new Callback<Attachment>() {
            @Override
            public void onResponse(@NonNull Call<Attachment> call, @NonNull Response<Attachment> response) {
                Attachment attachment = response.body();
                if (response.isSuccessful() && attachment != null) {
                    item.description = attachment.getDescription();
                    item.preview.setChecked(item.description != null && !item.description.isEmpty());
                    dialog.dismiss();
                } else {
                    showFailedCaptionMessage();
                }
            }

            @Override
            public void onFailure(@NonNull Call<Attachment> call, @NonNull Throwable t) {
                showFailedCaptionMessage();
            }
        });
    };

    AlertDialog dialog = new AlertDialog.Builder(this).setView(dialogLayout)
            .setPositiveButton(android.R.string.ok, okListener).setNegativeButton(android.R.string.cancel, null)
            .create();

    Window window = dialog.getWindow();
    if (window != null) {
        window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
    }

    dialog.show();
}

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  w w  .j  a  v a 2s  .  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();
        }
    };
}

From source file:com.aslanoba.hwc.SettingsActivity.java

/**
 * Click handler for the list items.  Will create the appropriate edit
 * box for the clicked setting./*from w  ww.ja  va  2s . c  o m*/
 */
@Override
public void onListItemClick(ListView oParent, View v, int iPos, long id) {
    final ListView oParentListView = oParent;
    final SettingsListItem oItem = m_filteredSettings.get(iPos);

    if (oItem instanceof ChoiceSettingsListItem) {
        final ChoiceSettingsListItem oChoiceItem = (ChoiceSettingsListItem) oItem;

        // Show dialog
        new AlertDialog.Builder(SettingsActivity.this)
                .setTitle(getString(R.string.Label_Edit) + " " + oItem.m_sLabel)
                .setSingleChoiceItems(oChoiceItem.m_asText, oChoiceItem.m_iSelectedItem,
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int whichButton) {
                                oChoiceItem.select(whichButton);
                                if (oItem.m_iPropId == PropertyID.CONNECTION_AUTO_REGISTRATION_HINT) {
                                    m_iRegistrationMethod = (Integer) oChoiceItem.m_oValue;
                                    if (m_iRegistrationMethod == Settings.REGISTRATION_METHOD.CERTIFICATE) {
                                        handleLocalCertificateSelection();
                                    }
                                }

                                // refresh in ui
                                refreshList();
                                oParentListView.invalidate();

                                // Close dialog
                                dialog.dismiss();
                            }
                        })
                .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        // Close dialog
                        dialog.dismiss();
                    }
                }).show();
    } else {
        // inflate the xml layout
        final View oView = m_oInflater.inflate(R.layout.settings_edit, null);

        TextView tv = (TextView) oView.findViewById(R.id.TextViewEditSettings);
        if (tv != null)
            tv.setText(getItemLabel(oItem));

        // set value
        tv = (TextView) oView.findViewById(R.id.EditTextEditSettings);
        if (tv != null)
            tv.setText(oItem.m_oValue.toString());

        // special input validator for integers
        if (oItem.m_oValue instanceof Integer)
            tv.setInputType(InputType.TYPE_CLASS_NUMBER);

        if (oItem.m_bPassword)
            tv.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);

        // show dialog, valid value when user clicks ok button
        new AlertDialog.Builder(this).setTitle(getString(R.string.Label_Edit) + " " + getItemLabel(oItem))
                .setView(oView).setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        TextView tv = (TextView) oView.findViewById(R.id.EditTextEditSettings);
                        String sText = tv.getText().toString();

                        if (oItem.m_oValue instanceof Integer)
                            oItem.m_oValue = Integer.parseInt(sText);
                        else if (oItem.m_oValue instanceof Boolean)
                            oItem.m_oValue = Boolean.parseBoolean(sText);
                        else
                            oItem.m_oValue = sText;

                        InputMethodManager imm = (InputMethodManager) getSystemService(
                                Context.INPUT_METHOD_SERVICE);
                        imm.hideSoftInputFromWindow(tv.getWindowToken(), 0);

                        //validate the input value
                        if (!validateField(oItem)) {
                            // validation failed, reset to original value
                            oItem.m_oValue = oItem.m_oOrigValue;
                            showValidationErrorDialog(oItem.m_sLabel);
                        } else {
                            // refresh in ui
                            refreshList();
                            oParentListView.invalidate();

                        }
                    }
                }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        TextView tv = (TextView) oView.findViewById(R.id.EditTextEditSettings);
                        InputMethodManager imm = (InputMethodManager) getSystemService(
                                Context.INPUT_METHOD_SERVICE);
                        imm.hideSoftInputFromWindow(tv.getWindowToken(), 0);
                        dialog.dismiss();
                    }
                }).show();
    }
}

From source file:com.gigabytedevelopersinc.app.calculator.Calculator.java

public void BtnClick(final View v) {

    page_no = mPager.getCurrentItem();//  w w  w .  j  a v a  2s  .  c  o  m
    unitSpinner = findViewById(R.id.units_spinner);
    switch (page_no) {
    /*case 0:
        result_TV = (AutoResizeTextView) findViewById(R.id.sci_result_TV);
        expression_TV = (EditText) findViewById(R.id.sci_expression_TV);
        break;
    case 1:
        result_TV = (AutoResizeTextView) findViewById(R.id.pro_result_TV);
        expression_TV = (EditText) findViewById(R.id.pro_expression_TV);
        break;*/
    case 2:
        result_TV = (AutoResizeTextView) findViewById(R.id.curr_result_TV);
        expression_TV = (EditText) findViewById(R.id.curr_expression_TV);
        resultant_TV = (AutoResizeTextView) findViewById(R.id.curr_resultant_TV);
        break;
    case 3:
    case 4:
        result_TV = (AutoResizeTextView) findViewById(R.id.conv_result_TV);
        expression_TV = (EditText) findViewById(R.id.conv_expression_TV);
        resultant_TV = (AutoResizeTextView) findViewById(R.id.conv_resultant_TV);
        break;

    }
    try {
        result_TV.setInputType(InputType.TYPE_NULL);
        result_TV.setRawInputType(InputType.TYPE_CLASS_TEXT);
        result_TV.setTextIsSelectable(true);
        result = result_TV.getText().toString();

        try {
            resultant_TV.setInputType(InputType.TYPE_NULL);
            resultant_TV.setRawInputType(InputType.TYPE_CLASS_TEXT);
            resultant_TV.setTextIsSelectable(true);
        } catch (Exception idk) {
            //
        }

        expression_TV.setInputType(InputType.TYPE_NULL);
        expression_TV.setRawInputType(InputType.TYPE_CLASS_TEXT);
        expression_TV.setTextIsSelectable(true);
        expression = expression_TV.getText().toString();
        if (!flag) {
            expression_TV.setText("");
            result_TV.setMaxTextSize(34);
            result_TV.setTextSize(34);
            result_TV.setText("" + 0);
            expression = "";
            result = "" + 0;
            flag = true;
        }
    } catch (Exception eee) {
        //
    }

    //Converter
    from = (Spinner) findViewById(R.id.from_spinner);
    to = (Spinner) findViewById(R.id.to_spinner);
    try {
        from.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                evaluate(expression_TV.getText().toString());
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {
            }
        });
        to.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                evaluate(expression_TV.getText().toString());
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {
            }
        });
    } catch (Exception e) {
        //
    }

    //Currency
    fro = (Spinner) findViewById(R.id.fro_spinner);
    too = (Spinner) findViewById(R.id.too_spinner);
    /*LinearLayout sciFunLayout = (LinearLayout) findViewById(R.id.sci_fun_layout);
    final ListView constantsList = (ListView) findViewById(R.id.constants_list);*/

    switch (page_no) {
    /*case 0:
        historyLayout = (LinearLayout) findViewById(R.id.sci_history_layout);
        memoryLayout = (LinearLayout) findViewById(R.id.sci_memory_layout);
        simplePad = (LinearLayout) findViewById(R.id.sci_simple_pad);
        historyList = (ListView) findViewById(R.id.sci_history_list);
        historyList.setEmptyView(findViewById(R.id.sci_empty_history));
        memoryList = (ListView) findViewById(R.id.sci_memory_list);
        memoryList.setEmptyView(findViewById(R.id.sci_empty));
        fav_List_LL = (LinearLayout) findViewById(R.id.conv_fav_layout);
        favList = (ListView) findViewById(R.id.conv_fav_list);
        favList.setEmptyView(findViewById(R.id.conv_empty_fav));
        hyBtn = (Button) findViewById(R.id.sci_history_Btn);
        myBtn = (Button) findViewById(R.id.sci_M_Btn);
        favBtn = (Button) findViewById(R.id.conv_fav_Btn);
        break;
    case 1:
        historyLayout = (LinearLayout) findViewById(R.id.pro_history_layout);
        memoryLayout = (LinearLayout) findViewById(R.id.pro_memory_layout);
        simplePad = (LinearLayout) findViewById(R.id.pro_simple_pad);
        historyList = (ListView) findViewById(R.id.pro_history_list);
        historyList.setEmptyView(findViewById(R.id.pro_empty_history));
        memoryList = (ListView) findViewById(R.id.pro_memory_list);
        memoryList.setEmptyView(findViewById(R.id.pro_empty));
        fav_List_LL = (LinearLayout) findViewById(R.id.conv_fav_layout);
        favList = (ListView) findViewById(R.id.conv_fav_list);
        favList.setEmptyView(findViewById(R.id.conv_empty_fav));
        favBtn = (Button) findViewById(R.id.conv_fav_Btn);
        break;*/
    case 2:
        historyLayout = (LinearLayout) findViewById(R.id.curr_history_layout);
        memoryLayout = (LinearLayout) findViewById(R.id.curr_memory_layout);
        simplePad = (LinearLayout) findViewById(R.id.curr_simple_pad);
        historyList = (ListView) findViewById(R.id.curr_history_list);
        historyList.setEmptyView(findViewById(R.id.curr_empty_history));
        memoryList = (ListView) findViewById(R.id.curr_memory_list);
        memoryList.setEmptyView(findViewById(R.id.curr_empty));
        fav_List_LL = (LinearLayout) findViewById(R.id.curr_fav_layout);
        favList = (ListView) findViewById(R.id.curr_fav_list);
        favList.setEmptyView(findViewById(R.id.curr_empty_fav));
        /*hyBtn = (Button) findViewById(R.id.curr_history_Btn);
        myBtn = (Button) findViewById(R.id.curr_M_Btn);
        favBtn = (Button) findViewById(R.id.curr_fav_Btn);*/
        break;
    case 3:
    case 4:
        historyLayout = (LinearLayout) findViewById(R.id.conv_history_layout);
        memoryLayout = (LinearLayout) findViewById(R.id.conv_memory_layout);
        simplePad = (LinearLayout) findViewById(R.id.conv_simple_pad);
        historyList = (ListView) findViewById(R.id.conv_history_list);
        historyList.setEmptyView(findViewById(R.id.conv_empty_history));
        memoryList = (ListView) findViewById(R.id.conv_memory_list);
        memoryList.setEmptyView(findViewById(R.id.conv_empty));
        fav_List_LL = (LinearLayout) findViewById(R.id.conv_fav_layout);
        favList = (ListView) findViewById(R.id.conv_fav_list);
        favList.setEmptyView(findViewById(R.id.conv_empty_fav));
        /*hyBtn = (Button) findViewById(R.id.conv_history_Btn);
        myBtn = (Button) findViewById(R.id.conv_M_Btn);
        favBtn = (Button) findViewById(R.id.conv_fav_Btn);*/
        break;
    default:
        historyLayout = (LinearLayout) findViewById(R.id.conv_history_layout);
        memoryLayout = (LinearLayout) findViewById(R.id.conv_memory_layout);
        simplePad = (LinearLayout) findViewById(R.id.conv_simple_pad);
        historyList = (ListView) findViewById(R.id.conv_history_list);
        historyList.setEmptyView(findViewById(R.id.conv_empty_history));
        fav_List_LL = (LinearLayout) findViewById(R.id.conv_fav_layout);
        memoryList = (ListView) findViewById(R.id.conv_memory_list);
        memoryList.setEmptyView(findViewById(R.id.conv_empty));
        favList = (ListView) findViewById(R.id.conv_fav_list);
        favList.setEmptyView(findViewById(R.id.conv_empty_fav));
        /*hyBtn = (Button) findViewById(R.id.conv_history_Btn);
        myBtn = (Button) findViewById(R.id.conv_M_Btn);
        favBtn = (Button) findViewById(R.id.conv_fav_Btn);*/
        break;
    }

    /*Button funcBtn = (Button) findViewById(R.id.functions_Btn);
    Button constBtn = (Button) findViewById(R.id.constants_Btn);
            
    Button decBtn = (Button) findViewById(R.id.dec_Btn);
    Button hexBtn = (Button) findViewById(R.id.hex_Btn);
    Button octBtn = (Button) findViewById(R.id.oct_Btn);
    Button binBtn = (Button) findViewById(R.id.bin_Btn);
            
    TextView decTV = (TextView) findViewById(R.id.dec_tv);
    TextView hexTV = (TextView) findViewById(R.id.hex_TV);
    TextView octTV = (TextView) findViewById(R.id.oct_TV);
    TextView binTV = (TextView) findViewById(R.id.bin_TV);*/

    int id = v.getId();
    Button btn = (Button) findViewById(id);
    final String btnText = btn.getText().toString();
    switch (id) {
    case R.id.curr_add_to_fav:
    case R.id.conv_add_to_fav:
        createFav();
        break;
    //case R.id.sci_history_Btn:
    //case R.id.conv_history_Btn:
    //case R.id.curr_history_Btn:
    /*dbAdapter = new DbAdapter(this);
    dbAdapter.open();
    fillData();
            
    if (historyLayout.getVisibility() == View.GONE) {
        historyLayout.setVisibility(View.VISIBLE);
        hyBtn.setTextColor(primary_text_color);
        hyBtn.setBackgroundColor(primary_color);
        myBtn.setTextColor(sec_text_color);
        myBtn.setBackgroundColor(sec_color);
        memoryLayout.setVisibility(View.GONE);
        try {
            fav_List_LL.setVisibility(View.GONE);
            favBtn.setTextColor(sec_text_color);
            favBtn.setBackgroundColor(sec_color);
        } catch (Exception e) {
            //
        }
        *//*try {
             constantsList.setVisibility(View.GONE);
             constBtn.setTextColor(sec_text_color);
             constBtn.setBackgroundColor(sec_color);
             sciFunLayout.setVisibility(View.GONE);
             funcBtn.setTextColor(sec_text_color);
             funcBtn.setBackgroundColor(sec_color);
           } catch (Exception e) {
             //
           }*//*
               simplePad.setVisibility(View.GONE);
               } else {
               hyBtn.setTextColor(sec_text_color);
               hyBtn.setBackgroundColor(sec_color);
               historyLayout.setVisibility(View.GONE);
               simplePad.setVisibility(View.VISIBLE);
               }
               break;*/

    /*case R.id.floating:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            if (getDrawPermit()) {
                Intent startServiceIntent = new Intent(MainActivity.this, FloatingCalculator.class);
                startService(startServiceIntent);
            } else
                Toast.makeText(getApplicationContext(),
                        "Allow permission to draw over other apps to use Floating Calculator.",
                        Toast.LENGTH_LONG).show();
        } else {
            Intent startServiceIntent = new Intent(MainActivity.this, FloatingCalculator.class);
            startService(startServiceIntent);
        }
        break;
    case R.id.matgraph:
        startActivity(new Intent(getApplicationContext(), Calculator.class).putExtra("MAIN", true));
        break;
    case R.id.settings:
        startActivity(new Intent(MainActivity.this, SettingsActivity.class));
        break;
    case R.id.report:
        Intent report = new Intent(Intent.ACTION_VIEW,
                Uri.parse("https://github.com/gigabytedevelopers/CalcMate/issues"));
        startActivity(report);
        break;
    case R.id.about:
        new LibsBuilder()
                .withLicenseShown(true)
                .withVersionShown(true)
                .withAboutVersionShown(true)
                .withActivityTitle(getString(R.string.app_name))
                .withAboutIconShown(true)
                .withListener(libsListener)
                .start(MainActivity.this);
        break;*/

    case R.id.AC_Btn:
        createHistory();
        reset();
        break;
    case R.id.C_Btn:
        int start = Math.max(expression_TV.getSelectionStart(), 0);
        int end = Math.max(expression_TV.getSelectionEnd(), 0);
        if (start == end && start != 0)
            expression_TV.getText().replace(Math.min(start, end) - 1, Math.max(start, end), "", 0, 0);
        else
            expression_TV.getText().replace(Math.min(start, end), Math.max(start, end), "", 0, 0);
        evaluate(expression_TV.getText().toString());
        break;

    //Memory
    case R.id.MC_Btn:
        dbAdapter = new DbAdapter(this);
        dbAdapter.open();
        dbAdapter.deleteAllMemories();
        Toast clearmem = Toast.makeText(Calculator.this, "Memory Cleared!", Toast.LENGTH_SHORT);
        clearmem.show();
        fillData();
        break;
    case R.id.MR_Btn:
        dbAdapter = new DbAdapter(this);
        dbAdapter.open();
        fillData();
        String mem = dbAdapter.memoryRetrieve();
        if (mem.equals("xyz")) {
            Toast toast = Toast.makeText(Calculator.this, "No Memory Yet!", Toast.LENGTH_SHORT);
            toast.show();
        } else
            insert(dbAdapter.memoryRetrieve());
        break;
    case R.id.MS_Btn:
        createMemory();
        Toast savemem = Toast.makeText(Calculator.this, "New Memory Saved!", Toast.LENGTH_SHORT);
        savemem.show();
        break;
    //case R.id.sci_M_Btn:
    //case R.id.curr_M_Btn:
    /*case R.id.conv_M_Btn:
    dbAdapter = new DbAdapter(this);
    dbAdapter.open();
    fillData();
    if (memoryLayout.getVisibility() == View.GONE) {
        memoryLayout.setVisibility(View.VISIBLE);
        myBtn.setTextColor(primary_text_color);
        myBtn.setBackgroundColor(primary_color);
        try {
            fav_List_LL.setVisibility(View.GONE);
            favBtn.setTextColor(sec_text_color);
            favBtn.setBackgroundColor(sec_color);
        } catch (Exception e) {
            //
        }
        *//*try {
             constantsList.setVisibility(View.GONE);
             constBtn.setTextColor(sec_text_color);
             constBtn.setBackgroundColor(sec_color);
             sciFunLayout.setVisibility(View.GONE);
             funcBtn.setTextColor(sec_text_color);
             funcBtn.setBackgroundColor(sec_color);
           } catch (Exception e) {
             //
           }*//*
               simplePad.setVisibility(View.GONE);
               hyBtn.setTextColor(sec_text_color);
               hyBtn.setBackgroundColor(sec_color);
               historyLayout.setVisibility(View.GONE);
               } else {
               myBtn.setTextColor(sec_text_color);
               myBtn.setBackgroundColor(sec_color);
               memoryLayout.setVisibility(View.GONE);
               simplePad.setVisibility(View.VISIBLE);
               }
               break;*/

    //case R.id.curr_fav_Btn:
    //case R.id.conv_fav_Btn:
    /*dbAdapter = new DbAdapter(this);
    dbAdapter.open();
    fillData();
    if (fav_List_LL.getVisibility() == View.GONE) {
        fav_List_LL.setVisibility(View.VISIBLE);
        try {
            memoryLayout.setVisibility(View.GONE);
            myBtn.setTextColor(sec_text_color);
            myBtn.setBackgroundColor(sec_color);
        } catch (Exception e) {
            //
        }
        favBtn.setTextColor(primary_text_color);
        favBtn.setBackgroundColor(primary_color);
        simplePad.setVisibility(View.GONE);
        hyBtn.setTextColor(sec_text_color);
        hyBtn.setBackgroundColor(sec_color);
        historyLayout.setVisibility(View.GONE);
    } else {
        fav_List_LL.setVisibility(View.GONE);
        favBtn.setTextColor(sec_text_color);
        favBtn.setBackgroundColor(sec_color);
        simplePad.setVisibility(View.VISIBLE);
    }
    break;*/

    /*case R.id.constants_Btn:
        dataBaseHelper = new DataBaseHelper(this);
        try {
            dataBaseHelper.createDataBase();
        } catch (IOException ioe) {
            throw new Error("Unable to create database");
        }
        dataBaseHelper.openDataBase();
        dataSource = new DataSource(this);
        dataSource.open();
        if (constantsList.getVisibility() == View.GONE) {
            constantsList.setVisibility(View.VISIBLE);
            constBtn.setTextColor(primary_text_color);
            constBtn.setBackgroundColor(primary_color);
            memoryLayout.setVisibility(View.GONE);
            myBtn.setTextColor(sec_text_color);
            myBtn.setBackgroundColor(sec_color);
            hyBtn.setTextColor(sec_text_color);
            hyBtn.setBackgroundColor(sec_color);
            historyLayout.setVisibility(View.GONE);
            try {
                sciFunLayout.setVisibility(View.GONE);
                funcBtn.setTextColor(sec_text_color);
                funcBtn.setBackgroundColor(sec_color);
            } catch (Exception e) {
                //
            }
            simplePad.setVisibility(View.GONE);
        } else {
            constantsList.setVisibility(View.GONE);
            constBtn.setTextColor(sec_text_color);
            constBtn.setBackgroundColor(sec_color);
            simplePad.setVisibility(View.VISIBLE);
        }
        try {
            Cursor c = dataSource.getConstants();
            startManagingCursor(c);
            
            String[] fro = new String[]{DataBaseHelper.COLUMN_NAME, DataBaseHelper.COLUMN_SYMBOL, DataBaseHelper.COLUMN_VALUE, DataBaseHelper.COLUMN_DIMENSION};
            int[] too = new int[]{R.id.text11, R.id.text12, R.id.text21, R.id.text22};
            
            SimpleCursorAdapter constants =
                    new SimpleCursorAdapter(this, R.layout.constants_row, c, fro, too);
            constantsList.setAdapter(constants);
            constantsList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    Cursor obj = (Cursor) constantsList.getItemAtPosition(position);
                    insert(obj.getString(3));
                }
            });
        } catch (Exception e) {
            //
        }
        break;
            
    case R.id.functions_Btn:
        if (sciFunLayout.getVisibility() == View.GONE) {
            funcBtn.setTextColor(primary_text_color);
            funcBtn.setBackgroundColor(primary_color);
            sciFunLayout.setVisibility(View.VISIBLE);
            memoryLayout.setVisibility(View.GONE);
            myBtn.setTextColor(sec_text_color);
            myBtn.setBackgroundColor(sec_color);
            hyBtn.setTextColor(sec_text_color);
            hyBtn.setBackgroundColor(sec_color);
            historyLayout.setVisibility(View.GONE);
            simplePad.setVisibility(View.GONE);
            constantsList.setVisibility(View.GONE);
            constBtn.setTextColor(sec_text_color);
            constBtn.setBackgroundColor(sec_color);
        } else {
            funcBtn.setTextColor(sec_text_color);
            funcBtn.setBackgroundColor(sec_color);
            sciFunLayout.setVisibility(View.GONE);
            simplePad.setVisibility(View.VISIBLE);
        }
        break;*/

    case R.id.conv_swap_Btn:
    case R.id.curr_swap_Btn:
        if (page_no == 4) {
            int temp = from.getSelectedItemPosition();
            from.setSelection(to.getSelectedItemPosition());
            to.setSelection(temp);
        } else {
            SharedPreferences settings = getSharedPreferences("MyPrefs", 0);
            Float rate = settings.getFloat("rate", 0);
            SharedPreferences.Editor editor = settings.edit();
            editor.putFloat("rate", 1 / rate);
            editor.apply();
            rate = 1 / rate;
            result_TV.setText("1");
            resultant_TV.setText(rate.toString());
            int temp = fro.getSelectedItemPosition();
            fro.setSelection(too.getSelectedItemPosition());
            too.setSelection(temp);
        }
        break;

    //Operators
    case R.id.leftBracket_Btn:
    case R.id.rightBracket_Btn:
    case R.id.add_Btn:
    case R.id.sub_Btn:
        //case R.id.factorial_Btn:
        // case R.id.imagine_Btn:
        //Numbers
    case R.id.dot_Btn:
    case R.id.Btn_0:
    case R.id.Btn_1:
    case R.id.Btn_2:
    case R.id.Btn_3:
    case R.id.Btn_4:
    case R.id.Btn_5:
    case R.id.Btn_6:
    case R.id.Btn_7:
    case R.id.Btn_8:
    case R.id.Btn_9:
        insert(btnText);
        break;
    case R.id.div_Btn:
        insert("/");
        break;
    case R.id.mul_Btn:
        insert("*");
        break;

    /*//Hex
    case R.id.A_Btn:
    case R.id.B_Btn:
    case R.id.C_hex_Btn:
    case R.id.D_Btn:
    case R.id.E_Btn:
    case R.id.F_Btn:
        insert(btnText);
        break;
    //Functions
    case R.id.abs_Btn:
    case R.id.ceil_Btn:
    case R.id.cos_Btn:
    case R.id.cosh_Btn:
    case R.id.exp_Btn:
    case R.id.floor_Btn:
    case R.id.log_Btn:
    case R.id.log10_Btn:
    case R.id.log2_Btn:
    case R.id.sin_Btn:
    case R.id.sinh_Btn:
    case R.id.tan_Btn:
    case R.id.tanh_Btn:
        insert(btnText + "(");
        break;
            
    case R.id.deg_Btn:
        insert("*" + getResources().getString(R.string.pi) + "/180");
        break;
            
    case R.id.acos_Btn:
        insert("acos(");
        break;
    case R.id.asin_Btn:
        insert("asin(");
        break;
    case R.id.atan_Btn:
        insert("atan(");
        break;
    case R.id.acosd_Btn:
        insert("acosd(");
        break;
    case R.id.acosh_Btn:
        insert("acosh(");
        break;
    case R.id.asind_Btn:
        insert("asind(");
        break;
    case R.id.sind_Btn:
        insert("sind(");
        break;
    case R.id.asinh_Btn:
        insert("asinh(");
        break;
    case R.id.cosd_Btn:
        insert("cosd(");
        break;
    case R.id.tand_Btn:
        insert("tand(");
        break;
    case R.id.atand_Btn:
        insert("atand(");
        break;
    case R.id.atanh_Btn:
        insert("atanh(");
        break;
            
    case R.id.root_Btn:
        insert("sqrt(");
        break;
            
    case R.id.cbrt_Btn:
        insert("cbrt(");
        break;
            
    case R.id.reciprocal_Btn:
        expression_TV.getText().replace(0, 0, "1/(", 0, 3);
        break;*/

    case R.id.percent_Btn:
        insert("%");
        break;

    /*case R.id.e_Btn:
        insert("2.7182818285");
        break;
            
    case R.id.pi_Btn:
        insert(btnText);
        break;*/

    case R.id.power_Btn:
        insert(btnText);
        break;

    case R.id.equals_Btn:
        done = true;
        evaluate(expression_TV.getText().toString());
        createHistory();
        try {
            expression_TV.setText("");
            insert(result_TV.getText().toString());
            result_TV.setText("0");
        } catch (RuntimeException ee) {
            //
        }
        break;

    /*case R.id.dec_Btn:
        try {
            decBtn.setBackgroundColor(sec_color);
            decBtn.setTextColor(sec_text_color);
            hexBtn.setBackgroundColor(primary_color);
            hexBtn.setTextColor(primary_text_color);
            octBtn.setBackgroundColor(primary_color);
            octBtn.setTextColor(primary_text_color);
            binBtn.setBackgroundColor(primary_color);
            binBtn.setTextColor(primary_text_color);
            decTV.setBackgroundColor(sec_color);
            decTV.setTextColor(sec_text_color);
            hexTV.setBackgroundColor(primary_color);
            hexTV.setTextColor(primary_text_color);
            octTV.setBackgroundColor(primary_color);
            octTV.setTextColor(primary_text_color);
            binTV.setBackgroundColor(primary_color);
            binTV.setTextColor(primary_text_color);
            expression_TV.setText("");
            insert(changeBase(expression, base, Base.DECIMAL));
            base = Base.DECIMAL;
        } catch (SyntaxException S) {
            Toast.makeText(getApplicationContext(), S.toString(), Toast.LENGTH_SHORT).show();
        }
        break;
    case R.id.hex_Btn:
        try {
            decBtn.setBackgroundColor(primary_color);
            decBtn.setTextColor(primary_text_color);
            hexBtn.setBackgroundColor(sec_color);
            hexBtn.setTextColor(sec_text_color);
            octBtn.setBackgroundColor(primary_color);
            octBtn.setTextColor(primary_text_color);
            binBtn.setBackgroundColor(primary_color);
            binBtn.setTextColor(primary_text_color);
            decTV.setBackgroundColor(primary_color);
            decTV.setTextColor(primary_text_color);
            hexTV.setBackgroundColor(sec_color);
            hexTV.setTextColor(sec_text_color);
            octTV.setBackgroundColor(primary_color);
            octTV.setTextColor(primary_text_color);
            binTV.setBackgroundColor(primary_color);
            binTV.setTextColor(primary_text_color);
            expression_TV.setText("");
            insert(changeBase(expression, base, Base.HEXADECIMAL));
            base = Base.HEXADECIMAL;
        } catch (SyntaxException S) {
            Toast.makeText(getApplicationContext(), S.toString(), Toast.LENGTH_SHORT).show();
        }
        break;
    case R.id.oct_Btn:
        try {
            decBtn.setBackgroundColor(primary_color);
            decBtn.setTextColor(primary_text_color);
            hexBtn.setBackgroundColor(primary_color);
            hexBtn.setTextColor(primary_text_color);
            octBtn.setBackgroundColor(sec_color);
            octBtn.setTextColor(sec_text_color);
            binBtn.setBackgroundColor(primary_color);
            binBtn.setTextColor(primary_text_color);
            decTV.setBackgroundColor(primary_color);
            decTV.setTextColor(primary_text_color);
            hexTV.setBackgroundColor(primary_color);
            hexTV.setTextColor(primary_text_color);
            octTV.setBackgroundColor(sec_color);
            octTV.setTextColor(sec_text_color);
            binTV.setBackgroundColor(primary_color);
            binTV.setTextColor(primary_text_color);
            expression_TV.setText("");
            insert(changeBase(expression, base, Base.OCTAL));
            base = Base.OCTAL;
        } catch (SyntaxException S) {
            Toast.makeText(getApplicationContext(), S.toString(), Toast.LENGTH_SHORT).show();
        }
        break;
    case R.id.bin_Btn:
        try {
            decBtn.setBackgroundColor(primary_color);
            decBtn.setTextColor(primary_text_color);
            hexBtn.setBackgroundColor(primary_color);
            hexBtn.setTextColor(primary_text_color);
            octBtn.setBackgroundColor(primary_color);
            octBtn.setTextColor(primary_text_color);
            binBtn.setBackgroundColor(sec_color);
            binBtn.setTextColor(sec_text_color);
            decTV.setBackgroundColor(primary_color);
            decTV.setTextColor(primary_text_color);
            hexTV.setBackgroundColor(primary_color);
            hexTV.setTextColor(primary_text_color);
            octTV.setBackgroundColor(primary_color);
            octTV.setTextColor(primary_text_color);
            binTV.setBackgroundColor(sec_color);
            binTV.setTextColor(sec_text_color);
            expression_TV.setText("");
            insert(changeBase(expression, base, Base.BINARY));
            base = Base.BINARY;
        } catch (SyntaxException S) {
            Toast.makeText(getApplicationContext(), S.toString(), Toast.LENGTH_SHORT).show();
        }
        break;
            
    default:
        break;
    }
    try {
        if (v.getId() != R.id.AC_Btn) {
            result_TV.resizeText();
            try {
                resultant_TV.resizeText();
            } catch (Exception e) {
                //
            }
        }
            
    } catch (Exception eeee) {
        //
    }*/
    }
}