Java Code Examples for android.widget.NumberPicker

The following are top voted examples for showing how to use android.widget.NumberPicker. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: GitHub   File: CustomTileDimensions.java   Source Code and License 7 votes vote down vote up
@OnClick(R.id.custom_tile_width_size)
public void onWidthClick() {
  final NumberPicker view = new NumberPicker(this);
  view.setMinValue(24);
  view.setMaxValue(64);
  view.setWrapSelectorWheel(false);
  view.setValue(currentTileWidth);
  new AlertDialog.Builder(this)
          .setView(view)
          .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(@NonNull DialogInterface dialog, int which) {
              currentTileWidth = view.getValue();
              widget.setTileWidthDp(currentTileWidth);
            }
          })
          .show();
}
 
Example 2
Project: GitHub   File: CustomTileDimensions.java   Source Code and License 7 votes vote down vote up
@OnClick(R.id.custom_tile_height_size)
public void onHeightClick() {
  final NumberPicker view = new NumberPicker(this);
  view.setMinValue(24);
  view.setMaxValue(64);
  view.setWrapSelectorWheel(false);
  view.setValue(currentTileHeight);
  new AlertDialog.Builder(this)
          .setView(view)
          .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(@NonNull DialogInterface dialog, int which) {
              currentTileHeight = view.getValue();
              widget.setTileHeightDp(currentTileHeight);
            }
          })
          .show();
}
 
Example 3
Project: HighSchoolScienceBowlPractice-Android   File: StudyModeSettingsPage.java   Source Code and License 7 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_study_mode_settings_page);

    biologyButton = (ToggleButton) findViewById(R.id.biologyButton);
    chemistryButton = (ToggleButton) findViewById(R.id.chemistryButton);
    earthAndSpaceButton = (ToggleButton) findViewById(R.id.earthAndSpaceButton);
    energyButton = (ToggleButton) findViewById(R.id.energyButton);
    mathButton = (ToggleButton) findViewById(R.id.mathButton);
    physicsButton = (ToggleButton) findViewById(R.id.physicsButton);
    randomButton = (ToggleButton) findViewById(R.id.randomButton);

    roundNumPicker = (NumberPicker) findViewById(R.id.roundNumPicker);
    roundNumPicker.setMinValue(0);
    roundNumPicker.setMaxValue(roundOptions.length-1);
    roundNumPicker.setWrapSelectorWheel(false);
    roundNumPicker.setDisplayedValues(roundOptions);

    menuButton = (Button) findViewById(R.id.menuButton);
}
 
Example 4
Project: CatchSpy   File: GlobalSettingsFragment.java   Source Code and License 6 votes vote down vote up
@SuppressWarnings("SameParameterValue")
private void playerNumberAlert(String title, final String preferenceName, int min, int max, int default_num) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    LayoutInflater inflater = LayoutInflater.from(getActivity());
    View mView = inflater.inflate(R.layout.dialog_number_picker, (ViewGroup) getActivity().findViewById(R.id.dialog_layout_number_picker));
    final NumberPicker numberPicker = mView.findViewById(R.id.dialog_number_picker);
    numberPicker.setMinValue(min);
    numberPicker.setMaxValue(max);
    numberPicker.setValue(default_num);
    builder.setTitle(title);
    builder.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            sharedPreferences.edit().putInt(preferenceName, numberPicker.getValue()).apply();
        }
    });
    builder.setNegativeButton(android.R.string.no, null);
    builder.setView(mView);
    builder.show();
}
 
Example 5
Project: GitHub   File: DynamicSettersActivity.java   Source Code and License 6 votes vote down vote up
@OnClick(R.id.button_set_tile_size)
void onTileSizeClicked() {
    final NumberPicker view = new NumberPicker(this);
    view.setMinValue(24);
    view.setMaxValue(64);
    view.setWrapSelectorWheel(false);
    view.setValue(currentTileSize);
    new AlertDialog.Builder(this)
            .setView(view)
            .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(@NonNull DialogInterface dialog, int which) {
                    currentTileSize = view.getValue();
                    widget.setTileSizeDp(currentTileSize);
                }
            })
            .show();
}
 
Example 6
Project: HustEating   File: SettingFragment.java   Source Code and License 6 votes vote down vote up
/**
 * 初始化传入的moneyPicker
 *
 * @param numberPickerArrayList 需要初始化的NumPicker
 */
private void initNumPicker(ArrayList<NumberPicker> numberPickerArrayList) {
    Iterator iterator = numberPickerArrayList.iterator();
    while (iterator.hasNext()) {
        NumberPicker moneyPicker = (NumberPicker) iterator.next();
        moneyPicker.setFormatter(this);
        moneyPicker.setOnValueChangedListener(this);
        moneyPicker.setOnScrollListener(this);
        moneyPicker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
    }

    numberPickerArrayList.get(0).setMinValue(3);numberPickerArrayList.get(0).setMaxValue(15);//早餐的价格区间
    numberPickerArrayList.get(1).setMinValue(5);numberPickerArrayList.get(1).setMaxValue(30);//午餐的价格区间
    numberPickerArrayList.get(2).setMinValue(5);numberPickerArrayList.get(2).setMaxValue(30);//晚餐的价格区间


    numberPickerArrayList.get(0).setValue(preferences.getInt("moneyBreakfastChosen", 5));//早餐默认为5
    numberPickerArrayList.get(1).setValue(preferences.getInt("moneyLunchChosen", 10));//午饭默认为10
    numberPickerArrayList.get(2).setValue(preferences.getInt("moneyDinnerChosen", 12));//早餐默认为12

}
 
Example 7
Project: LiveNotes   File: KeySigDialogFragment.java   Source Code and License 6 votes vote down vote up
private void initializeViews(Dialog dialog) {
    major = (ToggleButton) dialog.findViewById(R.id.major);
    minor = (ToggleButton) dialog.findViewById(R.id.minor);
    dialog.findViewById(R.id.major_parent).setOnClickListener(__ -> onMajorClicked());
    dialog.findViewById(R.id.minor_parent).setOnClickListener(__ -> onMinorClicked());

    keySigImage = (ImageView) dialog.findViewById(R.id.key_sig_image);

    key = (NumberPicker) dialog.findViewById(R.id.key);
    key.setWrapSelectorWheel(false);
    key.setMinValue(0);
    key.setMaxValue(KeySigHandler.FIFTHS.length - 1);

    major.setChecked(false);
    onMajorClicked();
    key.setOnValueChangedListener(this);
    key.setValue(6);
}
 
Example 8
Project: orgzly-android   File: EspressoUtils.java   Source Code and License 6 votes vote down vote up
/**
 * Set value for {@link NumberPicker}
 */
public static ViewAction setNumber(final int n) {
    return new ViewAction() {
        @Override
        public void perform(UiController uiController, View view) {
            ((NumberPicker) view).setValue(n);
        }

        @Override
        public String getDescription() {
            return "Set NumberPicker value";
        }

        @Override
        public Matcher<View> getConstraints() {
            return ViewMatchers.isAssignableFrom(NumberPicker.class);
        }
    };
}
 
Example 9
Project: what_are_those_app   File: AgeScreen.java   Source Code and License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_age);
    final EditText ageEdit = (EditText) findViewById(R.id.age);

    ageEdit.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (!hasFocus) {
                hideKeyboard(v);
                ageEdit.setCursorVisible(false);
            } else {
                showKeyboard(v);
                ageEdit.setCursorVisible(true);
            }
        }
    });

    NumberPicker numberPicker = (NumberPicker) findViewById(R.id.numberPicker);
    numberPicker.setMaxValue(28);
    numberPicker.setMinValue(1);

    NumberPicker stringPicker = (NumberPicker) findViewById(R.id.stringPicker);
    stringPicker.setMaxValue(2);
    stringPicker.setMinValue(0);
    stringPicker.setDisplayedValues( new String[] { "Days", "Months", "Years" } );

}
 
Example 10
Project: OneTwo   File: ListAdapter.java   Source Code and License 6 votes vote down vote up
public ListAdapterViewHolder(View view) {
    super(view);
    mTextView = (TextView) view.findViewById(R.id.tv_object_data);
    removeButton = (Button) view.findViewById(R.id.remove_button);
    numberPicker = (NumberPicker) view.findViewById(R.id.number_picker);
    numberPicker.setMaxValue(99999);
    numberPicker.setMinValue(0);
    numberPicker.setOnScrollListener(this);
    numberPicker.setOnValueChangedListener(this);
    numberPicker.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            v.performClick();
            return true;
        }
    });
    view.setOnClickListener(this);
}
 
Example 11
Project: HighSchoolScienceBowlPractice-Android   File: ReaderModeSettingsPage.java   Source Code and License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_reader_mode_settings_page);

    setNumPicker = (NumberPicker) findViewById(R.id.setNumPicker);
    setNumPicker.setMinValue(0);
    setNumPicker.setMaxValue(setOptions.length-1);
    setNumPicker.setWrapSelectorWheel(false);
    setNumPicker.setDisplayedValues(setOptions);

    roundNumPicker = (NumberPicker) findViewById(R.id.roundNumPicker);
    roundNumPicker.setMinValue(0);
    roundNumPicker.setMaxValue(roundOptions.length-1);
    roundNumPicker.setWrapSelectorWheel(false);
    roundNumPicker.setDisplayedValues(roundOptions);

    tossupTimeSpinner = (Spinner) findViewById(R.id.tossupTimeSelector);
    bonusTimeSpinner = (Spinner) findViewById(R.id.bonusTimeSelector);

    menuButton = (Button) findViewById(R.id.menuButton);
}
 
Example 12
Project: FitterNumberPicker   File: MainActivity.java   Source Code and License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitle(R.string.app_name);

    NumberPicker stockNumberPicker = (NumberPicker) findViewById(R.id.stock);
    stockNumberPicker.setMinValue(0);
    stockNumberPicker.setMaxValue(10);

    FitterNumberPicker defaultNumberPicker = (FitterNumberPicker) findViewById(R.id.default_number_picker);
    FitterNumberPicker customNumberPicker = (FitterNumberPicker) findViewById(R.id.custom_number_picker);

    ViewConfiguration configuration = ViewConfiguration.get(this);
    //This would be a good value to start with, then / or * to adjust
    //By default, the velocity is divided by 8, so do what you want to adjust
    int maxFlingVelocity = configuration.getScaledMaximumFlingVelocity() / 6;
    customNumberPicker.setMaximumFlingVelocity(maxFlingVelocity);
}
 
Example 13
Project: FitterNumberPicker   File: FitterNumberPicker.java   Source Code and License 6 votes vote down vote up
/**
 * Uses reflection to access divider private attribute and override its color
 * Use Color.Transparent if you wish to hide them
 *
 * @return true if separator set, false if field was not accessible
 */
public boolean setSeparatorColor(int separatorColor) {
    this.separatorColor = separatorColor;
    if (fieldPickerDivider == null) {
        Field[] pickerFields = NumberPicker.class.getDeclaredFields();
        for (Field pf : pickerFields) {
            if (pf.getName().equals("mSelectionDivider")) {
                pf.setAccessible(true);
                fieldPickerDivider = pf;
                break;
            }
        }
    }
    if (fieldPickerDivider != null) {
        try {
            fieldPickerDivider.set(this, new ColorDrawable(separatorColor));
        } catch (IllegalAccessException | IllegalArgumentException e) {
            return false;
        }
    } else {
        return false;
    }
    return true;
}
 
Example 14
Project: FitterNumberPicker   File: FitterNumberPicker.java   Source Code and License 6 votes vote down vote up
private boolean updateSelectorWheelPaint() {
    if (selectorWheelPaint == null) {
        try {
            Field selectorWheelPaintField = NumberPicker.class.getDeclaredField("mSelectorWheelPaint");
            selectorWheelPaintField.setAccessible(true);

            selectorWheelPaint = ((Paint) selectorWheelPaintField.get(this));
        } catch (Exception e) {
            return false;
        }
    }
    if (selectorWheelPaint != null) {
        selectorWheelPaint.setColor(textColor);
        selectorWheelPaint.setTextSize(textSize);
        invalidate();
        return true;
    }
    return false;
}
 
Example 15
Project: aos-Video   File: SubtitleDelayTVPicker.java   Source Code and License 6 votes vote down vote up
public SubtitleDelayTVPicker(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    mContext=context;
    slaveView=null;
    final NumberPicker.Formatter twoDigitFormatter = new NumberPicker.Formatter() {
        final StringBuilder mBuilder = new StringBuilder();
        final java.util.Formatter mFmt = new java.util.Formatter(mBuilder, java.util.Locale.US);
        final Object[] mArgs = new Object[1];
        public String format(int value) {
            mArgs[0] = value;
            mBuilder.delete(0, mBuilder.length());
            mFmt.format("%02d", mArgs);
            return mFmt.toString();
        }
    };

   
    init();
    if (!isEnabled()) {
        setEnabled(false);
    }
}
 
Example 16
Project: Runnest   File: RequestChallengeDialogFragment.java   Source Code and License 6 votes vote down vote up
private void setDividerColor(NumberPicker picker, int color) {

        java.lang.reflect.Field[] pickerFields = NumberPicker.class.getDeclaredFields();
        for (java.lang.reflect.Field pf : pickerFields) {
            if (pf.getName().equals("mSelectionDivider")) {
                pf.setAccessible(true);
                try {
                    ColorDrawable colorDrawable = new ColorDrawable(color);
                    pf.set(picker, colorDrawable);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                break;
            }
        }
    }
 
Example 17
Project: calendarview2   File: CustomTileDimensions.java   Source Code and License 6 votes vote down vote up
@OnClick(R.id.custom_tile_width_size)
public void onWidthClick() {
  final NumberPicker view = new NumberPicker(this);
  view.setMinValue(24);
  view.setMaxValue(64);
  view.setWrapSelectorWheel(false);
  view.setValue(currentTileWidth);
  new AlertDialog.Builder(this)
          .setView(view)
          .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(@NonNull DialogInterface dialog, int which) {
              currentTileWidth = view.getValue();
              widget.setTileWidthDp(currentTileWidth);
            }
          })
          .show();
}
 
Example 18
Project: calendarview2   File: CustomTileDimensions.java   Source Code and License 6 votes vote down vote up
@OnClick(R.id.custom_tile_height_size)
public void onHeightClick() {
  final NumberPicker view = new NumberPicker(this);
  view.setMinValue(24);
  view.setMaxValue(64);
  view.setWrapSelectorWheel(false);
  view.setValue(currentTileHeight);
  new AlertDialog.Builder(this)
          .setView(view)
          .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(@NonNull DialogInterface dialog, int which) {
              currentTileHeight = view.getValue();
              widget.setTileHeightDp(currentTileHeight);
            }
          })
          .show();
}
 
Example 19
Project: calendarview2   File: DynamicSettersActivity.java   Source Code and License 6 votes vote down vote up
@OnClick(R.id.button_set_tile_size)
void onTileSizeClicked() {
    final NumberPicker view = new NumberPicker(this);
    view.setMinValue(24);
    view.setMaxValue(64);
    view.setWrapSelectorWheel(false);
    view.setValue(currentTileSize);
    new AlertDialog.Builder(this)
            .setView(view)
            .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(@NonNull DialogInterface dialog, int which) {
                    currentTileSize = view.getValue();
                    widget.setTileSizeDp(currentTileSize);
                }
            })
            .show();
}
 
Example 20
Project: wallpaperboard   File: RefreshDurationFragment.java   Source Code and License 6 votes vote down vote up
private void setDividerColor (NumberPicker picker) {
    java.lang.reflect.Field[] pickerFields = NumberPicker.class.getDeclaredFields();
    for (java.lang.reflect.Field pf : pickerFields) {
        if (pf.getName().equals("mSelectionDivider")) {
            pf.setAccessible(true);
            try {
                int color = ColorHelper.getAttributeColor(getActivity(), R.attr.colorAccent);
                pf.set(picker, DrawableHelper.getTintedDrawable(
                        getActivity(), R.drawable.numberpicker_divider, color));
            } catch (Exception e) {
                LogUtil.e(Log.getStackTraceString(e));
            }
            break;
        }
    }
}
 
Example 21
Project: iconsole-android   File: BluetoothChatFragment.java   Source Code and License 6 votes vote down vote up
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    //mConversationView = (ListView) view.findViewById(R.id.in);
    mStartButton = (Button) view.findViewById(R.id.button_start);
    mStopButton = (Button) view.findViewById(R.id.button_stop);
    mDisconnectButton = (Button) view.findViewById(R.id.button_disconnect);
    mLevel = (NumberPicker) view.findViewById(R.id.Level);
    mLevel.setMaxValue(32);
    mLevel.setMinValue(1);
    mLevel.setValue(1);
    mLevel.setWrapSelectorWheel(false);
    mLevel.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
    mSpeedText = (TextView) view.findViewById(R.id.Speed);
    mPowerText = (TextView) view.findViewById(R.id.Power);
    mRPMText = (TextView) view.findViewById(R.id.RPM);
    mDistanceText = (TextView) view.findViewById(R.id.Distance);
    mCaloriesText = (TextView) view.findViewById(R.id.Calories);
    mHFText = (TextView) view.findViewById(R.id.Heart);
    mTimeText = (TextView) view.findViewById(R.id.Time);
}
 
Example 22
Project: MobiRNN-EMDL17   File: PhoneActivity.java   Source Code and License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    controlToggle = (ToggleButton) findViewById(R.id.toggle_control);

    mStatusTextView = (TextView) findViewById(R.id.tv_status);
    mStatusTextView.setMovementMethod(new ScrollingMovementMethod());
    mResultProgress = (ProgressBar) findViewById(R.id.progress);
    mResultProgress.setMax(100);

    NumberPicker picker = (NumberPicker) findViewById(R.id.number_picker);
    picker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
    picker.setOnValueChangedListener(this);
    picker.setDisplayedValues(mSampleSizes);
    picker.setMinValue(0);
    picker.setMaxValue(mSampleSizes.length - 1);
    picker.setWrapSelectorWheel(true);
    picker.setValue(0);
    mSampleSize = 1;
    Logger.i("Sample size initial value: %s", mSampleSize);

    checkPermissions();

}
 
Example 23
Project: android-chessclock   File: TimePickerView.java   Source Code and License 6 votes vote down vote up
/**
 * Set the reference of seconds picker, its digit format and register value change listener.
 *
 * @param pickerVisible if false, removes the spinner widget.
 */
@TargetApi(11)
protected void setupSecondPicker(boolean pickerVisible) {
    mSecondPicker = (NumberPicker) findViewById(R.id.seconds);
    if (pickerVisible) {
        mSecondPicker.setMinValue(0);
        mSecondPicker.setMaxValue(59);
        mSecondPicker.setFormatter(TWO_DIGIT_FORMATTER);
        mSecondPicker.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
            @Override
            public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
                mCurrentSecond = newVal;
            }
        });
    } else {
        mHourPicker.setVisibility(View.GONE);
    }
}
 
Example 24
Project: android-chessclock   File: TimePickerView.java   Source Code and License 6 votes vote down vote up
/**
 * Set the reference of minute picker, its digit format and register value change listener.
 *
 * @param pickerVisible if false, removes the spinner widget.
 */
@TargetApi(11)
protected void setupMinutePicker(boolean pickerVisible) {
    mMinutePicker = (NumberPicker) findViewById(R.id.minute);
    if (pickerVisible) {
        mMinutePicker.setMinValue(0);
        mMinutePicker.setMaxValue(59);
        mMinutePicker.setFormatter(TWO_DIGIT_FORMATTER);
        mMinutePicker.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
            @Override
            public void onValueChange(NumberPicker spinner, int oldVal, int newVal) {
                mCurrentMinute = newVal;
            }
        });
    } else {
        mMinutePicker.setVisibility(View.GONE);
        findViewById(R.id.minute_divider).setVisibility(View.GONE);
    }
}
 
Example 25
Project: android-chessclock   File: TimePickerView.java   Source Code and License 6 votes vote down vote up
/**
 * Set the reference of hour picker, its digit format and register value change listener.
 *
 * @param pickerVisible if false, removes the spinner widget.
 */
@TargetApi(11)
protected void setupHourPicker(boolean pickerVisible) {

    mHourPicker = (NumberPicker) findViewById(R.id.hour);
    if (pickerVisible) {
        mHourPicker.setMinValue(0);
        mHourPicker.setMaxValue(10);
        mHourPicker.setFormatter(TWO_DIGIT_FORMATTER);
        mHourPicker.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
            @Override
            public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
                mCurrentHour = newVal;
            }
        });
    } else {
        mHourPicker.setVisibility(View.GONE);
        findViewById(R.id.hour_divider).setVisibility(View.GONE);
    }
}
 
Example 26
Project: candybar-library   File: CandyBarMuzeiActivity.java   Source Code and License 6 votes vote down vote up
private void setDividerColor (NumberPicker picker) {
    java.lang.reflect.Field[] pickerFields = NumberPicker.class.getDeclaredFields();
    for (java.lang.reflect.Field pf : pickerFields) {
        if (pf.getName().equals("mSelectionDivider")) {
            pf.setAccessible(true);
            try {
                pf.set(picker, ContextCompat.getDrawable(this,
                        Preferences.get(this).isDarkTheme() ?
                                R.drawable.numberpicker_divider_dark :
                                R.drawable.numberpicker_divider));
            } catch (Exception e) {
                LogUtil.e(Log.getStackTraceString(e));
            }
            break;
        }
    }
}
 
Example 27
Project: RPG-Software   File: DiceActivity.java   Source Code and License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_dice);
    mTextViewResult = (TextView)findViewById(R.id.textView_Result);
    Button buttonThrow = (Button)findViewById(R.id.button_throw);
    final NumberPicker numberPickerMin = (NumberPicker)findViewById(R.id.numberPickerMin);
    final NumberPicker numberPickerMax = (NumberPicker)findViewById(R.id.numberPickerMax);
    numberPickerMin.setMinValue(1);
    numberPickerMin.setMaxValue(100);
    numberPickerMax.setMinValue(1);
    numberPickerMax.setMaxValue(100);
    numberPickerMax.setValue(6);

    buttonThrow.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Dice d = new Dice(numberPickerMin.getValue(),numberPickerMax.getValue());
            int result = d.diceGenerator();
            mTextViewResult.setText("Result : " + result);
        }
    });
}
 
Example 28
Project: MyWorld   File: NewPeriodicCareFragment.java   Source Code and License 6 votes vote down vote up
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_new_periodic_care, container, false);
    goalPicker = (NumberPicker) view.findViewById(R.id.goal_picker);
    punishmentPicker = (NumberPicker) view.findViewById(R.id.punishment_picker);
    lengthPicker = (NumberPicker) view.findViewById(R.id.length_picker);
    unitPicker = (NumberPicker) view.findViewById(R.id.unit_picker);
    goalPicker.setMaxValue(Integer.MAX_VALUE);
    goalPicker.setMinValue(1);
    goalPicker.setWrapSelectorWheel(false);
    punishmentPicker.setMaxValue(Integer.MAX_VALUE);
    punishmentPicker.setMinValue(0);
    punishmentPicker.setValue(1);
    punishmentPicker.setWrapSelectorWheel(false);
    lengthPicker.setMaxValue(Integer.MAX_VALUE);
    lengthPicker.setMinValue(1);
    lengthPicker.setWrapSelectorWheel(false);
    unitPicker.setDisplayedValues(getResources().getStringArray(R.array.period_units));
    unitPicker.setMaxValue(3);
    unitPicker.setMinValue(0);
    unitPicker.setValue(3);
    unitPicker.setWrapSelectorWheel(true);
    return view;
}
 
Example 29
Project: yun2win-sdk-android   File: ChooseDateDialog.java   Source Code and License 6 votes vote down vote up
/**
 * 得到viewGroup里面的numberpicker组件
 * @param viewGroup
 * @return
 */
private List<NumberPicker> findNumberPicker(ViewGroup viewGroup){
    List<NumberPicker> npList = new ArrayList<NumberPicker>();
    View child = null;
    if(null != viewGroup){
        for(int i = 0; i < viewGroup.getChildCount(); i++){
            child = viewGroup.getChildAt(i);
            if(child instanceof NumberPicker){
                npList.add((NumberPicker)child);
            }
            else if(child instanceof LinearLayout){
                List<NumberPicker> result = findNumberPicker((ViewGroup)child);
                if(result.size()>0){
                    return result;
                }
            }
        }
    }
    return npList;
}
 
Example 30
Project: xDrip   File: SnoozeActivity.java   Source Code and License 6 votes vote down vote up
static void SetSnoozePickerValues(NumberPicker picker, boolean above, int default_snooze) {
    String[] values=new String[snoozeValues.length];
    for(int i=0;i<values.length;i++){
        values[i]=getNameFromTime(snoozeValues[i]);
    }

    picker.setMaxValue(values.length -1);
    picker.setMinValue(0);
    picker.setDisplayedValues(values);
    picker.setWrapSelectorWheel(false);
    if(default_snooze != 0) {
        picker.setValue(getSnoozeLocatoin(default_snooze));
    } else {
        picker.setValue(getSnoozeLocatoin(getDefaultSnooze(above)));
    }
}
 
Example 31
Project: xDrip   File: SnoozeActivity.java   Source Code and License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //KS if (Home.get_holo()) { setTheme(R.style.OldAppTheme); }
    setContentView(R.layout.activity_snooze);
    alertStatus = (TextView) findViewById(R.id.alert_status);
    snoozeValue = (NumberPicker) findViewById(R.id.snooze);

    prefs =  PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    doMgdl = (prefs.getString("units", "mgdl").compareTo("mgdl") == 0);

    addListenerOnButton();
    if(BgGraphBuilder.isXLargeTablet(getApplicationContext())) {
        alertStatus.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);
        buttonSnooze.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);
    }
    displayStatus();
}
 
Example 32
Project: xDrip   File: SnoozeActivity.java   Source Code and License 6 votes vote down vote up
static void SetSnoozePickerValues(NumberPicker picker, boolean above, int default_snooze) {
    String[] values=new String[snoozeValues.length];
    for(int i=0;i<values.length;i++){
        values[i]=getNameFromTime(snoozeValues[i]);
    }

    picker.setMaxValue(values.length -1);
    picker.setMinValue(0);
    picker.setDisplayedValues(values);
    picker.setWrapSelectorWheel(false);
    if(default_snooze != 0) {
        picker.setValue(getSnoozeLocatoin(default_snooze));
    } else {
        picker.setValue(getSnoozeLocatoin(getDefaultSnooze(above)));
    }
}
 
Example 33
Project: xDrip   File: SnoozeActivity.java   Source Code and License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (Home.get_holo()) { setTheme(R.style.OldAppThemeNoTitleBar); }
    JoH.fixActionBar(this);
    setContentView(R.layout.activity_snooze);
    alertStatus = (TextView) findViewById(R.id.alert_status);
    snoozeValue = (NumberPicker) findViewById(R.id.snooze);

    prefs =  PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    doMgdl = (prefs.getString("units", "mgdl").compareTo("mgdl") == 0);

    addListenerOnButton();
    if(BgGraphBuilder.isXLargeTablet(getApplicationContext())) {
        alertStatus.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);
        buttonSnooze.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);
    }
    displayStatus();
}
 
Example 34
Project: xDrip-plus   File: SnoozeActivity.java   Source Code and License 6 votes vote down vote up
static void SetSnoozePickerValues(NumberPicker picker, boolean above, int default_snooze) {
    String[] values=new String[snoozeValues.length];
    for(int i=0;i<values.length;i++){
        values[i]=getNameFromTime(snoozeValues[i]);
    }

    picker.setMaxValue(values.length -1);
    picker.setMinValue(0);
    picker.setDisplayedValues(values);
    picker.setWrapSelectorWheel(false);
    if(default_snooze != 0) {
        picker.setValue(getSnoozeLocatoin(default_snooze));
    } else {
        picker.setValue(getSnoozeLocatoin(getDefaultSnooze(above)));
    }
}
 
Example 35
Project: xDrip-plus   File: SnoozeActivity.java   Source Code and License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //KS if (Home.get_holo()) { setTheme(R.style.OldAppTheme); }
    setContentView(R.layout.activity_snooze);
    alertStatus = (TextView) findViewById(R.id.alert_status);
    snoozeValue = (NumberPicker) findViewById(R.id.snooze);

    prefs =  PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    doMgdl = (prefs.getString("units", "mgdl").compareTo("mgdl") == 0);

    addListenerOnButton();
    if(BgGraphBuilder.isXLargeTablet(getApplicationContext())) {
        alertStatus.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);
        buttonSnooze.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);
    }
    displayStatus();
}
 
Example 36
Project: xDrip-plus   File: SnoozeActivity.java   Source Code and License 6 votes vote down vote up
static void SetSnoozePickerValues(NumberPicker picker, boolean above, int default_snooze) {
    String[] values=new String[snoozeValues.length];
    for(int i=0;i<values.length;i++){
        values[i]=getNameFromTime(snoozeValues[i]);
    }

    picker.setMaxValue(values.length -1);
    picker.setMinValue(0);
    picker.setDisplayedValues(values);
    picker.setWrapSelectorWheel(false);
    if(default_snooze != 0) {
        picker.setValue(getSnoozeLocatoin(default_snooze));
    } else {
        picker.setValue(getSnoozeLocatoin(getDefaultSnooze(above)));
    }
}
 
Example 37
Project: xDrip-plus   File: SnoozeActivity.java   Source Code and License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (Home.get_holo()) { setTheme(R.style.OldAppThemeNoTitleBar); }
    JoH.fixActionBar(this);
    setContentView(R.layout.activity_snooze);
    alertStatus = (TextView) findViewById(R.id.alert_status);
    snoozeValue = (NumberPicker) findViewById(R.id.snooze);

    prefs =  PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    doMgdl = (prefs.getString("units", "mgdl").compareTo("mgdl") == 0);

    addListenerOnButton();
    if(BgGraphBuilder.isXLargeTablet(getApplicationContext())) {
        alertStatus.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);
        buttonSnooze.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);
    }
    displayStatus();
}
 
Example 38
Project: DialogAlchemy   File: NumberPickerStone.java   Source Code and License 6 votes vote down vote up
@Override
public void bindView(Dialog dialog) {
    textView = (TextView) dialog.findViewById(R.id.description);
    numberPicker = (NumberPicker) dialog.findViewById(R.id.number_picker);

    textView.setText(description);

    numberPicker.setMaxValue(maxValue != null ? maxValue : 24);
    numberPicker.setMinValue(minValue != null ? minValue : 1);
    numberPicker.setOnLongPressUpdateInterval(100);
    numberPicker.setWrapSelectorWheel(false);
    if (currentValue != null) {
        numberPicker.setValue(currentValue);
    }
    if (!canUseKeyBoard) {
        numberPicker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
    }
}
 
Example 39
Project: YingBeautyNote   File: DateTimePicker.java   Source Code and License 6 votes vote down vote up
@Override
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
    int minValue = mMinuteSpinner.getMinValue();
    int maxValue = mMinuteSpinner.getMaxValue();
    int offset = 0;
    if (oldVal == maxValue && newVal == minValue) {
        offset += 1;
    } else if (oldVal == minValue && newVal == maxValue) {
        offset -= 1;
    }
    if (offset != 0) {
        mDate.add(Calendar.HOUR_OF_DAY, offset);
        mHourSpinner.setValue(getCurrentHour());
        updateDateControl();
        int newHour = getCurrentHourOfDay();
        if (newHour >= HOURS_IN_HALF_DAY) {
            mIsAm = false;
            updateAmPmControl();
        } else {
            mIsAm = true;
            updateAmPmControl();
        }
    }
    mDate.set(Calendar.MINUTE, newVal);
    onDateTimeChanged();
}
 
Example 40
Project: medical-data-android   File: TestActivity.java   Source Code and License 6 votes vote down vote up
/**
 * Auxiliar function to get questions 8 to 10 value and set an error if they have not been
 * answered.
 *
 * @param i     Number of question
 * @param id    {@link RatingStars} id
 * @param text  {@link TextView} id of the question title
 * @param error {@link TextView} title of the first question title whose question has an error
 * @return <code>true</code> if an error was set; <code>false</code> otherwise.
 */
private TextView NumberPickerAnswered(int i, int id, int text, TextView error) {
    NumberPicker np = (NumberPicker) findViewById(id);
    int value = np.getValue();
    TextView tv = (TextView) findViewById(text);
    if (value == 0) {
        tv.setError("");
        if (error == null) {
            return tv;
        }
    } else {
        questions[i] = ((i == 7) ? (value - 1) * 10 : (value - 1));
        tv.setError(null);
    }
    return error;
}
 
Example 41
Project: msb-android   File: SelectCityDialogV11.java   Source Code and License 6 votes vote down vote up
@Override
protected void initPicker() {
	mProvincePicker = (NumberPicker) findViewById(R.id.province);
	mCityPicker = (NumberPicker) findViewById(R.id.city);

	mProvincePicker.setDisplayedValues(mProvinceNames);
	mProvincePicker.setMinValue(0);
	mProvincePicker.setMaxValue(mAreas.size() - 1);
	mProvincePicker.setOnValueChangedListener(this);

	int provinceIndex = getDefaultProvinceIndex(mProvince);
	mProvincePicker.setValue(provinceIndex);

	updateCityPicker(provinceIndex);

	int cityIndex = getDefaultCityIndex(provinceIndex, mCity);
	mCityPicker.setValue(cityIndex);
}
 
Example 42
Project: rabbitmq-management-android   File: PortNumberPicker.java   Source Code and License 6 votes vote down vote up
protected void initializeWidgets() {
  part10000 = (NumberPicker) findViewById(R.id.port_picker_part_10000);
  part1000 = (NumberPicker) findViewById(R.id.port_picker_part_1000);
  part100 = (NumberPicker) findViewById(R.id.port_picker_part_100);
  part10 = (NumberPicker) findViewById(R.id.port_picker_part_10);
  part1 = (NumberPicker) findViewById(R.id.port_picker_part_1);

  NumberPicker[] pickers = new NumberPicker[] { part10000, part1000, part100, part10, part1 };

  for (int i = 0; i < pickers.length; ++i) {
    pickers[i].setWrapSelectorWheel(false);
    pickers[i].setDisplayedValues(PART_VALUES);
    pickers[i].setMinValue(PART_MIN_VALUE);
    pickers[i].setMaxValue(PART_VALUES.length - 1);
  }
}
 
Example 43
Project: MaterialPreference   File: NumberPickerPreference.java   Source Code and License 6 votes vote down vote up
@SuppressLint("RestrictedApi")
public NumberPickerPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);

    mNumberPicker = new NumberPicker(context);

    TypedArray a;
    a = context.obtainStyledAttributes(attrs, R.styleable.NumberPickerPreference);
    mNumberPicker.setMinValue(a.getInt(R.styleable.NumberPickerPreference_min, 0));
    mNumberPicker.setMaxValue(a.getInt(R.styleable.NumberPickerPreference_max, 100));

    a = context.obtainStyledAttributes(attrs,
            R.styleable.Preference, defStyleAttr, defStyleRes);

    mSummary = TypedArrayUtils.getString(a, R.styleable.Preference_summary,
            R.styleable.Preference_android_summary);

    a.recycle();
}
 
Example 44
Project: CutoutViewIndicator   File: MainViewBinding.java   Source Code and License 6 votes vote down vote up
public MainViewBinding(View root) {
    this.root = (ViewGroup) root;

    toolbar = (Toolbar) root.findViewById(R.id.toolbar);
    mainViewPager = (ViewPager) root.findViewById(R.id.mainViewPager);
    fab = (FloatingActionButton) root.findViewById(R.id.fab);

    cvi = (CutoutViewIndicator) root.findViewById(R.id.cutoutViewIndicator);

    spacing = (NumberPicker) root.findViewById(R.id.spacingPicker);
    width = (NumberPicker) root.findViewById(R.id.widthPicker);
    height = (NumberPicker) root.findViewById(R.id.heightPicker);

    gridLayout = (GridLayout) root.findViewById(R.id.gridLayout);

    unifiedButton = (CompoundButton) root.findViewById(R.id.unifiedSwitch);
    orientationButton = (CompoundButton) root.findViewById(R.id.orientationSwitch);
}
 
Example 45
Project: deglancer   File: StageSelectView.java   Source Code and License 6 votes vote down vote up
private void init() {
    inflate(getContext(), R.layout.stage_select_view, this);

    if (!isInEditMode()) {
        MainApplication.from(getContext()).getGraph().inject(this);

        npStage = (NumberPicker) findViewById(R.id.npStage);
        npDay = (NumberPicker) findViewById(R.id.npDay);
        npHour = (NumberPicker) findViewById(R.id.npHour);

        npStage.setMinValue(1);
        npStage.setMaxValue(5);

        npDay.setMinValue(1);
        npDay.setMaxValue(7);

        npHour.setMinValue(1);
        npHour.setMaxValue(23);

        npStage.setOnValueChangedListener(valueChangeListener);
        npDay.setOnValueChangedListener(valueChangeListener);
        npHour.setOnValueChangedListener(valueChangeListener);

        findViewById(R.id.btnSetStageAsCurrentStage).setOnClickListener(buttonClickListener);
    }
}
 
Example 46
Project: android-shengshiqu   File: SSQCustomPicker.java   Source Code and License 6 votes vote down vote up
@Override
public void setDisplayedValues(String[] displayedValues) {
    super.setDisplayedValues(displayedValues);

    int customDividerColor = customDividerColor();
    if(customDividerColor != 0) {
        Field[] pickerFields = NumberPicker.class.getDeclaredFields();
        for (Field pf : pickerFields) {
            if (pf.getName().equals("mSelectionDivider")) {
                pf.setAccessible(true);
                try {
                    //设置分割线的颜色值
                    pf.set(this, new ColorDrawable(customDividerColor));
                } catch (Exception e) {
                    e.printStackTrace();
                }
                break;
            }
        }
    }
}
 
Example 47
Project: android-shengshiqu   File: ShengShiQuPicker.java   Source Code and License 6 votes vote down vote up
private void init() {
    LayoutInflater.from(getContext()).inflate(inflateLayout(), this, true);

    shengPicker = findShengPicker();
    shiPicker = findShiPicker();
    quPicker = findQuPicker();

    // 关掉编辑模式
    shengPicker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
    shiPicker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
    quPicker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);

    shengPicker.setOnValueChangedListener(getShengPickerChangeListener());
    shiPicker.setOnValueChangedListener(getShiPickerChangeListener());
    quPicker.setOnValueChangedListener(getQuPickerChangeListener());

    loadData();
}
 
Example 48
Project: extend-enhance-base   File: NumberPickerPreferenceDialogFragmentCompat.java   Source Code and License 6 votes vote down vote up
@Override
protected void onBindDialogView(View view) {
    NumberPickerPreference preference = getNumberPickerPreference();

    numberPicker = (NumberPicker) view.findViewById(R.id.numberpicker);
    numberPicker.setMinValue(preference.getMinValue());
    numberPicker.setMaxValue(preference.getMaxValue());
    numberPicker.setValue(restoredState ? restoredValue : preference.getValue());
    if (preference.getDescendantFocusability() > 0) {
        //noinspection ResourceType
        numberPicker.setDescendantFocusability(preference.getDescendantFocusability());
    }
    numberPicker.setWrapSelectorWheel(preference.isWrapSelectorWheel());

    TextView textView = (TextView) view.findViewById(R.id.subtitle);
    textView.setText(preference.getSubtitleText());
}
 
Example 49
Project: Mobile-Office   File: MeetingFragment.java   Source Code and License 6 votes vote down vote up
/** 弹出数字选择器 **/
private void showNumPick() {
	final NumberPicker picker = new NumberPicker(getActivity());
	picker.setMinValue(0);
	picker.setMaxValue(200);
	picker.setValue(mMinTime);
	new AlertDialog.Builder(getActivity()).setView(picker)
		.setPositiveButton(getResources().getString(R.string.ok), new OnClickListener() {
			
			@Override
			public void onClick(DialogInterface dialog, int which) {
				mMinTime = picker.getValue();
				tv_min_time.setText(getResources().getString(R.string.search_min_time, mMinTime));
			}
		}).show();
}
 
Example 50
Project: FMTech   File: giq.java   Source Code and License 6 votes vote down vote up
public final Dialog c(Bundle paramBundle)
{
  Bundle localBundle = this.m;
  AlertDialog.Builder localBuilder = new AlertDialog.Builder(f());
  this.Z = new NumberPicker(this.ad);
  this.Z.setMinValue(localBundle.getInt("min"));
  this.Z.setMaxValue(localBundle.getInt("max"));
  this.Z.setValue(localBundle.getInt("current"));
  this.Z.setOnValueChangedListener(this);
  String[] arrayOfString = localBundle.getStringArray("displayedValues");
  int i = 1 + (this.Z.getMaxValue() - this.Z.getMinValue());
  if ((arrayOfString != null) && (arrayOfString.length == i)) {
    this.Z.setDisplayedValues(arrayOfString);
  }
  Resources localResources = g();
  localBuilder.setTitle(localBundle.getString("title")).setView(this.Z).setPositiveButton(localResources.getString(ehr.au), this).setNegativeButton(localResources.getString(ehr.at), this);
  return localBuilder.create();
}
 
Example 51
Project: Gizwits-SmartBuld_Android   File: GosScheduleEditDateAcitivty.java   Source Code and License 6 votes vote down vote up
private void initEvent() {
	tvBack.setOnClickListener(this);
	llAction.setOnClickListener(this);
	tvSave.setOnClickListener(this);
	llRepeat.setOnClickListener(this);

	npMin.setMaxValue(59);
	npMin.setMinValue(0);
	npMin.setOnLongPressUpdateInterval(100);
	npMin.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
	npMin.setFormatter(TWO_DIGIT_FORMATTER);
	setNumberPickerDividerColor(npMin);
	npHour.setMaxValue(23);
	npHour.setMinValue(0);
	npHour.setOnLongPressUpdateInterval(100);
	npHour.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
	npHour.setFormatter(TWO_DIGIT_FORMATTER);
	setNumberPickerDividerColor(npHour);

	String[] time = selectDate.getTvTime().split(":");
	int hour = Integer.parseInt(time[0]);
	int min = Integer.parseInt(time[1]);
	npHour.setValue(hour);
	npMin.setValue(min);

}
 
Example 52
Project: xDrip-Experimental   File: SnoozeActivity.java   Source Code and License 6 votes vote down vote up
static void SetSnoozePickerValues(NumberPicker picker, boolean above, int default_snooze) {
    String[] values=new String[snoozeValues.length];
    for(int i=0;i<values.length;i++){
        values[i]=getNameFromTime(snoozeValues[i]);
    }

    picker.setMaxValue(values.length -1);
    picker.setMinValue(0);
    picker.setDisplayedValues(values);
    picker.setWrapSelectorWheel(false);
    if(default_snooze != 0) {
        picker.setValue(getSnoozeLocatoin(default_snooze));
    } else {
        picker.setValue(getSnoozeLocatoin(getDefaultSnooze(above)));
    }
}
 
Example 53
Project: xDrip-Experimental   File: SnoozeActivity.java   Source Code and License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_snooze);
    alertStatus = (TextView) findViewById(R.id.alert_status);
    snoozeValue = (NumberPicker) findViewById(R.id.snooze);

    prefs =  PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    doMgdl = (prefs.getString("units", "mgdl").compareTo("mgdl") == 0);

    addListenerOnButton();
    if(BgGraphBuilder.isXLargeTablet(getApplicationContext())) {
        alertStatus.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);
        buttonSnooze.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);
    }
    displayStatus();
}
 
Example 54
Project: NumberPickerPreference   File: NumberPickerPreference.java   Source Code and License 6 votes vote down vote up
/**
 *
 * @return dialog view with picker inside
 */
@Override
protected View onCreateDialogView() {
    FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    layoutParams.gravity = Gravity.CENTER;

    numPicker= new NumberPicker(getContext());
    numPicker.setLayoutParams(layoutParams);
    numPicker.setMinValue(minValue);
    numPicker.setMaxValue(maxValue);

    FrameLayout dialogView = new FrameLayout(getContext());
    dialogView.addView(numPicker);

    return dialogView;
}
 
Example 55
Project: MaterialNumberPicker   File: MaterialNumberPicker.java   Source Code and License 6 votes vote down vote up
/**
 * Init number picker by disabling focusability of edit text embedded inside the number picker
 * We also override the edit text filter private attribute by using reflection as the formatter is still buggy while attempting to display the default value
 * This is still an open Google @see <a href="https://code.google.com/p/android/issues/detail?id=35482#c9">issue</a> from 2012
 */
private void initView() {
    setMinValue(MIN_VALUE);
    setMaxValue(MAX_VALUE);
    setValue(DEFAULT_VALUE);
    setBackgroundColor(BACKGROUND_COLOR);
    setSeparatorColor(SEPARATOR_COLOR);
    setTextColor(TEXT_COLOR);
    setTextSize(TEXT_SIZE);
    setWrapSelectorWheel(false);
    setFocusability(false);

    try {
        Field f = NumberPicker.class.getDeclaredField("mInputText");
        f.setAccessible(true);
        EditText inputText = (EditText)f.get(this);
        inputText.setFilters(new InputFilter[0]);
    } catch (NoSuchFieldException | IllegalAccessException | IllegalArgumentException e) {
        e.printStackTrace();
    }
}
 
Example 56
Project: MaterialNumberPicker   File: MaterialNumberPicker.java   Source Code and License 6 votes vote down vote up
/**
 * Uses reflection to access divider private attribute and override its color
 * Use Color.Transparent if you wish to hide them
 */
public void setSeparatorColor(int separatorColor) {
    mSeparatorColor = separatorColor;

    Field[] pickerFields = NumberPicker.class.getDeclaredFields();
    for (Field pf : pickerFields) {
        if (pf.getName().equals("mSelectionDivider")) {
            pf.setAccessible(true);
            try {
                pf.set(this, new ColorDrawable(separatorColor));
            } catch (IllegalAccessException | IllegalArgumentException e) {
                e.printStackTrace();
            }
            break;
        }
    }
}
 
Example 57
Project: translationRecorder   File: TestUtils.java   Source Code and License 6 votes vote down vote up
public static Matcher<View> hasNumberPickerDisplayedValue(final Matcher<String> stringMatcher) {
    return new BoundedMatcher<View, NumberPicker>(NumberPicker.class) {

        @Override
        public void describeTo(final Description description) {
            description.appendText("With number picker displayed value: ");
            stringMatcher.describeTo(description);
        }

        @Override
        public boolean matchesSafely(final NumberPicker view) {
            int index = view.getValue();
            String[] displayedValues = view.getDisplayedValues();
            return stringMatcher.matches(displayedValues[index-1]);
        }
    };
}
 
Example 58
Project: NightWatch   File: SnoozeActivity.java   Source Code and License 6 votes vote down vote up
static void SetSnoozePickerValues(NumberPicker picker, boolean above, int default_snooze) {
    String[] values=new String[snoozeValues.length];
    for(int i=0;i<values.length;i++){
        values[i]=getNameFromTime(snoozeValues[i]);
    }

    picker.setMaxValue(values.length -1);
    picker.setMinValue(0);
    picker.setDisplayedValues(values);
    picker.setWrapSelectorWheel(false);
    if(default_snooze != 0) {
        picker.setValue(getSnoozeLocatoin(default_snooze));
    } else {
        picker.setValue(getSnoozeLocatoin(getDefaultSnooze(above)));
    }
}
 
Example 59
Project: NightWatch   File: SnoozeActivity.java   Source Code and License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    alertStatus = (TextView) findViewById(R.id.alert_status);
    snoozeValue = (NumberPicker) findViewById(R.id.snooze);

    prefs =  PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    doMgdl = (prefs.getString("units", "mgdl").compareTo("mgdl") == 0);

    addListenerOnButton();
    if(BgGraphBuilder.isXLargeTablet(getApplicationContext())) {
        alertStatus.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);
        buttonSnooze.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);
    }

    displayStatus();
}
 
Example 60
Project: chronosnap   File: TimeIntervalPreference.java   Source Code and License 6 votes vote down vote up
/**
 * Perform initialization of the view items
 */
@Override
protected void onBindDialogView(View view) {
    super.onBindDialogView(view);

    // Obtain the current value
    long currentValue = Long.valueOf(getPersistedString(
            getContext().getString(R.string.pref_interval_default)));
    Interval interval = getInterval(currentValue);

    // Obtain references to the pickers and initialize them with the correct value
    mHourPicker = (NumberPicker) view.findViewById(R.id.hourPicker);
    mHourPicker.setMinValue(0);
    mHourPicker.setMaxValue(23);
    mHourPicker.setValue(interval.mHours);

    mMinutePicker = (NumberPicker) view.findViewById(R.id.minutePicker);
    mMinutePicker.setMinValue(0);
    mMinutePicker.setMaxValue(59);
    mMinutePicker.setValue(interval.mMinutes);

    mSecondPicker = (NumberPicker) view.findViewById(R.id.secondPicker);
    mSecondPicker.setMinValue(0);
    mSecondPicker.setMaxValue(59);
    mSecondPicker.setValue(interval.mSeconds);
}