예제 #1
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);
  }
  @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);
  }