Search in sources :

Example 1 with CalendarDay

use of com.prolificinteractive.materialcalendarview.CalendarDay in project material-calendarview by prolificinteractive.

the class CustomizeCodeActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_basic);
    ButterKnife.bind(this);
    widget.setShowOtherDates(MaterialCalendarView.SHOW_ALL);
    widget.setArrowColor(getResources().getColor(R.color.sample_primary));
    widget.setLeftArrowMask(getResources().getDrawable(R.drawable.ic_navigation_arrow_back));
    widget.setRightArrowMask(getResources().getDrawable(R.drawable.ic_navigation_arrow_forward));
    widget.setSelectionColor(getResources().getColor(R.color.sample_primary));
    widget.setHeaderTextAppearance(R.style.TextAppearance_AppCompat_Medium);
    widget.setWeekDayTextAppearance(R.style.TextAppearance_AppCompat_Medium);
    widget.setDateTextAppearance(R.style.CustomDayTextAppearance);
    widget.setTitleFormatter(new MonthArrayTitleFormatter(getResources().getTextArray(R.array.custom_months)));
    widget.setWeekDayFormatter(new ArrayWeekDayFormatter(getResources().getTextArray(R.array.custom_weekdays)));
    widget.setTileSize((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 36, getResources().getDisplayMetrics()));
    widget.setTitleAnimationOrientation(MaterialCalendarView.VERTICAL);
    CalendarDay today = CalendarDay.from(2016, 5, 2);
    widget.setCurrentDate(today);
    widget.setSelectedDate(today);
    widget.state().edit().setFirstDayOfWeek(Calendar.WEDNESDAY).setMinimumDate(CalendarDay.from(2016, 4, 3)).setMaximumDate(CalendarDay.from(2016, 5, 12)).setCalendarDisplayMode(CalendarMode.WEEKS).commit();
}
Also used : MonthArrayTitleFormatter(com.prolificinteractive.materialcalendarview.format.MonthArrayTitleFormatter) ArrayWeekDayFormatter(com.prolificinteractive.materialcalendarview.format.ArrayWeekDayFormatter) CalendarDay(com.prolificinteractive.materialcalendarview.CalendarDay)

Example 2 with CalendarDay

use of com.prolificinteractive.materialcalendarview.CalendarDay in project GeekNews by codeestX.

the class DailyFragment method initEventAndData.

@Override
protected void initEventAndData() {
    super.initEventAndData();
    currentDate = DateUtil.getTomorrowDate();
    mAdapter = new DailyAdapter(mContext, mList);
    mAdapter.setOnItemClickListener(new DailyAdapter.OnItemClickListener() {

        @Override
        public void onItemClick(int position, View shareView) {
            mPresenter.insertReadToDB(mList.get(position).getId());
            mAdapter.setReadState(position, true);
            if (mAdapter.getIsBefore()) {
                mAdapter.notifyItemChanged(position + 1);
            } else {
                mAdapter.notifyItemChanged(position + 2);
            }
            Intent intent = new Intent();
            intent.setClass(mContext, ZhihuDetailActivity.class);
            intent.putExtra(Constants.IT_ZHIHU_DETAIL_ID, mList.get(position).getId());
            ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(mActivity, shareView, "shareView");
            mContext.startActivity(intent, options.toBundle());
        }
    });
    swipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            if (currentDate.equals(DateUtil.getTomorrowDate())) {
                mPresenter.getDailyData();
            } else {
                int year = Integer.valueOf(currentDate.substring(0, 4));
                int month = Integer.valueOf(currentDate.substring(4, 6));
                int day = Integer.valueOf(currentDate.substring(6, 8));
                CalendarDay date = CalendarDay.from(year, month - 1, day);
                RxBus.getDefault().post(date);
            }
        }
    });
    rvDailyList.setLayoutManager(new LinearLayoutManager(mContext));
    rvDailyList.setAdapter(mAdapter);
    stateLoading();
    mPresenter.getDailyData();
}
Also used : Intent(android.content.Intent) CalendarDay(com.prolificinteractive.materialcalendarview.CalendarDay) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) BindView(butterknife.BindView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) ZhihuDetailActivity(com.codeest.geeknews.ui.zhihu.activity.ZhihuDetailActivity) DailyAdapter(com.codeest.geeknews.ui.zhihu.adapter.DailyAdapter) ActivityOptions(android.app.ActivityOptions)

Example 3 with CalendarDay

use of com.prolificinteractive.materialcalendarview.CalendarDay in project GeekNews by codeestX.

the class DailyPresenter method registerEvent.

private void registerEvent() {
    Subscription rxSubscription = RxBus.getDefault().toObservable(CalendarDay.class).subscribeOn(Schedulers.io()).map(new Func1<CalendarDay, String>() {

        @Override
        public String call(CalendarDay calendarDay) {
            StringBuilder date = new StringBuilder();
            String year = String.valueOf(calendarDay.getYear());
            String month = String.valueOf(calendarDay.getMonth() + 1);
            String day = String.valueOf(calendarDay.getDay() + 1);
            if (month.length() < 2) {
                month = "0" + month;
            }
            if (day.length() < 2) {
                day = "0" + day;
            }
            return date.append(year).append(month).append(day).toString();
        }
    }).filter(new Func1<String, Boolean>() {

        @Override
        public Boolean call(String s) {
            if (s.equals(DateUtil.getTomorrowDate())) {
                getDailyData();
                return false;
            }
            return true;
        }
    }).observeOn(//为了网络请求切到io线程
    Schedulers.io()).flatMap(new Func1<String, Observable<DailyBeforeListBean>>() {

        @Override
        public Observable<DailyBeforeListBean> call(String date) {
            return mRetrofitHelper.fetchDailyBeforeListInfo(date);
        }
    }).observeOn(//为了使用Realm和显示结果切到主线程
    AndroidSchedulers.mainThread()).map(new Func1<DailyBeforeListBean, DailyBeforeListBean>() {

        @Override
        public DailyBeforeListBean call(DailyBeforeListBean dailyBeforeListBean) {
            List<DailyListBean.StoriesBean> list = dailyBeforeListBean.getStories();
            for (DailyListBean.StoriesBean item : list) {
                item.setReadState(mRealmHelper.queryNewsId(item.getId()));
            }
            return dailyBeforeListBean;
        }
    }).subscribe(new CommonSubscriber<DailyBeforeListBean>(mView) {

        @Override
        public void onNext(DailyBeforeListBean dailyBeforeListBean) {
            int year = Integer.valueOf(dailyBeforeListBean.getDate().substring(0, 4));
            int month = Integer.valueOf(dailyBeforeListBean.getDate().substring(4, 6));
            int day = Integer.valueOf(dailyBeforeListBean.getDate().substring(6, 8));
            mView.showMoreContent(String.format("%d年%d月%d日", year, month, day), dailyBeforeListBean);
        }
    });
    addSubscrebe(rxSubscription);
}
Also used : DailyListBean(com.codeest.geeknews.model.bean.DailyListBean) DailyBeforeListBean(com.codeest.geeknews.model.bean.DailyBeforeListBean) Subscription(rx.Subscription) CalendarDay(com.prolificinteractive.materialcalendarview.CalendarDay) Func1(rx.functions.Func1)

Example 4 with CalendarDay

use of com.prolificinteractive.materialcalendarview.CalendarDay in project GitTest by xiaoxige.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    materialCalendarView = (MaterialCalendarView) findViewById(R.id.materialCalendarView);
    disableDecorator = new DisableDecorator(this);
    broadDecorator = new BroadDecorator(this);
    // 三年前
    Calendar mixTime = Calendar.getInstance();
    mixTime.add(Calendar.MONTH, -3 * 12);
    // 二十年后
    Calendar maxTime = Calendar.getInstance();
    maxTime.add(Calendar.YEAR, 5);
    maxTime.set(Calendar.DAY_OF_MONTH, maxTime.getActualMaximum(Calendar.DAY_OF_MONTH));
    materialCalendarView.addDecorators(new DefaultDecorator(this), disableDecorator, broadDecorator, descDecorator, mSelectDecorator);
    materialCalendarView.setTopbarVisible(true);
    materialCalendarView.setDynamicHeightEnabled(true);
    materialCalendarView.setSelectionMode(MaterialCalendarView.SELECTION_MODE_SINGLE);
    materialCalendarView.state().edit().setCalendarDisplayMode(CalendarMode.MONTHS).setMinimumDate(mixTime.getTime()).setMaximumDate(maxTime.getTime()).commit();
    materialCalendarView.setSelectedDate(CalendarDay.today());
    materialCalendarView.invalidateDecorators();
    materialCalendarView.setOnDateChangedListener(new OnDateSelectedListener() {

        @Override
        public void onDateSelected(@NonNull MaterialCalendarView widget, @NonNull CalendarDay date, boolean selected) {
            List<CalendarDay> dates = new ArrayList<>();
            dates.add(date);
            mSelectDecorator.setDays(dates);
            descDecorator.setDays(dates);
            materialCalendarView.invalidateDecorators();
        }

        @Override
        public void onDisableDateSelected(@NonNull MaterialCalendarView widget, @NonNull CalendarDay date, boolean selected) {
        }
    });
}
Also used : DisableDecorator(com.pangpangzhu.p2papp.test.calendardecorators.DisableDecorator) Calendar(java.util.Calendar) DefaultDecorator(com.pangpangzhu.p2papp.test.calendardecorators.DefaultDecorator) BroadDecorator(com.pangpangzhu.p2papp.test.calendardecorators.BroadDecorator) ArrayList(java.util.ArrayList) List(java.util.List) OnDateSelectedListener(com.prolificinteractive.materialcalendarview.OnDateSelectedListener) MaterialCalendarView(com.prolificinteractive.materialcalendarview.MaterialCalendarView) CalendarDay(com.prolificinteractive.materialcalendarview.CalendarDay)

Example 5 with CalendarDay

use of com.prolificinteractive.materialcalendarview.CalendarDay in project Habba18 by chiragsastry1996.

the class TimeLineActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    overridePendingTransitionEnter();
    setContentView(R.layout.activity_timeline);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        // in Activity's onCreate() for instance
        Window w = getWindow();
        w.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    }
    getSupportActionBar().hide();
    timestampsList = new ArrayList<>();
    timelineList = new ArrayList();
    if (getSupportActionBar() != null)
        getSupportActionBar().setDisplayHomeAsUpEnabled(false);
    calendarView = (MaterialCalendarView) findViewById(R.id.calendar);
    // setTitle(mOrientation == Orientation.HORIZONTAL ? getResources().getString(R.string.horizontal_timeline) : getResources().getString(R.string.vertical_timeline));
    mRecyclerView = (RecyclerView) findViewById(R.id.recyclerView);
    mRecyclerView.setLayoutManager(getLinearLayoutManager());
    mRecyclerView.setItemAnimator(new DefaultItemAnimator());
    mRecyclerView.setNestedScrollingEnabled(false);
    calendarDays = new HashSet<CalendarDay>();
    datespan();
    calendarView.setDateSelected(CalendarDay.today(), true);
    // calendarView.addDecorator(new EventDecorator(Color.RED, calendarDays));
    calendarView.state().edit().setFirstDayOfWeek(Calendar.WEDNESDAY).setMinimumDate(CalendarDay.from(2018, 1, 1)).setMaximumDate(CalendarDay.from(2018, 2, 31)).commit();
    calendarView.setOnDateChangedListener(new OnDateSelectedListener() {

        @Override
        public void onDateSelected(@NonNull MaterialCalendarView widget, @NonNull CalendarDay date, boolean selected) {
            mDataList.clear();
            timelineList.clear();
            mRecyclerView.invalidate();
            int curDate = date.getDay();
            int months = date.getMonth() + 1;
            String mon = "", dat = "";
            if (months < 10)
                mon = "0" + String.valueOf(months);
            else
                mon = String.valueOf(months);
            if (curDate < 10)
                dat = "0" + String.valueOf(curDate);
            else
                dat = String.valueOf(curDate);
            String searchDate = date.getYear() + "-" + mon + "-" + dat;
            for (int i = 0; i < Test.timeline.size(); i++) {
                if (searchDate.equals(Test.timeline.get(i).get(1))) {
                    ArrayList<String> indexList = new ArrayList<String>();
                    indexList.add(Test.timeline.get(i).get(0));
                    String time = Test.timeline.get(i).get(2);
                    SimpleDateFormat date12Format = new SimpleDateFormat("hh:mm a");
                    SimpleDateFormat date24Format = new SimpleDateFormat("HH:mm");
                    try {
                        tmstmp = Test.timeline.get(i).get(1) + " " + date24Format.format(date12Format.parse(time));
                        indexList.add(tmstmp);
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }
                    indexList.add(Test.timeline.get(i).get(3));
                    indexList.add(Test.timeline.get(i).get(4));
                    timelineList.add(indexList);
                }
            }
            initView();
        }
    });
    calendarView.setDateSelected(CalendarDay.today(), true);
    int curDate = CalendarDay.today().getDay();
    int months = CalendarDay.today().getMonth() + 1;
    String mon = "", dat = "";
    if (months < 10)
        mon = "0" + String.valueOf(months);
    else
        mon = String.valueOf(months);
    if (curDate < 10)
        dat = "0" + String.valueOf(curDate);
    else
        dat = String.valueOf(curDate);
    String search = CalendarDay.today().getYear() + "-" + mon + "-" + dat;
    // toolbar.setTitle(search);
    for (int i = 0; i < Test.timeline.size(); i++) {
        if (search.equals(Test.timeline.get(i).get(1))) {
            ArrayList<String> indexList = new ArrayList<String>();
            indexList.add(Test.timeline.get(i).get(0));
            String time = Test.timeline.get(i).get(2);
            SimpleDateFormat date12Format = new SimpleDateFormat("hh:mm a");
            SimpleDateFormat date24Format = new SimpleDateFormat("HH:mm");
            try {
                indexList.add(Test.timeline.get(i).get(1) + " " + date24Format.format(date12Format.parse(time)));
            } catch (ParseException e) {
                e.printStackTrace();
            }
            indexList.add(Test.timeline.get(i).get(3));
            indexList.add(Test.timeline.get(i).get(4));
            timelineList.add(indexList);
        }
    }
    initView();
}
Also used : Window(android.view.Window) ArrayList(java.util.ArrayList) MaterialCalendarView(com.prolificinteractive.materialcalendarview.MaterialCalendarView) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) SuppressLint(android.annotation.SuppressLint) OnDateSelectedListener(com.prolificinteractive.materialcalendarview.OnDateSelectedListener) ParseException(java.text.ParseException) CalendarDay(com.prolificinteractive.materialcalendarview.CalendarDay) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

CalendarDay (com.prolificinteractive.materialcalendarview.CalendarDay)6 MaterialCalendarView (com.prolificinteractive.materialcalendarview.MaterialCalendarView)3 OnDateSelectedListener (com.prolificinteractive.materialcalendarview.OnDateSelectedListener)3 ArrayList (java.util.ArrayList)2 SuppressLint (android.annotation.SuppressLint)1 ActivityOptions (android.app.ActivityOptions)1 Intent (android.content.Intent)1 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)1 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 Window (android.view.Window)1 BindView (butterknife.BindView)1 DailyBeforeListBean (com.codeest.geeknews.model.bean.DailyBeforeListBean)1 DailyListBean (com.codeest.geeknews.model.bean.DailyListBean)1 ZhihuDetailActivity (com.codeest.geeknews.ui.zhihu.activity.ZhihuDetailActivity)1 DailyAdapter (com.codeest.geeknews.ui.zhihu.adapter.DailyAdapter)1 BroadDecorator (com.pangpangzhu.p2papp.test.calendardecorators.BroadDecorator)1 DefaultDecorator (com.pangpangzhu.p2papp.test.calendardecorators.DefaultDecorator)1