public ColorPaletteAdapter(IOnColorSelectedListener listener, Color[] colors, int selectedPosition, ColorShape colorShape) { _listener = listener; Colors = colors; _selectedPosition = selectedPosition; _colorShape = colorShape; }
private void Init(IAttributeSet attrs) { Persistent = true; var a = Context.ObtainStyledAttributes(attrs, Resource.Styleable.ColorPreference); _showDialog = a.GetBoolean(Resource.Styleable.ColorPreference_cpv_showDialog, true); //noinspection WrongConstant _dialogType = (ColorPickerDialog.DialogType)a.GetInt(Resource.Styleable.ColorPreference_cpv_dialogType, (int)ColorPickerDialog.DialogType.Preset); _colorShape = (ColorShape)a.GetInt(Resource.Styleable.ColorPreference_cpv_colorShape, (int)ColorShape.Circle); _allowPresets = a.GetBoolean(Resource.Styleable.ColorPreference_cpv_allowPresets, true); _allowCustom = a.GetBoolean(Resource.Styleable.ColorPreference_cpv_allowCustom, true); _showAlphaSlider = a.GetBoolean(Resource.Styleable.ColorPreference_cpv_showAlphaSlider, false); _showColorShades = a.GetBoolean(Resource.Styleable.ColorPreference_cpv_showColorShades, true); _previewSize = a.GetInt(Resource.Styleable.ColorPreference_cpv_previewSize, SIZE_NORMAL); var presetsResId = a.GetResourceId(Resource.Styleable.ColorPreference_cpv_colorPresets, 0); _dialogTitle = a.GetResourceId(Resource.Styleable.ColorPreference_cpv_dialogTitle, Resource.String.cpv_default_title); if (presetsResId != 0) { _presets = Context.Resources.GetIntArray(presetsResId).Select(d => new Color(d)).ToArray(); } else { _presets = ColorPickerDialog.MATERIAL_COLORS; } if (_colorShape == ColorShape.Circle) { WidgetLayoutResource = _previewSize == SIZE_LARGE ? Resource.Layout.cpv_preference_circle_large : Resource.Layout.cpv_preference_circle; } else { WidgetLayoutResource = _previewSize == SIZE_LARGE ? Resource.Layout.cpv_preference_square_large : Resource.Layout.cpv_preference_square; } a.Recycle(); }
// -------------------- // Main Game Loops // -------------------- //AWAKE // Get all children from GameObject.find() and reassign this as parent void Awake() { // Retrieve all Shapes from Level GameObject[] levelShapes = GameObject.FindGameObjectsWithTag("Shape"); foreach (GameObject startShape in levelShapes) { // Get color info from current parent ColorShape colorShapeScript = startShape.GetComponent <ColorShape>(); colorShapeScript.overrideColorAll(); // Change parent to game core startShape.transform.SetParent(transform); // Initialize with tracker connections colorShapeScript.initializeAll(paintTracker, paintSurface, barrierTracker, tokenTracker, tokenSphere); // Set to invisible to start } }
private void Init(Context context, IAttributeSet attrs) { var a = Context.ObtainStyledAttributes(attrs, Resource.Styleable.ColorPanelView); _shape = (ColorShape) a.GetInt(Resource.Styleable.ColorPanelView_cpv_colorShape, (int) ColorShape.Circle); _showOldColor = a.GetBoolean(Resource.Styleable.ColorPanelView_cpv_showOldColor, false); if (_showOldColor && _shape != ColorShape.Circle) { throw new IllegalStateException("Color preview is only available in circle mode"); } _borderColor = a.GetColor(Resource.Styleable.ColorPanelView_cpv_borderColor, DEFAULT_BORDER_COLOR); a.Recycle(); if (_borderColor == DEFAULT_BORDER_COLOR) { // If no specific border color has been set we take the default secondary text color as border/slider color. // Thus it will adopt to theme changes automatically. var value = new TypedValue(); var typedArray = context.ObtainStyledAttributes(value.Data, new[] {Android.Resource.Attribute.TextColorSecondary}); _borderColor = typedArray.GetColor(0, _borderColor); typedArray.Recycle(); } _borderWidthPx = DrawingUtils.DpToPx(context, 1); _borderPaint = new Paint {AntiAlias = true}; _colorPaint = new Paint {AntiAlias = true}; if (_showOldColor) { _originalPaint = new Paint(); } if (_shape == ColorShape.Circle) { var bitmap = ((BitmapDrawable) context.GetDrawable(Resource.Drawable.cpv_alpha)).Bitmap; _alphaPaint = new Paint {AntiAlias = true}; var shader = new BitmapShader(bitmap, Shader.TileMode.Repeat, Shader.TileMode.Repeat); _alphaPaint.SetShader(shader); } }
private void Init(IAttributeSet attrs) { Persistent = true; var a = Context.ObtainStyledAttributes(attrs, Resource.Styleable.ColorPreference); _showDialog = a.GetBoolean(Resource.Styleable.ColorPreference_cpv_showDialog, true); //noinspection WrongConstant _dialogType = (ColorPickerDialog.DialogType)a.GetInt(Resource.Styleable.ColorPreference_cpv_dialogType, (int)ColorPickerDialog.DialogType.Preset); _colorShape = (ColorShape)a.GetInt(Resource.Styleable.ColorPreference_cpv_colorShape, (int)ColorShape.Circle); _allowPresets = a.GetBoolean(Resource.Styleable.ColorPreference_cpv_allowPresets, true); _allowCustom = a.GetBoolean(Resource.Styleable.ColorPreference_cpv_allowCustom, true); _showAlphaSlider = a.GetBoolean(Resource.Styleable.ColorPreference_cpv_showAlphaSlider, false); _showColorShades = a.GetBoolean(Resource.Styleable.ColorPreference_cpv_showColorShades, true); _previewSize = a.GetInt(Resource.Styleable.ColorPreference_cpv_previewSize, SIZE_NORMAL); var presetsResId = a.GetResourceId(Resource.Styleable.ColorPreference_cpv_colorPresets, 0); _dialogTitle = a.GetResourceId(Resource.Styleable.ColorPreference_cpv_dialogTitle, Resource.String.cpv_default_title); if (presetsResId != 0) { _presets = Context.Resources.GetIntArray(presetsResId).Select(d => new Color(d)).ToArray(); } else { _presets = ColorPickerDialog.MATERIAL_COLORS; } if (_colorShape == ColorShape.Circle) { WidgetLayoutResource = _previewSize == SIZE_LARGE ? Resource.Layout.cpv_preference_circle_large : Resource.Layout.cpv_preference_circle; } else { WidgetLayoutResource = _previewSize == SIZE_LARGE ? Resource.Layout.cpv_preference_square_large : Resource.Layout.cpv_preference_square; } _args = new Bundle(); var dialogId = a.GetInt(Resource.Styleable.ColorPreference_cpv_dialogID, 0); var presetsButtonText = a.GetResourceId(Resource.Styleable.ColorPreference_cpv_presetsButtonText, Resource.String.cpv_default_title); var customButtonText = a.GetResourceId(Resource.Styleable.ColorPreference_cpv_customButtonText, Resource.String.cpv_default_title); var selectedButtonText = a.GetResourceId(Resource.Styleable.ColorPreference_cpv_selectedButtonText, Resource.String.cpv_default_title); _args.PutInt(ColorPickerDialogPreference.ARG_ID, dialogId); _args.PutInt(ColorPickerDialogPreference.ARG_TYPE, (int)_dialogType); _args.PutInt(ColorPickerDialogPreference.ARG_COLOR, _color); _args.PutIntArray(ColorPickerDialogPreference.ARG_PRESETS, _presets.Select(d => d.ToArgb()).ToArray()); _args.PutBoolean(ColorPickerDialogPreference.ARG_ALPHA, _showAlphaSlider); _args.PutBoolean(ColorPickerDialogPreference.ARG_ALLOW_CUSTOM, _allowCustom); _args.PutBoolean(ColorPickerDialogPreference.ARG_ALLOW_PRESETS, _allowPresets); _args.PutInt(ColorPickerDialogPreference.ARG_DIALOG_TITLE, _dialogTitle); _args.PutBoolean(ColorPickerDialogPreference.ARG_SHOW_COLOR_SHADES, _showColorShades); _args.PutInt(ColorPickerDialogPreference.ARG_COLOR_SHAPE, (int)_colorShape); _args.PutInt(ColorPickerDialogPreference.ARG_PRESETS_BUTTON_TEXT, presetsButtonText); _args.PutInt(ColorPickerDialogPreference.ARG_CUSTOM_BUTTON_TEXT, customButtonText); _args.PutInt(ColorPickerDialogPreference.ARG_SELECTED_BUTTON_TEXT, selectedButtonText); a.Recycle(); }
/** * Set the shape. * * @param shape * Either {@link ColorShape#SQUARE} or {@link ColorShape#CIRCLE}. */ public void SetShape(ColorShape shape) { _shape = shape; Invalidate(); }
public override Dialog OnCreateDialog(Bundle savedInstanceState) { _dialogId = GetColorPreference().GetArgs().GetInt(ARG_ID); _showAlphaSlider = GetColorPreference().GetArgs().GetBoolean(ARG_ALPHA); _showColorShades = GetColorPreference().GetArgs().GetBoolean(ARG_SHOW_COLOR_SHADES); _colorShape = (ColorShape)GetColorPreference().GetArgs().GetInt(ARG_COLOR_SHAPE); if (savedInstanceState == null) { _color = new Color(GetColorPreference().GetColor()); _dialogType = (ColorPickerDialog.DialogType)GetColorPreference().GetArgs().GetInt(ARG_TYPE); } else { _color = new Color(savedInstanceState.GetInt(ARG_COLOR)); _dialogType = (ColorPickerDialog.DialogType)savedInstanceState.GetInt(ARG_TYPE); } _rootView = new FrameLayout(Activity); if (_dialogType == ColorPickerDialog.DialogType.Custom) { _rootView.AddView(CreatePickerView()); } else if (_dialogType == ColorPickerDialog.DialogType.Preset) { _rootView.AddView(CreatePresetsView()); } var selectedButtonStringRes = GetColorPreference().GetArgs().GetInt(ARG_SELECTED_BUTTON_TEXT); if (selectedButtonStringRes == 0) { selectedButtonStringRes = Resource.String.cpv_select; } var builder = new AlertDialog.Builder(Activity).SetView(_rootView).SetPositiveButton( selectedButtonStringRes, new DialogInterfaceOnClickListener( (d, w) => { OnColorSelected(); })); var dialogTitleStringRes = GetColorPreference().GetArgs().GetInt(ARG_DIALOG_TITLE); if (dialogTitleStringRes != 0) { builder.SetTitle(dialogTitleStringRes); } _presetsButtonStringRes = GetColorPreference().GetArgs().GetInt(ARG_PRESETS_BUTTON_TEXT); _customButtonStringRes = GetColorPreference().GetArgs().GetInt(ARG_CUSTOM_BUTTON_TEXT); int neutralButtonStringRes; if (_dialogType == ColorPickerDialog.DialogType.Custom && GetColorPreference().GetArgs().GetBoolean(ARG_ALLOW_PRESETS)) { neutralButtonStringRes = (_presetsButtonStringRes != 0 ? _presetsButtonStringRes : Resource.String.cpv_presets); } else if (_dialogType == ColorPickerDialog.DialogType.Preset && GetColorPreference().GetArgs().GetBoolean(ARG_ALLOW_CUSTOM)) { neutralButtonStringRes = (_customButtonStringRes != 0 ? _customButtonStringRes : Resource.String.cpv_custom); } else { neutralButtonStringRes = 0; } if (neutralButtonStringRes != 0) { builder.SetNeutralButton(neutralButtonStringRes, (IDialogInterfaceOnClickListener)null); } return(builder.Create()); }
/** * Set the shape of the color panel view. * * @param colorShape * Either {@link ColorShape#CIRCLE} or {@link ColorShape#SQUARE}. * @return This builder object for chaining method calls */ public Builder SetColorShape(ColorShape colorShape) { _colorShape = colorShape; return(this); }