Overriding Multiple Selection and Tap Handler

4 posts, 0 answers
  1. Vincent
    Vincent avatar
    2 posts
    Member since:
    Mar 2015

    Posted 12 Mar 2015 Link to this post

    I'm working on a Calendar now that has a variety of renders.

    To handle all of this I've extended the RadCalendarView for some basic configurations. Then I created a custom Decorator to handle some of the different cell drawings I needed.

    Now I need to change some behavior on a cell tap. So I was looking at handling the tap gesture. There doesn't seem to be a way to set or pass in any sort of tap gesture handler so I looked in to overriding the CalendarSelectionManager to intercept it. However, if I extend the CalendarSelectionManager I get a NullPointerException in handleTapGesture on CalendarSelectionManager.java:193. If I override the handleTapGesture and comment out the super call, it does not NPE. This seems like a bug but it appears to happen for all touch listeners and handlers so I wasn't sure if I missed something. I've tried extending the gesture manager but run in to the same problems.

    All I want to do is intercept a date selection when it's tapped and know which cell was selected. Is this possible?
  2. Antony Jekov
    Admin
    Antony Jekov avatar
    88 posts

    Posted 13 Mar 2015 Link to this post

    Hi Vincent,

    Thank you for contacting the Android team!

    I looked at all possible scenarios of intercepting a cell tap and custom decorations. However I cannot see any problem with it. Here is the code I am using, presenting a very simple decorator and three ways of getting the cell, that was selected:
    @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
     
            final RadCalendarView calendarView = new CustomCalendarView(this);
            calendarView.setCellDecorator(new Decorator(calendarView) {
                HashMap<Integer,List<CalendarCell>> cellsForDecoration = new HashMap<>();
     
                @Override
                public void clearDecorations() {
                    cellsForDecoration.clear();
                }
     
                @Override
                public void renderLayer(int layerId, Canvas canvas) {
                    if (cellsForDecoration.containsKey(layerId)) {
                        List<CalendarCell> cellsForLayer = cellsForDecoration.get(layerId);
                        if (cellsForLayer.size() > 0) {
                            for (CalendarCell cell : cellsForLayer) {
                                canvas.drawCircle(cell.virtualLeft() + (cell.getWidth() / 2), cell.virtualTop() + (cell.getHeight() / 2), 50, this.paint);
                            }
                        }
                    }
                }
     
                @Override
                public void toggleDecorationForCell(CalendarCell cell, int layerId) {
                    if (!cellsForDecoration.containsKey(layerId)) {
                        cellsForDecoration.put(layerId, new ArrayList<CalendarCell>());
                    }
     
                    cellsForDecoration.get(layerId).add(cell);
                }
            });
            calendarView.setGestureManager(new CustomGestureManager(calendarView));
            calendarView.setOnSelectedDatesChangedListener(new RadCalendarView.OnSelectedDatesChangedListener() {
                @Override
                public void onSelectedDatesChanged(RadCalendarView.SelectionContext context) {
                    if (context.newSelection().size() > 0) {
                        Toast.makeText(MainActivity.this, "setOnSelectedDatesChangedListener: Date as long from listener: " + context.newSelection().get(0), Toast.LENGTH_LONG).show();
                        List<CalendarDayCell> cellsWithThatDate = calendarView.dateToCell().get(context.newSelection().get(0));
                        // Respond to cell click here...
                    }
                }
            });
     
            calendarView.setOnCellClickListener(new RadCalendarView.OnCellClickListener() {
                @Override
                public void onCellClick(CalendarCell clickedCell) {
                    // Respond to cell click here...
                    Toast.makeText(MainActivity.this, "setOnCellClickListener: " + clickedCell.getText(), Toast.LENGTH_LONG).show();
                }
            });
     
            setContentView(calendarView);
        }
     
        class CustomCalendarView extends RadCalendarView{
     
            public CustomCalendarView(Context context) {
                super(context);
            }
        }
     
        class CustomGestureManager extends CalendarGestureManager {
     
            public CustomGestureManager(RadCalendarView owner) {
                super(owner);
            }
     
            @Override
            protected void handleTapGesture(CalendarDayCell calendarCell) {
                super.handleTapGesture(calendarCell);
                Toast.makeText(owner.getContext(), "handleTapGesture: Cell is " + calendarCell.getText(), Toast.LENGTH_LONG).show();
                // Respond to cell click here...
            }
        }

    Please take time to test this code and tell me if it has problems on your side. It works as expected on mine.
    You mentioned you extended the calendar. We might have to review that as well.

    Could you please send me some code, that represents the problem? It seems I cannot reproduce it on my side following your steps.

    Thank you for your time and all best!

    Regards,
    Antony Jekov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. DevCraft banner
  4. Vincent
    Vincent avatar
    2 posts
    Member since:
    Mar 2015

    Posted 13 Mar 2015 in reply to Antony Jekov Link to this post

    onCellClickListener is what I was looking for and can't believe I missed it. Thanks.
  5. Antony Jekov
    Admin
    Antony Jekov avatar
    88 posts

    Posted 16 Mar 2015 Link to this post

    Hello Vincent,

    I am glad you have a working solution. I will proceed and close this ticket now. Please feel free to reopen it at any time, or start a new one.

    Thank you for your time and all best!

    Regards,
    Antony Jekov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top
DevCraft banner