Code example for SeekBar

Methods: getProgresssetProgresssetVisibility

0
				in_update = true;
				if( r != sbRed.getProgress() ){
					sbRed.setProgress(r);
					bUpdate = true;
				} 
				if( g != sbGreen.getProgress() ){
					sbGreen.setProgress(g);
					bUpdate = true;
				} 
				if( b != sbBlue.getProgress() ){
					sbBlue.setProgress(b);
					bUpdate = true;
				} 
				if( v != sbGrey.getProgress() ){
					sbGrey.setProgress(v);
					bUpdate = true;
				} 
				in_update = false;
 
				if( ! tbColor.isChecked() && ( r != g || r != b ) ){
					setColorMode(true); 
				} 
				 
				if(bUpdate) update();
			} 
		}); 
         
        tbColor.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			@Override 
			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
				setColorMode(isChecked);
			} 
		}); 
         
        tbHex.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			@Override 
			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
				etSampleHex.setVisibility(isChecked? View.VISIBLE : View.INVISIBLE);
				if(!isChecked){
					 getDialog().getWindow().setSoftInputMode(
			        		WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN
			        		| WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
			        ); 
					 // EditText が自動的にsoft keyboard を開くのを抑止する 
					 Context c = etSampleHex.getContext();
					 IBinder token = etSampleHex.getWindowToken();
				     InputMethodManager imm = (InputMethodManager)c.getSystemService(Context.INPUT_METHOD_SERVICE);
				     imm.hideSoftInputFromInputMethod(token,InputMethodManager.HIDE_IMPLICIT_ONLY);
				     imm.hideSoftInputFromWindow(token,0);
				} 
			} 
		}); 
    } 
 
    SeekBar.OnSeekBarChangeListener sb_listener = new SeekBar.OnSeekBarChangeListener(){
    	@Override 
        public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) { 
    		if(in_update) return; 
    		int v = (sbRed.getProgress() + sbGreen.getProgress() + sbBlue.getProgress() )/3; 
    		in_update=true; 
    		sbGrey.setProgress(v); 
    		in_update=false; 
            update(); 
        } 
        @Override public void onStartTrackingTouch(SeekBar seekBar) {} 
        @Override public void onStopTrackingTouch(SeekBar seekBar) { 
        	update_text(); 
        } 
    }; 
     
    SeekBar.OnSeekBarChangeListener sb_listener_mono = new SeekBar.OnSeekBarChangeListener(){
    	@Override 
        public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) { 
    		if(in_update) return; 
    		int v = sbGrey.getProgress(); 
    		in_update=true; 
    		sbRed.setProgress(v); 
    		sbGreen.setProgress(v); 
    		sbBlue.setProgress(v); 
    		in_update=false; 
            update(); 
        } 
        @Override public void onStartTrackingTouch(SeekBar seekBar) {} 
        @Override public void onStopTrackingTouch(SeekBar seekBar) { 
        	update_text(); 
        } 
    }; 
     
    @Override 
    protected void onDialogClosed(boolean positiveResult) {
        if( ! positiveResult ) return;
         
        int r = sbRed.getProgress();
    	int g = sbGreen.getProgress();
    	int b = sbBlue.getProgress();
 
    	Editor e = pref.edit();
        e.putInt(getKey(), Color.rgb(r,g,b));
        e.commit();
    } 
     
    public void setDefault(int col) {
        defaultColor = col;
    } 
    
    //  
    void setColorMode(boolean colored){
    	tbColor.setChecked(colored);
 
    	sbGrey.setVisibility( colored ? View.INVISIBLE : View.VISIBLE);
    	tvGrey.setVisibility( colored ? View.INVISIBLE : View.VISIBLE);
    	 
    	sbRed.setVisibility( colored ? View.VISIBLE : View.INVISIBLE);
    	tvRed.setVisibility( colored ? View.VISIBLE : View.INVISIBLE );
    	sbGreen.setVisibility( colored ? View.VISIBLE : View.INVISIBLE );
    	tvGreen.setVisibility( colored ? View.VISIBLE : View.INVISIBLE );
    	sbBlue.setVisibility( colored ? View.VISIBLE : View.INVISIBLE );
    	tvBlue.setVisibility( colored ? View.VISIBLE : View.INVISIBLE );
    	 
    	if(! colored ){
    		int v = (sbRed.getProgress() + sbGreen.getProgress() + sbBlue.getProgress() + 1 ) /3;
    		sbRed.setProgress(v);
    		sbGreen.setProgress(v);
    		sbBlue.setProgress(v);
    		update(); 
    	} 
    } 
 
    // イベント抑制用 
    boolean in_update = false;
 
    // 表示の更新 
    private void update(){ 
    	int r = sbRed.getProgress();
    	int g = sbGreen.getProgress();
    	int b = sbBlue.getProgress();
    	int v = sbGrey.getProgress();
    	tvSample.setBackgroundColor(Color.rgb(r,g,b));
    	tvRed.setText(Integer.toString(r));
    	tvGreen.setText(Integer.toString(g));