Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import android.content.Context;
- import android.graphics.Color;
- import android.preference.DialogPreference;
- import android.util.AttributeSet;
- import android.util.Log;
- import android.view.View;
- public class rgbaPreference extends DialogPreference {
- rgbaView rgbaValue;
- int mColor = -1;
- public rgbaPreference(Context context, AttributeSet attrs, int defStyle) {
- super( context, attrs, defStyle );
- init( context, attrs );
- }
- public rgbaPreference(Context context, AttributeSet attrs) {
- super( context, attrs );
- init( context, attrs );
- }
- private void init( Context context, AttributeSet attrs ) {
- }
- public rgbaPreference(Context context) {
- this( context, null );
- }
- @Override
- protected View onCreateDialogView() {
- rgbaValue = new rgbaView( getContext(), null );
- rgbaValue.setEnabled( true );
- rgbaValue.setColor( mColor );
- rgbaValue.setAlphaSliderVisible( true );
- return rgbaValue;
- }
- @Override
- protected void onSetInitialValue( boolean restorePersistedValue,
- Object defaultValue ) {
- if ( defaultValue instanceof Integer ) {
- Integer intDefaultValue = (Integer)defaultValue;
- setColor( restorePersistedValue ? getPersistedInt( mColor )
- : intDefaultValue );
- } else {
- setColor( restorePersistedValue ? getPersistedInt( mColor ) : Color.WHITE );
- }
- }
- private void setColor( int color ) {
- mColor = color;
- }
- @Override
- protected void onDialogClosed( boolean positiveResult ) {
- super.onDialogClosed( positiveResult );
- if ( positiveResult ) {
- Integer value = new Integer( rgbaValue.getColor() );
- if ( callChangeListener( value ) ) {
- storeColor( value );
- }
- }
- Log.i( "rgbaPreference", "Colour: " + mColor );
- }
- public void storeColor( int color ) {
- mColor = color;
- final boolean wasBlocking = shouldDisableDependents();
- persistInt( color );
- final boolean isBlocking = shouldDisableDependents();
- if ( isBlocking != wasBlocking ) {
- notifyDependencyChange( isBlocking );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment