Merged PR 204597: Renamed DatePickerView and associated classes, files and references to use CalendarView

- renamed DatePickerView and associated files, classes and references to use CalendarView
- removed lifecycle dependency from gradle file

Related work items: #648067
This commit is contained in:
William Do 2018-11-21 00:41:31 +00:00
Родитель 27b5c71d7e
Коммит db6ca1fb6c
27 изменённых файлов: 160 добавлений и 154 удалений

Просмотреть файл

@ -6,13 +6,13 @@ import android.support.v4.app.Fragment
import android.support.v7.app.AppCompatActivity
import android.view.MenuItem
import com.jakewharton.threetenabp.AndroidThreeTen
import com.microsoft.officeuifabric.datepicker.DateTimePickerListener
import com.microsoft.officeuifabric.core.DateTimeSelectionListener
import com.microsoft.officeuifabricdemo.demos.DateTimePickerDialogFragment
import kotlinx.android.synthetic.main.activity_demo_detail.*
import org.threeten.bp.ZonedDateTime
import java.util.*
class DemoActivity : AppCompatActivity(), DateTimePickerListener {
class DemoActivity : AppCompatActivity(), DateTimeSelectionListener {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
AndroidThreeTen.init(this)

Просмотреть файл

@ -7,7 +7,7 @@ import kotlin.reflect.KClass
const val AVATAR = "Avatar"
const val BUTTON = "Button"
const val DATE_PICKER = "DatePicker"
const val CALENDAR_VIEW = "CalendarView"
const val DATE_TIME_PICKER_DIALOG = "DateTimePickerDialog"
const val PERSONA = "Persona"
const val PERSONA_CHIP = "PersonaChip"
@ -18,7 +18,7 @@ const val TYPOGRAPHY = "Typography"
val DEMOS = arrayListOf(
Demo(AVATAR, AvatarFragment::class),
Demo(BUTTON, ButtonFragment::class),
Demo(DATE_PICKER, DatePickerFragment::class),
Demo(CALENDAR_VIEW, CalendarViewFragment::class),
Demo(DATE_TIME_PICKER_DIALOG, DateTimePickerDialogFragment::class),
Demo(PERSONA, PersonaFragment::class),
Demo(PERSONA_CHIP, PersonaChipFragment::class),

Просмотреть файл

@ -8,18 +8,18 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.microsoft.officeuifabric.datepicker.DateTimePickerListener
import com.microsoft.officeuifabric.core.DateTimeSelectionListener
import com.microsoft.officeuifabric.util.DateStringUtils
import com.microsoft.officeuifabricdemo.DemoFragment
import com.microsoft.officeuifabricdemo.R
import kotlinx.android.synthetic.main.fragment_date_picker.view.*
import kotlinx.android.synthetic.main.fragment_calendar.view.*
import org.threeten.bp.ZonedDateTime
class DatePickerFragment : DemoFragment() {
class CalendarViewFragment : DemoFragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view = inflater.inflate(R.layout.fragment_date_picker, container, false)
val view = inflater.inflate(R.layout.fragment_calendar, container, false)
val context = context ?: return view
view.date_picker_view.listener = object : DateTimePickerListener {
view.calendar_view.listener = object : DateTimeSelectionListener {
override fun onDateSelected(date: ZonedDateTime) {
view.example_date_title.text = DateStringUtils.formatDateWithWeekDay(context, date)
}

Просмотреть файл

@ -8,12 +8,12 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.microsoft.officeuifabric.datepicker.DatePickerDialog
import com.microsoft.officeuifabric.datepicker.DateTimePickerDialog
import com.microsoft.officeuifabric.datetimepicker.DatePickerDialog
import com.microsoft.officeuifabric.datetimepicker.DateTimePickerDialog
import com.microsoft.officeuifabric.util.DateStringUtils
import com.microsoft.officeuifabricdemo.DemoFragment
import com.microsoft.officeuifabricdemo.R
import kotlinx.android.synthetic.main.fragment_date_picker_dialog.*
import kotlinx.android.synthetic.main.fragment_date_time_picker_dialog.*
import org.threeten.bp.Duration
import org.threeten.bp.ZonedDateTime
@ -30,7 +30,7 @@ class DateTimePickerDialogFragment : DemoFragment() {
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.fragment_date_picker_dialog, container, false)
return inflater.inflate(R.layout.fragment_date_time_picker_dialog, container, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
@ -39,7 +39,7 @@ class DateTimePickerDialogFragment : DemoFragment() {
if (savedInstanceState != null)
date = savedInstanceState.getSerializable(SAVE_DATE) as ZonedDateTime
date_picker_button.setOnClickListener {
date_time_picker_button.setOnClickListener {
val dialog = DateTimePickerDialog.newInstance(
date,
Duration.ZERO,

Просмотреть файл

@ -10,14 +10,14 @@
android:layout_height="wrap_content"
android:paddingTop="@dimen/default_layout_margin"
android:paddingBottom="@dimen/default_layout_margin"
android:textSize="@dimen/date_picker_date_title_text_size"
android:text="@string/date_picker_example_chosen_date"
android:textColor="@color/date_picker_chosen_date_text"
android:textSize="@dimen/calendar_date_title_text_size"
android:text="@string/calendar_example_chosen_date"
android:textColor="@color/calendar_selected_date_text"
android:textAlignment="center"
android:background="@color/date_picker_chosen_date_background"/>
android:background="@color/calendar_selected_date_background"/>
<com.microsoft.officeuifabric.datepicker.DatePickerView
android:id="@+id/date_picker_view"
<com.microsoft.officeuifabric.calendar.CalendarView
android:id="@+id/calendar_view"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>

Просмотреть файл

@ -17,7 +17,7 @@
android:text="@string/date_time_picker_dialog_date_picked_default" />
<Button
android:id="@+id/date_picker_button"
android:id="@+id/date_time_picker_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="@dimen/default_layout_margin"

Просмотреть файл

@ -3,6 +3,6 @@
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
<color name="date_picker_chosen_date_text">#E1E1E1</color>
<color name="date_picker_chosen_date_background">#333</color>
<color name="calendar_selected_date_text">#E1E1E1</color>
<color name="calendar_selected_date_background">#333</color>
</resources>

Просмотреть файл

@ -6,5 +6,5 @@
<dimen name="button_width">287dp</dimen>
<dimen name="cell_horizontal_spacing">8dp</dimen>
<dimen name="cell_vertical_spacing">2dp</dimen>
<dimen name="date_picker_date_title_text_size">18sp</dimen>
<dimen name="calendar_date_title_text_size">18sp</dimen>
</resources>

Просмотреть файл

@ -72,7 +72,7 @@
<string name="caption">Caption</string>
<!--DatePicker-->
<string name="date_picker_example_chosen_date">Choose a date</string>
<string name="calendar_example_chosen_date">Choose a date</string>
<!--DateTimePickerDialog-->
<string name="date_time_picker_dialog_button">Show date picker</string>

Просмотреть файл

@ -2,7 +2,7 @@
* Copyright © 2018 Microsoft Corporation. All rights reserved.
*/
package com.microsoft.officeuifabric.datepicker
package com.microsoft.officeuifabric.calendar
import android.content.Context
import android.graphics.drawable.Drawable
@ -15,7 +15,8 @@ import android.support.v7.widget.RecyclerView
import android.view.View
import android.view.ViewGroup
import com.microsoft.officeuifabric.R
import com.microsoft.officeuifabric.datepicker.DatePickerDaySelectionDrawable.Mode
import com.microsoft.officeuifabric.calendar.CalendarDaySelectionDrawable.Mode
import com.microsoft.officeuifabric.core.DateTimeSelectionListener
import com.microsoft.officeuifabric.managers.PreferencesManager
import com.microsoft.officeuifabric.util.DateTimeUtils
import org.threeten.bp.*
@ -23,9 +24,9 @@ import org.threeten.bp.temporal.ChronoUnit
import java.util.concurrent.TimeUnit
/**
* [DatePickerAdapter] is the adapter for the DatePicker
* [CalendarAdapter] is the adapter for the [CalendarView]
*/
class DatePickerAdapter : RecyclerView.Adapter<DatePickerAdapter.DatePickerDayViewHolder>, View.OnClickListener {
class CalendarAdapter : RecyclerView.Adapter<CalendarAdapter.CalendarDayViewHolder>, View.OnClickListener {
companion object {
private const val MONTH_BACK = 3L
private const val MONTH_AHEAD = 12L
@ -59,27 +60,27 @@ class DatePickerAdapter : RecyclerView.Adapter<DatePickerAdapter.DatePickerDayVi
private var firstDayOfWeek: DayOfWeek? = null
private var dayCount: Int
private val context: Context
private val config: DatePickerView.Config
private val listener: DateTimePickerListener
private val config: CalendarView.Config
private val listener: DateTimeSelectionListener
private var selectedDuration: Duration? = null
private val selectionDrawableCircle: DatePickerDaySelectionDrawable
private val selectionDrawableStart: DatePickerDaySelectionDrawable
private val selectionDrawableMiddle: DatePickerDaySelectionDrawable
private val selectionDrawableEnd: DatePickerDaySelectionDrawable
private val selectionDrawableCircle: CalendarDaySelectionDrawable
private val selectionDrawableStart: CalendarDaySelectionDrawable
private val selectionDrawableMiddle: CalendarDaySelectionDrawable
private val selectionDrawableEnd: CalendarDaySelectionDrawable
private val dayViewAccessibilityDelegate = DayViewAccessibilityDelegate()
constructor(context: Context, config: DatePickerView.Config, listener: DateTimePickerListener) {
constructor(context: Context, config: CalendarView.Config, listener: DateTimeSelectionListener) {
this.context = context
this.config = config
this.listener = listener
selectionDrawableCircle = DatePickerDaySelectionDrawable(this.context, Mode.SINGLE)
selectionDrawableStart = DatePickerDaySelectionDrawable(this.context, Mode.START)
selectionDrawableMiddle = DatePickerDaySelectionDrawable(this.context, Mode.MIDDLE)
selectionDrawableEnd = DatePickerDaySelectionDrawable(this.context, Mode.END)
selectionDrawableCircle = CalendarDaySelectionDrawable(this.context, Mode.SINGLE)
selectionDrawableStart = CalendarDaySelectionDrawable(this.context, Mode.START)
selectionDrawableMiddle = CalendarDaySelectionDrawable(this.context, Mode.MIDDLE)
selectionDrawableEnd = CalendarDaySelectionDrawable(this.context, Mode.END)
updateDayIndicesAndHeading()
@ -123,15 +124,15 @@ class DatePickerAdapter : RecyclerView.Adapter<DatePickerAdapter.DatePickerDayVi
}
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): DatePickerDayViewHolder {
val dayView = DatePickerDayView(parent.context, config)
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CalendarDayViewHolder {
val dayView = CalendarDayView(parent.context, config)
dayView.layoutParams = ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)
dayView.setOnClickListener(this)
ViewCompat.setAccessibilityDelegate(dayView, dayViewAccessibilityDelegate)
return DatePickerDayViewHolder(dayView)
return CalendarDayViewHolder(dayView)
}
override fun onBindViewHolder(holder: DatePickerDayViewHolder, position: Int) {
override fun onBindViewHolder(holder: CalendarDayViewHolder, position: Int) {
val date = minDate.plusDays(position.toLong())
holder.date = date
@ -152,7 +153,7 @@ class DatePickerAdapter : RecyclerView.Adapter<DatePickerAdapter.DatePickerDayVi
override fun getItemCount() = dayCount
override fun onClick(v: View) {
listener.onDateSelected((v as DatePickerDayView).date.getLocalDateToZonedDateTime)
listener.onDateSelected((v as CalendarDayView).date.getLocalDateToZonedDateTime)
}
private fun updateDayIndicesAndHeading() {
@ -173,31 +174,31 @@ class DatePickerAdapter : RecyclerView.Adapter<DatePickerAdapter.DatePickerDayVi
}
/**
* ViewHolder for the [DatePickerDayView]
* ViewHolder for the [CalendarDayView]
*/
inner class DatePickerDayViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
inner class CalendarDayViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
/**
* Sets and gets the selected date in the [DatePickerDayView]
* Sets and gets the selected date in the [CalendarDayView]
*/
var date: LocalDate
get() = datePickerDayView.date
set(value) { datePickerDayView.date = value }
get() = calendarDayView.date
set(value) { calendarDayView.date = value }
/**
* Sets and gets the selected Drawable in the [DatePickerDayView]
* Sets and gets the selected Drawable in the [CalendarDayView]
*/
var selectedDrawable: Drawable?
get() = datePickerDayView.selectedDrawable
set(value) { datePickerDayView.selectedDrawable = value }
get() = calendarDayView.selectedDrawable
set(value) { calendarDayView.selectedDrawable = value }
/**
* Sets and gets the selected state of the [DatePickerDayView]
* Sets and gets the selected state of the [CalendarDayView]
*/
var isSelected: Boolean
get() = datePickerDayView.isChecked
set(value) { datePickerDayView.isChecked = value }
get() = calendarDayView.isChecked
set(value) { calendarDayView.isChecked = value }
private val datePickerDayView = itemView as DatePickerDayView
private val calendarDayView = itemView as CalendarDayView
}
private inner class DayViewAccessibilityDelegate : AccessibilityDelegateCompat() {

Просмотреть файл

@ -2,7 +2,7 @@
* Copyright © 2018 Microsoft Corporation. All rights reserved.
* */
package com.microsoft.officeuifabric.datepicker
package com.microsoft.officeuifabric.calendar
import android.content.Context
import android.graphics.Canvas
@ -15,9 +15,9 @@ import android.support.v4.content.ContextCompat
import com.microsoft.officeuifabric.R
/**
* [DatePickerDaySelectionDrawable] is a drawable added to a [DatePickerDayView] displaying selected state
* [CalendarDaySelectionDrawable] is a drawable added to a [CalendarDayView] displaying selected state
*/
class DatePickerDaySelectionDrawable : Drawable {
class CalendarDaySelectionDrawable : Drawable {
enum class Mode {
SINGLE, START, END, MIDDLE
}
@ -31,7 +31,7 @@ class DatePickerDaySelectionDrawable : Drawable {
this.context = context
this.mode = mode
paint.color = ContextCompat.getColor(context, R.color.uifabric_primary)
circleSize = context.resources.getDimensionPixelSize(R.dimen.uifabric_date_picker_view_day_selection_size)
circleSize = context.resources.getDimensionPixelSize(R.dimen.uifabric_calendar_day_selection_size)
}
override fun draw(canvas: Canvas) {

Просмотреть файл

@ -2,7 +2,7 @@
* Copyright © 2018 Microsoft Corporation. All rights reserved.
*/
package com.microsoft.officeuifabric.datepicker
package com.microsoft.officeuifabric.calendar
import android.annotation.TargetApi
import android.content.Context
@ -35,9 +35,9 @@ import org.threeten.bp.temporal.ChronoUnit
import java.util.*
/**
* [DatePickerDayView] View that displays a day of the week
* [CalendarDayView] View that displays a day of the week
*/
class DatePickerDayView: AppCompatButton, Checkable {
class CalendarDayView: AppCompatButton, Checkable {
companion object {
private val MONTH = DateTimeFormatter.ofPattern("MMM")
private val CHECKED_STATE_SET = intArrayOf(android.R.attr.state_checked)
@ -91,7 +91,7 @@ class DatePickerDayView: AppCompatButton, Checkable {
ViewCompat.postInvalidateOnAnimation(this)
}
private lateinit var config: DatePickerView.Config
private lateinit var config: CalendarView.Config
private var paint = Paint()
@ -110,14 +110,14 @@ class DatePickerDayView: AppCompatButton, Checkable {
/**
* @param [context] Context
* @param [datePickerConfig] Config passes DatePickerView attributes
* @constructor creates an instance of a DatePickerDayView
* @param [calendarConfig] Config passes CalendarView attributes
* @constructor creates an instance of a CalendarDayView
*/
constructor(context: Context, datePickerConfig: DatePickerView.Config) : super(context) {
config = datePickerConfig
constructor(context: Context, calendarConfig: CalendarView.Config) : super(context) {
config = calendarConfig
setWillNotDraw(false)
todayBackgroundDrawable = ContextCompat.getDrawable(context, R.drawable.date_picker_view_background_today)
todayBackgroundDrawable = ContextCompat.getDrawable(context, R.drawable.calendar_background_today)
paint.isAntiAlias = true

Просмотреть файл

@ -2,7 +2,7 @@
* Copyright © 2018 Microsoft Corporation. All rights reserved.
*/
package com.microsoft.officeuifabric.datepicker
package com.microsoft.officeuifabric.calendar
import android.animation.Animator
import android.animation.AnimatorListenerAdapter
@ -18,17 +18,18 @@ import android.widget.LinearLayout
import com.jakewharton.threetenabp.AndroidThreeTen
import com.microsoft.officeuifabric.R
import com.microsoft.officeuifabric.core.DateTimeSelectionListener
import org.threeten.bp.*
// TODO: Convert to TemplateView along with other things that extend LinearLayout
// TODO: implement ability to add icon to DatePickerDayView
// TODO: implement ability to change background color of DatePickerDayView cell
// TODO: implement ability to add icon to CalendarDayView
// TODO: implement ability to change background color of CalendarDayView cell
/**
* [DatePickerView] is a custom LinearLayout that groups together views used to display
* [CalendarView] is a custom LinearLayout that groups together views used to display
* calendar dates and allows a user to select a date
*/
class DatePickerView : LinearLayout, DateTimePickerListener {
class CalendarView : LinearLayout, DateTimeSelectionListener {
companion object {
const val DAYS_IN_WEEK = 7
private const val VIEW_MODE_CHANGE_ANIMATION_DURATION = 300L
@ -50,7 +51,7 @@ class DatePickerView : LinearLayout, DateTimePickerListener {
/**
* Callback implementation for date picking listener
*/
var listener: DateTimePickerListener? = null
var listener: DateTimeSelectionListener? = null
/**
* Integer returning the calendar width for tablet
@ -110,7 +111,7 @@ class DatePickerView : LinearLayout, DateTimePickerListener {
constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : super(context, attrs, defStyleAttr) {
AndroidThreeTen.init(context)
dividerHeight = Math.round(resources.getDimension(R.dimen.uifabric_divider_height))
calendarViewWidthForTablet = Math.round(resources.getDimension(R.dimen.uifabric_date_picker_view_weeks_max_width))
calendarViewWidthForTablet = Math.round(resources.getDimension(R.dimen.uifabric_calendar_weeks_max_width))
config = Config()
@ -123,7 +124,7 @@ class DatePickerView : LinearLayout, DateTimePickerListener {
}
/**
* Sets the [DisplayMode] with a flag to animate the resize of the [DatePickerView]
* Sets the [DisplayMode] with a flag to animate the resize of the [CalendarView]
*/
fun setDisplayMode(mode: DisplayMode, animateResize: Boolean) {
if (mode == displayMode)
@ -240,28 +241,28 @@ class DatePickerView : LinearLayout, DateTimePickerListener {
*/
inner class Config {
var weekHeadingBackgroundColor = Color.WHITE
var weekdayHeadingTextColor = ContextCompat.getColor(context, R.color.uifabric_date_picker_week_heading_week_day_text)
var weekendHeadingTextColor = ContextCompat.getColor(context, R.color.uifabric_date_picker_week_heading_weekend_text)
var weekHeadingHeight = context.resources.getDimensionPixelSize(R.dimen.uifabric_date_picker_view_week_heading_height)
var weekHeadingTextSize = context.resources.getDimensionPixelSize(R.dimen.uifabric_date_picker_view_week_heading_text_size)
var weekdayHeadingTextColor = ContextCompat.getColor(context, R.color.uifabric_calendar_week_heading_week_day_text)
var weekendHeadingTextColor = ContextCompat.getColor(context, R.color.uifabric_calendar_week_heading_weekend_text)
var weekHeadingHeight = context.resources.getDimensionPixelSize(R.dimen.uifabric_calendar_week_heading_height)
var weekHeadingTextSize = context.resources.getDimensionPixelSize(R.dimen.uifabric_calendar_week_heading_text_size)
var showWeekHeadingDivider = false
var selectionAccentColor = ContextCompat.getColor(context, R.color.uifabric_primary)
var isFullMode = true
var monthOverlayBackgroundColor = ContextCompat.getColor(context, R.color.uifabric_date_picker_month_overlay_background)
var monthOverlayTextSize = context.resources.getDimensionPixelSize(R.dimen.uifabric_date_picker_view_month_overlay_text_size)
var monthOverlayBackgroundColor = ContextCompat.getColor(context, R.color.uifabric_calendar_month_overlay_background)
var monthOverlayTextSize = context.resources.getDimensionPixelSize(R.dimen.uifabric_calendar_month_overlay_text_size)
var monthOverlayTextColor = ContextCompat.getColor(context, R.color.uifabric_primary)
var differentiateOddEvenMonth = true
var isTodayHighlighted = true
var otherMonthBackgroundColor = ContextCompat.getColor(context, R.color.uifabric_date_picker_other_month_background)
var calendarDayMonthYearTextSize = context.resources.getDimensionPixelSize(R.dimen.uifabric_date_picker_view_month_year_font_size)
var otherMonthBackgroundColor = ContextCompat.getColor(context, R.color.uifabric_calendar_other_month_background)
var calendarDayMonthYearTextSize = context.resources.getDimensionPixelSize(R.dimen.uifabric_calendar_month_year_font_size)
var calendarDayWeekdayTextColorId = R.color.uifabric_date_picker_view_week_day_text
var calendarDayWeekendTextColorId = R.color.uifabric_date_picker_view_week_day_text
var calendarDayFirstDayOfMonthTextColorId = R.color.uifabric_date_picker_view_week_day_text
var calendarDayMonochromeTextColorId = R.color.uifabric_date_picker_view_monochrome_text
var calendarDayWeekdayTextColorId = R.color.uifabric_calendar_week_day_text
var calendarDayWeekendTextColorId = R.color.uifabric_calendar_week_day_text
var calendarDayFirstDayOfMonthTextColorId = R.color.uifabric_calendar_week_day_text
var calendarDayMonochromeTextColorId = R.color.uifabric_calendar_monochrome_text
}
}

Просмотреть файл

@ -2,7 +2,7 @@
* Copyright © 2018 Microsoft Corporation. All rights reserved.
*/
package com.microsoft.officeuifabric.datepicker
package com.microsoft.officeuifabric.calendar
import android.content.Context
import android.support.v4.view.ViewCompat
@ -18,14 +18,14 @@ import com.microsoft.officeuifabric.managers.PreferencesManager
import org.threeten.bp.DayOfWeek
/**
* [WeekHeadingView] is a LinearLayout holding the DatePicker header with views for
* [WeekHeadingView] is a LinearLayout holding the [CalendarView] header with views for
* the week day letters, S, M, T, W, T, F, S
*/
class WeekHeadingView : LinearLayout {
private lateinit var config: DatePickerView.Config
private lateinit var config: CalendarView.Config
constructor(context: Context, datePickerConfig: DatePickerView.Config) : super(context) {
config = datePickerConfig
constructor(context: Context, calendarConfig: CalendarView.Config) : super(context) {
config = calendarConfig
setBackgroundColor(config.weekHeadingBackgroundColor)
var dayOfWeek = PreferencesManager.getWeekStart(context)
@ -36,7 +36,7 @@ class WeekHeadingView : LinearLayout {
val weekendHeadingColor = config.weekendHeadingTextColor
val strDayOfWeek = resources.getStringArray(R.array.weekday_initial)
for (i in 1..DatePickerView.DAYS_IN_WEEK) {
for (i in 1..CalendarView.DAYS_IN_WEEK) {
val textView = TextView(context)
TextViewCompat.setTextAppearance(textView, headingTextAppearance)
textView.text = strDayOfWeek[dayOfWeek.value - 1]

Просмотреть файл

@ -2,7 +2,7 @@
* Copyright © 2018 Microsoft Corporation. All rights reserved.
*/
package com.microsoft.officeuifabric.datepicker
package com.microsoft.officeuifabric.calendar
import android.animation.Animator
import android.animation.AnimatorListenerAdapter
@ -24,6 +24,7 @@ import android.text.format.DateUtils.FORMAT_NO_MONTH_DAY
import android.text.format.DateUtils.FORMAT_SHOW_DATE
import android.util.AttributeSet
import com.microsoft.officeuifabric.R
import com.microsoft.officeuifabric.core.DateTimeSelectionListener
import com.microsoft.officeuifabric.util.ColorProperty
import com.microsoft.officeuifabric.util.DateTimeUtils
import com.microsoft.officeuifabric.view.MSRecyclerView
@ -70,9 +71,9 @@ class WeeksView : MSRecyclerView {
val firstVisibleItemPosition: Int
get() = (layoutManager as GridLayoutManager).findFirstVisibleItemPosition()
private lateinit var config: DatePickerView.Config
private lateinit var config: CalendarView.Config
private lateinit var pickerAdapter: DatePickerAdapter
private lateinit var pickerAdapter: CalendarAdapter
private var overlayDisplayState = OverlayState.HIDDEN
private val overlayTransitionAnimator = AnimatorSet()
@ -93,10 +94,10 @@ class WeeksView : MSRecyclerView {
private lateinit var overlayBackgroundColorProperty: ColorProperty
private lateinit var overlayFontColorProperty: ColorProperty
private lateinit var listener: DateTimePickerListener
private lateinit var listener: DateTimeSelectionListener
private lateinit var paint: TextPaint
constructor(context: Context, config: DatePickerView.Config, listener: DateTimePickerListener) : super(context) {
constructor(context: Context, config: CalendarView.Config, listener: DateTimeSelectionListener) : super(context) {
this.config = config
this.listener = listener
setWillNotDraw(false)
@ -107,7 +108,7 @@ class WeeksView : MSRecyclerView {
addItemDecoration(divider)
}
pickerAdapter = DatePickerAdapter(context, config, this.listener)
pickerAdapter = CalendarAdapter(context, config, this.listener)
adapter = pickerAdapter
setHasFixedSize(true)
@ -130,14 +131,14 @@ class WeeksView : MSRecyclerView {
@JvmOverloads
constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : super(context, attrs, defStyleAttr)
fun ensureDateVisible(date: LocalDate?, displayMode: DatePickerView.DisplayMode, rowHeight: Int, dividerHeight: Int) {
fun ensureDateVisible(date: LocalDate?, displayMode: CalendarView.DisplayMode, rowHeight: Int, dividerHeight: Int) {
val date = date ?: return
smoothScrollBy(0, 0)
val datePosition = ChronoUnit.DAYS.between(minDate, date).toInt()
val visibleRows = displayMode.visibleRows
val firstVisiblePosition = firstVisibleItemPosition
val lastVisiblePosition = firstVisiblePosition + DatePickerView.DAYS_IN_WEEK * visibleRows
val lastVisiblePosition = firstVisiblePosition + CalendarView.DAYS_IN_WEEK * visibleRows
if (RecyclerView.NO_POSITION == firstVisiblePosition || datePosition < firstVisiblePosition || DateTimeUtils.isSameDay(date, ZonedDateTime.now())) {
scrollToPositionWithOffset(datePosition, 0)
@ -201,8 +202,8 @@ class WeeksView : MSRecyclerView {
val now = ZonedDateTime.now().truncatedTo(ChronoUnit.DAYS)
val monthDescriptors = ArrayList<MonthDescriptor>(MONTH_DESCRIPTORS_CAPACITY)
for (i in 0 until childCount step DAYS_IN_WEEK) {
val datePickerDayView = getChildAt(i) as DatePickerDayView
val date = datePickerDayView.date
val calendarDayView = getChildAt(i) as CalendarDayView
val date = calendarDayView.date
val month = date.month
if (previousMonth == month)
continue

Просмотреть файл

@ -2,14 +2,14 @@
* Copyright © 2018 Microsoft Corporation. All rights reserved.
*/
package com.microsoft.officeuifabric.datepicker
package com.microsoft.officeuifabric.core
import org.threeten.bp.ZonedDateTime
/**
* [DateTimePickerListener] is an interface for Date and Time picker callbacks
* [DateTimeSelectionListener] is an interface for Date and Time picker callbacks
*/
interface DateTimePickerListener {
interface DateTimeSelectionListener {
/**
* Method called when a user selects a date
* @param [date] the selected date
@ -20,7 +20,7 @@ interface DateTimePickerListener {
/**
* Method called when a user picks a date. This would be used in a scenario where
* date picking is completed and the DatePicker is dismissed
* date picking is completed and the DatePickerDialog is dismissed
* @param [date] the picked date
*/
fun onDatePicked(date: ZonedDateTime) {

Просмотреть файл

@ -2,7 +2,7 @@
* Copyright © 2018 Microsoft Corporation. All rights reserved.
*/
package com.microsoft.officeuifabric.datepicker
package com.microsoft.officeuifabric.datetimepicker
import android.app.Dialog
import android.os.Build
@ -14,6 +14,8 @@ import android.view.ViewGroup
import android.view.WindowManager
import com.microsoft.officeuifabric.R
import com.microsoft.officeuifabric.calendar.CalendarView
import com.microsoft.officeuifabric.core.DateTimeSelectionListener
import com.microsoft.officeuifabric.util.DateStringUtils
import com.microsoft.officeuifabric.view.PositionableDialog
import kotlinx.android.synthetic.main.dialog_day_picker.*
@ -22,10 +24,10 @@ import org.threeten.bp.Duration
import org.threeten.bp.ZonedDateTime
/**
* [DatePickerDialog] houses a [DatePickerView] instances within a positionable dialog as well as
* [DatePickerDialog] houses a [CalendarView] instances within a positionable dialog as well as
* configures aspects of the view
*/
class DatePickerDialog : PositionableDialog(), DateTimePickerListener {
class DatePickerDialog : PositionableDialog(), DateTimeSelectionListener {
companion object {
private const val ELEVATION = 0f
@ -71,21 +73,21 @@ class DatePickerDialog : PositionableDialog(), DateTimePickerListener {
}
val fullModeHeight: Int
get() = date_picker_view.fullModeHeight
get() = calendar_view.fullModeHeight
fun setTimeSlot(startTime: ZonedDateTime, duration: Duration) {
displayDate = startTime
val endTime = startTime.plus(duration).with(startTime.toLocalTime())
this.duration = Duration.between(startTime, endTime)
date_picker_view.setSelectedDateRange(displayDate.toLocalDate(), this.duration, pickMode == PickMode.RANGE_END)
calendar_view.setSelectedDateRange(displayDate.toLocalDate(), this.duration, pickMode == PickMode.RANGE_END)
}
fun expandCalendarView() {
date_picker_view.displayMode = DatePickerView.DisplayMode.LENGTHY_MODE
calendar_view.displayMode = CalendarView.DisplayMode.LENGTHY_MODE
}
fun collapseCalendarView() {
date_picker_view.leaveLengthyMode()
calendar_view.leaveLengthyMode()
}
override fun onCreate(savedInstanceState: Bundle?) {
@ -104,8 +106,8 @@ class DatePickerDialog : PositionableDialog(), DateTimePickerListener {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
date_picker_view.setSelectedDateRange(displayDate.toLocalDate(), duration, pickMode == PickMode.SINGLE)
date_picker_view.listener = this
calendar_view.setSelectedDateRange(displayDate.toLocalDate(), duration, pickMode == PickMode.SINGLE)
calendar_view.listener = this
val arguments = arguments ?: return
if (arguments.getBoolean(DateTimePickerExtras.SHOW_TITLEBAR)) {
@ -156,7 +158,7 @@ class DatePickerDialog : PositionableDialog(), DateTimePickerListener {
}
}
(parentFragment as? DateTimePickerListener)?.onDateSelected(date)
(parentFragment as? DateTimeSelectionListener)?.onDateSelected(date)
if (title.visibility == View.VISIBLE)
context?.let { title.text = DateStringUtils.formatDateAbbrevAll(it, displayDate) }

Просмотреть файл

@ -2,7 +2,7 @@
* Copyright © 2018 Microsoft Corporation. All rights reserved.
*/
package com.microsoft.officeuifabric.datepicker
package com.microsoft.officeuifabric.datetimepicker
import android.animation.Animator
import android.animation.AnimatorListenerAdapter
@ -19,6 +19,7 @@ import android.view.View
import android.view.ViewGroup
import com.microsoft.officeuifabric.R
import com.microsoft.officeuifabric.core.DateTimeSelectionListener
import com.microsoft.officeuifabric.util.DateStringUtils
import com.microsoft.officeuifabric.view.ResizableDialog
import kotlinx.android.synthetic.main.dialog_date_time_picker.*
@ -30,7 +31,7 @@ import org.threeten.bp.ZonedDateTime
* [DateTimePickerDialog] provides a dialog view housing both a [DatePickerDialog] and Time Picker in a [ViewPager]
* as well as includes toolbar UI and menu buttons to dismiss the dialog and accept a date/ time
*/
class DateTimePickerDialog : ResizableDialog(), Toolbar.OnMenuItemClickListener, DateTimePickerListener {
class DateTimePickerDialog : ResizableDialog(), Toolbar.OnMenuItemClickListener, DateTimeSelectionListener {
companion object {
@JvmStatic
fun newInstance(
@ -57,7 +58,7 @@ class DateTimePickerDialog : ResizableDialog(), Toolbar.OnMenuItemClickListener,
NORMAL_TIME(true, true, true, 0, 1, 1)
}
var listener: DateTimePickerListener? = null
var listener: DateTimeSelectionListener? = null
private lateinit var displayDate: ZonedDateTime
private lateinit var duration: Duration
@ -187,7 +188,7 @@ class DateTimePickerDialog : ResizableDialog(), Toolbar.OnMenuItemClickListener,
private fun callDateListener() {
// Routing communication through Activities rather than Fragment to Fragment is preferred in Android
(activity as? DateTimePickerListener)?.onDatePicked(displayDate)
(activity as? DateTimeSelectionListener)?.onDatePicked(displayDate)
listener?.onDatePicked(displayDate)
}

Просмотреть файл

@ -1,4 +1,4 @@
package com.microsoft.officeuifabric.datepicker
package com.microsoft.officeuifabric.datetimepicker
object DateTimePickerExtras {
const val MODE = "MODE"

Просмотреть файл

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/uifabric_date_picker_day_today_background"/>
<solid android:color="@color/uifabric_calendar_day_today_background"/>
</shape>

Просмотреть файл

@ -1,13 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/uifabric_date_picker_item_highlight" android:state_focused="true" android:state_pressed="true" />
<item android:drawable="@color/uifabric_calendar_item_highlight" android:state_focused="true" android:state_pressed="true" />
<item android:drawable="@color/uifabric_date_picker_item_highlight" android:state_focused="false" android:state_pressed="true" />
<item android:drawable="@color/uifabric_calendar_item_highlight" android:state_focused="false" android:state_pressed="true" />
<item android:drawable="@color/uifabric_date_picker_item_highlight" android:state_focused="true" />
<item android:drawable="@color/uifabric_calendar_item_highlight" android:state_focused="true" />
<item android:drawable="@color/uifabric_date_picker_item_highlight" android:state_selected="true" />
<item android:drawable="@color/uifabric_calendar_item_highlight" android:state_selected="true" />
<item android:drawable="@android:color/transparent" />

Просмотреть файл

@ -9,7 +9,7 @@
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="@dimen/uifabric_date_picker_toolbar_elevation"
android:elevation="@dimen/uifabric_calendar_toolbar_elevation"
android:background="@color/uifabric_white"/>
<LinearLayout

Просмотреть файл

@ -18,8 +18,8 @@
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.microsoft.officeuifabric.datepicker.DatePickerView
android:id="@+id/date_picker_view"
<com.microsoft.officeuifabric.calendar.CalendarView
android:id="@+id/calendar_view"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

Просмотреть файл

@ -61,20 +61,20 @@
<color name="uifabric_chip_error_text">#A80000</color>
<color name="uifabric_chip_disabled_text">@color/uifabric_gray</color>
<!--DatePicker-->
<color name="uifabric_date_picker_week_header_background">@color/uifabric_primary</color>
<color name="uifabric_date_picker_week_heading_week_day_text">@color/uifabric_gray</color>
<color name="uifabric_date_picker_week_heading_weekend_text">@color/uifabric_border_light_gray</color>
<!--CalendarView-->
<color name="uifabric_calendar_week_header_background">@color/uifabric_primary</color>
<color name="uifabric_calendar_week_heading_week_day_text">@color/uifabric_gray</color>
<color name="uifabric_calendar_week_heading_weekend_text">@color/uifabric_border_light_gray</color>
<!-- TODO update after design adds #B2FFFFFF to toolkit -->
<color name="uifabric_date_picker_month_overlay_background">#B2FFFFFF</color>
<color name="uifabric_date_picker_month_overlay_text">@color/uifabric_black</color>
<color name="uifabric_date_picker_other_month_background">@color/uifabric_background_light_gray</color>
<color name="uifabric_calendar_month_overlay_background">#B2FFFFFF</color>
<color name="uifabric_calendar_month_overlay_text">@color/uifabric_black</color>
<color name="uifabric_calendar_other_month_background">@color/uifabric_background_light_gray</color>
<!-- TODO update after design adds #FFF5FAFC to toolkit -->
<color name="uifabric_date_picker_day_today_background">#FFF5FAFC</color>
<color name="uifabric_calendar_day_today_background">#FFF5FAFC</color>
<!-- TODO update after design adds #0E000000 to toolkit -->
<color name="uifabric_date_picker_item_highlight">#0E000000</color> <!-- 5% black -->
<color name="uifabric_date_picker_view_week_day_text">@color/date_picker_week_day_text_selector</color>
<color name="uifabric_date_picker_view_monochrome_text">@color/date_picker_week_day_text_selector</color>
<color name="uifabric_calendar_item_highlight">#0E000000</color> <!-- 5% black -->
<color name="uifabric_calendar_week_day_text">@color/calendar_week_day_text_selector</color>
<color name="uifabric_calendar_monochrome_text">@color/calendar_week_day_text_selector</color>
<!--Shared-->
<color name="uifabric_divider">@color/uifabric_border_gray</color>

Просмотреть файл

@ -13,15 +13,15 @@
<dimen name="uifabric_chip_padding">6dp</dimen>
<dimen name="uifabric_chip_spacing">6dp</dimen>
<!--DatePicker-->
<dimen name="uifabric_date_picker_view_week_day_font_size">16sp</dimen>
<dimen name="uifabric_date_picker_view_month_year_font_size">12sp</dimen>
<dimen name="uifabric_date_picker_view_week_heading_height">28dp</dimen>
<dimen name="uifabric_date_picker_view_week_heading_text_size">12sp</dimen>
<dimen name="uifabric_date_picker_view_month_overlay_text_size">20sp</dimen>
<dimen name="uifabric_date_picker_view_weeks_max_width">336dp</dimen>
<dimen name="uifabric_date_picker_view_day_selection_size">36dp</dimen>
<dimen name="uifabric_date_picker_toolbar_elevation">2dp</dimen>
<!--CalendarView-->
<dimen name="uifabric_calendar_week_day_font_size">16sp</dimen>
<dimen name="uifabric_calendar_month_year_font_size">12sp</dimen>
<dimen name="uifabric_calendar_week_heading_height">28dp</dimen>
<dimen name="uifabric_calendar_week_heading_text_size">12sp</dimen>
<dimen name="uifabric_calendar_month_overlay_text_size">20sp</dimen>
<dimen name="uifabric_calendar_weeks_max_width">336dp</dimen>
<dimen name="uifabric_calendar_day_selection_size">36dp</dimen>
<dimen name="uifabric_calendar_toolbar_elevation">2dp</dimen>
<!--DateTimePickerDialog-->
<dimen name="uifabric_date_time_picker_dialog_title_horizontal_margin">24dp</dimen>

Просмотреть файл

@ -1,7 +1,7 @@
<resources>
<string name="persona_title_placeholder">No name</string>
<!-- *** DatePicker *** -->
<!-- *** CalendarView *** -->
<string name="date_at_time">%1$s at %2$s</string>
<string name="all_day">All Day</string>