private void setupView() {

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    final ActionBar ab = getSupportActionBar();
    ab.setDisplayHomeAsUpEnabled(true);

    mWeekView = (WeekView) findViewById(R.id.weekView);
    mWeekView.setOnEventClickListener(this);
    mWeekView.setMonthChangeListener(this);
    mWeekView.setEventLongPressListener(this);
    setupDateTimeInterpreter(false);
  }
Ejemplo n.º 2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Get a reference for the week view in the layout.
    mWeekView = (WeekView) findViewById(R.id.weekView);

    // Show a toast message about the touched event.
    mWeekView.setOnEventClickListener(this);

    // The week view has infinite scrolling horizontally. We have to provide the events of a
    // month every time the month changes on the week view.
    mWeekView.setMonthChangeListener(this);

    // Set long press listener for events.
    mWeekView.setEventLongPressListener(this);
  }
Ejemplo n.º 3
0
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    switch (id) {
      case R.id.action_today:
        mWeekView.goToToday();
        return true;
      case R.id.action_type:
        if (mWeekViewType == TYPE_WEEK_VIEW) {
          mWeekViewType = TYPE_DAY_VIEW;
          mWeekView.setNumberOfVisibleDays(1);
          item.setTitle(R.string.action_week_view);
        } else {
          mWeekViewType = TYPE_WEEK_VIEW;
          mWeekView.setNumberOfVisibleDays(3);
          item.setTitle(R.string.action_day_view);
        }
        return true;
    }

    return super.onOptionsItemSelected(item);
  }
  private void setupDateTimeInterpreter(final boolean shortDate) {
    mWeekView.setDateTimeInterpreter(
        new DateTimeInterpreter() {
          @Override
          public String interpretDate(Calendar date) {
            SimpleDateFormat weekdayNameFormat = new SimpleDateFormat("EEE", Locale.getDefault());
            String weekday = weekdayNameFormat.format(date.getTime());
            SimpleDateFormat format = new SimpleDateFormat(" M/d", Locale.getDefault());

            // All android api level do not have a standard way of getting the first letter of
            // the week day name. Hence we get the first char programmatically.
            // Details:
            // http://stackoverflow.com/questions/16959502/get-one-letter-abbreviation-of-week-day-of-a-date-in-java#answer-16959657
            if (shortDate) weekday = String.valueOf(weekday.charAt(0));
            return weekday.toUpperCase() + format.format(date.getTime());
          }

          @Override
          public String interpretTime(int hour) {
            return hour > 11 ? (hour - 12) + " PM" : (hour == 0 ? "12 AM" : hour + " AM");
          }
        });
  }
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    setupDateTimeInterpreter(id == R.id.action_week_view);
    switch (id) {
      case android.R.id.home:
        finish();
        break;
      case R.id.action_today:
        mWeekView.goToToday();
        return true;
      case R.id.action_day_view:
        if (mWeekViewType != TYPE_DAY_VIEW) {
          item.setChecked(!item.isChecked());
          mWeekViewType = TYPE_DAY_VIEW;
          mWeekView.setNumberOfVisibleDays(1);

          // Lets change some dimensions to best fit the view.
          mWeekView.setColumnGap(
              (int)
                  TypedValue.applyDimension(
                      TypedValue.COMPLEX_UNIT_DIP, 8, getResources().getDisplayMetrics()));
          mWeekView.setTextSize(
              (int)
                  TypedValue.applyDimension(
                      TypedValue.COMPLEX_UNIT_SP, 12, getResources().getDisplayMetrics()));
          mWeekView.setEventTextSize(
              (int)
                  TypedValue.applyDimension(
                      TypedValue.COMPLEX_UNIT_SP, 12, getResources().getDisplayMetrics()));
        }
        return true;
      case R.id.action_three_day_view:
        if (mWeekViewType != TYPE_THREE_DAY_VIEW) {
          item.setChecked(!item.isChecked());
          mWeekViewType = TYPE_THREE_DAY_VIEW;
          mWeekView.setNumberOfVisibleDays(3);

          // Lets change some dimensions to best fit the view.
          mWeekView.setColumnGap(
              (int)
                  TypedValue.applyDimension(
                      TypedValue.COMPLEX_UNIT_DIP, 8, getResources().getDisplayMetrics()));
          mWeekView.setTextSize(
              (int)
                  TypedValue.applyDimension(
                      TypedValue.COMPLEX_UNIT_SP, 12, getResources().getDisplayMetrics()));
          mWeekView.setEventTextSize(
              (int)
                  TypedValue.applyDimension(
                      TypedValue.COMPLEX_UNIT_SP, 12, getResources().getDisplayMetrics()));
        }
        return true;
      case R.id.action_week_view:
        if (mWeekViewType != TYPE_WEEK_VIEW) {
          item.setChecked(!item.isChecked());
          mWeekViewType = TYPE_WEEK_VIEW;
          mWeekView.setNumberOfVisibleDays(7);

          // Lets change some dimensions to best fit the view.
          mWeekView.setColumnGap(
              (int)
                  TypedValue.applyDimension(
                      TypedValue.COMPLEX_UNIT_DIP, 2, getResources().getDisplayMetrics()));
          mWeekView.setTextSize(
              (int)
                  TypedValue.applyDimension(
                      TypedValue.COMPLEX_UNIT_SP, 10, getResources().getDisplayMetrics()));
          mWeekView.setEventTextSize(
              (int)
                  TypedValue.applyDimension(
                      TypedValue.COMPLEX_UNIT_SP, 10, getResources().getDisplayMetrics()));
        }
        return true;
    }

    return super.onOptionsItemSelected(item);
  }