Example usage for android.widget NumberPicker setOnScrollListener

List of usage examples for android.widget NumberPicker setOnScrollListener

Introduction

In this page you can find the example usage for android.widget NumberPicker setOnScrollListener.

Prototype

public void setOnScrollListener(OnScrollListener onScrollListener) 

Source Link

Document

Set listener to be notified for scroll state changes.

Usage

From source file:com.almalence.plugins.capture.video.VideoCapturePlugin.java

public void TimeLapseDialog() {
    if (isRecording)
        return;/*  w w w.  j  a v a  2 s. co  m*/

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ApplicationScreen.getMainContext());
    interval = Integer.valueOf(prefs.getString("timelapseInterval", "0"));
    measurementVal = Integer.valueOf(prefs.getString("timelapseMeasurementVal", "0"));

    // show time lapse settings
    timeLapseDialog = new TimeLapseDialog(ApplicationScreen.instance);
    timeLapseDialog.setContentView(R.layout.plugin_capture_video_timelapse_dialog);
    final NumberPicker np = (NumberPicker) timeLapseDialog.findViewById(R.id.numberPicker1);
    np.setMaxValue(16);
    np.setMinValue(0);
    np.setValue(interval);
    np.setDisplayedValues(stringInterval);
    np.setWrapSelectorWheel(false);
    np.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);

    final NumberPicker np2 = (NumberPicker) timeLapseDialog.findViewById(R.id.numberPicker2);
    np2.setMaxValue(2);
    np2.setMinValue(0);
    np2.setValue(measurementVal);
    np2.setWrapSelectorWheel(false);
    np2.setDisplayedValues(stringMeasurement);
    np2.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);

    final Switch sw = (Switch) timeLapseDialog.findViewById(R.id.timelapse_switcher);

    // disable/enable controls in dialog
    sw.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (!sw.isChecked()) {
                swChecked = false;
            } else {
                swChecked = true;
            }
        }
    });

    np2.setOnScrollListener(new NumberPicker.OnScrollListener() {
        @Override
        public void onScrollStateChange(NumberPicker numberPicker, int scrollState) {
            sw.setChecked(true);
        }
    });
    np.setOnScrollListener(new NumberPicker.OnScrollListener() {
        @Override
        public void onScrollStateChange(NumberPicker numberPicker, int scrollState) {
            sw.setChecked(true);
        }
    });

    // disable control in dialog by default
    if (!swChecked) {
        sw.setChecked(false);
    } else {
        sw.setChecked(true);
    }

    timeLapseDialog.setOnDismissListener(new OnDismissListener() {
        @Override
        public void onDismiss(DialogInterface dialog) {
            if (swChecked) {
                measurementVal = np2.getValue();
                interval = np.getValue();

                SharedPreferences prefs = PreferenceManager
                        .getDefaultSharedPreferences(ApplicationScreen.getMainContext());
                Editor editor = prefs.edit();
                editor.putString("timelapseMeasurementVal", String.valueOf(measurementVal));
                editor.putString("timelapseInterval", String.valueOf(interval));
                editor.commit();

                timeLapseButton.setImageDrawable(ApplicationScreen.getAppResources()
                        .getDrawable(R.drawable.plugin_capture_video_timelapse_active));

                ApplicationScreen.getGUIManager().setShutterIcon(ShutterButton.RECORDER_START);
            } else {
                timeLapseButton.setImageDrawable(ApplicationScreen.getAppResources()
                        .getDrawable(R.drawable.plugin_capture_video_timelapse_inactive));
                ApplicationScreen.getGUIManager().setShutterIcon(ShutterButton.RECORDER_START);
            }

        }
    });
    timeLapseDialog.show();
}

From source file:com.softminds.matrixcalculator.dialog_activity.FunctionMaker.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
    final boolean isDark = preferences.getBoolean("DARK_THEME_KEY", false);
    if (isDark)//ww  w .j a  va2s .  co  m
        setTheme(R.style.AppThemeDarkDialog);
    else
        setTheme(R.style.AppThemeDialog);

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_function_maker);

    //Grab all Control References
    Button proceed = findViewById(R.id.ConfirmMakeFunction);
    final NumberPicker expo = findViewById(R.id.FunctionMakerExponent);
    final NumberPicker deg = findViewById(R.id.FunctionMakerDegree);
    final EditText coefficient = findViewById(R.id.MainCoefficientFiller);
    //Put Properties to Number Picker
    expo.setValue(1);
    expo.setMinValue(1);
    expo.setMaxValue(9);
    deg.setMinValue(1);
    deg.setMaxValue(7);
    deg.setValue(1);
    //Grab Default References
    final TextView ConstSign = findViewById(R.id.ConstantSign);
    final TextView FirstAuto = findViewById(R.id.FirstXAuto);
    FirstAuto.setText(ConvertToExponent(getString(R.string.X)));
    final TextView Const = findViewById(R.id.ConstantValueFunction);

    //Grab all Inactive TextViews
    final TextView Term1 = findViewById(R.id.CreatedXAuto1);
    Term1.setText(null);
    Term1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            coefficient.setText(null);
            if (CurrentTermCoefficient != null) {
                if (isDark)
                    CurrentTermCoefficient.setBackgroundColor(
                            ContextCompat.getColor(getApplicationContext(), R.color.DarkcolorPrimaryDark));
                else
                    CurrentTermCoefficient
                            .setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.grey));
            }
            CurrentTermCoefficient = Term1;
            CurrentTermCoefficient
                    .setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.cardColor));
        }
    });
    final TextView Term2 = findViewById(R.id.CreatedXAuto2);
    Term2.setText(null);
    Term2.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            coefficient.setText(null);
            if (CurrentTermCoefficient != null) {
                if (isDark)
                    CurrentTermCoefficient.setBackgroundColor(
                            ContextCompat.getColor(getApplicationContext(), R.color.DarkcolorPrimaryDark));
                else
                    CurrentTermCoefficient
                            .setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.grey));
            }
            CurrentTermCoefficient = Term2;
            CurrentTermCoefficient
                    .setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.cardColor));
        }
    });
    final TextView Term3 = findViewById(R.id.CreatedXAuto3);
    Term3.setText(null);
    Term3.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            coefficient.setText(null);
            if (CurrentTermCoefficient != null) {
                if (isDark)
                    CurrentTermCoefficient.setBackgroundColor(
                            ContextCompat.getColor(getApplicationContext(), R.color.DarkcolorPrimaryDark));
                else
                    CurrentTermCoefficient
                            .setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.grey));
            }
            CurrentTermCoefficient = Term3;
            CurrentTermCoefficient
                    .setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.cardColor));
        }
    });
    final TextView Term4 = findViewById(R.id.CreatedXAuto4);
    Term4.setText(null);
    Term4.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            coefficient.setText(null);
            if (CurrentTermCoefficient != null) {
                if (isDark)
                    CurrentTermCoefficient.setBackgroundColor(
                            ContextCompat.getColor(getApplicationContext(), R.color.DarkcolorPrimaryDark));
                else
                    CurrentTermCoefficient
                            .setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.grey));
            }
            CurrentTermCoefficient = Term4;
            CurrentTermCoefficient
                    .setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.cardColor));
        }
    });
    final TextView Term5 = findViewById(R.id.CreatedXAuto5);
    Term5.setText(null);
    Term5.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            coefficient.setText(null);
            if (CurrentTermCoefficient != null) {
                if (isDark)
                    CurrentTermCoefficient.setBackgroundColor(
                            ContextCompat.getColor(getApplicationContext(), R.color.DarkcolorPrimaryDark));
                else
                    CurrentTermCoefficient
                            .setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.grey));
            }
            CurrentTermCoefficient = Term5;
            CurrentTermCoefficient
                    .setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.cardColor));
        }
    });
    final TextView Term6 = findViewById(R.id.CreatedXAuto6);
    Term6.setText(null);
    Term6.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            coefficient.setText(null);
            if (CurrentTermCoefficient != null) {
                if (isDark)
                    CurrentTermCoefficient.setBackgroundColor(
                            ContextCompat.getColor(getApplicationContext(), R.color.DarkcolorPrimaryDark));
                else
                    CurrentTermCoefficient
                            .setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.grey));
            }
            CurrentTermCoefficient = Term6;
            CurrentTermCoefficient
                    .setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.cardColor));
        }
    });

    //All Inactive Signs and Setting Click to Change Sign
    final TextView Sign1 = findViewById(R.id.AutoSign1);
    Sign1.setText(null);
    Sign1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            SignChanger(Sign1);
        }
    });
    final TextView Sign2 = findViewById(R.id.AutoSign2);
    Sign2.setText(null);
    Sign2.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            SignChanger(Sign2);
        }
    });
    final TextView Sign3 = findViewById(R.id.AutoSign3);
    Sign3.setText(null);
    Sign3.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            SignChanger(Sign3);
        }
    });
    final TextView Sign4 = findViewById(R.id.AutoSign4);
    Sign4.setText(null);
    Sign4.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            SignChanger(Sign4);
        }
    });
    final TextView Sign5 = findViewById(R.id.AutoSign5);
    Sign5.setText(null);
    Sign5.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            SignChanger(Sign5);
        }
    });
    final TextView Sign6 = findViewById(R.id.AutoSign6);
    Sign6.setText(null);
    Sign6.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            SignChanger(Sign6);
        }
    });

    //Set Click Listener to each
    deg.setOnScrollListener(new NumberPicker.OnScrollListener() {
        @Override
        public void onScrollStateChange(NumberPicker numberPicker, int i) {
            //Degree maker will be here
            switch (numberPicker.getValue()) {
            case 7:
                Term2.setText(ConvertToExponent(getString(R.string.X)));
                Sign2.setText("+");
                Term6.setText(ConvertToExponent(getString(R.string.NewX) + String.valueOf(deg.getValue())));
                Sign6.setText("+");
                Term3.setText(ConvertToExponent(getString(R.string.X)));
                Sign3.setText("+");
                Term4.setText(ConvertToExponent(getString(R.string.X)));
                Sign4.setText("+");
                Term5.setText(ConvertToExponent(getString(R.string.X)));
                Sign5.setText("+");
                Term1.setText(ConvertToExponent(getString(R.string.X)));
                Sign1.setText("+");
                break;
            case 6:
                Term2.setText(ConvertToExponent(getString(R.string.X)));
                Sign2.setText("+");
                Term5.setText(ConvertToExponent(getString(R.string.NewX) + String.valueOf(deg.getValue())));
                Sign5.setText("+");
                Term3.setText(ConvertToExponent(getString(R.string.X)));
                Sign3.setText("+");
                Term4.setText(ConvertToExponent(getString(R.string.X)));
                Sign4.setText("+");
                Term1.setText(ConvertToExponent(getString(R.string.X)));
                Sign1.setText("+");
                Sign6.setText(null);
                Term6.setText(null);
                break;
            case 5:
                Term2.setText(ConvertToExponent(getString(R.string.X)));
                Sign2.setText("+");
                Term4.setText(ConvertToExponent(getString(R.string.NewX) + String.valueOf(deg.getValue())));
                Sign4.setText("+");
                Term3.setText(ConvertToExponent(getString(R.string.X)));
                Sign3.setText("+");
                Term1.setText(ConvertToExponent(getString(R.string.X)));
                Sign1.setText("+");
                Term5.setText(null);
                Term6.setText(null);
                Sign5.setText(null);
                Sign6.setText(null);
                break;
            case 4:
                Term2.setText(ConvertToExponent(getString(R.string.X)));
                Sign2.setText("+");
                Term3.setText(ConvertToExponent(getString(R.string.NewX) + String.valueOf(deg.getValue())));
                Sign3.setText("+");
                Term1.setText(ConvertToExponent(getString(R.string.X)));
                Sign1.setText("+");
                Term4.setText(null);
                Term5.setText(null);
                Term6.setText(null);
                Sign4.setText(null);
                Sign5.setText(null);
                Sign6.setText(null);
                break;
            case 3:
                Term1.setText(ConvertToExponent(getString(R.string.X)));
                Sign1.setText("+");
                Term2.setText(ConvertToExponent(getString(R.string.NewX) + String.valueOf(deg.getValue())));
                Sign2.setText("+");
                Term3.setText(null);
                Term4.setText(null);
                Term5.setText(null);
                Term6.setText(null);
                Sign3.setText(null);
                Sign4.setText(null);
                Sign5.setText(null);
                Sign6.setText(null);
                break;
            case 2:
                Term1.setText(ConvertToExponent(getString(R.string.NewX) + String.valueOf(deg.getValue())));
                Sign1.setText("+");
                Term2.setText(null);
                Term3.setText(null);
                Term4.setText(null);
                Term5.setText(null);
                Term6.setText(null);
                Sign2.setText(null);
                Sign3.setText(null);
                Sign4.setText(null);
                Sign5.setText(null);
                Sign6.setText(null);
                break;
            case 1:
                Term1.setText(null);
                Sign1.setText(null);
                Term2.setText(null);
                Term3.setText(null);
                Term4.setText(null);
                Term5.setText(null);
                Term6.setText(null);
                Sign2.setText(null);
                Sign3.setText(null);
                Sign4.setText(null);
                Sign5.setText(null);
                Sign6.setText(null);
                break;
            }
        }
    });
    expo.setOnScrollListener(new NumberPicker.OnScrollListener() {
        @Override
        public void onScrollStateChange(NumberPicker numberPicker, int i) {
            if (CurrentTermCoefficient != null) {
                if (CurrentTermCoefficient.getText().toString().contains("x")) {
                    String order = CurrentTermCoefficient.getText().toString();
                    String SubString = order.substring(0, order.indexOf("x") + 1); //Get Everything except from Exponent
                    String SubString2 = SubString + String.valueOf(numberPicker.getValue());
                    CurrentTermCoefficient.setText(ConvertToExponent(SubString2));
                }
            } else {
                Toast.makeText(getApplicationContext(), R.string.Warning12, Toast.LENGTH_SHORT).show();
                numberPicker.setValue(2);
            }
        }
    });

    //EditText KeyChange Listener
    coefficient.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View view, int i, KeyEvent keyEvent) {
            if (CurrentTermCoefficient == null) {
                Toast.makeText(getApplicationContext(), R.string.Warning12, Toast.LENGTH_SHORT).show();
                return true;
            } else {
                if (CurrentTermCoefficient.getText().toString().contains("x")) {
                    String res = coefficient.getText().toString() + "x" + String.valueOf(expo.getValue());
                    CurrentTermCoefficient.setText(ConvertToExponent(res));
                } else
                    CurrentTermCoefficient.setText(coefficient.getText().toString());
                return false;
            }
        }
    });
    //default Changers
    ConstSign.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            SignChanger(ConstSign);
        }
    });
    //default Coefficient
    FirstAuto.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            coefficient.setText(null);
            if (CurrentTermCoefficient != null) {
                if (isDark)
                    CurrentTermCoefficient.setBackgroundColor(
                            ContextCompat.getColor(getApplicationContext(), R.color.DarkcolorPrimaryDark));
                else
                    CurrentTermCoefficient
                            .setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.grey));
            }
            CurrentTermCoefficient = FirstAuto;
            FirstAuto.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.cardColor));
        }
    });
    //Constant changer
    Const.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            coefficient.setText(null);
            if (CurrentTermCoefficient != null) {
                if (isDark)
                    CurrentTermCoefficient.setBackgroundColor(
                            ContextCompat.getColor(getApplicationContext(), R.color.DarkcolorPrimaryDark));
                else
                    CurrentTermCoefficient
                            .setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.grey));
            }
            CurrentTermCoefficient = Const;
            Const.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.cardColor));
        }
    });

    //SetterListener

    proceed.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Function EndUserCreation = GetMainFunction(deg.getValue(),
                    Float.parseFloat(Const.getText().toString()), SignReturner(ConstSign));
            ((GlobalValues) getApplication()).SendToGlobal(EndUserCreation);
            Log.d("Function is :", EndUserCreation.toString());
            setResult(1452);
            finish();

        }
    });
}