Guest User

Untitled

a guest
May 20th, 2011
346
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.13 KB | None | 0 0
  1.  
  2. import android.content.Context;
  3. import android.graphics.Color;
  4. import android.preference.DialogPreference;
  5. import android.util.AttributeSet;
  6. import android.util.Log;
  7. import android.view.View;
  8.  
  9. public class rgbaPreference extends DialogPreference {
  10.   rgbaView rgbaValue;
  11.   int      mColor = -1;
  12.  
  13.   public rgbaPreference(Context context, AttributeSet attrs, int defStyle) {
  14.     super( context, attrs, defStyle );
  15.     init( context, attrs );
  16.   }
  17.  
  18.   public rgbaPreference(Context context, AttributeSet attrs) {
  19.     super( context, attrs );
  20.     init( context, attrs );
  21.   }
  22.  
  23.   private void init( Context context, AttributeSet attrs ) {
  24.   }
  25.  
  26.   public rgbaPreference(Context context) {
  27.     this( context, null );
  28.   }
  29.  
  30.   @Override
  31.   protected View onCreateDialogView() {
  32.     rgbaValue = new rgbaView( getContext(), null );
  33.     rgbaValue.setEnabled( true );
  34.     rgbaValue.setColor( mColor );
  35.     rgbaValue.setAlphaSliderVisible( true );
  36.     return rgbaValue;
  37.   }
  38.  
  39.   @Override
  40.   protected void onSetInitialValue( boolean restorePersistedValue,
  41.       Object defaultValue ) {
  42.     if ( defaultValue instanceof Integer ) {
  43.       Integer intDefaultValue = (Integer)defaultValue;
  44.       setColor( restorePersistedValue ? getPersistedInt( mColor )
  45.           : intDefaultValue );
  46.     } else {
  47.       setColor( restorePersistedValue ? getPersistedInt( mColor ) : Color.WHITE );
  48.     }
  49.   }
  50.  
  51.   private void setColor( int color ) {
  52.     mColor = color;
  53.   }
  54.  
  55.   @Override
  56.   protected void onDialogClosed( boolean positiveResult ) {
  57.     super.onDialogClosed( positiveResult );
  58.     if ( positiveResult ) {
  59.       Integer value = new Integer( rgbaValue.getColor() );
  60.       if ( callChangeListener( value ) ) {
  61.         storeColor( value );
  62.       }
  63.     }
  64.    
  65.     Log.i( "rgbaPreference", "Colour: " + mColor );
  66.   }
  67.  
  68.   public void storeColor( int color ) {
  69.     mColor = color;
  70.     final boolean wasBlocking = shouldDisableDependents();
  71.     persistInt( color );
  72.     final boolean isBlocking = shouldDisableDependents();
  73.     if ( isBlocking != wasBlocking ) {
  74.       notifyDependencyChange( isBlocking );
  75.     }    
  76.   }  
  77. }
Advertisement
Add Comment
Please, Sign In to add comment