package com.Tricot.calcutator.Calculator1pager.Calculator1;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Bundle;
import android.text.Editable;
import android.text.InputType;
import android.text.TextWatcher;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.TableLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;

import com.Tricot.calcutator.And_Application;
import com.Tricot.calcutator.CalculatorMenu.Bar_select;
import com.Tricot.calcutator.Calculator_pop;
import com.Tricot.calcutator.R;
import com.Tricot.calcutator.data.Calculation1_pager;
import com.Tricot.calcutator.data.OnTimePickerSerListener;

import java.util.ArrayList;
import java.util.List;

public class Calcul1pager extends Fragment {
    ImageView FinishBtn;
    ConstraintLayout cb;
    ConstraintLayout cb1;
    TableLayout tb;
    TableLayout tb1;
    Integer calcul;
    private float mScale1;
    private float mScale2;
    private float calwidth1;
    private float calwidth2;
    private float calwidth3;
    private int calheight1;
    private int calheight2;
    private EditText et1;
    private EditText et2;
    private EditText et3;
    private EditText et4;
    private TextView tbv1;
    private TextView tbv2;
    private TextView tbv3;
    private EditText first;
    private EditText autoEdit;
    private int a;
    private int b;
    private int c;
    private int second;
    private List list;
    EditText[] SecondEdit;
    EditText[] ThirdEdit;
    EditText[] QuadEdit;
    Integer secondnum = 201;
    Integer thirdnum = 301;
    Integer quad=401;
    List list1;
    List list2;
    List list3;
    private int bar;
    private int page;
    private int sum = 0;
    private int sum3 = 0;
    private int sum2;
    private int o=0;
    int cal1_1;
    int cal1_3;
    int cal1_4;
    double change_num;
    int ym_switch;
    EditText[] cal1_1_mil;
    EditText[] cal1_1_rock;
    EditText[] cal1_1_bon;
    EditText[] cal1_1_deni;
    int cal1_mil = 101;
    int cal1_rock = 201;
    int cal1_bon = 301;
    int cal1_deni = 401;
    static private String SHARE_NAME = "SHARE_PREF";
    static SharedPreferences sharePref = null;
    static SharedPreferences.Editor editor = null;
    Boolean onOff=false;
    private boolean isFirstSelected = true; // 전역변수로 선언
    String strColor = "#001E68";

    private OnTimePickerSerListener onTimePickerSerListener;

    public Calcul1pager(){

    }



    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        sharePref=getContext().getSharedPreferences(SHARE_NAME,Context.MODE_PRIVATE);
        editor = sharePref.edit();
        onOff=sharePref.getBoolean("onOff",false);
        if(onOff==false){
            Intent intent = new Intent(this.getContext(), Calculator_pop.class);
            startActivity(intent);
        }else{
        }
    }

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

        return rootView;
    }
    public void onViewCreated(final View view, Bundle savedInstanceState){
        super.onViewCreated(view, savedInstanceState);
        bar = getActivity().getIntent().getExtras().getInt("bars");
        page = getActivity().getIntent().getExtras().getInt("pages");
        change_num=((And_Application)getActivity().getApplication()).getConversion_ym();
        ym_switch=((And_Application)getActivity().getApplication()).getYm_switch();
        cal1_1_mil = new EditText[bar];
        cal1_1_rock = new EditText[bar];
        cal1_1_bon = new EditText[bar];
        cal1_1_deni = new EditText[bar];


        FinishBtn=view.findViewById(R.id.backImg);
        FinishBtn.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v) {
                getActivity().finish();
            }
        });
      //  String[] str= getResources().getStringArray((R.array.title_array1));
       // final ArrayAdapter<String> adapter =new ArrayAdapter<String>(getActivity(), R.layout.content_calculator_1_1,, str);

        Spinner spinner = (Spinner)view.findViewById(R.id.spinner);
        spinner.setSelection(0);
        //spinner.setAdapter(adapter);
                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);
                            }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) {

            }
        });

        if(bar!=0&&page==0){
            calcul = bar;
            tb = view.findViewById(R.id.table1);
            tb1 = view.findViewById(R.id.table2);
            list = new ArrayList();
            list1 = new ArrayList();
            list2 = new ArrayList();
            list3 = new ArrayList();
            int z=0;
            a=70;
            b=40;
            c=90;
            mScale1=getResources().getDisplayMetrics().density;
            calwidth1= (float)0.2;
            calwidth2 = (float)0.333;
            calheight1=(int)(b*mScale1);
            calheight2=(int)(c*mScale1);

            list.add(101);
            for (int i = 1; i <=calcul; i++) {
                ConstraintLayout row= new ConstraintLayout(getContext());
                ConstraintLayout row1 = new ConstraintLayout(getContext());
                TextView tv = new TextView(getContext());
                tbv1 = new TextView(getContext());
                tbv2 = new TextView(getContext());
                tbv3 = new TextView(getContext());
                int b=116;
                float mScale2=getResources().getDisplayMetrics().density;
                et1 = new EditText(getContext());
                et2 = new EditText(getContext());
                et3 = new EditText(getContext());
                et4 = new EditText(getContext());
                et1.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
                et2.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
                et3.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
                et4.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
                /*------------------------------------------
                et1.setLayoutParams(layparms1);
                et2.setLayoutParams(layparms2);
                et3.setLayoutParams(layparms3);
                et4.setLayoutParams(layparms4);
                ------------------------------------------*/
                et1.setIncludeFontPadding(false);
                et2.setIncludeFontPadding(false);
                et3.setIncludeFontPadding(false);
                et4.setIncludeFontPadding(false);
                tv.setIncludeFontPadding(false);
                tv.setBackground(ContextCompat.getDrawable(getContext(),R.drawable.border2));
                et1.setBackground(ContextCompat.getDrawable(getContext(),R.drawable.border2));
                et2.setBackground(ContextCompat.getDrawable(getContext(),R.drawable.border2));
                et3.setBackground(ContextCompat.getDrawable(getContext(),R.drawable.border2));
                et4.setBackground(ContextCompat.getDrawable(getContext(),R.drawable.border2));
                String strColor = "#000000";
                tv.setTextColor(Color.parseColor(strColor));
                /*
                if(ym_switch==0){
                    et1.setHint("Meter");
                }else{
                    et1.setHint("Yard");
                }*/
                tv.setId(1000+i);
                tv.setGravity(Gravity.CENTER);
                tv.setHeight(calheight1);
                tv.setMaxHeight(calheight1);
                tv.setText("GB"+i);

                et1.setGravity(Gravity.CENTER);
                et2.setGravity(Gravity.CENTER);
                et3.setGravity(Gravity.CENTER);
                et4.setGravity(Gravity.CENTER);
                et1.setId(100+i);et1.setHeight(calheight1);et1.setMaxHeight(calheight1);
                et2.setId(200+i);et2.setHeight(calheight1);et2.setMaxHeight(calheight1);et3.setId(300+i);
                et3.setHeight(calheight1);et3.setMaxHeight(calheight1);et4.setId(400+i);et4.setHeight(calheight1);et4.setMaxHeight(calheight1);
                /*-----------------------------------*/
                ConstraintLayout.LayoutParams layparms = new ConstraintLayout.LayoutParams(0,calheight1);
                layparms.topToTop = ConstraintLayout.LayoutParams.PARENT_ID;
                layparms.startToStart = ConstraintLayout.LayoutParams.PARENT_ID;
                layparms.bottomToBottom = ConstraintLayout.LayoutParams.PARENT_ID;
                layparms.matchConstraintPercentWidth = calwidth1;

                ConstraintLayout.LayoutParams layparms1 = new ConstraintLayout.LayoutParams(0,calheight1);
                layparms1.topToTop = ConstraintLayout.LayoutParams.PARENT_ID;
                layparms1.rightToRight = ConstraintLayout.LayoutParams.PARENT_ID;
                layparms1.bottomToBottom = ConstraintLayout.LayoutParams.PARENT_ID;
                layparms1.startToEnd = tv.getId();
                layparms1.matchConstraintPercentWidth = calwidth1;


                ConstraintLayout.LayoutParams layparms2 = new ConstraintLayout.LayoutParams(0,calheight1);
                layparms2.topToTop = ConstraintLayout.LayoutParams.PARENT_ID;
                layparms2.rightToRight = ConstraintLayout.LayoutParams.PARENT_ID;
                layparms2.bottomToBottom = ConstraintLayout.LayoutParams.PARENT_ID;
                layparms2.startToEnd = et1.getId();
                layparms2.matchConstraintPercentWidth = calwidth1;

                ConstraintLayout.LayoutParams layparms3 = new ConstraintLayout.LayoutParams(0,calheight1);
                layparms3.topToTop = ConstraintLayout.LayoutParams.PARENT_ID;
                layparms3.rightToRight = ConstraintLayout.LayoutParams.PARENT_ID;
                layparms3.bottomToBottom = ConstraintLayout.LayoutParams.PARENT_ID;
                layparms3.startToEnd = et2.getId();
                layparms3.matchConstraintPercentWidth = calwidth1;

                ConstraintLayout.LayoutParams layparms4 = new ConstraintLayout.LayoutParams(0,calheight1);
                layparms4.topToTop = ConstraintLayout.LayoutParams.PARENT_ID;
                layparms4.rightToRight = ConstraintLayout.LayoutParams.PARENT_ID;
                layparms4.bottomToBottom = ConstraintLayout.LayoutParams.PARENT_ID;
                layparms4.startToEnd = et3.getId();
                layparms4.matchConstraintPercentWidth = calwidth1;

                tv.setLayoutParams(layparms);
                et1.setLayoutParams(layparms1);
                et2.setLayoutParams(layparms2);
                et3.setLayoutParams(layparms3);
                et4.setLayoutParams(layparms4);

                row.addView(tv);
                row.addView(et1);
                row.addView(et2);
                row.addView(et3);
                row.addView(et4);

                list1.add(100+i);
                list2.add(200+i);
                list3.add(300+i);
                secondnum = 201;
                tb.addView(row,i);
                /*-----------------------------------*/


                /*+++++++++++++++++++++++++++++++++++++++++*/
                tbv1.setId(2000+i);
                tbv2.setId(500+i);
                tbv3.setId(600+i);
                ConstraintLayout.LayoutParams layparms5 = new ConstraintLayout.LayoutParams(0,calheight1);
                layparms5.topToTop = ConstraintLayout.LayoutParams.PARENT_ID;
                layparms5.startToStart = ConstraintLayout.LayoutParams.PARENT_ID;
                layparms5.bottomToBottom = ConstraintLayout.LayoutParams.PARENT_ID;
                layparms5.matchConstraintPercentWidth = calwidth2;

                ConstraintLayout.LayoutParams layparms6 = new ConstraintLayout.LayoutParams(0,calheight1);
                layparms6.topToTop = ConstraintLayout.LayoutParams.PARENT_ID;
                layparms6.rightToRight = ConstraintLayout.LayoutParams.PARENT_ID;
                layparms6.bottomToBottom = ConstraintLayout.LayoutParams.PARENT_ID;
                layparms6.startToEnd = tbv1.getId();
                layparms6.matchConstraintPercentWidth = calwidth2;

                ConstraintLayout.LayoutParams layparms7 = new ConstraintLayout.LayoutParams(0,calheight1);
                layparms7.topToTop = ConstraintLayout.LayoutParams.PARENT_ID;
                layparms7.rightToRight = ConstraintLayout.LayoutParams.PARENT_ID;
                layparms7.bottomToBottom = ConstraintLayout.LayoutParams.PARENT_ID;
                layparms7.startToEnd = tbv2.getId();
                layparms7.matchConstraintPercentWidth = calwidth2;

                tbv1.setLayoutParams(layparms5);
                tbv2.setLayoutParams(layparms6);
                tbv3.setLayoutParams(layparms7);

                tbv1.setGravity(Gravity.CENTER);
                tbv1.setTextSize(18);
                tbv1.setTextColor(Color.parseColor(strColor));
                tbv2.setGravity(Gravity.CENTER);
                tbv2.setTextSize(18);
                tbv2.setTextColor(Color.parseColor(strColor));
                tbv3.setGravity(Gravity.CENTER);
                tbv3.setTextSize(18);
                tbv3.setTextColor(Color.parseColor(strColor));

                tbv1.setText("GB" + i);
                tbv2.setText("");
                row1.addView(tbv1);
                row1.addView(tbv2);
                row1.addView(tbv3);
                tb1.addView(row1, i);
                //tb1.setBackground(ContextCompat.getDrawable(getContext(),R.drawable.border2));
                tbv1.setBackground(ContextCompat.getDrawable(getContext(),R.drawable.border2));
                tbv2.setBackground(ContextCompat.getDrawable(getContext(),R.drawable.border2));
                tbv3.setBackground(ContextCompat.getDrawable(getContext(),R.drawable.border));
                /*+++++++++++++++++++++++++++++++++++++++++*/
            }
            int idnum1 = 510;
            int idnum2 = 520;
            int idnum3 = 530;
            ConstraintLayout row= new ConstraintLayout(getContext());
            TextView tv1 = new TextView(getContext());
            TextView tv2 = new TextView(getContext());
            TextView tv3 = new TextView(getContext());
            tv1.setText("합계");
            tv1.setGravity(Gravity.CENTER);
            tv1.setId(idnum3);
            tv2.setId(idnum1);
            tv3.setId(idnum2);
            tv2.setText("");
            tv3.setText("");
            tv2.setGravity(Gravity.CENTER);
            tv2.setHeight(calheight2);
            tv3.setGravity(Gravity.CENTER);

            ConstraintLayout.LayoutParams layparms1_1 = new ConstraintLayout.LayoutParams(0,calheight1);
            layparms1_1.topToTop = ConstraintLayout.LayoutParams.PARENT_ID;
            layparms1_1.startToStart = ConstraintLayout.LayoutParams.PARENT_ID;
            layparms1_1.bottomToBottom = ConstraintLayout.LayoutParams.PARENT_ID;
            layparms1_1.matchConstraintPercentWidth = calwidth2;

            ConstraintLayout.LayoutParams layparms1_2 = new ConstraintLayout.LayoutParams(0,calheight1);
            layparms1_2.topToTop = ConstraintLayout.LayoutParams.PARENT_ID;
            layparms1_2.rightToRight = ConstraintLayout.LayoutParams.PARENT_ID;
            layparms1_2.bottomToBottom = ConstraintLayout.LayoutParams.PARENT_ID;
            layparms1_2.startToEnd = tv1.getId();
            layparms1_2.matchConstraintPercentWidth = calwidth2;

            ConstraintLayout.LayoutParams layparms1_3 = new ConstraintLayout.LayoutParams(0,calheight1);
            layparms1_3.topToTop = ConstraintLayout.LayoutParams.PARENT_ID;
            layparms1_3.rightToRight = ConstraintLayout.LayoutParams.PARENT_ID;
            layparms1_3.bottomToBottom = ConstraintLayout.LayoutParams.PARENT_ID;
            layparms1_3.startToEnd = tv2.getId();
            layparms1_3.matchConstraintPercentWidth = calwidth2;

            tv1.setLayoutParams(layparms1_1);
            tv2.setLayoutParams(layparms1_2);
            tv3.setLayoutParams(layparms1_3);


            row.addView(tv1);
            row.addView(tv2);
            row.addView(tv3);
            tb1.addView(row);
            tv1.setTextColor(Color.parseColor(strColor));
            tv2.setTextColor(Color.parseColor(strColor));
            tv3.setTextColor(Color.parseColor(strColor));
            tv1.setTextSize(18);
            tv2.setTextSize(18);
            tv3.setTextSize(18);
            tv1.setHeight(calheight1);tv1.setMaxHeight(calheight1);
            tv2.setHeight(calheight1);tv2.setMaxHeight(calheight1);
            tv3.setHeight(calheight1);tv2.setMaxHeight(calheight1);
            tv1.setBackground(ContextCompat.getDrawable(getContext(),R.drawable.border2));
            tv2.setBackground(ContextCompat.getDrawable(getContext(),R.drawable.border2));
            tv3.setBackground(ContextCompat.getDrawable(getContext(),R.drawable.border2));
            try {
                first = (EditText)view.findViewById(Integer.parseInt(list.get(z).toString()));
                first.requestFocus();
            }catch (Exception e){
            }
            SecondEdit = new EditText[bar];
            for (int i = 0; i < bar; i++) {
                SecondEdit[i] = view.findViewById(secondnum+i);
                SecondEdit[i].setImeOptions(EditorInfo.IME_ACTION_NEXT);
                SecondEdit[i].setOnEditorActionListener(new TextView.OnEditorActionListener() {
                    @Override
                    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                        if(actionId==EditorInfo.IME_ACTION_NEXT){
                            try {
                                SecondEdit[sum].setNextFocusForwardId(thirdnum+sum);
                                sum = sum+1;
                            }catch (Exception e){
                                System.out.println(e);
                            }
                        }
                        return false;
                    }
                });
            }
            ThirdEdit = new EditText[bar];
            for (int i = 0; i < bar; i++) {
                ThirdEdit[i] = view.findViewById(thirdnum+i);
                ThirdEdit[i].setImeOptions(EditorInfo.IME_ACTION_NEXT);
                ThirdEdit[i].setOnEditorActionListener(new TextView.OnEditorActionListener() {
                    @Override
                    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                        if(actionId==EditorInfo.IME_ACTION_NEXT){
                            try {
                                ThirdEdit[sum2].setNextFocusForwardId(quad+sum2);
                                sum2 = sum2+1;
                            }catch (Exception e){
                                System.out.println(e);
                            }
                        }
                        return false;
                    }
                });
            }
            QuadEdit = new EditText[bar];
            for(o = 0; o < bar; o++){

                QuadEdit[o] = view.findViewById(quad+o);
                if (o>=bar-1){
                    QuadEdit[o].setOnEditorActionListener(new TextView.OnEditorActionListener() {
                        @Override
                        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                            if(actionId==EditorInfo.IME_ACTION_NEXT||o<bar){
                                try {
                                    QuadEdit[sum3].setNextFocusForwardId(R.id.weight);
                                }catch (Exception e){
                                    System.out.println(e);
                                }
                            }
                            return false;
                        }
                    });
                }else {
                    QuadEdit[o].setOnEditorActionListener(new TextView.OnEditorActionListener() {
                        @Override
                        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                            if(actionId==EditorInfo.IME_ACTION_NEXT||o<bar){
                                try {
                                    QuadEdit[sum3].setNextFocusForwardId(secondnum+1+sum3);
                                    sum3 = sum3 + 1;
                                }catch (Exception e){
                                    System.out.println(e);
                                }
                            }
                            return false;
                        }
                    });
                }
            }
            //ThirdEdit=(EditText)findViewById(Integer.parseInt(list3.get(z+sum2).toString()));
            first.addTextChangedListener(new TextWatcher() {
                @Override
                public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                    for(int i=1;i<bar;i++){
                        autoEdit = (EditText)view.findViewById(Integer.parseInt(list1.get(i).toString()));
                        autoEdit.setText(first.getText());
                    }
                }
                @Override
                public void onTextChanged(CharSequence s, int start, int before, int count) { }
                @Override
                public void afterTextChanged(Editable s) {
                    for(int i=1;i<bar;i++){
                        autoEdit = (EditText)view.findViewById(Integer.parseInt(list1.get(i).toString()));
                        autoEdit.setText(first.getText());
                    }
                }
            });

            second = Integer.parseInt(list2.get(z).toString());
            first.setOnEditorActionListener(new TextView.OnEditorActionListener() {
                @Override
                public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                    if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                        first.setNextFocusRightId(second);
                        return true;
                    }
                    return false;
                }
            });
            cal1_1 = 1;
            cal1_3 = 0;
            cal1_4 = 0;
            onTimePickerSerListener.onTimePickerSet(cal1_1,cal1_3,cal1_4);
            for (int i=0; i<bar;i++){
                cal1_1_mil[i] = view.findViewById(cal1_mil+i);
                cal1_1_rock[i] = view.findViewById(cal1_rock+i);
                cal1_1_bon[i] = view.findViewById(cal1_bon+i);
                cal1_1_deni[i] = view.findViewById(cal1_deni+i);
            }
            for (int i=0; i<bar;i++){
                final int is = i;
                cal1_1_mil[i].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(cal1_1_mil[is].getText().toString().length()!=0&&cal1_1_rock[is].getText().toString().length()!=0&&cal1_1_bon[is].getText().toString().length()!=0&&cal1_1_deni[is].getText().toString().length()!=0){
                            ((Calculation1_pager) Calculation1_pager.mContext).calculation(view);
                        }
                    }
                });
            }
            for (int i=0; i<bar;i++){
                final int is = i;
                cal1_1_rock[i].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(cal1_1_mil[is].getText().toString().length()!=0&&cal1_1_rock[is].getText().toString().length()!=0&&cal1_1_bon[is].getText().toString().length()!=0&&cal1_1_deni[is].getText().toString().length()!=0){
                            ((Calculation1_pager) Calculation1_pager.mContext).calculation(view);
                        }
                    }
                });
            }
            for (int i=0; i<bar;i++){
                final int is = i;
                cal1_1_bon[i].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(cal1_1_mil[is].getText().toString().length()!=0&&cal1_1_rock[is].getText().toString().length()!=0&&cal1_1_bon[is].getText().toString().length()!=0&&cal1_1_deni[is].getText().toString().length()!=0){
                            ((Calculation1_pager) Calculation1_pager.mContext).calculation(view);
                        }
                    }
                });
            }
            for (int i=0; i<bar;i++){
                final int is = i;
                cal1_1_deni[i].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(cal1_1_mil[is].getText().toString().length()!=0&&cal1_1_rock[is].getText().toString().length()!=0&&cal1_1_bon[is].getText().toString().length()!=0&&cal1_1_deni[is].getText().toString().length()!=0){
                            ((Calculation1_pager) Calculation1_pager.mContext).calculation(view);
                        }
                    }
                });
            }
        }
    }
    @Override
    public void onAttach(Context context){
        super.onAttach(context);
        if(context instanceof OnTimePickerSerListener){
            onTimePickerSerListener = (OnTimePickerSerListener)context;
        }else {
            throw new RuntimeException(context.toString()+"되자제발");
        }
    }

}
