/*********************************************************************************** * The MIT License (MIT) * Copyright (c) 2014 Robin Chutaux * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. ***********************************************************************************/ package com.marshalchen.common.uimodule.calendarlistview; import android.content.Context; import android.content.res.TypedArray; import android.util.AttributeSet; import android.widget.AbsListView; import android.widget.ListView; import com.marshalchen.common.uimodule.R; public class DayPickerView extends ListView implements AbsListView.OnScrollListener { protected Context mContext; protected SimpleMonthAdapter mAdapter; private DatePickerController mController; protected int mCurrentScrollState = 0; private boolean mPerformingScroll; protected long mPreviousScrollPosition; protected int mPreviousScrollState = 0; final TypedArray typedArray; private final AttributeSet attrs; public DayPickerView(Context context) { this(context, null); } public DayPickerView(Context context, AttributeSet attrs) { this(context, attrs, 0); } public DayPickerView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); this.attrs = attrs; typedArray = context.obtainStyledAttributes(attrs, R.styleable.DayPickerView); setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); setDrawSelectorOnTop(false); init(context); } public void setmController(DatePickerController mController) { this.mController = mController; setUpAdapter(); setAdapter(mAdapter); } public void init(Context paramContext) { mContext = paramContext; setUpListView(); } protected void layoutChildren() { super.layoutChildren(); if (mPerformingScroll) { mPerformingScroll = false; } } public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { SimpleMonthView child = (SimpleMonthView) view.getChildAt(0); if (child == null) { return; } long currScroll = view.getFirstVisiblePosition() * child.getHeight() - child.getBottom(); mPreviousScrollPosition = currScroll; mPreviousScrollState = mCurrentScrollState; } public void onScrollStateChanged(AbsListView absListView, int scroll) { } protected void setUpAdapter() { if (mAdapter == null) { mAdapter = new SimpleMonthAdapter(getContext(), mController, typedArray); } mAdapter.notifyDataSetChanged(); } protected void setUpListView() { setCacheColorHint(0); setDivider(null); setItemsCanFocus(true); setFastScrollEnabled(false); setVerticalScrollBarEnabled(false); setOnScrollListener(this); setFadingEdgeLength(0); } public SimpleMonthAdapter.SelectedDays<SimpleMonthAdapter.CalendarDay> getSelectedDays() { return mAdapter.getSelectedDays(); } }