package com.Tricot.calcutator.Calculator1pager.Calculator1;

import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.Tricot.calcutator.CalculatorMenu.Bar_select;
import com.Tricot.calcutator.R;
import com.Tricot.calcutator.data.Calculation1_pager;

import java.text.DecimalFormat;

public class Calcul7pager extends Fragment {
    ImageView FinishBtn;
    EditText rack_gague1;
    EditText rack_density1;
    EditText rack_texture1;
    EditText rack_denier1;
    EditText rack_denier2;
    EditText rack_denier3;
    EditText rack_gague2;
    EditText rack_density2;
    EditText rack_texture2;
    EditText rack_gague3;
    EditText rack_density3;
    EditText rack_texture3;
    EditText firstgauge;
    String formattedStringPrice;
    private boolean isFirstSelected = true; // 전역변수로 선언


    public Calcul7pager(){



    }
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.content_calculator_1_7, container, false);
        return rootView;
    }

    public void onViewCreated(final View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        rack_gague1=(EditText)view.findViewById(R.id.rack_gauge1);
        rack_gague2=(EditText)view.findViewById(R.id.rack_gauge2);
        rack_gague3=(EditText)view.findViewById(R.id.rack_gauge3);
        rack_density1=(EditText)view.findViewById(R.id.rack_density1);
        rack_density2=(EditText)view.findViewById(R.id.rack_density2);
        rack_density3=(EditText)view.findViewById(R.id.rack_density3);
        rack_texture1=(EditText)view.findViewById(R.id.rack_texture1);
        rack_texture2=(EditText)view.findViewById(R.id.rack_texture2);
        rack_texture3=(EditText)view.findViewById(R.id.rack_texture3);
        rack_denier1=(EditText)view.findViewById(R.id.rack_denier1);
        rack_denier2=(EditText)view.findViewById(R.id.rack_denier2);
        rack_denier3=(EditText)view.findViewById(R.id.rack_denier3);
        final DecimalFormat myFormatter= new DecimalFormat("###,###");
        FinishBtn=view.findViewById(R.id.backImg);
        FinishBtn.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v) {
                getActivity().finish();
            }
        });

        Spinner spinner = (Spinner)view.findViewById(R.id.spinner);
        spinner.setSelection(6);
        spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                System.out.println("-------------------------");
                System.out.println(position);
                System.out.println("-------------------------");

                if(isFirstSelected){
                    isFirstSelected=false;
                }else{
                    if(position==0){
                        Intent intent = new Intent(getActivity(), Bar_select.class);
                        intent.putExtra("menu",1);
                        intent.putExtra("pages",0);
                        startActivity(intent);
                        getActivity().finish();
                    }else if(position==1){
                        Intent intent = new Intent(getActivity(), Calculation1_pager.class);
                        intent.putExtra("pages",1);
                        startActivity(intent);
                        getActivity().finish();
                    }else if(position==2){
                        Intent intent = new Intent(getActivity(), Bar_select.class);
                        intent.putExtra("pages",2);
                        intent.putExtra("menu",1);
                        startActivity(intent);
                        getActivity().finish();
                    }else if(position==3){
                        Intent intent = new Intent(getActivity(), Bar_select.class);
                        intent.putExtra("pages",3);
                        intent.putExtra("menu",1);
                        startActivity(intent);
                        getActivity().finish();
                    }else if(position==4){
                        Intent intent = new Intent(getActivity(), Calculation1_pager.class);
                        intent.putExtra("pages",4);
                        startActivity(intent);
                        getActivity().finish();
                    }else if(position==5){
                        Intent intent = new Intent(getActivity(), Calculation1_pager.class);
                        intent.putExtra("pages",5);
                        startActivity(intent);
                        getActivity().finish();
                    }else if(position==6){
                        Intent intent = new Intent(getActivity(), Calculation1_pager.class);
                        intent.putExtra("pages",6);
                        startActivity(intent);
                        getActivity().finish();
                    }else if(position==7){
                        Intent intent = new Intent(getActivity(), Calculation1_pager.class);
                        intent.putExtra("pages",7);
                        startActivity(intent);
                        getActivity().finish();
                    }else if(position==8){
                        Intent intent = new Intent(getActivity(), Calculation1_pager.class);
                        intent.putExtra("pages",8);
                        startActivity(intent);
                        getActivity().finish();
                    }
                    else if(position==9){
                        Intent intent = new Intent(getActivity(), Calculation1_pager.class);
                        intent.putExtra("pages",9);
                        startActivity(intent);
                        getActivity().finish();
                    }
                    else if(position==10){
                        Intent intent = new Intent(getActivity(), Calculation1_pager.class);
                        intent.putExtra("pages",10);
                        startActivity(intent);
                        getActivity().finish();
                    }else if(position==11){
                        Intent intent = new Intent(getActivity(), Calculation1_pager.class);
                        intent.putExtra("pages",11);
                        startActivity(intent);
                        getActivity().finish();
                    }
                }


            }

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

            }
        });

        rack_gague1.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }

            @Override
            public void afterTextChanged(Editable s) {
                if(rack_gague1.getText().toString().length()!=0&&rack_gague1.getText().toString().length()!=0){
                    firstgauge = view.findViewById(R.id.rack_gauge1);
                    EditText density =view.findViewById(R.id.rack_density1);
                    EditText texture = view.findViewById(R.id.rack_texture1);
                    EditText denier = view.findViewById(R.id.rack_denier1);
                    TextView rack_mm = view.findViewById(R.id.rack_mm);
                    try {
                        float rack_gauge = Float.parseFloat(firstgauge.getText().toString());
                        float rack_density = Float.parseFloat(density.getText().toString());
                        float rack_texture = Float.parseFloat(texture.getText().toString());
                        float rack_denier = Float.parseFloat(denier.getText().toString());
                        double cal_gauge = 25.4 / rack_gauge;
                        double cal_gauge2 = cal_gauge * cal_gauge;

                        double cal_density = 10/rack_density;
                        double cal_density2 = cal_density * cal_density;

                        double cal_texture = rack_texture * rack_texture;

                        double cal_denier = 0.01114 * Math.sqrt(rack_denier);
                        double cal_denier2 = cal_denier * cal_denier;

                        double course = Math.sqrt((cal_density2 + (cal_texture * cal_gauge2))) + 2.05 * Math.sqrt((cal_density2 + (cal_texture * cal_denier2))) + (7.28 * cal_denier);
                        double cal_rackmm = course * 480;

                        double cal_rackmm2 = Math.round(cal_rackmm);
                        formattedStringPrice=myFormatter.format(cal_rackmm2);
                        rack_mm.setText(formattedStringPrice + "R/mm2");

                    } catch (NumberFormatException e) {
                    }
                }
            }

        });
        rack_gague2.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }

            @Override
            public void afterTextChanged(Editable s) {
                if(rack_gague2.getText().toString().length()!=0&&rack_gague2.getText().toString().length()!=0){
                    EditText gauge = view.findViewById(R.id.rack_gauge2);
                    EditText density = view.findViewById(R.id.rack_density2);
                    EditText texture = view.findViewById(R.id.rack_texture2);
                    EditText denier = view.findViewById(R.id.rack_denier2);
                    TextView rack_mm = view.findViewById(R.id.rack_mm2);

                    try {
                        float rack_gauge = Float.parseFloat(gauge.getText().toString());
                        float rack_density = Float.parseFloat(density.getText().toString());
                        float rack_texture = Float.parseFloat(texture.getText().toString());
                        float rack_denier = Float.parseFloat(denier.getText().toString());

                        double cal_gauge = 25.4 / rack_gauge;
                        double cal_gauge2 = cal_gauge * cal_gauge;

                        double cal_density = 10 / rack_density;
                        double cal_density2 = cal_density * cal_density;

                        double cal_texture = rack_texture * rack_texture;

                        double cal_denier = 0.01371 * Math.sqrt(rack_denier);
                        double cal_denier2 = cal_denier * cal_denier;

                        double course = Math.sqrt((cal_density2 + (cal_texture * cal_gauge2))) + 2.05 * Math.sqrt((cal_density2 + (cal_texture * cal_denier2))) + (7.28 * cal_denier);
                        double cal_rackmm = course * 480;

                        double cal_rackmm2 = Math.round(cal_rackmm);
                        formattedStringPrice=myFormatter.format(cal_rackmm2);
                        rack_mm.setText(formattedStringPrice + "R/mm");
                    } catch (NumberFormatException e) {
                    }
                }
            }

        });
        rack_gague3.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }

            @Override
            public void afterTextChanged(Editable s) {
                if(rack_gague3.getText().toString().length()!=0&&rack_gague3.getText().toString().length()!=0){
                    EditText gauge = view.findViewById(R.id.rack_gauge3);
                    EditText density = view.findViewById(R.id.rack_density3);
                    EditText texture = view.findViewById(R.id.rack_texture3);
                    EditText denier = view.findViewById(R.id.rack_denier3);
                    TextView rack_mm = view.findViewById(R.id.rack_mm3);

                    try {
                        float rack_gauge = Float.parseFloat(gauge.getText().toString());
                        float rack_density = Float.parseFloat(density.getText().toString());
                        float rack_texture = Float.parseFloat(texture.getText().toString());
                        float rack_denier = Float.parseFloat(denier.getText().toString());

                        double cal_gauge = 25.4 / rack_gauge;
                        double cal_gauge2 = cal_gauge * cal_gauge;

                        double cal_density = 10 / rack_density;
                        double cal_density2 = cal_density * cal_density;

                        double cal_texture = rack_texture * rack_texture;

                        double cal_denier = 0.019 * Math.sqrt((12 * rack_denier) - 3) / 3;
                        double cal_denier2 = cal_denier * cal_denier;

                        double course = Math.sqrt((cal_density2 + (cal_texture * cal_gauge2))) + 2.05 * Math.sqrt((cal_density2 + (cal_texture * cal_denier2))) + (7.28 * cal_denier);
                        double cal_rackmm = course * 480;

                        double cal_rackmm2 = Math.round(cal_rackmm);
                        formattedStringPrice=myFormatter.format(cal_rackmm2);
                        rack_mm.setText(formattedStringPrice + "R/mm");
                    } catch (NumberFormatException e) {
                    }
                }
            }

        });

        rack_density1.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }

            @Override
            public void afterTextChanged(Editable s) {
                if(rack_density1.getText().toString().length()!=0&&rack_density1.getText().toString().length()!=0){
                    firstgauge = view.findViewById(R.id.rack_gauge1);
                    EditText density =view.findViewById(R.id.rack_density1);
                    EditText texture = view.findViewById(R.id.rack_texture1);
                    EditText denier = view.findViewById(R.id.rack_denier1);
                    TextView rack_mm = view.findViewById(R.id.rack_mm);
                    try {
                        float rack_gauge = Float.parseFloat(firstgauge.getText().toString());
                        float rack_density = Float.parseFloat(density.getText().toString());
                        float rack_texture = Float.parseFloat(texture.getText().toString());
                        float rack_denier = Float.parseFloat(denier.getText().toString());

                        double cal_gauge = 25.4 / rack_gauge;
                        double cal_gauge2 = cal_gauge * cal_gauge;

                        double cal_density = 10/rack_density;
                        double cal_density2 = cal_density * cal_density;

                        double cal_texture = rack_texture * rack_texture;

                        double cal_denier = 0.01114 * Math.sqrt(rack_denier);
                        double cal_denier2 = cal_denier * cal_denier;

                        double course = Math.sqrt((cal_density2 + (cal_texture * cal_gauge2))) + 2.05 * Math.sqrt((cal_density2 + (cal_texture * cal_denier2))) + (7.28 * cal_denier);
                        double cal_rackmm = course * 480;

                        double cal_rackmm2 = Math.round(cal_rackmm);
                        formattedStringPrice=myFormatter.format(cal_rackmm2);
                        rack_mm.setText(formattedStringPrice + "R/mm");
                    } catch (NumberFormatException e) {
                    }
                }
            }

        });
        rack_density2.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }

            @Override
            public void afterTextChanged(Editable s) {
                if(rack_density2.getText().toString().length()!=0&&rack_density2.getText().toString().length()!=0){
                    EditText gauge = view.findViewById(R.id.rack_gauge2);
                    EditText density = view.findViewById(R.id.rack_density2);
                    EditText texture = view.findViewById(R.id.rack_texture2);
                    EditText denier = view.findViewById(R.id.rack_denier2);
                    TextView rack_mm = view.findViewById(R.id.rack_mm2);

                    try {
                        float rack_gauge = Float.parseFloat(gauge.getText().toString());
                        float rack_density = Float.parseFloat(density.getText().toString());
                        float rack_texture = Float.parseFloat(texture.getText().toString());
                        float rack_denier = Float.parseFloat(denier.getText().toString());

                        double cal_gauge = 25.4 / rack_gauge;
                        double cal_gauge2 = cal_gauge * cal_gauge;

                        double cal_density = 10 / rack_density;
                        double cal_density2 = cal_density * cal_density;

                        double cal_texture = rack_texture * rack_texture;

                        double cal_denier = 0.01371 * Math.sqrt(rack_denier);
                        double cal_denier2 = cal_denier * cal_denier;

                        double course = Math.sqrt((cal_density2 + (cal_texture * cal_gauge2))) + 2.05 * Math.sqrt((cal_density2 + (cal_texture * cal_denier2))) + (7.28 * cal_denier);
                        double cal_rackmm = course * 480;

                        double cal_rackmm2 = Math.round(cal_rackmm);
                        formattedStringPrice=myFormatter.format(cal_rackmm2);
                        rack_mm.setText(formattedStringPrice + "R/mm");
                    } catch (NumberFormatException e) {
                    }
                }
            }

        });
        rack_density3.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }

            @Override
            public void afterTextChanged(Editable s) {
                if(rack_density3.getText().toString().length()!=0&&rack_density3.getText().toString().length()!=0){
                    EditText gauge = view.findViewById(R.id.rack_gauge3);
                    EditText density = view.findViewById(R.id.rack_density3);
                    EditText texture = view.findViewById(R.id.rack_texture3);
                    EditText denier = view.findViewById(R.id.rack_denier3);
                    TextView rack_mm = view.findViewById(R.id.rack_mm3);

                    try {
                        float rack_gauge = Float.parseFloat(gauge.getText().toString());
                        float rack_density = Float.parseFloat(density.getText().toString());
                        float rack_texture = Float.parseFloat(texture.getText().toString());
                        float rack_denier = Float.parseFloat(denier.getText().toString());

                        double cal_gauge = 25.4 / rack_gauge;
                        double cal_gauge2 = cal_gauge * cal_gauge;

                        double cal_density = 10 / rack_density;
                        double cal_density2 = cal_density * cal_density;

                        double cal_texture = rack_texture * rack_texture;

                        double cal_denier = 0.019 * Math.sqrt((12 * rack_denier) - 3) / 3;
                        double cal_denier2 = cal_denier * cal_denier;

                        double course = Math.sqrt((cal_density2 + (cal_texture * cal_gauge2))) + 2.05 * Math.sqrt((cal_density2 + (cal_texture * cal_denier2))) + (7.28 * cal_denier);
                        double cal_rackmm = course * 480;

                        double cal_rackmm2 = Math.round(cal_rackmm);
                        formattedStringPrice=myFormatter.format(cal_rackmm2);
                        rack_mm.setText(formattedStringPrice + "R/mm");
                    } catch (NumberFormatException e) {
                    }
                }
            }

        });

        rack_denier1.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }

            @Override
            public void afterTextChanged(Editable s) {
                if(rack_denier1.getText().toString().length()!=0&&rack_denier1.getText().toString().length()!=0){
                    firstgauge = view.findViewById(R.id.rack_gauge1);
                    EditText density =view.findViewById(R.id.rack_density1);
                    EditText texture = view.findViewById(R.id.rack_texture1);
                    EditText denier = view.findViewById(R.id.rack_denier1);
                    TextView rack_mm = view.findViewById(R.id.rack_mm);
                    try {
                        float rack_gauge = Float.parseFloat(firstgauge.getText().toString());
                        float rack_density = Float.parseFloat(density.getText().toString());
                        float rack_texture = Float.parseFloat(texture.getText().toString());
                        float rack_denier = Float.parseFloat(denier.getText().toString());

                        double cal_gauge = 25.4 / rack_gauge;
                        double cal_gauge2 = cal_gauge * cal_gauge;

                        double cal_density = 10/rack_density;
                        double cal_density2 = cal_density*cal_density;

                        double cal_texture = rack_texture * rack_texture;

                        double cal_denier = 0.01114 * Math.sqrt(rack_denier);
                        double cal_denier2 = cal_denier * cal_denier;

                        double course = Math.sqrt((cal_density2 + (cal_texture * cal_gauge2))) + 2.05 * Math.sqrt((cal_density2 + (cal_texture * cal_denier2))) + (7.28 * cal_denier);
                        double cal_rackmm = course * 480;

                        double cal_rackmm2 = Math.round(cal_rackmm);
                        formattedStringPrice=myFormatter.format(cal_rackmm2);
                        rack_mm.setText(formattedStringPrice + "R/mm");
                    } catch (NumberFormatException e) {
                    };
                }
            }

        });
        rack_denier2.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }

            @Override
            public void afterTextChanged(Editable s) {
                if(rack_denier2.getText().toString().length()!=0&&rack_denier2.getText().toString().length()!=0){
                    EditText gauge = view.findViewById(R.id.rack_gauge2);
                    EditText density = view.findViewById(R.id.rack_density2);
                    EditText texture = view.findViewById(R.id.rack_texture2);
                    EditText denier = view.findViewById(R.id.rack_denier2);
                    TextView rack_mm = view.findViewById(R.id.rack_mm2);

                    try {
                        float rack_gauge = Float.parseFloat(gauge.getText().toString());
                        float rack_density = Float.parseFloat(density.getText().toString());
                        float rack_texture = Float.parseFloat(texture.getText().toString());
                        float rack_denier = Float.parseFloat(denier.getText().toString());

                        double cal_gauge = 25.4 / rack_gauge;
                        double cal_gauge2 = cal_gauge * cal_gauge;

                        double cal_density = 10 / rack_density;
                        double cal_density2 = cal_density * cal_density;

                        double cal_texture = rack_texture * rack_texture;

                        double cal_denier = 0.01371 * Math.sqrt(rack_denier);
                        double cal_denier2 = cal_denier * cal_denier;

                        double course = Math.sqrt((cal_density2 + (cal_texture * cal_gauge2))) + 2.05 * Math.sqrt((cal_density2 + (cal_texture * cal_denier2))) + (7.28 * cal_denier);
                        double cal_rackmm = course * 480;

                        double cal_rackmm2 = Math.round(cal_rackmm);
                        formattedStringPrice=myFormatter.format(cal_rackmm2);
                        rack_mm.setText(formattedStringPrice + "R/mm");
                    } catch (NumberFormatException e) {
                    }
                }
            }

        });
        rack_denier3.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }

            @Override
            public void afterTextChanged(Editable s) {
                if(rack_denier3.getText().toString().length()!=0&&rack_denier3.getText().toString().length()!=0){
                    EditText gauge = view.findViewById(R.id.rack_gauge3);
                    EditText density = view.findViewById(R.id.rack_density3);
                    EditText texture = view.findViewById(R.id.rack_texture3);
                    EditText denier = view.findViewById(R.id.rack_denier3);
                    TextView rack_mm = view.findViewById(R.id.rack_mm3);

                    try {
                        float rack_gauge = Float.parseFloat(gauge.getText().toString());
                        float rack_density = Float.parseFloat(density.getText().toString());
                        float rack_texture = Float.parseFloat(texture.getText().toString());
                        float rack_denier = Float.parseFloat(denier.getText().toString());

                        double cal_gauge = 25.4 / rack_gauge;
                        double cal_gauge2 = cal_gauge * cal_gauge;

                        double cal_density = 10 / rack_density;
                        double cal_density2 = cal_density * cal_density;

                        double cal_texture = rack_texture * rack_texture;

                        double cal_denier = 0.019 * Math.sqrt((12 * rack_denier) - 3) / 3;
                        double cal_denier2 = cal_denier * cal_denier;

                        double course = Math.sqrt((cal_density2 + (cal_texture * cal_gauge2))) + 2.05 * Math.sqrt((cal_density2 + (cal_texture * cal_denier2))) + (7.28 * cal_denier);
                        double cal_rackmm = course * 480;

                        double cal_rackmm2 = Math.round(cal_rackmm);
                        formattedStringPrice=myFormatter.format(cal_rackmm2);
                        rack_mm.setText(formattedStringPrice + "R/mm");
                    } catch (NumberFormatException e) {
                    }
                }
            }

        });

        rack_texture1.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if(rack_texture1.getText().toString().length()!=0&&rack_texture1.getText().toString().length()!=0){
                    firstgauge = view.findViewById(R.id.rack_gauge1);
                    EditText density =view.findViewById(R.id.rack_density1);
                    EditText texture = view.findViewById(R.id.rack_texture1);
                    EditText denier = view.findViewById(R.id.rack_denier1);
                    TextView rack_mm = view.findViewById(R.id.rack_mm);
                    try {
                        float rack_gauge = Float.parseFloat(firstgauge.getText().toString());
                        float rack_density = Float.parseFloat(density.getText().toString());
                        float rack_texture = Float.parseFloat(texture.getText().toString());
                        float rack_denier = Float.parseFloat(denier.getText().toString());

                        double cal_gauge = 25.4 / rack_gauge;
                        double cal_gauge2 = cal_gauge * cal_gauge;

                        double cal_density = rack_density;
                        double cal_density2 = cal_density * cal_density;

                        double cal_texture = rack_texture * rack_texture;

                        double cal_denier = 0.01114 * Math.sqrt(rack_denier);
                        double cal_denier2 = cal_denier * cal_denier;

                        double course = Math.sqrt((cal_density2 + (cal_texture * cal_gauge2))) + 2.05 * Math.sqrt((cal_density2 + (cal_texture * cal_denier2))) + (7.28 * cal_denier);
                        double cal_rackmm = course * 480;

                        double cal_rackmm2 = Math.round(cal_rackmm);
                        formattedStringPrice=myFormatter.format(cal_rackmm2);
                        rack_mm.setText(formattedStringPrice + "R/mm");
                    } catch (NumberFormatException e) {
                    };
                }
            }

        });
        rack_texture2.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }

            @Override
            public void afterTextChanged(Editable s) {
                if(rack_texture2.getText().toString().length()!=0&&rack_texture2.getText().toString().length()!=0){
                    EditText gauge = view.findViewById(R.id.rack_gauge2);
                    EditText density = view.findViewById(R.id.rack_density2);
                    EditText texture = view.findViewById(R.id.rack_texture2);
                    EditText denier = view.findViewById(R.id.rack_denier2);
                    TextView rack_mm = view.findViewById(R.id.rack_mm2);

                    try {
                        float rack_gauge = Float.parseFloat(gauge.getText().toString());
                        float rack_density = Float.parseFloat(density.getText().toString());
                        float rack_texture = Float.parseFloat(texture.getText().toString());
                        float rack_denier = Float.parseFloat(denier.getText().toString());

                        double cal_gauge = 25.4 / rack_gauge;
                        double cal_gauge2 = cal_gauge * cal_gauge;

                        double cal_density = 10 / rack_density;
                        double cal_density2 = cal_density * cal_density;

                        double cal_texture = rack_texture * rack_texture;

                        double cal_denier = 0.01371 * Math.sqrt(rack_denier);
                        double cal_denier2 = cal_denier * cal_denier;

                        double course = Math.sqrt((cal_density2 + (cal_texture * cal_gauge2))) + 2.05 * Math.sqrt((cal_density2 + (cal_texture * cal_denier2))) + (7.28 * cal_denier);
                        double cal_rackmm = course * 480;

                        double cal_rackmm2 = Math.round(cal_rackmm);
                        formattedStringPrice=myFormatter.format(cal_rackmm2);
                        rack_mm.setText(formattedStringPrice + "R/mm");
                    } catch (NumberFormatException e) {
                    }
                }
            }

        });
        rack_texture3.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }

            @Override
            public void afterTextChanged(Editable s) {
                if(rack_texture3.getText().toString().length()!=0&&rack_texture3.getText().toString().length()!=0){
                    EditText gauge = view.findViewById(R.id.rack_gauge3);
                    EditText density = view.findViewById(R.id.rack_density3);
                    EditText texture = view.findViewById(R.id.rack_texture3);
                    EditText denier = view.findViewById(R.id.rack_denier3);
                    TextView rack_mm = view.findViewById(R.id.rack_mm3);

                    try {
                        float rack_gauge = Float.parseFloat(gauge.getText().toString());
                        float rack_density = Float.parseFloat(density.getText().toString());
                        float rack_texture = Float.parseFloat(texture.getText().toString());
                        float rack_denier = Float.parseFloat(denier.getText().toString());

                        double cal_gauge = 25.4 / rack_gauge;
                        double cal_gauge2 = cal_gauge * cal_gauge;

                        double cal_density = 10 / rack_density;
                        double cal_density2 = cal_density * cal_density;

                        double cal_texture = rack_texture * rack_texture;

                        double cal_denier = 0.019 * Math.sqrt((12 * rack_denier) - 3) / 3;
                        double cal_denier2 = cal_denier * cal_denier;

                        double course = Math.sqrt((cal_density2 + (cal_texture * cal_gauge2))) + 2.05 * Math.sqrt((cal_density2 + (cal_texture * cal_denier2))) + (7.28 * cal_denier);
                        double cal_rackmm = course * 480;

                        double cal_rackmm2 = Math.round(cal_rackmm);
                        formattedStringPrice=myFormatter.format(cal_rackmm2);
                        rack_mm.setText(formattedStringPrice + "R/mm");
                    } catch (NumberFormatException e) {

                    }
                }
            }

        });
    }
}
