/*
|
* Copyright (C) 2019 xuexiangjys(xuexiangjys@163.com)
|
*
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
* you may not use this file except in compliance with the License.
|
* You may obtain a copy of the License at
|
*
|
* http://www.apache.org/licenses/LICENSE-2.0
|
*
|
* Unless required by applicable law or agreed to in writing, software
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* See the License for the specific language governing permissions and
|
* limitations under the License.
|
*/
|
|
package com.kuanzhai.driver.utils.citypickerview.picker.widget.builder;
|
|
import android.content.Context;
|
import android.view.ViewGroup;
|
|
import com.kuanzhai.driver.utils.citypickerview.picker.wheelview.WheelView;
|
import com.kuanzhai.driver.utils.citypickerview.picker.widget.TimePickerView;
|
import com.kuanzhai.driver.utils.citypickerview.picker.widget.configure.PickerOptions;
|
import com.kuanzhai.driver.utils.citypickerview.picker.widget.configure.TimePickerType;
|
import com.kuanzhai.driver.utils.citypickerview.picker.widget.listener.CustomListener;
|
import com.kuanzhai.driver.utils.citypickerview.picker.widget.listener.OnTimeSelectChangeListener;
|
import com.kuanzhai.driver.utils.citypickerview.picker.widget.listener.OnTimeSelectListener;
|
import com.xuexiang.xui.utils.ThemeUtils;
|
|
import java.util.Calendar;
|
|
/**
|
* 时间选择器构建者
|
*
|
* @author xuexiang
|
* @since 2019/1/1 下午8:20
|
*/
|
public class TimePickerBuilder {
|
|
private PickerOptions mPickerOptions;
|
|
//Required
|
public TimePickerBuilder(Context context, OnTimeSelectListener listener) {
|
mPickerOptions = new PickerOptions(PickerOptions.TYPE_PICKER_TIME);
|
mPickerOptions.context = context;
|
mPickerOptions.timeSelectListener = listener;
|
mPickerOptions.textColorConfirm = ThemeUtils.resolveColor(context, com.xuexiang.xui.R.attr.colorAccent);
|
mPickerOptions.textColorCancel = ThemeUtils.resolveColor(context, com.xuexiang.xui.R.attr.colorAccent);
|
}
|
|
//Option
|
public TimePickerBuilder setGravity(int gravity) {
|
mPickerOptions.textGravity = gravity;
|
return this;
|
}
|
|
/**
|
* new boolean[]{true, true, true, false, false, false}
|
* control the "year","month","day","hours","minutes","seconds " display or hide.
|
* 分别控制“年”“月”“日”“时”“分”“秒”的显示或隐藏。
|
*
|
* @param types 布尔型数组,长度需要设置为6。
|
* @return TimePickerBuilder
|
*/
|
public TimePickerBuilder setType(boolean... types) {
|
if (types.length != 6) {
|
throw new IllegalArgumentException("控制“年”“月”“日”“时”“分”“秒”的显示或隐藏, 长度必须为6!");
|
}
|
mPickerOptions.type = types;
|
return this;
|
}
|
|
|
/**
|
* 设置时间选择器的类型
|
*
|
* @param type 时间选择器的类型
|
* @return TimePickerBuilder
|
*/
|
public TimePickerBuilder setType(TimePickerType type) {
|
mPickerOptions.type = type.getType();
|
return this;
|
}
|
|
public TimePickerBuilder setSubmitText(String textContentConfirm) {
|
mPickerOptions.textContentConfirm = textContentConfirm;
|
return this;
|
}
|
|
public TimePickerBuilder isDialog(boolean isDialog) {
|
mPickerOptions.isDialog = isDialog;
|
return this;
|
}
|
|
public TimePickerBuilder setCancelText(String textContentCancel) {
|
mPickerOptions.textContentCancel = textContentCancel;
|
return this;
|
}
|
|
public TimePickerBuilder setTitleText(String textContentTitle) {
|
mPickerOptions.textContentTitle = textContentTitle;
|
return this;
|
}
|
|
public TimePickerBuilder setSubmitColor(int textColorConfirm) {
|
mPickerOptions.textColorConfirm = textColorConfirm;
|
return this;
|
}
|
|
public TimePickerBuilder setCancelColor(int textColorCancel) {
|
mPickerOptions.textColorCancel = textColorCancel;
|
return this;
|
}
|
|
/**
|
* ViewGroup 类型的容器
|
*
|
* @param decorView 选择器会被添加到此容器中
|
* @return TimePickerBuilder
|
*/
|
public TimePickerBuilder setDecorView(ViewGroup decorView) {
|
mPickerOptions.decorView = decorView;
|
return this;
|
}
|
|
public TimePickerBuilder setBgColor(int bgColorWheel) {
|
mPickerOptions.bgColorWheel = bgColorWheel;
|
return this;
|
}
|
|
public TimePickerBuilder setTitleBgColor(int bgColorTitle) {
|
mPickerOptions.bgColorTitle = bgColorTitle;
|
return this;
|
}
|
|
public TimePickerBuilder setTitleColor(int textColorTitle) {
|
mPickerOptions.textColorTitle = textColorTitle;
|
return this;
|
}
|
|
public TimePickerBuilder setSubCalSize(int textSizeSubmitCancel) {
|
mPickerOptions.textSizeSubmitCancel = textSizeSubmitCancel;
|
return this;
|
}
|
|
public TimePickerBuilder setTitleSize(int textSizeTitle) {
|
mPickerOptions.textSizeTitle = textSizeTitle;
|
return this;
|
}
|
|
public TimePickerBuilder setContentTextSize(int textSizeContent) {
|
mPickerOptions.textSizeContent = textSizeContent;
|
return this;
|
}
|
|
/**
|
* 因为系统Calendar的月份是从0-11的,所以如果是调用Calendar的set方法来设置时间,月份的范围也要是从0-11
|
*
|
* @param date
|
* @return TimePickerBuilder
|
*/
|
public TimePickerBuilder setDate(Calendar date) {
|
mPickerOptions.date = date;
|
return this;
|
}
|
|
public TimePickerBuilder setLayoutRes(int res, CustomListener customListener) {
|
mPickerOptions.layoutRes = res;
|
mPickerOptions.customListener = customListener;
|
return this;
|
}
|
|
|
/**
|
* 设置起始时间
|
* 因为系统Calendar的月份是从0-11的,所以如果是调用Calendar的set方法来设置时间,月份的范围也要是从0-11
|
*/
|
|
public TimePickerBuilder setRangDate(Calendar startDate, Calendar endDate) {
|
mPickerOptions.startDate = startDate;
|
mPickerOptions.endDate = endDate;
|
return this;
|
}
|
|
|
/**
|
* 设置间距倍数,但是只能在1.0-4.0f之间
|
*
|
* @param lineSpacingMultiplier
|
*/
|
public TimePickerBuilder setLineSpacingMultiplier(float lineSpacingMultiplier) {
|
mPickerOptions.lineSpacingMultiplier = lineSpacingMultiplier;
|
return this;
|
}
|
|
/**
|
* 设置分割线的颜色
|
*
|
* @param dividerColor
|
*/
|
public TimePickerBuilder setDividerColor(int dividerColor) {
|
mPickerOptions.dividerColor = dividerColor;
|
return this;
|
}
|
|
/**
|
* 设置分割线的类型
|
*
|
* @param dividerType
|
*/
|
public TimePickerBuilder setDividerType(WheelView.DividerType dividerType) {
|
mPickerOptions.dividerType = dividerType;
|
return this;
|
}
|
|
/**
|
* //显示时的外部背景色颜色,默认是灰色
|
*
|
* @param backgroundId
|
*/
|
|
public TimePickerBuilder setBackgroundId(int backgroundId) {
|
mPickerOptions.backgroundId = backgroundId;
|
return this;
|
}
|
|
/**
|
* 设置分割线之间的文字的颜色
|
*
|
* @param textColorCenter
|
*/
|
public TimePickerBuilder setTextColorCenter(int textColorCenter) {
|
mPickerOptions.textColorCenter = textColorCenter;
|
return this;
|
}
|
|
/**
|
* 设置分割线以外文字的颜色
|
*
|
* @param textColorOut
|
*/
|
public TimePickerBuilder setTextColorOut(int textColorOut) {
|
mPickerOptions.textColorOut = textColorOut;
|
return this;
|
}
|
|
public TimePickerBuilder isCyclic(boolean cyclic) {
|
mPickerOptions.cyclic = cyclic;
|
return this;
|
}
|
|
public TimePickerBuilder setOutSideCancelable(boolean cancelable) {
|
mPickerOptions.cancelable = cancelable;
|
return this;
|
}
|
|
public TimePickerBuilder setLunarCalendar(boolean lunarCalendar) {
|
mPickerOptions.isLunarCalendar = lunarCalendar;
|
return this;
|
}
|
|
|
public TimePickerBuilder setLabel(String label_year, String label_month, String label_day, String label_hours, String label_mins, String label_seconds) {
|
mPickerOptions.label_year = label_year;
|
mPickerOptions.label_month = label_month;
|
mPickerOptions.label_day = label_day;
|
mPickerOptions.label_hours = label_hours;
|
mPickerOptions.label_minutes = label_mins;
|
mPickerOptions.label_seconds = label_seconds;
|
return this;
|
}
|
|
/**
|
* 设置X轴倾斜角度[ -90 , 90°]
|
*
|
* @param x_offset_year 年
|
* @param x_offset_month 月
|
* @param x_offset_day 日
|
* @param x_offset_hours 时
|
* @param x_offset_minutes 分
|
* @param x_offset_seconds 秒
|
* @return
|
*/
|
public TimePickerBuilder setTextXOffset(int x_offset_year, int x_offset_month, int x_offset_day,
|
int x_offset_hours, int x_offset_minutes, int x_offset_seconds) {
|
mPickerOptions.x_offset_year = x_offset_year;
|
mPickerOptions.x_offset_month = x_offset_month;
|
mPickerOptions.x_offset_day = x_offset_day;
|
mPickerOptions.x_offset_hours = x_offset_hours;
|
mPickerOptions.x_offset_minutes = x_offset_minutes;
|
mPickerOptions.x_offset_seconds = x_offset_seconds;
|
return this;
|
}
|
|
public TimePickerBuilder isCenterLabel(boolean isCenterLabel) {
|
mPickerOptions.isCenterLabel = isCenterLabel;
|
return this;
|
}
|
|
/**
|
* @param listener 切换item项滚动停止时,实时回调监听。
|
* @return
|
*/
|
public TimePickerBuilder setTimeSelectChangeListener(OnTimeSelectChangeListener listener) {
|
mPickerOptions.timeSelectChangeListener = listener;
|
return this;
|
}
|
|
public TimePickerView build() {
|
return new TimePickerView(mPickerOptions);
|
}
|
}
|