Code example for NumberPicker

Methods: clearFocushasFocussetEnabledsetValue, setFocusable, setFocusableInTouchMode

0
        if (!enabled) {
            if (nameEdit.hasFocus()) {
                nameEdit.clearFocus();
            } else if (univEdit.hasFocus()) {
                univEdit.clearFocus();
            } else if (startAddrEdit.hasFocus()) {
                startAddrEdit.clearFocus();
            } else if (endAddrEdit.hasFocus()) {
                endAddrEdit.clearFocus();
            } 
        } 
 
        nameEdit.setFocusable(enabled);
        nameEdit.setFocusableInTouchMode(enabled);
        univEdit.setEnabled(enabled);
        univEdit.setFocusable(enabled);
        univEdit.setFocusableInTouchMode(enabled);
        startAddrEdit.setEnabled(enabled);
        startAddrEdit.setFocusable(enabled);
        startAddrEdit.setFocusableInTouchMode(enabled);
        endAddrEdit.setEnabled(enabled);
        endAddrEdit.setFocusable(enabled);
        endAddrEdit.setFocusableInTouchMode(enabled);
        valueSeekBar.setEnabled(enabled);
        valueSeekBar.setFocusable(enabled);
        valueSeekBar.setFocusableInTouchMode(enabled);
    } 
 
    @Override 
    public void onItemAdded(Light light) {
        super.onItemAdded(light);
        nameEdit.setText(light.getName());
        setControlsEnabled(true); 
        updateItemView(false); 
    } 
 
    @Override 
    public void onFocusChange(View view, boolean hasFocus) {
        showHideKeyboard(view, hasFocus);
    } 
 
    @Override 
    public void onViewCreated(View view, Bundle savedInstanceState) {
        nameEdit = (EditText)getView().findViewById(R.id.light_detail_name_edit);
        nameEdit.setOnFocusChangeListener(this);
 
        univEdit = (NumberPicker)getView().findViewById(R.id.light_detail_universe_picker);
        startAddrEdit = (NumberPicker)getView().findViewById(R.id.light_detail_addr_picker);
        endAddrEdit = (NumberPicker)getView().findViewById(R.id.light_detail_end_addr_picker);
        valueLabel = (TextView)getView().findViewById(R.id.light_detail_light_value_label);
        valueSeekBar = (SeekBar)getView().findViewById(R.id.light_detail_light_value);
 
        univEdit.setOnFocusChangeListener(this);
        univEdit.setMinValue(0);
        univEdit.setMaxValue(2);
 
        startAddrEdit.setOnFocusChangeListener(this);
        startAddrEdit.setMinValue(1);
        startAddrEdit.setMaxValue(512);
 
        endAddrEdit.setOnFocusChangeListener(this);
        endAddrEdit.setMinValue(1);
        endAddrEdit.setMaxValue(512);
 
        valueSeekBar.setMax(255);
        valueSeekBar.setOnSeekBarChangeListener(this);
 
        setControlsEnabled(false); 
 
        super.onViewCreated(view, savedInstanceState);
    } 
 
    public void updateItemView() { 
        updateItemView(true); 
    } 
 
    @Override 
    public boolean onCreateActionMode(ActionMode actionMode, Menu menu) {
        MenuInflater inflater = actionMode.getMenuInflater();
        inflater.inflate(R.menu.fragment_action_cancel, menu);
        setControlsEnabled(true); 
        return super.onCreateActionMode(actionMode, menu);
    } 
 
    @Override 
    public void onDestroyActionMode(ActionMode actionMode) {
        Object tag = actionMode.getTag();
        boolean cancelled = tag != null && tag.equals(R.string.cancelled);
        DmxGroupLight light = (DmxGroupLight)item;
        if (!cancelled) {
            if (!nameEdit.getText().toString().isEmpty()) {
                item.setName(nameEdit.getText().toString());
            } 
 
            light.setUniverse(univEdit.getValue());
            light.setAddress(startAddrEdit.getValue());
            light.setEndAddress(endAddrEdit.getValue());
            light.setValue(valueSeekBar.getProgress());
        } 
        setControlsEnabled(false); 
        super.onDestroyActionMode(actionMode);
    } 
 
    public void updateItemView(boolean updateValues) {
        if (updateValues) {
            if (nameEdit != null) {
                nameEdit.setText(item != null ? item.getName() : "");
            } 
 
            if (univEdit != null && startAddrEdit != null && endAddrEdit != null && item != null) {
                DmxGroupLight light = (DmxGroupLight)item;
                int universe = light.getUniverse();
                int startAddress = light.getAddress();
                int endAddress = light.getEndAddress();
                univEdit.setValue(universe < 0 ? 0 : universe);
                startAddrEdit.setValue(startAddress > 0 ? startAddress : 1);
                endAddrEdit.setValue(endAddress > 0 ? endAddress : 1);
                valueLabel.setText(String.valueOf(light.getPercent()) + "%");
                valueSeekBar.setProgress(light.getValue());
            } 
        }