在android

时间:2015-12-30 07:38:59

标签: android

我使用CalendarPickerView。我在日历上显示当前日期。我希望在日历上禁用通过日期。请。救救我!

这是我的代码

 public class CalendarActivity extends BaseActivity implements View.OnClickListener, CalendarCellDecorator {
    private Toolbar mToolbar;
    private CalendarPickerView mCalendarView;
    private int mDay, mMonth, mYear;
    private String mDayOfWeek;
    private long mTimeDate;
    private long minDate;
    private TextView mBtnBack, mToolbar_title_right;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_calendar);
    boolean isType = getIntent().getBooleanExtra(Constant.INTENT_TYPE_ACTIVITY, true);
    if (isType) {
        setUpToolBar(this, getString(R.string.title_activity_date_repay), getString(R.string.text_button_back_area));
    } else {
        setUpToolBar(this, getString(R.string.title_activity_date_borrow), getString(R.string.text_button_back_area));
    }
    addControl();
    initCalendar();
    addEventOnclick();
}

private void addEventOnclick() {
    mToolbar_title_right.setVisibility(View.GONE);
    mBtnBack.setVisibility(View.VISIBLE);
    mBtnBack.setText(getResources().getString(R.string.text_button_back_area));
    mBtnBack.setOnClickListener(this);
    mBtnBack.setTextColor(getResources().getColor(R.color.background_button_main_2));
}

private void addControl() {
    mToolbar = (Toolbar) findViewById(R.id.my_toolbar);
    mBtnBack = (TextView) findViewById(R.id.text_back);
    mToolbar_title_right = (TextView) findViewById(R.id.text_title_right);
    mCalendarView = (CalendarPickerView) findViewById(R.id.calendar_view);
    List<CalendarCellDecorator> decoratorList = new ArrayList<>();
    decoratorList.add(this);
    mCalendarView.setDecorators(decoratorList);
}


private void initCalendar() {
    minDate = getIntent().getLongExtra(Constant.EXTRA_MIN_DATE, 0);
    mTimeDate = getIntent().getLongExtra(Constant.EXTRA_TIME_DATE, 0);
    mDay = getIntent().getIntExtra(Constant.EXTRA_DAY, 1);
    mMonth = getIntent().getIntExtra(Constant.EXTRA_MONTH, 1) - 1;
    mYear = getIntent().getIntExtra(Constant.EXTRA_YEAR, 2016);
    mDayOfWeek = getIntent().getStringExtra(Constant.EXTRA_DAY_OF_WEEK);
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(mTimeDate);

    Calendar maxDate = Calendar.getInstance();
    maxDate.add(Calendar.YEAR, 1);

    Calendar calMin = Calendar.getInstance();
    if (minDate != 0) {
        calMin.setTimeInMillis(minDate);
    }
    Date selectDate = new Date();
    if (calendar.compareTo(calMin) > 0) {
        selectDate = calendar.getTime();
    } else {
        selectDate = calMin.getTime();
    }

    mCalendarView.init(calMin.getTime(), maxDate.getTime())
            .withSelectedDate(selectDate)
            .inMode(CalendarPickerView.SelectionMode.SINGLE);
    mCalendarView.setOnDateSelectedListener(mDateListener);
}

@Override
public void onClick(View view) {
    switch (view.getId()) {
        case R.id.text_back:
            finish();
            break;
        default:
            break;
    }
}

private CalendarPickerView.OnDateSelectedListener mDateListener = new CalendarPickerView.OnDateSelectedListener() {

    @Override
    public void onDateSelected(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        mDay = calendar.get(Calendar.DAY_OF_MONTH);
        mMonth = calendar.get(Calendar.MONTH);
        mYear = calendar.get(Calendar.YEAR);
        mDayOfWeek = new SimpleDateFormat("EE", Locale.JAPAN).format(date);
        long startDate = Utils.getStartOfDay(date.getTime());
        long startCurrDate = Utils.getStartOfDay(mTimeDate);
        long millisecond = mTimeDate - startCurrDate;
        Intent mIntent = new Intent();
        mIntent.putExtra(Constant.EXTRA_TIME_DATE, startDate + millisecond);
        mIntent.putExtra(Constant.EXTRA_DAY, mDay);
        mIntent.putExtra(Constant.EXTRA_MONTH, mMonth + 1);
        mIntent.putExtra(Constant.EXTRA_YEAR, mYear);
        mIntent.putExtra(Constant.EXTRA_DAY_OF_WEEK, mDayOfWeek);
        setResult(RESULT_OK, mIntent);
        finish();
    }

    @Override
    public void onDateUnselected(Date date) {

    }
};

@Override
public void decorate(CalendarCellView cellView, Date date) {
    Calendar calendar1 = Calendar.getInstance();
    calendar1.setTime(date);
    String holiday = HolidayUtil.getHolidayName(calendar1);
    if (!TextUtils.isEmpty(holiday)) {
        cellView.setText(holiday);
        cellView.setTextSize(10);
        cellView.setTextColor(getResources().getColor(R.color.color_red));
    } else {
        cellView.setTextSize(14);
        cellView.setTextColor(getResources().getColor(R.color.color_text_dark));
    }
}
}

1 个答案:

答案 0 :(得分:0)

使用CalenderView.setMinDate()并使用getCurrentTime将当前日期作为参数传递,如此RewriteEngine on RewriteBase /fap2/ RewriteRule ^videos/([^/]+) vid.php?id=$1 [L]