Select a date and select 30 days next

18 posts, 0 answers
  1. Miguel
    Miguel avatar
    5 posts
    Member since:
    Oct 2015

    Posted 15 Oct 2015 Link to this post

    Hello ,

    I am using the radcalendar on my android project and I wanted to do was that when selecting a calendar day the next 30 days stay selected.

     

    No i used this code for to now the picked date.

     

      calendarView.setSelectionMode(CalendarSelectionMode.Range);
            calendarView.setOnSelectedDatesChangedListener(new RadCalendarView.
                                                    OnSelectedDatesChangedListener() {
                @Override
                public void onSelectedDatesChanged(
                    RadCalendarView.SelectionContext context) {
                    Toast.makeText(getApplicationContext(), 
                      String.format("%tF", context.newSelection().get(0)), 
                      Toast.LENGTH_SHORT).show();
       
                }
            });​

  2. Todor
    Admin
    Todor avatar
    778 posts

    Posted 20 Oct 2015 Link to this post

    Hi Miguel,

    Thank you for your question.

    Here's how you can set the selection to a range of dates starting from one date and continues 30 days:

    private void selected30Dates(long start) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(start);
        calendar.add(Calendar.DATE, 30);
        long end = calendar.getTimeInMillis();
        DateRange dateRange = new DateRange(start, end);
        calendarView.setSelectedRange(dateRange);
    }

    Now what's left is to call this method when a cell is clicked:

    calendarView.setOnCellClickListener(new RadCalendarView.OnCellClickListener() {
        @Override
        public void onCellClick(CalendarCell calendarCell) {
            selected30Dates(calendarCell.getDate());
        }
    });

    Don't forget to set the relevant selection mode:

    calendarView.setSelectionMode(CalendarSelectionMode.Range);

    Let us know if you need further assistance.

    Regards,
    Todor
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. DevCraft banner
  4. Miguel
    Miguel avatar
    5 posts
    Member since:
    Oct 2015

    Posted 21 Oct 2015 in reply to Todor Link to this post

    The solution you gave me works something .

    This is because I do not let the user select -a- weekend , so if I use the solution they gave me, and choosing for example a Wednesday just get selected Thursday and Friday this week and does not select the 30 days.

     

    I use it not to let the user select the weekends:

      final Calendar calendar = Calendar.getInstance();
                   calendarView.setCustomizationRule(new Procedure<CalendarCell>(){

            @Override
            public void apply(CalendarCell calendarCell) {
            // TODO Auto-generated method stub
            if (calendarCell instanceof CalendarDayCell) {
                       calendar.setTimeInMillis(calendarCell.getDate());
                       ((CalendarDayCell) calendarCell).setSelectable(
                        !(calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY ||
                               calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY));
                   }
            }
                   }); 

     

    In the image 1 is the end result that I want to get when user choose a day and with your solution I get what is in the picture 2​

  5. Todor
    Admin
    Todor avatar
    778 posts

    Posted 21 Oct 2015 Link to this post

    Hello Miguel,

    Thank you for getting back to us.

    Actually this behavior differs a bit from our intended implementation, namely we don't expect you to want to select a cell, marked as *not selectable*. However, here's how you can workaround this:

    1) First, change your customization rule to mark that dates in the weekend as not enabled, instead of not selectable:

    calendarView.setCustomizationRule(new Procedure<CalendarCell>() {
     
        @Override
        public void apply(CalendarCell calendarCell) {
        if (calendarCell instanceof CalendarDayCell) {
            calendar.setTimeInMillis(calendarCell.getDate());
            calendarCell.setEnabled(
                    !(calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY ||
                            calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY));
        }
        }
    });

    2) Now, let's take this into consideration when handling the cell clicks and select dates only if pressed cell is enabled:

    calendarView.setOnCellClickListener(new RadCalendarView.OnCellClickListener() {
     
        @Override
        public void onCellClick(CalendarCell calendarCell) {
            if (calendarCell.isEnabled()) {
                selected30Dates(calendarCell.getDate());
            }
        }
    });

    3) Make a modification to our implementation for selection:

    public class MySelectionManager extends CalendarSelectionManager {
        public MySelectionManager(RadCalendarView owner) {
            super(owner);
        }
     
        @Override
        public void handleTapGesture(CalendarDayCell calendarCell) {
            if(calendarCell.isEnabled()) {
                super.handleTapGesture(calendarCell);
            }
        }
    }

    4) Set the modified selection to your calendar instance:

    calendarView.setSelectionManager(new MySelectionManager(calendarView));

    I hope this information helps.

    Regards,
    Todor
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  6. Miguel
    Miguel avatar
    5 posts
    Member since:
    Oct 2015

    Posted 21 Oct 2015 in reply to Todor Link to this post

    I used your solution but the map was not selected in the days as shown in picture 1 in the previous answer. But it was as I show attached. Attached as I also send my calendar class . With your solution , if I pick a day , the app crashes

     My class its here:

    import java.text.DateFormat;
    import java.util.ArrayList;
    import java.util.Calendar;
    import java.util.Date;
    import java.util.Locale;

    import android.app.Activity;
    import android.app.AlertDialog;
    import android.app.ProgressDialog;
    import android.content.DialogInterface;
    import android.content.pm.ActivityInfo;
    import android.graphics.Color;
    import android.os.Bundle;
    import android.support.v7.app.ActionBar;
    import android.support.v7.app.ActionBarActivity;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.widget.TextView;

    import com.paysimplex.R;
    import com.paysimplex.Helpers.BaseActivity;
    import com.telerik.android.common.Function;
    import com.telerik.android.common.Procedure;
    import com.telerik.widget.calendar.CalendarAdapter;
    import com.telerik.widget.calendar.CalendarCell;
    import com.telerik.widget.calendar.CalendarDayCell;
    import com.telerik.widget.calendar.CalendarSelectionManager;
    import com.telerik.widget.calendar.CalendarSelectionMode;
    import com.telerik.widget.calendar.CalendarStyles;
    import com.telerik.widget.calendar.CalendarTextElement;
    import com.telerik.widget.calendar.DateRange;
    import com.telerik.widget.calendar.RadCalendarView;
    import com.telerik.widget.calendar.ScrollMode;
    import com.telerik.widget.calendar.decorations.CircularRangeDecorator;

    @SuppressWarnings("deprecation")
    public class DatesSelection extends ActionBarActivity{

    private static final int SELECTION_COLOR_MAIN = Color.parseColor("#C56BB9");
        private static final int SELECTION_COLOR_SECONDARY = Color.parseColor("#E6BDE0");
        private static final int PURPLE_COLOR = Color.parseColor("#511749");
        private static final int BLUEPAYSIMPLEX = Color.parseColor("#0000FF");
        private static final int BACKGROUND_COLOR = Color.parseColor("#F2F2F2");

    private DateRange selectionRange;

    @SuppressWarnings("unused")
    private BaseActivity mClass;
        private Activity activity;
        private android.support.v7.app.ActionBar actionBar;
    private AlertDialog dialog;
    private ProgressDialog dialog_;
    private RadCalendarView calendarView;
    private boolean dialogOpened;
    private View rootView;


    public DatesSelection() {
            // Required empty public constructor
        }


    @Override
        public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
            setContentView(R.layout.layout);

    mClass = new BaseActivity();
    activity = this;
    this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    actionBar = getSupportActionBar();
    actionBar.setHomeButtonEnabled(true);
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
    actionBar.setCustomView(R.layout.actionbar_titletext_layout);
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setHomeAsUpIndicator(R.drawable.ic_launcher);

    showRangeSelector();
        }


    private void selected30Dates(long start) {
            Calendar calendar = Calendar.getInstance();
            calendar.setTimeInMillis(start);
            calendar.add(Calendar.DATE, 30);
            long end = calendar.getTimeInMillis();
            DateRange dateRange = new DateRange(start, end);
            calendarView.setSelectedRange(dateRange);
        }
        
        public class MySelectionManager extends CalendarSelectionManager {
            public MySelectionManager(RadCalendarView owner) {
                super(owner);
            }
         
            @Override
            public void handleTapGesture(CalendarDayCell calendarCell) {
                if(calendarCell.isEnabled()) {
                    super.handleTapGesture(calendarCell);
                }
            }
        }

        private void showRangeSelector() {
            if (this.dialogOpened)
                return;
            this.dialogOpened = true;

            AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
    LayoutInflater li = getLayoutInflater();
       rootView = li.inflate(R.layout.calendar_range_popup, null);
            rootView.findViewById(R.id.left_arrow).setOnClickListener(new View.OnClickListener() {
           
           @Override
           public void onClick(View v) {
                   calendarView.animateToPrevious();
               }
           });
           rootView.findViewById(R.id.right_arrow).setOnClickListener(new View.OnClickListener() {
               @Override
               public void onClick(View v) {
                   calendarView.animateToNext();
               }
            });

            calendarView = (RadCalendarView) rootView.findViewById(R.id.calendarView);
            calendarView.setMinDate(Calendar.getInstance().getTimeInMillis());
            calendarView.setHorizontalScroll(true);
            calendarView.setShowGridLines(false);
            calendarView.setScrollMode(ScrollMode.None);
            updateHandledGestures(calendarView);
            calendarView.setSelectionMode(CalendarSelectionMode.Range);
            calendarView.setSelectionManager(new MySelectionManager(calendarView));
            CircularRangeDecorator decorator = new CircularRangeDecorator(calendarView);
            calendarView.setCellDecorator(decorator);

            calendarView.setOnCellClickListener(new RadCalendarView.OnCellClickListener() {
             
                @Override
                public void onCellClick(CalendarCell calendarCell) {
                    if (calendarCell.isEnabled()) {
                        selected30Dates(calendarCell.getDate());
                    }
                }
            });
            

            if (selectionRange != null) {
                calendarView.setSelectedRange(selectionRange);
            } 
            else
            {
                ArrayList<Long> selectedDates = new ArrayList<Long>();
                Calendar today = Calendar.getInstance();
                selectedDates.add(today.getTimeInMillis());
                
                     calendarView.setDateToColor(new Function<Long, Integer>() {
                    @Override
                    public Integer apply(Long argument) {
                        Calendar today = Calendar.getInstance();
                        Calendar cellDate = Calendar.getInstance();
                        
                        cellDate.setTimeInMillis(argument);
                        if (cellDate.get(Calendar.YEAR) == today.get(Calendar.YEAR) &&
                                cellDate.get(Calendar.MONTH) == today.get(Calendar.MONTH) &&
                                cellDate.get(Calendar.DAY_OF_MONTH) == today.get(Calendar.DAY_OF_MONTH)) {
                            return PURPLE_COLOR;
                        }
                        return null;
                    }

                });


    today.add(Calendar.DATE, 30);
                   selectedDates.add(today.getTimeInMillis());
                   calendarView.setSelectedDates(selectedDates);
                   
           final Calendar calendar = Calendar.getInstance();
                   calendarView.setCustomizationRule(new Procedure<CalendarCell>(){

           @Override
           public void apply(CalendarCell calendarCell) {
           // TODO Auto-generated method stub
           if (calendarCell instanceof CalendarDayCell) {
                       calendar.setTimeInMillis(calendarCell.getDate());
                       ((CalendarDayCell) calendarCell).setSelectable(
                       !(calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY ||
                               calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY));
                   }
           }
                   }); 
            }
            
             dialogBuilder.setView(rootView);
            dialogBuilder.setPositiveButton(R.string.abc_action_mode_done, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogs, int which) {
                dialogs.dismiss();
                    
                    selectionRange = calendarView.getSelectedRange();
                  
                    Long start = selectionRange.getStart();
                    startCovenant = new Date(start);
                    Long end = selectionRange.getEnd();
                    endCovenant = new Date(end);
                    Calendar cal = Calendar.getInstance();
                    cal.setTime(endCovenant); 
                    cal.add(Calendar.HOUR_OF_DAY, 6);
                        
                    DateFormat formatter = DateFormat.getInstance(); // Date and time
                    String dateStr = formatter.format(cal.getTime());
    txtRange.setText(getFormattedRangeString(selectionRange));
                    txtRange.setTextSize(15);
       
                }
            });
            dialog = dialogBuilder.create();

            dialog.show();
            dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
                @Override
                public void onDismiss(DialogInterface dialogInterface) {
                    dialogOpened = false;
                    dialog.dismiss();
                }
            });

            CalendarAdapter adapter = calendarView.getAdapter();
            adapter.setStyle(CalendarStyles.light(this));
            adapter.setTitleBackgroundColor(BACKGROUND_COLOR);
            adapter.setTitleTextColor(PURPLE_COLOR);
            adapter.setTodayCellBorderColor(Color.TRANSPARENT);

            adapter.setDateCellBackgroundColor(BACKGROUND_COLOR, BACKGROUND_COLOR);
            adapter.setTodayCellBackgroundColor(BACKGROUND_COLOR);
            adapter.setSelectedCellBackgroundColor(BACKGROUND_COLOR);
            adapter.setDateTextPosition(CalendarTextElement.CENTER);

            adapter.setDayNameBackgroundColor(BACKGROUND_COLOR);
            adapter.setDayNameTextPosition(CalendarTextElement.CENTER);

            decorator.setColor(SELECTION_COLOR_SECONDARY);
            decorator.setShapeColor(SELECTION_COLOR_MAIN);
        }

      @Override
        public void onSaveInstanceState(Bundle outState) {
            super.onSaveInstanceState(outState);
            if (selectionRange != null) {
                outState.putLong("selectionRangeStart", selectionRange.getStart());
                outState.putLong("selectionRangeEnd", selectionRange.getEnd());
            }
            if (dialog != null) {
                outState.putBoolean("dialogShown", dialog.isShowing());
                if (dialog.isShowing() && calendarView != null && calendarView.getSelectedRange() != null) {
                    outState.putLong("dialogRangeStart", calendarView.getSelectedRange().getStart());
                    outState.putLong("dialogRangeEnd", calendarView.getSelectedRange().getEnd());
                    outState.putLong("dialogDisplayDate", calendarView.getDisplayDate());
                }
            }
        }

    public void onActivityCreated(Bundle savedInstanceState) {
       //super.onActivityCreated(savedInstanceState);
            if (savedInstanceState != null) {
                // Restore last state for checked position.
                if (savedInstanceState.containsKey("selectionRangeStart") && savedInstanceState.containsKey("selectionRangeEnd")) {
                    Long start = savedInstanceState.getLong("selectionRangeStart");
                    Long end = savedInstanceState.getLong("selectionRangeEnd");
                    this.selectionRange = new DateRange(start, end);
                    txtRange.setText(getFormattedDateString(selectionRange));
                    txtRange.setTextSize(15);
                }
                if (savedInstanceState.containsKey("dialogShown")) {
                    boolean isShown = savedInstanceState.getBoolean("dialogShown");
                    if (isShown) {
                        showRangeSelector();
                        if (savedInstanceState.containsKey("dialogRangeStart") && savedInstanceState.containsKey("dialogRangeEnd")) {
                            Long start = savedInstanceState.getLong("dialogRangeStart");
                            Long end = savedInstanceState.getLong("dialogRangeEnd");
                            calendarView.setSelectedRange(new DateRange(start, end));
                        }
                        if (savedInstanceState.containsKey("dialogDisplayDate")) {
                            long displayDate = savedInstanceState.getLong("dialogDisplayDate");
                            calendarView.setDisplayDate(displayDate);
                        }
                    }
                }
            }
        }

       private String getFormattedDateString(DateRange date) {
            Calendar startValue = Calendar.getInstance();
            startValue.setTimeInMillis(date.getStart());
            String startMonth = startValue.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.getDefault());
            int startMonthDate = startValue.get(Calendar.DAY_OF_MONTH);
            String nightsText = "1 dia";
            String result = "Dia " + startMonthDate + " de " + startMonth + " - " + nightsText;
            return result;
        }

        private String getFormattedRangeString(DateRange date) {
            Calendar startValue = Calendar.getInstance();
            startValue.setTimeInMillis(date.getStart());
            Calendar endValue = Calendar.getInstance();
            endValue.setTimeInMillis(date.getEnd());
            int nightsCount = this.getDayCount(date.getEnd() - date.getStart());
            String startMonth = startValue.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.getDefault());
            int startMonthDate = startValue.get(Calendar.DAY_OF_MONTH);
            
            int endMonthDate = endValue.get(Calendar.DAY_OF_MONTH);
            String endMonth = endValue.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.getDefault());
            String nightsText = nightsCount == 1 ? "dia" : "dias";
            String result = "De "+ startMonthDate + " " + startMonth + " a " + endMonthDate + " " + endMonth + " - " + nightsCount + " " +nightsText;
            return result;
        }

    private void updateHandledGestures(RadCalendarView calendarView) {

            calendarView.getGestureManager().setSwipeUpToChangeDisplayMode(false);
            calendarView.getGestureManager().setPinchCloseToChangeDisplayMode(false);
            calendarView.getGestureManager().setPinchOpenToChangeDisplayMode(false);
            calendarView.getGestureManager().setDoubleTapToChangeDisplayMode(false);
            calendarView.getGestureManager().setUsingDragToMakeRangeSelection(true);//true
      
        }

        private int getDayCount(long millis) {
            return (int) (((millis / 1000) / 60) / 60) / 24;
        }
    }

     

     

  7. Todor
    Admin
    Todor avatar
    778 posts

    Posted 23 Oct 2015 Link to this post

    Hi Miguel,

    Thank you for writing back and for sharing the code, which helped my identify why it doesn't work.

    What you need to do, is to move the setting of the selection mode after the setting of the new selection manager, so that it can be properly initialized.

    Working code:

    calendarView.setSelectionManager(new MySelectionManager(calendarView));
    calendarView.setSelectionMode(CalendarSelectionMode.Range);

    Your code:

    calendarView.setSelectionMode(CalendarSelectionMode.Range);
    calendarView.setSelectionManager(new MySelectionManager(calendarView));

    I hope this information helps.

    Regards,
    Todor
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  8. Miguel
    Miguel avatar
    5 posts
    Member since:
    Oct 2015

    Posted 26 Oct 2015 in reply to Todor Link to this post

    I try your solutions but i don´t have the effect what i need.

    The result of your solutions is on image1 and the effect if i want appears in the image2

  9. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 29 Oct 2015 Link to this post

    Hello Miguel,

    Thank you for writing.
    To receive further support, please consider purchasing a license for the controls.

    Regards,
    Victor
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  10. Miguel
    Miguel avatar
    5 posts
    Member since:
    Oct 2015

    Posted 29 Oct 2015 in reply to Victor Link to this post


    I already bought the Android UI module , but in the meantime there was confusion and was attached to another account here of the company. So where can I get more support
  11. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 29 Oct 2015 Link to this post

    Hi Miguel,

    Can you please clarify which is that other account? As soon as your license is verified we will help you your question. Also, to avoid further confusion you can post questions from the account with which the license is associated. Otherwise the system says that you do not have active support.

    Regards,
    Victor
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  12. paySimplex
    paySimplex avatar
    4 posts
    Member since:
    Sep 2015

    Posted 29 Oct 2015 in reply to Victor Link to this post

    Hello I am Miguel, the account whitch bought the license product this is.

    How can i then do to help me in this problme?

     

    Thank you

  13. Todor
    Admin
    Todor avatar
    778 posts

    Posted 03 Nov 2015 Link to this post

    Hello Miguel,

    Thank you for getting back to us.

    I have reviewed the code that you have sent and it seems that you have missed one of the directions that I had given to you - to change the customization rule in way that the cells from the weekend are set as -not enabled*, while in your code they are set as *not selectable*. In short use this to set your customization rule:

    calendarView.setCustomizationRule(new Procedure<CalendarCell>() {
        @Override
        public void apply(CalendarCell calendarCell) {
        if (calendarCell instanceof CalendarDayCell) {
            calendar.setTimeInMillis(calendarCell.getDate());
            calendarCell.setEnabled(
                    !(calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY ||
                            calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY));
        }
        }
    });

    I hope now you will be able to achieve your scenario.

    Regards,
    Todor
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  14. paySimplex
    paySimplex avatar
    4 posts
    Member since:
    Sep 2015

    Posted 03 Nov 2015 in reply to Todor Link to this post

    It works, thank you.

    Now i have one last question.

    I want is not posssible select x days forward to start on the current day.

  15. Todor
    Admin
    Todor avatar
    778 posts

    Posted 04 Nov 2015 Link to this post

    Hi,

    I'm not sure I correctly understand what you want to achieve.
    If you mean that you want to have a certain number of days after today to be not selectable, then you have two options:
    1) change the min date to a date that is x dates from today (if that is the requirement):
    Calendar minDate = Calendar.getInstance();
    minDate.add(Calendar.DATE, 5);
    calendarView.setMinDate(minDate.getTimeInMillis());
    2) change the customization rule so that the x dates from today are treated in the same way as weekends:
    calendarView.setCustomizationRule(new Procedure<CalendarCell>() {
        @Override
        public void apply(CalendarCell calendarCell) {
            if (calendarCell instanceof CalendarDayCell) {
                calendar.setTimeInMillis(calendarCell.getDate());
                calendarCell.setEnabled(
                        !(calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY ||calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY)
                && (calendar.getTimeInMillis() > minDate.getTimeInMillis()));
            }
        }
    });

    I hope this helps. You can read more about the min date from this article.

    Regards,
    Todor
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  16. paySimplex
    paySimplex avatar
    4 posts
    Member since:
    Sep 2015

    Posted 05 Nov 2015 in reply to Todor Link to this post

    We are close to the result we want .

    At the moment I only have a problem I want when ​user open the calendar look like the image 1 and when user select the day user want to appear like the image 2, but the results I'm getting is the image 3 .

     

    The code i used it is:

     

       maxDate = Calendar.getInstance();
           minDate = Calendar.getInstance();
           calendarView = (RadCalendarView) rootView.findViewById(R.id.calendarView);
           maxDate.add(Calendar.DATE, 5);
             calendarView.setMinDate(Calendar.getInstance().getTimeInMillis());
             calendarView.setMaxDate(maxDate.getTimeInMillis());
                  calendarView.setHorizontalScroll(true);
                  calendarView.setShowGridLines(false);
                  calendarView.setScrollMode(ScrollMode.None);
                  updateHandledGestures(calendarView);​

     

            today.add(Calendar.DATE, 30);
                             selectedDates.add(today.getTimeInMillis());
                             calendarView.setSelectedDates(selectedDates);
                             
                      final Calendar calendar = Calendar.getInstance();
                         calendarView.setCustomizationRule(new Procedure<CalendarCell>(){
                             
                      @Override
                      public void apply(CalendarCell calendarCell) {
                      // TODO Auto-generated method stub
                      if (calendarCell instanceof CalendarDayCell) {
                                 calendar.setTimeInMillis(calendarCell.getDate());
                                 ((CalendarDayCell) calendarCell).setEnabled(
                                  !(calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY ||
                                         calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY));
                             }
                      }
                             }); ​

     

     

     calendarView.setSelectionManager(new MySelectionManager(calendarView));
                      calendarView.setSelectionMode(CalendarSelectionMode.Range);
                 CircularRangeDecorator decorator = new CircularRangeDecorator(calendarView);
                 calendarView.setCellDecorator(decorator);
                 calendarView.setOnCellClickListener(new RadCalendarView.OnCellClickListener() {
                 
                     @Override
                     public void onCellClick(CalendarCell calendarCell) {
                      if (calendarCell.isEnabled()) 
                      {
                             selected30Dates(calendarCell.getDate());
                         }
                     }
                 });

     

     

     

     

        private void selected30Dates(long start) {
            Calendar calendar = Calendar.getInstance();
            calendar.setTimeInMillis(start);
            calendar.add(Calendar.DATE, 30);
            long end = calendar.getTimeInMillis();
            DateRange dateRange = new DateRange(start, end);
            calendarView.setSelectedRange(dateRange);
        }​

     

  17. Todor
    Admin
    Todor avatar
    778 posts

    Posted 10 Nov 2015 Link to this post

    Hello Miguel,

    Try with the following customization rule:

    calendarView.setCustomizationRule(new Procedure<CalendarCell>() {
        @Override
        public void apply(CalendarCell calendarCell) {
            if (calendarCell instanceof CalendarDayCell) {
                calendar.setTimeInMillis(calendarCell.getDate());
                calendarCell.setEnabled(
                        !(calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY || calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY)
                                && (calendar.getTimeInMillis() > minDate.getTimeInMillis())
                                && (calendar.getTimeInMillis() < maxDate.getTimeInMillis()));
            }
        }
    });

    and remove these lines:

    calendarView.setMinDate(Calendar.getInstance().getTimeInMillis());
    calendarView.setMaxDate(maxDate.getTimeInMillis());

    I hope this information helps.

    Regards,
    Todor
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  18. paySimplex
    paySimplex avatar
    4 posts
    Member since:
    Sep 2015

    Posted 13 Nov 2015 in reply to Todor Link to this post

    It was really what I wanted to thank you. I think you guys should have a more complete API , because I think it has very little information to the programmer. However it has a good forum.

    Thank you

  19. Todor
    Admin
    Todor avatar
    778 posts

    Posted 13 Nov 2015 Link to this post

    Hi,

    I'm happy to see that we have achieved the desired behavior.

    Thank you for the provided feedback.

    Regards,
    Todor
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
DevCraft banner