Ejemplo n.º 1
0
        /**
         * Append tag to this group.
         *
         * @param tag the tag to append.
         */
        protected void appendTag(TagColor color, string tag)
        {
            TagView newTag = new TagView(this, Context, TagView.STATE_NORMAL, color, tag);

            newTag.Click += NewTag_Click;
            AddView(newTag);
        }
Ejemplo n.º 2
0
        public static List <TagColor> getRandomColors(int size)
        {
            List <TagColor> list = new List <TagColor>();

            for (int i = 0; i < size; i++)
            {
                TagColor color = new TagColor();
                color.borderColor = color.backgroundColor = Constant.tagColors[i % Constant.tagColors.Length];
                list.Add(color);
            }
            return(list);
        }
Ejemplo n.º 3
0
        protected void appendInputTag(TagColor color, string tag)
        {
            TagView previousInputTag = getInputTag();

            if (previousInputTag != null)
            {
                throw new IllegalStateException("Already has a INPUT tag in group.");
            }

            TagView newInputTag = new TagView(this, Context, TagView.STATE_INPUT, color, tag);

            newInputTag.Click += NewTag_Click;

            AddView(newInputTag);
        }
Ejemplo n.º 4
0
        public void setTags(List <TagColor> colors, params string[] tags)
        {
            RemoveAllViews();
            int i = 0;

            foreach (string tag in tags)
            {
                TagColor color = null;
                if (colors != null)
                {
                    color = colors[i++];
                }
                appendTag(color, tag);
            }

            if (isAppendMode)
            {
                appendInputTag();
            }
        }
Ejemplo n.º 5
0
            public TagView(TagGroup tagGroup, Context context, int state, TagColor color, string text) : base(context)
            {
                this.tagGroup = tagGroup;
                this.color    = color;
                SetPadding(tagGroup.horizontalPadding, tagGroup.verticalPadding, tagGroup.horizontalPadding, tagGroup.verticalPadding);
                LayoutParameters = new TagGroup.LayoutParams(
                    TagGroup.LayoutParams.WrapContent,
                    TagGroup.LayoutParams.WrapContent);

                Gravity = (GravityFlags.Center);
                Text    = text;
                SetTextSize(ComplexUnitType.Px, tagGroup.textSize);

                mState = state;

                Clickable            = (tagGroup.isAppendMode);
                Focusable            = (state == STATE_INPUT);
                FocusableInTouchMode = (state == STATE_INPUT);
                Hint           = (state == STATE_INPUT ? tagGroup.inputHint : null);
                MovementMethod = (state == STATE_INPUT ? ArrowKeyMovementMethod.Instance : null);

                mBorderPaint.SetStyle(Style.Stroke);
                mBorderPaint.StrokeWidth = tagGroup.borderStrokeWidth;
                mBackgroundPaint.SetStyle(Style.Fill);
                mCheckedMarkerPaint.SetStyle(Style.Fill);
                mCheckedMarkerPaint.StrokeWidth = CHECKED_MARKER_STROKE_WIDTH;
                mCheckedMarkerPaint.Color       = new Color(tagGroup.checkedMarkerColor);

                // Interrupted long click event to avoid PAUSE popup.
                //setOnLongClickListener(new OnLongClickListener() {
                //    @Override
                //    public bool onLongClick(View v) {
                //        return state != STATE_INPUT;
                //    }
                //});

                if (state == STATE_INPUT)
                {
                    RequestFocus();

                    // Handle the ENTER key down.
                    //setOnEditorActionListener(new OnEditorActionListener() {
                    //    @Override
                    //    public bool onEditorAction(TextView v, int actionId, KeyEvent event) {
                    //        if (actionId == EditorInfo.IME_NULL
                    //                && (event != null && event.getKeyCode() == KeyEvent.KEYCODE_ENTER
                    //                && event.getAction() == KeyEvent.ACTION_DOWN)) {
                    //            if (isInputAvailable()) {
                    //                // If the input content is available, end the input and dispatch
                    //                // the event, then append a new INPUT state tag.
                    //                endInput();
                    //                if (mOnTagChangeListener != null) {
                    //                    mOnTagChangeListener.onAppend(TagGroup.this, getText().ToString());
                    //                }
                    //                appendInputTag();
                    //            }
                    //            return true;
                    //        }
                    //        return false;
                    //    }
                    //});

                    // Handle the BACKSPACE key down.
                    //setOnKeyListener(new OnKeyListener() {
                    //    @Override
                    //    public bool onKey(View v, int keyCode, KeyEvent event) {
                    //        if (keyCode == Keycode.Del && event.getAction() == KeyEvent.ACTION_DOWN) {
                    //            // If the input content is empty, check or remove the last NORMAL state tag.
                    //            if (TextUtils.isEmpty(getText().ToString())) {
                    //                TagView lastNormalTagView = getLastNormalTagView();
                    //                if (lastNormalTagView != null) {
                    //                    if (lastNormalTagView.isChecked) {
                    //                        removeView(lastNormalTagView);
                    //                        if (mOnTagChangeListener != null) {
                    //                            mOnTagChangeListener.onDelete(TagGroup.this, lastNormalTagView.Text);
                    //                        }
                    //                    } else {
                    //                        TagView checkedTagView = getCheckedTag();
                    //                        if (checkedTagView != null) {
                    //                            checkedTagView.setChecked(false);
                    //                        }
                    //                        lastNormalTagView.setChecked(true);
                    //                    }
                    //                    return true;
                    //                }
                    //            }
                    //        }
                    //        return false;
                    //    }
                    //});

                    // Handle the INPUT tag content changed.
                    //addTextChangedListener(new TextWatcher() {
                    //    @Override
                    //    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                    //        // When the INPUT state tag changed, uncheck the checked tag if exists.
                    //        TagView checkedTagView = getCheckedTag();
                    //        if (checkedTagView != null) {
                    //            checkedTagView.setChecked(false);
                    //        }
                    //    }

                    //    @Override
                    //    public void onTextChanged(CharSequence s, int start, int before, int count) {
                    //    }

                    //    @Override
                    //    public void afterTextChanged(Editable s) {
                    //    }
                    //});
                }

                invalidatePaint();
            }