private void onModeSelected(int mode) { int oldMode = mRecurring.getRepeatMode(); mRecurring.setRepeatMode(mode); updatePeriodUnit(); mRecurring.setRepeatSetting(0); if (mode == Recurring.REPEAT_NONE) { mPeriodEditText.setEnabled(false); mEndSpinner.setEnabled(false); mEndNumEditText.setEnabled(false); mEndDateButton.setEnabled(false); mSameDayRadioButton.setEnabled(false); mSameWeekdayRadioButton.setEnabled(false); mWeekView.setEnabled(false); } else { if (oldMode == Recurring.REPEAT_NONE) { mPeriodEditText.setEnabled(true); mEndSpinner.setEnabled(true); mEndNumEditText.setEnabled(true); mEndDateButton.setEnabled(true); mSameDayRadioButton.setEnabled(true); mSameWeekdayRadioButton.setEnabled(true); mWeekView.setEnabled(true); } switch (mode) { case Recurring.REPEAT_DAILY: case Recurring.REPEAT_YEARLY: animOut(mSameDayRadioButton, true, true); animOut(mSameWeekdayRadioButton, true, true); animOut(mWeekView, true, true); break; case Recurring.REPEAT_MONTHLY: animIn(mSameDayRadioButton, false); animIn(mSameWeekdayRadioButton, false); animOut(mWeekView, true, true); mRecurring.setMonthRepeatType( mSameDayRadioButton.isChecked() ? Recurring.MONTH_SAME_DAY : Recurring.MONTH_SAME_WEEKDAY); break; case Recurring.REPEAT_WEEKLY: animOut(mSameDayRadioButton, true, true); animOut(mSameWeekdayRadioButton, true, true); animIn(mWeekView, false); for (int i = Calendar.SUNDAY; i <= Calendar.SATURDAY; i++) mRecurring.setEnabledWeekday(i, mWeekView.isSelected(i)); break; } } }
private void updateRecurringData() { Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(mRecurring.getStartTime()); int order = Recurring.getWeekDayOrderNum(cal); String dayOfWeek = cal.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.getDefault()); int formattedTextId = MONTH_SAME_WEEKDAY[(order + 1) % MONTH_SAME_WEEKDAY.length]; mSameWeekdayRadioButton.setText( getContext().getResources().getString(formattedTextId, dayOfWeek)); mPeriodEditText.setText(String.valueOf(mRecurring.getPeriod())); if (mRecurring.getRepeatMode() == Recurring.REPEAT_WEEKLY) { for (int i = Calendar.SUNDAY; i <= Calendar.SATURDAY; i++) mWeekView.setSelected(i, mRecurring.isEnabledWeekday(i), true); } else { int day = cal.get(Calendar.DAY_OF_WEEK); for (int i = Calendar.SUNDAY; i <= Calendar.SATURDAY; i++) mWeekView.setSelected(i, i == day, true); if (mRecurring.getRepeatMode() == Recurring.REPEAT_MONTHLY) { mSameDayRadioButton.setCheckedImmediately( mRecurring.getMonthRepeatType() == Recurring.MONTH_SAME_DAY); mSameWeekdayRadioButton.setCheckedImmediately( mRecurring.getMonthRepeatType() == Recurring.MONTH_SAME_WEEKDAY); } else { mSameDayRadioButton.setCheckedImmediately(true); mSameWeekdayRadioButton.setCheckedImmediately(false); } } if (mModeSpinner.getSelectedItemPosition() != mRecurring.getRepeatMode()) mModeSpinner.setSelection(mRecurring.getRepeatMode()); else onModeSelected(mRecurring.getRepeatMode()); mEndNumEditText.setText( String.valueOf( mRecurring.getEndMode() == Recurring.END_FOR_EVENT ? mRecurring.getEventNumber() : 10)); long date = mRecurring.getEndMode() == Recurring.END_UNTIL_DATE ? mRecurring.getEndDate() : (Math.max(System.currentTimeMillis(), mRecurring.getStartTime()) + 86400000L * 31); mEndDateButton.setText(mDateFormat.format(new Date(date))); mEndDateButton.setTag(date); if (mEndSpinner.getSelectedItemPosition() != mRecurring.getEndMode()) mEndSpinner.setSelection(mRecurring.getEndMode()); else onEndSelected(mRecurring.getEndMode()); }
/** * A method to update the current month. Sets the variable that controls the month and updates the * text. * * @param newMonth an integer value between 0 and 11. */ public void updateMonth(int newMonth) { pastMonthOffset = currentMonthOffset; currentMonthOffset = CakeCal.getDayOfWeek(new SimpleDate((newMonth), 1, currentYear)); miniDays[(currentDay - 1) + pastMonthOffset].setForeground(Color.black); currentMonth = newMonth; miniCalTitle.setText(curMonths[currentMonth - 1] + ", " + currentYear); events = calendar.getEvents( Period.parse( currentYear + "." + currentMonth + ".1:00.00-" + currentYear + "." + currentMonth + "." + curMonths[currentMonth - 1] + ":24.00")); panelEvent.update(); if (currentDay > (CakeCal.getMonths(currentYear))[currentMonth - 1]) { currentDay = (CakeCal.getMonths(currentYear))[currentMonth - 1]; } updateDays(); mview.updateMonth(); dayView.updateDay(); weekView.updateWeek(); this.updateDays(); }
/** Updates the days, and how they are viewed. */ public void updateDays() { curMonths = CakeCal.getMonths(currentYear); // create the days in the particular month for (int i = 0; i < 42; i++) { if (i >= currentMonthOffset && i < curMonths[currentMonth - 1] + currentMonthOffset) { miniDays[i].setText(i - currentMonthOffset + 1 + ""); miniDays[i].setName(i - currentMonthOffset + 1 + ""); if (mview.hasEvents(new SimpleDate(currentMonth, i, currentYear)) == true) { miniDays[i].setToolTipText("You have events scheduled here."); } else { miniDays[i].setToolTipText("No events have been scheduled"); } Border line = BorderFactory.createEtchedBorder(Color.BLACK, Color.BLACK); TitledBorder title = BorderFactory.createTitledBorder(line); miniDays[currentDay + (currentMonthOffset - 1)].setBorder(title); miniDays[currentDay + (currentMonthOffset - 1)].setFont(new Font("Verdana", Font.BOLD, 12)); } else { miniDays[i].setToolTipText(null); miniDays[i].setText(" "); miniDays[i].setName(" "); } if (i == currentDay + currentMonthOffset - 1) { miniDays[i].setForeground(Color.red); } // Setting properly (one-digit) alignment in the mini calendar if (miniDays[i].getText().length() == 1) { String s = " " + miniDays[i].getText(); miniDays[i].setText(s); } float[] n = new float[3]; Color.RGBtoHSB(212, 208, 200, n); miniDays[i].setOpaque(true); miniDays[i].setBackground(Color.WHITE); miniDays[i].setForeground(Color.BLACK); miniDays[i].setFont(null); Border line = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED); TitledBorder title = BorderFactory.createTitledBorder(line); miniDays[i].setBorder(title); if (currentMonth == TODAYMONTH && currentYear == TODAYYEAR) { miniDays[(TODAYDAY - 1) + currentMonthOffset].setForeground(Color.RED); miniDays[(TODAYDAY - 1) + currentMonthOffset].setFont(new Font("Verdana", Font.BOLD, 12)); } } if (DayToErase > 0) { miniDays[DayToErase].setForeground(Color.black); DayToErase = -1; } // This var holds the number of dates of the previous month int previousMonthDates = curMonths[((currentMonth - 2) + 12) % 12]; float[] n = new float[3]; Color.RGBtoHSB(200, 200, 200, n); for (int k = currentMonthOffset - 1; k >= 0; k--) { miniDays[k].setText(previousMonthDates + ""); miniDays[k].setForeground(Color.GRAY); miniDays[k].setBackground(Color.getHSBColor(n[0], n[1], n[2])); previousMonthDates--; } int count = 1; for (int k = (curMonths[currentMonth - 1] + currentMonthOffset); k < 42; k++) { miniDays[k].setText(count + ""); miniDays[k].setForeground(Color.GRAY); miniDays[k].setBackground(Color.getHSBColor(n[0], n[1], n[2])); count++; } String shortDate = " " + Cakeday.MONTHS[currentMonth - 1]; title.setTitle(shortDate); bottomRight.setBorder(title); bottomRight.repaint(); // ------------END OF---TITLED BORDER------------- // -------Updates the year in the JTextField in the mini calendar------// yearField.setText("" + currentYear); // -------Updates the year in the JTextField in the mini calendar------// smallMonth.repaint(); weekView.updateWeek(); dayView.updateDay(); miniMonth.repaint(); }
/** * On the mini month this method will always highlight the current day in red * * @param s The new day */ public void highlightToday(int s) { // Creates border on the selected day for (int i = 0; i < 42; i++) { float[] n = new float[3]; Color.RGBtoHSB(212, 208, 200, n); miniDays[i].setOpaque(true); miniDays[i].setForeground(Color.BLACK); miniDays[i].setFont(null); Border line = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED); TitledBorder title = BorderFactory.createTitledBorder(line); miniDays[i].setBorder(title); } // Creates the font for the selected day miniDays[(currentDay - 1) + currentMonthOffset].setForeground(Color.black); miniDays[(s - 1) + currentMonthOffset].setForeground(Color.BLACK); miniDays[(s - 1) + currentMonthOffset].setFont(new Font("Verdana", Font.BOLD, 12)); miniDays[(s - 1) + currentMonthOffset].setOpaque(true); // Set the border of the selected date in the mini calendar Border line = BorderFactory.createEtchedBorder(Color.BLACK, Color.BLACK); TitledBorder title = BorderFactory.createTitledBorder(line); miniDays[(s - 1) + currentMonthOffset].setBorder(title); // miniDays[(s-1) + currentMonthOffset].setBackground(Color.WHITE); currentDay = s; if (currentMonth == TODAYMONTH && currentYear == TODAYYEAR) { // Highlights the current day in red when the current month and year is selected miniDays[(TODAYDAY - 1) + currentMonthOffset].setForeground(Color.RED); miniDays[(TODAYDAY - 1) + currentMonthOffset].setFont(new Font("Verdana", Font.BOLD, 12)); DayToErase = (TODAYDAY - 1) + currentMonthOffset; } else if (DayToErase > 0) { // changes the current day back to black when the current month and year are not highlighted. miniDays[DayToErase].setForeground(Color.black); DayToErase = -1; } // This var holds the number of dates of the previous month int previousMonthDates = curMonths[((currentMonth - 2) + 12) % 12]; for (int k = currentMonthOffset - 1; k >= 0; k--) { miniDays[k].setText(previousMonthDates + ""); miniDays[k].setForeground(Color.GRAY); previousMonthDates--; } // Testing // Testing // System.out.println("curMonths[currentMonth - 1] ==" + curMonths[currentMonth - 1]); int count = 1; for (int k = (curMonths[currentMonth - 1] + currentMonthOffset); k < 42; k++) { miniDays[k].setText(count + ""); miniDays[k].setForeground(Color.GRAY); count++; } // Testing smallMonth.repaint(); miniMonth.repaint(); panelEvent.update(); weekView.updateWeek(); }
/** Initialize the three panels which will switch out in the center */ private void initializeCenter() { viewChanger = new CardLayout(); // initialize the 3 different JPanels which go in the center center = new JPanel(viewChanger); month = new JPanel(); mview.addComponentsToPane(month); // JPanel weekTitles = new JPanel( new GridLayout(7,7)); smallMonth = new JPanel(new GridLayout(7, 7)); String weekDay[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; JLabel label = new JLabel(); for (int i = 0; i < 7; i++) { label = new JLabel(weekDay[i]); label.setHorizontalAlignment(JLabel.CENTER); label.setFont(new Font("Verdana", Font.BOLD, 12)); smallMonth.add(label); } // smallMonth = new JPanel( new GridLayout( 6, 7 )); for (int i = 0; i < 42; i++) { if (i >= currentMonthOffset && i < curMonths[currentMonth - 1] + currentMonthOffset) { miniDays[i] = new JLabel(i - currentMonthOffset + 1 + ""); miniDays[i].setName(i - currentMonthOffset + 1 + ""); miniDays[i].addMouseListener((MouseListener) this); miniDays[i].setHorizontalAlignment(JLabel.CENTER); if (mview.hasEvents(new SimpleDate(currentMonth, i, currentYear)) == true) { miniDays[i].setToolTipText("You have events scheduled here."); } else { miniDays[i].setToolTipText("No Events have been scheduled."); } if (i == currentDay + currentMonthOffset - 1) { miniDays[i].setFont(new Font("Verdana", Font.BOLD, 12)); miniDays[i].setOpaque(true); Border line = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED); TitledBorder title = BorderFactory.createTitledBorder(line); miniDays[i].setBorder(title); } } else { miniDays[i] = new JLabel(""); miniDays[i].setName(""); miniDays[i].addMouseListener((MouseListener) this); miniDays[i].setHorizontalAlignment(JLabel.CENTER); } smallMonth.add(miniDays[i]); smallMonth.setBorder(miniTitle); } for (int j = 0; j < 42; j++) { Border line = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED); TitledBorder title = BorderFactory.createTitledBorder(line); miniDays[j].setBorder(title); } int count = 1; for (int k = curMonths[currentMonth - 1]; k < 42; k++) { miniDays[k].setName(count++ + ""); } week = weekView.getPanel(); day = dayView.getPane(); day.setFocusable(true); center.add(week, WEEK); center.add(day, DAY); center.add(month, MONTH); }
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) @Override protected void onCreate() { View v = LayoutInflater.from(getContext()).inflate(R.layout.dialog_recurring, null); setContentView(v); FrameLayout fl_mode = (FrameLayout) v.findViewById(R.id.rd_fl_mode); final ScrollView sv_repeat = (ScrollView) v.findViewById(R.id.rd_sv_repeat); final LinearLayout ll_repeat = (LinearLayout) v.findViewById(R.id.rd_ll_repeat); mModeSpinner = (Spinner) fl_mode.findViewById(R.id.rd_spn_mode); mEndSpinner = (Spinner) v.findViewById(R.id.rd_spn_end); mPeriodEditText = (EditText) v.findViewById(R.id.rd_et_period); mPeriodUnitTextView = (TextView) v.findViewById(R.id.rd_tv_period_unit); mSameDayRadioButton = (RadioButton) v.findViewById(R.id.rd_month_rb_same); mSameWeekdayRadioButton = (RadioButton) v.findViewById(R.id.rd_month_rb_week); mEndNumEditText = (EditText) v.findViewById(R.id.rd_et_end_num); mEndNumUnitTextView = (TextView) v.findViewById(R.id.rd_tv_end_num_unit); mEndDateButton = (Button) v.findViewById(R.id.rd_bt_end_date); mWeekView = (WeekView) v.findViewById(R.id.rd_wv_week); sv_repeat .getViewTreeObserver() .addOnGlobalLayoutListener( new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { showDivider(ll_repeat.getMeasuredHeight() > sv_repeat.getMeasuredHeight()); } }); mHeaderBackground = new HeaderDrawable(getContext()); ViewCompat.setPaddingRelative(fl_mode, mContentPadding, 0, mContentPadding, 0); ViewUtil.setBackground(fl_mode, mHeaderBackground); ViewCompat.setPaddingRelative( ll_repeat, mContentPadding, mActionOuterPadding, mContentPadding, mActionPadding); mModeAdapter = new ModeAdapter(); mModeSpinner.setAdapter(mModeAdapter); mModeSpinner.setOnItemSelectedListener( new Spinner.OnItemSelectedListener() { @Override public void onItemSelected(Spinner parent, View view, int position, long id) { onModeSelected(position); } }); mEndAdapter = new EndAdapter(); mEndSpinner.setAdapter(mEndAdapter); mEndSpinner.setOnItemSelectedListener( new Spinner.OnItemSelectedListener() { @Override public void onItemSelected(Spinner parent, View view, int position, long id) { onEndSelected(position); } }); mPeriodEditText.addTextChangedListener( new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) {} @Override public void onTextChanged(CharSequence s, int start, int before, int count) {} @Override public void afterTextChanged(Editable s) { onPeriodChanged(); } }); mPeriodEditText.setOnKeyListener( new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_UP) { String text = mPeriodEditText.getText().toString(); if (TextUtils.isEmpty(text)) mPeriodEditText.setText(String.valueOf(mRecurring.getPeriod())); } return false; } }); CompoundButton.OnCheckedChangeListener mCheckChangeListener = new android.widget.CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged( android.widget.CompoundButton buttonView, boolean isChecked) { if (isChecked) { if (buttonView == mSameDayRadioButton) mSameWeekdayRadioButton.setChecked(false); else mSameDayRadioButton.setChecked(false); onMonthSettingChanged(); } } }; mSameDayRadioButton.setOnCheckedChangeListener(mCheckChangeListener); mSameWeekdayRadioButton.setOnCheckedChangeListener(mCheckChangeListener); mEndNumEditText.addTextChangedListener( new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) {} @Override public void onTextChanged(CharSequence s, int start, int before, int count) {} @Override public void afterTextChanged(Editable s) { onEventNumberChanged(); } }); mEndNumEditText.setOnKeyListener( new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_UP) { String text = mEndNumEditText.getText().toString(); if (TextUtils.isEmpty(text)) mEndNumEditText.setText(String.valueOf(mRecurring.getEventNumber())); } return false; } }); View.OnClickListener mDateClickListener = new View.OnClickListener() { @Override public void onClick(View v) { final DatePickerDialog dialog = new DatePickerDialog(getContext(), mDatePickerDialogStyleId); long minTime = System.currentTimeMillis(); Calendar cal = dialog.getCalendar(); cal.setTimeInMillis(minTime); cal.add(Calendar.YEAR, 100); long maxTime = cal.getTimeInMillis(); dialog .dateRange(minTime, maxTime) .date((long) mEndDateButton.getTag()) .positiveAction(mPositiveAction.getText()) .positiveActionClickListener( new View.OnClickListener() { @Override public void onClick(View v) { onEndDateChanged(dialog.getDate()); dialog.dismiss(); } }) .negativeAction(mNegativeAction.getText()) .negativeActionClickListener( new View.OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); } }) .show(); } }; mEndDateButton.setOnClickListener(mDateClickListener); mWeekView.setOnDaySelectionChangedListener(this); }