Example usage for android.widget NumberPicker getValue

List of usage examples for android.widget NumberPicker getValue

Introduction

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

Prototype

public int getValue() 

Source Link

Document

Returns the value of the picker.

Usage

From source file:es.ugr.swad.swadroid.modules.tests.TestsMake.java

private void setNumQuestions() {
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
        android.widget.NumberPicker numberPicker = (android.widget.NumberPicker) findViewById(
                R.id.testNumQuestionsNumberPicker);

        numQuestions = numberPicker.getValue();
    } else {//from   w w w  .j av  a 2s  .c  o  m
        es.ugr.swad.swadroid.gui.widget.NumberPicker numberPickerOld = (es.ugr.swad.swadroid.gui.widget.NumberPicker) findViewById(
                R.id.testNumQuestionsNumberPickerOld);

        numQuestions = numberPickerOld.getCurrent();
    }

    if (isDebuggable) {
        Log.d(TAG, "numQuestions=" + numQuestions);
    }

    selectTags();
}

From source file:org.ounl.lifelonglearninghub.fcube.navigate.SwipeFragmentActivity.java

/**
 * Returns active command for controls selected in view .
 * Returns null for wrong command//from  w ww  .j  av a 2 s. co  m
 * 
 * @param v
 * @return
 */
private IFeedbackCubeCommnads getCommnand(View v) {

    LinearLayout llButtons = (LinearLayout) v.getParent();
    LinearLayout llRoot = (LinearLayout) llButtons.getParent();

    String sTag = v.getTag().toString();
    if (sTag.compareTo(getString(R.string.tab_vi)) == 0) {

        TextView tvRed = (TextView) llRoot.findViewById(R.id.textViewRedValue);
        TextView tvGreen = (TextView) llRoot.findViewById(R.id.textViewGreenValue);
        TextView tvBlue = (TextView) llRoot.findViewById(R.id.textViewBlueValue);

        RadioButton rbF = (RadioButton) llRoot.findViewById(R.id.rbFullColor);
        RadioButton rbP = (RadioButton) llRoot.findViewById(R.id.rbPartColor);

        if (rbP.isChecked()) {

            NumberPicker npStart = (NumberPicker) llRoot.findViewById(R.id.npLedStart);
            NumberPicker npStop = (NumberPicker) llRoot.findViewById(R.id.npLedStop);

            FCPieChart c = new FCPieChart(FeedbackCubeConfig.getSingleInstance().getIp(),
                    npStart.getValue() + "", npStop.getValue() + "", tvRed.getText().toString(),
                    tvGreen.getText().toString(), tvBlue.getText().toString());

            //            Toast.makeText(this, "Launch cube " + c.toString(),
            //                  Toast.LENGTH_SHORT).show();

            return c;

        } else {
            FCColor c = new FCColor(FeedbackCubeConfig.getSingleInstance().getIp(), tvRed.getText().toString(),
                    tvGreen.getText().toString(), tvBlue.getText().toString());
            //            Toast.makeText(this, "Launch cube " + c.toString(),
            //                  Toast.LENGTH_SHORT).show();

            return c;

        }

    } else if (sTag.compareTo(getString(R.string.tab_au)) == 0) {

        //         CheckBox cb = (CheckBox) llRoot.findViewById(R.id.cbBeep);
        //         if (cb.isChecked()) {
        //            FCBeep c = new FCBeep(FeedbackCubeConfig.getSingleInstance()
        //                  .getIp());
        ////            Toast.makeText(this, "Launch cube " + c.toString(),
        ////                  Toast.LENGTH_SHORT).show();
        //
        //            return c;
        //         } else {
        //            Toast.makeText(this,
        //                  "Check off the Beep! to launch the action.",
        //                  Toast.LENGTH_SHORT).show();
        //         }

        RadioButton rbBeep = (RadioButton) llRoot.findViewById(R.id.rbBeep);
        RadioButton rbMelody = (RadioButton) llRoot.findViewById(R.id.rbMelody1);

        if (rbBeep.isChecked()) {

            FCBeep c = new FCBeep(FeedbackCubeConfig.getSingleInstance().getIp());
            //            Toast.makeText(this, "Launch cube " + c.toString(),
            //                  Toast.LENGTH_SHORT).show();

            return c;

        } else if (rbMelody.isChecked()) {

            FCMelody1 c = new FCMelody1(FeedbackCubeConfig.getSingleInstance().getIp());

            //            Toast.makeText(this, "Launch cube " + c.toString(),
            //                  Toast.LENGTH_SHORT).show();

            return c;

        }

    } else if (sTag.compareTo(getString(R.string.tab_ef)) == 0) {

        RadioButton rbRainbow = (RadioButton) llRoot.findViewById(R.id.rbRainbow);
        RadioButton rbRainbowC = (RadioButton) llRoot.findViewById(R.id.rbRainbowCircle);
        RadioButton rbFade = (RadioButton) llRoot.findViewById(R.id.rbFade);

        if (rbRainbow.isChecked()) {

            FCRainbow c = new FCRainbow(FeedbackCubeConfig.getSingleInstance().getIp());
            //            Toast.makeText(this, "Launch cube " + c.toString(),
            //                  Toast.LENGTH_SHORT).show();

            return c;

        } else if (rbRainbowC.isChecked()) {

            FCRainbowCircle c = new FCRainbowCircle(FeedbackCubeConfig.getSingleInstance().getIp());

            //            Toast.makeText(this, "Launch cube " + c.toString(),
            //                  Toast.LENGTH_SHORT).show();

            return c;

        } else if (rbFade.isChecked()) {

            NumberPicker npD = (NumberPicker) llRoot.findViewById(R.id.npDelay);
            NumberPicker npN = (NumberPicker) llRoot.findViewById(R.id.npNumber);

            FCFade c = new FCFade(FeedbackCubeConfig.getSingleInstance().getIp(), "" + npN.getValue(),
                    "" + npD.getValue());

            //            Toast.makeText(this, "Launch cube " + c.toString(),
            //                  Toast.LENGTH_SHORT).show();

            return c;
        }

    }
    return null;

}

From source file:com.metinkale.prayerapp.vakit.PrefsView.java

@Override
public void onClick(View v) {
    Object o = getValue();/*from www . j a v  a2  s.  c  o m*/
    if ((mPref == Pref.Sound) || (mPref == Pref.Dua) || (mPref == Pref.Sela)) {
        new SoundChooser().showExpanded(((Activity) getContext()).getFragmentManager(), new Callback() {

            @Override
            public String getCurrent() {
                return (String) getValue();
            }

            @Override
            public void setCurrent(String current) {
                setValue(current);

            }

            @Override
            public Vakit getVakit() {
                return mVakit;
            }

            @Override
            public List<Sound> getSounds() {
                if (mPref == Pref.Sound) {
                    return Sounds.getSounds(mVakit);
                } else if (mPref == Pref.Dua) {
                    return Sounds.getSounds("dua", "extra");
                } else if (mPref == Pref.Sela) {
                    return Sounds.getSounds("sela", "extra");
                }

                return Sounds.getSounds(mVakit);
            }

        });

    } else if (mPref == Pref.SabahTime) {
        AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
        LayoutInflater inflater = LayoutInflater.from(getContext());
        View view = inflater.inflate(R.layout.sabahtime_dialog, null);
        final NumberPicker np = (NumberPicker) view.findViewById(R.id.number_picker);
        final RadioGroup rg = (RadioGroup) view.findViewById(R.id.rg);

        int val = (Integer) getValue();
        np.setMinValue(0);
        np.setMaxValue(300);
        np.setValue(Math.abs(val));

        rg.check((val < 0) ? R.id.afterImsak : R.id.beforeGunes);
        builder.setView(view).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int id) {
                setValue(np.getValue() * ((rg.getCheckedRadioButtonId() == R.id.beforeGunes) ? 1 : -1));
            }
        }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int id) {
            }
        });
        builder.show();
    } else if (mPref == Pref.Vibration2) {
        int i = (Integer) o;
        i++;
        if ((i < -1) || (i > 1)) {
            i = -1;
        }
        setValue(i);
        performHapticFeedback(HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING
                | HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
    } else if (o instanceof Boolean) {
        setValue(!(Boolean) o);
        performHapticFeedback(HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING
                | HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
    } else if (o instanceof Integer) {
        int titleId = 0;
        switch (mPref) {
        case Silenter:
            PermissionUtils.get(getContext()).needNotificationPolicy((Activity) getContext());
            titleId = R.string.silenterDuration;
            break;
        case Time:
            titleId = R.string.time;
            break;
        default:
            break;
        }
        NumberPickerDialog npd = new NumberPickerDialog(getContext(), new OnNumberSetListener() {

            @Override
            public void onNumberSet(int dialogId, int number) {
                setValue(number);

            }
        }, (Integer) o, 0, 300, titleId, 0, 0);
        npd.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)//from   w w w.  j  a va2 s .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();

        }
    });
}

From source file:org.odk.collect.android.fragments.dialogs.NumberPickerDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.number_picker_dialog, null);

    final NumberPicker numberPicker = (NumberPicker) view.findViewById(R.id.number_picker);
    numberPicker.setMaxValue(((String[]) getArguments().getSerializable(DISPLAYED_VALUES)).length - 1);
    numberPicker.setMinValue(0);//from   w  ww .  jav  a2s .co  m
    numberPicker.setWrapSelectorWheel(false);
    numberPicker.setDisplayedValues((String[]) getArguments().getSerializable(DISPLAYED_VALUES));
    numberPicker.setValue(((String[]) getArguments().getSerializable(DISPLAYED_VALUES)).length - 1
            - getArguments().getInt(PROGRESS));

    return new AlertDialog.Builder(getActivity()).setTitle("Number Picker").setView(view)
            .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    listener.onNumberPickerValueSelected(getArguments().getInt(WIDGET_ID),
                            numberPicker.getValue());
                }
            }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                }
            }).create();
}

From source file:org.ciasaboark.tacere.activity.fragment.AdvancedSettingsFragment.java

private void drawEventBufferWidgets() {
    LinearLayout bufferBox = (LinearLayout) rootView.findViewById(R.id.advanced_settings_buffer_box);
    bufferBox.setOnClickListener(new View.OnClickListener() {
        @Override/*from ww w  . j  a va 2 s .  c om*/
        public void onClick(View v) {
            AlertDialog.Builder builder = new AlertDialog.Builder(
                    new ContextThemeWrapper(context, R.style.Dialog));
            builder.setTitle("Buffer Minutes");
            final NumberPicker number = new NumberPicker(context);
            String[] nums = new String[32];

            for (int i = 0; i < nums.length; i++) {
                nums[i] = Integer.toString(i);
            }

            number.setMinValue(1);
            number.setMaxValue(nums.length - 1);
            number.setWrapSelectorWheel(false);
            number.setDisplayedValues(nums);
            number.setValue(prefs.getBufferMinutes() + 1);

            builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    prefs.setBufferMinutes(number.getValue() - 1);
                    drawEventBufferWidgets();
                }
            });

            builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    // Do nothing
                }
            });

            builder.setView(number);

            AlertDialog dialog = builder.show();
        }
    });

    // the event buffer button
    TextView bufferTV = (TextView) rootView.findViewById(R.id.bufferMinutesDescription);
    String bufferText = getResources().getString(R.string.advanced_settings_section_intervals_buffer_duration);
    bufferTV.setText(String.format(bufferText, prefs.getBufferMinutes()));
}

From source file:com.retroteam.studio.retrostudio.MeasureEditor.java

/**
 * Show the user the octave changer prompt.
 *//*from  www . j ava 2s.co m*/
private void octavePrompt() {

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    LayoutInflater inflater = this.getLayoutInflater();

    final View tempo_picker = inflater.inflate(R.layout.octave_picker, null);
    final NumberPicker np = (NumberPicker) tempo_picker.findViewById(R.id.octavePickerField);
    np.setMaxValue(8);
    np.setMinValue(0);
    np.setValue(noteSUB);

    builder.setTitle("Set Measure Octave").setView(tempo_picker)
            .setPositiveButton(R.string.set, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {

                    int sub = np.getValue();
                    noteSUB = sub;

                }
            }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    // do nothing
                }
            });

    AlertDialog dialog = builder.create();

    dialog.show();
}

From source file:cz.maresmar.sfm.view.menu.MenuDetailsFragment.java

private void showPickerDialog(@StringRes int title, int min, int max, int value, IntConsumer newValueConsumer) {
    // Prepare number picker
    NumberPicker picker = new NumberPicker(getContext());
    picker.setMinValue(min);//from  w  w w  .  ja v  a  2 s. com
    picker.setMaxValue(max);
    picker.setValue(value);
    picker.setWrapSelectorWheel(false);

    FrameLayout layout = new FrameLayout(getContext());
    layout.addView(picker, new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT,
            FrameLayout.LayoutParams.WRAP_CONTENT, Gravity.CENTER));

    // Show alert
    new AlertDialog.Builder(getContext()).setTitle(title).setMessage(R.string.menu_detail_pick_new_value)
            .setView(layout).setPositiveButton(android.R.string.ok, (dialogInterface, i) -> {
                // do something with picker.getValue()
                newValueConsumer.accept(picker.getValue());
            }).setNegativeButton(android.R.string.cancel, null).show();
}

From source file:com.yacorso.nowaste.views.adapters.FridgeFoodAdapter.java

@Override
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, final int position) {
    final FridgeViewHolder holder = (FridgeViewHolder) viewHolder;

    final Food food = foodList.get(position);

    final int quantity = food.getFoodFridge().getQuantity();

    holder.tvName.setText(food.getName());
    holder.btnQuantity.setText(Integer.toString(quantity));
    Date outOfDate = food.getFoodFridge().getOutOfDate();
    holder.outOfDate.setText(getDateTextFromDate(outOfDate));
    setOpenIcon(holder.btnOpenToggle, food);

    setColorCircleFromDate(holder.btnQuantity, outOfDate, mContext.getResources());

    View.OnClickListener clickListener = new View.OnClickListener() {
        @Override/*w  ww  . j a va 2  s.c  om*/
        public void onClick(View v) {

            lastFoodClickedPosition = position;
            switch (v.getId()) {
            case R.id.btn_food_quantity:
                /*
                 *  Popup changement quantit
                 */
                final NumberPicker numberPicker = new NumberPicker(mContext);
                numberPicker.setMinValue(1);
                numberPicker.setMaxValue(100);
                numberPicker.setValue(quantity);
                numberPicker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);

                AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
                builder.setMessage(R.string.title_quantity_number_picker);
                builder.setView(numberPicker);

                builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        /*
                         * Save the modification
                         */
                        int selectedValue = numberPicker.getValue();
                        food.getFoodFridge().setQuantity(selectedValue);
                        mFoodProvider.update(food);
                    }
                });

                builder.setNegativeButton(android.R.string.cancel, null);

                builder.create().show();
                break;

            case R.id.btn_open_toggle:
                /*
                 *  Open/close food
                 */
                FoodFridge foodFridge = food.getFoodFridge();
                foodFridge.toggleOpen();
                setOpenIcon(v, food);
                Date outOfDate = foodFridge.getOutOfDate();
                setColorCircleFromDate(holder.btnQuantity, outOfDate, v.getResources());
                mFoodProvider.update(food);
                break;

            case R.id.item_text_zone:
                EventBus.getDefault().post(new CallUpdateFoodEvent(food));
                break;
            case R.id.btn_favorite_toggle:
                EventBus.getDefault().post(new CallAddFoodToCustomListEvent(food));
                break;
            }
        }
    };

    holder.btnQuantity.setOnClickListener(clickListener);
    holder.btnOpenToggle.setOnClickListener(clickListener);
    holder.btnFavoriteToggle.setOnClickListener(clickListener);
    holder.textZone.setOnClickListener(clickListener);
}

From source file:com.fitme.MainActivity.java

public void onExerciseCreationRequested(final String trainName, final TrainingsListAdapter tla) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(R.string.title_add_exercise_dialog);
    View view = getLayoutInflater().inflate(R.layout.dialog_add_exercise, null);
    builder.setView(view);//from w w w. j  av  a  2  s.co  m
    builder.setPositiveButton(android.R.string.ok, null);
    builder.setNegativeButton(android.R.string.cancel, null);
    final AlertDialog dialogEx = builder.create();
    dialogEx.setOnShowListener(new DialogInterface.OnShowListener() {

        @Override
        public void onShow(DialogInterface dialog) {
            Button positive = dialogEx.getButton(AlertDialog.BUTTON_POSITIVE);
            positive.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    Spinner spinMuscleGroup = (Spinner) dialogEx.findViewById(R.id.spinner_select_mg_ex);
                    Spinner spinExName = (Spinner) dialogEx.findViewById(R.id.spinner_select_ex);
                    NumberPicker numpickRepeats = (NumberPicker) dialogEx
                            .findViewById(R.id.numberpicker_repeats_ex);
                    //Since we decide to have all spinners pre-populated no need to check data
                    Exercise e = new Exercise();
                    e.setName(spinExName.getSelectedItem().toString());
                    e.setMuscleGroup(spinMuscleGroup.getSelectedItem().toString());
                    e.setRepeats(numpickRepeats.getValue());
                    //Identifying program and training
                    long programId = MainActivity.this.getActiveProgramId();
                    TrainingDAO td = new TrainingDAO(MainActivity.this);
                    long trId = td.getTrainingByName(programId, trainName).getId();
                    e.setTrainId(trId);

                    //Insert new entry to db
                    ExerciseDAO ed = new ExerciseDAO(MainActivity.this);
                    long exId = ed.createExercise(e).getId();
                    e.setId(exId);
                    Toast.makeText(MainActivity.this, getText(R.string.toast_add_exercise_ok),
                            Toast.LENGTH_SHORT).show();
                    tla.addExercise(e, trainName);
                    dialogEx.dismiss();
                }
            });

        }
    });
    dialogEx.show();
    // Populate dialog fields
    NumberPicker np = (NumberPicker) dialogEx.findViewById(R.id.numberpicker_repeats_ex);
    final Spinner spinMuscleGroup = (Spinner) dialogEx.findViewById(R.id.spinner_select_mg_ex);
    final Spinner spinExName = (Spinner) dialogEx.findViewById(R.id.spinner_select_ex);
    np.setMaxValue(Exercise.MAX_REPEATS);
    np.setMinValue(Exercise.MIN_REPEATS);

    //Filling muscle groups spinner
    String[] muscleGroups = getResources().getStringArray(R.array.muscle_groups);

    ArrayAdapter<String> mgAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,
            muscleGroups);
    spinMuscleGroup.setAdapter(mgAdapter);

    spinMuscleGroup.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            String arrayName = ("exercises_" + spinMuscleGroup.getSelectedItem().toString()).toLowerCase();
            int id = getResources().getIdentifier(arrayName, "array", MainActivity.this.getPackageName());
            String[] exercises = getResources().getStringArray(id);
            ArrayAdapter<String> exAdapter = new ArrayAdapter<String>(MainActivity.this,
                    android.R.layout.simple_spinner_item, exercises);
            spinExName.setAdapter(exAdapter);
        }

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

        }
    });
    spinMuscleGroup.setSelection(1);

}